aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2009-09-29 20:30:57 +0000
committerDevang Patel <dpatel@apple.com>2009-09-29 20:30:57 +0000
commit58a230a4917592f5c529cb40e75bfc3e1c681b69 (patch)
treeb2f31e6fba7970c32de4cfccd755ed35a1188b6b
parenta9a9c95f6789946d5df34185725fc28cebad8b16 (diff)
downloadexternal_llvm-58a230a4917592f5c529cb40e75bfc3e1c681b69.tar.gz
external_llvm-58a230a4917592f5c529cb40e75bfc3e1c681b69.tar.bz2
external_llvm-58a230a4917592f5c529cb40e75bfc3e1c681b69.zip
Only one custom meadata of each kind can be attached with an instruction.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83105 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Metadata.h4
-rw-r--r--include/llvm/Support/IRBuilder.h4
-rw-r--r--lib/AsmParser/LLParser.cpp2
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp2
-rw-r--r--lib/VMCore/Metadata.cpp28
5 files changed, 25 insertions, 15 deletions
diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h
index 2f740a6c84..8ad7aaf3f1 100644
--- a/include/llvm/Metadata.h
+++ b/include/llvm/Metadata.h
@@ -342,8 +342,8 @@ public:
/// 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.
diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h
index b5e17871ea..1f659787eb 100644
--- a/include/llvm/Support/IRBuilder.h
+++ b/include/llvm/Support/IRBuilder.h
@@ -148,7 +148,7 @@ public:
/// 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 @@ public:
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;
}
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index 9e8015966d..42ce95347d 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -2665,7 +2665,7 @@ bool LLParser::ParseBasicBlock(PerFunctionState &PFS) {
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);
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index f5ddd3ff3b..fe0366fb62 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1582,7 +1582,7 @@ bool BitcodeReader::ParseMetadataAttachment() {
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;
}
diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp
index 0a8e865cff..6e2fc3f25f 100644
--- a/lib/VMCore/Metadata.cpp
+++ b/lib/VMCore/Metadata.cpp
@@ -300,18 +300,29 @@ unsigned MetadataContext::getMDKind(const char *Name) {
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 @@ void MetadataContext::setMD(unsigned MDKind, MDNode *Node, Instruction *Inst) {
/// 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 @@ void MetadataContext::ValueIsCloned(const Instruction *In1, Instruction *In2) {
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);
}