llvm.org GIT mirror llvm / eddf9e2
Revert the new EH instructions This reverts commits r241888-r241891, I didn't mean to commit them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241893 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 5 years ago
35 changed file(s) with 93 addition(s) and 2129 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 `', ':ref:`catchblock `',
4730 ':ref:`catchendblock `',
4731 ':ref:`catchret `',
4732 ':ref:`cleanupret `',
4733 ':ref:`terminateblock `',
4734 and ':ref:`unreachable `'.
4729 ':ref:`resume `', and ':ref:`unreachable `'.
47354730
47364731 .. _i_ret:
47374732
50845079 .. code-block:: llvm
50855080
50865081 resume { i8*, i32 } %exn
5087
5088 .. _i_catchblock:
5089
5090 '``catchblock``' Instruction
5091 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5092
5093 Syntax:
5094 """""""
5095
5096 ::
5097
5098 = catchblock [*]
5099 to label unwind label
5100
5101 Overview:
5102 """""""""
5103
5104 The '``catchblock``' instruction is used by `LLVM's exception handling
5105 system `_ to specify that a basic block
5106 is a catch block --- one where a personality routine attempts to transfer
5107 control to catch an exception.
5108 The ``args`` correspond to whatever information the personality
5109 routine requires to know if this is an appropriate place to catch the
5110 exception. Control is tranfered to the ``exception`` label if the
5111 ``catchblock`` is not an appropriate handler for the in-flight exception.
5112 The ``normal`` label should contain the code found in the ``catch``
5113 portion of a ``try``/``catch`` sequence. It defines values supplied by
5114 the :ref:`personality function ` upon re-entry to the
5115 function. The ``resultval`` has the type ``resultty``.
5116
5117 Arguments:
5118 """"""""""
5119
5120 The instruction takes a list of arbitrary values which are interpreted
5121 by the :ref:`personality function `.
5122
5123 The ``catchblock`` must be provided a ``normal`` label to transfer control
5124 to if the ``catchblock`` matches the exception and an ``exception``
5125 label to transfer control to if it doesn't.
5126
5127 Semantics:
5128 """"""""""
5129
5130 The '``catchblock``' instruction defines the values which are set by the
5131 :ref:`personality function ` upon re-entry to the function, and
5132 therefore the "result type" of the ``catchblock`` instruction. As with
5133 calling conventions, how the personality function results are
5134 represented in LLVM IR is target specific.
5135
5136 When the call stack is being unwound due to an exception being thrown,
5137 the exception is compared against the ``args``. If it doesn't match,
5138 then control is transfered to the ``exception`` basic block.
5139
5140 The ``catchblock`` instruction has several restrictions:
5141
5142 - A catch block is a basic block which is the unwind destination of
5143 an exceptional instruction.
5144 - A catch block must have a '``catchblock``' instruction as its
5145 first non-PHI instruction.
5146 - A catch block's ``exception`` edge must refer to a catch block or a
5147 catch-end block.
5148 - There can be only one '``catchblock``' instruction within the
5149 catch block.
5150 - A basic block that is not a catch block may not include a
5151 '``catchblock``' instruction.
5152
5153 Example:
5154 """"""""
5155
5156 .. code-block:: llvm
5157
5158 ;; A catch block which can catch an integer.
5159 %res = catchblock { i8*, i32 } [i8** @_ZTIi]
5160 to label %int.handler unwind label %terminate
5161
5162 .. _i_catchendblock:
5163
5164 '``catchendblock``' Instruction
5165 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5166
5167 Syntax:
5168 """""""
5169
5170 ::
5171
5172 catchendblock unwind label
5173 catchendblock unwind to caller
5174
5175 Overview:
5176 """""""""
5177
5178 The '``catchendblock``' instruction is used by `LLVM's exception handling
5179 system `_ to communicate to the
5180 :ref:`personality function ` which invokes are associated
5181 with a chain of :ref:`catchblock ` instructions.
5182
5183 The ``nextaction`` label indicates where control should transfer to if
5184 none of the ``catchblock`` instructions are suitable for catching the
5185 in-flight exception.
5186
5187 If a ``nextaction`` label is not present, the instruction unwinds out of
5188 its parent function. The
5189 :ref:`personality function ` will continue processing
5190 exception handling actions in the caller.
5191
5192 Arguments:
5193 """"""""""
5194
5195 The instruction optionally takes a label, ``nextaction``, indicating
5196 where control should transfer to if none of the preceding
5197 ``catchblock`` instructions are suitable for the in-flight exception.
5198
5199 Semantics:
5200 """"""""""
5201
5202 When the call stack is being unwound due to an exception being thrown
5203 and none of the constituent ``catchblock`` instructions match, then
5204 control is transfered to ``nextaction`` if it is present. If it is not
5205 present, control is transfered to the caller.
5206
5207 The ``catchendblock`` instruction has several restrictions:
5208
5209 - A catch-end block is a basic block which is the unwind destination of
5210 an exceptional instruction.
5211 - A catch-end block must have a '``catchendblock``' instruction as its
5212 first non-PHI instruction.
5213 - There can be only one '``catchendblock``' instruction within the
5214 catch block.
5215 - A basic block that is not a catch-end block may not include a
5216 '``catchendblock``' instruction.
5217 - Exactly one catch block may unwind to a ``catchendblock``.
5218
5219 Example:
5220 """"""""
5221
5222 .. code-block:: llvm
5223
5224 catchendblock unwind label %terminate
5225 catchendblock unwind to caller
5226
5227 .. _i_catchret:
5228
5229 '``catchret``' Instruction
5230 ^^^^^^^^^^^^^^^^^^^^^^^^^^
5231
5232 Syntax:
5233 """""""
5234
5235 ::
5236
5237 catchret label
5238
5239 Overview:
5240 """""""""
5241
5242 The '``catchret``' instruction is a terminator instruction that has a
5243 single successor.
5244
5245
5246 Arguments:
5247 """"""""""
5248
5249 The '``catchret``' instruction requires one argument which specifies
5250 where control will transfer to next.
5251
5252 Semantics:
5253 """"""""""
5254
5255 The '``catchret``' instruction ends the existing (in-flight) exception
5256 whose unwinding was interrupted with a
5257 :ref:`catchblock ` instruction.
5258 The :ref:`personality function ` gets a chance to execute
5259 arbitrary code to, for example, run a C++ destructor.
5260 Control then transfers to ``normal``.
5261
5262 Example:
5263 """"""""
5264
5265 .. code-block:: llvm
5266
5267 catchret label %continue
5268
5269 .. _i_cleanupret:
5270
5271 '``cleanupret``' Instruction
5272 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5273
5274 Syntax:
5275 """""""
5276
5277 ::
5278
5279 cleanupret unwind label
5280 cleanupret unwind to caller
5281
5282 Overview:
5283 """""""""
5284
5285 The '``cleanupret``' instruction is a terminator instruction that has
5286 an optional successor.
5287
5288
5289 Arguments:
5290 """"""""""
5291
5292 The '``cleanupret``' instruction requires one argument, which must have the
5293 same type as the result of any '``cleanupblock``' instruction in the same
5294 function. It also has an optional successor, ``continue``.
5295
5296 Semantics:
5297 """"""""""
5298
5299 The '``cleanupret``' instruction indicates to the
5300 :ref:`personality function ` that one
5301 :ref:`cleanupblock ` it transferred control to has ended.
5302 It transfers control to ``continue`` or unwinds out of the function.
5303
5304 Example:
5305 """"""""
5306
5307 .. code-block:: llvm
5308
5309 cleanupret void unwind to caller
5310 cleanupret { i8*, i32 } %exn unwind label %continue
5311
5312 .. _i_terminateblock:
5313
5314 '``terminateblock``' Instruction
5315 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5316
5317 Syntax:
5318 """""""
5319
5320 ::
5321
5322 terminateblock [*] unwind label
5323 terminateblock [*] unwind to caller
5324
5325 Overview:
5326 """""""""
5327
5328 The '``terminateblock``' instruction is used by `LLVM's exception handling
5329 system `_ to specify that a basic block
5330 is a terminate block --- one where a personality routine may decide to
5331 terminate the program.
5332 The ``args`` correspond to whatever information the personality
5333 routine requires to know if this is an appropriate place to terminate the
5334 program. Control is transferred to the ``exception`` label if the
5335 personality routine decides not to terminate the program for the
5336 in-flight exception.
5337
5338 Arguments:
5339 """"""""""
5340
5341 The instruction takes a list of arbitrary values which are interpreted
5342 by the :ref:`personality function `.
5343
5344 The ``terminateblock`` may be given an ``exception`` label to
5345 transfer control to if the in-flight exception matches the ``args``.
5346
5347 Semantics:
5348 """"""""""
5349
5350 When the call stack is being unwound due to an exception being thrown,
5351 the exception is compared against the ``args``. If it matches,
5352 then control is transfered to the ``exception`` basic block. Otherwise,
5353 the program is terminated via personality-specific means. Typically,
5354 the first argument to ``terminateblock`` specifies what function the
5355 personality should defer to in order to terminate the program.
5356
5357 The ``terminateblock`` instruction has several restrictions:
5358
5359 - A terminate block is a basic block which is the unwind destination of
5360 an exceptional instruction.
5361 - A terminate block must have a '``terminateblock``' instruction as its
5362 first non-PHI instruction.
5363 - There can be only one '``terminateblock``' instruction within the
5364 terminate block.
5365 - A basic block that is not a terminate block may not include a
5366 '``terminateblock``' instruction.
5367
5368 Example:
5369 """"""""
5370
5371 .. code-block:: llvm
5372
5373 ;; A terminate block which only permits integers.
5374 terminateblock [i8** @_ZTIi] unwind label %continue
53755082
53765083 .. _i_unreachable:
53775084
83218028 catch i8** @_ZTIi
83228029 filter [1 x i8**] [@_ZTId]
83238030
8324 .. _i_cleanupblock:
8325
8326 '``cleanupblock``' Instruction
8327 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8328
8329 Syntax:
8330 """""""
8331
8332 ::
8333
8334 = cleanupblock [*]
8335
8336 Overview:
8337 """""""""
8338
8339 The '``cleanupblock``' instruction is used by `LLVM's exception handling
8340 system `_ to specify that a basic block
8341 is a cleanup block --- one where a personality routine attempts to
8342 transfer control to run cleanup actions.
8343 The ``args`` correspond to whatever additional
8344 information the :ref:`personality function ` requires to
8345 execute the cleanup.
8346 The ``resultval`` has the type ``resultty``.
8347
8348 Arguments:
8349 """"""""""
8350
8351 The instruction takes a list of arbitrary values which are interpreted
8352 by the :ref:`personality function `.
8353
8354 Semantics:
8355 """"""""""
8356
8357 The '``cleanupblock``' instruction defines the values which are set by the
8358 :ref:`personality function ` upon re-entry to the function, and
8359 therefore the "result type" of the ``cleanupblock`` instruction. As with
8360 calling conventions, how the personality function results are
8361 represented in LLVM IR is target specific.
8362
8363 When the call stack is being unwound due to an exception being thrown,
8364 the :ref:`personality function ` transfers control to the
8365 ``cleanupblock`` with the aid of the personality-specific arguments.
8366
8367 The ``cleanupblock`` instruction has several restrictions:
8368
8369 - A cleanup block is a basic block which is the unwind destination of
8370 an exceptional instruction.
8371 - A cleanup block must have a '``cleanupblock``' instruction as its
8372 first non-PHI instruction.
8373 - There can be only one '``cleanupblock``' instruction within the
8374 cleanup block.
8375 - A basic block that is not a cleanup block may not include a
8376 '``cleanupblock``' instruction.
8377
8378 Example:
8379 """"""""
8380
8381 .. code-block:: llvm
8382
8383 %res = cleanupblock { i8*, i32 } [label %nextaction]
8384
83858031 .. _intrinsics:
83868032
83878033 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#]
362356 };
363357
364358 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
314311 /// \brief Return true if this basic block is a landing pad.
315312 ///
316313 /// 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
706674 UnreachableInst *CreateUnreachable() {
707675 return Insert(new UnreachableInst(Context));
708676 }
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);}
176171 RetTy visitICmpInst(ICmpInst &I) { DELEGATE(CmpInst);}
177172 RetTy visitFCmpInst(FCmpInst &I) { DELEGATE(CmpInst);}
178173 RetTy visitAllocaInst(AllocaInst &I) { DELEGATE(UnaryInstruction);}
204199 RetTy visitExtractValueInst(ExtractValueInst &I){ DELEGATE(UnaryInstruction);}
205200 RetTy visitInsertValueInst(InsertValueInst &I) { DELEGATE(Instruction); }
206201 RetTy visitLandingPadInst(LandingPadInst &I) { DELEGATE(Instruction); }
207 RetTy visitCleanupBlockInst(CleanupBlockInst &I) { DELEGATE(Instruction); }
208202
209203 // Handle the special instrinsic instruction classes.
210204 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 }
9276 }
9377 };
9478
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 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)
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)
109104
110105 // Standard binary operators...
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)
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)
124119
125120 // Logical operators (integer operands)
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)
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)
133128
134129 // Memory operators...
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)
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)
144139
145140 // Cast operators ...
146141 // NOTE: The order matters here because CastInst::isEliminableCastPair
147142 // NOTE: (see Instructions.cpp) encodes a table based on this ordering.
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)
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)
163158
164159 // Other operators...
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)
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)
182176
183177 #undef FIRST_TERM_INST
184178 #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
404390 /// clone() - Create a copy of 'this' instruction that is identical in all
405391 /// ways except the following:
406392 /// * 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 catchblock!");
3808 return i == 0 ? getNormalDest() : getUnwindDest();
3809 }
3810
3811 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3812 assert(idx < 2 && "Successor # out of range for catchblock!");
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 //===----------------------------------------------------------------------===//
40743554 // UnreachableInst Class
40753555 //===----------------------------------------------------------------------===//
40763556
247247
248248 /* Exception Handling Operators */
249249 LLVMResume = 58,
250 LLVMLandingPad = 59,
251 LLVMCleanupRet = 61,
252 LLVMCatchRet = 62,
253 LLVMCatchBlock = 63,
254 LLVMTerminateBlock = 64,
255 LLVMCleanupBlock = 65,
256 LLVMCatchEndBlock = 66
250 LLVMLandingPad = 59
257251
258252 } LLVMOpcode;
259253
12081202 macro(InsertElementInst) \
12091203 macro(InsertValueInst) \
12101204 macro(LandingPadInst) \
1211 macro(CleanupBlockInst) \
12121205 macro(PHINode) \
12131206 macro(SelectInst) \
12141207 macro(ShuffleVectorInst) \
12211214 macro(SwitchInst) \
12221215 macro(UnreachableInst) \
12231216 macro(ResumeInst) \
1224 macro(CleanupReturnInst) \
1225 macro(CatchReturnInst) \
1226 macro(CatchBlockInst) \
1227 macro(TerminateBlockInst) \
1228 macro(CatchEndBlockInst) \
12291217 macro(UnaryInstruction) \
12301218 macro(AllocaInst) \
12311219 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);
160158 bool visitUnreachableInst(UnreachableInst &I);
161159
162160 public:
904902 return false;
905903 }
906904
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
919905 bool CallAnalyzer::visitUnreachableInst(UnreachableInst &I) {
920906 // FIXME: It might be reasonably to discount the cost of instructions leading
921907 // 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);
527526 KEYWORD(tail);
528527 KEYWORD(musttail);
529528 KEYWORD(target);
748747 INSTKEYWORD(extractvalue, ExtractValue);
749748 INSTKEYWORD(insertvalue, InsertValue);
750749 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);
757750 #undef INSTKEYWORD
758751
759752 #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);
44974491 // Binary Operators.
44984492 case lltok::kw_add:
44994493 case lltok::kw_sub:
48874881 return false;
48884882 }
48894883
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 terminateblock"))
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 catchendblock"))
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
50454884 //===----------------------------------------------------------------------===//
50464885 // Binary Operators.
50474886 //===----------------------------------------------------------------------===//
380380 bool IsMustTailCall = false,
381381 bool InVarArgsFunc = false);
382382
383 bool ParseExceptionArgs(SmallVectorImpl &Args,
384 PerFunctionState &PFS);
385
386383 // Constant Parsing.
387384 bool ParseValID(ValID &ID, PerFunctionState *PFS = nullptr);
388385 bool ParseGlobalValue(Type *Ty, Constant *&V);
443440 bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
444441 bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
445442 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);
452443
453444 bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc,
454445 unsigned OperandType);
5050 kw_zeroinitializer,
5151 kw_undef, kw_null,
5252 kw_to,
53 kw_caller,
5453 kw_tail,
5554 kw_musttail,
5655 kw_target,
176175 kw_landingpad, kw_personality, kw_cleanup, kw_catch, kw_filter,
177176
178177 kw_ret, kw_br, kw_switch, kw_indirectbr, kw_invoke, kw_resume,
179 kw_unreachable, kw_cleanupret, kw_catchret, kw_catchblock,
180 kw_terminateblock, kw_cleanupblock, kw_catchendblock,
178 kw_unreachable,
181179
182180 kw_alloca, kw_load, kw_store, kw_fence, kw_cmpxchg, kw_atomicrmw,
183181 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 }
39233795 case bitc::FUNC_CODE_INST_SWITCH: { // SWITCH: [opty, op0, op1, ...]
39243796 // Check magic
39253797 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 }
19051847 case Instruction::Unreachable:
19061848 Code = bitc::FUNC_CODE_INST_UNREACHABLE;
19071849 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!");
11921168 }
11931169
11941170 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);
742736
743737 uint32_t getEdgeWeight(const MachineBasicBlock *Src,
744738 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;
15541548 case Add: return ISD::ADD;
15551549 case FAdd: return ISD::FADD;
15561550 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 << "]";
28892850 } else if (isa(I) && !Operand) {
28902851 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";
29102852 } else if (const CallInst *CI = dyn_cast(&I)) {
29112853 // Print the calling convention being used.
29122854 if (CI->getCallingConv() != CallingConv::C) {
196196 return end();
197197
198198 iterator InsertPt = FirstNonPHI;
199 if (InsertPt->isEHBlock()) ++InsertPt;
199 if (isa(InsertPt)) ++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";
203198
204199 // Standard binary operators...
205200 case Add: return "add";
260255 case ExtractValue: return "extractvalue";
261256 case InsertValue: return "insertvalue";
262257 case LandingPad: return "landingpad";
263 case CleanupBlock: return "cleanupblock";
264258
265259 default: return " ";
266260 }
412406 case Instruction::Fence: // FIXME: refine definition of mayReadFromMemory
413407 case Instruction::AtomicCmpXchg:
414408 case Instruction::AtomicRMW:
415 case Instruction::CatchRet:
416 case Instruction::TerminateBlock:
417409 return true;
418410 case Instruction::Call:
419411 return !cast(this)->doesNotAccessMemory();
434426 case Instruction::VAArg:
435427 case Instruction::AtomicCmpXchg:
436428 case Instruction::AtomicRMW:
437 case Instruction::CatchRet:
438 case Instruction::TerminateBlock:
439429 return true;
440430 case Instruction::Call:
441431 return !cast(this)->onlyReadsMemory();
464454 bool Instruction::mayThrow() const {
465455 if (const CallInst *CI = dyn_cast(this))
466456 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();
471 if (const auto *TBI = dyn_cast(this))
472 return TBI->unwindsToCaller();
473457 return isa(this);
474458 }
475459
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);
967670 }
968671
969672 //===----------------------------------------------------------------------===//
39143617
39153618 ResumeInst *ResumeInst::cloneImpl() const { return new (1) ResumeInst(*this); }
39163619
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
39413620 UnreachableInst *UnreachableInst::cloneImpl() const {
39423621 LLVMContext &Context = getContext();
39433622 return new UnreachableInst(Context);
183183 /// \brief Track unresolved string-based type references.
184184 SmallDenseMap UnresolvedTypeRefs;
185185
186 /// \brief The result value from the personality function.
187 Type *PersonalityFnResultTy;
188
189186 /// \brief Whether we've seen a call to @llvm.localescape in this function
190187 /// already.
191188 bool SawFrameEscape;
196193
197194 public:
198195 explicit Verifier(raw_ostream &OS)
199 : VerifierSupport(OS), Context(nullptr), PersonalityFnResultTy(nullptr),
200 SawFrameEscape(false) {}
196 : VerifierSupport(OS), Context(nullptr), SawFrameEscape(false) {}
201197
202198 bool verify(const Function &F) {
203199 M = F.getParent();
231227 // FIXME: We strip const here because the inst visitor strips const.
232228 visit(const_cast(F));
233229 InstsInThisBlock.clear();
234 PersonalityFnResultTy = nullptr;
235230 SawFrameEscape = false;
236231
237232 return !Broken;
384379 void visitExtractValueInst(ExtractValueInst &EVI);
385380 void visitInsertValueInst(InsertValueInst &IVI);
386381 void visitLandingPadInst(LandingPadInst &LPI);
387 void visitCatchBlockInst(CatchBlockInst &CBI);
388 void visitCatchEndBlockInst(CatchEndBlockInst &CEBI);
389 void visitCleanupBlockInst(CleanupBlockInst &CBI);
390 void visitCleanupReturnInst(CleanupReturnInst &CRI);
391 void visitTerminateBlockInst(TerminateBlockInst &TBI);
392382
393383 void VerifyCallSite(CallSite CS);
394384 void verifyMustTailCall(CallInst &CI);
24132403 void Verifier::visitInvokeInst(InvokeInst &II) {
24142404 VerifyCallSite(&II);
24152405
2416 // Verify that the first non-PHI instruction of the unwind destination is an
2417 // exception handling instruction.
2418 Assert(
2419 II.getUnwindDest()->isEHBlock(),
2420 "The unwind destination does not have an exception handling instruction!",
2421 &II);
2406 // Verify that there is a landingpad instruction as the first non-PHI
2407 // instruction of the 'unwind' destination.
2408 Assert(II.getUnwindDest()->isLandingPad(),
2409 "The unwind destination does not have a landingpad instruction!", &II);
24222410
24232411 visitTerminatorInst(II);
24242412 }
28042792 &LPI);
28052793 }
28062794
2807 if (!PersonalityFnResultTy)
2808 PersonalityFnResultTy = LPI.getType();
2809 else
2810 Assert(PersonalityFnResultTy == LPI.getType(),
2811 "The personality routine should have a consistent result type "
2812 "inside a function.",
2813 &LPI);
2814
28152795 Function *F = LPI.getParent()->getParent();
28162796 Assert(F->hasPersonalityFn(),
28172797 "LandingPadInst needs to be in a function with a personality.", &LPI);
28352815 }
28362816
28372817 visitInstruction(LPI);
2838 }
2839
2840 void Verifier::visitCatchBlockInst(CatchBlockInst &CBI) {
2841 BasicBlock *BB = CBI.getParent();
2842
2843 if (!PersonalityFnResultTy)
2844 PersonalityFnResultTy = CBI.getType();
2845 else
2846 Assert(PersonalityFnResultTy == CBI.getType(),
2847 "The personality routine should have a consistent result type "
2848 "inside a function.",
2849 &CBI);
2850
2851 Function *F = BB->getParent();
2852 Assert(F->hasPersonalityFn(),
2853 "CatchBlockInst needs to be in a function with a personality.", &CBI);
2854
2855 // The catchblock instruction must be the first non-PHI instruction in the
2856 // block.
2857 Assert(BB->getFirstNonPHI() == &CBI,
2858 "CatchBlockInst not the first non-PHI instruction in the block.",
2859 &CBI);
2860
2861 BasicBlock *UnwindDest = CBI.getUnwindDest();
2862 Instruction *I = UnwindDest->getFirstNonPHI();
2863 Assert(
2864 isa(I) || isa(I),
2865 "CatchBlockInst must unwind to a CatchBlockInst or a CatchEndBlockInst.",
2866 &CBI);
2867
2868 visitTerminatorInst(CBI);
2869 }
2870
2871 void Verifier::visitCatchEndBlockInst(CatchEndBlockInst &CEBI) {
2872 BasicBlock *BB = CEBI.getParent();
2873
2874 Function *F = BB->getParent();
2875 Assert(F->hasPersonalityFn(),
2876 "CatchEndBlockInst needs to be in a function with a personality.",
2877 &CEBI);
2878
2879 // The catchendblock instruction must be the first non-PHI instruction in the
2880 // block.
2881 Assert(BB->getFirstNonPHI() == &CEBI,
2882 "CatchEndBlockInst not the first non-PHI instruction in the block.",
2883 &CEBI);
2884
2885 unsigned CatchBlocksSeen = 0;
2886 for (BasicBlock *PredBB : predecessors(BB))
2887 if (isa(PredBB->getTerminator()))
2888 ++CatchBlocksSeen;
2889
2890 Assert(CatchBlocksSeen <= 1, "CatchEndBlockInst must have no more than one "
2891 "CatchBlockInst predecessor.",
2892 &CEBI);
2893
2894 if (BasicBlock *UnwindDest = CEBI.getUnwindDest()) {
2895 Instruction *I = UnwindDest->getFirstNonPHI();
2896 Assert(
2897 I->isEHBlock() && !isa(I),
2898 "CatchEndBlock must unwind to an EH block which is not a landingpad.",
2899 &CEBI);
2900 }
2901
2902 visitTerminatorInst(CEBI);
2903 }
2904
2905 void Verifier::visitCleanupBlockInst(CleanupBlockInst &CBI) {
2906 BasicBlock *BB = CBI.getParent();
2907
2908 if (!PersonalityFnResultTy)
2909 PersonalityFnResultTy = CBI.getType();
2910 else
2911 Assert(PersonalityFnResultTy == CBI.getType(),
2912 "The personality routine should have a consistent result type "
2913 "inside a function.",
2914 &CBI);
2915
2916 Function *F = BB->getParent();
2917 Assert(F->hasPersonalityFn(),
2918 "CleanupBlockInst needs to be in a function with a personality.", &CBI);
2919
2920 // The cleanupblock instruction must be the first non-PHI instruction in the
2921 // block.
2922 Assert(BB->getFirstNonPHI() == &CBI,
2923 "CleanupBlockInst not the first non-PHI instruction in the block.",
2924 &CBI);
2925
2926 visitInstruction(CBI);
2927 }
2928
2929 void Verifier::visitCleanupReturnInst(CleanupReturnInst &CRI) {
2930 if (BasicBlock *UnwindDest = CRI.getUnwindDest()) {
2931 Instruction *I = UnwindDest->getFirstNonPHI();
2932 Assert(I->isEHBlock() && !isa(I),
2933 "CleanupReturnInst must unwind to an EH block which is not a "
2934 "landingpad.",
2935 &CRI);
2936 }
2937
2938 visitTerminatorInst(CRI);
2939 }
2940
2941 void Verifier::visitTerminateBlockInst(TerminateBlockInst &TBI) {
2942 BasicBlock *BB = TBI.getParent();
2943
2944 Function *F = BB->getParent();
2945 Assert(F->hasPersonalityFn(),
2946 "TerminateBlockInst needs to be in a function with a personality.",
2947 &TBI);
2948
2949 // The terminateblock instruction must be the first non-PHI instruction in the
2950 // block.
2951 Assert(BB->getFirstNonPHI() == &TBI,
2952 "TerminateBlockInst not the first non-PHI instruction in the block.",
2953 &TBI);
2954
2955 if (BasicBlock *UnwindDest = TBI.getUnwindDest()) {
2956 Instruction *I = UnwindDest->getFirstNonPHI();
2957 Assert(I->isEHBlock() && !isa(I),
2958 "TerminateBlockInst must unwind to an EH block which is not a "
2959 "landingpad.",
2960 &TBI);
2961 }
2962
2963 visitTerminatorInst(TBI);
29642818 }
29652819
29662820 void Verifier::verifyDominatesUse(Instruction &I, unsigned i) {
26522652 setOrigin(&I, getCleanOrigin());
26532653 }
26542654
2655 void visitCleanupBlockInst(CleanupBlockInst &I) {
2656 if (!I.getType()->isVoidTy()) {
2657 setShadow(&I, getCleanShadow(&I));
2658 setOrigin(&I, getCleanOrigin());
2659 }
2660 }
2661
2662 void visitCatchBlock(CatchBlockInst &I) {
2663 if (!I.getType()->isVoidTy()) {
2664 setShadow(&I, getCleanShadow(&I));
2665 setOrigin(&I, getCleanOrigin());
2666 }
2667 }
2668
2669 void visitTerminateBlock(TerminateBlockInst &I) {
2670 DEBUG(dbgs() << "TerminateBlock: " << I << "\n");
2671 // Nothing to do here.
2672 }
2673
2674 void visitCatchEndBlockInst(CatchEndBlockInst &I) {
2675 DEBUG(dbgs() << "CatchEndBlock: " << I << "\n");
2676 // Nothing to do here.
2677 }
2678
26792655 void visitGetElementPtrInst(GetElementPtrInst &I) {
26802656 handleShadowOr(I);
26812657 }
27162692
27172693 void visitResumeInst(ResumeInst &I) {
27182694 DEBUG(dbgs() << "Resume: " << I << "\n");
2719 // Nothing to do here.
2720 }
2721
2722 void visitCleanupReturnInst(CleanupReturnInst &CRI) {
2723 DEBUG(dbgs() << "CleanupReturn: " << CRI << "\n");
2724 // Nothing to do here.
2725 }
2726
2727 void visitCatchReturnInst(CatchReturnInst &CRI) {
2728 DEBUG(dbgs() << "CatchReturn: " << CRI << "\n");
27292695 // Nothing to do here.
27302696 }
27312697
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) || I.isEHBlock() ||
61 I.mayHaveSideEffects()) {
60 if (isa(I) || isa(I) ||
61 isa(I) || 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) || I->isEHBlock() ||
80 I->mayHaveSideEffects();
79 return isa(I) || isa(I) ||
80 isa(I) || 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 const TerminatorInst *TI = SinglePred->getTerminator();
672 if (!TI->isExceptional() && TI->getNumSuccessors() == 1 &&
671 if (SinglePred->getTerminator()->getNumSuccessors() == 1 &&
673672 SinglePred != BB && !hasAddressTakenAndUsed(BB)) {
674673 // If SinglePred was a loop header, BB becomes one.
675674 if (LoopHeaders.erase(SinglePred))
538538 return;
539539 }
540540
541 // Unwinding instructions successors are always executable.
542 if (TI.isExceptional()) {
543 Succs.assign(TI.getNumSuccessors(), true);
541 if (isa(TI)) {
542 // Invoke instructions successors are always executable.
543 Succs[0] = Succs[1] = true;
544544 return;
545545 }
546546
604604 return BI->getSuccessor(CI->isZero()) == To;
605605 }
606606
607 // Unwinding instructions successors are always executable.
608 if (TI->isExceptional())
607 // Invoke instructions successors are always executable.
608 if (isa(TI))
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 unwinding instructions.
122 if (PredBB->getTerminator()->isExceptional())
123 return false;
121 // Don't break invokes.
122 if (isa(PredBB->getTerminator())) return false;
124123
125124 succ_iterator SI(succ_begin(PredBB)), SE(succ_end(PredBB));
126125 BasicBlock *OnlySucc = BB;
282282 const TargetLibraryInfo *TLI) {
283283 if (!I->use_empty() || isa(I)) return false;
284284
285 // We don't want the landingpad-like instructions removed by anything this
286 // general.
287 if (I->isEHBlock())
285 // We don't want the landingpad instruction removed by anything this general.
286 if (isa(I))
288287 return false;
289288
290289 // 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 br label %bb2
61 bb:
62 ret i8 %cbv
63 bb2:
64 %cbv = catchblock i8 [i7 4] to label %bb unwind label %bb2
65 }
66
67 define void @terminateblock0() personality i32 (...)* @__gxx_personality_v0 {
68 entry:
69 br label %bb
70 bb:
71 terminateblock [i7 4] unwind label %bb
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 br label %bb
88 bb:
89 catchendblock unwind label %bb
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 an exception handling instruction
4 ; CHECK: The unwind destination does not have a landingpad 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 an exception handling instruction
20 ; CHECK: The unwind destination does not have a landingpad 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)
248243 STRINGIFY_CODE(FUNC_CODE, INST_PHI)
249244 STRINGIFY_CODE(FUNC_CODE, INST_ALLOCA)
250245 STRINGIFY_CODE(FUNC_CODE, INST_LOAD)