summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2009-09-16 20:21:17 +0000
committerDevang Patel <dpatel@apple.com>2009-09-16 20:21:17 +0000
commitdec23fd82522b157b5d27e55e5908eb371f7b884 (patch)
treec131ff905d9a0fd30f66a71cf99dd15e8c45ec93 /llvm
parent5d8cfb217c43a36fa554fa8fef952dfb88119daf (diff)
downloadbcm5719-llvm-dec23fd82522b157b5d27e55e5908eb371f7b884.tar.gz
bcm5719-llvm-dec23fd82522b157b5d27e55e5908eb371f7b884.zip
Print debug info attached with an instruction.
llvm-svn: 82075
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Metadata.h8
-rw-r--r--llvm/lib/VMCore/AsmWriter.cpp18
-rw-r--r--llvm/lib/VMCore/Metadata.cpp9
3 files changed, 32 insertions, 3 deletions
diff --git a/llvm/include/llvm/Metadata.h b/llvm/include/llvm/Metadata.h
index 66a10a87e11..a2394beb400 100644
--- a/llvm/include/llvm/Metadata.h
+++ b/llvm/include/llvm/Metadata.h
@@ -312,9 +312,11 @@ public:
/// ID values are 1 or higher. This ID is set by RegisterMDKind.
typedef unsigned MDKindID;
class Metadata {
-private:
+public:
typedef std::pair<MDKindID, WeakVH> MDPairTy;
typedef SmallVector<MDPairTy, 2> MDMapTy;
+
+private:
typedef DenseMap<const Instruction *, MDMapTy> MDStoreTy;
/// MetadataStore - Collection of metadata used in this context.
@@ -324,7 +326,6 @@ private:
StringMap<unsigned> MDHandlerNames;
public:
-
/// RegisterMDKind - Register a new metadata kind and return its ID.
/// A metadata kind can be registered only once.
MDKindID RegisterMDKind(const char *Name);
@@ -337,6 +338,9 @@ public:
/// If the metadata is not found then return 0.
MDNode *getMD(MDKindID Kind, const Instruction *Inst);
+ /// getMDs - Get the metadata attached with an Instruction.
+ const MDMapTy *getMDs(const Instruction *Inst);
+
/// setMD - Attach the metadata of given kind with an Instruction.
void setMD(MDKindID Kind, MDNode *Node, Instruction *Inst);
diff --git a/llvm/lib/VMCore/AsmWriter.cpp b/llvm/lib/VMCore/AsmWriter.cpp
index a61f8fb2315..12436523b16 100644
--- a/llvm/lib/VMCore/AsmWriter.cpp
+++ b/llvm/lib/VMCore/AsmWriter.cpp
@@ -678,6 +678,8 @@ void SlotTracker::processFunction() {
ST_DEBUG("Inserting Instructions:\n");
+ Metadata &TheMetadata = TheFunction->getContext().getMetadata();
+
// Add all of the basic blocks and instructions with no names.
for (Function::const_iterator BB = TheFunction->begin(),
E = TheFunction->end(); BB != E; ++BB) {
@@ -691,9 +693,17 @@ void SlotTracker::processFunction() {
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
if (MDNode *N = dyn_cast_or_null<MDNode>(I->getOperand(i)))
CreateMetadataSlot(N);
+
+ // Process metadata attached with this instruction.
+ const Metadata::MDMapTy *MDs = TheMetadata.getMDs(I);
+ if (MDs)
+ for (Metadata::MDMapTy::const_iterator MI = MDs->begin(),
+ ME = MDs->end(); MI != ME; ++MI)
+ if (MDNode *MDN = dyn_cast_or_null<MDNode>(MI->second))
+ CreateMetadataSlot(MDN);
}
}
-
+
FunctionProcessed = true;
ST_DEBUG("end processFunction!\n");
@@ -1255,6 +1265,7 @@ class AssemblyWriter {
// Each MDNode is assigned unique MetadataIDNo.
std::map<const MDNode *, unsigned> MDNodes;
unsigned MetadataIDNo;
+
public:
inline AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
const Module *M,
@@ -1979,6 +1990,11 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
Out << ", align " << cast<StoreInst>(I).getAlignment();
}
+ // Print DebugInfo
+ Metadata &TheMetadata = I.getContext().getMetadata();
+ unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
+ if (const MDNode *Dbg = TheMetadata.getMD(MDDbgKind, &I))
+ Out << ", dbg !" << Machine.getMetadataSlot(Dbg);
printInfoComment(I);
}
diff --git a/llvm/lib/VMCore/Metadata.cpp b/llvm/lib/VMCore/Metadata.cpp
index 062fb96e5bf..2c80a60a8cf 100644
--- a/llvm/lib/VMCore/Metadata.cpp
+++ b/llvm/lib/VMCore/Metadata.cpp
@@ -308,6 +308,15 @@ MDNode *Metadata::getMD(MDKindID MDKind, const Instruction *Inst) {
return Node;
}
+/// getMDs - Get the metadata attached with an Instruction.
+const Metadata::MDMapTy *Metadata::getMDs(const Instruction *Inst) {
+ MDStoreTy::iterator I = MetadataStore.find(Inst);
+ if (I == MetadataStore.end())
+ return NULL;
+
+ return &(I->second);
+}
+
/// ValueIsDeleted - This handler is used to update metadata store
/// when a value is deleted.
void Metadata::ValueIsDeleted(const Instruction *Inst) {
OpenPOWER on IntegriCloud