aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2010-09-14 20:59:01 +0000
committerBill Wendling <isanbard@gmail.com>2010-09-14 20:59:01 +0000
commit139d4669f1c34105b54e268a100511807c8ed063 (patch)
treec980bbc389be4b5374d90e35a77bcb01240d6cbd
parent02bf305a3f5879eddcb4bd1f3917e021349fc0c0 (diff)
Approved by Chris:
$ svn merge -c 113557 https://llvm.org/svn/llvm-project/llvm/trunk --- Merging r113557 into '.': U include/llvm/Bitcode/LLVMBitCodes.h U tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp U lib/Bitcode/Reader/BitcodeReader.cpp U lib/Bitcode/Writer/BitcodeWriter.cpp $ svn merge -c 113764 https://llvm.org/svn/llvm-project/llvm/trunk --- Merging r113764 into '.': U lib/Bitcode/Reader/BitcodeReader.h G lib/Bitcode/Reader/BitcodeReader.cpp $ svn merge -c 113828 https://llvm.org/svn/llvm-project/llvm/trunk --- Merging r113828 into '.': U lib/VMCore/Metadata.cpp git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_28@113853 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Bitcode/LLVMBitCodes.h28
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp61
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.h9
-rw-r--r--lib/Bitcode/Writer/BitcodeWriter.cpp14
-rw-r--r--lib/VMCore/Metadata.cpp18
-rw-r--r--tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp6
6 files changed, 111 insertions, 25 deletions
diff --git a/include/llvm/Bitcode/LLVMBitCodes.h b/include/llvm/Bitcode/LLVMBitCodes.h
index 942c032920..4f9b783aa9 100644
--- a/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/include/llvm/Bitcode/LLVMBitCodes.h
@@ -110,12 +110,20 @@ namespace bitc {
enum MetadataCodes {
METADATA_STRING = 1, // MDSTRING: [values]
- METADATA_NODE = 2, // MDNODE: [n x (type num, value num)]
- METADATA_FN_NODE = 3, // FN_MDNODE: [n x (type num, value num)]
+ // FIXME: Remove NODE in favor of NODE2 in LLVM 3.0
+ METADATA_NODE = 2, // NODE with potentially invalid metadata
+ // FIXME: Remove FN_NODE in favor of FN_NODE2 in LLVM 3.0
+ METADATA_FN_NODE = 3, // FN_NODE with potentially invalid metadata
METADATA_NAME = 4, // STRING: [values]
- METADATA_NAMED_NODE = 5, // NAMEDMDNODE: [n x mdnodes]
+ // FIXME: Remove NAMED_NODE in favor of NAMED_NODE2 in LLVM 3.0
+ METADATA_NAMED_NODE = 5, // NAMED_NODE with potentially invalid metadata
METADATA_KIND = 6, // [n x [id, name]]
- METADATA_ATTACHMENT = 7 // [m x [value, [n x [id, mdnode]]]
+ // FIXME: Remove ATTACHMENT in favor of ATTACHMENT2 in LLVM 3.0
+ METADATA_ATTACHMENT = 7, // ATTACHMENT with potentially invalid metadata
+ METADATA_NODE2 = 8, // NODE2: [n x (type num, value num)]
+ METADATA_FN_NODE2 = 9, // FN_NODE2: [n x (type num, value num)]
+ METADATA_NAMED_NODE2 = 10, // NAMED_NODE2: [n x mdnodes]
+ METADATA_ATTACHMENT2 = 11 // [m x [value, [n x [id, mdnode]]]
};
// The constants block (CONSTANTS_BLOCK_ID) describes emission for each
// constant and maintains an implicit current type value.
@@ -223,7 +231,8 @@ namespace bitc {
FUNC_CODE_INST_LOAD = 20, // LOAD: [opty, op, align, vol]
// FIXME: Remove STORE in favor of STORE2 in LLVM 3.0
FUNC_CODE_INST_STORE = 21, // STORE: [valty,val,ptr, align, vol]
- FUNC_CODE_INST_CALL = 22, // CALL: [attr, fnty, fnid, args...]
+ // FIXME: Remove CALL in favor of CALL2 in LLVM 3.0
+ FUNC_CODE_INST_CALL = 22, // CALL with potentially invalid metadata
FUNC_CODE_INST_VAARG = 23, // VAARG: [valistty, valist, instty]
// This store code encodes the pointer type, rather than the value type
// this is so information only available in the pointer type (e.g. address
@@ -241,8 +250,13 @@ namespace bitc {
FUNC_CODE_INST_INBOUNDS_GEP= 30, // INBOUNDS_GEP: [n x operands]
FUNC_CODE_INST_INDIRECTBR = 31, // INDIRECTBR: [opty, op0, op1, ...]
- FUNC_CODE_DEBUG_LOC = 32, // DEBUG_LOC: [Line,Col,ScopeVal, IAVal]
- FUNC_CODE_DEBUG_LOC_AGAIN = 33 // DEBUG_LOC_AGAIN
+ // FIXME: Remove DEBUG_LOC in favor of DEBUG_LOC2 in LLVM 3.0
+ FUNC_CODE_DEBUG_LOC = 32, // DEBUG_LOC with potentially invalid metadata
+ FUNC_CODE_DEBUG_LOC_AGAIN = 33, // DEBUG_LOC_AGAIN
+
+ FUNC_CODE_INST_CALL2 = 34, // CALL2: [attr, fnty, fnid, args...]
+
+ FUNC_CODE_DEBUG_LOC2 = 35 // DEBUG_LOC2: [Line,Col,ScopeVal, IAVal]
};
} // End bitc namespace
} // End llvm namespace
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index cb7f2f40c4..ee55ebbbc5 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -774,7 +774,8 @@ bool BitcodeReader::ParseMetadata() {
bool IsFunctionLocal = false;
// Read a record.
Record.clear();
- switch (Stream.ReadRecord(Code, Record)) {
+ Code = Stream.ReadRecord(Code, Record);
+ switch (Code) {
default: // Default behavior: ignore.
break;
case bitc::METADATA_NAME: {
@@ -787,8 +788,12 @@ bool BitcodeReader::ParseMetadata() {
Record.clear();
Code = Stream.ReadCode();
- // METADATA_NAME is always followed by METADATA_NAMED_NODE.
- if (Stream.ReadRecord(Code, Record) != bitc::METADATA_NAMED_NODE)
+ // METADATA_NAME is always followed by METADATA_NAMED_NODE2.
+ // Or METADATA_NAMED_NODE in LLVM 2.7. FIXME: Remove this in LLVM 3.0.
+ unsigned NextBitCode = Stream.ReadRecord(Code, Record);
+ if (NextBitCode == bitc::METADATA_NAMED_NODE) {
+ LLVM2_7MetadataDetected = true;
+ } else if (NextBitCode != bitc::METADATA_NAMED_NODE2)
assert ( 0 && "Inavlid Named Metadata record");
// Read named metadata elements.
@@ -800,14 +805,29 @@ bool BitcodeReader::ParseMetadata() {
return Error("Malformed metadata record");
NMD->addOperand(MD);
}
+ // Backwards compatibility hack: NamedMDValues used to be Values,
+ // and they got their own slots in the value numbering. They are no
+ // longer Values, however we still need to account for them in the
+ // numbering in order to be able to read old bitcode files.
+ // FIXME: Remove this in LLVM 3.0.
+ if (LLVM2_7MetadataDetected)
+ MDValueList.AssignValue(0, NextMDValueNo++);
break;
}
- case bitc::METADATA_FN_NODE:
+ case bitc::METADATA_FN_NODE: // FIXME: Remove in LLVM 3.0.
+ case bitc::METADATA_FN_NODE2:
IsFunctionLocal = true;
// fall-through
- case bitc::METADATA_NODE: {
+ case bitc::METADATA_NODE: // FIXME: Remove in LLVM 3.0.
+ case bitc::METADATA_NODE2: {
+
+ // Detect 2.7-era metadata.
+ // FIXME: Remove in LLVM 3.0.
+ if (Code == bitc::METADATA_FN_NODE || Code == bitc::METADATA_NODE)
+ LLVM2_7MetadataDetected = true;
+
if (Record.size() % 2 == 1)
- return Error("Invalid METADATA_NODE record");
+ return Error("Invalid METADATA_NODE2 record");
unsigned Size = Record.size();
SmallVector<Value*, 8> Elts;
@@ -1594,7 +1614,10 @@ bool BitcodeReader::ParseMetadataAttachment() {
switch (Stream.ReadRecord(Code, Record)) {
default: // Default behavior: ignore.
break;
- case bitc::METADATA_ATTACHMENT: {
+ // FIXME: Remove in LLVM 3.0.
+ case bitc::METADATA_ATTACHMENT:
+ LLVM2_7MetadataDetected = true;
+ case bitc::METADATA_ATTACHMENT2: {
unsigned RecordLength = Record.size();
if (Record.empty() || (RecordLength - 1) % 2 == 1)
return Error ("Invalid METADATA_ATTACHMENT reader!");
@@ -1707,7 +1730,10 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
I = 0;
continue;
- case bitc::FUNC_CODE_DEBUG_LOC: { // DEBUG_LOC: [line, col, scope, ia]
+ // FIXME: Remove this in LLVM 3.0.
+ case bitc::FUNC_CODE_DEBUG_LOC:
+ LLVM2_7MetadataDetected = true;
+ case bitc::FUNC_CODE_DEBUG_LOC2: { // DEBUG_LOC: [line, col, scope, ia]
I = 0; // Get the last instruction emitted.
if (CurBB && !CurBB->empty())
I = &CurBB->back();
@@ -2169,7 +2195,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
}
case bitc::FUNC_CODE_INST_ALLOCA: { // ALLOCA: [instty, opty, op, align]
// For backward compatibility, tolerate a lack of an opty, and use i32.
- // LLVM 3.0: Remove this.
+ // Remove this in LLVM 3.0.
if (Record.size() < 3 || Record.size() > 4)
return Error("Invalid ALLOCA record");
unsigned OpNum = 0;
@@ -2222,7 +2248,10 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
InstructionList.push_back(I);
break;
}
- case bitc::FUNC_CODE_INST_CALL: {
+ // FIXME: Remove this in LLVM 3.0.
+ case bitc::FUNC_CODE_INST_CALL:
+ LLVM2_7MetadataDetected = true;
+ case bitc::FUNC_CODE_INST_CALL2: {
// CALL: [paramattrs, cc, fnty, fnid, arg0, arg1...]
if (Record.size() < 3)
return Error("Invalid CALL record");
@@ -2341,9 +2370,21 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
BlockAddrFwdRefs.erase(BAFRI);
}
+ // FIXME: Remove this in LLVM 3.0.
+ unsigned NewMDValueListSize = MDValueList.size();
+
// Trim the value list down to the size it was before we parsed this function.
ValueList.shrinkTo(ModuleValueListSize);
MDValueList.shrinkTo(ModuleMDValueListSize);
+
+ // Backwards compatibility hack: Function-local metadata numbers
+ // were previously not reset between functions. This is now fixed,
+ // however we still need to understand the old numbering in order
+ // to be able to read old bitcode files.
+ // FIXME: Remove this in LLVM 3.0.
+ if (LLVM2_7MetadataDetected)
+ MDValueList.resize(NewMDValueListSize);
+
std::vector<BasicBlock*>().swap(FunctionBBs);
return false;
diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h
index a5ab5d29e9..053121bdad 100644
--- a/lib/Bitcode/Reader/BitcodeReader.h
+++ b/lib/Bitcode/Reader/BitcodeReader.h
@@ -173,11 +173,18 @@ class BitcodeReader : public GVMaterializer {
/// are resolved lazily when functions are loaded.
typedef std::pair<unsigned, GlobalVariable*> BlockAddrRefTy;
DenseMap<Function*, std::vector<BlockAddrRefTy> > BlockAddrFwdRefs;
+
+ /// LLVM2_7MetadataDetected - True if metadata produced by LLVM 2.7 or
+ /// earlier was detected, in which case we behave slightly differently,
+ /// for compatibility.
+ /// FIXME: Remove in LLVM 3.0.
+ bool LLVM2_7MetadataDetected;
public:
explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C)
: Context(C), TheModule(0), Buffer(buffer), BufferOwned(false),
- ErrorString(0), ValueList(C), MDValueList(C) {
+ ErrorString(0), ValueList(C), MDValueList(C),
+ LLVM2_7MetadataDetected(false) {
HasReversedFunctionsWithBodies = false;
}
~BitcodeReader() {
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp
index 07727f33d9..7b6fc6cd92 100644
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -485,8 +485,8 @@ static void WriteMDNode(const MDNode *N,
Record.push_back(0);
}
}
- unsigned MDCode = N->isFunctionLocal() ? bitc::METADATA_FN_NODE :
- bitc::METADATA_NODE;
+ unsigned MDCode = N->isFunctionLocal() ? bitc::METADATA_FN_NODE2 :
+ bitc::METADATA_NODE2;
Stream.EmitRecord(MDCode, Record, 0);
Record.clear();
}
@@ -549,7 +549,7 @@ static void WriteModuleMetadata(const Module *M,
// Write named metadata operands.
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
Record.push_back(VE.getValueID(NMD->getOperand(i)));
- Stream.EmitRecord(bitc::METADATA_NAMED_NODE, Record, 0);
+ Stream.EmitRecord(bitc::METADATA_NAMED_NODE2, Record, 0);
Record.clear();
}
@@ -585,7 +585,7 @@ static void WriteMetadataAttachment(const Function &F,
SmallVector<uint64_t, 64> Record;
// Write metadata attachments
- // METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]]
+ // METADATA_ATTACHMENT2 - [m x [value, [n x [id, mdnode]]]
SmallVector<std::pair<unsigned, MDNode*>, 4> MDs;
for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
@@ -603,7 +603,7 @@ static void WriteMetadataAttachment(const Function &F,
Record.push_back(MDs[i].first);
Record.push_back(VE.getValueID(MDs[i].second));
}
- Stream.EmitRecord(bitc::METADATA_ATTACHMENT, Record, 0);
+ Stream.EmitRecord(bitc::METADATA_ATTACHMENT2, Record, 0);
Record.clear();
}
@@ -1111,7 +1111,7 @@ static void WriteInstruction(const Instruction &I, unsigned InstID,
const PointerType *PTy = cast<PointerType>(CI.getCalledValue()->getType());
const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
- Code = bitc::FUNC_CODE_INST_CALL;
+ Code = bitc::FUNC_CODE_INST_CALL2;
Vals.push_back(VE.getAttributeID(CI.getAttributes()));
Vals.push_back((CI.getCallingConv() << 1) | unsigned(CI.isTailCall()));
@@ -1255,7 +1255,7 @@ static void WriteFunction(const Function &F, ValueEnumerator &VE,
Vals.push_back(DL.getCol());
Vals.push_back(Scope ? VE.getValueID(Scope)+1 : 0);
Vals.push_back(IA ? VE.getValueID(IA)+1 : 0);
- Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
+ Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC2, Vals);
Vals.clear();
LastDL = DL;
diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp
index b9f97dbf60..da69c43ff7 100644
--- a/lib/VMCore/Metadata.cpp
+++ b/lib/VMCore/Metadata.cpp
@@ -354,6 +354,22 @@ void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) {
// InsertPoint will have been set by the FindNodeOrInsertPos call.
pImpl->MDNodeSet.InsertNode(this, InsertPoint);
+
+ // If this MDValue was previously function-local but no longer is, clear
+ // its function-local flag.
+ if (isFunctionLocal() && !isFunctionLocalValue(To)) {
+ bool isStillFunctionLocal = false;
+ for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
+ Value *V = getOperand(i);
+ if (!V) continue;
+ if (isFunctionLocalValue(V)) {
+ isStillFunctionLocal = true;
+ break;
+ }
+ }
+ if (!isStillFunctionLocal)
+ setValueSubclassData(getSubclassDataFromValue() & ~FunctionLocalBit);
+ }
}
//===----------------------------------------------------------------------===//
@@ -387,6 +403,8 @@ MDNode *NamedMDNode::getOperand(unsigned i) const {
/// addOperand - Add metadata Operand.
void NamedMDNode::addOperand(MDNode *M) {
+ assert(!M->isFunctionLocal() &&
+ "NamedMDNode operands must not be function-local!");
getNMDOps(Operands).push_back(TrackingVH<MDNode>(M));
}
diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
index 80a8d74988..9c0d675793 100644
--- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
+++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
@@ -236,6 +236,8 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID,
case bitc::FUNC_CODE_INST_VSELECT: return "INST_VSELECT";
case bitc::FUNC_CODE_DEBUG_LOC: return "DEBUG_LOC";
case bitc::FUNC_CODE_DEBUG_LOC_AGAIN: return "DEBUG_LOC_AGAIN";
+ case bitc::FUNC_CODE_INST_CALL2: return "INST_CALL2";
+ case bitc::FUNC_CODE_DEBUG_LOC2: return "DEBUG_LOC2";
}
case bitc::TYPE_SYMTAB_BLOCK_ID:
switch (CodeID) {
@@ -263,6 +265,10 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID,
case bitc::METADATA_NAMED_NODE: return "METADATA_NAMED_NODE";
case bitc::METADATA_KIND: return "METADATA_KIND";
case bitc::METADATA_ATTACHMENT: return "METADATA_ATTACHMENT";
+ case bitc::METADATA_NODE2: return "METADATA_NODE2";
+ case bitc::METADATA_FN_NODE2: return "METADATA_FN_NODE2";
+ case bitc::METADATA_NAMED_NODE2: return "METADATA_NAMED_NODE2";
+ case bitc::METADATA_ATTACHMENT2: return "METADATA_ATTACHMENT2";
}
}
}