mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-14 15:28:20 +00:00
Support MDNode forward reference.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75031 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -84,6 +84,12 @@ bool LLParser::ValidateEndOfModule() {
|
|||||||
"use of undefined value '@" +
|
"use of undefined value '@" +
|
||||||
utostr(ForwardRefValIDs.begin()->first) + "'");
|
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
|
// Look for intrinsic functions and CallInst that need to be upgraded
|
||||||
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; )
|
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; )
|
||||||
UpgradeCallsToIntrinsic(FI++); // must be post-increment, as we remove
|
UpgradeCallsToIntrinsic(FI++); // must be post-increment, as we remove
|
||||||
@@ -382,6 +388,14 @@ bool LLParser::ParseStandaloneMetadata() {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
MetadataCache[MetadataID] = Init;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1632,9 +1646,24 @@ bool LLParser::ParseValID(ValID &ID) {
|
|||||||
unsigned MID = 0;
|
unsigned MID = 0;
|
||||||
if (!ParseUInt32(MID)) {
|
if (!ParseUInt32(MID)) {
|
||||||
std::map<unsigned, Constant *>::iterator I = MetadataCache.find(MID);
|
std::map<unsigned, Constant *>::iterator I = MetadataCache.find(MID);
|
||||||
if (I == MetadataCache.end())
|
if (I != MetadataCache.end())
|
||||||
return TokError("Unknown metadata reference");
|
ID.ConstantVal = I->second;
|
||||||
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -46,6 +46,8 @@ namespace llvm {
|
|||||||
std::vector<PATypeHolder> NumberedTypes;
|
std::vector<PATypeHolder> NumberedTypes;
|
||||||
/// MetadataCache - This map keeps track of parsed metadata constants.
|
/// MetadataCache - This map keeps track of parsed metadata constants.
|
||||||
std::map<unsigned, Constant *> MetadataCache;
|
std::map<unsigned, Constant *> MetadataCache;
|
||||||
|
std::map<unsigned, std::pair<Constant *, LocTy> > ForwardRefMDNodes;
|
||||||
|
|
||||||
struct UpRefRecord {
|
struct UpRefRecord {
|
||||||
/// Loc - This is the location of the upref.
|
/// Loc - This is the location of the upref.
|
||||||
LocTy Loc;
|
LocTy Loc;
|
||||||
|
5
test/Feature/mdnode4.ll
Normal file
5
test/Feature/mdnode4.ll
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
; Test forward MDNode reference
|
||||||
|
; RUN: llvm-as < %s | llvm-dis -f -o /dev/null
|
||||||
|
|
||||||
|
@llvm.blah = constant metadata !{metadata !1}
|
||||||
|
!1 = constant metadata !{i32 23, i32 24}
|
Reference in New Issue
Block a user