llvm.org GIT mirror llvm / d7bb295
Beginning of the Great Exception Handling Rewrite. * Add a "landing pad" attribute to the BasicBlock. * Modify the bitcode reader and writer to handle said attribute. Later: The verifier will ensure that the landing pad attribute is used in the appropriate manner. I.e., not applied to the entry block, and applied only to basic blocks that are branched to via a `dispatch' instruction. (This is a work-in-progress.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129235 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 9 years ago
10 changed file(s) with 87 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
7373 private:
7474 InstListType InstList;
7575 Function *Parent;
76 bool IsLandingPad;
7677
7778 void setParent(Function *parent);
7879 friend class SymbolTableListTraits;
137138 return const_cast(this)->getFirstNonPHIOrDbg();
138139 }
139140
141 /// isLandingPad - True if this basic block is a landing pad for exception
142 /// handling.
143 bool isLandingPad() const { return IsLandingPad; }
144 void setIsLandingPad(bool Val = true) { IsLandingPad = Val; }
145
140146 /// removeFromParent - This method unlinks 'this' from the containing
141147 /// function, but does not delete it.
142148 ///
105105
106106 // The value symbol table only has one code (VST_ENTRY_CODE).
107107 enum ValueSymtabCodes {
108 VST_CODE_ENTRY = 1, // VST_ENTRY: [valid, namechar x N]
109 VST_CODE_BBENTRY = 2 // VST_BBENTRY: [bbid, namechar x N]
108 VST_CODE_ENTRY = 1, // VST_ENTRY: [valid, namechar x N]
109 VST_CODE_BBENTRY = 2, // VST_BBENTRY: [bbid, namechar x N]
110 VST_CODE_LPADENTRY = 3 // VST_LPADENTRY: [lpadid, namechar x N]
110111 };
111112
112113 enum MetadataCodes {
586586
587587 KEYWORD(x);
588588 KEYWORD(blockaddress);
589
590 KEYWORD(landingpad);
589591 #undef KEYWORD
590592
591593 // Keywords for types.
29172917 BasicBlock *BB = PFS.DefineBB(Name, NameLoc);
29182918 if (BB == 0) return true;
29192919
2920 if (Lex.getKind() == lltok::kw_landingpad) {
2921 BB->setIsLandingPad();
2922 Lex.Lex();
2923 }
2924
29202925 std::string NameStr;
29212926
29222927 // Parse the instructions in this block until we get a terminator.
124124 kw_extractelement, kw_insertelement, kw_shufflevector, kw_getresult,
125125 kw_extractvalue, kw_insertvalue, kw_blockaddress,
126126
127 // Basic block attribute.
128 kw_landingpad,
129
127130 // Unsigned Valued tokens (UIntVal).
128131 GlobalID, // @42
129132 LocalVarID, // %42
713713
714714 // Read a record.
715715 Record.clear();
716 switch (Stream.ReadRecord(Code, Record)) {
716 unsigned VSTCode = Stream.ReadRecord(Code, Record);
717 switch (VSTCode) {
717718 default: // Default behavior: unknown type.
718719 break;
719720 case bitc::VST_CODE_ENTRY: { // VST_ENTRY: [valueid, namechar x N]
728729 ValueName.clear();
729730 break;
730731 }
731 case bitc::VST_CODE_BBENTRY: {
732 case bitc::VST_CODE_BBENTRY:
733 case bitc::VST_CODE_LPADENTRY: {
732734 if (ConvertToString(Record, 1, ValueName))
733735 return Error("Invalid VST_BBENTRY record");
734736 BasicBlock *BB = getBasicBlock(Record[0]);
735737 if (BB == 0)
736738 return Error("Invalid BB ID in VST_BBENTRY record");
739
740 if (VSTCode == bitc::VST_CODE_LPADENTRY)
741 BB->setIsLandingPad(true);
737742
738743 BB->setName(StringRef(ValueName.data(), ValueName.size()));
739744 ValueName.clear();
3939 VST_ENTRY_7_ABBREV,
4040 VST_ENTRY_6_ABBREV,
4141 VST_BBENTRY_6_ABBREV,
42 VST_LPADENTRY_6_ABBREV,
4243
4344 // CONSTANTS_BLOCK abbrev id's.
4445 CONSTANTS_SETTYPE_ABBREV = bitc::FIRST_APPLICATION_ABBREV,
11781179
11791180 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
11801181
1181 // VST_ENTRY: [valueid, namechar x N]
1182 // VST_BBENTRY: [bbid, namechar x N]
1182 // VST_ENTRY: [valueid, namechar x N]
1183 // VST_BBENTRY: [bbid, namechar x N]
1184 // VST_LPADENTRY: [lpadid, namechar x N]
11831185 unsigned Code;
1184 if (isa(SI->getValue())) {
1185 Code = bitc::VST_CODE_BBENTRY;
1186 if (isChar6)
1187 AbbrevToUse = VST_BBENTRY_6_ABBREV;
1186 if (const BasicBlock *BB = dyn_cast(SI->getValue())) {
1187 if (BB->isLandingPad()) {
1188 Code = bitc::VST_CODE_LPADENTRY;
1189 if (isChar6)
1190 AbbrevToUse = VST_LPADENTRY_6_ABBREV;
1191 } else {
1192 Code = bitc::VST_CODE_BBENTRY;
1193 if (isChar6)
1194 AbbrevToUse = VST_BBENTRY_6_ABBREV;
1195 }
11881196 } else {
11891197 Code = bitc::VST_CODE_ENTRY;
11901198 if (isChar6)
13651373 Abbv) != VST_BBENTRY_6_ABBREV)
13661374 llvm_unreachable("Unexpected abbrev ordering!");
13671375 }
1368
1369
1376 { // 6-bit char6 VST_LPADENTRY strings.
1377 BitCodeAbbrev *Abbv = new BitCodeAbbrev();
1378 Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_LPADENTRY));
1379 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
1380 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1381 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
1382 if (Stream.EmitBlockInfoAbbrev(bitc::VALUE_SYMTAB_BLOCK_ID,
1383 Abbv) != VST_LPADENTRY_6_ABBREV)
1384 llvm_unreachable("Unexpected abbrev ordering!");
1385 }
13701386
13711387 { // SETTYPE abbrev for CONSTANTS_BLOCK.
13721388 BitCodeAbbrev *Abbv = new BitCodeAbbrev();
16861686 Out << "\n";
16871687 PrintLLVMName(Out, BB->getName(), LabelPrefix);
16881688 Out << ':';
1689 if (BB->isLandingPad())
1690 Out << " landingpad";
16891691 } else if (!BB->use_empty()) { // Don't print block # of no uses...
1690 Out << "\n; ;
1692 Out << '\n';
1693 if (BB->isLandingPad())
1694 Out << "landingpad ";
1695 Out << ";
16911696 int Slot = Machine.getLocalSlot(BB);
16921697 if (Slot != -1)
16931698 Out << Slot;
3737 // are not in the public header file...
3838 template class llvm::SymbolTableListTraits;
3939
40
4140 BasicBlock::BasicBlock(LLVMContext &C, const Twine &Name, Function *NewParent,
4241 BasicBlock *InsertBefore)
43 : Value(Type::getLabelTy(C), Value::BasicBlockVal), Parent(0) {
42 : Value(Type::getLabelTy(C), Value::BasicBlockVal), Parent(0),
43 IsLandingPad(false) {
4444
4545 // Make sure that we get added to a function
4646 LeakDetector::addGarbageObject(this);
5555
5656 setName(Name);
5757 }
58
5958
6059 BasicBlock::~BasicBlock() {
6160 // If the address of the block is taken and it is being deleted (e.g. because
0 ; RUN: llvm-as < %s | llvm-dis > %t1.ll
1 ; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
2 ; RUN: diff %t1.ll %t2.ll
3
4 ; Test for basic block attributes.
5
6 define i32 @f1(i32 %a) {
7 entry:
8 %cmp = icmp slt i32 %a, 37
9 br i1 %cmp, label %bb, label %lpad
10
11 bb:
12 ret i32 37
13
14 lpad: landingpad
15 ret i32 927
16 }
17
18 define i32 @f2(i32 %a) {
19 ; entry : 0
20 %1 = icmp slt i32 %a, 37
21 br i1 %1, label %2, label %3
22
23 ; bb : 2
24 ret i32 37
25
26 landingpad ; bb : 3
27 ret i32 927
28 }