summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2015-08-19 00:13:25 +0000
committerAlex Lorenz <arphaman@gmail.com>2015-08-19 00:13:25 +0000
commitdf9e3c6fb0b94dcff370eb1c840487f6349ac6a5 (patch)
tree6bfa02dc92ba4a0db970e96e43f397c00ee9fd4f /llvm/lib
parent861ad97e6f1bd354ec51865587073bd94bea2d64 (diff)
downloadbcm5719-llvm-df9e3c6fb0b94dcff370eb1c840487f6349ac6a5.tar.gz
bcm5719-llvm-df9e3c6fb0b94dcff370eb1c840487f6349ac6a5.zip
MIR Serialization: Serialize MMI's variable debug information.
llvm-svn: 245396
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/MIRParser/MIParser.cpp18
-rw-r--r--llvm/lib/CodeGen/MIRParser/MIParser.h5
-rw-r--r--llvm/lib/CodeGen/MIRParser/MIRParser.cpp61
-rw-r--r--llvm/lib/CodeGen/MIRPrinter.cpp29
4 files changed, 111 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
index 3ec039285b3..edfca5f88a4 100644
--- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
@@ -100,6 +100,7 @@ public:
bool parseStandaloneNamedRegister(unsigned &Reg);
bool parseStandaloneVirtualRegister(unsigned &Reg);
bool parseStandaloneStackObject(int &FI);
+ bool parseStandaloneMDNode(MDNode *&Node);
bool
parseBasicBlockDefinition(DenseMap<unsigned, MachineBasicBlock *> &MBBSlots);
@@ -677,6 +678,17 @@ bool MIParser::parseStandaloneStackObject(int &FI) {
return false;
}
+bool MIParser::parseStandaloneMDNode(MDNode *&Node) {
+ lex();
+ if (Token.isNot(MIToken::exclaim))
+ return error("expected a metadata node");
+ if (parseMDNode(Node))
+ return true;
+ if (Token.isNot(MIToken::Eof))
+ return error("expected end of string after the metadata node");
+ return false;
+}
+
static const char *printImplicitRegisterFlag(const MachineOperand &MO) {
assert(MO.isImplicit());
return MO.isDef() ? "implicit-def" : "implicit";
@@ -1858,3 +1870,9 @@ bool llvm::parseStackObjectReference(int &FI, SourceMgr &SM,
return MIParser(SM, MF, Error, Src, PFS, IRSlots)
.parseStandaloneStackObject(FI);
}
+
+bool llvm::parseMDNode(MDNode *&Node, SourceMgr &SM, MachineFunction &MF,
+ StringRef Src, const PerFunctionMIParsingState &PFS,
+ const SlotMapping &IRSlots, SMDiagnostic &Error) {
+ return MIParser(SM, MF, Error, Src, PFS, IRSlots).parseStandaloneMDNode(Node);
+}
diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.h b/llvm/lib/CodeGen/MIRParser/MIParser.h
index 9e997efa54c..8aef704ab36 100644
--- a/llvm/lib/CodeGen/MIRParser/MIParser.h
+++ b/llvm/lib/CodeGen/MIRParser/MIParser.h
@@ -23,6 +23,7 @@ class BasicBlock;
class MachineBasicBlock;
class MachineInstr;
class MachineFunction;
+class MDNode;
struct SlotMapping;
class SMDiagnostic;
class SourceMgr;
@@ -89,6 +90,10 @@ bool parseStackObjectReference(int &FI, SourceMgr &SM, MachineFunction &MF,
const PerFunctionMIParsingState &PFS,
const SlotMapping &IRSlots, SMDiagnostic &Error);
+bool parseMDNode(MDNode *&Node, SourceMgr &SM, MachineFunction &MF,
+ StringRef Src, const PerFunctionMIParsingState &PFS,
+ const SlotMapping &IRSlots, SMDiagnostic &Error);
+
} // end namespace llvm
#endif
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
index 95df67ea7a9..422efbc5ce5 100644
--- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
@@ -23,6 +23,7 @@
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/MIRYamlMapping.h"
#include "llvm/IR/BasicBlock.h"
@@ -113,6 +114,11 @@ public:
const yaml::StringValue &RegisterSource,
int FrameIdx);
+ bool parseStackObjectsDebugInfo(MachineFunction &MF,
+ PerFunctionMIParsingState &PFS,
+ const yaml::MachineStackObject &Object,
+ int FrameIdx);
+
bool initializeConstantPool(MachineConstantPool &ConstantPool,
const yaml::MachineFunction &YamlMF,
const MachineFunction &MF,
@@ -123,6 +129,9 @@ public:
PerFunctionMIParsingState &PFS);
private:
+ bool parseMDNode(MDNode *&Node, const yaml::StringValue &Source,
+ MachineFunction &MF, const PerFunctionMIParsingState &PFS);
+
bool parseMBBReference(MachineBasicBlock *&MBB,
const yaml::StringValue &Source, MachineFunction &MF,
const PerFunctionMIParsingState &PFS);
@@ -489,6 +498,8 @@ bool MIRParserImpl::initializeFrameInfo(MachineFunction &MF,
return true;
if (Object.LocalOffset)
MFI.mapLocalFrameObject(ObjectIdx, Object.LocalOffset.getValue());
+ if (parseStackObjectsDebugInfo(MF, PFS, Object, ObjectIdx))
+ return true;
}
MFI.setCalleeSavedInfo(CSIInfo);
if (!CSIInfo.empty())
@@ -522,6 +533,56 @@ bool MIRParserImpl::parseCalleeSavedRegister(
return false;
}
+/// Verify that given node is of a certain type. Return true on error.
+template <typename T>
+static bool typecheckMDNode(T *&Result, MDNode *Node,
+ const yaml::StringValue &Source,
+ StringRef TypeString, MIRParserImpl &Parser) {
+ if (!Node)
+ return false;
+ Result = dyn_cast<T>(Node);
+ if (!Result)
+ return Parser.error(Source.SourceRange.Start,
+ "expected a reference to a '" + TypeString +
+ "' metadata node");
+ return false;
+}
+
+bool MIRParserImpl::parseStackObjectsDebugInfo(
+ MachineFunction &MF, PerFunctionMIParsingState &PFS,
+ const yaml::MachineStackObject &Object, int FrameIdx) {
+ // Debug information can only be attached to stack objects; Fixed stack
+ // objects aren't supported.
+ assert(FrameIdx >= 0 && "Expected a stack object frame index");
+ MDNode *Var = nullptr, *Expr = nullptr, *Loc = nullptr;
+ if (parseMDNode(Var, Object.DebugVar, MF, PFS) ||
+ parseMDNode(Expr, Object.DebugExpr, MF, PFS) ||
+ parseMDNode(Loc, Object.DebugLoc, MF, PFS))
+ return true;
+ if (!Var && !Expr && !Loc)
+ return false;
+ DILocalVariable *DIVar = nullptr;
+ DIExpression *DIExpr = nullptr;
+ DILocation *DILoc = nullptr;
+ if (typecheckMDNode(DIVar, Var, Object.DebugVar, "DILocalVariable", *this) ||
+ typecheckMDNode(DIExpr, Expr, Object.DebugExpr, "DIExpression", *this) ||
+ typecheckMDNode(DILoc, Loc, Object.DebugLoc, "DILocation", *this))
+ return true;
+ MF.getMMI().setVariableDbgInfo(DIVar, DIExpr, unsigned(FrameIdx), DILoc);
+ return false;
+}
+
+bool MIRParserImpl::parseMDNode(MDNode *&Node, const yaml::StringValue &Source,
+ MachineFunction &MF,
+ const PerFunctionMIParsingState &PFS) {
+ if (Source.Value.empty())
+ return false;
+ SMDiagnostic Error;
+ if (llvm::parseMDNode(Node, SM, MF, Source.Value, PFS, IRSlots, Error))
+ return error(Error, Source.SourceRange);
+ return false;
+}
+
bool MIRParserImpl::initializeConstantPool(
MachineConstantPool &ConstantPool, const yaml::MachineFunction &YamlMF,
const MachineFunction &MF,
diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp
index 67fd5c226a5..faeb9055c23 100644
--- a/llvm/lib/CodeGen/MIRPrinter.cpp
+++ b/llvm/lib/CodeGen/MIRPrinter.cpp
@@ -84,7 +84,8 @@ public:
void convert(ModuleSlotTracker &MST, yaml::MachineJumpTable &YamlJTI,
const MachineJumpTableInfo &JTI);
void convertStackObjects(yaml::MachineFunction &MF,
- const MachineFrameInfo &MFI, ModuleSlotTracker &MST,
+ const MachineFrameInfo &MFI, MachineModuleInfo &MMI,
+ ModuleSlotTracker &MST,
const TargetRegisterInfo *TRI);
private:
@@ -171,7 +172,7 @@ void MIRPrinter::print(const MachineFunction &MF) {
ModuleSlotTracker MST(MF.getFunction()->getParent());
MST.incorporateFunction(*MF.getFunction());
convert(MST, YamlMF.FrameInfo, *MF.getFrameInfo());
- convertStackObjects(YamlMF, *MF.getFrameInfo(), MST,
+ convertStackObjects(YamlMF, *MF.getFrameInfo(), MF.getMMI(), MST,
MF.getSubtarget().getRegisterInfo());
if (const auto *ConstantPool = MF.getConstantPool())
convert(YamlMF, *ConstantPool);
@@ -265,6 +266,7 @@ void MIRPrinter::convert(ModuleSlotTracker &MST,
void MIRPrinter::convertStackObjects(yaml::MachineFunction &MF,
const MachineFrameInfo &MFI,
+ MachineModuleInfo &MMI,
ModuleSlotTracker &MST,
const TargetRegisterInfo *TRI) {
// Process fixed stack objects.
@@ -342,6 +344,29 @@ void MIRPrinter::convertStackObjects(yaml::MachineFunction &MF,
MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
.printStackObjectReference(MFI.getStackProtectorIndex());
}
+
+ // Print the debug variable information.
+ for (MachineModuleInfo::VariableDbgInfo &DebugVar :
+ MMI.getVariableDbgInfo()) {
+ auto StackObjectInfo = StackObjectOperandMapping.find(DebugVar.Slot);
+ assert(StackObjectInfo != StackObjectOperandMapping.end() &&
+ "Invalid stack object index");
+ const FrameIndexOperand &StackObject = StackObjectInfo->second;
+ assert(!StackObject.IsFixed && "Expected a non-fixed stack object");
+ auto &Object = MF.StackObjects[StackObject.ID];
+ {
+ raw_string_ostream StrOS(Object.DebugVar.Value);
+ DebugVar.Var->printAsOperand(StrOS, MST);
+ }
+ {
+ raw_string_ostream StrOS(Object.DebugExpr.Value);
+ DebugVar.Expr->printAsOperand(StrOS, MST);
+ }
+ {
+ raw_string_ostream StrOS(Object.DebugLoc.Value);
+ DebugVar.Loc->printAsOperand(StrOS, MST);
+ }
+ }
}
void MIRPrinter::convert(yaml::MachineFunction &MF,
OpenPOWER on IntegriCloud