[llvm-commits] [llvm] r75031 - in /llvm/trunk: lib/AsmParser/LLParser.cpp lib/AsmParser/LLParser.h test/Feature/mdnode4.ll
Devang Patel
dpatel at apple.com
Wed Jul 8 12:24:09 PDT 2009
Author: dpatel
Date: Wed Jul 8 14:23:54 2009
New Revision: 75031
URL: http://llvm.org/viewvc/llvm-project?rev=75031&view=rev
Log:
Support MDNode forward reference.
Added:
llvm/trunk/test/Feature/mdnode4.ll
Modified:
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/AsmParser/LLParser.h
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=75031&r1=75030&r2=75031&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Wed Jul 8 14:23:54 2009
@@ -84,6 +84,12 @@
"use of undefined value '@" +
utostr(ForwardRefValIDs.begin()->first) + "'");
+ if (!ForwardRefMDNodes.empty())
+ return Error(ForwardRefMDNodes.begin()->second.second,
+ "use of undefined metadata '!" +
+ utostr(ForwardRefMDNodes.begin()->first) + "'");
+
+
// Look for intrinsic functions and CallInst that need to be upgraded
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; )
UpgradeCallsToIntrinsic(FI++); // must be post-increment, as we remove
@@ -382,6 +388,14 @@
return true;
MetadataCache[MetadataID] = Init;
+ std::map<unsigned, std::pair<Constant *, LocTy> >::iterator
+ FI = ForwardRefMDNodes.find(MetadataID);
+ if (FI != ForwardRefMDNodes.end()) {
+ Constant *FwdNode = FI->second.first;
+ FwdNode->replaceAllUsesWith(Init);
+ ForwardRefMDNodes.erase(FI);
+ }
+
return false;
}
@@ -1632,9 +1646,24 @@
unsigned MID = 0;
if (!ParseUInt32(MID)) {
std::map<unsigned, Constant *>::iterator I = MetadataCache.find(MID);
- if (I == MetadataCache.end())
- return TokError("Unknown metadata reference");
- ID.ConstantVal = I->second;
+ if (I != MetadataCache.end())
+ ID.ConstantVal = I->second;
+ else {
+ std::map<unsigned, std::pair<Constant *, LocTy> >::iterator
+ FI = ForwardRefMDNodes.find(MID);
+ if (FI != ForwardRefMDNodes.end())
+ ID.ConstantVal = FI->second.first;
+ else {
+ // Create MDNode forward reference
+ SmallVector<Value *, 1> Elts;
+ std::string FwdRefName = "llvm.mdnode.fwdref." + MID;
+ Elts.push_back(Context.getMDString(FwdRefName));
+ MDNode *FwdNode = Context.getMDNode(Elts.data(), Elts.size());
+ ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc());
+ ID.ConstantVal = FwdNode;
+ }
+ }
+
return false;
}
Modified: llvm/trunk/lib/AsmParser/LLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.h?rev=75031&r1=75030&r2=75031&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.h (original)
+++ llvm/trunk/lib/AsmParser/LLParser.h Wed Jul 8 14:23:54 2009
@@ -46,6 +46,8 @@
std::vector<PATypeHolder> NumberedTypes;
/// MetadataCache - This map keeps track of parsed metadata constants.
std::map<unsigned, Constant *> MetadataCache;
+ std::map<unsigned, std::pair<Constant *, LocTy> > ForwardRefMDNodes;
+
struct UpRefRecord {
/// Loc - This is the location of the upref.
LocTy Loc;
Added: llvm/trunk/test/Feature/mdnode4.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Feature/mdnode4.ll?rev=75031&view=auto
==============================================================================
--- llvm/trunk/test/Feature/mdnode4.ll (added)
+++ llvm/trunk/test/Feature/mdnode4.ll Wed Jul 8 14:23:54 2009
@@ -0,0 +1,5 @@
+; Test forward MDNode reference
+; RUN: llvm-as < %s | llvm-dis -f -o /dev/null
+
+ at llvm.blah = constant metadata !{metadata !1}
+!1 = constant metadata !{i32 23, i32 24}
More information about the llvm-commits
mailing list