llvm.org GIT mirror llvm / 70c2fc0
Discard metadata produced by LLVM 2.7. The value enumeration it used is different from what the code now uses in a two ways: NamedMDNodes were considered Values and included in the numbering, and the function-local metadata counter wasn't reset between functions. The later problem breaks lazy deserialization, so instead of trying to emulate the old numbering, just drop the old metadata. The only in-tree use case is debug info with LTO, where the QOI loss is considered acceptable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113557 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
4 changed file(s) with 72 addition(s) and 22 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
785785 Record.clear();
786786 Code = Stream.ReadCode();
787787
788 // METADATA_NAME is always followed by METADATA_NAMED_NODE.
789 if (Stream.ReadRecord(Code, Record) != bitc::METADATA_NAMED_NODE)
788 // METADATA_NAME is always followed by METADATA_NAMED_NODE2.
789 unsigned NextBitCode = Stream.ReadRecord(Code, Record);
790 // FIXME: LLVM 3.0: Remove this.
791 if (NextBitCode == bitc::METADATA_NAMED_NODE)
792 break;
793 if (NextBitCode != bitc::METADATA_NAMED_NODE2)
790794 assert ( 0 && "Inavlid Named Metadata record");
791795
792796 // Read named metadata elements.
801805 break;
802806 }
803807 case bitc::METADATA_FN_NODE:
808 // FIXME: Legacy support for the old fn_node, where function-local
809 // metadata operands were bogus. Remove in LLVM 3.0.
810 break;
811 case bitc::METADATA_NODE:
812 // FIXME: Legacy support for the old node, where function-local
813 // metadata operands were bogus. Remove in LLVM 3.0.
814 break;
815 case bitc::METADATA_FN_NODE2:
804816 IsFunctionLocal = true;
805817 // fall-through
806 case bitc::METADATA_NODE: {
818 case bitc::METADATA_NODE2: {
807819 if (Record.size() % 2 == 1)
808 return Error("Invalid METADATA_NODE record");
820 return Error("Invalid METADATA_NODE2 record");
809821
810822 unsigned Size = Record.size();
811823 SmallVector Elts;
15921604 switch (Stream.ReadRecord(Code, Record)) {
15931605 default: // Default behavior: ignore.
15941606 break;
1595 case bitc::METADATA_ATTACHMENT: {
1607 case bitc::METADATA_ATTACHMENT:
1608 // LLVM 3.0: Remove this.
1609 break;
1610 case bitc::METADATA_ATTACHMENT2: {
15961611 unsigned RecordLength = Record.size();
15971612 if (Record.empty() || (RecordLength - 1) % 2 == 1)
15981613 return Error ("Invalid METADATA_ATTACHMENT reader!");
17051720 I = 0;
17061721 continue;
17071722
1708 case bitc::FUNC_CODE_DEBUG_LOC: { // DEBUG_LOC: [line, col, scope, ia]
1723 case bitc::FUNC_CODE_DEBUG_LOC:
1724 // FIXME: Ignore. Remove this in LLVM 3.0.
1725 continue;
1726
1727 case bitc::FUNC_CODE_DEBUG_LOC2: { // DEBUG_LOC: [line, col, scope, ia]
17091728 I = 0; // Get the last instruction emitted.
17101729 if (CurBB && !CurBB->empty())
17111730 I = &CurBB->back();
22202239 InstructionList.push_back(I);
22212240 break;
22222241 }
2223 case bitc::FUNC_CODE_INST_CALL: {
2242 case bitc::FUNC_CODE_INST_CALL:
2243 case bitc::FUNC_CODE_INST_CALL2: {
2244 // FIXME: Legacy support for the old call instruction, where function-local
2245 // metadata operands were bogus. Remove in LLVM 3.0.
2246 bool DropMetadata = BitCode == bitc::FUNC_CODE_INST_CALL;
2247
22242248 // CALL: [paramattrs, cc, fnty, fnid, arg0, arg1...]
22252249 if (Record.size() < 3)
22262250 return Error("Invalid CALL record");
22442268 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
22452269 if (FTy->getParamType(i)->getTypeID()==Type::LabelTyID)
22462270 Args.push_back(getBasicBlock(Record[OpNum]));
2247 else
2271 else if (DropMetadata &&
2272 FTy->getParamType(i)->getTypeID()==Type::MetadataTyID) {
2273 // LLVM 2.7 compatibility: drop metadata arguments to null.
2274 Value *Ops = 0;
2275 Args.push_back(MDNode::get(Context, &Ops, 1));
2276 continue;
2277 } else
22482278 Args.push_back(getFnValueByID(Record[OpNum], FTy->getParamType(i)));
22492279 if (Args.back() == 0) return Error("Invalid CALL record");
22502280 }
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;
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 }