llvm.org GIT mirror llvm / 751c4be
New EH representation for MSVC compatibility Summary: This introduces new instructions neccessary to implement MSVC-compatible exception handling support. Most of the middle-end and none of the back-end haven't been audited or updated to take them into account. Reviewers: rnk, JosephTremoulet, reames, nlewycky, rjmccall Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D11041 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241888 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 5 years ago
35 changed file(s) with 2042 addition(s) and 91 deletion(s). Raw diff Collapse all Expand all
47264726 The terminator instructions are: ':ref:`ret `',
47274727 ':ref:`br `', ':ref:`switch `',
47284728 ':ref:`indirectbr `', ':ref:`invoke `',
4729 ':ref:`resume `', and ':ref:`unreachable `'.
4729 ':ref:`resume `', ':ref:`catchblock `',
4730 ':ref:`catchendblock `',
4731 ':ref:`catchret `',
4732 ':ref:`terminateblock `',
4733 and ':ref:`unreachable `'.
47304734
47314735 .. _i_ret:
47324736
50795083 .. code-block:: llvm
50805084
50815085 resume { i8*, i32 } %exn
5086
5087 .. _i_catchblock:
5088
5089 '``catchblock``' Instruction
5090 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5091
5092 Syntax:
5093 """""""
5094
5095 ::
5096
5097 = catchblock [*]
5098 to label unwind label
5099
5100 Overview:
5101 """""""""
5102
5103 The '``catchblock``' instruction is used by `LLVM's exception handling
5104 system `_ to specify that a basic block
5105 is a catch block --- one where a personality routine attempts to transfer
5106 control to catch an exception.
5107 The ``args`` correspond to whatever information the personality
5108 routine requires to know if this is an appropriate place to catch the
5109 exception. Control is tranfered to the ``exception`` label if the
5110 ``catchblock`` is not an appropriate handler for the in-flight exception.
5111 The ``normal`` label should contain the code found in the ``catch``
5112 portion of a ``try``/``catch`` sequence. It defines values supplied by
5113 the :ref:`personality function ` upon re-entry to the
5114 function. The ``resultval`` has the type ``resultty``.
5115
5116 Arguments:
5117 """"""""""
5118
5119 The instruction takes a list of arbitrary values which are interpreted
5120 by the :ref:`personality function `.
5121
5122 The ``catchblock`` must be provided a ``normal`` label to transfer control
5123 to if the ``catchblock`` matches the exception and an ``exception``
5124 label to transfer control to if it doesn't.
5125
5126 Semantics:
5127 """"""""""
5128
5129 The '``catchblock``' instruction defines the values which are set by the
5130 :ref:`personality function ` upon re-entry to the function, and
5131 therefore the "result type" of the ``catchblock`` instruction. As with
5132 calling conventions, how the personality function results are
5133 represented in LLVM IR is target specific.
5134
5135 When the call stack is being unwound due to an exception being thrown,
5136 the exception is compared against the ``args``. If it doesn't match,
5137 then control is transfered to the ``exception`` basic block.
5138
5139 The ``catchblock`` instruction has several restrictions:
5140
5141 - A catch block is a basic block which is the unwind destination of
5142 an exceptional instruction.
5143 - A catch block must have a '``catchblock``' instruction as its
5144 first non-PHI instruction.
5145 - There can be only one '``catchblock``' instruction within the
5146 catch block.
5147 - A basic block that is not a catch block may not include a
5148 '``catchblock``' instruction.
5149
5150 Example:
5151 """"""""
5152
5153 .. code-block:: llvm
5154
5155 ;; A catch block which can catch an integer.
5156 %res = catchblock { i8*, i32 } [i8** @_ZTIi]
5157 to label %int.handler unwind label %terminate
5158
5159 .. _i_catchendblock:
5160
5161 '``catchendblock``' Instruction
5162 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5163
5164 Syntax:
5165 """""""
5166
5167 ::
5168
5169 catchendblock unwind label
5170 catchendblock unwind to caller
5171
5172 Overview:
5173 """""""""
5174
5175 The '``catchendblock``' instruction is used by `LLVM's exception handling
5176 system `_ to communicate to the
5177 :ref:`personality function ` which invokes are associated
5178 with a chain of :ref:`catchblock ` instructions.
5179
5180 The ``nextaction`` label indicates where control should transfer to if
5181 none of the ``catchblock`` instructions are suitable for catching the
5182 in-flight exception.
5183
5184 If a ``nextaction`` label is not present, the instruction unwinds out of
5185 the function it is located in. The
5186 :ref:`personality function ` will look for an appropriate
5187 catch block in the caller.
5188
5189 Arguments:
5190 """"""""""
5191
5192 The instruction optionally takes a label, ``nextaction``, indicating
5193 where control should transfer to if none of the constituent
5194 ``catchblock`` instructions are suitable for the in-flight exception.
5195
5196 Semantics:
5197 """"""""""
5198
5199 When the call stack is being unwound due to an exception being thrown
5200 and none of the constituent ``catchblock`` instructions match, then
5201 control is transfered to ``nextaction`` if it is present. If it is not
5202 present, control is transfered to the caller.
5203
5204 The ``catchendblock`` instruction has several restrictions:
5205
5206 - A catch-end block is a basic block which is the unwind destination of
5207 an exceptional instruction.
5208 - A catch-end block must have a '``catchendblock``' instruction as its
5209 first non-PHI instruction.
5210 - There can be only one '``catchendblock``' instruction within the
5211 catch block.
5212 - A basic block that is not a catch-end block may not include a
5213 '``catchendblock``' instruction.
5214
5215 Example:
5216 """"""""
5217
5218 .. code-block:: llvm
5219
5220 catchendblock unwind label %terminate
5221 catchendblock unwind to caller
5222
5223 .. _i_catchret:
5224
5225 '``catchret``' Instruction
5226 ^^^^^^^^^^^^^^^^^^^^^^^^^^
5227
5228 Syntax:
5229 """""""
5230
5231 ::
5232
5233 catchret label
5234
5235 Overview:
5236 """""""""
5237
5238 The '``catchret``' instruction is a terminator instruction that has a
5239 single successor.
5240
5241
5242 Arguments:
5243 """"""""""
5244
5245 The '``catchret``' instruction requires one argument which specifies
5246 where control will transfer to next.
5247
5248 Semantics:
5249 """"""""""
5250
5251 The '``catchret``' instruction ends the existing (in-flight) exception
5252 whose unwinding was interrupted with a
5253 :ref:`catchblock ` instruction and transfer control to
5254 ``normal``.
5255
5256 Example:
5257 """"""""
5258
5259 .. code-block:: llvm
5260
5261 catchret unwind label %continue
5262
5263 .. _i_cleanupret:
5264
5265 '``cleanupret``' Instruction
5266 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5267
5268 Syntax:
5269 """""""
5270
5271 ::
5272
5273 cleanupret unwind label
5274 cleanupret unwind to caller
5275
5276 Overview:
5277 """""""""
5278
5279 The '``cleanupret``' instruction is a terminator instruction that has
5280 an optional successor.
5281
5282
5283 Arguments:
5284 """"""""""
5285
5286 The '``cleanupret``' instruction requires one argument, which must have the
5287 same type as the result of any '``cleanupblock``' instruction in the same
5288 function. It also has an optional successor, ``continue``.
5289
5290 Semantics:
5291 """"""""""
5292
5293 The '``cleanupret``' instruction indicates to the
5294 :ref:`personality function ` that the
5295 :ref:`cleanupblock ` it transfered control to has ended.
5296 It transfers control to ``continue`` or unwinds out of the function.
5297
5298 Example:
5299 """"""""
5300
5301 .. code-block:: llvm
5302
5303 cleanupret { i8*, i32 } %exn unwind label %continue
5304
5305 .. _i_terminateblock:
5306
5307 '``terminateblock``' Instruction
5308 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5309
5310 Syntax:
5311 """""""
5312
5313 ::
5314
5315 terminateblock [*] unwind label
5316
5317 Overview:
5318 """""""""
5319
5320 The '``terminateblock``' instruction is used by `LLVM's exception handling
5321 system `_ to specify that a basic block
5322 is a terminate block --- one where a personality routine attempts to transfer
5323 control to terminate the program.
5324 The ``args`` correspond to whatever information the personality
5325 routine requires to know if this is an appropriate place to terminate the
5326 program. Control is tranfered to the ``exception`` label if the
5327 ``terminateblock`` is an appropriate handler for the in-flight exception.
5328 If the ``terminateblock`` is not an appropriate handler, execution of
5329 the program is terminated via
5330 :ref:`personality function ` specific means.
5331
5332 Arguments:
5333 """"""""""
5334
5335 The instruction takes a list of arbitrary values which are interpreted
5336 by the :ref:`personality function `.
5337
5338 The ``terminateblock`` must be provided an ``exception`` label to
5339 transfer control to if the in-flight exception matches the ``args``.
5340
5341 Semantics:
5342 """"""""""
5343
5344 When the call stack is being unwound due to an exception being thrown,
5345 the exception is compared against the ``args``. If it matches,
5346 then control is transfered to the ``exception`` basic block. Otherwise,
5347 the program is terminated via personality-specific means. Typically,
5348 the first argument to ``terminateblock`` specifies what function the
5349 personality should defer to in order to terminate the program.
5350
5351 The ``terminateblock`` instruction has several restrictions:
5352
5353 - A terminate block is a basic block which is the unwind destination of
5354 an exceptional instruction.
5355 - A terminate block must have a '``terminateblock``' instruction as its
5356 first non-PHI instruction.
5357 - There can be only one '``terminateblock``' instruction within the
5358 terminate block.
5359 - A basic block that is not a terminate block may not include a
5360 '``terminateblock``' instruction.
5361
5362 Example:
5363 """"""""
5364
5365 .. code-block:: llvm
5366
5367 ;; A terminate block which only permits integers.
5368 terminateblock [i8** @_ZTIi] unwind label %continue
50825369
50835370 .. _i_unreachable:
50845371
80288315 catch i8** @_ZTIi
80298316 filter [1 x i8**] [@_ZTId]
80308317
8318 .. _i_cleanupblock:
8319
8320 '``cleanupblock``' Instruction
8321 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8322
8323 Syntax:
8324 """""""
8325
8326 ::
8327
8328 = cleanupblock [*]
8329
8330 Overview:
8331 """""""""
8332
8333 The '``cleanupblock``' instruction is used by `LLVM's exception handling
8334 system `_ to specify that a basic block
8335 is a cleanup block --- one where a personality routine attempts to
8336 transfer control to run cleanup actions.
8337 The ``args`` correspond to whatever additional
8338 information the :ref:`personality function ` requires to
8339 execute the cleanup.
8340 :ref:`personality function ` upon re-entry to the
8341 function. The ``resultval`` has the type ``resultty``.
8342
8343 Arguments:
8344 """"""""""
8345
8346 The instruction takes a list of arbitrary values which are interpreted
8347 by the :ref:`personality function `.
8348
8349 Semantics:
8350 """"""""""
8351
8352 The '``cleanupblock``' instruction defines the values which are set by the
8353 :ref:`personality function ` upon re-entry to the function, and
8354 therefore the "result type" of the ``cleanupblock`` instruction. As with
8355 calling conventions, how the personality function results are
8356 represented in LLVM IR is target specific.
8357
8358 When the call stack is being unwound due to an exception being thrown,
8359 the :ref:`personality function ` transfers control to the
8360 ``cleanupblock`` with the aid of the personality-specific arguments.
8361
8362 The ``cleanupblock`` instruction has several restrictions:
8363
8364 - A cleanup block is a basic block which is the unwind destination of
8365 an exceptional instruction.
8366 - A cleanup block must have a '``cleanupblock``' instruction as its
8367 first non-PHI instruction.
8368 - There can be only one '``cleanupblock``' instruction within the
8369 cleanup block.
8370 - A basic block that is not a cleanup block may not include a
8371 '``cleanupblock``' instruction.
8372
8373 Example:
8374 """"""""
8375
8376 .. code-block:: llvm
8377
8378 %res = cleanupblock { i8*, i32 } [label %nextaction]
8379
80318380 .. _intrinsics:
80328381
80338382 Intrinsic Functions
353353 FUNC_CODE_INST_CMPXCHG = 46, // CMPXCHG: [ptrty,ptr,valty,cmp,new, align,
354354 // vol,ordering,synchscope]
355355 FUNC_CODE_INST_LANDINGPAD = 47, // LANDINGPAD: [ty,val,num,id0,val0...]
356 FUNC_CODE_INST_CLEANUPRET = 48, // CLEANUPRET: [] or [val] or [bb#] or [val,bb#]
357 FUNC_CODE_INST_CATCHRET = 49, // CATCHRET: [bb#]
358 FUNC_CODE_INST_CATCHBLOCK = 50, // CATCHBLOCK: [ty,val,val,num,args...]
359 FUNC_CODE_INST_TERMINATEBLOCK = 51, // TERMINATEBLOCK: [bb#,num,args...]
360 FUNC_CODE_INST_CLEANUPBLOCK = 52, // CLEANUPBLOCK: [num,args...]
361 FUNC_CODE_INST_CATCHENDBLOCK = 53, // CATCHENDBLOCK: [] or [bb#]
356362 };
357363
358364 enum UseListCodes {
308308 /// basic block \p New instead of to it.
309309 void replaceSuccessorsPhiUsesWith(BasicBlock *New);
310310
311 /// \brief Return true if this basic block is an exception handling block.
312 bool isEHBlock() const { return getFirstNonPHI()->isEHBlock(); }
313
311314 /// \brief Return true if this basic block is a landing pad.
312315 ///
313316 /// Being a ``landing pad'' means that the basic block is the destination of
671671 return Insert(ResumeInst::Create(Exn));
672672 }
673673
674 CleanupReturnInst *CreateCleanupRet(BasicBlock *UnwindBB = nullptr,
675 Value *RetVal = nullptr) {
676 return Insert(CleanupReturnInst::Create(Context, RetVal, UnwindBB));
677 }
678
679 CatchBlockInst *CreateCatchBlock(Type *Ty, BasicBlock *NormalDest,
680 BasicBlock *UnwindDest,
681 ArrayRef Args,
682 const Twine &Name = "") {
683 return Insert(CatchBlockInst::Create(Ty, NormalDest, UnwindDest, Args),
684 Name);
685 }
686
687 CatchEndBlockInst *CreateCatchEndBlock(BasicBlock *UnwindBB = nullptr) {
688 return Insert(CatchEndBlockInst::Create(Context, UnwindBB));
689 }
690
691 TerminateBlockInst *CreateTerminateBlock(BasicBlock *NormalDest = nullptr,
692 ArrayRef Args = {},
693 const Twine &Name = "") {
694 return Insert(TerminateBlockInst::Create(Context, NormalDest, Args), Name);
695 }
696
697 CleanupBlockInst *CreateCleanupBlock(Type *Ty, ArrayRef Args,
698 const Twine &Name = "") {
699 return Insert(CleanupBlockInst::Create(Ty, Args), Name);
700 }
701
702 CatchReturnInst *CreateCatchRet(BasicBlock *BB) {
703 return Insert(CatchReturnInst::Create(BB));
704 }
705
674706 UnreachableInst *CreateUnreachable() {
675707 return Insert(new UnreachableInst(Context));
676708 }
168168 RetTy visitIndirectBrInst(IndirectBrInst &I) { DELEGATE(TerminatorInst);}
169169 RetTy visitResumeInst(ResumeInst &I) { DELEGATE(TerminatorInst);}
170170 RetTy visitUnreachableInst(UnreachableInst &I) { DELEGATE(TerminatorInst);}
171 RetTy visitCleanupReturnInst(CleanupReturnInst &I) { DELEGATE(TerminatorInst);}
172 RetTy visitCatchReturnInst(CatchReturnInst &I) { DELEGATE(TerminatorInst);}
173 RetTy visitCatchBlockInst(CatchBlockInst &I) { DELEGATE(TerminatorInst);}
174 RetTy visitCatchEndBlockInst(CatchEndBlockInst &I) { DELEGATE(TerminatorInst); }
175 RetTy visitTerminateBlockInst(TerminateBlockInst &I) { DELEGATE(TerminatorInst);}
171176 RetTy visitICmpInst(ICmpInst &I) { DELEGATE(CmpInst);}
172177 RetTy visitFCmpInst(FCmpInst &I) { DELEGATE(CmpInst);}
173178 RetTy visitAllocaInst(AllocaInst &I) { DELEGATE(UnaryInstruction);}
199204 RetTy visitExtractValueInst(ExtractValueInst &I){ DELEGATE(UnaryInstruction);}
200205 RetTy visitInsertValueInst(InsertValueInst &I) { DELEGATE(Instruction); }
201206 RetTy visitLandingPadInst(LandingPadInst &I) { DELEGATE(Instruction); }
207 RetTy visitCleanupBlockInst(CleanupBlockInst &I) { DELEGATE(Instruction); }
202208
203209 // Handle the special instrinsic instruction classes.
204210 RetTy visitDbgDeclareInst(DbgDeclareInst &I) { DELEGATE(DbgInfoIntrinsic);}
7373 }
7474 static inline bool classof(const Value *V) {
7575 return isa(V) && classof(cast(V));
76 }
77
78 // \brief Returns true if this terminator relates to exception handling.
79 bool isExceptional() const {
80 switch (getOpcode()) {
81 case Instruction::CatchBlock:
82 case Instruction::CatchEndBlock:
83 case Instruction::CatchRet:
84 case Instruction::CleanupRet:
85 case Instruction::Invoke:
86 case Instruction::Resume:
87 case Instruction::TerminateBlock:
88 return true;
89 default:
90 return false;
91 }
7692 }
7793 };
7894
9393 // instructions for it to be a well formed basic block.
9494 //
9595 FIRST_TERM_INST ( 1)
96 HANDLE_TERM_INST ( 1, Ret , ReturnInst)
97 HANDLE_TERM_INST ( 2, Br , BranchInst)
98 HANDLE_TERM_INST ( 3, Switch , SwitchInst)
99 HANDLE_TERM_INST ( 4, IndirectBr , IndirectBrInst)
100 HANDLE_TERM_INST ( 5, Invoke , InvokeInst)
101 HANDLE_TERM_INST ( 6, Resume , ResumeInst)
102 HANDLE_TERM_INST ( 7, Unreachable, UnreachableInst)
103 LAST_TERM_INST ( 7)
96 HANDLE_TERM_INST ( 1, Ret , ReturnInst)
97 HANDLE_TERM_INST ( 2, Br , BranchInst)
98 HANDLE_TERM_INST ( 3, Switch , SwitchInst)
99 HANDLE_TERM_INST ( 4, IndirectBr , IndirectBrInst)
100 HANDLE_TERM_INST ( 5, Invoke , InvokeInst)
101 HANDLE_TERM_INST ( 6, Resume , ResumeInst)
102 HANDLE_TERM_INST ( 7, Unreachable , UnreachableInst)
103 HANDLE_TERM_INST ( 8, CleanupRet , CleanupReturnInst)
104 HANDLE_TERM_INST ( 9, CatchRet , CatchReturnInst)
105 HANDLE_TERM_INST (10, CatchBlock , CatchBlockInst)
106 HANDLE_TERM_INST (11, TerminateBlock, TerminateBlockInst)
107 HANDLE_TERM_INST (12, CatchEndBlock , CatchEndBlockInst)
108 LAST_TERM_INST (12)
104109
105110 // 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)
111 FIRST_BINARY_INST(13)
112 HANDLE_BINARY_INST(13, Add , BinaryOperator)
113 HANDLE_BINARY_INST(14, FAdd , BinaryOperator)
114 HANDLE_BINARY_INST(15, Sub , BinaryOperator)
115 HANDLE_BINARY_INST(16, FSub , BinaryOperator)
116 HANDLE_BINARY_INST(17, Mul , BinaryOperator)
117 HANDLE_BINARY_INST(18, FMul , BinaryOperator)
118 HANDLE_BINARY_INST(19, UDiv , BinaryOperator)
119 HANDLE_BINARY_INST(20, SDiv , BinaryOperator)
120 HANDLE_BINARY_INST(21, FDiv , BinaryOperator)
121 HANDLE_BINARY_INST(22, URem , BinaryOperator)
122 HANDLE_BINARY_INST(23, SRem , BinaryOperator)
123 HANDLE_BINARY_INST(24, FRem , BinaryOperator)
119124
120125 // 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)
126 HANDLE_BINARY_INST(25, Shl , BinaryOperator) // Shift left (logical)
127 HANDLE_BINARY_INST(26, LShr , BinaryOperator) // Shift right (logical)
128 HANDLE_BINARY_INST(27, AShr , BinaryOperator) // Shift right (arithmetic)
129 HANDLE_BINARY_INST(28, And , BinaryOperator)
130 HANDLE_BINARY_INST(29, Or , BinaryOperator)
131 HANDLE_BINARY_INST(30, Xor , BinaryOperator)
132 LAST_BINARY_INST(30)
128133
129134 // 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 HANDLE_MEMORY_INST(31, AtomicCmpXchg , AtomicCmpXchgInst )
137 HANDLE_MEMORY_INST(32, AtomicRMW , AtomicRMWInst )
138 LAST_MEMORY_INST(32)
135 FIRST_MEMORY_INST(31)
136 HANDLE_MEMORY_INST(31, Alloca, AllocaInst) // Stack management
137 HANDLE_MEMORY_INST(32, Load , LoadInst ) // Memory manipulation instrs
138 HANDLE_MEMORY_INST(33, Store , StoreInst )
139 HANDLE_MEMORY_INST(34, GetElementPtr, GetElementPtrInst)
140 HANDLE_MEMORY_INST(35, Fence , FenceInst )
141 HANDLE_MEMORY_INST(36, AtomicCmpXchg , AtomicCmpXchgInst )
142 HANDLE_MEMORY_INST(37, AtomicRMW , AtomicRMWInst )
143 LAST_MEMORY_INST(37)
139144
140145 // Cast operators ...
141146 // NOTE: The order matters here because CastInst::isEliminableCastPair
142147 // NOTE: (see Instructions.cpp) encodes a table based on this ordering.
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 HANDLE_CAST_INST(45, AddrSpaceCast, AddrSpaceCastInst) // addrspace cast
157 LAST_CAST_INST(45)
148 FIRST_CAST_INST(38)
149 HANDLE_CAST_INST(38, Trunc , TruncInst ) // Truncate integers
150 HANDLE_CAST_INST(39, ZExt , ZExtInst ) // Zero extend integers
151 HANDLE_CAST_INST(40, SExt , SExtInst ) // Sign extend integers
152 HANDLE_CAST_INST(41, FPToUI , FPToUIInst ) // floating point -> UInt
153 HANDLE_CAST_INST(42, FPToSI , FPToSIInst ) // floating point -> SInt
154 HANDLE_CAST_INST(43, UIToFP , UIToFPInst ) // UInt -> floating point
155 HANDLE_CAST_INST(44, SIToFP , SIToFPInst ) // SInt -> floating point
156 HANDLE_CAST_INST(45, FPTrunc , FPTruncInst ) // Truncate floating point
157 HANDLE_CAST_INST(46, FPExt , FPExtInst ) // Extend floating point
158 HANDLE_CAST_INST(47, PtrToInt, PtrToIntInst) // Pointer -> Integer
159 HANDLE_CAST_INST(48, IntToPtr, IntToPtrInst) // Integer -> Pointer
160 HANDLE_CAST_INST(49, BitCast , BitCastInst ) // Type cast
161 HANDLE_CAST_INST(50, AddrSpaceCast, AddrSpaceCastInst) // addrspace cast
162 LAST_CAST_INST(50)
158163
159164 // 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)
165 FIRST_OTHER_INST(51)
166 HANDLE_OTHER_INST(51, ICmp , ICmpInst ) // Integer comparison instruction
167 HANDLE_OTHER_INST(52, FCmp , FCmpInst ) // Floating point comparison instr.
168 HANDLE_OTHER_INST(53, PHI , PHINode ) // PHI node instruction
169 HANDLE_OTHER_INST(54, Call , CallInst ) // Call a function
170 HANDLE_OTHER_INST(55, Select , SelectInst ) // select instruction
171 HANDLE_OTHER_INST(56, UserOp1, Instruction) // May be used internally in a pass
172 HANDLE_OTHER_INST(57, UserOp2, Instruction) // Internal to passes only
173 HANDLE_OTHER_INST(58, VAArg , VAArgInst ) // vaarg instruction
174 HANDLE_OTHER_INST(59, ExtractElement, ExtractElementInst)// extract from vector
175 HANDLE_OTHER_INST(60, InsertElement, InsertElementInst) // insert into vector
176 HANDLE_OTHER_INST(61, ShuffleVector, ShuffleVectorInst) // shuffle two vectors.
177 HANDLE_OTHER_INST(62, ExtractValue, ExtractValueInst)// extract from aggregate
178 HANDLE_OTHER_INST(63, InsertValue, InsertValueInst) // insert into aggregate
179 HANDLE_OTHER_INST(64, LandingPad, LandingPadInst) // Landing pad instruction.
180 HANDLE_OTHER_INST(65, CleanupBlock, CleanupBlockInst)
181 LAST_OTHER_INST(65)
176182
177183 #undef FIRST_TERM_INST
178184 #undef HANDLE_TERM_INST
387387 return mayWriteToMemory() || mayThrow() || !mayReturn();
388388 }
389389
390 /// \brief Return true if the instruction is a variety of EH-block.
391 bool isEHBlock() const {
392 switch (getOpcode()) {
393 case Instruction::CatchBlock:
394 case Instruction::CatchEndBlock:
395 case Instruction::CleanupBlock:
396 case Instruction::LandingPad:
397 case Instruction::TerminateBlock:
398 return true;
399 default:
400 return false;
401 }
402 }
403
390404 /// clone() - Create a copy of 'this' instruction that is identical in all
391405 /// ways except the following:
392406 /// * The instruction has no parent
35513551 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
35523552
35533553 //===----------------------------------------------------------------------===//
3554 // CleanupReturnInst Class
3555 //===----------------------------------------------------------------------===//
3556
3557 class CleanupReturnInst : public TerminatorInst {
3558 CleanupReturnInst(const CleanupReturnInst &RI);
3559
3560 private:
3561 void init(Value *RetVal, BasicBlock *UnwindBB);
3562 CleanupReturnInst(LLVMContext &C, Value *RetVal, BasicBlock *UnwindBB,
3563 unsigned Values, Instruction *InsertBefore = nullptr);
3564 CleanupReturnInst(LLVMContext &C, Value *RetVal, BasicBlock *UnwindBB,
3565 unsigned Values, BasicBlock *InsertAtEnd);
3566
3567 int getUnwindLabelOpIdx() const {
3568 assert(hasUnwindDest());
3569 return 0;
3570 }
3571
3572 int getRetValOpIdx() const {
3573 assert(hasReturnValue());
3574 if (hasUnwindDest())
3575 return 1;
3576 return 0;
3577 }
3578
3579 protected:
3580 // Note: Instruction needs to be a friend here to call cloneImpl.
3581 friend class Instruction;
3582 CleanupReturnInst *cloneImpl() const;
3583
3584 public:
3585 static CleanupReturnInst *Create(LLVMContext &C,
3586 Value *RetVal = nullptr,
3587 BasicBlock *UnwindBB = nullptr,
3588 Instruction *InsertBefore = nullptr) {
3589 unsigned Values = 0;
3590 if (RetVal)
3591 ++Values;
3592 if (UnwindBB)
3593 ++Values;
3594 return new (Values)
3595 CleanupReturnInst(C, RetVal, UnwindBB, Values, InsertBefore);
3596 }
3597 static CleanupReturnInst *Create(LLVMContext &C, Value *RetVal,
3598 BasicBlock *UnwindBB,
3599 BasicBlock *InsertAtEnd) {
3600 unsigned Values = 0;
3601 if (RetVal)
3602 ++Values;
3603 if (UnwindBB)
3604 ++Values;
3605 return new (Values)
3606 CleanupReturnInst(C, RetVal, UnwindBB, Values, InsertAtEnd);
3607 }
3608
3609 /// Provide fast operand accessors
3610 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3611
3612 bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
3613 bool unwindsToCaller() const { return !hasUnwindDest(); }
3614 bool hasReturnValue() const { return getSubclassDataFromInstruction() & 2; }
3615
3616 /// Convenience accessor. Returns null if there is no return value.
3617 Value *getReturnValue() const {
3618 if (!hasReturnValue())
3619 return nullptr;
3620 return getOperand(getRetValOpIdx());
3621 }
3622 void setReturnValue(Value *RetVal) {
3623 assert(hasReturnValue());
3624 setOperand(getRetValOpIdx(), RetVal);
3625 }
3626
3627 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
3628
3629 BasicBlock *getUnwindDest() const;
3630 void setUnwindDest(BasicBlock *NewDest);
3631
3632 // Methods for support type inquiry through isa, cast, and dyn_cast:
3633 static inline bool classof(const Instruction *I) {
3634 return (I->getOpcode() == Instruction::CleanupRet);
3635 }
3636 static inline bool classof(const Value *V) {
3637 return isa(V) && classof(cast(V));
3638 }
3639
3640 private:
3641 BasicBlock *getSuccessorV(unsigned Idx) const override;
3642 unsigned getNumSuccessorsV() const override;
3643 void setSuccessorV(unsigned Idx, BasicBlock *B) override;
3644
3645 // Shadow Instruction::setInstructionSubclassData with a private forwarding
3646 // method so that subclasses cannot accidentally use it.
3647 void setInstructionSubclassData(unsigned short D) {
3648 Instruction::setInstructionSubclassData(D);
3649 }
3650 };
3651
3652 template <>
3653 struct OperandTraits
3654 : public VariadicOperandTraits {};
3655
3656 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CleanupReturnInst, Value)
3657
3658 //===----------------------------------------------------------------------===//
3659 // CatchEndBlockInst Class
3660 //===----------------------------------------------------------------------===//
3661
3662 class CatchEndBlockInst : public TerminatorInst {
3663 CatchEndBlockInst(const CatchEndBlockInst &RI);
3664
3665 private:
3666 void init(BasicBlock *UnwindBB);
3667 CatchEndBlockInst(LLVMContext &C, BasicBlock *UnwindBB, unsigned Values,
3668 Instruction *InsertBefore = nullptr);
3669 CatchEndBlockInst(LLVMContext &C, BasicBlock *UnwindBB, unsigned Values,
3670 BasicBlock *InsertAtEnd);
3671
3672 protected:
3673 // Note: Instruction needs to be a friend here to call cloneImpl.
3674 friend class Instruction;
3675 CatchEndBlockInst *cloneImpl() const;
3676
3677 public:
3678 static CatchEndBlockInst *Create(LLVMContext &C,
3679 BasicBlock *UnwindBB = nullptr,
3680 Instruction *InsertBefore = nullptr) {
3681 unsigned Values = UnwindBB ? 1 : 0;
3682 return new (Values) CatchEndBlockInst(C, UnwindBB, Values, InsertBefore);
3683 }
3684 static CatchEndBlockInst *Create(LLVMContext &C, BasicBlock *UnwindBB,
3685 BasicBlock *InsertAtEnd) {
3686 unsigned Values = UnwindBB ? 1 : 0;
3687 return new (Values) CatchEndBlockInst(C, UnwindBB, Values, InsertAtEnd);
3688 }
3689
3690 /// Provide fast operand accessors
3691 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3692
3693 bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
3694 bool unwindsToCaller() const { return !hasUnwindDest(); }
3695
3696 /// Convenience accessor. Returns null if there is no return value.
3697 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
3698
3699 BasicBlock *getUnwindDest() const { return cast(Op<-1>()); }
3700 void setUnwindDest(BasicBlock *NewDest) {
3701 assert(NewDest);
3702 Op<-1>() = NewDest;
3703 }
3704
3705 // Methods for support type inquiry through isa, cast, and dyn_cast:
3706 static inline bool classof(const Instruction *I) {
3707 return (I->getOpcode() == Instruction::CatchEndBlock);
3708 }
3709 static inline bool classof(const Value *V) {
3710 return isa(V) && classof(cast(V));
3711 }
3712
3713 private:
3714 BasicBlock *getSuccessorV(unsigned Idx) const override;
3715 unsigned getNumSuccessorsV() const override;
3716 void setSuccessorV(unsigned Idx, BasicBlock *B) override;
3717
3718 private:
3719 // Shadow Instruction::setInstructionSubclassData with a private forwarding
3720 // method so that subclasses cannot accidentally use it.
3721 void setInstructionSubclassData(unsigned short D) {
3722 Instruction::setInstructionSubclassData(D);
3723 }
3724 };
3725
3726 template <>
3727 struct OperandTraits
3728 : public VariadicOperandTraits {};
3729
3730 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchEndBlockInst, Value)
3731
3732 //===----------------------------------------------------------------------===//
3733 // CatchBlockInst Class
3734 //===----------------------------------------------------------------------===//
3735
3736 class CatchBlockInst : public TerminatorInst {
3737 private:
3738 void init(BasicBlock *IfNormal, BasicBlock *IfException,
3739 ArrayRef Args, const Twine &NameStr);
3740
3741 CatchBlockInst(const CatchBlockInst &CBI);
3742
3743 explicit CatchBlockInst(Type *RetTy, BasicBlock *IfNormal,
3744 BasicBlock *IfException, ArrayRef Args,
3745 unsigned Values, const Twine &NameStr,
3746 Instruction *InsertBefore);
3747 explicit CatchBlockInst(Type *RetTy, BasicBlock *IfNormal,
3748 BasicBlock *IfException, ArrayRef Args,
3749 unsigned Values, const Twine &NameStr,
3750 BasicBlock *InsertAtEnd);
3751
3752 protected:
3753 // Note: Instruction needs to be a friend here to call cloneImpl.
3754 friend class Instruction;
3755 CatchBlockInst *cloneImpl() const;
3756
3757 public:
3758 static CatchBlockInst *Create(Type *RetTy, BasicBlock *IfNormal,
3759 BasicBlock *IfException, ArrayRef Args,
3760 const Twine &NameStr = "",
3761 Instruction *InsertBefore = nullptr) {
3762 unsigned Values = unsigned(Args.size()) + 2;
3763 return new (Values) CatchBlockInst(RetTy, IfNormal, IfException, Args,
3764 Values, NameStr, InsertBefore);
3765 }
3766 static CatchBlockInst *Create(Type *RetTy, BasicBlock *IfNormal,
3767 BasicBlock *IfException, ArrayRef Args,
3768 const Twine &NameStr, BasicBlock *InsertAtEnd) {
3769 unsigned Values = unsigned(Args.size()) + 2;
3770 return new (Values) CatchBlockInst(RetTy, IfNormal, IfException, Args,
3771 Values, NameStr, InsertAtEnd);
3772 }
3773
3774 /// Provide fast operand accessors
3775 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3776
3777 /// getNumArgOperands - Return the number of catchblock arguments.
3778 ///
3779 unsigned getNumArgOperands() const { return getNumOperands() - 2; }
3780
3781 /// getArgOperand/setArgOperand - Return/set the i-th catchblock argument.
3782 ///
3783 Value *getArgOperand(unsigned i) const { return getOperand(i); }
3784 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
3785
3786 /// arg_operands - iteration adapter for range-for loops.
3787 iterator_range arg_operands() {
3788 return iterator_range(op_begin(), op_end() - 2);
3789 }
3790
3791 /// arg_operands - iteration adapter for range-for loops.
3792 iterator_range arg_operands() const {
3793 return iterator_range(op_begin(), op_end() - 2);
3794 }
3795
3796 /// \brief Wrappers for getting the \c Use of a catchblock argument.
3797 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
3798 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
3799
3800 // get*Dest - Return the destination basic blocks...
3801 BasicBlock *getNormalDest() const { return cast(Op<-2>()); }
3802 BasicBlock *getUnwindDest() const { return cast(Op<-1>()); }
3803 void setNormalDest(BasicBlock *B) { Op<-2>() = reinterpret_cast(B); }
3804 void setUnwindDest(BasicBlock *B) { Op<-1>() = reinterpret_cast(B); }
3805
3806 BasicBlock *getSuccessor(unsigned i) const {
3807 assert(i < 2 && "Successor # out of range for invoke!");
3808 return i == 0 ? getNormalDest() : getUnwindDest();
3809 }
3810
3811 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3812 assert(idx < 2 && "Successor # out of range for invoke!");
3813 *(&Op<-2>() + idx) = reinterpret_cast(NewSucc);
3814 }
3815
3816 unsigned getNumSuccessors() const { return 2; }
3817
3818 // Methods for support type inquiry through isa, cast, and dyn_cast:
3819 static inline bool classof(const Instruction *I) {
3820 return I->getOpcode() == Instruction::CatchBlock;
3821 }
3822 static inline bool classof(const Value *V) {
3823 return isa(V) && classof(cast(V));
3824 }
3825
3826 private:
3827 BasicBlock *getSuccessorV(unsigned idx) const override;
3828 unsigned getNumSuccessorsV() const override;
3829 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3830 };
3831
3832 template <>
3833 struct OperandTraits
3834 : public VariadicOperandTraits {};
3835
3836 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchBlockInst, Value)
3837
3838 //===----------------------------------------------------------------------===//
3839 // TerminateBlockInst Class
3840 //===----------------------------------------------------------------------===//
3841
3842 class TerminateBlockInst : public TerminatorInst {
3843 private:
3844 void init(BasicBlock *BB, ArrayRef Args, const Twine &NameStr);
3845
3846 TerminateBlockInst(const TerminateBlockInst &TBI);
3847
3848 explicit TerminateBlockInst(LLVMContext &C, BasicBlock *BB,
3849 ArrayRef Args, unsigned Values,
3850 const Twine &NameStr, Instruction *InsertBefore);
3851 explicit TerminateBlockInst(LLVMContext &C, BasicBlock *BB,
3852 ArrayRef Args, unsigned Values,
3853 const Twine &NameStr, BasicBlock *InsertAtEnd);
3854
3855 protected:
3856 // Note: Instruction needs to be a friend here to call cloneImpl.
3857 friend class Instruction;
3858 TerminateBlockInst *cloneImpl() const;
3859
3860 public:
3861 static TerminateBlockInst *Create(LLVMContext &C, BasicBlock *BB = nullptr,
3862 ArrayRef Args = {},
3863 const Twine &NameStr = "",
3864 Instruction *InsertBefore = nullptr) {
3865 unsigned Values = unsigned(Args.size());
3866 if (BB)
3867 ++Values;
3868 return new (Values)
3869 TerminateBlockInst(C, BB, Args, Values, NameStr, InsertBefore);
3870 }
3871 static TerminateBlockInst *Create(LLVMContext &C, BasicBlock *BB,
3872 ArrayRef Args,
3873 const Twine &NameStr,
3874 BasicBlock *InsertAtEnd) {
3875 unsigned Values = unsigned(Args.size());
3876 if (BB)
3877 ++Values;
3878 return new (Values)
3879 TerminateBlockInst(C, BB, Args, Values, NameStr, InsertAtEnd);
3880 }
3881
3882 /// Provide fast operand accessors
3883 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3884
3885 bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
3886 bool unwindsToCaller() const { return !hasUnwindDest(); }
3887
3888 /// getNumArgOperands - Return the number of terminateblock arguments.
3889 ///
3890 unsigned getNumArgOperands() const {
3891 unsigned NumOperands = getNumOperands();
3892 if (hasUnwindDest())
3893 return NumOperands - 1;
3894 return NumOperands;
3895 }
3896
3897 /// getArgOperand/setArgOperand - Return/set the i-th terminateblock argument.
3898 ///
3899 Value *getArgOperand(unsigned i) const { return getOperand(i); }
3900 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
3901
3902 const_op_iterator arg_end() const {
3903 if (hasUnwindDest())
3904 return op_end() - 1;
3905 return op_end();
3906 }
3907
3908 op_iterator arg_end() {
3909 if (hasUnwindDest())
3910 return op_end() - 1;
3911 return op_end();
3912 }
3913
3914 /// arg_operands - iteration adapter for range-for loops.
3915 iterator_range arg_operands() {
3916 return iterator_range(op_begin(), arg_end());
3917 }
3918
3919 /// arg_operands - iteration adapter for range-for loops.
3920 iterator_range arg_operands() const {
3921 return iterator_range(op_begin(), arg_end());
3922 }
3923
3924 /// \brief Wrappers for getting the \c Use of a terminateblock argument.
3925 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
3926 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
3927
3928 // get*Dest - Return the destination basic blocks...
3929 BasicBlock *getUnwindDest() const {
3930 if (!hasUnwindDest())
3931 return nullptr;
3932 return cast(Op<-1>());
3933 }
3934 void setUnwindDest(BasicBlock *B) {
3935 assert(B && hasUnwindDest());
3936 Op<-1>() = reinterpret_cast(B);
3937 }
3938
3939 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
3940
3941 // Methods for support type inquiry through isa, cast, and dyn_cast:
3942 static inline bool classof(const Instruction *I) {
3943 return I->getOpcode() == Instruction::TerminateBlock;
3944 }
3945 static inline bool classof(const Value *V) {
3946 return isa(V) && classof(cast(V));
3947 }
3948
3949 private:
3950 BasicBlock *getSuccessorV(unsigned idx) const override;
3951 unsigned getNumSuccessorsV() const override;
3952 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3953
3954 // Shadow Instruction::setInstructionSubclassData with a private forwarding
3955 // method so that subclasses cannot accidentally use it.
3956 void setInstructionSubclassData(unsigned short D) {
3957 Instruction::setInstructionSubclassData(D);
3958 }
3959 };
3960
3961 template <>
3962 struct OperandTraits
3963 : public VariadicOperandTraits {};
3964
3965 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(TerminateBlockInst, Value)
3966
3967 //===----------------------------------------------------------------------===//
3968 // CleanupBlockInst Class
3969 //===----------------------------------------------------------------------===//
3970
3971 class CleanupBlockInst : public Instruction {
3972 private:
3973 void init(ArrayRef Args, const Twine &NameStr);
3974
3975 CleanupBlockInst(const CleanupBlockInst &TBI);
3976
3977 explicit CleanupBlockInst(Type *RetTy, ArrayRef Args,
3978 const Twine &NameStr, Instruction *InsertBefore);
3979 explicit CleanupBlockInst(Type *RetTy, ArrayRef Args,
3980 const Twine &NameStr, BasicBlock *InsertAtEnd);
3981
3982 protected:
3983 // Note: Instruction needs to be a friend here to call cloneImpl.
3984 friend class Instruction;
3985 CleanupBlockInst *cloneImpl() const;
3986
3987 public:
3988 static CleanupBlockInst *Create(Type *RetTy, ArrayRef Args,
3989 const Twine &NameStr = "",
3990 Instruction *InsertBefore = nullptr) {
3991 return new (Args.size())
3992 CleanupBlockInst(RetTy, Args, NameStr, InsertBefore);
3993 }
3994 static CleanupBlockInst *Create(Type *RetTy, ArrayRef Args,
3995 const Twine &NameStr,
3996 BasicBlock *InsertAtEnd) {
3997 return new (Args.size())
3998 CleanupBlockInst(RetTy, Args, NameStr, InsertAtEnd);
3999 }
4000
4001 /// Provide fast operand accessors
4002 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
4003
4004 // Methods for support type inquiry through isa, cast, and dyn_cast:
4005 static inline bool classof(const Instruction *I) {
4006 return I->getOpcode() == Instruction::CleanupBlock;
4007 }
4008 static inline bool classof(const Value *V) {
4009 return isa(V) && classof(cast(V));
4010 }
4011 };
4012
4013 template <>
4014 struct OperandTraits
4015 : public VariadicOperandTraits {};
4016
4017 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CleanupBlockInst, Value)
4018
4019 //===----------------------------------------------------------------------===//
4020 // CatchReturnInst Class
4021 //===----------------------------------------------------------------------===//
4022
4023 class CatchReturnInst : public TerminatorInst {
4024 CatchReturnInst(const CatchReturnInst &RI);
4025
4026 private:
4027 void init(Value *RetVal, BasicBlock *UnwindBB);
4028 CatchReturnInst(BasicBlock *BB, Instruction *InsertBefore = nullptr);
4029 CatchReturnInst(BasicBlock *BB, BasicBlock *InsertAtEnd);
4030
4031 protected:
4032 // Note: Instruction needs to be a friend here to call cloneImpl.
4033 friend class Instruction;
4034 CatchReturnInst *cloneImpl() const;
4035
4036 public:
4037 static CatchReturnInst *Create(BasicBlock *BB,
4038 Instruction *InsertBefore = nullptr) {
4039 return new (1) CatchReturnInst(BB, InsertBefore);
4040 }
4041 static CatchReturnInst *Create(BasicBlock *BB, BasicBlock *InsertAtEnd) {
4042 return new (1) CatchReturnInst(BB, InsertAtEnd);
4043 }
4044
4045 /// Provide fast operand accessors
4046 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
4047
4048 /// Convenience accessors.
4049 BasicBlock *getSuccessor() const { return cast(Op<0>()); }
4050 void setSuccessor(BasicBlock *NewSucc) { Op<0>() = (Value *)NewSucc; }
4051 unsigned getNumSuccessors() const { return 1; }
4052
4053 // Methods for support type inquiry through isa, cast, and dyn_cast:
4054 static inline bool classof(const Instruction *I) {
4055 return (I->getOpcode() == Instruction::CatchRet);
4056 }
4057 static inline bool classof(const Value *V) {
4058 return isa(V) && classof(cast(V));
4059 }
4060
4061 private:
4062 BasicBlock *getSuccessorV(unsigned Idx) const override;
4063 unsigned getNumSuccessorsV() const override;
4064 void setSuccessorV(unsigned Idx, BasicBlock *B) override;
4065 };
4066
4067 template <>
4068 struct OperandTraits
4069 : public FixedNumOperandTraits {};
4070
4071 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchReturnInst, Value)
4072
4073 //===----------------------------------------------------------------------===//
35544074 // UnreachableInst Class
35554075 //===----------------------------------------------------------------------===//
35564076
247247
248248 /* Exception Handling Operators */
249249 LLVMResume = 58,
250 LLVMLandingPad = 59
250 LLVMLandingPad = 59,
251 LLVMCleanupRet = 61,
252 LLVMCatchRet = 62,
253 LLVMCatchBlock = 63,
254 LLVMTerminateBlock = 64,
255 LLVMCleanupBlock = 65,
256 LLVMCatchEndBlock = 66
251257
252258 } LLVMOpcode;
253259
12021208 macro(InsertElementInst) \
12031209 macro(InsertValueInst) \
12041210 macro(LandingPadInst) \
1211 macro(CleanupBlockInst) \
12051212 macro(PHINode) \
12061213 macro(SelectInst) \
12071214 macro(ShuffleVectorInst) \
12141221 macro(SwitchInst) \
12151222 macro(UnreachableInst) \
12161223 macro(ResumeInst) \
1224 macro(CleanupReturnInst) \
1225 macro(CatchReturnInst) \
1226 macro(CatchBlockInst) \
1227 macro(TerminateBlockInst) \
1228 macro(CatchEndBlockInst) \
12171229 macro(UnaryInstruction) \
12181230 macro(AllocaInst) \
12191231 macro(CastInst) \
155155 bool visitSwitchInst(SwitchInst &SI);
156156 bool visitIndirectBrInst(IndirectBrInst &IBI);
157157 bool visitResumeInst(ResumeInst &RI);
158 bool visitCleanupReturnInst(CleanupReturnInst &RI);
159 bool visitCatchReturnInst(CatchReturnInst &RI);
158160 bool visitUnreachableInst(UnreachableInst &I);
159161
160162 public:
902904 return false;
903905 }
904906
907 bool CallAnalyzer::visitCleanupReturnInst(CleanupReturnInst &CRI) {
908 // FIXME: It's not clear that a single instruction is an accurate model for
909 // the inline cost of a cleanupret instruction.
910 return false;
911 }
912
913 bool CallAnalyzer::visitCatchReturnInst(CatchReturnInst &CRI) {
914 // FIXME: It's not clear that a single instruction is an accurate model for
915 // the inline cost of a cleanupret instruction.
916 return false;
917 }
918
905919 bool CallAnalyzer::visitUnreachableInst(UnreachableInst &I) {
906920 // FIXME: It might be reasonably to discount the cost of instructions leading
907921 // to unreachable as they have the lowest possible impact on both runtime and
523523 KEYWORD(undef);
524524 KEYWORD(null);
525525 KEYWORD(to);
526 KEYWORD(caller);
526527 KEYWORD(tail);
527528 KEYWORD(musttail);
528529 KEYWORD(target);
747748 INSTKEYWORD(extractvalue, ExtractValue);
748749 INSTKEYWORD(insertvalue, InsertValue);
749750 INSTKEYWORD(landingpad, LandingPad);
751 INSTKEYWORD(cleanupret, CleanupRet);
752 INSTKEYWORD(catchret, CatchRet);
753 INSTKEYWORD(catchblock, CatchBlock);
754 INSTKEYWORD(terminateblock, TerminateBlock);
755 INSTKEYWORD(cleanupblock, CleanupBlock);
756 INSTKEYWORD(catchendblock, CatchEndBlock);
750757 #undef INSTKEYWORD
751758
752759 #define DWKEYWORD(TYPE, TOKEN) \
44884488 case lltok::kw_indirectbr: return ParseIndirectBr(Inst, PFS);
44894489 case lltok::kw_invoke: return ParseInvoke(Inst, PFS);
44904490 case lltok::kw_resume: return ParseResume(Inst, PFS);
4491 case lltok::kw_cleanupret: return ParseCleanupRet(Inst, PFS);
4492 case lltok::kw_catchret: return ParseCatchRet(Inst, PFS);
4493 case lltok::kw_catchblock: return ParseCatchBlock(Inst, PFS);
4494 case lltok::kw_terminateblock: return ParseTerminateBlock(Inst, PFS);
4495 case lltok::kw_cleanupblock: return ParseCleanupBlock(Inst, PFS);
4496 case lltok::kw_catchendblock: return ParseCatchEndBlock(Inst, PFS);
44914497 // Binary Operators.
44924498 case lltok::kw_add:
44934499 case lltok::kw_sub:
48814887 return false;
48824888 }
48834889
4890 bool LLParser::ParseExceptionArgs(SmallVectorImpl &Args,
4891 PerFunctionState &PFS) {
4892 if (ParseToken(lltok::lsquare, "expected '[' in cleanupblock"))
4893 return true;
4894
4895 while (Lex.getKind() != lltok::rsquare) {
4896 // If this isn't the first argument, we need a comma.
4897 if (!Args.empty() &&
4898 ParseToken(lltok::comma, "expected ',' in argument list"))
4899 return true;
4900
4901 // Parse the argument.
4902 LocTy ArgLoc;
4903 Type *ArgTy = nullptr;
4904 if (ParseType(ArgTy, ArgLoc))
4905 return true;
4906
4907 Value *V;
4908 if (ArgTy->isMetadataTy()) {
4909 if (ParseMetadataAsValue(V, PFS))
4910 return true;
4911 } else {
4912 if (ParseValue(ArgTy, V, PFS))
4913 return true;
4914 }
4915 Args.push_back(V);
4916 }
4917
4918 Lex.Lex(); // Lex the ']'.
4919 return false;
4920 }
4921
4922 /// ParseCleanupRet
4923 /// ::= 'cleanupret' ('void' | TypeAndValue) unwind ('to' 'caller' | TypeAndValue)
4924 bool LLParser::ParseCleanupRet(Instruction *&Inst, PerFunctionState &PFS) {
4925 Type *RetTy = nullptr;
4926 Value *RetVal = nullptr;
4927 if (ParseType(RetTy, /*AllowVoid=*/true))
4928 return true;
4929
4930 if (!RetTy->isVoidTy())
4931 if (ParseValue(RetTy, RetVal, PFS))
4932 return true;
4933
4934 if (ParseToken(lltok::kw_unwind, "expected 'unwind' in cleanupret"))
4935 return true;
4936
4937 BasicBlock *UnwindBB = nullptr;
4938 if (Lex.getKind() == lltok::kw_to) {
4939 Lex.Lex();
4940 if (ParseToken(lltok::kw_caller, "expected 'caller' in cleanupret"))
4941 return true;
4942 } else {
4943 if (ParseTypeAndBasicBlock(UnwindBB, PFS)) {
4944 return true;
4945 }
4946 }
4947
4948 Inst = CleanupReturnInst::Create(Context, RetVal, UnwindBB);
4949 return false;
4950 }
4951
4952 /// ParseCatchRet
4953 /// ::= 'catchret' TypeAndValue
4954 bool LLParser::ParseCatchRet(Instruction *&Inst, PerFunctionState &PFS) {
4955 BasicBlock *BB;
4956 if (ParseTypeAndBasicBlock(BB, PFS))
4957 return true;
4958
4959 Inst = CatchReturnInst::Create(BB);
4960 return false;
4961 }
4962
4963 /// ParseCatchBlock
4964 /// ::= 'catchblock' Type ParamList 'to' TypeAndValue 'unwind' TypeAndValue
4965 bool LLParser::ParseCatchBlock(Instruction *&Inst, PerFunctionState &PFS) {
4966 Type *RetType = nullptr;
4967
4968 SmallVector Args;
4969 if (ParseType(RetType, /*AllowVoid=*/true) || ParseExceptionArgs(Args, PFS))
4970 return true;
4971
4972 BasicBlock *NormalBB, *UnwindBB;
4973 if (ParseToken(lltok::kw_to, "expected 'to' in catchblock") ||
4974 ParseTypeAndBasicBlock(NormalBB, PFS) ||
4975 ParseToken(lltok::kw_unwind, "expected 'unwind' in catchblock") ||
4976 ParseTypeAndBasicBlock(UnwindBB, PFS))
4977 return true;
4978
4979 Inst = CatchBlockInst::Create(RetType, NormalBB, UnwindBB, Args);
4980 return false;
4981 }
4982
4983 /// ParseTerminateBlock
4984 /// ::= 'terminateblock' ParamList 'to' TypeAndValue
4985 bool LLParser::ParseTerminateBlock(Instruction *&Inst, PerFunctionState &PFS) {
4986 SmallVector Args;
4987 if (ParseExceptionArgs(Args, PFS))
4988 return true;
4989
4990 if (ParseToken(lltok::kw_unwind, "expected 'unwind' in terminateblock"))
4991 return true;
4992
4993 BasicBlock *UnwindBB = nullptr;
4994 if (Lex.getKind() == lltok::kw_to) {
4995 Lex.Lex();
4996 if (ParseToken(lltok::kw_caller, "expected 'caller' in cleanupret"))
4997 return true;
4998 } else {
4999 if (ParseTypeAndBasicBlock(UnwindBB, PFS)) {
5000 return true;
5001 }
5002 }
5003
5004 Inst = TerminateBlockInst::Create(Context, UnwindBB, Args);
5005 return false;
5006 }
5007
5008 /// ParseCleanupBlock
5009 /// ::= 'cleanupblock' ParamList
5010 bool LLParser::ParseCleanupBlock(Instruction *&Inst, PerFunctionState &PFS) {
5011 Type *RetType = nullptr;
5012
5013 SmallVector Args;
5014 if (ParseType(RetType, /*AllowVoid=*/true) || ParseExceptionArgs(Args, PFS))
5015 return true;
5016
5017 Inst = CleanupBlockInst::Create(RetType, Args);
5018 return false;
5019 }
5020
5021 /// ParseCatchEndBlock
5022 /// ::= 'catchendblock' unwind ('to' 'caller' | TypeAndValue)
5023 bool LLParser::ParseCatchEndBlock(Instruction *&Inst, PerFunctionState &PFS) {
5024 if (ParseToken(lltok::kw_unwind, "expected 'unwind' in cleanupret"))
5025 return true;
5026
5027 BasicBlock *UnwindBB = nullptr;
5028 if (Lex.getKind() == lltok::kw_to) {
5029 Lex.Lex();
5030 if (Lex.getKind() == lltok::kw_caller) {
5031 Lex.Lex();
5032 } else {
5033 return true;
5034 }
5035 } else {
5036 if (ParseTypeAndBasicBlock(UnwindBB, PFS)) {
5037 return true;
5038 }
5039 }
5040
5041 Inst = CatchEndBlockInst::Create(Context, UnwindBB);
5042 return false;
5043 }
5044
48845045 //===----------------------------------------------------------------------===//
48855046 // Binary Operators.
48865047 //===----------------------------------------------------------------------===//
380380 bool IsMustTailCall = false,
381381 bool InVarArgsFunc = false);
382382
383 bool ParseExceptionArgs(SmallVectorImpl &Args,
384 PerFunctionState &PFS);
385
383386 // Constant Parsing.
384387 bool ParseValID(ValID &ID, PerFunctionState *PFS = nullptr);
385388 bool ParseGlobalValue(Type *Ty, Constant *&V);
440443 bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
441444 bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
442445 bool ParseResume(Instruction *&Inst, PerFunctionState &PFS);
446 bool ParseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
447 bool ParseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
448 bool ParseCatchBlock(Instruction *&Inst, PerFunctionState &PFS);
449 bool ParseTerminateBlock(Instruction *&Inst, PerFunctionState &PFS);
450 bool ParseCleanupBlock(Instruction *&Inst, PerFunctionState &PFS);
451 bool ParseCatchEndBlock(Instruction *&Inst, PerFunctionState &PFS);
443452
444453 bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc,
445454 unsigned OperandType);
5050 kw_zeroinitializer,
5151 kw_undef, kw_null,
5252 kw_to,
53 kw_caller,
5354 kw_tail,
5455 kw_musttail,
5556 kw_target,
175176 kw_landingpad, kw_personality, kw_cleanup, kw_catch, kw_filter,
176177
177178 kw_ret, kw_br, kw_switch, kw_indirectbr, kw_invoke, kw_resume,
178 kw_unreachable,
179 kw_unreachable, kw_cleanupret, kw_catchret, kw_catchblock,
180 kw_terminateblock, kw_cleanupblock, kw_catchendblock,
179181
180182 kw_alloca, kw_load, kw_store, kw_fence, kw_cmpxchg, kw_atomicrmw,
181183 kw_getelementptr,
37923792 }
37933793 break;
37943794 }
3795 // CLEANUPRET: [] or [ty,val] or [bb#] or [ty,val,bb#]
3796 case bitc::FUNC_CODE_INST_CLEANUPRET: {
3797 if (Record.size() < 2)
3798 return error("Invalid record");
3799 unsigned Idx = 0;
3800 bool HasReturnValue = !!Record[Idx++];
3801 bool HasUnwindDest = !!Record[Idx++];
3802 Value *RetVal = nullptr;
3803 BasicBlock *UnwindDest = nullptr;
3804
3805 if (HasReturnValue && getValueTypePair(Record, Idx, NextValueNo, RetVal))
3806 return error("Invalid record");
3807 if (HasUnwindDest) {
3808 if (Idx == Record.size())
3809 return error("Invalid record");
3810 UnwindDest = getBasicBlock(Record[Idx++]);
3811 if (!UnwindDest)
3812 return error("Invalid record");
3813 }
3814
3815 if (Record.size() != Idx)
3816 return error("Invalid record");
3817
3818 I = CleanupReturnInst::Create(Context, RetVal, UnwindDest);
3819 InstructionList.push_back(I);
3820 break;
3821 }
3822 case bitc::FUNC_CODE_INST_CATCHRET: { // CATCHRET: [bb#]
3823 if (Record.size() != 1)
3824 return error("Invalid record");
3825 BasicBlock *BB = getBasicBlock(Record[0]);
3826 if (!BB)
3827 return error("Invalid record");
3828 I = CatchReturnInst::Create(BB);
3829 InstructionList.push_back(I);
3830 break;
3831 }
3832 case bitc::FUNC_CODE_INST_CATCHBLOCK: { // CATCHBLOCK: [ty,bb#,bb#,num,(ty,val)*]
3833 if (Record.size() < 4)
3834 return error("Invalid record");
3835 unsigned Idx = 0;
3836 Type *Ty = getTypeByID(Record[Idx++]);
3837 if (!Ty)
3838 return error("Invalid record");
3839 BasicBlock *NormalBB = getBasicBlock(Record[Idx++]);
3840 if (!NormalBB)
3841 return error("Invalid record");
3842 BasicBlock *UnwindBB = getBasicBlock(Record[Idx++]);
3843 if (!UnwindBB)
3844 return error("Invalid record");
3845 unsigned NumArgOperands = Record[Idx++];
3846 SmallVector Args;
3847 for (unsigned Op = 0; Op != NumArgOperands; ++Op) {
3848 Value *Val;
3849 if (getValueTypePair(Record, Idx, NextValueNo, Val))
3850 return error("Invalid record");
3851 Args.push_back(Val);
3852 }
3853 if (Record.size() != Idx)
3854 return error("Invalid record");
3855
3856 I = CatchBlockInst::Create(Ty, NormalBB, UnwindBB, Args);
3857 InstructionList.push_back(I);
3858 break;
3859 }
3860 case bitc::FUNC_CODE_INST_TERMINATEBLOCK: { // TERMINATEBLOCK: [bb#,num,(ty,val)*]
3861 if (Record.size() < 1)
3862 return error("Invalid record");
3863 unsigned Idx = 0;
3864 bool HasUnwindDest = !!Record[Idx++];
3865 BasicBlock *UnwindDest = nullptr;
3866 if (HasUnwindDest) {
3867 if (Idx == Record.size())
3868 return error("Invalid record");
3869 UnwindDest = getBasicBlock(Record[Idx++]);
3870 if (!UnwindDest)
3871 return error("Invalid record");
3872 }
3873 unsigned NumArgOperands = Record[Idx++];
3874 SmallVector Args;
3875 for (unsigned Op = 0; Op != NumArgOperands; ++Op) {
3876 Value *Val;
3877 if (getValueTypePair(Record, Idx, NextValueNo, Val))
3878 return error("Invalid record");
3879 Args.push_back(Val);
3880 }
3881 if (Record.size() != Idx)
3882 return error("Invalid record");
3883
3884 I = TerminateBlockInst::Create(Context, UnwindDest, Args);
3885 InstructionList.push_back(I);
3886 break;
3887 }
3888 case bitc::FUNC_CODE_INST_CLEANUPBLOCK: { // CLEANUPBLOCK: [ty, num,(ty,val)*]
3889 if (Record.size() < 2)
3890 return error("Invalid record");
3891 unsigned Idx = 0;
3892 Type *Ty = getTypeByID(Record[Idx++]);
3893 if (!Ty)
3894 return error("Invalid record");
3895 unsigned NumArgOperands = Record[Idx++];
3896 SmallVector Args;
3897 for (unsigned Op = 0; Op != NumArgOperands; ++Op) {
3898 Value *Val;
3899 if (getValueTypePair(Record, Idx, NextValueNo, Val))
3900 return error("Invalid record");
3901 Args.push_back(Val);
3902 }
3903 if (Record.size() != Idx)
3904 return error("Invalid record");
3905
3906 I = CleanupBlockInst::Create(Ty, Args);
3907 InstructionList.push_back(I);
3908 break;
3909 }
3910 case bitc::FUNC_CODE_INST_CATCHENDBLOCK: { // CATCHENDBLOCKINST: [bb#] or []
3911 if (Record.size() > 1)
3912 return error("Invalid record");
3913 BasicBlock *BB = nullptr;
3914 if (Record.size() == 1) {
3915 BB = getBasicBlock(Record[0]);
3916 if (!BB)
3917 return error("Invalid record");
3918 }
3919 I = CatchEndBlockInst::Create(Context, BB);
3920 InstructionList.push_back(I);
3921 break;
3922 }
37953923 case bitc::FUNC_CODE_INST_SWITCH: { // SWITCH: [opty, op0, op1, ...]
37963924 // Check magic
37973925 if ((Record[0] >> 16) == SWITCH_INST_MAGIC) {
18441844 Code = bitc::FUNC_CODE_INST_RESUME;
18451845 PushValueAndType(I.getOperand(0), InstID, Vals, VE);
18461846 break;
1847 case Instruction::CleanupRet: {
1848 Code = bitc::FUNC_CODE_INST_CLEANUPRET;
1849 const auto &CRI = cast(I);
1850 Vals.push_back(CRI.hasReturnValue());
1851 Vals.push_back(CRI.hasUnwindDest());
1852 if (CRI.hasReturnValue())
1853 PushValueAndType(CRI.getReturnValue(), InstID, Vals, VE);
1854 if (CRI.hasUnwindDest())
1855 Vals.push_back(VE.getValueID(CRI.getUnwindDest()));
1856 break;
1857 }
1858 case Instruction::CatchRet: {
1859 Code = bitc::FUNC_CODE_INST_CATCHRET;
1860 const auto &CRI = cast(I);
1861 Vals.push_back(VE.getValueID(CRI.getSuccessor()));
1862 break;
1863 }
1864 case Instruction::CatchBlock: {
1865 Code = bitc::FUNC_CODE_INST_CATCHBLOCK;
1866 const auto &CBI = cast(I);
1867 Vals.push_back(VE.getTypeID(CBI.getType()));
1868 Vals.push_back(VE.getValueID(CBI.getNormalDest()));
1869 Vals.push_back(VE.getValueID(CBI.getUnwindDest()));
1870 unsigned NumArgOperands = CBI.getNumArgOperands();
1871 Vals.push_back(NumArgOperands);
1872 for (unsigned Op = 0; Op != NumArgOperands; ++Op)
1873 PushValueAndType(CBI.getArgOperand(Op), InstID, Vals, VE);
1874 break;
1875 }
1876 case Instruction::TerminateBlock: {
1877 Code = bitc::FUNC_CODE_INST_TERMINATEBLOCK;
1878 const auto &TBI = cast(I);
1879 Vals.push_back(TBI.hasUnwindDest());
1880 if (TBI.hasUnwindDest())
1881 Vals.push_back(VE.getValueID(TBI.getUnwindDest()));
1882 unsigned NumArgOperands = TBI.getNumArgOperands();
1883 Vals.push_back(NumArgOperands);
1884 for (unsigned Op = 0; Op != NumArgOperands; ++Op)
1885 PushValueAndType(TBI.getArgOperand(Op), InstID, Vals, VE);
1886 break;
1887 }
1888 case Instruction::CleanupBlock: {
1889 Code = bitc::FUNC_CODE_INST_CLEANUPBLOCK;
1890 const auto &CBI = cast(I);
1891 Vals.push_back(VE.getTypeID(CBI.getType()));
1892 unsigned NumOperands = CBI.getNumOperands();
1893 Vals.push_back(NumOperands);
1894 for (unsigned Op = 0; Op != NumOperands; ++Op)
1895 PushValueAndType(CBI.getOperand(Op), InstID, Vals, VE);
1896 break;
1897 }
1898 case Instruction::CatchEndBlock: {
1899 Code = bitc::FUNC_CODE_INST_CATCHENDBLOCK;
1900 const auto &CEBI = cast(I);
1901 if (CEBI.hasUnwindDest())
1902 Vals.push_back(VE.getValueID(CEBI.getUnwindDest()));
1903 break;
1904 }
18471905 case Instruction::Unreachable:
18481906 Code = bitc::FUNC_CODE_INST_UNREACHABLE;
18491907 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
11651165 }
11661166
11671167 llvm_unreachable("Can't get register for value!");
1168 }
1169
1170 void SelectionDAGBuilder::visitCleanupRet(const CleanupReturnInst &I) {
1171 report_fatal_error("visitCleanupRet not yet implemented!");
1172 }
1173
1174 void SelectionDAGBuilder::visitCatchEndBlock(const CatchEndBlockInst &I) {
1175 report_fatal_error("visitCatchEndBlock not yet implemented!");
1176 }
1177
1178 void SelectionDAGBuilder::visitCatchRet(const CatchReturnInst &I) {
1179 report_fatal_error("visitCatchRet not yet implemented!");
1180 }
1181
1182 void SelectionDAGBuilder::visitCatchBlock(const CatchBlockInst &I) {
1183 report_fatal_error("visitCatchBlock not yet implemented!");
1184 }
1185
1186 void SelectionDAGBuilder::visitTerminateBlock(const TerminateBlockInst &TBI) {
1187 report_fatal_error("visitTerminateBlock not yet implemented!");
1188 }
1189
1190 void SelectionDAGBuilder::visitCleanupBlock(const CleanupBlockInst &TBI) {
1191 report_fatal_error("visitCleanupBlock not yet implemented!");
11681192 }
11691193
11701194 void SelectionDAGBuilder::visitRet(const ReturnInst &I) {
733733 void visitSwitch(const SwitchInst &I);
734734 void visitIndirectBr(const IndirectBrInst &I);
735735 void visitUnreachable(const UnreachableInst &I);
736 void visitCleanupRet(const CleanupReturnInst &I);
737 void visitCatchEndBlock(const CatchEndBlockInst &I);
738 void visitCatchRet(const CatchReturnInst &I);
739 void visitCatchBlock(const CatchBlockInst &I);
740 void visitTerminateBlock(const TerminateBlockInst &TBI);
741 void visitCleanupBlock(const CleanupBlockInst &CBI);
736742
737743 uint32_t getEdgeWeight(const MachineBasicBlock *Src,
738744 const MachineBasicBlock *Dst) const;
15451545 case Invoke: return 0;
15461546 case Resume: return 0;
15471547 case Unreachable: return 0;
1548 case CleanupRet: return 0;
1549 case CatchEndBlock: return 0;
1550 case CatchRet: return 0;
1551 case CatchBlock: return 0;
1552 case TerminateBlock: return 0;
1553 case CleanupBlock: return 0;
15481554 case Add: return ISD::ADD;
15491555 case FAdd: return ISD::FADD;
15501556 case Sub: return ISD::SUB;
28472847
28482848 writeOperand(LPI->getClause(i), true);
28492849 }
2850 } else if (const auto *CBI = dyn_cast(&I)) {
2851 Out << ' ';
2852 TypePrinter.print(I.getType(), Out);
2853
2854 Out << " [";
2855 for (unsigned Op = 0, NumOps = CBI->getNumArgOperands(); Op < NumOps;
2856 ++Op) {
2857 if (Op > 0)
2858 Out << ", ";
2859 writeOperand(CBI->getArgOperand(Op), /*PrintType=*/true);
2860 }
2861 Out << "] to ";
2862 writeOperand(CBI->getNormalDest(), /*PrintType=*/true);
2863 Out << " unwind ";
2864 writeOperand(CBI->getUnwindDest(), /*PrintType=*/true);
2865 } else if (const auto *TBI = dyn_cast(&I)) {
2866 Out << " [";
2867 for (unsigned Op = 0, NumOps = TBI->getNumArgOperands(); Op < NumOps;
2868 ++Op) {
2869 if (Op > 0)
2870 Out << ", ";
2871 writeOperand(TBI->getArgOperand(Op), /*PrintType=*/true);
2872 }
2873 Out << "] unwind ";
2874 if (TBI->hasUnwindDest())
2875 writeOperand(TBI->getUnwindDest(), /*PrintType=*/true);
2876 else
2877 Out << "to caller";
2878 } else if (const auto *CBI = dyn_cast(&I)) {
2879 Out << ' ';
2880 TypePrinter.print(I.getType(), Out);
2881
2882 Out << " [";
2883 for (unsigned Op = 0, NumOps = CBI->getNumOperands(); Op < NumOps; ++Op) {
2884 if (Op > 0)
2885 Out << ", ";
2886 writeOperand(CBI->getOperand(Op), /*PrintType=*/true);
2887 }
2888 Out << "]";
28502889 } else if (isa(I) && !Operand) {
28512890 Out << " void";
2891 } else if (const auto *CRI = dyn_cast(&I)) {
2892 if (CRI->hasReturnValue()) {
2893 Out << ' ';
2894 writeOperand(CRI->getReturnValue(), /*PrintType=*/true);
2895 } else {
2896 Out << " void";
2897 }
2898
2899 Out << " unwind ";
2900 if (CRI->hasUnwindDest())
2901 writeOperand(CRI->getUnwindDest(), /*PrintType=*/true);
2902 else
2903 Out << "to caller";
2904 } else if (const auto *CEBI = dyn_cast(&I)) {
2905 Out << " unwind ";
2906 if (CEBI->hasUnwindDest())
2907 writeOperand(CEBI->getUnwindDest(), /*PrintType=*/true);
2908 else
2909 Out << "to caller";
28522910 } else if (const CallInst *CI = dyn_cast(&I)) {
28532911 // Print the calling convention being used.
28542912 if (CI->getCallingConv() != CallingConv::C) {
196196 return end();
197197
198198 iterator InsertPt = FirstNonPHI;
199 if (isa(InsertPt)) ++InsertPt;
199 if (InsertPt->isEHBlock()) ++InsertPt;
200200 return InsertPt;
201201 }
202202
195195 case Invoke: return "invoke";
196196 case Resume: return "resume";
197197 case Unreachable: return "unreachable";
198 case CleanupRet: return "cleanupret";
199 case CatchEndBlock: return "catchendblock";
200 case CatchRet: return "catchret";
201 case CatchBlock: return "catchblock";
202 case TerminateBlock: return "terminateblock";
198203
199204 // Standard binary operators...
200205 case Add: return "add";
255260 case ExtractValue: return "extractvalue";
256261 case InsertValue: return "insertvalue";
257262 case LandingPad: return "landingpad";
263 case CleanupBlock: return "cleanupblock";
258264
259265 default: return " ";
260266 }
406412 case Instruction::Fence: // FIXME: refine definition of mayReadFromMemory
407413 case Instruction::AtomicCmpXchg:
408414 case Instruction::AtomicRMW:
415 case Instruction::CatchRet:
416 case Instruction::TerminateBlock:
409417 return true;
410418 case Instruction::Call:
411419 return !cast(this)->doesNotAccessMemory();
426434 case Instruction::VAArg:
427435 case Instruction::AtomicCmpXchg:
428436 case Instruction::AtomicRMW:
437 case Instruction::CatchRet:
438 case Instruction::TerminateBlock:
429439 return true;
430440 case Instruction::Call:
431441 return !cast(this)->onlyReadsMemory();
454464 bool Instruction::mayThrow() const {
455465 if (const CallInst *CI = dyn_cast(this))
456466 return !CI->doesNotThrow();
467 if (const auto *CRI = dyn_cast(this))
468 return CRI->unwindsToCaller();
469 if (const auto *CEBI = dyn_cast(this))
470 return CEBI->unwindsToCaller();
457471 return isa(this);
458472 }
459473
667667
668668 BasicBlock *ResumeInst::getSuccessorV(unsigned idx) const {
669669 llvm_unreachable("ResumeInst has no successors!");
670 }
671
672 //===----------------------------------------------------------------------===//
673 // CleanupReturnInst Implementation
674 //===----------------------------------------------------------------------===//
675
676 CleanupReturnInst::CleanupReturnInst(const CleanupReturnInst &CRI)
677 : TerminatorInst(CRI.getType(), Instruction::CleanupRet,
678 OperandTraits::op_end(this) -
679 CRI.getNumOperands(),
680 CRI.getNumOperands()) {
681 SubclassOptionalData = CRI.SubclassOptionalData;
682 if (Value *RetVal = CRI.getReturnValue())
683 setReturnValue(RetVal);
684 if (BasicBlock *UnwindDest = CRI.getUnwindDest())
685 setUnwindDest(UnwindDest);
686 }
687
688 void CleanupReturnInst::init(Value *RetVal, BasicBlock *UnwindBB) {
689 SubclassOptionalData = 0;
690 if (UnwindBB)
691 setInstructionSubclassData(getSubclassDataFromInstruction() | 1);
692 if (RetVal)
693 setInstructionSubclassData(getSubclassDataFromInstruction() | 2);
694
695 if (UnwindBB)
696 setUnwindDest(UnwindBB);
697 if (RetVal)
698 setReturnValue(RetVal);
699 }
700
701 CleanupReturnInst::CleanupReturnInst(LLVMContext &C, Value *RetVal,
702 BasicBlock *UnwindBB, unsigned Values,
703 Instruction *InsertBefore)
704 : TerminatorInst(Type::getVoidTy(C), Instruction::CleanupRet,
705 OperandTraits::op_end(this) - Values,
706 Values, InsertBefore) {
707 init(RetVal, UnwindBB);
708 }
709
710 CleanupReturnInst::CleanupReturnInst(LLVMContext &C, Value *RetVal,
711 BasicBlock *UnwindBB, unsigned Values,
712 BasicBlock *InsertAtEnd)
713 : TerminatorInst(Type::getVoidTy(C), Instruction::CleanupRet,
714 OperandTraits::op_end(this) - Values,
715 Values, InsertAtEnd) {
716 init(RetVal, UnwindBB);
717 }
718
719 BasicBlock *CleanupReturnInst::getUnwindDest() const {
720 if (hasUnwindDest())
721 return cast(getOperand(getUnwindLabelOpIdx()));
722 return nullptr;
723 }
724 void CleanupReturnInst::setUnwindDest(BasicBlock *NewDest) {
725 assert(NewDest);
726 setOperand(getUnwindLabelOpIdx(), NewDest);
727 }
728
729 BasicBlock *CleanupReturnInst::getSuccessorV(unsigned Idx) const {
730 assert(Idx == 0);
731 return getUnwindDest();
732 }
733 unsigned CleanupReturnInst::getNumSuccessorsV() const {
734 return getNumSuccessors();
735 }
736 void CleanupReturnInst::setSuccessorV(unsigned Idx, BasicBlock *B) {
737 assert(Idx == 0);
738 setUnwindDest(B);
739 }
740
741 //===----------------------------------------------------------------------===//
742 // CatchEndBlockInst Implementation
743 //===----------------------------------------------------------------------===//
744
745 CatchEndBlockInst::CatchEndBlockInst(const CatchEndBlockInst &CRI)
746 : TerminatorInst(CRI.getType(), Instruction::CatchEndBlock,
747 OperandTraits::op_end(this) -
748 CRI.getNumOperands(),
749 CRI.getNumOperands()) {
750 SubclassOptionalData = CRI.SubclassOptionalData;
751 if (BasicBlock *UnwindDest = CRI.getUnwindDest())
752 setUnwindDest(UnwindDest);
753 }
754
755 void CatchEndBlockInst::init(BasicBlock *UnwindBB) {
756 SubclassOptionalData = 0;
757 if (UnwindBB) {
758 setInstructionSubclassData(getSubclassDataFromInstruction() | 1);
759 setUnwindDest(UnwindBB);
760 }
761 }
762
763 CatchEndBlockInst::CatchEndBlockInst(LLVMContext &C, BasicBlock *UnwindBB,
764 unsigned Values, Instruction *InsertBefore)
765 : TerminatorInst(Type::getVoidTy(C), Instruction::CatchEndBlock,
766 OperandTraits::op_end(this) - Values,
767 Values, InsertBefore) {
768 init(UnwindBB);
769 }
770
771 CatchEndBlockInst::CatchEndBlockInst(LLVMContext &C, BasicBlock *UnwindBB,
772 unsigned Values, BasicBlock *InsertAtEnd)
773 : TerminatorInst(Type::getVoidTy(C), Instruction::CatchEndBlock,
774 OperandTraits::op_end(this) - Values,
775 Values, InsertAtEnd) {
776 init(UnwindBB);
777 }
778
779 BasicBlock *CatchEndBlockInst::getSuccessorV(unsigned Idx) const {
780 assert(Idx == 0);
781 return getUnwindDest();
782 }
783 unsigned CatchEndBlockInst::getNumSuccessorsV() const {
784 return getNumSuccessors();
785 }
786 void CatchEndBlockInst::setSuccessorV(unsigned Idx, BasicBlock *B) {
787 assert(Idx == 0);
788 setUnwindDest(B);
789 }
790
791 //===----------------------------------------------------------------------===//
792 // CatchReturnInst Implementation
793 //===----------------------------------------------------------------------===//
794
795 CatchReturnInst::CatchReturnInst(const CatchReturnInst &CRI)
796 : TerminatorInst(Type::getVoidTy(CRI.getContext()), Instruction::CatchRet,
797 OperandTraits::op_end(this) -
798 CRI.getNumOperands(),
799 CRI.getNumOperands()) {
800 Op<0>() = CRI.Op<0>();
801 }
802
803 CatchReturnInst::CatchReturnInst(BasicBlock *BB, Instruction *InsertBefore)
804 : TerminatorInst(Type::getVoidTy(BB->getContext()), Instruction::CatchRet,
805 OperandTraits::op_begin(this), 1,
806 InsertBefore) {
807 Op<0>() = BB;
808 }
809
810 CatchReturnInst::CatchReturnInst(BasicBlock *BB, BasicBlock *InsertAtEnd)
811 : TerminatorInst(Type::getVoidTy(BB->getContext()), Instruction::CatchRet,
812 OperandTraits::op_begin(this), 1,
813 InsertAtEnd) {
814 Op<0>() = BB;
815 }
816
817 BasicBlock *CatchReturnInst::getSuccessorV(unsigned Idx) const {
818 assert(Idx == 0);
819 return getSuccessor();
820 }
821 unsigned CatchReturnInst::getNumSuccessorsV() const {
822 return getNumSuccessors();
823 }
824 void CatchReturnInst::setSuccessorV(unsigned Idx, BasicBlock *B) {
825 assert(Idx == 0);
826 setSuccessor(B);
827 }
828
829 //===----------------------------------------------------------------------===//
830 // CatchBlockInst Implementation
831 //===----------------------------------------------------------------------===//
832 void CatchBlockInst::init(BasicBlock *IfNormal, BasicBlock *IfException,
833 ArrayRef Args, const Twine &NameStr) {
834 assert(getNumOperands() == 2 + Args.size() && "NumOperands not set up?");
835 Op<-2>() = IfNormal;
836 Op<-1>() = IfException;
837 std::copy(Args.begin(), Args.end(), op_begin());
838 setName(NameStr);
839 }
840
841 CatchBlockInst::CatchBlockInst(const CatchBlockInst &CBI)
842 : TerminatorInst(CBI.getType(), Instruction::CatchBlock,
843 OperandTraits::op_end(this) -
844 CBI.getNumOperands(),
845 CBI.getNumOperands()) {
846 std::copy(CBI.op_begin(), CBI.op_end(), op_begin());
847 }
848
849 CatchBlockInst::CatchBlockInst(Type *RetTy, BasicBlock *IfNormal,
850 BasicBlock *IfException, ArrayRef Args,
851 unsigned Values, const Twine &NameStr,
852 Instruction *InsertBefore)
853 : TerminatorInst(RetTy, Instruction::CatchBlock,
854 OperandTraits::op_end(this) - Values,
855 Values, InsertBefore) {
856 init(IfNormal, IfException, Args, NameStr);
857 }
858
859 CatchBlockInst::CatchBlockInst(Type *RetTy, BasicBlock *IfNormal,
860 BasicBlock *IfException, ArrayRef Args,
861 unsigned Values, const Twine &NameStr,
862 BasicBlock *InsertAtEnd)
863 : TerminatorInst(RetTy, Instruction::CatchBlock,
864 OperandTraits::op_end(this) - Values,
865 Values, InsertAtEnd) {
866 init(IfNormal, IfException, Args, NameStr);
867 }
868
869 BasicBlock *CatchBlockInst::getSuccessorV(unsigned Idx) const {
870 return getSuccessor(Idx);
871 }
872 unsigned CatchBlockInst::getNumSuccessorsV() const {
873 return getNumSuccessors();
874 }
875 void CatchBlockInst::setSuccessorV(unsigned Idx, BasicBlock *B) {
876 return setSuccessor(Idx, B);
877 }
878
879 //===----------------------------------------------------------------------===//
880 // TerminateBlockInst Implementation
881 //===----------------------------------------------------------------------===//
882 void TerminateBlockInst::init(BasicBlock *BB, ArrayRef Args,
883 const Twine &NameStr) {
884 SubclassOptionalData = 0;
885 if (BB)
886 setInstructionSubclassData(getSubclassDataFromInstruction() | 1);
887 if (BB)
888 Op<-1>() = BB;
889 std::copy(Args.begin(), Args.end(), op_begin());
890 setName(NameStr);
891 }
892
893 TerminateBlockInst::TerminateBlockInst(const TerminateBlockInst &TBI)
894 : TerminatorInst(TBI.getType(), Instruction::TerminateBlock,
895 OperandTraits::op_end(this) -
896 TBI.getNumOperands(),
897 TBI.getNumOperands()) {
898 SubclassOptionalData = TBI.SubclassOptionalData;
899 std::copy(TBI.op_begin(), TBI.op_end(), op_begin());
900 }
901
902 TerminateBlockInst::TerminateBlockInst(LLVMContext &C, BasicBlock *BB,
903 ArrayRef Args, unsigned Values,
904 const Twine &NameStr,
905 Instruction *InsertBefore)
906 : TerminatorInst(Type::getVoidTy(C), Instruction::TerminateBlock,
907 OperandTraits::op_end(this) - Values,
908 Values, InsertBefore) {
909 init(BB, Args, NameStr);
910 }
911
912 TerminateBlockInst::TerminateBlockInst(LLVMContext &C, BasicBlock *BB,
913 ArrayRef Args, unsigned Values,
914 const Twine &NameStr,
915 BasicBlock *InsertAtEnd)
916 : TerminatorInst(Type::getVoidTy(C), Instruction::TerminateBlock,
917 OperandTraits::op_end(this) - Values,
918 Values, InsertAtEnd) {
919 init(BB, Args, NameStr);
920 }
921
922 BasicBlock *TerminateBlockInst::getSuccessorV(unsigned Idx) const {
923 assert(Idx == 0);
924 return getUnwindDest();
925 }
926 unsigned TerminateBlockInst::getNumSuccessorsV() const {
927 return getNumSuccessors();
928 }
929 void TerminateBlockInst::setSuccessorV(unsigned Idx, BasicBlock *B) {
930 assert(Idx == 0);
931 return setUnwindDest(B);
932 }
933
934 //===----------------------------------------------------------------------===//
935 // CleanupBlockInst Implementation
936 //===----------------------------------------------------------------------===//
937 void CleanupBlockInst::init(ArrayRef Args, const Twine &NameStr) {
938 assert(getNumOperands() == Args.size() && "NumOperands not set up?");
939 std::copy(Args.begin(), Args.end(), op_begin());
940 setName(NameStr);
941 }
942
943 CleanupBlockInst::CleanupBlockInst(const CleanupBlockInst &CBI)
944 : Instruction(CBI.getType(), Instruction::CleanupBlock,
945 OperandTraits::op_end(this) -
946 CBI.getNumOperands(),
947 CBI.getNumOperands()) {
948 std::copy(CBI.op_begin(), CBI.op_end(), op_begin());
949 }
950
951 CleanupBlockInst::CleanupBlockInst(Type *RetTy, ArrayRef Args,
952 const Twine &NameStr,
953 Instruction *InsertBefore)
954 : Instruction(RetTy, Instruction::CleanupBlock,
955 OperandTraits::op_end(this) - Args.size(),
956 Args.size(), InsertBefore) {
957 init(Args, NameStr);
958 }
959
960 CleanupBlockInst::CleanupBlockInst(Type *RetTy, ArrayRef Args,
961 const Twine &NameStr,
962 BasicBlock *InsertAtEnd)
963 : Instruction(RetTy, Instruction::CleanupBlock,
964 OperandTraits::op_end(this) - Args.size(),
965 Args.size(), InsertAtEnd) {
966 init(Args, NameStr);
670967 }
671968
672969 //===----------------------------------------------------------------------===//
36173914
36183915 ResumeInst *ResumeInst::cloneImpl() const { return new (1) ResumeInst(*this); }
36193916
3917 CleanupReturnInst *CleanupReturnInst::cloneImpl() const {
3918 return new (getNumOperands()) CleanupReturnInst(*this);
3919 }
3920
3921 CatchEndBlockInst *CatchEndBlockInst::cloneImpl() const {
3922 return new (getNumOperands()) CatchEndBlockInst(*this);
3923 }
3924
3925 CatchReturnInst *CatchReturnInst::cloneImpl() const {
3926 return new (1) CatchReturnInst(*this);
3927 }
3928
3929 CatchBlockInst *CatchBlockInst::cloneImpl() const {
3930 return new (getNumOperands()) CatchBlockInst(*this);
3931 }
3932
3933 TerminateBlockInst *TerminateBlockInst::cloneImpl() const {
3934 return new (getNumOperands()) TerminateBlockInst(*this);
3935 }
3936
3937 CleanupBlockInst *CleanupBlockInst::cloneImpl() const {
3938 return new (getNumOperands()) CleanupBlockInst(*this);
3939 }
3940
36203941 UnreachableInst *UnreachableInst::cloneImpl() const {
36213942 LLVMContext &Context = getContext();
36223943 return new UnreachableInst(Context);
379379 void visitExtractValueInst(ExtractValueInst &EVI);
380380 void visitInsertValueInst(InsertValueInst &IVI);
381381 void visitLandingPadInst(LandingPadInst &LPI);
382 void visitCatchBlockInst(CatchBlockInst &CBI);
383 void visitCatchEndBlockInst(CatchEndBlockInst &CEBI);
384 void visitCleanupBlockInst(CleanupBlockInst &CBI);
385 void visitTerminateBlockInst(TerminateBlockInst &TBI);
382386
383387 void VerifyCallSite(CallSite CS);
384388 void verifyMustTailCall(CallInst &CI);
24032407 void Verifier::visitInvokeInst(InvokeInst &II) {
24042408 VerifyCallSite(&II);
24052409
2406 // Verify that there is a landingpad instruction as the first non-PHI
2410 // Verify that there is an exception block instruction is the first non-PHI
24072411 // instruction of the 'unwind' destination.
2408 Assert(II.getUnwindDest()->isLandingPad(),
2409 "The unwind destination does not have a landingpad instruction!", &II);
2412 Assert(
2413 II.getUnwindDest()->isEHBlock(),
2414 "The unwind destination does not have an exception handling instruction!",
2415 &II);
24102416
24112417 visitTerminatorInst(II);
24122418 }
28172823 visitInstruction(LPI);
28182824 }
28192825
2826 void Verifier::visitCatchBlockInst(CatchBlockInst &CBI) {
2827 BasicBlock *BB = CBI.getParent();
2828
2829 Function *F = BB->getParent();
2830 Assert(F->hasPersonalityFn(),
2831 "CatchBlockInst needs to be in a function with a personality.", &CBI);
2832
2833 // The catchblock instruction must be the first non-PHI instruction in the
2834 // block.
2835 Assert(BB->getFirstNonPHI() == &CBI,
2836 "CatchBlockInst not the first non-PHI instruction in the block.",
2837 &CBI);
2838
2839 visitTerminatorInst(CBI);
2840 }
2841
2842 void Verifier::visitCatchEndBlockInst(CatchEndBlockInst &CEBI) {
2843 BasicBlock *BB = CEBI.getParent();
2844
2845 Function *F = BB->getParent();
2846 Assert(F->hasPersonalityFn(),
2847 "CatchEndBlockInst needs to be in a function with a personality.",
2848 &CEBI);
2849
2850 // The catchendblock instruction must be the first non-PHI instruction in the
2851 // block.
2852 Assert(BB->getFirstNonPHI() == &CEBI,
2853 "CatchEndBlockInst not the first non-PHI instruction in the block.",
2854 &CEBI);
2855
2856 visitTerminatorInst(CEBI);
2857 }
2858
2859 void Verifier::visitCleanupBlockInst(CleanupBlockInst &CBI) {
2860 BasicBlock *BB = CBI.getParent();
2861
2862 Function *F = BB->getParent();
2863 Assert(F->hasPersonalityFn(),
2864 "CleanupBlockInst needs to be in a function with a personality.", &CBI);
2865
2866 // The cleanupblock instruction must be the first non-PHI instruction in the
2867 // block.
2868 Assert(BB->getFirstNonPHI() == &CBI,
2869 "CleanupBlockInst not the first non-PHI instruction in the block.",
2870 &CBI);
2871
2872 visitInstruction(CBI);
2873 }
2874
2875 void Verifier::visitTerminateBlockInst(TerminateBlockInst &TBI) {
2876 BasicBlock *BB = TBI.getParent();
2877
2878 Function *F = BB->getParent();
2879 Assert(F->hasPersonalityFn(),
2880 "TerminateBlockInst needs to be in a function with a personality.",
2881 &TBI);
2882
2883 // The terminateblock instruction must be the first non-PHI instruction in the
2884 // block.
2885 Assert(BB->getFirstNonPHI() == &TBI,
2886 "TerminateBlockInst not the first non-PHI instruction in the block.",
2887 &TBI);
2888
2889 visitTerminatorInst(TBI);
2890 }
2891
28202892 void Verifier::verifyDominatesUse(Instruction &I, unsigned i) {
28212893 Instruction *Op = cast(I.getOperand(i));
28222894 // If the we have an invalid invoke, don't try to compute the dominance.
26522652 setOrigin(&I, getCleanOrigin());
26532653 }
26542654
2655 void visitCleanupBlockInst(CleanupBlockInst &I) {
2656 setShadow(&I, getCleanShadow(&I));
2657 setOrigin(&I, getCleanOrigin());
2658 }
2659
2660 void visitCatchBlock(CatchBlockInst &I) {
2661 setShadow(&I, getCleanShadow(&I));
2662 setOrigin(&I, getCleanOrigin());
2663 }
2664
2665 void visitTerminateBlock(TerminateBlockInst &I) {
2666 setShadow(&I, getCleanShadow(&I));
2667 setOrigin(&I, getCleanOrigin());
2668 }
2669
2670 void visitCatchEndBlockInst(CatchEndBlockInst &I) {
2671 setShadow(&I, getCleanShadow(&I));
2672 setOrigin(&I, getCleanOrigin());
2673 }
2674
26552675 void visitGetElementPtrInst(GetElementPtrInst &I) {
26562676 handleShadowOr(I);
26572677 }
26922712
26932713 void visitResumeInst(ResumeInst &I) {
26942714 DEBUG(dbgs() << "Resume: " << I << "\n");
2715 // Nothing to do here.
2716 }
2717
2718 void visitCleanupReturnInst(CleanupReturnInst &CRI) {
2719 DEBUG(dbgs() << "CleanupReturn: " << CRI << "\n");
2720 // Nothing to do here.
2721 }
2722
2723 void visitCatchReturnInst(CatchReturnInst &CRI) {
2724 DEBUG(dbgs() << "CatchReturn: " << CRI << "\n");
26952725 // Nothing to do here.
26962726 }
26972727
5757
5858 // Collect the set of "root" instructions that are known live.
5959 for (Instruction &I : inst_range(F)) {
60 if (isa(I) || isa(I) ||
61 isa(I) || I.mayHaveSideEffects()) {
60 if (isa(I) || isa(I) || I.isEHBlock() ||
61 I.mayHaveSideEffects()) {
6262 Alive.insert(&I);
6363 Worklist.push_back(&I);
6464 }
7676 false, false)
7777
7878 static bool isAlwaysLive(Instruction *I) {
79 return isa(I) || isa(I) ||
80 isa(I) || I->mayHaveSideEffects();
79 return isa(I) || isa(I) || I->isEHBlock() ||
80 I->mayHaveSideEffects();
8181 }
8282
8383 void BDCE::determineLiveOperandBits(const Instruction *UserI,
668668 // because now the condition in this block can be threaded through
669669 // predecessors of our predecessor block.
670670 if (BasicBlock *SinglePred = BB->getSinglePredecessor()) {
671 if (SinglePred->getTerminator()->getNumSuccessors() == 1 &&
671 const TerminatorInst *TI = SinglePred->getTerminator();
672 if (!TI->isExceptional() && TI->getNumSuccessors() == 1 &&
672673 SinglePred != BB && !hasAddressTakenAndUsed(BB)) {
673674 // If SinglePred was a loop header, BB becomes one.
674675 if (LoopHeaders.erase(SinglePred))
538538 return;
539539 }
540540
541 if (isa(TI)) {
542 // Invoke instructions successors are always executable.
543 Succs[0] = Succs[1] = true;
541 // Unwinding instructions successors are always executable.
542 if (TI.isExceptional()) {
543 Succs.assign(TI.getNumSuccessors(), true);
544544 return;
545545 }
546546
604604 return BI->getSuccessor(CI->isZero()) == To;
605605 }
606606
607 // Invoke instructions successors are always executable.
608 if (isa(TI))
607 // Unwinding instructions successors are always executable.
608 if (TI->isExceptional())
609609 return true;
610610
611611 if (SwitchInst *SI = dyn_cast(TI)) {
118118
119119 // Don't break self-loops.
120120 if (PredBB == BB) return false;
121 // Don't break invokes.
122 if (isa(PredBB->getTerminator())) return false;
121 // Don't break unwinding instructions.
122 if (PredBB->getTerminator()->isExceptional())
123 return false;
123124
124125 succ_iterator SI(succ_begin(PredBB)), SE(succ_end(PredBB));
125126 BasicBlock *OnlySucc = BB;
282282 const TargetLibraryInfo *TLI) {
283283 if (!I->use_empty() || isa(I)) return false;
284284
285 // We don't want the landingpad instruction removed by anything this general.
286 if (isa(I))
285 // We don't want the landingpad-like instructions removed by anything this
286 // general.
287 if (I->isEHBlock())
287288 return false;
288289
289290 // We don't want debug info removed by anything this general, unless
2424 declare void @_Z3quxv() optsize
2525
2626 declare i32 @__gxx_personality_v0(...)
27
28 define void @cleanupret0() personality i32 (...)* @__gxx_personality_v0 {
29 entry:
30 cleanupret i8 0 unwind label %bb
31 bb:
32 ret void
33 }
34
35 define void @cleanupret1() personality i32 (...)* @__gxx_personality_v0 {
36 entry:
37 cleanupret void unwind label %bb
38 bb:
39 ret void
40 }
41
42 define void @cleanupret2() personality i32 (...)* @__gxx_personality_v0 {
43 entry:
44 cleanupret i8 0 unwind to caller
45 }
46
47 define void @cleanupret3() personality i32 (...)* @__gxx_personality_v0 {
48 cleanupret void unwind to caller
49 }
50
51 define void @catchret() personality i32 (...)* @__gxx_personality_v0 {
52 entry:
53 br label %bb
54 bb:
55 catchret label %bb
56 }
57
58 define i8 @catchblock() personality i32 (...)* @__gxx_personality_v0 {
59 entry:
60 %cbv = catchblock i8 [i7 4] to label %bb unwind label %bb2
61 bb:
62 ret i8 %cbv
63 bb2:
64 ret i8 42
65 }
66
67 define void @terminateblock0() personality i32 (...)* @__gxx_personality_v0 {
68 entry:
69 terminateblock [i7 4] unwind label %bb
70 bb:
71 ret void
72 }
73
74 define void @terminateblock1() personality i32 (...)* @__gxx_personality_v0 {
75 entry:
76 terminateblock [i7 4] unwind to caller
77 }
78
79 define void @cleanupblock() personality i32 (...)* @__gxx_personality_v0 {
80 entry:
81 cleanupblock void [i7 4]
82 ret void
83 }
84
85 define void @catchendblock0() personality i32 (...)* @__gxx_personality_v0 {
86 entry:
87 catchendblock unwind label %bb
88 bb:
89 ret void
90 }
91
92 define void @catchendblock1() personality i32 (...)* @__gxx_personality_v0 {
93 entry:
94 catchendblock unwind to caller
95 }
11
22 ; PR1042
33 define i32 @foo() {
4 ; CHECK: The unwind destination does not have a landingpad instruction
4 ; CHECK: The unwind destination does not have an exception handling instruction
55 %A = invoke i32 @foo( )
66 to label %L unwind label %L ; [#uses=1]
77 L: ; preds = %0, %0
1717 L2: ; preds = %0
1818 br label %L
1919 L: ; preds = %L2, %L1, %L1
20 ; CHECK: The unwind destination does not have a landingpad instruction
20 ; CHECK: The unwind destination does not have an exception handling instruction
2121 ret i32 %A
2222 }
2323
240240 STRINGIFY_CODE(FUNC_CODE, INST_SWITCH)
241241 STRINGIFY_CODE(FUNC_CODE, INST_INVOKE)
242242 STRINGIFY_CODE(FUNC_CODE, INST_UNREACHABLE)
243 STRINGIFY_CODE(FUNC_CODE, INST_CLEANUPRET)
244 STRINGIFY_CODE(FUNC_CODE, INST_CATCHRET)
245 STRINGIFY_CODE(FUNC_CODE, INST_CATCHBLOCK)
246 STRINGIFY_CODE(FUNC_CODE, INST_CATCHENDBLOCK)
247 STRINGIFY_CODE(FUNC_CODE, INST_TERMINATEBLOCK)
243248 STRINGIFY_CODE(FUNC_CODE, INST_PHI)
244249 STRINGIFY_CODE(FUNC_CODE, INST_ALLOCA)
245250 STRINGIFY_CODE(FUNC_CODE, INST_LOAD)