mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-25 00:29: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:
parent
59ae6b9987
commit
1c7eea60d3
@ -84,6 +84,12 @@ bool LLParser::ValidateEndOfModule() {
|
||||
"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 @@ bool LLParser::ParseStandaloneMetadata() {
|
||||
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 @@ bool LLParser::ParseValID(ValID &ID) {
|
||||
unsigned MID = 0;
|
||||
if (!ParseUInt32(MID)) {
|
||||
std::map<unsigned, Constant *>::iterator I = MetadataCache.find(MID);
|
||||
if (I == MetadataCache.end())
|
||||
return TokError("Unknown metadata reference");
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,8 @@ namespace llvm {
|
||||
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;
|
||||
|
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}
|
Loading…
Reference in New Issue
Block a user