llvm.org GIT mirror llvm / a624524
Add special case bitcode support for DebugLoc. This avoids having the bitcode writer materialize mdnodes for all the debug location tuples when writing out the bc file and stores the information in a more compact form. For example, the -O0 -g bc file for combine.c in 176.gcc shrinks from 739392 to 512096 bytes. This concludes my planned short-term debug info work. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100261 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
5 changed file(s) with 91 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
239239 // new select on i1 or [N x i1]
240240 FUNC_CODE_INST_VSELECT = 29, // VSELECT: [ty,opval,opval,predty,pred]
241241 FUNC_CODE_INST_INBOUNDS_GEP= 30, // INBOUNDS_GEP: [n x operands]
242 FUNC_CODE_INST_INDIRECTBR = 31 // INDIRECTBR: [opty, op0, op1, ...]
242 FUNC_CODE_INST_INDIRECTBR = 31, // INDIRECTBR: [opty, op0, op1, ...]
243
244 FUNC_CODE_DEBUG_LOC = 32, // DEBUG_LOC: [Line,Col,ScopeVal, IAVal]
245 FUNC_CODE_DEBUG_LOC_AGAIN = 33 // DEBUG_LOC_AGAIN
243246 };
244247 } // End bitc namespace
245248 } // End llvm namespace
16431643 BasicBlock *CurBB = 0;
16441644 unsigned CurBBNo = 0;
16451645
1646 DebugLoc LastLoc;
1647
16461648 // Read all the records.
16471649 SmallVector Record;
16481650 while (1) {
16971699 FunctionBBs[i] = BasicBlock::Create(Context, "", F);
16981700 CurBB = FunctionBBs[0];
16991701 continue;
1702
1703
1704 case bitc::FUNC_CODE_DEBUG_LOC_AGAIN: // DEBUG_LOC_AGAIN
1705 // This record indicates that the last instruction is at the same
1706 // location as the previous instruction with a location.
1707 I = 0;
1708
1709 // Get the last instruction emitted.
1710 if (CurBB && !CurBB->empty())
1711 I = &CurBB->back();
1712 else if (CurBBNo && FunctionBBs[CurBBNo-1] &&
1713 !FunctionBBs[CurBBNo-1]->empty())
1714 I = &FunctionBBs[CurBBNo-1]->back();
1715
1716 if (I == 0) return Error("Invalid DEBUG_LOC_AGAIN record");
1717 I->setDebugLoc(LastLoc);
1718 I = 0;
1719 continue;
1720
1721 case bitc::FUNC_CODE_DEBUG_LOC: { // DEBUG_LOC: [line, col, scope, ia]
1722 I = 0; // Get the last instruction emitted.
1723 if (CurBB && !CurBB->empty())
1724 I = &CurBB->back();
1725 else if (CurBBNo && FunctionBBs[CurBBNo-1] &&
1726 !FunctionBBs[CurBBNo-1]->empty())
1727 I = &FunctionBBs[CurBBNo-1]->back();
1728 if (I == 0 || Record.size() < 4)
1729 return Error("Invalid FUNC_CODE_DEBUG_LOC record");
1730
1731 unsigned Line = Record[0], Col = Record[1];
1732 unsigned ScopeID = Record[2], IAID = Record[3];
1733
1734 MDNode *Scope = 0, *IA = 0;
1735 if (ScopeID) Scope = cast(MDValueList.getValueFwdRef(ScopeID-1));
1736 if (IAID) IA = cast(MDValueList.getValueFwdRef(IAID-1));
1737 LastLoc = DebugLoc::get(Line, Col, Scope, IA);
1738 I->setDebugLoc(LastLoc);
1739 I = 0;
1740 continue;
1741 }
17001742
17011743 case bitc::FUNC_CODE_INST_BINOP: { // BINOP: [opval, ty, opval, opcode]
17021744 unsigned OpNum = 0;
22842326
22852327 // See if anything took the address of blocks in this function. If so,
22862328 // resolve them now.
2287 /// BlockAddrFwdRefs - These are blockaddr references to basic blocks. These
2288 /// are resolved lazily when functions are loaded.
22892329 DenseMap >::iterator BAFRI =
22902330 BlockAddrFwdRefs.find(F);
22912331 if (BAFRI != BlockAddrFwdRefs.end()) {
595595 static void WriteMetadataAttachment(const Function &F,
596596 const ValueEnumerator &VE,
597597 BitstreamWriter &Stream) {
598 bool StartedMetadataBlock = false;
598 Stream.EnterSubblock(bitc::METADATA_ATTACHMENT_ID, 3);
599
599600 SmallVector Record;
600601
601602 // Write metadata attachments
606607 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
607608 I != E; ++I) {
608609 MDs.clear();
609 I->getAllMetadata(MDs);
610 I->getAllMetadataOtherThanDebugLoc(MDs);
610611
611612 // If no metadata, ignore instruction.
612613 if (MDs.empty()) continue;
617618 Record.push_back(MDs[i].first);
618619 Record.push_back(VE.getValueID(MDs[i].second));
619620 }
620 if (!StartedMetadataBlock) {
621 Stream.EnterSubblock(bitc::METADATA_ATTACHMENT_ID, 3);
622 StartedMetadataBlock = true;
623 }
624621 Stream.EmitRecord(bitc::METADATA_ATTACHMENT, Record, 0);
625622 Record.clear();
626623 }
627624
628 if (StartedMetadataBlock)
629 Stream.ExitBlock();
625 Stream.ExitBlock();
630626 }
631627
632628 static void WriteModuleMetadataStore(const Module *M, BitstreamWriter &Stream) {
12551251 // Keep a running idea of what the instruction ID is.
12561252 unsigned InstID = CstEnd;
12571253
1254 bool NeedsMetadataAttachment = false;
1255
1256 DebugLoc LastDL;
1257
12581258 // Finally, emit all the instructions, in order.
12591259 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
12601260 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
12611261 I != E; ++I) {
12621262 WriteInstruction(*I, InstID, VE, Stream, Vals);
1263
12631264 if (!I->getType()->isVoidTy())
12641265 ++InstID;
1266
1267 // If the instruction has metadata, write a metadata attachment later.
1268 NeedsMetadataAttachment |= I->hasMetadataOtherThanDebugLoc();
1269
1270 // If the instruction has a debug location, emit it.
1271 DebugLoc DL = I->getDebugLoc();
1272 if (DL.isUnknown()) {
1273 // nothing todo.
1274 } else if (DL == LastDL) {
1275 // Just repeat the same debug loc as last time.
1276 Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC_AGAIN, Vals);
1277 } else {
1278 MDNode *Scope, *IA;
1279 DL.getScopeAndInlinedAt(Scope, IA, I->getContext());
1280
1281 Vals.push_back(DL.getLine());
1282 Vals.push_back(DL.getCol());
1283 Vals.push_back(Scope ? VE.getValueID(Scope)+1 : 0);
1284 Vals.push_back(IA ? VE.getValueID(IA)+1 : 0);
1285 Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
1286 Vals.clear();
1287
1288 LastDL = DL;
1289 }
12651290 }
12661291
12671292 // Emit names for all the instructions etc.
12681293 WriteValueSymbolTable(F.getValueSymbolTable(), VE, Stream);
12691294
1270 WriteMetadataAttachment(F, VE, Stream);
1295 if (NeedsMetadataAttachment)
1296 WriteMetadataAttachment(F, VE, Stream);
12711297 VE.purgeFunction();
12721298 Stream.ExitBlock();
12731299 }
103103
104104 // Enumerate metadata attached with this instruction.
105105 MDs.clear();
106 I->getAllMetadata(MDs);
106 I->getAllMetadataOtherThanDebugLoc(MDs);
107107 for (unsigned i = 0, e = MDs.size(); i != e; ++i)
108108 EnumerateMetadata(MDs[i].second);
109
110 if (!I->getDebugLoc().isUnknown()) {
111 MDNode *Scope, *IA;
112 I->getDebugLoc().getScopeAndInlinedAt(Scope, IA, I->getContext());
113 if (Scope) EnumerateMetadata(Scope);
114 if (IA) EnumerateMetadata(IA);
115 }
109116 }
110117 }
111118
236236 case bitc::FUNC_CODE_INST_INSERTVAL: return "INST_INSERTVAL";
237237 case bitc::FUNC_CODE_INST_CMP2: return "INST_CMP2";
238238 case bitc::FUNC_CODE_INST_VSELECT: return "INST_VSELECT";
239 case bitc::FUNC_CODE_DEBUG_LOC: return "DEBUG_LOC";
240 case bitc::FUNC_CODE_DEBUG_LOC_AGAIN: return "DEBUG_LOC_AGAIN";
239241 }
240242 case bitc::TYPE_SYMTAB_BLOCK_ID:
241243 switch (CodeID) {