"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
return true;
LocTy TyLoc;
- bool IsConstant;
PATypeHolder Ty(Type::VoidTy);
- if (ParseGlobalType(IsConstant) ||
- ParseType(Ty, TyLoc))
+ if (ParseType(Ty, TyLoc))
return true;
Constant *Init = 0;
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;
}
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." + utostr(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;
}
if (Opc == Instruction::FCmp) {
if (!LHS->getType()->isFPOrFPVector())
return Error(Loc, "fcmp requires floating point operands");
- Inst = new FCmpInst(CmpInst::Predicate(Pred), LHS, RHS);
+ Inst = new FCmpInst(Context, CmpInst::Predicate(Pred), LHS, RHS);
} else {
assert(Opc == Instruction::ICmp && "Unknown opcode for CmpInst!");
if (!LHS->getType()->isIntOrIntVector() &&
!isa<PointerType>(LHS->getType()))
return Error(Loc, "icmp requires integer operands");
- Inst = new ICmpInst(CmpInst::Predicate(Pred), LHS, RHS);
+ Inst = new ICmpInst(Context, CmpInst::Predicate(Pred), LHS, RHS);
}
return false;
}