llvm.org GIT mirror llvm / 10c6d12
Revert r136253, r136263, r136269, r136313, r136325, r136326, r136329, r136338, r136339, r136341, r136369, r136387, r136392, r136396, r136429, r136430, r136444, r136445, r136446, r136253 pending review. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136556 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 9 years ago
31 changed file(s) with 112 addition(s) and 1036 deletion(s). Raw diff Collapse all Expand all
123123
  • 'indirectbr' Instruction
  • 124124
  • 'invoke' Instruction
  • 125125
  • 'unwind' Instruction
  • 126
  • 'resume' Instruction
  • 127126
  • 'unreachable' Instruction
  • 128127
    129128
    30233022 control flow, not values (the one exception being the
    30243023 'invoke' instruction).

    30253024
    3026

    There are eight different terminator instructions: the

    3025

    There are seven different terminator instructions: the

    30273026 'ret' instruction, the
    30283027 'br' instruction, the
    30293028 'switch' instruction, the
    30303029 ''indirectbr' Instruction, the
    30313030 'invoke' instruction, the
    3032 'unwind' instruction, the
    3033 'resume' instruction, and the
    3031 'unwind' instruction, and the
    30343032 'unreachable' instruction.

    30353033
    30363034
    33483346
    33493347

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

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

    3351
    3352
    3353
    3354
    3355
    3356

    3357 'resume' Instruction
    3358
    3359
    3360
    3361
    3362
    Syntax:
    3363
    
                      
                    
    3364 resume <type> <value>
    3365
    3366
    3367
    Overview:
    3368

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

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

    3371
    3372
    Semantics:
    3373

    The 'resume' instruction resumes propagation of an existing

    3374 (in-flight) exception.

    3375
    3376
    Example:
    3377
    
                      
                    
    3378 resume { i8*, i32 } %exn
    3379
    33803349
    33813350
    33823351
    273273 FUNC_CODE_INST_UNREACHABLE = 15, // UNREACHABLE
    274274
    275275 FUNC_CODE_INST_PHI = 16, // PHI: [ty, val0,bb0, ...]
    276 FUNC_CODE_INST_RESUME = 17, // RESUME: [opval]
    276 // 17 is unused.
    277277 // 18 is unused.
    278278 FUNC_CODE_INST_ALLOCA = 19, // ALLOCA: [instty, op, align]
    279279 FUNC_CODE_INST_LOAD = 20, // LOAD: [opty, op, align, vol]
    301301
    302302 FUNC_CODE_DEBUG_LOC = 35, // DEBUG_LOC: [Line,Col,ScopeVal, IAVal]
    303303 FUNC_CODE_INST_FENCE = 36, // FENCE: [ordering, synchscope]
    304 FUNC_CODE_INST_LANDINGPAD = 37, // LANDINGPAD: [ty,val,val,num,id0,val0...]
    305 FUNC_CODE_INST_CMPXCHG = 38, // CMPXCHG: [ptrty,ptr,cmp,new, align, vol,
    304 FUNC_CODE_INST_CMPXCHG = 37, // CMPXCHG: [ptrty,ptr,cmp,new, align, vol,
    306305 // ordering, synchscope]
    307 FUNC_CODE_INST_ATOMICRMW = 39 // ATOMICRMW: [ptrty,ptr,val, operation,
    306 FUNC_CODE_INST_ATOMICRMW = 38 // ATOMICRMW: [ptrty,ptr,val, operation,
    308307 // align, vol,
    309308 // ordering, synchscope]
    310
    311309 };
    312310 } // End bitc namespace
    313311 } // End llvm namespace
    219219 void CopyCatchInfo(const BasicBlock *SuccBB, const BasicBlock *LPad,
    220220 MachineModuleInfo *MMI, FunctionLoweringInfo &FLI);
    221221
    222 /// AddLandingPadInfo - Extract the exception handling information from the
    223 /// landingpad instruction and add them to the specified machine module info.
    224 void AddLandingPadInfo(const LandingPadInst &I, MachineModuleInfo &MMI,
    225 MachineBasicBlock *MBB);
    226
    227222 } // end namespace llvm
    228223
    229224 #endif
    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, Resume , ResumeInst)
    103 HANDLE_TERM_INST ( 8, Unreachable, UnreachableInst)
    104 LAST_TERM_INST ( 8)
    102 HANDLE_TERM_INST ( 7, Unreachable, UnreachableInst)
    103 LAST_TERM_INST ( 7)
    105104
    106105 // Standard binary operators...
    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)
    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)
    120119
    121120 // Logical operators (integer operands)
    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)
    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)
    129128
    130129 // Memory operators...
    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 HANDLE_MEMORY_INST(32, AtomicCmpXchg , AtomicCmpXchgInst )
    138 HANDLE_MEMORY_INST(33, AtomicRMW , AtomicRMWInst )
    139 LAST_MEMORY_INST(33)
    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 HANDLE_MEMORY_INST(31, AtomicCmpXchg , AtomicCmpXchgInst )
    137 HANDLE_MEMORY_INST(32, AtomicRMW , AtomicRMWInst )
    138 LAST_MEMORY_INST(32)
    140139
    141140 // Cast operators ...
    142141 // NOTE: The order matters here because CastInst::isEliminableCastPair
    143142 // NOTE: (see Instructions.cpp) encodes a table based on this ordering.
    144 FIRST_CAST_INST(34)
    145 HANDLE_CAST_INST(34, Trunc , TruncInst ) // Truncate integers
    146 HANDLE_CAST_INST(35, ZExt , ZExtInst ) // Zero extend integers
    147 HANDLE_CAST_INST(36, SExt , SExtInst ) // Sign extend integers
    148 HANDLE_CAST_INST(37, FPToUI , FPToUIInst ) // floating point -> UInt
    149 HANDLE_CAST_INST(38, FPToSI , FPToSIInst ) // floating point -> SInt
    150 HANDLE_CAST_INST(39, UIToFP , UIToFPInst ) // UInt -> floating point
    151 HANDLE_CAST_INST(40, SIToFP , SIToFPInst ) // SInt -> floating point
    152 HANDLE_CAST_INST(41, FPTrunc , FPTruncInst ) // Truncate floating point
    153 HANDLE_CAST_INST(42, FPExt , FPExtInst ) // Extend floating point
    154 HANDLE_CAST_INST(43, PtrToInt, PtrToIntInst) // Pointer -> Integer
    155 HANDLE_CAST_INST(44, IntToPtr, IntToPtrInst) // Integer -> Pointer
    156 HANDLE_CAST_INST(45, BitCast , BitCastInst ) // Type cast
    157 LAST_CAST_INST(45)
    143 FIRST_CAST_INST(33)
    144 HANDLE_CAST_INST(33, Trunc , TruncInst ) // Truncate integers
    145 HANDLE_CAST_INST(34, ZExt , ZExtInst ) // Zero extend integers
    146 HANDLE_CAST_INST(35, SExt , SExtInst ) // Sign extend integers
    147 HANDLE_CAST_INST(36, FPToUI , FPToUIInst ) // floating point -> UInt
    148 HANDLE_CAST_INST(37, FPToSI , FPToSIInst ) // floating point -> SInt
    149 HANDLE_CAST_INST(38, UIToFP , UIToFPInst ) // UInt -> floating point
    150 HANDLE_CAST_INST(39, SIToFP , SIToFPInst ) // SInt -> floating point
    151 HANDLE_CAST_INST(40, FPTrunc , FPTruncInst ) // Truncate floating point
    152 HANDLE_CAST_INST(41, FPExt , FPExtInst ) // Extend floating point
    153 HANDLE_CAST_INST(42, PtrToInt, PtrToIntInst) // Pointer -> Integer
    154 HANDLE_CAST_INST(43, IntToPtr, IntToPtrInst) // Integer -> Pointer
    155 HANDLE_CAST_INST(44, BitCast , BitCastInst ) // Type cast
    156 LAST_CAST_INST(44)
    158157
    159158 // Other operators...
    160 FIRST_OTHER_INST(46)
    161 HANDLE_OTHER_INST(46, ICmp , ICmpInst ) // Integer comparison instruction
    162 HANDLE_OTHER_INST(47, FCmp , FCmpInst ) // Floating point comparison instr.
    163 HANDLE_OTHER_INST(48, PHI , PHINode ) // PHI node instruction
    164 HANDLE_OTHER_INST(49, Call , CallInst ) // Call a function
    165 HANDLE_OTHER_INST(50, Select , SelectInst ) // select instruction
    166 HANDLE_OTHER_INST(51, UserOp1, Instruction) // May be used internally in a pass
    167 HANDLE_OTHER_INST(52, UserOp2, Instruction) // Internal to passes only
    168 HANDLE_OTHER_INST(53, VAArg , VAArgInst ) // vaarg instruction
    169 HANDLE_OTHER_INST(54, ExtractElement, ExtractElementInst)// extract from vector
    170 HANDLE_OTHER_INST(55, InsertElement, InsertElementInst) // insert into vector
    171 HANDLE_OTHER_INST(56, ShuffleVector, ShuffleVectorInst) // shuffle two vectors.
    172 HANDLE_OTHER_INST(57, ExtractValue, ExtractValueInst)// extract from aggregate
    173 HANDLE_OTHER_INST(58, InsertValue, InsertValueInst) // insert into aggregate
    174 HANDLE_OTHER_INST(59, LandingPad, LandingPadInst) // Landing pad instruction.
    175 LAST_OTHER_INST(59)
    159 FIRST_OTHER_INST(45)
    160 HANDLE_OTHER_INST(45, ICmp , ICmpInst ) // Integer comparison instruction
    161 HANDLE_OTHER_INST(46, FCmp , FCmpInst ) // Floating point comparison instr.
    162 HANDLE_OTHER_INST(47, PHI , PHINode ) // PHI node instruction
    163 HANDLE_OTHER_INST(48, Call , CallInst ) // Call a function
    164 HANDLE_OTHER_INST(49, Select , SelectInst ) // select instruction
    165 HANDLE_OTHER_INST(50, UserOp1, Instruction) // May be used internally in a pass
    166 HANDLE_OTHER_INST(51, UserOp2, Instruction) // Internal to passes only
    167 HANDLE_OTHER_INST(52, VAArg , VAArgInst ) // vaarg instruction
    168 HANDLE_OTHER_INST(53, ExtractElement, ExtractElementInst)// extract from vector
    169 HANDLE_OTHER_INST(54, InsertElement, InsertElementInst) // insert into vector
    170 HANDLE_OTHER_INST(55, ShuffleVector, ShuffleVectorInst) // shuffle two vectors.
    171 HANDLE_OTHER_INST(56, ExtractValue, ExtractValueInst)// extract from aggregate
    172 HANDLE_OTHER_INST(57, InsertValue, InsertValueInst) // insert into aggregate
    173
    174 LAST_OTHER_INST(57)
    176175
    177176 #undef FIRST_TERM_INST
    178177 #undef HANDLE_TERM_INST
    20272027
    20282028 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
    20292029
    2030 //===----------------------------------------------------------------------===//
    2031 // LandingPadInst Class
    2032 //===----------------------------------------------------------------------===//
    2033
    2034 //===---------------------------------------------------------------------------
    2035 /// LandingPadInst - The landingpad instruction holds all of the information
    2036 /// necessary to generate correct exception handling. The landingpad instruction
    2037 /// cannot be moved from the top of a landing pad block, which itself is
    2038 /// accessible only from the 'unwind' edge of an invoke.
    2039 ///
    2040 class LandingPadInst : public Instruction {
    2041 /// ReservedSpace - The number of operands actually allocated. NumOperands is
    2042 /// the number actually in use.
    2043 unsigned ReservedSpace;
    2044
    2045 /// IsCleanup - True if the landingpad instruction is also a cleanup.
    2046 bool IsCleanup;
    2047 LandingPadInst(const LandingPadInst &LP);
    2048 public:
    2049 enum ClauseType { Catch, Filter };
    2050 private:
    2051 /// ClauseIdxs - This indexes into the OperandList, indicating what the
    2052 /// values are at a given index.
    2053 SmallVector ClauseIdxs;
    2054
    2055 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
    2056 // Allocate space for exactly zero operands.
    2057 void *operator new(size_t s) {
    2058 return User::operator new(s, 0);
    2059 }
    2060 void growOperands();
    2061 void init(Function *PersFn, unsigned NumReservedValues, const Twine &NameStr);
    2062
    2063 explicit LandingPadInst(Type *RetTy, Function *PersonalityFn,
    2064 unsigned NumReservedValues, const Twine &NameStr,
    2065 Instruction *InsertBefore)
    2066 : Instruction(RetTy, Instruction::LandingPad, 0, 0, InsertBefore),
    2067 IsCleanup(false) {
    2068 init(PersonalityFn, 1 + NumReservedValues, NameStr);
    2069 }
    2070 explicit LandingPadInst(Type *RetTy, Function *PersonalityFn,
    2071 unsigned NumReservedValues, const Twine &NameStr,
    2072 BasicBlock *InsertAtEnd)
    2073 : Instruction(RetTy, Instruction::LandingPad, 0, 0, InsertAtEnd),
    2074 IsCleanup(false) {
    2075 init(PersonalityFn, 1 + NumReservedValues, NameStr);
    2076 }
    2077 protected:
    2078 virtual LandingPadInst *clone_impl() const;
    2079 public:
    2080 static LandingPadInst *Create(Type *RetTy, Function *PersonalityFn,
    2081 unsigned NumReservedValues,
    2082 const Twine &NameStr = "",
    2083 Instruction *InsertBefore = 0) {
    2084 return new LandingPadInst(RetTy, PersonalityFn, NumReservedValues, NameStr,
    2085 InsertBefore);
    2086 }
    2087 static LandingPadInst *Create(Type *RetTy, Function *PersonalityFn,
    2088 unsigned NumReservedValues,
    2089 const Twine &NameStr, BasicBlock *InsertAtEnd) {
    2090 return new LandingPadInst(RetTy, PersonalityFn, NumReservedValues, NameStr,
    2091 InsertAtEnd);
    2092 }
    2093 ~LandingPadInst();
    2094
    2095 /// Provide fast operand accessors
    2096 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
    2097
    2098 /// getPersonalityFn - Get the personality function associated with this
    2099 /// landing pad.
    2100 const Function *getPersonalityFn() const {
    2101 return cast(getOperand(0));
    2102 }
    2103
    2104 // Simple accessors.
    2105 bool isCleanup() const { return IsCleanup; }
    2106 void setCleanup(bool Val) { IsCleanup = Val; }
    2107
    2108 /// addClause - Add a clause to the landing pad.
    2109 void addClause(ClauseType CT, Constant *ClauseVal);
    2110
    2111 /// getClauseType - Return the type of the clause at this index. The two
    2112 /// supported clauses are Catch and Filter.
    2113 ClauseType getClauseType(unsigned I) const {
    2114 assert(I < ClauseIdxs.size() && "Index too large!");
    2115 return ClauseIdxs[I];
    2116 }
    2117
    2118 /// getClauseValue - Return the value of the clause at this index.
    2119 Constant *getClauseValue(unsigned I) const {
    2120 assert(I + 1 < getNumOperands() && "Index too large!");
    2121 return cast(OperandList[I + 1]);
    2122 }
    2123
    2124 /// getNumClauses - Get the number of clauses for this landing pad.
    2125 unsigned getNumClauses() const { return getNumOperands() - 1; }
    2126
    2127 /// reserveClauses - Grow the size of the operand list to accomodate the new
    2128 /// number of clauses.
    2129 void reserveClauses(unsigned Size);
    2130
    2131 // Methods for support type inquiry through isa, cast, and dyn_cast:
    2132 static inline bool classof(const LandingPadInst *) { return true; }
    2133 static inline bool classof(const Instruction *I) {
    2134 return I->getOpcode() == Instruction::LandingPad;
    2135 }
    2136 static inline bool classof(const Value *V) {
    2137 return isa(V) && classof(cast(V));
    2138 }
    2139 };
    2140
    2141 template <>
    2142 struct OperandTraits : public HungoffOperandTraits<2> {
    2143 };
    2144
    2145 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
    21462030
    21472031 //===----------------------------------------------------------------------===//
    21482032 // ReturnInst Class
    27322616 Op<-1>() = reinterpret_cast(B);
    27332617 }
    27342618
    2735 // getLandingPad - Get the landingpad instruction from the landing pad block
    2736 // (the unwind destination).
    2737 LandingPadInst *getLandingPad() const;
    2738
    27392619 BasicBlock *getSuccessor(unsigned i) const {
    27402620 assert(i < 2 && "Successor # out of range for invoke!");
    27412621 return i == 0 ? getNormalDest() : getUnwindDest();
    28352715 };
    28362716
    28372717 //===----------------------------------------------------------------------===//
    2838 // ResumeInst Class
    2839 //===----------------------------------------------------------------------===//
    2840
    2841 //===---------------------------------------------------------------------------
    2842 /// ResumeInst - Resume the propagation of an exception.
    2843 ///
    2844 class ResumeInst : public TerminatorInst {
    2845 ResumeInst(const ResumeInst &RI);
    2846
    2847 explicit ResumeInst(LLVMContext &C, Value *Exn, Instruction *InsertBefore=0);
    2848 ResumeInst(LLVMContext &C, Value *Exn, BasicBlock *InsertAtEnd);
    2849 protected:
    2850 virtual ResumeInst *clone_impl() const;
    2851 public:
    2852 static ResumeInst *Create(LLVMContext &C, Value *Exn,
    2853 Instruction *InsertBefore = 0) {
    2854 return new(1) ResumeInst(C, Exn, InsertBefore);
    2855 }
    2856 static ResumeInst *Create(LLVMContext &C, Value *Exn,
    2857 BasicBlock *InsertAtEnd) {
    2858 return new(1) ResumeInst(C, Exn, InsertAtEnd);
    2859 }
    2860
    2861 /// Provide fast operand accessors
    2862 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
    2863
    2864 /// Convenience accessor.
    2865 Value *getResumeValue() const { return Op<0>(); }
    2866
    2867 unsigned getNumSuccessors() const { return 0; }
    2868
    2869 // Methods for support type inquiry through isa, cast, and dyn_cast:
    2870 static inline bool classof(const ResumeInst *) { return true; }
    2871 static inline bool classof(const Instruction *I) {
    2872 return I->getOpcode() == Instruction::Resume;
    2873 }
    2874 static inline bool classof(const Value *V) {
    2875 return isa(V) && classof(cast(V));
    2876 }
    2877 private:
    2878 virtual BasicBlock *getSuccessorV(unsigned idx) const;
    2879 virtual unsigned getNumSuccessorsV() const;
    2880 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
    2881 };
    2882
    2883 template <>
    2884 struct OperandTraits :
    2885 public FixedNumOperandTraits {
    2886 };
    2887
    2888 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
    2889
    2890 //===----------------------------------------------------------------------===//
    28912718 // UnreachableInst Class
    28922719 //===----------------------------------------------------------------------===//
    28932720
    478478 return Insert(new UnwindInst(Context));
    479479 }
    480480
    481 ResumeInst *CreateResume(Value *Exn) {
    482 return Insert(ResumeInst::Create(Context, Exn));
    483 }
    484
    485481 UnreachableInst *CreateUnreachable() {
    486482 return Insert(new UnreachableInst(Context));
    487483 }
    12051201 if (Constant *ValC = dyn_cast(Val))
    12061202 return Insert(Folder.CreateInsertValue(AggC, ValC, Idxs), Name);
    12071203 return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
    1208 }
    1209
    1210 Value *CreateLandingPad(Type *Ty, Function *PersFn, unsigned NumClauses,
    1211 const Twine &Name = "") {
    1212 return Insert(LandingPadInst::Create(Ty, PersFn, NumClauses, Name));
    12131204 }
    12141205
    12151206 //===--------------------------------------------------------------------===//
    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);}
    166165 RetTy visitUnreachableInst(UnreachableInst &I) { DELEGATE(TerminatorInst);}
    167166 RetTy visitICmpInst(ICmpInst &I) { DELEGATE(CmpInst);}
    168167 RetTy visitFCmpInst(FCmpInst &I) { DELEGATE(CmpInst);}
    194193 RetTy visitShuffleVectorInst(ShuffleVectorInst &I) { DELEGATE(Instruction); }
    195194 RetTy visitExtractValueInst(ExtractValueInst &I) { DELEGATE(Instruction);}
    196195 RetTy visitInsertValueInst(InsertValueInst &I) { DELEGATE(Instruction); }
    197 RetTy visitLandingPadInst(LandingPadInst &I) { DELEGATE(Instruction); }
    198196
    199197 // Next level propagators: If the user does not overload a specific
    200198 // instruction type, they can overload one of these to get the whole class
    187187 /* Atomic operators */
    188188 LLVMFence = 55,
    189189 LLVMAtomicCmpXchg = 56,
    190 LLVMAtomicRMW = 57,
    191
    192 /* Exception Handling Operators */
    193 LLVMLandingPad = 58,
    194 LLVMResume = 59
    190 LLVMAtomicRMW = 57
    195191
    196192 } LLVMOpcode;
    197193
    282278 LLVMRealUNE, /**< True if unordered or not equal */
    283279 LLVMRealPredicateTrue /**< Always true (always folded) */
    284280 } LLVMRealPredicate;
    285
    286 typedef enum {
    287 LLVMCatch, /**< A catch clause */
    288 LLVMFilter /**< A filter clause */
    289 } LLVMLandingPadClauseTy;
    290281
    291282 void LLVMInitializeCore(LLVMPassRegistryRef R);
    292283
    474465 macro(GetElementPtrInst) \
    475466 macro(InsertElementInst) \
    476467 macro(InsertValueInst) \
    477 macro(LandingPadInst) \
    478468 macro(PHINode) \
    479469 macro(SelectInst) \
    480470 macro(ShuffleVectorInst) \
    486476 macro(SwitchInst) \
    487477 macro(UnreachableInst) \
    488478 macro(UnwindInst) \
    489 macro(ResumeInst) \
    490479 macro(UnaryInstruction) \
    491480 macro(AllocaInst) \
    492481 macro(CastInst) \
    835824 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
    836825 const char *Name);
    837826 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
    838 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
    839827 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
    840828
    841829 /* Add a case to the switch instruction */
    844832
    845833 /* Add a destination to the indirectbr instruction */
    846834 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
    847
    848 /* Add a clause to the landingpad instruction */
    849 void LLVMAddClause(LLVMValueRef LandingPad, LLVMLandingPadClauseTy ClauseTy,
    850 LLVMValueRef ClauseVal);
    851
    852 /* Set the 'cleanup' flag in the landingpad instruction */
    853 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
    854835
    855836 /* Arithmetic */
    856837 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
    583583
    584584 KEYWORD(x);
    585585 KEYWORD(blockaddress);
    586
    587 KEYWORD(personality);
    588 KEYWORD(cleanup);
    589 KEYWORD(catch);
    590 KEYWORD(filter);
    591586 #undef KEYWORD
    592587
    593588 // Keywords for types.
    640635 INSTKEYWORD(switch, Switch);
    641636 INSTKEYWORD(indirectbr, IndirectBr);
    642637 INSTKEYWORD(invoke, Invoke);
    643 INSTKEYWORD(resume, Resume);
    644638 INSTKEYWORD(unwind, Unwind);
    645639 INSTKEYWORD(unreachable, Unreachable);
    646640
    657651 INSTKEYWORD(shufflevector, ShuffleVector);
    658652 INSTKEYWORD(extractvalue, ExtractValue);
    659653 INSTKEYWORD(insertvalue, InsertValue);
    660 INSTKEYWORD(landingpad, LandingPad);
    661654 #undef INSTKEYWORD
    662655
    663656 // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
    684677 CurPtr = TokStart+1;
    685678 return lltok::Error;
    686679 }
    680
    687681
    688682 /// Lex0x: Handle productions that start with 0x, knowing that it matches and
    689683 /// 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);
    28882887 // Binary Operators.
    28892888 case lltok::kw_add:
    28902889 case lltok::kw_sub:
    29442943 case lltok::kw_insertelement: return ParseInsertElement(Inst, PFS);
    29452944 case lltok::kw_shufflevector: return ParseShuffleVector(Inst, PFS);
    29462945 case lltok::kw_phi: return ParsePHI(Inst, PFS);
    2947 case lltok::kw_landingpad: return ParseLandingPad(Inst, PFS);
    29482946 case lltok::kw_call: return ParseCall(Inst, PFS, false);
    29492947 case lltok::kw_tail: return ParseCall(Inst, PFS, true);
    29502948 // Memory.
    32543252 return false;
    32553253 }
    32563254
    3257 /// ParseResume
    3258 /// ::= 'resume' TypeAndValue
    3259 bool LLParser::ParseResume(Instruction *&Inst, PerFunctionState &PFS) {
    3260 Value *Exn; LocTy ExnLoc;
    3261 LocTy Loc = Lex.getLoc();
    3262 if (ParseTypeAndValue(Exn, ExnLoc, PFS))
    3263 return true;
    3264
    3265 ResumeInst *RI = ResumeInst::Create(Context, Exn);
    3266 Inst = RI;
    3267 return false;
    3268 }
    3255
    32693256
    32703257 //===----------------------------------------------------------------------===//
    32713258 // Binary Operators.
    35113498 PN->addIncoming(PHIVals[i].first, PHIVals[i].second);
    35123499 Inst = PN;
    35133500 return AteExtraComma ? InstExtraComma : InstNormal;
    3514 }
    3515
    3516 /// ParseLandingPad
    3517 /// ::= 'landingpad' Type 'personality' TypeAndValue 'cleanup'?
    3518 /// (ClauseID ClauseList)+
    3519 /// ClauseID
    3520 /// ::= 'catch'
    3521 /// ::= 'filter'
    3522 /// ClauseList
    3523 /// ::= TypeAndValue (',' TypeAndValue)*
    3524 bool LLParser::ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS) {
    3525 Type *Ty = 0; LocTy TyLoc;
    3526 Value *PersFn; LocTy PersFnLoc;
    3527 LocTy LPLoc = Lex.getLoc();
    3528
    3529 if (ParseType(Ty, TyLoc) ||
    3530 ParseToken(lltok::kw_personality, "expected 'personality'") ||
    3531 ParseTypeAndValue(PersFn, PersFnLoc, PFS))
    3532 return true;
    3533
    3534 bool IsCleanup = EatIfPresent(lltok::kw_cleanup);
    3535
    3536 SmallVector, 16> Clauses;
    3537 while (Lex.getKind() == lltok::kw_catch || Lex.getKind() == lltok::kw_filter){
    3538 LandingPadInst::ClauseType CT;
    3539 if (Lex.getKind() == lltok::kw_catch) {
    3540 CT = LandingPadInst::Catch;
    3541 ParseToken(lltok::kw_catch, "expected 'catch'");
    3542 } else {
    3543 CT = LandingPadInst::Filter;
    3544 ParseToken(lltok::kw_filter, "expected 'filter'");
    3545 }
    3546
    3547 do {
    3548 Value *V; LocTy VLoc;
    3549 if (ParseTypeAndValue(V, VLoc, PFS))
    3550 return true;
    3551 Clauses.push_back(std::make_pair(CT, cast(V)));
    3552 } while (EatIfPresent(lltok::comma));
    3553 }
    3554
    3555 LandingPadInst *LP = LandingPadInst::Create(Ty, cast(PersFn),
    3556 Clauses.size());
    3557 LP->setCleanup(IsCleanup);
    3558
    3559 for (SmallVectorImpl
    3560 Constant*> >::iterator
    3561 I = Clauses.begin(), E = Clauses.end(); I != E; ++I)
    3562 LP->addClause(I->first, I->second);
    3563
    3564 Inst = LP;
    3565 return false;
    35663501 }
    35673502
    35683503 /// ParseCall
    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);
    350349
    351350 bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc,
    352351 unsigned OperandType);
    359358 bool ParseInsertElement(Instruction *&I, PerFunctionState &PFS);
    360359 bool ParseShuffleVector(Instruction *&I, PerFunctionState &PFS);
    361360 int ParsePHI(Instruction *&I, PerFunctionState &PFS);
    362 bool ParseLandingPad(Instruction *&I, PerFunctionState &PFS);
    363361 bool ParseCall(Instruction *&I, PerFunctionState &PFS, bool isTail);
    364362 int ParseAlloc(Instruction *&I, PerFunctionState &PFS);
    365363 int ParseLoad(Instruction *&I, PerFunctionState &PFS, bool isVolatile);
    123123 kw_fptoui, kw_fptosi, kw_inttoptr, kw_ptrtoint, kw_bitcast,
    124124 kw_select, kw_va_arg,
    125125
    126 kw_landingpad, kw_personality, kw_cleanup, kw_catch, kw_filter,
    127
    128 kw_ret, kw_br, kw_switch, kw_indirectbr, kw_invoke, kw_unwind, kw_resume,
    126 kw_ret, kw_br, kw_switch, kw_indirectbr, kw_invoke, kw_unwind,
    129127 kw_unreachable,
    130128
    131129 kw_alloca, kw_load, kw_store, kw_fence, kw_cmpxchg, kw_atomicrmw,
    148146 // Type valued tokens (TyVal).
    149147 Type,
    150148
    151 APFloat, // APFloatVal
    152 APSInt // APSInt
    149 APFloat, // APFloatVal
    150 APSInt // APSInt
    153151 };
    154152 } // end namespace lltok
    155153 } // end namespace llvm
    25072507 cast(I)->setAttributes(PAL);
    25082508 break;
    25092509 }
    2510 case bitc::FUNC_CODE_INST_RESUME: { // RESUME: [opval]
    2511 unsigned Idx = 0;
    2512 Value *Val = 0;
    2513 if (getValueTypePair(Record, Idx, NextValueNo, Val))
    2514 return Error("Invalid RESUME record");
    2515 I = ResumeInst::Create(Context, Val);
    2516 break;
    2517 }
    25182510 case bitc::FUNC_CODE_INST_UNWIND: // UNWIND
    25192511 I = new UnwindInst(Context);
    25202512 InstructionList.push_back(I);
    25392531 PN->addIncoming(V, BB);
    25402532 }
    25412533 I = PN;
    2542 break;
    2543 }
    2544
    2545 case bitc::FUNC_CODE_INST_LANDINGPAD: {
    2546 // LANDINGPAD: [ty, val, val, num, (id0,val0 ...)?]
    2547 unsigned Idx = 0;
    2548 if (Record.size() < 4)
    2549 return Error("Invalid LANDINGPAD record");
    2550 Type *Ty = getTypeByID(Record[Idx++]);
    2551 if (!Ty) return Error("Invalid LANDINGPAD record");
    2552 Value *PersFn = 0;
    2553 if (getValueTypePair(Record, Idx, NextValueNo, PersFn))
    2554 return Error("Invalid LANDINGPAD record");
    2555
    2556 bool IsCleanup = !!Record[Idx++];
    2557 unsigned NumClauses = Record[Idx++];
    2558 LandingPadInst *LP = LandingPadInst::Create(Ty, cast(PersFn),
    2559 NumClauses);
    2560 LP->setCleanup(IsCleanup);
    2561 for (unsigned J = 0; J != NumClauses; ++J) {
    2562 LandingPadInst::ClauseType CT =
    2563 LandingPadInst::ClauseType(Record[Idx++]);
    2564 Value *Val = 0;
    2565 if (getValueTypePair(Record, Idx, NextValueNo, Val)) {
    2566 delete LP;
    2567 return Error("Invalid LANDINGPAD record");
    2568 }
    2569
    2570 LP->addClause(CT, cast(Val));
    2571 }
    2572
    2573 I = LP;
    25742534 break;
    25752535 }
    25762536
    11421142 }
    11431143 break;
    11441144 }
    1145 case Instruction::Resume:
    1146 Code = bitc::FUNC_CODE_INST_RESUME;
    1147 PushValueAndType(I.getOperand(0), InstID, Vals, VE);
    1148 break;
    11491145 case Instruction::Unwind:
    11501146 Code = bitc::FUNC_CODE_INST_UNWIND;
    11511147 break;
    11611157 for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) {
    11621158 Vals.push_back(VE.getValueID(PN.getIncomingValue(i)));
    11631159 Vals.push_back(VE.getValueID(PN.getIncomingBlock(i)));
    1164 }
    1165 break;
    1166 }
    1167
    1168 case Instruction::LandingPad: {
    1169 const LandingPadInst &LP = cast(I);
    1170 Code = bitc::FUNC_CODE_INST_LANDINGPAD;
    1171 Vals.push_back(VE.getTypeID(LP.getType()));
    1172 PushValueAndType(LP.getPersonalityFn(), InstID, Vals, VE);
    1173 Vals.push_back(LP.isCleanup());
    1174 Vals.push_back(LP.getNumClauses());
    1175 for (unsigned I = 0, E = LP.getNumClauses(); I != E; ++I) {
    1176 Vals.push_back(LP.getClauseType(I));
    1177 PushValueAndType(LP.getClauseValue(I), InstID, Vals, VE);
    11781160 }
    11791161 break;
    11801162 }
    6161 // The landing pads for this function.
    6262 typedef SmallPtrSet BBSet;
    6363 BBSet LandingPads;
    64
    65 bool InsertUnwindResumeCalls();
    6664
    6765 bool NormalizeLandingPads();
    6866 bool LowerUnwindsAndResumes();
    659657 return CallInst::Create(ExceptionValueIntrinsic, "eh.value.call", Start);
    660658 }
    661659
    662 /// InsertUnwindResumeCalls - Convert the ResumeInsts that are still present
    663 /// into calls to the appropriate _Unwind_Resume function.
    664 bool DwarfEHPrepare::InsertUnwindResumeCalls() {
    665 SmallVector Resumes;
    666 for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I)
    667 for (BasicBlock::iterator II = I->begin(), IE = I->end(); II != IE; ++II)
    668 if (ResumeInst *RI = dyn_cast(II))
    669 Resumes.push_back(RI);
    670
    671 if (Resumes.empty())
    672 return false;
    673
    674 // Find the rewind function if we didn't already.
    675 if (!RewindFunction) {
    676 LLVMContext &Ctx = Resumes[0]->getContext();
    677 FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx),
    678 Type::getInt8PtrTy(Ctx), false);
    679 const char *RewindName = TLI->getLibcallName(RTLIB::UNWIND_RESUME);
    680 RewindFunction = F->getParent()->getOrInsertFunction(RewindName, FTy);
    681 }
    682
    683 // Create the basic block where the _Unwind_Resume call will live.
    684 LLVMContext &Ctx = F->getContext();
    685 BasicBlock *UnwindBB = BasicBlock::Create(Ctx, "unwind_resume", F);
    686 PHINode *PN = PHINode::Create(Type::getInt8PtrTy(Ctx), Resumes.size(),
    687 "exn.obj", UnwindBB);
    688
    689 // Extract the exception object from the ResumeInst and add it to the PHI node
    690 // that feeds the _Unwind_Resume call.
    691 for (SmallVectorImpl::iterator
    692 I = Resumes.begin(), E = Resumes.end(); I != E; ++I) {
    693 ResumeInst *RI = *I;
    694 BranchInst::Create(UnwindBB, RI->getParent());
    695 ExtractValueInst *ExnObj = ExtractValueInst::Create(RI->getOperand(0),
    696 0, "exn.obj", RI);
    697 PN->addIncoming(ExnObj, RI->getParent());
    698 RI->eraseFromParent();
    699 }
    700
    701 // Call the function.
    702 CallInst *CI = CallInst::Create(RewindFunction, PN, "", UnwindBB);
    703 CI->setCallingConv(TLI->getLibcallCallingConv(RTLIB::UNWIND_RESUME));
    704
    705 // We never expect _Unwind_Resume to return.
    706 new UnreachableInst(Ctx, UnwindBB);
    707 return true;
    708 }
    709
    710660 bool DwarfEHPrepare::runOnFunction(Function &Fn) {
    711661 bool Changed = false;
    712662
    713663 // Initialize internal state.
    714 DT = &getAnalysis(); // FIXME: We won't need this with the new EH.
    664 DT = &getAnalysis();
    715665 F = &Fn;
    716
    717 if (InsertUnwindResumeCalls()) {
    718 // FIXME: The reset of this function can go once the new EH is done.
    719 LandingPads.clear();
    720 return true;
    721 }
    722666
    723667 // Ensure that only unwind edges end at landing pads (a landing pad is a
    724668 // basic block where an invoke unwind edge ends).
    453453 break;
    454454 }
    455455 }
    456
    457 //--------- NEW EH - Begin ---------
    458
    459 /// AddLandingPadInfo - Extract the exception handling information from the
    460 /// landingpad instruction and add them to the specified machine module info.
    461 void llvm::AddLandingPadInfo(const LandingPadInst &I, MachineModuleInfo &MMI,
    462 MachineBasicBlock *MBB) {
    463 MMI.addPersonality(MBB, I.getPersonalityFn());
    464
    465 if (I.isCleanup())
    466 MMI.addCleanup(MBB);
    467
    468 for (unsigned i = 0, e = I.getNumClauses(); i != e; ) {
    469 switch (I.getClauseType(i)) {
    470 case LandingPadInst::Catch:
    471 MMI.addCatchTypeInfo(MBB, dyn_cast(I.getClauseValue(i)));
    472 ++i;
    473 break;
    474 case LandingPadInst::Filter: {
    475 // Add filters in a list.
    476 SmallVector FilterList;
    477 do {
    478 FilterList.push_back(cast(I.getClauseValue(i)));
    479 ++i;
    480 } while (i != e && I.getClauseType(i) == LandingPadInst::Filter);
    481
    482 MMI.addFilterTypeInfo(MBB, FilterList);
    483 break;
    484 }
    485 }
    486 }
    487 }
    488
    489 //--------- NEW EH - End ---------
    18071807 }
    18081808
    18091809 void SelectionDAGBuilder::visitUnwind(const UnwindInst &I) {
    1810 }
    1811
    1812 void SelectionDAGBuilder::visitResume(const ResumeInst &RI) {
    1813 llvm_unreachable("SelectionDAGBuilder shouldn't visit resume instructions!");
    1814 }
    1815
    1816 void SelectionDAGBuilder::visitLandingPad(const LandingPadInst &LP) {
    1817 // FIXME: Handle this
    1818 assert(FuncInfo.MBB->isLandingPad() &&
    1819 "Call to landingpad not in landing pad!");
    1820
    1821 MachineBasicBlock *MBB = FuncInfo.MBB;
    1822 MachineModuleInfo &MMI = DAG.getMachineFunction().getMMI();
    1823 AddLandingPadInfo(LP, MMI, MBB);
    1824
    1825 SmallVector ValueVTs;
    1826 ComputeValueVTs(TLI, LP.getType(), ValueVTs);
    1827
    1828 // Insert the EXCEPTIONADDR instruction.
    1829 assert(FuncInfo.MBB->isLandingPad() &&
    1830 "Call to eh.exception not in landing pad!");
    1831 SDVTList VTs = DAG.getVTList(TLI.getPointerTy(), MVT::Other);
    1832 SDValue Ops[2];
    1833 Ops[0] = DAG.getRoot();
    1834 SDValue Op1 = DAG.getNode(ISD::EXCEPTIONADDR, getCurDebugLoc(), VTs, Ops, 1);
    1835 SDValue Chain = Op1.getValue(1);
    1836
    1837 // Insert the EHSELECTION instruction.
    1838 VTs = DAG.getVTList(TLI.getPointerTy(), MVT::Other);
    1839 Ops[0] = Op1;
    1840 Ops[1] = Chain;
    1841 SDValue Op2 = DAG.getNode(ISD::EHSELECTION, getCurDebugLoc(), VTs, Ops, 2);
    1842 Chain = Op2.getValue(1);
    1843 Op2 = DAG.getSExtOrTrunc(Op2, getCurDebugLoc(), MVT::i32);
    1844
    1845 Ops[0] = Op1;
    1846 Ops[1] = Op2;
    1847 SDValue Res = DAG.getNode(ISD::MERGE_VALUES, getCurDebugLoc(),
    1848 DAG.getVTList(&ValueVTs[0], ValueVTs.size()),
    1849 &Ops[0], 2);
    1850
    1851 std::pair RetPair = std::make_pair(Res, Chain);
    1852 setValue(&LP, RetPair.first);
    1853 DAG.setRoot(RetPair.second);
    18541810 }
    18551811
    18561812 /// handleSmallSwitchCaseRange - Emit a series of specific tests (suitable for
    466466 private:
    467467 // These all get lowered before this pass.
    468468 void visitInvoke(const InvokeInst &I);
    469 void visitResume(const ResumeInst &I);
    470469 void visitUnwind(const UnwindInst &I);
    471470
    472471 void visitBinary(const User &I, unsigned OpCode);
    511510
    512511 void visitExtractValue(const ExtractValueInst &I);
    513512 void visitInsertValue(const InsertValueInst &I);
    514 void visitLandingPad(const LandingPadInst &I);
    515513
    516514 void visitGetElementPtr(const User &I);
    517515 void visitSelect(const User &I);
    112112 while (StateBB != StateE) {
    113113 BasicBlock *CurBB = StateBB++;
    114114
    115 // Branches and invokes do not escape, only unwind, resume, and return
    116 // do.
    115 // Branches and invokes do not escape, only unwind and return do.
    117116 TerminatorInst *TI = CurBB->getTerminator();
    118 if (!isa(TI) && !isa(TI) &&
    119 !isaInst>(TI))
    117 if (!isa(TI) && !isaInst>(TI))
    120118 continue;
    121119
    122120 Builder.SetInsertPoint(TI->getParent(), TI);
    287287 void visitInvokeInst(InvokeInst &I) {
    288288 llvm_unreachable("Lowerinvoke pass didn't work!");
    289289 }
    290
    290291 void visitUnwindInst(UnwindInst &I) {
    291 llvm_unreachable("Lowerinvoke pass didn't work!");
    292 }
    293 void visitResumeInst(ResumeInst &I) {
    294292 llvm_unreachable("Lowerinvoke pass didn't work!");
    295293 }
    296294 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 }
    10711066 case Instruction::Invoke: {
    10721067 const InvokeInst* inv = cast(I);
    10731068 Out << "std::vector " << iName << "_params;";
    14271422 Out << "\", " << bbname << ");";
    14281423 break;
    14291424 }
    1430 case Instruction::LandingPad: {
    1431 break;
    1432 }
    14331425 }
    14341426 DefinedValues.insert(I);
    14351427 nl(Out);
    25052505 CallStack.pop_back(); // return from fn.
    25062506 return true; // We succeeded at evaluating this ctor!
    25072507 } else {
    2508 // invoke, unwind, resume, unreachable.
    2508 // invoke, unwind, unreachable.
    25092509 return false; // Cannot handle this terminator.
    25102510 }
    25112511
    731731 }
    732732 }
    733733
    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)))
    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)))
    739737 return EraseInstFromFunction(CI);
    740738 break;
    741739 }
    514514 void visitShuffleVectorInst(ShuffleVectorInst &I);
    515515 void visitExtractValueInst(ExtractValueInst &EVI);
    516516 void visitInsertValueInst(InsertValueInst &IVI);
    517 void visitLandingPadInst(LandingPadInst &I) { markAnythingOverdefined(&I); }
    518517
    519518 // Instructions that cannot be folded away.
    520519 void visitStoreInst (StoreInst &I);
    528527 visitTerminatorInst(II);
    529528 }
    530529 void visitCallSite (CallSite CS);
    531 void visitResumeInst (TerminatorInst &I) { /*returns void*/ }
    532530 void visitUnwindInst (TerminatorInst &I) { /*returns void*/ }
    533531 void visitUnreachableInst(TerminatorInst &I) { /*returns void*/ }
    534532 void visitFenceInst (FenceInst &I) { /*returns void*/ }
    249249 PHINode *InnerSelectorPHI;
    250250 SmallVector UnwindDestPHIValues;
    251251
    252 // New EH:
    253 BasicBlock *OuterResumeDest; //< Destination of the invoke's unwind.
    254 BasicBlock *InnerResumeDest; //< Destination for the callee's resume.
    255 LandingPadInst *CallerLPad; //< LandingPadInst associated with the invoke.
    256 PHINode *InnerEHValuesPHI; //< PHI for EH values from landingpad insts.
    257
    258252 public:
    259 InvokeInliningInfo(InvokeInst *II)
    260 : OuterUnwindDest(II->getUnwindDest()), OuterSelector(0),
    261 InnerUnwindDest(0), InnerExceptionPHI(0), InnerSelectorPHI(0),
    262
    263 OuterResumeDest(II->getUnwindDest()), InnerResumeDest(0),
    264 CallerLPad(0), InnerEHValuesPHI(0) {
    265 // If there are PHI nodes in the unwind destination block, we need to keep
    266 // track of which values came into them from the invoke before removing
    267 // the edge from this block.
    268 llvm::BasicBlock *InvokeBB = II->getParent();
    269 BasicBlock::iterator I = OuterUnwindDest->begin();
    270 for (; isa(I); ++I) {
    253 InvokeInliningInfo(InvokeInst *II) :
    254 OuterUnwindDest(II->getUnwindDest()), OuterSelector(0),
    255 InnerUnwindDest(0), InnerExceptionPHI(0), InnerSelectorPHI(0) {
    256
    257 // If there are PHI nodes in the unwind destination block, we
    258 // need to keep track of which values came into them from the
    259 // invoke before removing the edge from this block.
    260 llvm::BasicBlock *invokeBB = II->getParent();
    261 for (BasicBlock::iterator I = OuterUnwindDest->begin();
    262 isa(I); ++I) {
    271263 // Save the value to use for this edge.
    272 PHINode *PHI = cast(I);
    273 UnwindDestPHIValues.push_back(PHI->getIncomingValueForBlock(InvokeBB));
    274 }
    275
    276 // FIXME: With the new EH, this if/dyn_cast should be a 'cast'.
    277 if (LandingPadInst *LPI = dyn_cast(I)) {
    278 CallerLPad = LPI;
    264 PHINode *phi = cast(I);
    265 UnwindDestPHIValues.push_back(phi->getIncomingValueForBlock(invokeBB));
    279266 }
    280267 }
    281268
    292279 }
    293280
    294281 BasicBlock *getInnerUnwindDest();
    295 BasicBlock *getInnerUnwindDest_new();
    296
    297 LandingPadInst *getLandingPadInst() const { return CallerLPad; }
    298282
    299283 bool forwardEHResume(CallInst *call, BasicBlock *src);
    300284
    301 /// forwardResume - Forward the 'resume' instruction to the caller's landing
    302 /// pad block. When the landing pad block has only one predecessor, this is
    303 /// a simple branch. When there is more than one predecessor, we need to
    304 /// split the landing pad block after the landingpad instruction and jump
    305 /// to there.
    306 void forwardResume(ResumeInst *RI);
    307
    308 /// addIncomingPHIValuesFor - Add incoming-PHI values to the unwind
    309 /// destination block for the given basic block, using the values for the
    310 /// original invoke's source block.
    285 /// Add incoming-PHI values to the unwind destination block for
    286 /// the given basic block, using the values for the original
    287 /// invoke's source block.
    311288 void addIncomingPHIValuesFor(BasicBlock *BB) const {
    312289 addIncomingPHIValuesForInto(BB, OuterUnwindDest);
    313290 }
    291
    314292 void addIncomingPHIValuesForInto(BasicBlock *src, BasicBlock *dest) const {
    315293 BasicBlock::iterator I = dest->begin();
    316294 for (unsigned i = 0, e = UnwindDestPHIValues.size(); i != e; ++i, ++I) {
    317 PHINode *PHI = cast(I);
    318 PHI->addIncoming(UnwindDestPHIValues[i], src);
    295 PHINode *phi = cast(I);
    296 phi->addIncoming(UnwindDestPHIValues[i], src);
    319297 }
    320298 }
    321299 };
    425403 return true;
    426404 }
    427405
    428 /// Get or create a target for the branch from ResumeInsts.
    429 BasicBlock *InvokeInliningInfo::getInnerUnwindDest_new() {
    430 if (InnerResumeDest) return InnerResumeDest;
    431
    432 // Split the landing pad.
    433 BasicBlock::iterator SplitPoint = CallerLPad; ++SplitPoint;
    434 InnerResumeDest =
    435 OuterResumeDest->splitBasicBlock(SplitPoint,
    436 OuterResumeDest->getName() + ".body");
    437
    438 // The number of incoming edges we expect to the inner landing pad.
    439 const unsigned PHICapacity = 2;
    440
    441 // Create corresponding new PHIs for all the PHIs in the outer landing pad.
    442 BasicBlock::iterator InsertPoint = InnerResumeDest->begin();
    443 BasicBlock::iterator I = OuterResumeDest->begin();
    444 for (unsigned i = 0, e = UnwindDestPHIValues.size(); i != e; ++i, ++I) {
    445 PHINode *OuterPHI = cast(I);
    446 PHINode *InnerPHI = PHINode::Create(OuterPHI->getType(), PHICapacity,
    447 OuterPHI->getName() + ".lpad-body",
    448 InsertPoint);
    449 OuterPHI->replaceAllUsesWith(InnerPHI);
    450 InnerPHI->addIncoming(OuterPHI, OuterResumeDest);
    451 }
    452
    453 // Create a PHI for the exception values.
    454 InnerEHValuesPHI = PHINode::Create(CallerLPad->getType(), PHICapacity,
    455 "eh.lpad-body", InsertPoint);
    456 CallerLPad->replaceAllUsesWith(InnerEHValuesPHI);
    457 InnerEHValuesPHI->addIncoming(CallerLPad, OuterResumeDest);
    458
    459 // All done.
    460 return InnerResumeDest;
    461 }
    462
    463 /// forwardResume - Forward the 'resume' instruction to the caller's landing pad
    464 /// block. When the landing pad block has only one predecessor, this is a simple
    465 /// branch. When there is more than one predecessor, we need to split the
    466 /// landing pad block after the landingpad instruction and jump to there.
    467 void InvokeInliningInfo::forwardResume(ResumeInst *RI) {
    468 BasicBlock *Dest = getInnerUnwindDest_new();
    469 BasicBlock *Src = RI->getParent();
    470
    471 BranchInst::Create(Dest, Src);
    472
    473 // Update the PHIs in the destination. They were inserted in an order which
    474 // makes this work.
    475 addIncomingPHIValuesForInto(Src, Dest);
    476
    477 InnerEHValuesPHI->addIncoming(RI->getOperand(0), Src);
    478 RI->eraseFromParent();
    479 }
    480
    481406 /// [LIBUNWIND] Check whether this selector is "only cleanups":
    482407 /// call i32 @llvm.eh.selector(blah, blah, i32 0)
    483408 static bool isCleanupOnlySelector(EHSelectorInst *selector) {
    495420 /// Returns true to indicate that the next block should be skipped.
    496421 static bool HandleCallsInBlockInlinedThroughInvoke(BasicBlock *BB,
    497422 InvokeInliningInfo &Invoke) {
    498 LandingPadInst *LPI = Invoke.getLandingPadInst();
    499
    500423 for (BasicBlock::iterator BBI = BB->begin(), E = BB->end(); BBI != E; ) {
    501424 Instruction *I = BBI++;
    502
    503 if (LPI) // FIXME: This won't be NULL in the new EH.
    504 if (LandingPadInst *L = dyn_cast(I)) {
    505 unsigned NumClauses = LPI->getNumClauses();
    506 L->reserveClauses(NumClauses);
    507 for (unsigned i = 0; i != NumClauses; ++i)
    508 L->addClause(LPI->getClauseType(i), LPI->getClauseValue(i));
    509 }
    510
    425
    511426 // We only need to check for function calls: inlined invoke
    512427 // instructions require no special handling.
    513428 CallInst *CI = dyn_cast(I);
    640555 // Update any PHI nodes in the exceptional block to indicate that
    641556 // there is now a new entry in them.
    642557 Invoke.addIncomingPHIValuesFor(BB);
    643 }
    644
    645 if (ResumeInst *RI = dyn_cast(BB->getTerminator())) {
    646 Invoke.forwardResume(RI);
    647558 }
    648559 }
    649560
    916827 else if (CalledFunc->getGC() != Caller->getGC())
    917828 return false;
    918829 }
    919
    920 // Find the personality function used by the landing pads of the caller. If it
    921 // exists, then check to see that it matches the personality function used in
    922 // the callee.
    923 for (Function::const_iterator
    924 I = Caller->begin(), E = Caller->end(); I != E; ++I)
    925 if (const InvokeInst *II = dyn_cast(I->getTerminator())) {
    926 const BasicBlock *BB = II->getUnwindDest();
    927 // FIXME: This 'isa' here should become go away once the new EH system is
    928 // in place.
    929 if (!isa(BB->getFirstNonPHI()))
    930 continue;
    931 const LandingPadInst *LP = cast(BB->getFirstNonPHI());
    932 const Value *CallerPersFn = LP->getPersonalityFn();
    933
    934 // If the personality functions match, then we can perform the
    935 // inlining. Otherwise, we can't inline.
    936 // TODO: This isn't 100% true. Some personality functions are proper
    937 // supersets of others and can be used in place of the other.
    938 for (Function::const_iterator
    939 I = CalledFunc->begin(), E = CalledFunc->end(); I != E; ++I)
    940 if (const InvokeInst *II = dyn_cast(I->getTerminator())) {
    941 const BasicBlock *BB = II->getUnwindDest();
    942 // FIXME: This 'if/dyn_cast' here should become a normal 'cast' once
    943 // the new EH system is in place.
    944 if (const LandingPadInst *LP =
    945 dyn_cast(BB->getFirstNonPHI()))
    946 if (CallerPersFn != LP->getPersonalityFn())
    947 return false;
    948 break;
    949 }
    950
    951 break;
    952 }
    953830
    954831 // Get an iterator to the last basic block in the function, which will have
    955832 // the new function inlined after it.
    17301730 writeOperand(I.getOperand(i), true);
    17311731 }
    17321732 Out << ']';
    1733 } else if (isa(I)) {
    1734 Out << ' ';
    1735 writeOperand(Operand, true);
    17361733 } else if (const PHINode *PN = dyn_cast(&I)) {
    17371734 Out << ' ';
    17381735 TypePrinter.print(I.getType(), Out);
    17551752 writeOperand(I.getOperand(1), true);
    17561753 for (const unsigned *i = IVI->idx_begin(), *e = IVI->idx_end(); i != e; ++i)
    17571754 Out << ", " << *i;
    1758 } else if (const LandingPadInst *LPI = dyn_cast(&I)) {
    1759 Out << ' ';
    1760 TypePrinter.print(I.getType(), Out);
    1761 Out << " personality ";
    1762 writeOperand(LPI->getPersonalityFn(), true); Out << '\n';
    1763
    1764 if (LPI->isCleanup())
    1765 Out << " cleanup";
    1766
    1767 for (unsigned i = 0, e = LPI->getNumClauses(); i != e; ) {
    1768 if (i != 0 || LPI->isCleanup()) Out << "\n";
    1769
    1770 SmallVector Vals;
    1771 LandingPadInst::ClauseType CT = LPI->getClauseType(i);
    1772 for (; i != e && LPI->getClauseType(i) == CT; ++i)
    1773 Vals.push_back(LPI->getClauseValue(i));
    1774
    1775 if (CT == LandingPadInst::Catch)
    1776 Out << " catch ";
    1777 else
    1778 Out << " filter ";
    1779
    1780 for (unsigned II = 0, IE = Vals.size(); II != IE; ++II) {
    1781 if (II != 0) Out << ", ";
    1782 writeOperand(Vals[II], true);
    1783 }
    1784 }
    17851755 } else if (isa(I) && !Operand) {
    17861756 Out << " void";
    17871757 } 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),
    1689 cast(unwrap(PersFn)),
    1690 NumClauses, Name));
    1691 }
    1692
    16931685 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef B) {
    16941686 return wrap(unwrap(B)->CreateUnwind());
    1695 }
    1696
    1697 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn) {
    1698 return wrap(unwrap(B)->CreateResume(unwrap(Exn)));
    16991687 }
    17001688
    17011689 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B) {
    17091697
    17101698 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest) {
    17111699 unwrap(IndirectBr)->addDestination(unwrap(Dest));
    1712 }
    1713
    1714 void LLVMAddClause(LLVMValueRef LandingPad, LLVMLandingPadClauseTy ClauseTy,
    1715 LLVMValueRef ClauseVal) {
    1716 unwrap(LandingPad)->
    1717 addClause(static_cast(ClauseTy),
    1718 cast(unwrap(ClauseVal)));
    1719 }
    1720
    1721 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val) {
    1722 unwrap(LandingPad)->setCleanup(Val);
    17231700 }
    17241701
    17251702 /*--.. Arithmetic ..........................................................--*/
    100100 case Switch: return "switch";
    101101 case IndirectBr: return "indirectbr";
    102102 case Invoke: return "invoke";
    103 case Resume: return "resume";
    104103 case Unwind: return "unwind";
    105104 case Unreachable: return "unreachable";
    106105
    161160 case ShuffleVector: return "shufflevector";
    162161 case ExtractValue: return "extractvalue";
    163162 case InsertValue: return "insertvalue";
    164 case LandingPad: return "landingpad";
    165163
    166164 default: return " ";
    167165 }
    165165 return ConstantValue;
    166166 }
    167167
    168 //===----------------------------------------------------------------------===//
    169 // LandingPadInst Implementation
    170 //===----------------------------------------------------------------------===//
    171
    172 void LandingPadInst::init(Function *PersFn, unsigned NumReservedValues,
    173 const Twine &NameStr) {
    174 ReservedSpace = NumReservedValues;
    175 NumOperands = 1;
    176 OperandList = allocHungoffUses(ReservedSpace);
    177 OperandList[0] = (Value*)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::reserveClauses(unsigned Size) {
    217 unsigned e = getNumOperands();
    218 if (ReservedSpace >= e + Size) return;
    219 ReservedSpace = e + Size;
    220
    221 Use *NewOps = allocHungoffUses(ReservedSpace);
    222 Use *OldOps = OperandList;
    223 for (unsigned i = 0; i != e; ++i)
    224 NewOps[i] = OldOps[i];
    225
    226 OperandList = NewOps;
    227 Use::zap(OldOps, OldOps + e, true);
    228 }
    229
    230 void LandingPadInst::addClause(ClauseType CT, Constant *ClauseVal) {
    231 unsigned OpNo = getNumOperands();
    232 if (OpNo + 1 > ReservedSpace)
    233 growOperands();
    234 assert(OpNo < ReservedSpace && "Growing didn't work!");
    235 ClauseIdxs.push_back(CT);
    236 ++NumOperands;
    237 OperandList[OpNo] = (Value*)ClauseVal;
    238 }
    239168
    240169 //===----------------------------------------------------------------------===//
    241170 // CallInst Implementation
    564493 setAttributes(PAL);
    565494 }
    566495
    567 LandingPadInst *InvokeInst::getLandingPad() const {
    568 return cast(getUnwindDest()->getFirstNonPHI());
    569 }
    570496
    571497 //===----------------------------------------------------------------------===//
    572498 // ReturnInst Implementation
    647573 }
    648574
    649575 //===----------------------------------------------------------------------===//
    650 // ResumeInst Implementation
    651 //===----------------------------------------------------------------------===//
    652
    653 ResumeInst::ResumeInst(const ResumeInst &RI)
    654 : TerminatorInst(Type::getVoidTy(RI.getContext()), Instruction::Resume,
    655 OperandTraits::op_begin(this), 1) {
    656 Op<0>() = RI.Op<0>();
    657 SubclassOptionalData = RI.SubclassOptionalData;
    658 }
    659
    660 ResumeInst::ResumeInst(LLVMContext &C, Value *Exn, Instruction *InsertBefore)
    661 : TerminatorInst(Type::getVoidTy(C), Instruction::Resume,
    662 OperandTraits::op_begin(this), 1, InsertBefore) {
    663 Op<0>() = Exn;
    664 }
    665
    666 ResumeInst::ResumeInst(LLVMContext &C, Value *Exn, BasicBlock *InsertAtEnd)
    667 : TerminatorInst(Type::getVoidTy(C), Instruction::Resume,
    668 OperandTraits::op_begin(this), 1, InsertAtEnd) {
    669 Op<0>() = Exn;
    670 }
    671
    672 unsigned ResumeInst::getNumSuccessorsV() const {
    673 return getNumSuccessors();
    674 }
    675
    676 void ResumeInst::setSuccessorV(unsigned idx, BasicBlock *NewSucc) {
    677 llvm_unreachable("ResumeInst has no successors!");
    678 }
    679
    680 BasicBlock *ResumeInst::getSuccessorV(unsigned idx) const {
    681 llvm_unreachable("ResumeInst has no successors!");
    682 return 0;
    683 }
    684
    685 //===----------------------------------------------------------------------===//
    686576 // UnreachableInst Implementation
    687577 //===----------------------------------------------------------------------===//
    688578
    701591 }
    702592
    703593 void UnreachableInst::setSuccessorV(unsigned idx, BasicBlock *NewSucc) {
    704 llvm_unreachable("UnreachableInst has no successors!");
    594 llvm_unreachable("UnwindInst has no successors!");
    705595 }
    706596
    707597 BasicBlock *UnreachableInst::getSuccessorV(unsigned idx) const {
    708 llvm_unreachable("UnreachableInst has no successors!");
    598 llvm_unreachable("UnwindInst has no successors!");
    709599 return 0;
    710600 }
    711601
    33423232 return new PHINode(*this);
    33433233 }
    33443234
    3345 LandingPadInst *LandingPadInst::clone_impl() const {
    3346 return new LandingPadInst(*this);
    3347 }
    3348
    33493235 ReturnInst *ReturnInst::clone_impl() const {
    33503236 return new(getNumOperands()) ReturnInst(*this);
    33513237 }
    33653251
    33663252 InvokeInst *InvokeInst::clone_impl() const {
    33673253 return new(getNumOperands()) InvokeInst(*this);
    3368 }
    3369
    3370 ResumeInst *ResumeInst::clone_impl() const {
    3371 return new(1) ResumeInst(*this);
    33723254 }
    33733255
    33743256 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.
    4337 // * All other things that are tested by asserts spread about the code...
    4438 //
    4539 //===----------------------------------------------------------------------===//
    136130 /// already.
    137131 SmallPtrSet MDNodes;
    138132
    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
    144133 Verifier()
    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 }
    134 : FunctionPass(ID),
    135 Broken(false), RealPass(true), action(AbortProcessAction),
    136 Mod(0), Context(0), DT(0), MessagesStr(Messages) {
    137 initializeVerifierPass(*PassRegistry::getPassRegistry());
    138 }
    150139 explicit Verifier(VerifierFailureAction ctn)
    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 }
    140 : FunctionPass(ID),
    141 Broken(false), RealPass(true), action(ctn), Mod(0), Context(0), DT(0),
    142 MessagesStr(Messages) {
    143 initializeVerifierPass(*PassRegistry::getPassRegistry());
    144 }
    155145
    156146 bool doInitialization(Module &M) {
    157147 Mod = &M;
    293283 void visitAllocaInst(AllocaInst &AI);
    294284 void visitExtractValueInst(ExtractValueInst &EVI);
    295285 void visitInsertValueInst(InsertValueInst &IVI);
    296 void visitLandingPadInst(LandingPadInst &LPI);
    297286
    298287 void VerifyCallSite(CallSite CS);
    299288 bool PerformTypeCheck(Intrinsic::ID ID, Function *F, Type *Ty,
    13711360 Assert1(Ordering == Acquire || Ordering == Release ||
    13721361 Ordering == AcquireRelease || Ordering == SequentiallyConsistent,
    13731362 "fence instructions may only have "
    1374 "acquire, release, acq_rel, or seq_cst ordering.", &FI);
    1363 " acquire, release, acq_rel, or seq_cst ordering.", &FI);
    13751364 visitInstruction(FI);
    13761365 }
    13771366
    13911380 "Invalid InsertValueInst operands!", &IVI);
    13921381
    13931382 visitInstruction(IVI);
    1394 }
    1395
    1396 void Verifier::visitLandingPadInst(LandingPadInst &LPI) {
    1397 BasicBlock *BB = LPI.getParent();
    1398
    1399 // The landingpad instruction is ill-formed if it doesn't have any clauses and
    1400 // isn't a cleanup.
    1401 Assert1(LPI.getNumClauses() > 0 || LPI.isCleanup(),
    1402 "LandingPadInst needs at least one clause or to be a cleanup.", &LPI);
    1403
    1404 // The landingpad instruction defines its parent as a landing pad block. The
    1405 // landing pad block may be branched to only by the unwind edge of an invoke.
    1406 for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) {
    1407 const InvokeInst *II = dyn_cast((*I)->getTerminator());
    1408 Assert1(II && II->getUnwindDest() == BB,
    1409 "Block containing LandingPadInst must be jumped to "
    1410 "only by the unwind edge of an invoke.", &LPI);
    1411 }
    1412
    1413 // The landingpad instruction must be the first non-PHI instruction in the
    1414 // block.
    1415 BasicBlock::iterator I = BB->begin(), E = BB->end();
    1416 while (I != E && isa(I))
    1417 ++I;
    1418 Assert1(I != E && isa(I) && I == LPI,
    1419 "LandingPadInst not the first non-PHI instruction in the block.",
    1420 &LPI);
    1421
    1422 // The personality functions for all landingpad instructions within the same
    1423 // function should match.
    1424 if (PersonalityFn)
    1425 Assert1(LPI.getPersonalityFn() == PersonalityFn,
    1426 "Personality function doesn't match others in function", &LPI);
    1427 PersonalityFn = LPI.getPersonalityFn();
    1428
    1429 visitInstruction(LPI);
    14301383 }
    14311384
    14321385 /// verifyInstruction - Verify that an instruction is well formed.
    +0
    -54
    test/Feature/exceptionhandling.ll less more
    None ; 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()