llvm.org GIT mirror llvm / 772fe17
Merge the contents from exception-handling-rewrite to the mainline. This adds the new instructions 'landingpad' and 'resume'. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136253 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 9 years ago
27 changed file(s) with 743 addition(s) and 107 deletion(s). Raw diff Collapse all Expand all
122122
  • 'indirectbr' Instruction
  • 123123
  • 'invoke' Instruction
  • 124124
  • 'unwind' Instruction
  • 125
  • 'resume' Instruction
  • 125126
  • 'unreachable' Instruction
  • 126127
    127128
    29412942 control flow, not values (the one exception being the
    29422943 'invoke' instruction).

    29432944
    2944

    There are seven different terminator instructions: the

    2945

    There are eight different terminator instructions: the

    29452946 'ret' instruction, the
    29462947 'br' instruction, the
    29472948 'switch' instruction, the
    29482949 ''indirectbr' Instruction, the
    29492950 'invoke' instruction, the
    2950 'unwind' instruction, and the
    2951 'unwind' instruction, the
    2952 'resume' instruction, and the
    29512953 'unreachable' instruction.

    29522954
    29532955
    32653267
    32663268

    Note that the code generator does not yet completely support unwind, and

    32673269 that the invoke/unwind semantics are likely to change in future versions.

    3270
    3271
    3272
    3273
    3274
    3275

    3276 'resume' Instruction
    3277
    3278
    3279
    3280
    3281
    Syntax:
    3282
    
                      
                    
    3283 resume <type> <value>
    3284
    3285
    3286
    Overview:
    3287

    The 'resume' instruction is a terminator instruction that has no

    3288 successors. Its operand must have the same type as the result of any
    3289 'landingpad' instruction in the same function.

    3290
    3291
    Semantics:
    3292

    The 'resume' instruction resumes propagation of an existing

    3293 (in-flight) exception.

    3294
    3295
    Example:
    3296
    
                      
                    
    3297 resume { i8*, i32 } %exn
    3298
    32683299
    32693300
    32703301
    256256 FUNC_CODE_INST_UNREACHABLE = 15, // UNREACHABLE
    257257
    258258 FUNC_CODE_INST_PHI = 16, // PHI: [ty, val0,bb0, ...]
    259 // 17 is unused.
    259 FUNC_CODE_INST_RESUME = 17, // RESUME: [opval]
    260260 // 18 is unused.
    261261 FUNC_CODE_INST_ALLOCA = 19, // ALLOCA: [instty, op, align]
    262262 FUNC_CODE_INST_LOAD = 20, // LOAD: [opty, op, align, vol]
    283283 FUNC_CODE_INST_CALL = 34, // CALL: [attr, fnty, fnid, args...]
    284284
    285285 FUNC_CODE_DEBUG_LOC = 35, // DEBUG_LOC: [Line,Col,ScopeVal, IAVal]
    286 FUNC_CODE_INST_FENCE = 36 // FENCE: [ordering, synchscope]
    286 FUNC_CODE_INST_FENCE = 36, // FENCE: [ordering, synchscope]
    287 FUNC_CODE_INST_LANDINGPAD = 37 // LANDINGPAD: [ty,val,val,num,id0,val0...]
    287288 };
    288289 } // End bitc namespace
    289290 } // End llvm namespace
    9999 HANDLE_TERM_INST ( 4, IndirectBr , IndirectBrInst)
    100100 HANDLE_TERM_INST ( 5, Invoke , InvokeInst)
    101101 HANDLE_TERM_INST ( 6, Unwind , UnwindInst)
    102 HANDLE_TERM_INST ( 7, Unreachable, UnreachableInst)
    103 LAST_TERM_INST ( 7)
    102 HANDLE_TERM_INST ( 7, Resume , ResumeInst)
    103 HANDLE_TERM_INST ( 8, Unreachable, UnreachableInst)
    104 LAST_TERM_INST ( 8)
    104105
    105106 // Standard binary operators...
    106 FIRST_BINARY_INST( 8)
    107 HANDLE_BINARY_INST( 8, Add , BinaryOperator)
    108 HANDLE_BINARY_INST( 9, FAdd , BinaryOperator)
    109 HANDLE_BINARY_INST(10, Sub , BinaryOperator)
    110 HANDLE_BINARY_INST(11, FSub , BinaryOperator)
    111 HANDLE_BINARY_INST(12, Mul , BinaryOperator)
    112 HANDLE_BINARY_INST(13, FMul , BinaryOperator)
    113 HANDLE_BINARY_INST(14, UDiv , BinaryOperator)
    114 HANDLE_BINARY_INST(15, SDiv , BinaryOperator)
    115 HANDLE_BINARY_INST(16, FDiv , BinaryOperator)
    116 HANDLE_BINARY_INST(17, URem , BinaryOperator)
    117 HANDLE_BINARY_INST(18, SRem , BinaryOperator)
    118 HANDLE_BINARY_INST(19, FRem , BinaryOperator)
    107 FIRST_BINARY_INST( 9)
    108 HANDLE_BINARY_INST( 9, Add , BinaryOperator)
    109 HANDLE_BINARY_INST(10, FAdd , BinaryOperator)
    110 HANDLE_BINARY_INST(11, Sub , BinaryOperator)
    111 HANDLE_BINARY_INST(12, FSub , BinaryOperator)
    112 HANDLE_BINARY_INST(13, Mul , BinaryOperator)
    113 HANDLE_BINARY_INST(14, FMul , BinaryOperator)
    114 HANDLE_BINARY_INST(15, UDiv , BinaryOperator)
    115 HANDLE_BINARY_INST(16, SDiv , BinaryOperator)
    116 HANDLE_BINARY_INST(17, FDiv , BinaryOperator)
    117 HANDLE_BINARY_INST(18, URem , BinaryOperator)
    118 HANDLE_BINARY_INST(19, SRem , BinaryOperator)
    119 HANDLE_BINARY_INST(20, FRem , BinaryOperator)
    119120
    120121 // Logical operators (integer operands)
    121 HANDLE_BINARY_INST(20, Shl , BinaryOperator) // Shift left (logical)
    122 HANDLE_BINARY_INST(21, LShr , BinaryOperator) // Shift right (logical)
    123 HANDLE_BINARY_INST(22, AShr , BinaryOperator) // Shift right (arithmetic)
    124 HANDLE_BINARY_INST(23, And , BinaryOperator)
    125 HANDLE_BINARY_INST(24, Or , BinaryOperator)
    126 HANDLE_BINARY_INST(25, Xor , BinaryOperator)
    127 LAST_BINARY_INST(25)
    122 HANDLE_BINARY_INST(21, Shl , BinaryOperator) // Shift left (logical)
    123 HANDLE_BINARY_INST(22, LShr , BinaryOperator) // Shift right (logical)
    124 HANDLE_BINARY_INST(23, AShr , BinaryOperator) // Shift right (arithmetic)
    125 HANDLE_BINARY_INST(24, And , BinaryOperator)
    126 HANDLE_BINARY_INST(25, Or , BinaryOperator)
    127 HANDLE_BINARY_INST(26, Xor , BinaryOperator)
    128 LAST_BINARY_INST(26)
    128129
    129130 // Memory operators...
    130 FIRST_MEMORY_INST(26)
    131 HANDLE_MEMORY_INST(26, Alloca, AllocaInst) // Stack management
    132 HANDLE_MEMORY_INST(27, Load , LoadInst ) // Memory manipulation instrs
    133 HANDLE_MEMORY_INST(28, Store , StoreInst )
    134 HANDLE_MEMORY_INST(29, GetElementPtr, GetElementPtrInst)
    135 HANDLE_MEMORY_INST(30, Fence , FenceInst )
    136 LAST_MEMORY_INST(30)
    131 FIRST_MEMORY_INST(27)
    132 HANDLE_MEMORY_INST(27, Alloca, AllocaInst) // Stack management
    133 HANDLE_MEMORY_INST(28, Load , LoadInst ) // Memory manipulation instrs
    134 HANDLE_MEMORY_INST(29, Store , StoreInst )
    135 HANDLE_MEMORY_INST(30, GetElementPtr, GetElementPtrInst)
    136 HANDLE_MEMORY_INST(31, Fence , FenceInst )
    137 LAST_MEMORY_INST(31)
    137138
    138139 // Cast operators ...
    139140 // NOTE: The order matters here because CastInst::isEliminableCastPair
    168169 HANDLE_OTHER_INST(55, ShuffleVector, ShuffleVectorInst) // shuffle two vectors.
    169170 HANDLE_OTHER_INST(56, ExtractValue, ExtractValueInst)// extract from aggregate
    170171 HANDLE_OTHER_INST(57, InsertValue, InsertValueInst) // insert into aggregate
    171
    172 LAST_OTHER_INST(57)
    172 HANDLE_OTHER_INST(58, LandingPad, LandingPadInst) // Landing pad instruction.
    173 LAST_OTHER_INST(58)
    173174
    174175 #undef FIRST_TERM_INST
    175176 #undef HANDLE_TERM_INST
    17741774
    17751775 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
    17761776
    1777 //===----------------------------------------------------------------------===//
    1778 // LandingPadInst Class
    1779 //===----------------------------------------------------------------------===//
    1780
    1781 //===---------------------------------------------------------------------------
    1782 /// LandingPadInst - The landingpad instruction holds all of the information
    1783 /// necessary to generate correct exception handling. The landingpad instruction
    1784 /// cannot be moved from the top of a landing pad block, which itself is
    1785 /// accessible only from the 'unwind' edge of an invoke.
    1786 ///
    1787 class LandingPadInst : public Instruction {
    1788 /// ReservedSpace - The number of operands actually allocated. NumOperands is
    1789 /// the number actually in use.
    1790 unsigned ReservedSpace;
    1791
    1792 /// IsCleanup - True if the landingpad instruction is also a cleanup.
    1793 bool IsCleanup;
    1794 LandingPadInst(const LandingPadInst &LP);
    1795 public:
    1796 enum ClauseType { Catch, Filter };
    1797 private:
    1798 /// ClauseIdxs - This indexes into the OperandList, indicating what the
    1799 /// values are at a given index.
    1800 SmallVector ClauseIdxs;
    1801
    1802 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
    1803 // Allocate space for exactly zero operands.
    1804 void *operator new(size_t s) {
    1805 return User::operator new(s, 0);
    1806 }
    1807 void growOperands();
    1808 void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
    1809
    1810 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
    1811 unsigned NumReservedValues, const Twine &NameStr,
    1812 Instruction *InsertBefore)
    1813 : Instruction(RetTy, Instruction::LandingPad, 0, 0, InsertBefore),
    1814 IsCleanup(false) {
    1815 init(PersonalityFn, 1 + NumReservedValues, NameStr);
    1816 }
    1817 explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
    1818 unsigned NumReservedValues, const Twine &NameStr,
    1819 BasicBlock *InsertAtEnd)
    1820 : Instruction(RetTy, Instruction::LandingPad, 0, 0, InsertAtEnd),
    1821 IsCleanup(false) {
    1822 init(PersonalityFn, 1 + NumReservedValues, NameStr);
    1823 }
    1824 protected:
    1825 virtual LandingPadInst *clone_impl() const;
    1826 public:
    1827 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
    1828 unsigned NumReservedValues,
    1829 const Twine &NameStr = "",
    1830 Instruction *InsertBefore = 0) {
    1831 return new LandingPadInst(RetTy, PersonalityFn, NumReservedValues, NameStr,
    1832 InsertBefore);
    1833 }
    1834 static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
    1835 unsigned NumReservedValues,
    1836 const Twine &NameStr, BasicBlock *InsertAtEnd) {
    1837 return new LandingPadInst(RetTy, PersonalityFn, NumReservedValues, NameStr,
    1838 InsertAtEnd);
    1839 }
    1840 ~LandingPadInst();
    1841
    1842 /// Provide fast operand accessors
    1843 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
    1844
    1845 /// getPersonalityFn - Get the personality function associated with this
    1846 /// landing pad.
    1847 const Value *getPersonalityFn() const { return getOperand(0); }
    1848
    1849 // Simple accessors.
    1850 bool isCleanup() const { return IsCleanup; }
    1851 void setCleanup(bool Val) { IsCleanup = Val; }
    1852
    1853 /// addClause - Add a clause to the landing pad.
    1854 void addClause(ClauseType CT, Value *ClauseVal);
    1855
    1856 /// getClauseType - Return the type of the clause at this index. The two
    1857 /// supported clauses are Catch and Filter.
    1858 ClauseType getClauseType(unsigned I) const {
    1859 assert(I < ClauseIdxs.size() && "Index too large!");
    1860 return ClauseIdxs[I];
    1861 }
    1862
    1863 /// getClauseValue - Return the value of the clause at this index.
    1864 Value *getClauseValue(unsigned I) const {
    1865 assert(I + 1 < getNumOperands() && "Index too large!");
    1866 return OperandList[I + 1];
    1867 }
    1868
    1869 /// getNumClauses - Get the number of clauses for this landing pad.
    1870 unsigned getNumClauses() const { return getNumOperands() - 1; }
    1871
    1872 // Methods for support type inquiry through isa, cast, and dyn_cast:
    1873 static inline bool classof(const LandingPadInst *) { return true; }
    1874 static inline bool classof(const Instruction *I) {
    1875 return I->getOpcode() == Instruction::LandingPad;
    1876 }
    1877 static inline bool classof(const Value *V) {
    1878 return isa(V) && classof(cast(V));
    1879 }
    1880 };
    1881
    1882 template <>
    1883 struct OperandTraits : public HungoffOperandTraits<2> {
    1884 };
    1885
    1886 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
    17771887
    17781888 //===----------------------------------------------------------------------===//
    17791889 // ReturnInst Class
    24622572 };
    24632573
    24642574 //===----------------------------------------------------------------------===//
    2575 // ResumeInst Class
    2576 //===----------------------------------------------------------------------===//
    2577
    2578 //===---------------------------------------------------------------------------
    2579 /// ResumeInst - Resume the propagation of an exception.
    2580 ///
    2581 class ResumeInst : public TerminatorInst {
    2582 ResumeInst(const ResumeInst &RI);
    2583
    2584 explicit ResumeInst(LLVMContext &C, Value *Exn, Instruction *InsertBefore=0);
    2585 ResumeInst(LLVMContext &C, Value *Exn, BasicBlock *InsertAtEnd);
    2586 protected:
    2587 virtual ResumeInst *clone_impl() const;
    2588 public:
    2589 static ResumeInst *Create(LLVMContext &C, Value *Exn,
    2590 Instruction *InsertBefore = 0) {
    2591 return new(1) ResumeInst(C, Exn, InsertBefore);
    2592 }
    2593 static ResumeInst *Create(LLVMContext &C, Value *Exn,
    2594 BasicBlock *InsertAtEnd) {
    2595 return new(1) ResumeInst(C, Exn, InsertAtEnd);
    2596 }
    2597
    2598 /// Provide fast operand accessors
    2599 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
    2600
    2601 /// Convenience accessor.
    2602 Value *getResumeValue() const { return Op<0>(); }
    2603
    2604 unsigned getNumSuccessors() const { return 0; }
    2605
    2606 // Methods for support type inquiry through isa, cast, and dyn_cast:
    2607 static inline bool classof(const ResumeInst *) { return true; }
    2608 static inline bool classof(const Instruction *I) {
    2609 return I->getOpcode() == Instruction::Resume;
    2610 }
    2611 static inline bool classof(const Value *V) {
    2612 return isa(V) && classof(cast(V));
    2613 }
    2614 private:
    2615 virtual BasicBlock *getSuccessorV(unsigned idx) const;
    2616 virtual unsigned getNumSuccessorsV() const;
    2617 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
    2618 };
    2619
    2620 template <>
    2621 struct OperandTraits :
    2622 public FixedNumOperandTraits {
    2623 };
    2624
    2625 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
    2626
    2627 //===----------------------------------------------------------------------===//
    24652628 // UnreachableInst Class
    24662629 //===----------------------------------------------------------------------===//
    24672630
    478478 return Insert(new UnwindInst(Context));
    479479 }
    480480
    481 ResumeInst *CreateResume(Value *Exn) {
    482 return Insert(ResumeInst::Create(Context, Exn));
    483 }
    484
    481485 UnreachableInst *CreateUnreachable() {
    482486 return Insert(new UnreachableInst(Context));
    483487 }
    11911195 if (Constant *ValC = dyn_cast(Val))
    11921196 return Insert(Folder.CreateInsertValue(AggC, ValC, Idxs), Name);
    11931197 return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
    1198 }
    1199
    1200 Value *CreateLandingPad(Type *Ty, Value *PersFn, unsigned NumClauses,
    1201 const Twine &Name = "") {
    1202 return Insert(LandingPadInst::Create(Ty, PersFn, NumClauses, Name));
    11941203 }
    11951204
    11961205 //===--------------------------------------------------------------------===//
    162162 RetTy visitIndirectBrInst(IndirectBrInst &I) { DELEGATE(TerminatorInst);}
    163163 RetTy visitInvokeInst(InvokeInst &I) { DELEGATE(TerminatorInst);}
    164164 RetTy visitUnwindInst(UnwindInst &I) { DELEGATE(TerminatorInst);}
    165 RetTy visitResumeInst(ResumeInst &I) { DELEGATE(TerminatorInst);}
    165166 RetTy visitUnreachableInst(UnreachableInst &I) { DELEGATE(TerminatorInst);}
    166167 RetTy visitICmpInst(ICmpInst &I) { DELEGATE(CmpInst);}
    167168 RetTy visitFCmpInst(FCmpInst &I) { DELEGATE(CmpInst);}
    191192 RetTy visitShuffleVectorInst(ShuffleVectorInst &I) { DELEGATE(Instruction); }
    192193 RetTy visitExtractValueInst(ExtractValueInst &I) { DELEGATE(Instruction);}
    193194 RetTy visitInsertValueInst(InsertValueInst &I) { DELEGATE(Instruction); }
    195 RetTy visitLandingPadInst(LandingPadInst &I) { DELEGATE(Instruction); }
    194196
    195197 // Next level propagators: If the user does not overload a specific
    196198 // instruction type, they can overload one of these to get the whole class
    125125 LLVMIndirectBr = 4,
    126126 LLVMInvoke = 5,
    127127 LLVMUnwind = 6,
    128 LLVMUnreachable = 7,
    128 LLVMResume = 7,
    129 LLVMUnreachable = 8,
    129130
    130131 /* Standard Binary Operators */
    131 LLVMAdd = 8,
    132 LLVMFAdd = 9,
    133 LLVMSub = 10,
    134 LLVMFSub = 11,
    135 LLVMMul = 12,
    136 LLVMFMul = 13,
    137 LLVMUDiv = 14,
    138 LLVMSDiv = 15,
    139 LLVMFDiv = 16,
    140 LLVMURem = 17,
    141 LLVMSRem = 18,
    142 LLVMFRem = 19,
    132 LLVMAdd = 9,
    133 LLVMFAdd = 10,
    134 LLVMSub = 11,
    135 LLVMFSub = 12,
    136 LLVMMul = 13,
    137 LLVMFMul = 14,
    138 LLVMUDiv = 15,
    139 LLVMSDiv = 16,
    140 LLVMFDiv = 17,
    141 LLVMURem = 18,
    142 LLVMSRem = 19,
    143 LLVMFRem = 20,
    143144
    144145 /* Logical Operators */
    145 LLVMShl = 20,
    146 LLVMLShr = 21,
    147 LLVMAShr = 22,
    148 LLVMAnd = 23,
    149 LLVMOr = 24,
    150 LLVMXor = 25,
    146 LLVMShl = 21,
    147 LLVMLShr = 22,
    148 LLVMAShr = 23,
    149 LLVMAnd = 24,
    150 LLVMOr = 25,
    151 LLVMXor = 26,
    151152
    152153 /* Memory Operators */
    153 LLVMAlloca = 26,
    154 LLVMLoad = 27,
    155 LLVMStore = 28,
    156 LLVMGetElementPtr = 29,
    154 LLVMAlloca = 27,
    155 LLVMLoad = 28,
    156 LLVMStore = 29,
    157 LLVMGetElementPtr = 30,
    157158
    158159 /* Cast Operators */
    159 LLVMTrunc = 30,
    160 LLVMZExt = 31,
    161 LLVMSExt = 32,
    162 LLVMFPToUI = 33,
    163 LLVMFPToSI = 34,
    164 LLVMUIToFP = 35,
    165 LLVMSIToFP = 36,
    166 LLVMFPTrunc = 37,
    167 LLVMFPExt = 38,
    168 LLVMPtrToInt = 39,
    169 LLVMIntToPtr = 40,
    170 LLVMBitCast = 41,
    160 LLVMTrunc = 31,
    161 LLVMZExt = 32,
    162 LLVMSExt = 33,
    163 LLVMFPToUI = 34,
    164 LLVMFPToSI = 35,
    165 LLVMUIToFP = 36,
    166 LLVMSIToFP = 37,
    167 LLVMFPTrunc = 38,
    168 LLVMFPExt = 39,
    169 LLVMPtrToInt = 40,
    170 LLVMIntToPtr = 41,
    171 LLVMBitCast = 42,
    171172
    172173 /* Other Operators */
    173 LLVMICmp = 42,
    174 LLVMFCmp = 43,
    175 LLVMPHI = 44,
    176 LLVMCall = 45,
    177 LLVMSelect = 46,
    174 LLVMICmp = 43,
    175 LLVMFCmp = 44,
    176 LLVMPHI = 45,
    177 LLVMCall = 46,
    178 LLVMSelect = 47,
    178179 /* UserOp1 */
    179180 /* UserOp2 */
    180 LLVMVAArg = 49,
    181 LLVMExtractElement = 50,
    182 LLVMInsertElement = 51,
    183 LLVMShuffleVector = 52,
    184 LLVMExtractValue = 53,
    185 LLVMInsertValue = 54,
    181 LLVMVAArg = 50,
    182 LLVMExtractElement = 51,
    183 LLVMInsertElement = 52,
    184 LLVMShuffleVector = 53,
    185 LLVMExtractValue = 54,
    186 LLVMInsertValue = 55,
    187 LLVMLandingPad = 56,
    186188
    187189 /* Atomic operators */
    188 LLVMFence = 55
    190 LLVMFence = 57
    189191 } LLVMOpcode;
    190192
    191193 typedef enum {
    275277 LLVMRealUNE, /**< True if unordered or not equal */
    276278 LLVMRealPredicateTrue /**< Always true (always folded) */
    277279 } LLVMRealPredicate;
    280
    281 typedef enum {
    282 LLVMCatch, /**< A catch clause */
    283 LLVMFilter /**< A filter clause */
    284 } LLVMLandingPadClauseTy;
    278285
    279286 void LLVMInitializeCore(LLVMPassRegistryRef R);
    280287
    462469 macro(GetElementPtrInst) \
    463470 macro(InsertElementInst) \
    464471 macro(InsertValueInst) \
    472 macro(LandingPadInst) \
    465473 macro(PHINode) \
    466474 macro(SelectInst) \
    467475 macro(ShuffleVectorInst) \
    473481 macro(SwitchInst) \
    474482 macro(UnreachableInst) \
    475483 macro(UnwindInst) \
    484 macro(ResumeInst) \
    476485 macro(UnaryInstruction) \
    477486 macro(AllocaInst) \
    478487 macro(CastInst) \
    821830 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
    822831 const char *Name);
    823832 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
    833 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
    824834 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
    825835
    826836 /* Add a case to the switch instruction */
    829839
    830840 /* Add a destination to the indirectbr instruction */
    831841 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
    842
    843 /* Add a clause to the landingpad instruction */
    844 void LLVMAddClause(LLVMValueRef LandingPad, LLVMLandingPadClauseTy ClauseTy,
    845 LLVMValueRef ClauseVal);
    846
    847 /* Set the 'cleanup' flag in the landingpad instruction */
    848 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
    832849
    833850 /* Arithmetic */
    834851 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
    580580
    581581 KEYWORD(x);
    582582 KEYWORD(blockaddress);
    583
    584 KEYWORD(personality);
    585 KEYWORD(cleanup);
    586 KEYWORD(catch);
    587 KEYWORD(filter);
    583588 #undef KEYWORD
    584589
    585590 // Keywords for types.
    632637 INSTKEYWORD(switch, Switch);
    633638 INSTKEYWORD(indirectbr, IndirectBr);
    634639 INSTKEYWORD(invoke, Invoke);
    640 INSTKEYWORD(resume, Resume);
    635641 INSTKEYWORD(unwind, Unwind);
    636642 INSTKEYWORD(unreachable, Unreachable);
    637643
    646652 INSTKEYWORD(shufflevector, ShuffleVector);
    647653 INSTKEYWORD(extractvalue, ExtractValue);
    648654 INSTKEYWORD(insertvalue, InsertValue);
    655 INSTKEYWORD(landingpad, LandingPad);
    649656 #undef INSTKEYWORD
    650657
    651658 // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
    672679 CurPtr = TokStart+1;
    673680 return lltok::Error;
    674681 }
    675
    676682
    677683 /// Lex0x: Handle productions that start with 0x, knowing that it matches and
    678684 /// that this is not a label:
    28842884 case lltok::kw_switch: return ParseSwitch(Inst, PFS);
    28852885 case lltok::kw_indirectbr: return ParseIndirectBr(Inst, PFS);
    28862886 case lltok::kw_invoke: return ParseInvoke(Inst, PFS);
    2887 case lltok::kw_resume: return ParseResume(Inst, PFS);
    28872888 // Binary Operators.
    28882889 case lltok::kw_add:
    28892890 case lltok::kw_sub:
    29432944 case lltok::kw_insertelement: return ParseInsertElement(Inst, PFS);
    29442945 case lltok::kw_shufflevector: return ParseShuffleVector(Inst, PFS);
    29452946 case lltok::kw_phi: return ParsePHI(Inst, PFS);
    2947 case lltok::kw_landingpad: return ParseLandingPad(Inst, PFS);
    29462948 case lltok::kw_call: return ParseCall(Inst, PFS, false);
    29472949 case lltok::kw_tail: return ParseCall(Inst, PFS, true);
    29482950 // Memory.
    32463248 return false;
    32473249 }
    32483250
    3249
    3251 /// ParseResume
    3252 /// ::= 'resume' TypeAndValue
    3253 bool LLParser::ParseResume(Instruction *&Inst, PerFunctionState &PFS) {
    3254 Value *Exn; LocTy ExnLoc;
    3255 LocTy Loc = Lex.getLoc();
    3256 if (ParseTypeAndValue(Exn, ExnLoc, PFS))
    3257 return true;
    3258
    3259 ResumeInst *RI = ResumeInst::Create(Context, Exn);
    3260 Inst = RI;
    3261 return false;
    3262 }
    32503263
    32513264 //===----------------------------------------------------------------------===//
    32523265 // Binary Operators.
    34943507 return AteExtraComma ? InstExtraComma : InstNormal;
    34953508 }
    34963509
    3510 /// ParseLandingPad
    3511 /// ::= 'landingpad' Type 'personality' TypeAndValue 'cleanup'?
    3512 /// (ClauseID ClauseList)+
    3513 /// ClauseID
    3514 /// ::= 'catch'
    3515 /// ::= 'filter'
    3516 /// ClauseList
    3517 /// ::= TypeAndValue (',' TypeAndValue)*
    3518 bool LLParser::ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS) {
    3519 Type *Ty = 0; LocTy TyLoc;
    3520 Value *PersFn; LocTy PersFnLoc;
    3521 LocTy LPLoc = Lex.getLoc();
    3522
    3523 if (ParseType(Ty, TyLoc) ||
    3524 ParseToken(lltok::kw_personality, "expected 'personality'") ||
    3525 ParseTypeAndValue(PersFn, PersFnLoc, PFS))
    3526 return true;
    3527
    3528 bool IsCleanup = EatIfPresent(lltok::kw_cleanup);
    3529
    3530 SmallVector, 16> Clauses;
    3531 while (Lex.getKind() == lltok::kw_catch || Lex.getKind() == lltok::kw_filter){
    3532 LandingPadInst::ClauseType CT;
    3533 if (Lex.getKind() == lltok::kw_catch) {
    3534 CT = LandingPadInst::Catch;
    3535 ParseToken(lltok::kw_catch, "expected 'catch'");
    3536 } else {
    3537 CT = LandingPadInst::Filter;
    3538 ParseToken(lltok::kw_filter, "expected 'filter'");
    3539 }
    3540
    3541 do {
    3542 Value *V; LocTy VLoc;
    3543 if (ParseTypeAndValue(V, VLoc, PFS))
    3544 return true;
    3545 Clauses.push_back(std::make_pair(CT, V));
    3546 } while (EatIfPresent(lltok::comma));
    3547 }
    3548
    3549 LandingPadInst *LP = LandingPadInst::Create(Ty, PersFn, Clauses.size());
    3550 LP->setCleanup(IsCleanup);
    3551
    3552 for (SmallVectorImpl >::iterator
    3553 I = Clauses.begin(), E = Clauses.end(); I != E; ++I)
    3554 LP->addClause(I->first, I->second);
    3555
    3556 Inst = LP;
    3557 return false;
    3558 }
    3559
    34973560 /// ParseCall
    34983561 /// ::= 'tail'? 'call' OptionalCallingConv OptionalAttrs Type Value
    34993562 /// ParameterList OptionalAttrs
    346346 bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
    347347 bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
    348348 bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
    349 bool ParseResume(Instruction *&Inst, PerFunctionState &PFS);
    349350
    350351 bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc,
    351352 unsigned OperandType);
    358359 bool ParseInsertElement(Instruction *&I, PerFunctionState &PFS);
    359360 bool ParseShuffleVector(Instruction *&I, PerFunctionState &PFS);
    360361 int ParsePHI(Instruction *&I, PerFunctionState &PFS);
    362 bool ParseLandingPad(Instruction *&I, PerFunctionState &PFS);
    361363 bool ParseCall(Instruction *&I, PerFunctionState &PFS, bool isTail);
    362364 int ParseAlloc(Instruction *&I, PerFunctionState &PFS);
    363365 int ParseLoad(Instruction *&I, PerFunctionState &PFS, bool isVolatile);
    120120 kw_fptoui, kw_fptosi, kw_inttoptr, kw_ptrtoint, kw_bitcast,
    121121 kw_select, kw_va_arg,
    122122
    123 kw_ret, kw_br, kw_switch, kw_indirectbr, kw_invoke, kw_unwind,
    123 kw_landingpad, kw_personality, kw_cleanup, kw_catch, kw_filter,
    124
    125 kw_ret, kw_br, kw_switch, kw_indirectbr, kw_invoke, kw_unwind, kw_resume,
    124126 kw_unreachable,
    125127
    126128 kw_alloca, kw_load, kw_store, kw_fence, kw_getelementptr,
    142144 // Type valued tokens (TyVal).
    143145 Type,
    144146
    145 APFloat, // APFloatVal
    146 APSInt // APSInt
    147 APFloat, // APFloatVal
    148 APSInt // APSInt
    147149 };
    148150 } // end namespace lltok
    149151 } // end namespace llvm
    24902490 cast(I)->setAttributes(PAL);
    24912491 break;
    24922492 }
    2493 case bitc::FUNC_CODE_INST_RESUME: { // RESUME: [opval]
    2494 unsigned Idx = 0;
    2495 Value *Val = 0;
    2496 if (getValueTypePair(Record, Idx, NextValueNo, Val))
    2497 return Error("Invalid RESUME record");
    2498 I = ResumeInst::Create(Context, Val);
    2499 break;
    2500 }
    24932501 case bitc::FUNC_CODE_INST_UNWIND: // UNWIND
    24942502 I = new UnwindInst(Context);
    24952503 InstructionList.push_back(I);
    25142522 PN->addIncoming(V, BB);
    25152523 }
    25162524 I = PN;
    2525 break;
    2526 }
    2527
    2528 case bitc::FUNC_CODE_INST_LANDINGPAD: {
    2529 // LANDINGPAD: [ty, val, val, num, (id0,val0 ...)?]
    2530 unsigned Idx = 0;
    2531 if (Record.size() < 4)
    2532 return Error("Invalid LANDINGPAD record");
    2533 Type *Ty = getTypeByID(Record[Idx++]);
    2534 if (!Ty) return Error("Invalid LANDINGPAD record");
    2535 Value *PersFn = 0;
    2536 if (getValueTypePair(Record, Idx, NextValueNo, PersFn))
    2537 return Error("Invalid LANDINGPAD record");
    2538
    2539 bool IsCleanup = !!Record[Idx++];
    2540 unsigned NumClauses = Record[Idx++];
    2541 LandingPadInst *LP = LandingPadInst::Create(Ty, PersFn, NumClauses);
    2542 LP->setCleanup(IsCleanup);
    2543 for (unsigned J = 0; J != NumClauses; ++J) {
    2544 LandingPadInst::ClauseType CT =
    2545 LandingPadInst::ClauseType(Record[Idx++]);
    2546 Value *Val = 0;
    2547 if (getValueTypePair(Record, Idx, NextValueNo, Val)) {
    2548 delete LP;
    2549 return Error("Invalid LANDINGPAD record");
    2550 }
    2551
    2552 LP->addClause(CT, Val);
    2553 }
    2554
    2555 I = LP;
    25172556 break;
    25182557 }
    25192558
    11251125 }
    11261126 break;
    11271127 }
    1128 case Instruction::Resume:
    1129 Code = bitc::FUNC_CODE_INST_RESUME;
    1130 PushValueAndType(I.getOperand(0), InstID, Vals, VE);
    1131 break;
    11281132 case Instruction::Unwind:
    11291133 Code = bitc::FUNC_CODE_INST_UNWIND;
    11301134 break;
    11401144 for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) {
    11411145 Vals.push_back(VE.getValueID(PN.getIncomingValue(i)));
    11421146 Vals.push_back(VE.getValueID(PN.getIncomingBlock(i)));
    1147 }
    1148 break;
    1149 }
    1150
    1151 case Instruction::LandingPad: {
    1152 const LandingPadInst &LP = cast(I);
    1153 Code = bitc::FUNC_CODE_INST_LANDINGPAD;
    1154 Vals.push_back(VE.getTypeID(LP.getType()));
    1155 PushValueAndType(LP.getPersonalityFn(), InstID, Vals, VE);
    1156 Vals.push_back(LP.isCleanup());
    1157 Vals.push_back(LP.getNumClauses());
    1158 for (unsigned I = 0, E = LP.getNumClauses(); I != E; ++I) {
    1159 Vals.push_back(LP.getClauseType(I));
    1160 PushValueAndType(LP.getClauseValue(I), InstID, Vals, VE);
    11431161 }
    11441162 break;
    11451163 }
    913913 llvm_unreachable("SelectionDAGBuilder shouldn't visit PHI nodes!");
    914914 }
    915915
    916 void SelectionDAGBuilder::visitLandingPad(const LandingPadInst &) {
    917 // FIXME: Handle this
    918 }
    919
    916920 void SelectionDAGBuilder::visit(unsigned Opcode, const User &I) {
    917921 // Note: this doesn't use InstVisitor, because it has to work with
    918922 // ConstantExpr's in addition to instructions.
    18051809 }
    18061810
    18071811 void SelectionDAGBuilder::visitUnwind(const UnwindInst &I) {
    1812 }
    1813
    1814 void SelectionDAGBuilder::visitResume(const ResumeInst &RI) {
    1815 // FIXME: Handle this
    18081816 }
    18091817
    18101818 /// handleSmallSwitchCaseRange - Emit a series of specific tests (suitable for
    452452 private:
    453453 // These all get lowered before this pass.
    454454 void visitInvoke(const InvokeInst &I);
    455 void visitResume(const ResumeInst &I);
    455456 void visitUnwind(const UnwindInst &I);
    456457
    457458 void visitBinary(const User &I, unsigned OpCode);
    496497
    497498 void visitExtractValue(const ExtractValueInst &I);
    498499 void visitInsertValue(const InsertValueInst &I);
    500 void visitLandingPad(const LandingPadInst &I);
    499501
    500502 void visitGetElementPtr(const User &I);
    501503 void visitSelect(const User &I);
    112112 while (StateBB != StateE) {
    113113 BasicBlock *CurBB = StateBB++;
    114114
    115 // Branches and invokes do not escape, only unwind and return do.
    115 // Branches and invokes do not escape, only unwind, resume, and return
    116 // do.
    116117 TerminatorInst *TI = CurBB->getTerminator();
    117 if (!isa(TI) && !isa(TI))
    118 if (!isa(TI) && !isa(TI) &&
    119 !isa(TI))
    118120 continue;
    119121
    120122 Builder.SetInsertPoint(TI->getParent(), TI);
    287287 void visitInvokeInst(InvokeInst &I) {
    288288 llvm_unreachable("Lowerinvoke pass didn't work!");
    289289 }
    290
    291290 void visitUnwindInst(UnwindInst &I) {
    291 llvm_unreachable("Lowerinvoke pass didn't work!");
    292 }
    293 void visitResumeInst(ResumeInst &I) {
    292294 llvm_unreachable("Lowerinvoke pass didn't work!");
    293295 }
    294296 void visitUnreachableInst(UnreachableInst &I);
    10631063 }
    10641064 break;
    10651065 }
    1066 case Instruction::Resume: {
    1067 Out << "ResumeInst::Create(mod->getContext(), " << opNames[0]
    1068 << ", " << bbname << ");";
    1069 break;
    1070 }
    10661071 case Instruction::Invoke: {
    10671072 const InvokeInst* inv = cast(I);
    10681073 Out << "std::vector " << iName << "_params;";
    14221427 Out << "\", " << bbname << ");";
    14231428 break;
    14241429 }
    1430 case Instruction::LandingPad: {
    1431 break;
    1432 }
    14251433 }
    14261434 DefinedValues.insert(I);
    14271435 nl(Out);
    25052505 CallStack.pop_back(); // return from fn.
    25062506 return true; // We succeeded at evaluating this ctor!
    25072507 } else {
    2508 // invoke, unwind, unreachable.
    2508 // invoke, unwind, resume, unreachable.
    25092509 return false; // Cannot handle this terminator.
    25102510 }
    25112511
    731731 }
    732732 }
    733733
    734 // If the stack restore is in a return/unwind block and if there are no
    735 // allocas or calls between the restore and the return, nuke the restore.
    736 if (!CannotRemove && (isa(TI) || isa(TI)))
    734 // If the stack restore is in a return, resume, or unwind block and if there
    735 // are no allocas or calls between the restore and the return, nuke the
    736 // restore.
    737 if (!CannotRemove && (isa(TI) || isa(TI) ||
    738 isa(TI)))
    737739 return EraseInstFromFunction(CI);
    738740 break;
    739741 }
    514514 void visitShuffleVectorInst(ShuffleVectorInst &I);
    515515 void visitExtractValueInst(ExtractValueInst &EVI);
    516516 void visitInsertValueInst(InsertValueInst &IVI);
    517 void visitLandingPadInst(LandingPadInst &I) { markAnythingOverdefined(&I); }
    517518
    518519 // Instructions that cannot be folded away.
    519520 void visitStoreInst (StoreInst &I);
    527528 visitTerminatorInst(II);
    528529 }
    529530 void visitCallSite (CallSite CS);
    531 void visitResumeInst (TerminatorInst &I) { /*returns void*/ }
    530532 void visitUnwindInst (TerminatorInst &I) { /*returns void*/ }
    531533 void visitUnreachableInst(TerminatorInst &I) { /*returns void*/ }
    532534 void visitFenceInst (FenceInst &I) { /*returns void*/ }
    17091709 writeOperand(I.getOperand(i), true);
    17101710 }
    17111711 Out << ']';
    1712 } else if (isa(I)) {
    1713 Out << ' ';
    1714 writeOperand(Operand, true);
    17121715 } else if (const PHINode *PN = dyn_cast(&I)) {
    17131716 Out << ' ';
    17141717 TypePrinter.print(I.getType(), Out);
    17311734 writeOperand(I.getOperand(1), true);
    17321735 for (const unsigned *i = IVI->idx_begin(), *e = IVI->idx_end(); i != e; ++i)
    17331736 Out << ", " << *i;
    1737 } else if (const LandingPadInst *LPI = dyn_cast(&I)) {
    1738 Out << ' ';
    1739 TypePrinter.print(I.getType(), Out);
    1740 Out << " personality ";
    1741 writeOperand(LPI->getPersonalityFn(), true); Out << '\n';
    1742
    1743 if (LPI->isCleanup())
    1744 Out << " cleanup";
    1745
    1746 for (unsigned i = 0, e = LPI->getNumClauses(); i != e; ) {
    1747 if (i != 0 || LPI->isCleanup()) Out << "\n";
    1748
    1749 SmallVector Vals;
    1750 LandingPadInst::ClauseType CT = LPI->getClauseType(i);
    1751 for (; i != e && LPI->getClauseType(i) == CT; ++i)
    1752 Vals.push_back(LPI->getClauseValue(i));
    1753
    1754 if (CT == LandingPadInst::Catch)
    1755 Out << " catch ";
    1756 else
    1757 Out << " filter ";
    1758
    1759 for (unsigned II = 0, IE = Vals.size(); II != IE; ++II) {
    1760 if (II != 0) Out << ", ";
    1761 writeOperand(Vals[II], true);
    1762 }
    1763 }
    17341764 } else if (isa(I) && !Operand) {
    17351765 Out << " void";
    17361766 } else if (const CallInst *CI = dyn_cast(&I)) {
    16821682 Name));
    16831683 }
    16841684
    1685 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
    1686 LLVMValueRef PersFn, unsigned NumClauses,
    1687 const char *Name) {
    1688 return wrap(unwrap(B)->CreateLandingPad(unwrap(Ty), unwrap(PersFn),
    1689 NumClauses, Name));
    1690 }
    1691
    16851692 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef B) {
    16861693 return wrap(unwrap(B)->CreateUnwind());
    1694 }
    1695
    1696 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn) {
    1697 return wrap(unwrap(B)->CreateResume(unwrap(Exn)));
    16871698 }
    16881699
    16891700 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B) {
    16971708
    16981709 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest) {
    16991710 unwrap(IndirectBr)->addDestination(unwrap(Dest));
    1711 }
    1712
    1713 void LLVMAddClause(LLVMValueRef LandingPad, LLVMLandingPadClauseTy ClauseTy,
    1714 LLVMValueRef ClauseVal) {
    1715 unwrap(LandingPad)->
    1716 addClause(static_cast(ClauseTy),
    1717 unwrap(ClauseVal));
    1718 }
    1719
    1720 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val) {
    1721 unwrap(LandingPad)->setCleanup(Val);
    17001722 }
    17011723
    17021724 /*--.. Arithmetic ..........................................................--*/
    100100 case Switch: return "switch";
    101101 case IndirectBr: return "indirectbr";
    102102 case Invoke: return "invoke";
    103 case Resume: return "resume";
    103104 case Unwind: return "unwind";
    104105 case Unreachable: return "unreachable";
    105106
    158159 case ShuffleVector: return "shufflevector";
    159160 case ExtractValue: return "extractvalue";
    160161 case InsertValue: return "insertvalue";
    162 case LandingPad: return "landingpad";
    161163
    162164 default: return " ";
    163165 }
    165165 return ConstantValue;
    166166 }
    167167
    168 //===----------------------------------------------------------------------===//
    169 // LandingPadInst Implementation
    170 //===----------------------------------------------------------------------===//
    171
    172 void LandingPadInst::init(Value *PersFn, unsigned NumReservedValues,
    173 const Twine &NameStr) {
    174 ReservedSpace = NumReservedValues;
    175 NumOperands = 1;
    176 OperandList = allocHungoffUses(ReservedSpace);
    177 OperandList[0] = PersFn;
    178 setName(NameStr);
    179 }
    180
    181 LandingPadInst::LandingPadInst(const LandingPadInst &LP)
    182 : Instruction(LP.getType(), Instruction::LandingPad,
    183 allocHungoffUses(LP.getNumOperands()), LP.getNumOperands()),
    184 ReservedSpace(LP.getNumOperands()) {
    185 Use *OL = OperandList, *InOL = LP.OperandList;
    186 for (unsigned I = 0, E = ReservedSpace; I != E; ++I)
    187 OL[I] = InOL[I];
    188
    189 for (SmallVectorImpl::const_iterator
    190 I = LP.ClauseIdxs.begin(), E = LP.ClauseIdxs.end(); I != E; ++I)
    191 ClauseIdxs.push_back(*I);
    192
    193 IsCleanup = LP.IsCleanup;
    194 SubclassOptionalData = LP.SubclassOptionalData;
    195 }
    196
    197 LandingPadInst::~LandingPadInst() {
    198 dropHungoffUses();
    199 }
    200
    201 /// growOperands - grow operands - This grows the operand list in response to a
    202 /// push_back style of operation. This grows the number of ops by 2 times.
    203 void LandingPadInst::growOperands() {
    204 unsigned e = getNumOperands();
    205 ReservedSpace = e * 2;
    206
    207 Use *NewOps = allocHungoffUses(ReservedSpace);
    208 Use *OldOps = OperandList;
    209 for (unsigned i = 0; i != e; ++i)
    210 NewOps[i] = OldOps[i];
    211
    212 OperandList = NewOps;
    213 Use::zap(OldOps, OldOps + e, true);
    214 }
    215
    216 void LandingPadInst::addClause(ClauseType CT, Value *ClauseVal) {
    217 unsigned OpNo = getNumOperands();
    218 if (OpNo + 1 > ReservedSpace)
    219 growOperands();
    220 assert(OpNo < ReservedSpace && "Growing didn't work!");
    221 ClauseIdxs.push_back(CT);
    222 ++NumOperands;
    223 OperandList[OpNo] = ClauseVal;
    224 }
    168225
    169226 //===----------------------------------------------------------------------===//
    170227 // CallInst Implementation
    573630 }
    574631
    575632 //===----------------------------------------------------------------------===//
    633 // ResumeInst Implementation
    634 //===----------------------------------------------------------------------===//
    635
    636 ResumeInst::ResumeInst(const ResumeInst &RI)
    637 : TerminatorInst(Type::getVoidTy(RI.getContext()), Instruction::Resume,
    638 OperandTraits::op_begin(this), 1) {
    639 Op<0>() = RI.Op<0>();
    640 SubclassOptionalData = RI.SubclassOptionalData;
    641 }
    642
    643 ResumeInst::ResumeInst(LLVMContext &C, Value *Exn, Instruction *InsertBefore)
    644 : TerminatorInst(Type::getVoidTy(C), Instruction::Resume,
    645 OperandTraits::op_begin(this), 1, InsertBefore) {
    646 Op<0>() = Exn;
    647 }
    648
    649 ResumeInst::ResumeInst(LLVMContext &C, Value *Exn, BasicBlock *InsertAtEnd)
    650 : TerminatorInst(Type::getVoidTy(C), Instruction::Resume,
    651 OperandTraits::op_begin(this), 1, InsertAtEnd) {
    652 Op<0>() = Exn;
    653 }
    654
    655 unsigned ResumeInst::getNumSuccessorsV() const {
    656 return getNumSuccessors();
    657 }
    658
    659 void ResumeInst::setSuccessorV(unsigned idx, BasicBlock *NewSucc) {
    660 llvm_unreachable("ResumeInst has no successors!");
    661 }
    662
    663 BasicBlock *ResumeInst::getSuccessorV(unsigned idx) const {
    664 llvm_unreachable("ResumeInst has no successors!");
    665 return 0;
    666 }
    667
    668 //===----------------------------------------------------------------------===//
    576669 // UnreachableInst Implementation
    577670 //===----------------------------------------------------------------------===//
    578671
    591684 }
    592685
    593686 void UnreachableInst::setSuccessorV(unsigned idx, BasicBlock *NewSucc) {
    594 llvm_unreachable("UnwindInst has no successors!");
    687 llvm_unreachable("UnreachableInst has no successors!");
    595688 }
    596689
    597690 BasicBlock *UnreachableInst::getSuccessorV(unsigned idx) const {
    598 llvm_unreachable("UnwindInst has no successors!");
    691 llvm_unreachable("UnreachableInst has no successors!");
    599692 return 0;
    600693 }
    601694
    31213214 return new PHINode(*this);
    31223215 }
    31233216
    3217 LandingPadInst *LandingPadInst::clone_impl() const {
    3218 return new LandingPadInst(*this);
    3219 }
    3220
    31243221 ReturnInst *ReturnInst::clone_impl() const {
    31253222 return new(getNumOperands()) ReturnInst(*this);
    31263223 }
    31403237
    31413238 InvokeInst *InvokeInst::clone_impl() const {
    31423239 return new(getNumOperands()) InvokeInst(*this);
    3240 }
    3241
    3242 ResumeInst *ResumeInst::clone_impl() const {
    3243 return new(1) ResumeInst(*this);
    31433244 }
    31443245
    31453246 UnwindInst *UnwindInst::clone_impl() const {
    3434 // * It is illegal to have a ret instruction that returns a value that does not
    3535 // agree with the function return value type.
    3636 // * Function call argument types match the function prototype
    37 // * A landing pad is defined by a landingpad instruction, and can be jumped to
    38 // only by the unwind edge of an invoke instruction.
    39 // * A landingpad instruction must be the first non-PHI instruction in the
    40 // block.
    41 // * All landingpad instructions must use the same personality function with
    42 // the same function.
    3743 // * All other things that are tested by asserts spread about the code...
    3844 //
    3945 //===----------------------------------------------------------------------===//
    130136 /// already.
    131137 SmallPtrSet MDNodes;
    132138
    139 /// PersonalityFn - The personality function referenced by the
    140 /// LandingPadInsts. All LandingPadInsts within the same function must use
    141 /// the same personality function.
    142 const Value *PersonalityFn;
    143
    133144 Verifier()
    134 : FunctionPass(ID),
    135 Broken(false), RealPass(true), action(AbortProcessAction),
    136 Mod(0), Context(0), DT(0), MessagesStr(Messages) {
    137 initializeVerifierPass(*PassRegistry::getPassRegistry());
    138 }
    145 : FunctionPass(ID), Broken(false), RealPass(true),
    146 action(AbortProcessAction), Mod(0), Context(0), DT(0),
    147 MessagesStr(Messages), PersonalityFn(0) {
    148 initializeVerifierPass(*PassRegistry::getPassRegistry());
    149 }
    139150 explicit Verifier(VerifierFailureAction ctn)
    140 : FunctionPass(ID),
    141 Broken(false), RealPass(true), action(ctn), Mod(0), Context(0), DT(0),
    142 MessagesStr(Messages) {
    143 initializeVerifierPass(*PassRegistry::getPassRegistry());
    144 }
    151 : FunctionPass(ID), Broken(false), RealPass(true), action(ctn), Mod(0),
    152 Context(0), DT(0), MessagesStr(Messages), PersonalityFn(0) {
    153 initializeVerifierPass(*PassRegistry::getPassRegistry());
    154 }
    145155
    146156 bool doInitialization(Module &M) {
    147157 Mod = &M;
    281291 void visitAllocaInst(AllocaInst &AI);
    282292 void visitExtractValueInst(ExtractValueInst &EVI);
    283293 void visitInsertValueInst(InsertValueInst &IVI);
    294 void visitLandingPadInst(LandingPadInst &LPI);
    284295
    285296 void VerifyCallSite(CallSite CS);
    286297 bool PerformTypeCheck(Intrinsic::ID ID, Function *F, Type *Ty,
    13201331 Assert1(Ordering == Acquire || Ordering == Release ||
    13211332 Ordering == AcquireRelease || Ordering == SequentiallyConsistent,
    13221333 "fence instructions may only have "
    1323 " acquire, release, acq_rel, or seq_cst ordering.", &FI);
    1334 "acquire, release, acq_rel, or seq_cst ordering.", &FI);
    13241335 visitInstruction(FI);
    13251336 }
    13261337
    13401351 "Invalid InsertValueInst operands!", &IVI);
    13411352
    13421353 visitInstruction(IVI);
    1354 }
    1355
    1356 void Verifier::visitLandingPadInst(LandingPadInst &LPI) {
    1357 BasicBlock *BB = LPI.getParent();
    1358
    1359 // The landingpad instruction is ill-formed if it doesn't have any clauses and
    1360 // isn't a cleanup.
    1361 Assert1(LPI.getNumClauses() > 0 || LPI.isCleanup(),
    1362 "LandingPadInst needs at least one clause or to be a cleanup.", &LPI);
    1363
    1364 // The landingpad instruction defines its parent as a landing pad block. The
    1365 // landing pad block may be branched to only by the unwind edge of an invoke.
    1366 for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) {
    1367 const InvokeInst *II = dyn_cast((*I)->getTerminator());
    1368 Assert1(II && II->getUnwindDest() == BB,
    1369 "Block containing LandingPadInst must be jumped to "
    1370 "only by the unwind edge of an invoke.", &LPI);
    1371 }
    1372
    1373 // The landingpad instruction must be the first non-PHI instruction in the
    1374 // block.
    1375 BasicBlock::iterator I = BB->begin(), E = BB->end();
    1376 while (I != E && isa(I))
    1377 ++I;
    1378 Assert1(I != E && isa(I) && I == LPI,
    1379 "LandingPadInst not the first non-PHI instruction in the block.",
    1380 &LPI);
    1381
    1382 // The personality functions for all landingpad instructions within the same
    1383 // function should match.
    1384 if (PersonalityFn)
    1385 Assert1(LPI.getPersonalityFn() == PersonalityFn,
    1386 "Personality function doesn't match others in function", &LPI);
    1387 PersonalityFn = LPI.getPersonalityFn();
    1388
    1389 visitInstruction(LPI);
    13431390 }
    13441391
    13451392 /// verifyInstruction - Verify that an instruction is well formed.
    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 @_ZTIc = external constant i8*
    5 @_ZTId = external constant i8*
    6 @_ZTIPKc = external constant i8*
    7 @.str = private unnamed_addr constant [16 x i8] c"caught char %c\0A\00", align 1
    8
    9 define void @_Z3barv() uwtable optsize alwaysinline ssp {
    10 entry:
    11 invoke void @_Z3quxv() optsize
    12 to label %try.cont unwind label %lpad
    13
    14 invoke.cont4: ; preds = %lpad
    15 %eh.obj = extractvalue {i8*, i32} %exn, 0
    16 %tmp0 = tail call i8* @__cxa_begin_catch(i8* %eh.obj) nounwind
    17 %exn.scalar = load i8* %tmp0, align 1
    18 %conv = sext i8 %exn.scalar to i32
    19 %call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([16 x i8]* @.str, i64 0, i64 0), i32 %conv) optsize
    20 tail call void @__cxa_end_catch() nounwind
    21 br label %try.cont
    22
    23 try.cont: ; preds = %entry, %invoke.cont4
    24 ret void
    25
    26 lpad: ; preds = %entry
    27 %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
    28 cleanup
    29 catch i8** @_ZTIc
    30 filter i8** @_ZTIPKc
    31 catch i8** @_ZTId
    32 %tmp1 = extractvalue {i8*, i32} %exn, 1
    33 %tmp2 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIc to i8*)) nounwind
    34 %tmp3 = icmp eq i32 %tmp1, %tmp2
    35 br i1 %tmp3, label %invoke.cont4, label %eh.resume
    36
    37 eh.resume:
    38 resume { i8*, i32 } %exn
    39 }
    40
    41 declare void @_Z3quxv() optsize
    42
    43 declare i32 @__gxx_personality_v0(...)
    44
    45 declare i32 @llvm.eh.typeid.for(i8*) nounwind
    46
    47 declare void @llvm.eh.resume(i8*, i32)
    48
    49 declare i8* @__cxa_begin_catch(i8*)
    50
    51 declare i32 @printf(i8* nocapture, ...) nounwind optsize
    52
    53 declare void @__cxa_end_catch()