llvm.org GIT mirror llvm / 139d466
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 Bill Wendling 9 years ago
6 changed file(s) with 113 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
109109
110110 enum MetadataCodes {
111111 METADATA_STRING = 1, // MDSTRING: [values]
112 METADATA_NODE = 2, // MDNODE: [n x (type num, value num)]
113 METADATA_FN_NODE = 3, // FN_MDNODE: [n x (type num, value num)]
112 // FIXME: Remove NODE in favor of NODE2 in LLVM 3.0
113 METADATA_NODE = 2, // NODE with potentially invalid metadata
114 // FIXME: Remove FN_NODE in favor of FN_NODE2 in LLVM 3.0
115 METADATA_FN_NODE = 3, // FN_NODE with potentially invalid metadata
114116 METADATA_NAME = 4, // STRING: [values]
115 METADATA_NAMED_NODE = 5, // NAMEDMDNODE: [n x mdnodes]
117 // FIXME: Remove NAMED_NODE in favor of NAMED_NODE2 in LLVM 3.0
118 METADATA_NAMED_NODE = 5, // NAMED_NODE with potentially invalid metadata
116119 METADATA_KIND = 6, // [n x [id, name]]
117 METADATA_ATTACHMENT = 7 // [m x [value, [n x [id, mdnode]]]
120 // FIXME: Remove ATTACHMENT in favor of ATTACHMENT2 in LLVM 3.0
121 METADATA_ATTACHMENT = 7, // ATTACHMENT with potentially invalid metadata
122 METADATA_NODE2 = 8, // NODE2: [n x (type num, value num)]
123 METADATA_FN_NODE2 = 9, // FN_NODE2: [n x (type num, value num)]
124 METADATA_NAMED_NODE2 = 10, // NAMED_NODE2: [n x mdnodes]
125 METADATA_ATTACHMENT2 = 11 // [m x [value, [n x [id, mdnode]]]
118126 };
119127 // The constants block (CONSTANTS_BLOCK_ID) describes emission for each
120128 // constant and maintains an implicit current type value.
222230 FUNC_CODE_INST_LOAD = 20, // LOAD: [opty, op, align, vol]
223231 // FIXME: Remove STORE in favor of STORE2 in LLVM 3.0
224232 FUNC_CODE_INST_STORE = 21, // STORE: [valty,val,ptr, align, vol]
225 FUNC_CODE_INST_CALL = 22, // CALL: [attr, fnty, fnid, args...]
233 // FIXME: Remove CALL in favor of CALL2 in LLVM 3.0
234 FUNC_CODE_INST_CALL = 22, // CALL with potentially invalid metadata
226235 FUNC_CODE_INST_VAARG = 23, // VAARG: [valistty, valist, instty]
227236 // This store code encodes the pointer type, rather than the value type
228237 // this is so information only available in the pointer type (e.g. address
240249 FUNC_CODE_INST_INBOUNDS_GEP= 30, // INBOUNDS_GEP: [n x operands]
241250 FUNC_CODE_INST_INDIRECTBR = 31, // INDIRECTBR: [opty, op0, op1, ...]
242251
243 FUNC_CODE_DEBUG_LOC = 32, // DEBUG_LOC: [Line,Col,ScopeVal, IAVal]
244 FUNC_CODE_DEBUG_LOC_AGAIN = 33 // DEBUG_LOC_AGAIN
252 // FIXME: Remove DEBUG_LOC in favor of DEBUG_LOC2 in LLVM 3.0
253 FUNC_CODE_DEBUG_LOC = 32, // DEBUG_LOC with potentially invalid metadata
254 FUNC_CODE_DEBUG_LOC_AGAIN = 33, // DEBUG_LOC_AGAIN
255
256 FUNC_CODE_INST_CALL2 = 34, // CALL2: [attr, fnty, fnid, args...]
257
258 FUNC_CODE_DEBUG_LOC2 = 35 // DEBUG_LOC2: [Line,Col,ScopeVal, IAVal]
245259 };
246260 } // End bitc namespace
247261 } // End llvm namespace
773773 bool IsFunctionLocal = false;
774774 // Read a record.
775775 Record.clear();
776 switch (Stream.ReadRecord(Code, Record)) {
776 Code = Stream.ReadRecord(Code, Record);
777 switch (Code) {
777778 default: // Default behavior: ignore.
778779 break;
779780 case bitc::METADATA_NAME: {
786787 Record.clear();
787788 Code = Stream.ReadCode();
788789
789 // METADATA_NAME is always followed by METADATA_NAMED_NODE.
790 if (Stream.ReadRecord(Code, Record) != bitc::METADATA_NAMED_NODE)
790 // METADATA_NAME is always followed by METADATA_NAMED_NODE2.
791 // Or METADATA_NAMED_NODE in LLVM 2.7. FIXME: Remove this in LLVM 3.0.
792 unsigned NextBitCode = Stream.ReadRecord(Code, Record);
793 if (NextBitCode == bitc::METADATA_NAMED_NODE) {
794 LLVM2_7MetadataDetected = true;
795 } else if (NextBitCode != bitc::METADATA_NAMED_NODE2)
791796 assert ( 0 && "Inavlid Named Metadata record");
792797
793798 // Read named metadata elements.
799804 return Error("Malformed metadata record");
800805 NMD->addOperand(MD);
801806 }
802 break;
803 }
804 case bitc::METADATA_FN_NODE:
807 // Backwards compatibility hack: NamedMDValues used to be Values,
808 // and they got their own slots in the value numbering. They are no
809 // longer Values, however we still need to account for them in the
810 // numbering in order to be able to read old bitcode files.
811 // FIXME: Remove this in LLVM 3.0.
812 if (LLVM2_7MetadataDetected)
813 MDValueList.AssignValue(0, NextMDValueNo++);
814 break;
815 }
816 case bitc::METADATA_FN_NODE: // FIXME: Remove in LLVM 3.0.
817 case bitc::METADATA_FN_NODE2:
805818 IsFunctionLocal = true;
806819 // fall-through
807 case bitc::METADATA_NODE: {
820 case bitc::METADATA_NODE: // FIXME: Remove in LLVM 3.0.
821 case bitc::METADATA_NODE2: {
822
823 // Detect 2.7-era metadata.
824 // FIXME: Remove in LLVM 3.0.
825 if (Code == bitc::METADATA_FN_NODE || Code == bitc::METADATA_NODE)
826 LLVM2_7MetadataDetected = true;
827
808828 if (Record.size() % 2 == 1)
809 return Error("Invalid METADATA_NODE record");
829 return Error("Invalid METADATA_NODE2 record");
810830
811831 unsigned Size = Record.size();
812832 SmallVector Elts;
15931613 switch (Stream.ReadRecord(Code, Record)) {
15941614 default: // Default behavior: ignore.
15951615 break;
1596 case bitc::METADATA_ATTACHMENT: {
1616 // FIXME: Remove in LLVM 3.0.
1617 case bitc::METADATA_ATTACHMENT:
1618 LLVM2_7MetadataDetected = true;
1619 case bitc::METADATA_ATTACHMENT2: {
15971620 unsigned RecordLength = Record.size();
15981621 if (Record.empty() || (RecordLength - 1) % 2 == 1)
15991622 return Error ("Invalid METADATA_ATTACHMENT reader!");
17061729 I = 0;
17071730 continue;
17081731
1709 case bitc::FUNC_CODE_DEBUG_LOC: { // DEBUG_LOC: [line, col, scope, ia]
1732 // FIXME: Remove this in LLVM 3.0.
1733 case bitc::FUNC_CODE_DEBUG_LOC:
1734 LLVM2_7MetadataDetected = true;
1735 case bitc::FUNC_CODE_DEBUG_LOC2: { // DEBUG_LOC: [line, col, scope, ia]
17101736 I = 0; // Get the last instruction emitted.
17111737 if (CurBB && !CurBB->empty())
17121738 I = &CurBB->back();
21682194 }
21692195 case bitc::FUNC_CODE_INST_ALLOCA: { // ALLOCA: [instty, opty, op, align]
21702196 // For backward compatibility, tolerate a lack of an opty, and use i32.
2171 // LLVM 3.0: Remove this.
2197 // Remove this in LLVM 3.0.
21722198 if (Record.size() < 3 || Record.size() > 4)
21732199 return Error("Invalid ALLOCA record");
21742200 unsigned OpNum = 0;
22212247 InstructionList.push_back(I);
22222248 break;
22232249 }
2224 case bitc::FUNC_CODE_INST_CALL: {
2250 // FIXME: Remove this in LLVM 3.0.
2251 case bitc::FUNC_CODE_INST_CALL:
2252 LLVM2_7MetadataDetected = true;
2253 case bitc::FUNC_CODE_INST_CALL2: {
22252254 // CALL: [paramattrs, cc, fnty, fnid, arg0, arg1...]
22262255 if (Record.size() < 3)
22272256 return Error("Invalid CALL record");
23402369 BlockAddrFwdRefs.erase(BAFRI);
23412370 }
23422371
2372 // FIXME: Remove this in LLVM 3.0.
2373 unsigned NewMDValueListSize = MDValueList.size();
2374
23432375 // Trim the value list down to the size it was before we parsed this function.
23442376 ValueList.shrinkTo(ModuleValueListSize);
23452377 MDValueList.shrinkTo(ModuleMDValueListSize);
2378
2379 // Backwards compatibility hack: Function-local metadata numbers
2380 // were previously not reset between functions. This is now fixed,
2381 // however we still need to understand the old numbering in order
2382 // to be able to read old bitcode files.
2383 // FIXME: Remove this in LLVM 3.0.
2384 if (LLVM2_7MetadataDetected)
2385 MDValueList.resize(NewMDValueListSize);
2386
23462387 std::vector().swap(FunctionBBs);
23472388
23482389 return false;
172172 /// are resolved lazily when functions are loaded.
173173 typedef std::pair BlockAddrRefTy;
174174 DenseMap > BlockAddrFwdRefs;
175
176 /// LLVM2_7MetadataDetected - True if metadata produced by LLVM 2.7 or
177 /// earlier was detected, in which case we behave slightly differently,
178 /// for compatibility.
179 /// FIXME: Remove in LLVM 3.0.
180 bool LLVM2_7MetadataDetected;
175181
176182 public:
177183 explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C)
178184 : Context(C), TheModule(0), Buffer(buffer), BufferOwned(false),
179 ErrorString(0), ValueList(C), MDValueList(C) {
185 ErrorString(0), ValueList(C), MDValueList(C),
186 LLVM2_7MetadataDetected(false) {
180187 HasReversedFunctionsWithBodies = false;
181188 }
182189 ~BitcodeReader() {
484484 Record.push_back(0);
485485 }
486486 }
487 unsigned MDCode = N->isFunctionLocal() ? bitc::METADATA_FN_NODE :
488 bitc::METADATA_NODE;
487 unsigned MDCode = N->isFunctionLocal() ? bitc::METADATA_FN_NODE2 :
488 bitc::METADATA_NODE2;
489489 Stream.EmitRecord(MDCode, Record, 0);
490490 Record.clear();
491491 }
548548 // Write named metadata operands.
549549 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
550550 Record.push_back(VE.getValueID(NMD->getOperand(i)));
551 Stream.EmitRecord(bitc::METADATA_NAMED_NODE, Record, 0);
551 Stream.EmitRecord(bitc::METADATA_NAMED_NODE2, Record, 0);
552552 Record.clear();
553553 }
554554
584584 SmallVector Record;
585585
586586 // Write metadata attachments
587 // METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]]
587 // METADATA_ATTACHMENT2 - [m x [value, [n x [id, mdnode]]]
588588 SmallVector, 4> MDs;
589589
590590 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
602602 Record.push_back(MDs[i].first);
603603 Record.push_back(VE.getValueID(MDs[i].second));
604604 }
605 Stream.EmitRecord(bitc::METADATA_ATTACHMENT, Record, 0);
605 Stream.EmitRecord(bitc::METADATA_ATTACHMENT2, Record, 0);
606606 Record.clear();
607607 }
608608
11101110 const PointerType *PTy = cast(CI.getCalledValue()->getType());
11111111 const FunctionType *FTy = cast(PTy->getElementType());
11121112
1113 Code = bitc::FUNC_CODE_INST_CALL;
1113 Code = bitc::FUNC_CODE_INST_CALL2;
11141114
11151115 Vals.push_back(VE.getAttributeID(CI.getAttributes()));
11161116 Vals.push_back((CI.getCallingConv() << 1) | unsigned(CI.isTailCall()));
12541254 Vals.push_back(DL.getCol());
12551255 Vals.push_back(Scope ? VE.getValueID(Scope)+1 : 0);
12561256 Vals.push_back(IA ? VE.getValueID(IA)+1 : 0);
1257 Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
1257 Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC2, Vals);
12581258 Vals.clear();
12591259
12601260 LastDL = DL;
353353
354354 // InsertPoint will have been set by the FindNodeOrInsertPos call.
355355 pImpl->MDNodeSet.InsertNode(this, InsertPoint);
356
357 // If this MDValue was previously function-local but no longer is, clear
358 // its function-local flag.
359 if (isFunctionLocal() && !isFunctionLocalValue(To)) {
360 bool isStillFunctionLocal = false;
361 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
362 Value *V = getOperand(i);
363 if (!V) continue;
364 if (isFunctionLocalValue(V)) {
365 isStillFunctionLocal = true;
366 break;
367 }
368 }
369 if (!isStillFunctionLocal)
370 setValueSubclassData(getSubclassDataFromValue() & ~FunctionLocalBit);
371 }
356372 }
357373
358374 //===----------------------------------------------------------------------===//
386402
387403 /// addOperand - Add metadata Operand.
388404 void NamedMDNode::addOperand(MDNode *M) {
405 assert(!M->isFunctionLocal() &&
406 "NamedMDNode operands must not be function-local!");
389407 getNMDOps(Operands).push_back(TrackingVH(M));
390408 }
391409
235235 case bitc::FUNC_CODE_INST_VSELECT: return "INST_VSELECT";
236236 case bitc::FUNC_CODE_DEBUG_LOC: return "DEBUG_LOC";
237237 case bitc::FUNC_CODE_DEBUG_LOC_AGAIN: return "DEBUG_LOC_AGAIN";
238 case bitc::FUNC_CODE_INST_CALL2: return "INST_CALL2";
239 case bitc::FUNC_CODE_DEBUG_LOC2: return "DEBUG_LOC2";
238240 }
239241 case bitc::TYPE_SYMTAB_BLOCK_ID:
240242 switch (CodeID) {
262264 case bitc::METADATA_NAMED_NODE: return "METADATA_NAMED_NODE";
263265 case bitc::METADATA_KIND: return "METADATA_KIND";
264266 case bitc::METADATA_ATTACHMENT: return "METADATA_ATTACHMENT";
267 case bitc::METADATA_NODE2: return "METADATA_NODE2";
268 case bitc::METADATA_FN_NODE2: return "METADATA_FN_NODE2";
269 case bitc::METADATA_NAMED_NODE2: return "METADATA_NAMED_NODE2";
270 case bitc::METADATA_ATTACHMENT2: return "METADATA_ATTACHMENT2";
265271 }
266272 }
267273 }