Add support for embedded metadata to LLVM. This introduces two new types of

Constant, MDString and MDNode which can only be used by globals with a name
that starts with "llvm." or as arguments to a function with the same naming
restriction.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68420 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nick Lewycky
2009-04-04 07:22:01 +00:00
parent 2cd1b777d7
commit 21cc4460ef
17 changed files with 518 additions and 9 deletions

View File

@ -286,10 +286,12 @@ void BitcodeReaderValueList::ResolveConstantForwardRefs() {
UserCS->getType()->isPacked());
} else if (isa<ConstantVector>(UserC)) {
NewC = ConstantVector::get(&NewOps[0], NewOps.size());
} else {
// Must be a constant expression.
} else if (isa<ConstantExpr>(UserC)) {
NewC = cast<ConstantExpr>(UserC)->getWithOperands(&NewOps[0],
NewOps.size());
} else {
assert(isa<MDNode>(UserC) && "Must be a metadata node.");
NewC = MDNode::get(&NewOps[0], NewOps.size());
}
UserC->replaceAllUsesWith(NewC);
@ -999,6 +1001,29 @@ bool BitcodeReader::ParseConstants() {
AsmStr, ConstrStr, HasSideEffects);
break;
}
case bitc::CST_CODE_MDSTRING: {
if (Record.size() < 2) return Error("Invalid MDSTRING record");
unsigned MDStringLength = Record.size();
SmallString<8> String;
String.resize(MDStringLength);
for (unsigned i = 0; i != MDStringLength; ++i)
String[i] = Record[i];
V = MDString::get(String.c_str(), String.c_str() + MDStringLength);
break;
}
case bitc::CST_CODE_MDNODE: {
if (Record.empty() || Record.size() % 2 == 1)
return Error("Invalid CST_MDNODE record");
unsigned Size = Record.size();
SmallVector<Constant*, 8> Elts;
for (unsigned i = 0; i != Size; i += 2) {
const Type *Ty = getTypeByID(Record[i], false);
Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], Ty));
}
V = MDNode::get(&Elts[0], Elts.size());
break;
}
}
ValueList.AssignValue(V, NextCstNo);