[llvm-commits] [llvm] r83105 - in /llvm/trunk: include/llvm/Metadata.h include/llvm/Support/IRBuilder.h lib/AsmParser/LLParser.cpp lib/Bitcode/Reader/BitcodeReader.cpp lib/VMCore/Metadata.cpp
Devang Patel
dpatel at apple.com
Tue Sep 29 13:30:57 PDT 2009
Author: dpatel
Date: Tue Sep 29 15:30:57 2009
New Revision: 83105
URL: http://llvm.org/viewvc/llvm-project?rev=83105&view=rev
Log:
Only one custom meadata of each kind can be attached with an instruction.
Modified:
llvm/trunk/include/llvm/Metadata.h
llvm/trunk/include/llvm/Support/IRBuilder.h
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/lib/VMCore/Metadata.cpp
Modified: llvm/trunk/include/llvm/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Metadata.h?rev=83105&r1=83104&r2=83105&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Metadata.h (original)
+++ llvm/trunk/include/llvm/Metadata.h Tue Sep 29 15:30:57 2009
@@ -342,8 +342,8 @@
/// 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(unsigned Kind, MDNode *Node, Instruction *Inst);
+ /// addMD - Attach the metadata of given kind with an Instruction.
+ void addMD(unsigned Kind, MDNode *Node, Instruction *Inst);
/// getHandlerNames - Get handler names. This is used by bitcode
/// writer.
Modified: llvm/trunk/include/llvm/Support/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/IRBuilder.h?rev=83105&r1=83104&r2=83105&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/IRBuilder.h (original)
+++ llvm/trunk/include/llvm/Support/IRBuilder.h Tue Sep 29 15:30:57 2009
@@ -148,7 +148,7 @@
/// SetDebugLocation - Set location information for the given instruction.
void SetDebugLocation(Instruction *I) {
if (CurDbgLocation)
- Context.getMetadata().setMD(MDKind, CurDbgLocation, I);
+ Context.getMetadata().addMD(MDKind, CurDbgLocation, I);
}
/// Insert - Insert and return the specified instruction.
@@ -156,7 +156,7 @@
InstTy *Insert(InstTy *I, const Twine &Name = "") const {
this->InsertHelper(I, Name, BB, InsertPt);
if (CurDbgLocation)
- Context.getMetadata().setMD(MDKind, CurDbgLocation, I);
+ Context.getMetadata().addMD(MDKind, CurDbgLocation, I);
return I;
}
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=83105&r1=83104&r2=83105&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Tue Sep 29 15:30:57 2009
@@ -2665,7 +2665,7 @@
MetadataContext &TheMetadata = M->getContext().getMetadata();
for (SmallVector<std::pair<unsigned, MDNode *>, 2>::iterator
MDI = MDsOnInst.begin(), MDE = MDsOnInst.end(); MDI != MDE; ++MDI)
- TheMetadata.setMD(MDI->first, MDI->second, Inst);
+ TheMetadata.addMD(MDI->first, MDI->second, Inst);
MDsOnInst.clear();
BB->getInstList().push_back(Inst);
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=83105&r1=83104&r2=83105&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Tue Sep 29 15:30:57 2009
@@ -1582,7 +1582,7 @@
for (unsigned i = 1; i != RecordLength; i = i+2) {
unsigned Kind = Record[i];
Value *Node = MDValueList.getValueFwdRef(Record[i+1]);
- TheMetadata.setMD(Kind, cast<MDNode>(Node), Inst);
+ TheMetadata.addMD(Kind, cast<MDNode>(Node), Inst);
}
break;
}
Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=83105&r1=83104&r2=83105&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Tue Sep 29 15:30:57 2009
@@ -300,18 +300,29 @@
return I->getValue();
}
-/// setMD - Attach the metadata of given kind with an Instruction.
-void MetadataContext::setMD(unsigned MDKind, MDNode *Node, Instruction *Inst) {
- MDStoreTy::iterator I = MetadataStore.find(Inst);
+/// addMD - Attach the metadata of given kind with an Instruction.
+void MetadataContext::addMD(unsigned MDKind, MDNode *Node, Instruction *Inst) {
+ assert (Node && "Unable to add custome metadata");
Inst->HasMetadata = true;
+ MDStoreTy::iterator I = MetadataStore.find(Inst);
if (I == MetadataStore.end()) {
MDMapTy Info;
Info.push_back(std::make_pair(MDKind, Node));
MetadataStore.insert(std::make_pair(Inst, Info));
return;
}
-
+
MDMapTy &Info = I->second;
+ // If there is an entry for this MDKind then replace it.
+ for (unsigned i = 0, e = Info.size(); i != e; ++i) {
+ MDPairTy &P = Info[i];
+ if (P.first == MDKind) {
+ Info[i] = std::make_pair(MDKind, Node);
+ return;
+ }
+ }
+
+ // Otherwise add a new entry.
Info.push_back(std::make_pair(MDKind, Node));
return;
}
@@ -319,16 +330,15 @@
/// getMD - Get the metadata of given kind attached with an Instruction.
/// If the metadata is not found then return 0.
MDNode *MetadataContext::getMD(unsigned MDKind, const Instruction *Inst) {
- MDNode *Node = NULL;
MDStoreTy::iterator I = MetadataStore.find(Inst);
if (I == MetadataStore.end())
- return Node;
+ return NULL;
MDMapTy &Info = I->second;
for (MDMapTy::iterator I = Info.begin(), E = Info.end(); I != E; ++I)
if (I->first == MDKind)
- Node = dyn_cast_or_null<MDNode>(I->second);
- return Node;
+ return dyn_cast_or_null<MDNode>(I->second);
+ return NULL;
}
/// getMDs - Get the metadata attached with an Instruction.
@@ -374,5 +384,5 @@
MDMapTy In2Info;
for (MDMapTy::iterator I = In1Info.begin(), E = In1Info.end(); I != E; ++I)
if (MDNode *MD = dyn_cast_or_null<MDNode>(I->second))
- setMD(I->first, MD, In2);
+ addMD(I->first, MD, In2);
}
More information about the llvm-commits
mailing list