/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/include/llvm/IR/Instructions.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- llvm/Instructions.h - Instruction subclass definitions ---*- C++ -*-===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | // |
10 | | // This file exposes the class definitions of all of the subclasses of the |
11 | | // Instruction class. This is meant to be an easy way to get access to all |
12 | | // instruction subclasses. |
13 | | // |
14 | | //===----------------------------------------------------------------------===// |
15 | | |
16 | | #ifndef LLVM_IR_INSTRUCTIONS_H |
17 | | #define LLVM_IR_INSTRUCTIONS_H |
18 | | |
19 | | #include "llvm/ADT/ArrayRef.h" |
20 | | #include "llvm/ADT/None.h" |
21 | | #include "llvm/ADT/STLExtras.h" |
22 | | #include "llvm/ADT/SmallVector.h" |
23 | | #include "llvm/ADT/StringRef.h" |
24 | | #include "llvm/ADT/Twine.h" |
25 | | #include "llvm/ADT/iterator.h" |
26 | | #include "llvm/ADT/iterator_range.h" |
27 | | #include "llvm/IR/Attributes.h" |
28 | | #include "llvm/IR/BasicBlock.h" |
29 | | #include "llvm/IR/CallingConv.h" |
30 | | #include "llvm/IR/Constant.h" |
31 | | #include "llvm/IR/DerivedTypes.h" |
32 | | #include "llvm/IR/Function.h" |
33 | | #include "llvm/IR/InstrTypes.h" |
34 | | #include "llvm/IR/Instruction.h" |
35 | | #include "llvm/IR/OperandTraits.h" |
36 | | #include "llvm/IR/Type.h" |
37 | | #include "llvm/IR/Use.h" |
38 | | #include "llvm/IR/User.h" |
39 | | #include "llvm/IR/Value.h" |
40 | | #include "llvm/Support/AtomicOrdering.h" |
41 | | #include "llvm/Support/Casting.h" |
42 | | #include "llvm/Support/ErrorHandling.h" |
43 | | #include <cassert> |
44 | | #include <cstddef> |
45 | | #include <cstdint> |
46 | | #include <iterator> |
47 | | |
48 | | namespace llvm { |
49 | | |
50 | | class APInt; |
51 | | class ConstantInt; |
52 | | class DataLayout; |
53 | | class LLVMContext; |
54 | | |
55 | | //===----------------------------------------------------------------------===// |
56 | | // AllocaInst Class |
57 | | //===----------------------------------------------------------------------===// |
58 | | |
59 | | /// an instruction to allocate memory on the stack |
60 | | class AllocaInst : public UnaryInstruction { |
61 | | Type *AllocatedType; |
62 | | |
63 | | protected: |
64 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
65 | | friend class Instruction; |
66 | | |
67 | | AllocaInst *cloneImpl() const; |
68 | | |
69 | | public: |
70 | | explicit AllocaInst(Type *Ty, unsigned AddrSpace, |
71 | | Value *ArraySize = nullptr, |
72 | | const Twine &Name = "", |
73 | | Instruction *InsertBefore = nullptr); |
74 | | AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, |
75 | | const Twine &Name, BasicBlock *InsertAtEnd); |
76 | | |
77 | | AllocaInst(Type *Ty, unsigned AddrSpace, |
78 | | const Twine &Name, Instruction *InsertBefore = nullptr); |
79 | | AllocaInst(Type *Ty, unsigned AddrSpace, |
80 | | const Twine &Name, BasicBlock *InsertAtEnd); |
81 | | |
82 | | AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, unsigned Align, |
83 | | const Twine &Name = "", Instruction *InsertBefore = nullptr); |
84 | | AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, unsigned Align, |
85 | | const Twine &Name, BasicBlock *InsertAtEnd); |
86 | | |
87 | | /// Return true if there is an allocation size parameter to the allocation |
88 | | /// instruction that is not 1. |
89 | | bool isArrayAllocation() const; |
90 | | |
91 | | /// Get the number of elements allocated. For a simple allocation of a single |
92 | | /// element, this will return a constant 1 value. |
93 | 1.85M | const Value *getArraySize() const { return getOperand(0); } |
94 | 1.44M | Value *getArraySize() { return getOperand(0); } |
95 | | |
96 | | /// Overload to return most specific pointer type. |
97 | 671k | PointerType *getType() const { |
98 | 671k | return cast<PointerType>(Instruction::getType()); |
99 | 671k | } |
100 | | |
101 | | /// Return the type that is being allocated by the instruction. |
102 | 46.0M | Type *getAllocatedType() const { return AllocatedType; } |
103 | | /// for use only in special circumstances that need to generically |
104 | | /// transform a whole instruction (eg: IR linking and vectorization). |
105 | 72 | void setAllocatedType(Type *Ty) { AllocatedType = Ty; } |
106 | | |
107 | | /// Return the alignment of the memory that is being allocated by the |
108 | | /// instruction. |
109 | 42.3M | unsigned getAlignment() const { |
110 | 42.3M | return (1u << (getSubclassDataFromInstruction() & 31)) >> 1; |
111 | 42.3M | } |
112 | | void setAlignment(unsigned Align); |
113 | | |
114 | | /// Return true if this alloca is in the entry block of the function and is a |
115 | | /// constant size. If so, the code generator will fold it into the |
116 | | /// prolog/epilog code, so it is basically free. |
117 | | bool isStaticAlloca() const; |
118 | | |
119 | | /// Return true if this alloca is used as an inalloca argument to a call. Such |
120 | | /// allocas are never considered static even if they are in the entry block. |
121 | 1.55M | bool isUsedWithInAlloca() const { |
122 | 1.55M | return getSubclassDataFromInstruction() & 32; |
123 | 1.55M | } |
124 | | |
125 | | /// Specify whether this alloca is used to represent the arguments to a call. |
126 | 189k | void setUsedWithInAlloca(bool V) { |
127 | 189k | setInstructionSubclassData((getSubclassDataFromInstruction() & ~32) | |
128 | 189k | (V ? 32178 : 0188k )); |
129 | 189k | } |
130 | | |
131 | | /// Return true if this alloca is used as a swifterror argument to a call. |
132 | 1.46M | bool isSwiftError() const { |
133 | 1.46M | return getSubclassDataFromInstruction() & 64; |
134 | 1.46M | } |
135 | | |
136 | | /// Specify whether this alloca is used to represent a swifterror. |
137 | 188k | void setSwiftError(bool V) { |
138 | 188k | setInstructionSubclassData((getSubclassDataFromInstruction() & ~64) | |
139 | 188k | (V ? 64104 : 0188k )); |
140 | 188k | } |
141 | | |
142 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
143 | 1.14G | static bool classof(const Instruction *I) { |
144 | 1.14G | return (I->getOpcode() == Instruction::Alloca); |
145 | 1.14G | } |
146 | 1.19G | static bool classof(const Value *V) { |
147 | 845M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
148 | 1.19G | } |
149 | | |
150 | | private: |
151 | | // Shadow Instruction::setInstructionSubclassData with a private forwarding |
152 | | // method so that subclasses cannot accidentally use it. |
153 | 2.18M | void setInstructionSubclassData(unsigned short D) { |
154 | 2.18M | Instruction::setInstructionSubclassData(D); |
155 | 2.18M | } |
156 | | }; |
157 | | |
158 | | //===----------------------------------------------------------------------===// |
159 | | // LoadInst Class |
160 | | //===----------------------------------------------------------------------===// |
161 | | |
162 | | /// An instruction for reading from memory. This uses the SubclassData field in |
163 | | /// Value to store whether or not the load is volatile. |
164 | | class LoadInst : public UnaryInstruction { |
165 | | void AssertOK(); |
166 | | |
167 | | protected: |
168 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
169 | | friend class Instruction; |
170 | | |
171 | | LoadInst *cloneImpl() const; |
172 | | |
173 | | public: |
174 | | LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore); |
175 | | LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd); |
176 | | LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile = false, |
177 | | Instruction *InsertBefore = nullptr); |
178 | | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false, |
179 | | Instruction *InsertBefore = nullptr) |
180 | | : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr, |
181 | 35.0k | NameStr, isVolatile, InsertBefore) {} llvm::LoadInst::LoadInst(llvm::Value*, llvm::Twine const&, bool, llvm::Instruction*) Line | Count | Source | 181 | 35.0k | NameStr, isVolatile, InsertBefore) {} |
Unexecuted instantiation: llvm::LoadInst::LoadInst(llvm::Value*, llvm::Twine const&, bool, llvm::Instruction*) |
182 | | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, |
183 | | BasicBlock *InsertAtEnd); |
184 | | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align, |
185 | | Instruction *InsertBefore = nullptr) |
186 | | : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr, |
187 | 4.89k | NameStr, isVolatile, Align, InsertBefore) {} llvm::LoadInst::LoadInst(llvm::Value*, llvm::Twine const&, bool, unsigned int, llvm::Instruction*) Line | Count | Source | 187 | 4.89k | NameStr, isVolatile, Align, InsertBefore) {} |
Unexecuted instantiation: llvm::LoadInst::LoadInst(llvm::Value*, llvm::Twine const&, bool, unsigned int, llvm::Instruction*) |
188 | | LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile, |
189 | | unsigned Align, Instruction *InsertBefore = nullptr); |
190 | | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, |
191 | | unsigned Align, BasicBlock *InsertAtEnd); |
192 | | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align, |
193 | | AtomicOrdering Order, SyncScope::ID SSID = SyncScope::System, |
194 | | Instruction *InsertBefore = nullptr) |
195 | | : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr, |
196 | 774k | NameStr, isVolatile, Align, Order, SSID, InsertBefore) {} llvm::LoadInst::LoadInst(llvm::Value*, llvm::Twine const&, bool, unsigned int, llvm::AtomicOrdering, unsigned char, llvm::Instruction*) Line | Count | Source | 196 | 774k | NameStr, isVolatile, Align, Order, SSID, InsertBefore) {} |
Unexecuted instantiation: llvm::LoadInst::LoadInst(llvm::Value*, llvm::Twine const&, bool, unsigned int, llvm::AtomicOrdering, unsigned char, llvm::Instruction*) |
197 | | LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile, |
198 | | unsigned Align, AtomicOrdering Order, |
199 | | SyncScope::ID SSID = SyncScope::System, |
200 | | Instruction *InsertBefore = nullptr); |
201 | | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, |
202 | | unsigned Align, AtomicOrdering Order, SyncScope::ID SSID, |
203 | | BasicBlock *InsertAtEnd); |
204 | | LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore); |
205 | | LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd); |
206 | | LoadInst(Type *Ty, Value *Ptr, const char *NameStr = nullptr, |
207 | | bool isVolatile = false, Instruction *InsertBefore = nullptr); |
208 | | explicit LoadInst(Value *Ptr, const char *NameStr = nullptr, |
209 | | bool isVolatile = false, |
210 | | Instruction *InsertBefore = nullptr) |
211 | | : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr, |
212 | 4.24M | NameStr, isVolatile, InsertBefore) {} llvm::LoadInst::LoadInst(llvm::Value*, char const*, bool, llvm::Instruction*) Line | Count | Source | 212 | 4.24M | NameStr, isVolatile, InsertBefore) {} |
Unexecuted instantiation: llvm::LoadInst::LoadInst(llvm::Value*, char const*, bool, llvm::Instruction*) |
213 | | LoadInst(Value *Ptr, const char *NameStr, bool isVolatile, |
214 | | BasicBlock *InsertAtEnd); |
215 | | |
216 | | /// Return true if this is a load from a volatile memory location. |
217 | 244M | bool isVolatile() const { return getSubclassDataFromInstruction() & 1; } |
218 | | |
219 | | /// Specify whether this is a volatile load or not. |
220 | 8.57M | void setVolatile(bool V) { |
221 | 8.57M | setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | |
222 | 8.57M | (V ? 120.9k : 08.55M )); |
223 | 8.57M | } |
224 | | |
225 | | /// Return the alignment of the access that is being performed. |
226 | 35.7M | unsigned getAlignment() const { |
227 | 35.7M | return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1; |
228 | 35.7M | } |
229 | | |
230 | | void setAlignment(unsigned Align); |
231 | | |
232 | | /// Returns the ordering constraint of this load instruction. |
233 | 224M | AtomicOrdering getOrdering() const { |
234 | 224M | return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7); |
235 | 224M | } |
236 | | |
237 | | /// Sets the ordering constraint of this load instruction. May not be Release |
238 | | /// or AcquireRelease. |
239 | 8.69M | void setOrdering(AtomicOrdering Ordering) { |
240 | 8.69M | setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) | |
241 | 8.69M | ((unsigned)Ordering << 7)); |
242 | 8.69M | } |
243 | | |
244 | | /// Returns the synchronization scope ID of this load instruction. |
245 | 2.99M | SyncScope::ID getSyncScopeID() const { |
246 | 2.99M | return SSID; |
247 | 2.99M | } |
248 | | |
249 | | /// Sets the synchronization scope ID of this load instruction. |
250 | 8.69M | void setSyncScopeID(SyncScope::ID SSID) { |
251 | 8.69M | this->SSID = SSID; |
252 | 8.69M | } |
253 | | |
254 | | /// Sets the ordering constraint and the synchronization scope ID of this load |
255 | | /// instruction. |
256 | | void setAtomic(AtomicOrdering Ordering, |
257 | 8.69M | SyncScope::ID SSID = SyncScope::System) { |
258 | 8.69M | setOrdering(Ordering); |
259 | 8.69M | setSyncScopeID(SSID); |
260 | 8.69M | } |
261 | | |
262 | 36.5M | bool isSimple() const { return !isAtomic() && 36.5M !isVolatile()36.5M ; } |
263 | | |
264 | 129M | bool isUnordered() const { |
265 | 129M | return (getOrdering() == AtomicOrdering::NotAtomic || |
266 | 25.5k | getOrdering() == AtomicOrdering::Unordered) && |
267 | 129M | !isVolatile(); |
268 | 129M | } |
269 | | |
270 | 93.7M | Value *getPointerOperand() { return getOperand(0); } |
271 | 44.7M | const Value *getPointerOperand() const { return getOperand(0); } |
272 | 654 | static unsigned getPointerOperandIndex() { return 0U; } |
273 | 13.5M | Type *getPointerOperandType() const { return getPointerOperand()->getType(); } |
274 | | |
275 | | /// Returns the address space of the pointer operand. |
276 | 13.5M | unsigned getPointerAddressSpace() const { |
277 | 13.5M | return getPointerOperandType()->getPointerAddressSpace(); |
278 | 13.5M | } |
279 | | |
280 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
281 | 1.03G | static bool classof(const Instruction *I) { |
282 | 1.03G | return I->getOpcode() == Instruction::Load; |
283 | 1.03G | } |
284 | 399M | static bool classof(const Value *V) { |
285 | 336M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
286 | 399M | } |
287 | | |
288 | | private: |
289 | | // Shadow Instruction::setInstructionSubclassData with a private forwarding |
290 | | // method so that subclasses cannot accidentally use it. |
291 | 30.2M | void setInstructionSubclassData(unsigned short D) { |
292 | 30.2M | Instruction::setInstructionSubclassData(D); |
293 | 30.2M | } |
294 | | |
295 | | /// The synchronization scope ID of this load instruction. Not quite enough |
296 | | /// room in SubClassData for everything, so synchronization scope ID gets its |
297 | | /// own field. |
298 | | SyncScope::ID SSID; |
299 | | }; |
300 | | |
301 | | //===----------------------------------------------------------------------===// |
302 | | // StoreInst Class |
303 | | //===----------------------------------------------------------------------===// |
304 | | |
305 | | /// An instruction for storing to memory. |
306 | | class StoreInst : public Instruction { |
307 | | void AssertOK(); |
308 | | |
309 | | protected: |
310 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
311 | | friend class Instruction; |
312 | | |
313 | | StoreInst *cloneImpl() const; |
314 | | |
315 | | public: |
316 | | StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore); |
317 | | StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd); |
318 | | StoreInst(Value *Val, Value *Ptr, bool isVolatile = false, |
319 | | Instruction *InsertBefore = nullptr); |
320 | | StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd); |
321 | | StoreInst(Value *Val, Value *Ptr, bool isVolatile, |
322 | | unsigned Align, Instruction *InsertBefore = nullptr); |
323 | | StoreInst(Value *Val, Value *Ptr, bool isVolatile, |
324 | | unsigned Align, BasicBlock *InsertAtEnd); |
325 | | StoreInst(Value *Val, Value *Ptr, bool isVolatile, |
326 | | unsigned Align, AtomicOrdering Order, |
327 | | SyncScope::ID SSID = SyncScope::System, |
328 | | Instruction *InsertBefore = nullptr); |
329 | | StoreInst(Value *Val, Value *Ptr, bool isVolatile, |
330 | | unsigned Align, AtomicOrdering Order, SyncScope::ID SSID, |
331 | | BasicBlock *InsertAtEnd); |
332 | | |
333 | | // allocate space for exactly two operands |
334 | 4.37M | void *operator new(size_t s) { |
335 | 4.37M | return User::operator new(s, 2); |
336 | 4.37M | } |
337 | | |
338 | | /// Return true if this is a store to a volatile memory location. |
339 | 166M | bool isVolatile() const { return getSubclassDataFromInstruction() & 1; } |
340 | | |
341 | | /// Specify whether this is a volatile store or not. |
342 | 4.37M | void setVolatile(bool V) { |
343 | 4.37M | setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | |
344 | 4.37M | (V ? 117.8k : 04.35M )); |
345 | 4.37M | } |
346 | | |
347 | | /// Transparently provide more efficient getOperand methods. |
348 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
349 | | |
350 | | /// Return the alignment of the access that is being performed |
351 | 26.1M | unsigned getAlignment() const { |
352 | 26.1M | return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1; |
353 | 26.1M | } |
354 | | |
355 | | void setAlignment(unsigned Align); |
356 | | |
357 | | /// Returns the ordering constraint of this store instruction. |
358 | 132M | AtomicOrdering getOrdering() const { |
359 | 132M | return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7); |
360 | 132M | } |
361 | | |
362 | | /// Sets the ordering constraint of this store instruction. May not be |
363 | | /// Acquire or AcquireRelease. |
364 | 4.42M | void setOrdering(AtomicOrdering Ordering) { |
365 | 4.42M | setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) | |
366 | 4.42M | ((unsigned)Ordering << 7)); |
367 | 4.42M | } |
368 | | |
369 | | /// Returns the synchronization scope ID of this store instruction. |
370 | 5.58M | SyncScope::ID getSyncScopeID() const { |
371 | 5.58M | return SSID; |
372 | 5.58M | } |
373 | | |
374 | | /// Sets the synchronization scope ID of this store instruction. |
375 | 4.42M | void setSyncScopeID(SyncScope::ID SSID) { |
376 | 4.42M | this->SSID = SSID; |
377 | 4.42M | } |
378 | | |
379 | | /// Sets the ordering constraint and the synchronization scope ID of this |
380 | | /// store instruction. |
381 | | void setAtomic(AtomicOrdering Ordering, |
382 | 4.42M | SyncScope::ID SSID = SyncScope::System) { |
383 | 4.42M | setOrdering(Ordering); |
384 | 4.42M | setSyncScopeID(SSID); |
385 | 4.42M | } |
386 | | |
387 | 29.6M | bool isSimple() const { return !isAtomic() && 29.6M !isVolatile()29.4M ; } |
388 | | |
389 | 66.6M | bool isUnordered() const { |
390 | 66.6M | return (getOrdering() == AtomicOrdering::NotAtomic || |
391 | 374k | getOrdering() == AtomicOrdering::Unordered) && |
392 | 66.2M | !isVolatile(); |
393 | 66.6M | } |
394 | | |
395 | 63.6M | Value *getValueOperand() { return getOperand(0); } |
396 | 27.3M | const Value *getValueOperand() const { return getOperand(0); } |
397 | | |
398 | 65.9M | Value *getPointerOperand() { return getOperand(1); } |
399 | 43.1M | const Value *getPointerOperand() const { return getOperand(1); } |
400 | 458k | static unsigned getPointerOperandIndex() { return 1U; } |
401 | 15.2M | Type *getPointerOperandType() const { return getPointerOperand()->getType(); } |
402 | | |
403 | | /// Returns the address space of the pointer operand. |
404 | 15.2M | unsigned getPointerAddressSpace() const { |
405 | 15.2M | return getPointerOperandType()->getPointerAddressSpace(); |
406 | 15.2M | } |
407 | | |
408 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
409 | 991M | static bool classof(const Instruction *I) { |
410 | 991M | return I->getOpcode() == Instruction::Store; |
411 | 991M | } |
412 | 45.6M | static bool classof(const Value *V) { |
413 | 43.3M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
414 | 45.6M | } |
415 | | |
416 | | private: |
417 | | // Shadow Instruction::setInstructionSubclassData with a private forwarding |
418 | | // method so that subclasses cannot accidentally use it. |
419 | 15.8M | void setInstructionSubclassData(unsigned short D) { |
420 | 15.8M | Instruction::setInstructionSubclassData(D); |
421 | 15.8M | } |
422 | | |
423 | | /// The synchronization scope ID of this store instruction. Not quite enough |
424 | | /// room in SubClassData for everything, so synchronization scope ID gets its |
425 | | /// own field. |
426 | | SyncScope::ID SSID; |
427 | | }; |
428 | | |
429 | | template <> |
430 | | struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> { |
431 | | }; |
432 | | |
433 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value) |
434 | | |
435 | | //===----------------------------------------------------------------------===// |
436 | | // FenceInst Class |
437 | | //===----------------------------------------------------------------------===// |
438 | | |
439 | | /// An instruction for ordering other memory operations. |
440 | | class FenceInst : public Instruction { |
441 | | void Init(AtomicOrdering Ordering, SyncScope::ID SSID); |
442 | | |
443 | | protected: |
444 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
445 | | friend class Instruction; |
446 | | |
447 | | FenceInst *cloneImpl() const; |
448 | | |
449 | | public: |
450 | | // Ordering may only be Acquire, Release, AcquireRelease, or |
451 | | // SequentiallyConsistent. |
452 | | FenceInst(LLVMContext &C, AtomicOrdering Ordering, |
453 | | SyncScope::ID SSID = SyncScope::System, |
454 | | Instruction *InsertBefore = nullptr); |
455 | | FenceInst(LLVMContext &C, AtomicOrdering Ordering, SyncScope::ID SSID, |
456 | | BasicBlock *InsertAtEnd); |
457 | | |
458 | | // allocate space for exactly zero operands |
459 | 5.44k | void *operator new(size_t s) { |
460 | 5.44k | return User::operator new(s, 0); |
461 | 5.44k | } |
462 | | |
463 | | /// Returns the ordering constraint of this fence instruction. |
464 | 17.9k | AtomicOrdering getOrdering() const { |
465 | 17.9k | return AtomicOrdering(getSubclassDataFromInstruction() >> 1); |
466 | 17.9k | } |
467 | | |
468 | | /// Sets the ordering constraint of this fence instruction. May only be |
469 | | /// Acquire, Release, AcquireRelease, or SequentiallyConsistent. |
470 | 5.44k | void setOrdering(AtomicOrdering Ordering) { |
471 | 5.44k | setInstructionSubclassData((getSubclassDataFromInstruction() & 1) | |
472 | 5.44k | ((unsigned)Ordering << 1)); |
473 | 5.44k | } |
474 | | |
475 | | /// Returns the synchronization scope ID of this fence instruction. |
476 | 4.91k | SyncScope::ID getSyncScopeID() const { |
477 | 4.91k | return SSID; |
478 | 4.91k | } |
479 | | |
480 | | /// Sets the synchronization scope ID of this fence instruction. |
481 | 5.44k | void setSyncScopeID(SyncScope::ID SSID) { |
482 | 5.44k | this->SSID = SSID; |
483 | 5.44k | } |
484 | | |
485 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
486 | 94.6M | static bool classof(const Instruction *I) { |
487 | 94.6M | return I->getOpcode() == Instruction::Fence; |
488 | 94.6M | } |
489 | 0 | static bool classof(const Value *V) { |
490 | 0 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
491 | 0 | } |
492 | | |
493 | | private: |
494 | | // Shadow Instruction::setInstructionSubclassData with a private forwarding |
495 | | // method so that subclasses cannot accidentally use it. |
496 | 5.44k | void setInstructionSubclassData(unsigned short D) { |
497 | 5.44k | Instruction::setInstructionSubclassData(D); |
498 | 5.44k | } |
499 | | |
500 | | /// The synchronization scope ID of this fence instruction. Not quite enough |
501 | | /// room in SubClassData for everything, so synchronization scope ID gets its |
502 | | /// own field. |
503 | | SyncScope::ID SSID; |
504 | | }; |
505 | | |
506 | | //===----------------------------------------------------------------------===// |
507 | | // AtomicCmpXchgInst Class |
508 | | //===----------------------------------------------------------------------===// |
509 | | |
510 | | /// an instruction that atomically checks whether a |
511 | | /// specified value is in a memory location, and, if it is, stores a new value |
512 | | /// there. Returns the value that was loaded. |
513 | | /// |
514 | | class AtomicCmpXchgInst : public Instruction { |
515 | | void Init(Value *Ptr, Value *Cmp, Value *NewVal, |
516 | | AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, |
517 | | SyncScope::ID SSID); |
518 | | |
519 | | protected: |
520 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
521 | | friend class Instruction; |
522 | | |
523 | | AtomicCmpXchgInst *cloneImpl() const; |
524 | | |
525 | | public: |
526 | | AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, |
527 | | AtomicOrdering SuccessOrdering, |
528 | | AtomicOrdering FailureOrdering, |
529 | | SyncScope::ID SSID, Instruction *InsertBefore = nullptr); |
530 | | AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, |
531 | | AtomicOrdering SuccessOrdering, |
532 | | AtomicOrdering FailureOrdering, |
533 | | SyncScope::ID SSID, BasicBlock *InsertAtEnd); |
534 | | |
535 | | // allocate space for exactly three operands |
536 | 12.5k | void *operator new(size_t s) { |
537 | 12.5k | return User::operator new(s, 3); |
538 | 12.5k | } |
539 | | |
540 | | /// Return true if this is a cmpxchg from a volatile memory |
541 | | /// location. |
542 | | /// |
543 | 46.6k | bool isVolatile() const { |
544 | 46.6k | return getSubclassDataFromInstruction() & 1; |
545 | 46.6k | } |
546 | | |
547 | | /// Specify whether this is a volatile cmpxchg. |
548 | | /// |
549 | 11.2k | void setVolatile(bool V) { |
550 | 11.2k | setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | |
551 | 11.2k | (unsigned)V); |
552 | 11.2k | } |
553 | | |
554 | | /// Return true if this cmpxchg may spuriously fail. |
555 | 24.7k | bool isWeak() const { |
556 | 24.7k | return getSubclassDataFromInstruction() & 0x100; |
557 | 24.7k | } |
558 | | |
559 | 11.1k | void setWeak(bool IsWeak) { |
560 | 11.1k | setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x100) | |
561 | 11.1k | (IsWeak << 8)); |
562 | 11.1k | } |
563 | | |
564 | | /// Transparently provide more efficient getOperand methods. |
565 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
566 | | |
567 | | /// Returns the success ordering constraint of this cmpxchg instruction. |
568 | 82.2k | AtomicOrdering getSuccessOrdering() const { |
569 | 82.2k | return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7); |
570 | 82.2k | } |
571 | | |
572 | | /// Sets the success ordering constraint of this cmpxchg instruction. |
573 | 12.6k | void setSuccessOrdering(AtomicOrdering Ordering) { |
574 | 12.6k | assert(Ordering != AtomicOrdering::NotAtomic && |
575 | 12.6k | "CmpXchg instructions can only be atomic."); |
576 | 12.6k | setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x1c) | |
577 | 12.6k | ((unsigned)Ordering << 2)); |
578 | 12.6k | } |
579 | | |
580 | | /// Returns the failure ordering constraint of this cmpxchg instruction. |
581 | 37.2k | AtomicOrdering getFailureOrdering() const { |
582 | 37.2k | return AtomicOrdering((getSubclassDataFromInstruction() >> 5) & 7); |
583 | 37.2k | } |
584 | | |
585 | | /// Sets the failure ordering constraint of this cmpxchg instruction. |
586 | 12.6k | void setFailureOrdering(AtomicOrdering Ordering) { |
587 | 12.6k | assert(Ordering != AtomicOrdering::NotAtomic && |
588 | 12.6k | "CmpXchg instructions can only be atomic."); |
589 | 12.6k | setInstructionSubclassData((getSubclassDataFromInstruction() & ~0xe0) | |
590 | 12.6k | ((unsigned)Ordering << 5)); |
591 | 12.6k | } |
592 | | |
593 | | /// Returns the synchronization scope ID of this cmpxchg instruction. |
594 | 3.50k | SyncScope::ID getSyncScopeID() const { |
595 | 3.50k | return SSID; |
596 | 3.50k | } |
597 | | |
598 | | /// Sets the synchronization scope ID of this cmpxchg instruction. |
599 | 12.5k | void setSyncScopeID(SyncScope::ID SSID) { |
600 | 12.5k | this->SSID = SSID; |
601 | 12.5k | } |
602 | | |
603 | 12.2k | Value *getPointerOperand() { return getOperand(0); } |
604 | 7.92k | const Value *getPointerOperand() const { return getOperand(0); } |
605 | 126 | static unsigned getPointerOperandIndex() { return 0U; } |
606 | | |
607 | 53.1k | Value *getCompareOperand() { return getOperand(1); } |
608 | 4.94k | const Value *getCompareOperand() const { return getOperand(1); } |
609 | | |
610 | 9.77k | Value *getNewValOperand() { return getOperand(2); } |
611 | 2.47k | const Value *getNewValOperand() const { return getOperand(2); } |
612 | | |
613 | | /// Returns the address space of the pointer operand. |
614 | 2.97k | unsigned getPointerAddressSpace() const { |
615 | 2.97k | return getPointerOperand()->getType()->getPointerAddressSpace(); |
616 | 2.97k | } |
617 | | |
618 | | /// Returns the strongest permitted ordering on failure, given the |
619 | | /// desired ordering on success. |
620 | | /// |
621 | | /// If the comparison in a cmpxchg operation fails, there is no atomic store |
622 | | /// so release semantics cannot be provided. So this function drops explicit |
623 | | /// Release requests from the AtomicOrdering. A SequentiallyConsistent |
624 | | /// operation would remain SequentiallyConsistent. |
625 | | static AtomicOrdering |
626 | 1.43k | getStrongestFailureOrdering(AtomicOrdering SuccessOrdering) { |
627 | 1.43k | switch (SuccessOrdering) { |
628 | 0 | default: |
629 | 0 | llvm_unreachable("invalid cmpxchg success ordering"); |
630 | 808 | case AtomicOrdering::Release: |
631 | 808 | case AtomicOrdering::Monotonic: |
632 | 808 | return AtomicOrdering::Monotonic; |
633 | 414 | case AtomicOrdering::AcquireRelease: |
634 | 414 | case AtomicOrdering::Acquire: |
635 | 414 | return AtomicOrdering::Acquire; |
636 | 209 | case AtomicOrdering::SequentiallyConsistent: |
637 | 209 | return AtomicOrdering::SequentiallyConsistent; |
638 | 1.43k | } |
639 | 1.43k | } |
640 | | |
641 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
642 | 91.5M | static bool classof(const Instruction *I) { |
643 | 91.5M | return I->getOpcode() == Instruction::AtomicCmpXchg; |
644 | 91.5M | } |
645 | 339k | static bool classof(const Value *V) { |
646 | 339k | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
647 | 339k | } |
648 | | |
649 | | private: |
650 | | // Shadow Instruction::setInstructionSubclassData with a private forwarding |
651 | | // method so that subclasses cannot accidentally use it. |
652 | 47.7k | void setInstructionSubclassData(unsigned short D) { |
653 | 47.7k | Instruction::setInstructionSubclassData(D); |
654 | 47.7k | } |
655 | | |
656 | | /// The synchronization scope ID of this cmpxchg instruction. Not quite |
657 | | /// enough room in SubClassData for everything, so synchronization scope ID |
658 | | /// gets its own field. |
659 | | SyncScope::ID SSID; |
660 | | }; |
661 | | |
662 | | template <> |
663 | | struct OperandTraits<AtomicCmpXchgInst> : |
664 | | public FixedNumOperandTraits<AtomicCmpXchgInst, 3> { |
665 | | }; |
666 | | |
667 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value) |
668 | | |
669 | | //===----------------------------------------------------------------------===// |
670 | | // AtomicRMWInst Class |
671 | | //===----------------------------------------------------------------------===// |
672 | | |
673 | | /// an instruction that atomically reads a memory location, |
674 | | /// combines it with another value, and then stores the result back. Returns |
675 | | /// the old value. |
676 | | /// |
677 | | class AtomicRMWInst : public Instruction { |
678 | | protected: |
679 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
680 | | friend class Instruction; |
681 | | |
682 | | AtomicRMWInst *cloneImpl() const; |
683 | | |
684 | | public: |
685 | | /// This enumeration lists the possible modifications atomicrmw can make. In |
686 | | /// the descriptions, 'p' is the pointer to the instruction's memory location, |
687 | | /// 'old' is the initial value of *p, and 'v' is the other value passed to the |
688 | | /// instruction. These instructions always return 'old'. |
689 | | enum BinOp { |
690 | | /// *p = v |
691 | | Xchg, |
692 | | /// *p = old + v |
693 | | Add, |
694 | | /// *p = old - v |
695 | | Sub, |
696 | | /// *p = old & v |
697 | | And, |
698 | | /// *p = ~(old & v) |
699 | | Nand, |
700 | | /// *p = old | v |
701 | | Or, |
702 | | /// *p = old ^ v |
703 | | Xor, |
704 | | /// *p = old >signed v ? old : v |
705 | | Max, |
706 | | /// *p = old <signed v ? old : v |
707 | | Min, |
708 | | /// *p = old >unsigned v ? old : v |
709 | | UMax, |
710 | | /// *p = old <unsigned v ? old : v |
711 | | UMin, |
712 | | |
713 | | FIRST_BINOP = Xchg, |
714 | | LAST_BINOP = UMin, |
715 | | BAD_BINOP |
716 | | }; |
717 | | |
718 | | AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, |
719 | | AtomicOrdering Ordering, SyncScope::ID SSID, |
720 | | Instruction *InsertBefore = nullptr); |
721 | | AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, |
722 | | AtomicOrdering Ordering, SyncScope::ID SSID, |
723 | | BasicBlock *InsertAtEnd); |
724 | | |
725 | | // allocate space for exactly two operands |
726 | 46.1k | void *operator new(size_t s) { |
727 | 46.1k | return User::operator new(s, 2); |
728 | 46.1k | } |
729 | | |
730 | 207k | BinOp getOperation() const { |
731 | 207k | return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5); |
732 | 207k | } |
733 | | |
734 | 46.1k | void setOperation(BinOp Operation) { |
735 | 46.1k | unsigned short SubclassData = getSubclassDataFromInstruction(); |
736 | 46.1k | setInstructionSubclassData((SubclassData & 31) | |
737 | 46.1k | (Operation << 5)); |
738 | 46.1k | } |
739 | | |
740 | | /// Return true if this is a RMW on a volatile memory location. |
741 | | /// |
742 | 110k | bool isVolatile() const { |
743 | 110k | return getSubclassDataFromInstruction() & 1; |
744 | 110k | } |
745 | | |
746 | | /// Specify whether this is a volatile RMW or not. |
747 | | /// |
748 | 45.3k | void setVolatile(bool V) { |
749 | 45.3k | setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | |
750 | 45.3k | (unsigned)V); |
751 | 45.3k | } |
752 | | |
753 | | /// Transparently provide more efficient getOperand methods. |
754 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
755 | | |
756 | | /// Returns the ordering constraint of this rmw instruction. |
757 | 267k | AtomicOrdering getOrdering() const { |
758 | 267k | return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7); |
759 | 267k | } |
760 | | |
761 | | /// Sets the ordering constraint of this rmw instruction. |
762 | 47.5k | void setOrdering(AtomicOrdering Ordering) { |
763 | 47.5k | assert(Ordering != AtomicOrdering::NotAtomic && |
764 | 47.5k | "atomicrmw instructions can only be atomic."); |
765 | 47.5k | setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) | |
766 | 47.5k | ((unsigned)Ordering << 2)); |
767 | 47.5k | } |
768 | | |
769 | | /// Returns the synchronization scope ID of this rmw instruction. |
770 | 43.2k | SyncScope::ID getSyncScopeID() const { |
771 | 43.2k | return SSID; |
772 | 43.2k | } |
773 | | |
774 | | /// Sets the synchronization scope ID of this rmw instruction. |
775 | 46.1k | void setSyncScopeID(SyncScope::ID SSID) { |
776 | 46.1k | this->SSID = SSID; |
777 | 46.1k | } |
778 | | |
779 | 46.0k | Value *getPointerOperand() { return getOperand(0); } |
780 | 24.1k | const Value *getPointerOperand() const { return getOperand(0); } |
781 | 98 | static unsigned getPointerOperandIndex() { return 0U; } |
782 | | |
783 | 207k | Value *getValOperand() { return getOperand(1); } |
784 | 18.5k | const Value *getValOperand() const { return getOperand(1); } |
785 | | |
786 | | /// Returns the address space of the pointer operand. |
787 | 5.59k | unsigned getPointerAddressSpace() const { |
788 | 5.59k | return getPointerOperand()->getType()->getPointerAddressSpace(); |
789 | 5.59k | } |
790 | | |
791 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
792 | 91.5M | static bool classof(const Instruction *I) { |
793 | 91.5M | return I->getOpcode() == Instruction::AtomicRMW; |
794 | 91.5M | } |
795 | 340k | static bool classof(const Value *V) { |
796 | 340k | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
797 | 340k | } |
798 | | |
799 | | private: |
800 | | void Init(BinOp Operation, Value *Ptr, Value *Val, |
801 | | AtomicOrdering Ordering, SyncScope::ID SSID); |
802 | | |
803 | | // Shadow Instruction::setInstructionSubclassData with a private forwarding |
804 | | // method so that subclasses cannot accidentally use it. |
805 | 139k | void setInstructionSubclassData(unsigned short D) { |
806 | 139k | Instruction::setInstructionSubclassData(D); |
807 | 139k | } |
808 | | |
809 | | /// The synchronization scope ID of this rmw instruction. Not quite enough |
810 | | /// room in SubClassData for everything, so synchronization scope ID gets its |
811 | | /// own field. |
812 | | SyncScope::ID SSID; |
813 | | }; |
814 | | |
815 | | template <> |
816 | | struct OperandTraits<AtomicRMWInst> |
817 | | : public FixedNumOperandTraits<AtomicRMWInst,2> { |
818 | | }; |
819 | | |
820 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value) |
821 | | |
822 | | //===----------------------------------------------------------------------===// |
823 | | // GetElementPtrInst Class |
824 | | //===----------------------------------------------------------------------===// |
825 | | |
826 | | // checkGEPType - Simple wrapper function to give a better assertion failure |
827 | | // message on bad indexes for a gep instruction. |
828 | | // |
829 | 6.46M | inline Type *checkGEPType(Type *Ty) { |
830 | 6.46M | assert(Ty && "Invalid GetElementPtrInst indices for type!"); |
831 | 6.46M | return Ty; |
832 | 6.46M | } |
833 | | |
834 | | /// an instruction for type-safe pointer arithmetic to |
835 | | /// access elements of arrays and structs |
836 | | /// |
837 | | class GetElementPtrInst : public Instruction { |
838 | | Type *SourceElementType; |
839 | | Type *ResultElementType; |
840 | | |
841 | | GetElementPtrInst(const GetElementPtrInst &GEPI); |
842 | | |
843 | | /// Constructors - Create a getelementptr instruction with a base pointer an |
844 | | /// list of indices. The first ctor can optionally insert before an existing |
845 | | /// instruction, the second appends the new instruction to the specified |
846 | | /// BasicBlock. |
847 | | inline GetElementPtrInst(Type *PointeeType, Value *Ptr, |
848 | | ArrayRef<Value *> IdxList, unsigned Values, |
849 | | const Twine &NameStr, Instruction *InsertBefore); |
850 | | inline GetElementPtrInst(Type *PointeeType, Value *Ptr, |
851 | | ArrayRef<Value *> IdxList, unsigned Values, |
852 | | const Twine &NameStr, BasicBlock *InsertAtEnd); |
853 | | |
854 | | void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr); |
855 | | |
856 | | protected: |
857 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
858 | | friend class Instruction; |
859 | | |
860 | | GetElementPtrInst *cloneImpl() const; |
861 | | |
862 | | public: |
863 | | static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr, |
864 | | ArrayRef<Value *> IdxList, |
865 | | const Twine &NameStr = "", |
866 | 6.40M | Instruction *InsertBefore = nullptr) { |
867 | 6.40M | unsigned Values = 1 + unsigned(IdxList.size()); |
868 | 6.40M | if (!PointeeType) |
869 | 732k | PointeeType = |
870 | 732k | cast<PointerType>(Ptr->getType()->getScalarType())->getElementType(); |
871 | 6.40M | else |
872 | 6.40M | assert( |
873 | 6.40M | PointeeType == |
874 | 6.40M | cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()); |
875 | 6.40M | return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values, |
876 | 6.40M | NameStr, InsertBefore); |
877 | 6.40M | } |
878 | | |
879 | | static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr, |
880 | | ArrayRef<Value *> IdxList, |
881 | | const Twine &NameStr, |
882 | | BasicBlock *InsertAtEnd) { |
883 | | unsigned Values = 1 + unsigned(IdxList.size()); |
884 | | if (!PointeeType) |
885 | | PointeeType = |
886 | | cast<PointerType>(Ptr->getType()->getScalarType())->getElementType(); |
887 | | else |
888 | | assert( |
889 | | PointeeType == |
890 | | cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()); |
891 | | return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values, |
892 | | NameStr, InsertAtEnd); |
893 | | } |
894 | | |
895 | | /// Create an "inbounds" getelementptr. See the documentation for the |
896 | | /// "inbounds" flag in LangRef.html for details. |
897 | | static GetElementPtrInst *CreateInBounds(Value *Ptr, |
898 | | ArrayRef<Value *> IdxList, |
899 | | const Twine &NameStr = "", |
900 | 202k | Instruction *InsertBefore = nullptr){ |
901 | 202k | return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertBefore); |
902 | 202k | } |
903 | | |
904 | | static GetElementPtrInst * |
905 | | CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef<Value *> IdxList, |
906 | | const Twine &NameStr = "", |
907 | 1.40M | Instruction *InsertBefore = nullptr) { |
908 | 1.40M | GetElementPtrInst *GEP = |
909 | 1.40M | Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore); |
910 | 1.40M | GEP->setIsInBounds(true); |
911 | 1.40M | return GEP; |
912 | 1.40M | } |
913 | | |
914 | | static GetElementPtrInst *CreateInBounds(Value *Ptr, |
915 | | ArrayRef<Value *> IdxList, |
916 | | const Twine &NameStr, |
917 | 0 | BasicBlock *InsertAtEnd) { |
918 | 0 | return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertAtEnd); |
919 | 0 | } |
920 | | |
921 | | static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr, |
922 | | ArrayRef<Value *> IdxList, |
923 | | const Twine &NameStr, |
924 | 0 | BasicBlock *InsertAtEnd) { |
925 | 0 | GetElementPtrInst *GEP = |
926 | 0 | Create(PointeeType, Ptr, IdxList, NameStr, InsertAtEnd); |
927 | 0 | GEP->setIsInBounds(true); |
928 | 0 | return GEP; |
929 | 0 | } |
930 | | |
931 | | /// Transparently provide more efficient getOperand methods. |
932 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
933 | | |
934 | 397M | Type *getSourceElementType() const { return SourceElementType; } |
935 | | |
936 | 97 | void setSourceElementType(Type *Ty) { SourceElementType = Ty; } |
937 | 67 | void setResultElementType(Type *Ty) { ResultElementType = Ty; } |
938 | | |
939 | 572k | Type *getResultElementType() const { |
940 | 572k | assert(ResultElementType == |
941 | 572k | cast<PointerType>(getType()->getScalarType())->getElementType()); |
942 | 572k | return ResultElementType; |
943 | 572k | } |
944 | | |
945 | | /// Returns the address space of this instruction's pointer type. |
946 | 99.0k | unsigned getAddressSpace() const { |
947 | 99.0k | // Note that this is always the same as the pointer operand's address space |
948 | 99.0k | // and that is cheaper to compute, so cheat here. |
949 | 99.0k | return getPointerAddressSpace(); |
950 | 99.0k | } |
951 | | |
952 | | /// Returns the type of the element that would be loaded with |
953 | | /// a load instruction with the specified parameters. |
954 | | /// |
955 | | /// Null is returned if the indices are invalid for the specified |
956 | | /// pointer type. |
957 | | /// |
958 | | static Type *getIndexedType(Type *Ty, ArrayRef<Value *> IdxList); |
959 | | static Type *getIndexedType(Type *Ty, ArrayRef<Constant *> IdxList); |
960 | | static Type *getIndexedType(Type *Ty, ArrayRef<uint64_t> IdxList); |
961 | | |
962 | 18.5M | inline op_iterator idx_begin() { return op_begin()+1; } |
963 | 0 | inline const_op_iterator idx_begin() const { return op_begin()+1; } |
964 | 6.46M | inline op_iterator idx_end() { return op_end(); } |
965 | 0 | inline const_op_iterator idx_end() const { return op_end(); } |
966 | | |
967 | 8.55k | inline iterator_range<op_iterator> indices() { |
968 | 8.55k | return make_range(idx_begin(), idx_end()); |
969 | 8.55k | } |
970 | | |
971 | 0 | inline iterator_range<const_op_iterator> indices() const { |
972 | 0 | return make_range(idx_begin(), idx_end()); |
973 | 0 | } |
974 | | |
975 | 10.5M | Value *getPointerOperand() { |
976 | 10.5M | return getOperand(0); |
977 | 10.5M | } |
978 | 39.8M | const Value *getPointerOperand() const { |
979 | 39.8M | return getOperand(0); |
980 | 39.8M | } |
981 | 4 | static unsigned getPointerOperandIndex() { |
982 | 4 | return 0U; // get index for modifying correct operand. |
983 | 4 | } |
984 | | |
985 | | /// Method to return the pointer operand as a |
986 | | /// PointerType. |
987 | 39.8M | Type *getPointerOperandType() const { |
988 | 39.8M | return getPointerOperand()->getType(); |
989 | 39.8M | } |
990 | | |
991 | | /// Returns the address space of the pointer operand. |
992 | 7.14M | unsigned getPointerAddressSpace() const { |
993 | 7.14M | return getPointerOperandType()->getPointerAddressSpace(); |
994 | 7.14M | } |
995 | | |
996 | | /// Returns the pointer type returned by the GEP |
997 | | /// instruction, which may be a vector of pointers. |
998 | 47 | static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) { |
999 | 47 | return getGEPReturnType( |
1000 | 47 | cast<PointerType>(Ptr->getType()->getScalarType())->getElementType(), |
1001 | 47 | Ptr, IdxList); |
1002 | 47 | } |
1003 | | static Type *getGEPReturnType(Type *ElTy, Value *Ptr, |
1004 | 6.40M | ArrayRef<Value *> IdxList) { |
1005 | 6.40M | Type *PtrTy = PointerType::get(checkGEPType(getIndexedType(ElTy, IdxList)), |
1006 | 6.40M | Ptr->getType()->getPointerAddressSpace()); |
1007 | 6.40M | // Vector GEP |
1008 | 6.40M | if (Ptr->getType()->isVectorTy()6.40M ) { |
1009 | 244 | unsigned NumElem = Ptr->getType()->getVectorNumElements(); |
1010 | 244 | return VectorType::get(PtrTy, NumElem); |
1011 | 244 | } |
1012 | 6.40M | for (Value *Index : IdxList) |
1013 | 13.5M | if (13.5M Index->getType()->isVectorTy()13.5M ) { |
1014 | 142 | unsigned NumElem = Index->getType()->getVectorNumElements(); |
1015 | 142 | return VectorType::get(PtrTy, NumElem); |
1016 | 142 | } |
1017 | 6.40M | // Scalar GEP |
1018 | 6.40M | return PtrTy; |
1019 | 6.40M | } |
1020 | | |
1021 | 28.7M | unsigned getNumIndices() const { // Note: always non-negative |
1022 | 28.7M | return getNumOperands() - 1; |
1023 | 28.7M | } |
1024 | | |
1025 | 0 | bool hasIndices() const { |
1026 | 0 | return getNumOperands() > 1; |
1027 | 0 | } |
1028 | | |
1029 | | /// Return true if all of the indices of this GEP are |
1030 | | /// zeros. If so, the result pointer and the first operand have the same |
1031 | | /// value, just potentially different types. |
1032 | | bool hasAllZeroIndices() const; |
1033 | | |
1034 | | /// Return true if all of the indices of this GEP are |
1035 | | /// constant integers. If so, the result pointer and the first operand have |
1036 | | /// a constant offset between them. |
1037 | | bool hasAllConstantIndices() const; |
1038 | | |
1039 | | /// Set or clear the inbounds flag on this GEP instruction. |
1040 | | /// See LangRef.html for the meaning of inbounds on a getelementptr. |
1041 | | void setIsInBounds(bool b = true); |
1042 | | |
1043 | | /// Determine whether the GEP has the inbounds flag. |
1044 | | bool isInBounds() const; |
1045 | | |
1046 | | /// Accumulate the constant address offset of this GEP if possible. |
1047 | | /// |
1048 | | /// This routine accepts an APInt into which it will accumulate the constant |
1049 | | /// offset of this GEP if the GEP is in fact constant. If the GEP is not |
1050 | | /// all-constant, it returns false and the value of the offset APInt is |
1051 | | /// undefined (it is *not* preserved!). The APInt passed into this routine |
1052 | | /// must be at least as wide as the IntPtr type for the address space of |
1053 | | /// the base GEP pointer. |
1054 | | bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const; |
1055 | | |
1056 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
1057 | 634M | static bool classof(const Instruction *I) { |
1058 | 634M | return (I->getOpcode() == Instruction::GetElementPtr); |
1059 | 634M | } |
1060 | 604M | static bool classof(const Value *V) { |
1061 | 490M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
1062 | 604M | } |
1063 | | }; |
1064 | | |
1065 | | template <> |
1066 | | struct OperandTraits<GetElementPtrInst> : |
1067 | | public VariadicOperandTraits<GetElementPtrInst, 1> { |
1068 | | }; |
1069 | | |
1070 | | GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr, |
1071 | | ArrayRef<Value *> IdxList, unsigned Values, |
1072 | | const Twine &NameStr, |
1073 | | Instruction *InsertBefore) |
1074 | | : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr, |
1075 | | OperandTraits<GetElementPtrInst>::op_end(this) - Values, |
1076 | | Values, InsertBefore), |
1077 | | SourceElementType(PointeeType), |
1078 | 6.40M | ResultElementType(getIndexedType(PointeeType, IdxList)) { |
1079 | 6.40M | assert(ResultElementType == |
1080 | 6.40M | cast<PointerType>(getType()->getScalarType())->getElementType()); |
1081 | 6.40M | init(Ptr, IdxList, NameStr); |
1082 | 6.40M | } |
1083 | | |
1084 | | GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr, |
1085 | | ArrayRef<Value *> IdxList, unsigned Values, |
1086 | | const Twine &NameStr, |
1087 | | BasicBlock *InsertAtEnd) |
1088 | | : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr, |
1089 | | OperandTraits<GetElementPtrInst>::op_end(this) - Values, |
1090 | | Values, InsertAtEnd), |
1091 | | SourceElementType(PointeeType), |
1092 | | ResultElementType(getIndexedType(PointeeType, IdxList)) { |
1093 | | assert(ResultElementType == |
1094 | | cast<PointerType>(getType()->getScalarType())->getElementType()); |
1095 | | init(Ptr, IdxList, NameStr); |
1096 | | } |
1097 | | |
1098 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value) |
1099 | | |
1100 | | //===----------------------------------------------------------------------===// |
1101 | | // ICmpInst Class |
1102 | | //===----------------------------------------------------------------------===// |
1103 | | |
1104 | | /// This instruction compares its operands according to the predicate given |
1105 | | /// to the constructor. It only operates on integers or pointers. The operands |
1106 | | /// must be identical types. |
1107 | | /// Represent an integer comparison operator. |
1108 | | class ICmpInst: public CmpInst { |
1109 | 0 | void AssertOK() { |
1110 | 0 | assert(isIntPredicate() && |
1111 | 0 | "Invalid ICmp predicate value"); |
1112 | 0 | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
1113 | 0 | "Both operands to ICmp instruction are not of the same type!"); |
1114 | 0 | // Check that the operands are the right type |
1115 | 0 | assert((getOperand(0)->getType()->isIntOrIntVectorTy() || |
1116 | 0 | getOperand(0)->getType()->isPtrOrPtrVectorTy()) && |
1117 | 0 | "Invalid operand types for ICmp instruction"); |
1118 | 0 | } |
1119 | | |
1120 | | protected: |
1121 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
1122 | | friend class Instruction; |
1123 | | |
1124 | | /// Clone an identical ICmpInst |
1125 | | ICmpInst *cloneImpl() const; |
1126 | | |
1127 | | public: |
1128 | | /// Constructor with insert-before-instruction semantics. |
1129 | | ICmpInst( |
1130 | | Instruction *InsertBefore, ///< Where to insert |
1131 | | Predicate pred, ///< The predicate to use for the comparison |
1132 | | Value *LHS, ///< The left-hand-side of the expression |
1133 | | Value *RHS, ///< The right-hand-side of the expression |
1134 | | const Twine &NameStr = "" ///< Name of the instruction |
1135 | | ) : CmpInst(makeCmpResultType(LHS->getType()), |
1136 | | Instruction::ICmp, pred, LHS, RHS, NameStr, |
1137 | 100k | InsertBefore) { |
1138 | | #ifndef NDEBUG |
1139 | | AssertOK(); |
1140 | | #endif |
1141 | | } |
1142 | | |
1143 | | /// Constructor with insert-at-end semantics. |
1144 | | ICmpInst( |
1145 | | BasicBlock &InsertAtEnd, ///< Block to insert into. |
1146 | | Predicate pred, ///< The predicate to use for the comparison |
1147 | | Value *LHS, ///< The left-hand-side of the expression |
1148 | | Value *RHS, ///< The right-hand-side of the expression |
1149 | | const Twine &NameStr = "" ///< Name of the instruction |
1150 | | ) : CmpInst(makeCmpResultType(LHS->getType()), |
1151 | | Instruction::ICmp, pred, LHS, RHS, NameStr, |
1152 | 72 | &InsertAtEnd) { |
1153 | | #ifndef NDEBUG |
1154 | | AssertOK(); |
1155 | | #endif |
1156 | | } |
1157 | | |
1158 | | /// Constructor with no-insertion semantics |
1159 | | ICmpInst( |
1160 | | Predicate pred, ///< The predicate to use for the comparison |
1161 | | Value *LHS, ///< The left-hand-side of the expression |
1162 | | Value *RHS, ///< The right-hand-side of the expression |
1163 | | const Twine &NameStr = "" ///< Name of the instruction |
1164 | | ) : CmpInst(makeCmpResultType(LHS->getType()), |
1165 | 3.32M | Instruction::ICmp, pred, LHS, RHS, NameStr) { |
1166 | | #ifndef NDEBUG |
1167 | | AssertOK(); |
1168 | | #endif |
1169 | | } |
1170 | | |
1171 | | /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc. |
1172 | | /// @returns the predicate that would be the result if the operand were |
1173 | | /// regarded as signed. |
1174 | | /// Return the signed version of the predicate |
1175 | 8 | Predicate getSignedPredicate() const { |
1176 | 8 | return getSignedPredicate(getPredicate()); |
1177 | 8 | } |
1178 | | |
1179 | | /// This is a static version that you can use without an instruction. |
1180 | | /// Return the signed version of the predicate. |
1181 | | static Predicate getSignedPredicate(Predicate pred); |
1182 | | |
1183 | | /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc. |
1184 | | /// @returns the predicate that would be the result if the operand were |
1185 | | /// regarded as unsigned. |
1186 | | /// Return the unsigned version of the predicate |
1187 | 16.5k | Predicate getUnsignedPredicate() const { |
1188 | 16.5k | return getUnsignedPredicate(getPredicate()); |
1189 | 16.5k | } |
1190 | | |
1191 | | /// This is a static version that you can use without an instruction. |
1192 | | /// Return the unsigned version of the predicate. |
1193 | | static Predicate getUnsignedPredicate(Predicate pred); |
1194 | | |
1195 | | /// Return true if this predicate is either EQ or NE. This also |
1196 | | /// tests for commutativity. |
1197 | 205M | static bool isEquality(Predicate P) { |
1198 | 96.0M | return P == ICMP_EQ || P == ICMP_NE; |
1199 | 205M | } |
1200 | | |
1201 | | /// Return true if this predicate is either EQ or NE. This also |
1202 | | /// tests for commutativity. |
1203 | 127M | bool isEquality() const { |
1204 | 127M | return isEquality(getPredicate()); |
1205 | 127M | } |
1206 | | |
1207 | | /// @returns true if the predicate of this ICmpInst is commutative |
1208 | | /// Determine if this relation is commutative. |
1209 | 0 | bool isCommutative() const { return isEquality(); } |
1210 | | |
1211 | | /// Return true if the predicate is relational (not EQ or NE). |
1212 | | /// |
1213 | 13.1k | bool isRelational() const { |
1214 | 13.1k | return !isEquality(); |
1215 | 13.1k | } |
1216 | | |
1217 | | /// Return true if the predicate is relational (not EQ or NE). |
1218 | | /// |
1219 | 3.92M | static bool isRelational(Predicate P) { |
1220 | 3.92M | return !isEquality(P); |
1221 | 3.92M | } |
1222 | | |
1223 | | /// Exchange the two operands to this instruction in such a way that it does |
1224 | | /// not modify the semantics of the instruction. The predicate value may be |
1225 | | /// changed to retain the same result if the predicate is order dependent |
1226 | | /// (e.g. ult). |
1227 | | /// Swap operands and adjust predicate. |
1228 | 64.2k | void swapOperands() { |
1229 | 64.2k | setPredicate(getSwappedPredicate()); |
1230 | 64.2k | Op<0>().swap(Op<1>()); |
1231 | 64.2k | } |
1232 | | |
1233 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
1234 | 390M | static bool classof(const Instruction *I) { |
1235 | 390M | return I->getOpcode() == Instruction::ICmp; |
1236 | 390M | } |
1237 | 312M | static bool classof(const Value *V) { |
1238 | 305M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
1239 | 312M | } |
1240 | | }; |
1241 | | |
1242 | | //===----------------------------------------------------------------------===// |
1243 | | // FCmpInst Class |
1244 | | //===----------------------------------------------------------------------===// |
1245 | | |
1246 | | /// This instruction compares its operands according to the predicate given |
1247 | | /// to the constructor. It only operates on floating point values or packed |
1248 | | /// vectors of floating point values. The operands must be identical types. |
1249 | | /// Represents a floating point comparison operator. |
1250 | | class FCmpInst: public CmpInst { |
1251 | 54.0k | void AssertOK() { |
1252 | 54.0k | assert(isFPPredicate() && "Invalid FCmp predicate value"); |
1253 | 54.0k | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
1254 | 54.0k | "Both operands to FCmp instruction are not of the same type!"); |
1255 | 54.0k | // Check that the operands are the right type |
1256 | 54.0k | assert(getOperand(0)->getType()->isFPOrFPVectorTy() && |
1257 | 54.0k | "Invalid operand types for FCmp instruction"); |
1258 | 54.0k | } |
1259 | | |
1260 | | protected: |
1261 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
1262 | | friend class Instruction; |
1263 | | |
1264 | | /// Clone an identical FCmpInst |
1265 | | FCmpInst *cloneImpl() const; |
1266 | | |
1267 | | public: |
1268 | | /// Constructor with insert-before-instruction semantics. |
1269 | | FCmpInst( |
1270 | | Instruction *InsertBefore, ///< Where to insert |
1271 | | Predicate pred, ///< The predicate to use for the comparison |
1272 | | Value *LHS, ///< The left-hand-side of the expression |
1273 | | Value *RHS, ///< The right-hand-side of the expression |
1274 | | const Twine &NameStr = "" ///< Name of the instruction |
1275 | | ) : CmpInst(makeCmpResultType(LHS->getType()), |
1276 | | Instruction::FCmp, pred, LHS, RHS, NameStr, |
1277 | 732 | InsertBefore) { |
1278 | 732 | AssertOK(); |
1279 | 732 | } |
1280 | | |
1281 | | /// Constructor with insert-at-end semantics. |
1282 | | FCmpInst( |
1283 | | BasicBlock &InsertAtEnd, ///< Block to insert into. |
1284 | | Predicate pred, ///< The predicate to use for the comparison |
1285 | | Value *LHS, ///< The left-hand-side of the expression |
1286 | | Value *RHS, ///< The right-hand-side of the expression |
1287 | | const Twine &NameStr = "" ///< Name of the instruction |
1288 | | ) : CmpInst(makeCmpResultType(LHS->getType()), |
1289 | | Instruction::FCmp, pred, LHS, RHS, NameStr, |
1290 | 0 | &InsertAtEnd) { |
1291 | 0 | AssertOK(); |
1292 | 0 | } |
1293 | | |
1294 | | /// Constructor with no-insertion semantics |
1295 | | FCmpInst( |
1296 | | Predicate pred, ///< The predicate to use for the comparison |
1297 | | Value *LHS, ///< The left-hand-side of the expression |
1298 | | Value *RHS, ///< The right-hand-side of the expression |
1299 | | const Twine &NameStr = "" ///< Name of the instruction |
1300 | | ) : CmpInst(makeCmpResultType(LHS->getType()), |
1301 | 53.3k | Instruction::FCmp, pred, LHS, RHS, NameStr) { |
1302 | 53.3k | AssertOK(); |
1303 | 53.3k | } |
1304 | | |
1305 | | /// @returns true if the predicate of this instruction is EQ or NE. |
1306 | | /// Determine if this is an equality predicate. |
1307 | 142k | static bool isEquality(Predicate Pred) { |
1308 | 142k | return Pred == FCMP_OEQ || Pred == FCMP_ONE135k || Pred == FCMP_UEQ134k || |
1309 | 134k | Pred == FCMP_UNE; |
1310 | 142k | } |
1311 | | |
1312 | | /// @returns true if the predicate of this instruction is EQ or NE. |
1313 | | /// Determine if this is an equality predicate. |
1314 | 142k | bool isEquality() const { return isEquality(getPredicate()); } |
1315 | | |
1316 | | /// @returns true if the predicate of this instruction is commutative. |
1317 | | /// Determine if this is a commutative predicate. |
1318 | 0 | bool isCommutative() const { |
1319 | 0 | return isEquality() || |
1320 | 0 | getPredicate() == FCMP_FALSE || |
1321 | 0 | getPredicate() == FCMP_TRUE || |
1322 | 0 | getPredicate() == FCMP_ORD || |
1323 | 0 | getPredicate() == FCMP_UNO; |
1324 | 0 | } |
1325 | | |
1326 | | /// @returns true if the predicate is relational (not EQ or NE). |
1327 | | /// Determine if this a relational predicate. |
1328 | 0 | bool isRelational() const { return !isEquality(); } |
1329 | | |
1330 | | /// Exchange the two operands to this instruction in such a way that it does |
1331 | | /// not modify the semantics of the instruction. The predicate value may be |
1332 | | /// changed to retain the same result if the predicate is order dependent |
1333 | | /// (e.g. ult). |
1334 | | /// Swap operands and adjust predicate. |
1335 | 3.28k | void swapOperands() { |
1336 | 3.28k | setPredicate(getSwappedPredicate()); |
1337 | 3.28k | Op<0>().swap(Op<1>()); |
1338 | 3.28k | } |
1339 | | |
1340 | | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
1341 | 13.5M | static bool classof(const Instruction *I) { |
1342 | 13.5M | return I->getOpcode() == Instruction::FCmp; |
1343 | 13.5M | } |
1344 | 12.8M | static bool classof(const Value *V) { |
1345 | 12.8M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
1346 | 12.8M | } |
1347 | | }; |
1348 | | |
1349 | | //===----------------------------------------------------------------------===// |
1350 | | /// This class represents a function call, abstracting a target |
1351 | | /// machine's calling convention. This class uses low bit of the SubClassData |
1352 | | /// field to indicate whether or not this is a tail call. The rest of the bits |
1353 | | /// hold the calling convention of the call. |
1354 | | /// |
1355 | | class CallInst : public Instruction, |
1356 | | public OperandBundleUser<CallInst, User::op_iterator> { |
1357 | | friend class OperandBundleUser<CallInst, User::op_iterator>; |
1358 | | |
1359 | | AttributeList Attrs; ///< parameter attributes for call |
1360 | | FunctionType *FTy; |
1361 | | |
1362 | | CallInst(const CallInst &CI); |
1363 | | |
1364 | | /// Construct a CallInst given a range of arguments. |
1365 | | /// Construct a CallInst from a range of arguments |
1366 | | inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args, |
1367 | | ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr, |
1368 | | Instruction *InsertBefore); |
1369 | | |
1370 | | inline CallInst(Value *Func, ArrayRef<Value *> Args, |
1371 | | ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr, |
1372 | | Instruction *InsertBefore) |
1373 | | : CallInst(cast<FunctionType>( |
1374 | | cast<PointerType>(Func->getType())->getElementType()), |
1375 | 0 | Func, Args, Bundles, NameStr, InsertBefore) {} |
1376 | | |
1377 | | inline CallInst(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr, |
1378 | | Instruction *InsertBefore) |
1379 | 0 | : CallInst(Func, Args, None, NameStr, InsertBefore) {} |
1380 | | |
1381 | | /// Construct a CallInst given a range of arguments. |
1382 | | /// Construct a CallInst from a range of arguments |
1383 | | inline CallInst(Value *Func, ArrayRef<Value *> Args, |
1384 | | ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr, |
1385 | | BasicBlock *InsertAtEnd); |
1386 | | |
1387 | | explicit CallInst(Value *F, const Twine &NameStr, |
1388 | | Instruction *InsertBefore); |
1389 | | |
1390 | | CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd); |
1391 | | |
1392 | | void init(Value *Func, ArrayRef<Value *> Args, |
1393 | 6.07k | ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr) { |
1394 | 6.07k | init(cast<FunctionType>( |
1395 | 6.07k | cast<PointerType>(Func->getType())->getElementType()), |
1396 | 6.07k | Func, Args, Bundles, NameStr); |
1397 | 6.07k | } |
1398 | | void init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args, |
1399 | | ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr); |
1400 | | void init(Value *Func, const Twine &NameStr); |
1401 | | |
1402 | 1.02G | bool hasDescriptor() const { return HasDescriptor; } |
1403 | | |
1404 | | protected: |
1405 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
1406 | | friend class Instruction; |
1407 | | |
1408 | | CallInst *cloneImpl() const; |
1409 | | |
1410 | | public: |
1411 | | static CallInst *Create(Value *Func, ArrayRef<Value *> Args, |
1412 | | ArrayRef<OperandBundleDef> Bundles = None, |
1413 | | const Twine &NameStr = "", |
1414 | 581k | Instruction *InsertBefore = nullptr) { |
1415 | 581k | return Create(cast<FunctionType>( |
1416 | 581k | cast<PointerType>(Func->getType())->getElementType()), |
1417 | 581k | Func, Args, Bundles, NameStr, InsertBefore); |
1418 | 581k | } |
1419 | | |
1420 | | static CallInst *Create(Value *Func, ArrayRef<Value *> Args, |
1421 | | const Twine &NameStr, |
1422 | 605k | Instruction *InsertBefore = nullptr) { |
1423 | 605k | return Create(cast<FunctionType>( |
1424 | 605k | cast<PointerType>(Func->getType())->getElementType()), |
1425 | 605k | Func, Args, None, NameStr, InsertBefore); |
1426 | 605k | } |
1427 | | |
1428 | | static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args, |
1429 | | const Twine &NameStr, |
1430 | 0 | Instruction *InsertBefore = nullptr) { |
1431 | 0 | return new (unsigned(Args.size() + 1)) |
1432 | 0 | CallInst(Ty, Func, Args, None, NameStr, InsertBefore); |
1433 | 0 | } |
1434 | | |
1435 | | static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args, |
1436 | | ArrayRef<OperandBundleDef> Bundles = None, |
1437 | | const Twine &NameStr = "", |
1438 | 4.44M | Instruction *InsertBefore = nullptr) { |
1439 | 4.44M | const unsigned TotalOps = |
1440 | 4.44M | unsigned(Args.size()) + CountBundleInputs(Bundles) + 1; |
1441 | 4.44M | const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo); |
1442 | 4.44M | |
1443 | 4.44M | return new (TotalOps, DescriptorBytes) |
1444 | 4.44M | CallInst(Ty, Func, Args, Bundles, NameStr, InsertBefore); |
1445 | 4.44M | } |
1446 | | |
1447 | | static CallInst *Create(Value *Func, ArrayRef<Value *> Args, |
1448 | | ArrayRef<OperandBundleDef> Bundles, |
1449 | 0 | const Twine &NameStr, BasicBlock *InsertAtEnd) { |
1450 | 0 | const unsigned TotalOps = |
1451 | 0 | unsigned(Args.size()) + CountBundleInputs(Bundles) + 1; |
1452 | 0 | const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo); |
1453 | 0 |
|
1454 | 0 | return new (TotalOps, DescriptorBytes) |
1455 | 0 | CallInst(Func, Args, Bundles, NameStr, InsertAtEnd); |
1456 | 0 | } |
1457 | | |
1458 | | static CallInst *Create(Value *Func, ArrayRef<Value *> Args, |
1459 | 6.07k | const Twine &NameStr, BasicBlock *InsertAtEnd) { |
1460 | 6.07k | return new (unsigned(Args.size() + 1)) |
1461 | 6.07k | CallInst(Func, Args, None, NameStr, InsertAtEnd); |
1462 | 6.07k | } |
1463 | | |
1464 | | static CallInst *Create(Value *F, const Twine &NameStr = "", |
1465 | 747 | Instruction *InsertBefore = nullptr) { |
1466 | 747 | return new(1) CallInst(F, NameStr, InsertBefore); |
1467 | 747 | } |
1468 | | |
1469 | | static CallInst *Create(Value *F, const Twine &NameStr, |
1470 | 26 | BasicBlock *InsertAtEnd) { |
1471 | 26 | return new(1) CallInst(F, NameStr, InsertAtEnd); |
1472 | 26 | } |
1473 | | |
1474 | | /// Create a clone of \p CI with a different set of operand bundles and |
1475 | | /// insert it before \p InsertPt. |
1476 | | /// |
1477 | | /// The returned call instruction is identical \p CI in every way except that |
1478 | | /// the operand bundles for the new instruction are set to the operand bundles |
1479 | | /// in \p Bundles. |
1480 | | static CallInst *Create(CallInst *CI, ArrayRef<OperandBundleDef> Bundles, |
1481 | | Instruction *InsertPt = nullptr); |
1482 | | |
1483 | | /// Generate the IR for a call to malloc: |
1484 | | /// 1. Compute the malloc call's argument as the specified type's size, |
1485 | | /// possibly multiplied by the array size if the array size is not |
1486 | | /// constant 1. |
1487 | | /// 2. Call malloc with that argument. |
1488 | | /// 3. Bitcast the result of the malloc call to the specified type. |
1489 | | static Instruction *CreateMalloc(Instruction *InsertBefore, |
1490 | | Type *IntPtrTy, Type *AllocTy, |
1491 | | Value *AllocSize, Value *ArraySize = nullptr, |
1492 | | Function* MallocF = nullptr, |
1493 | | const Twine &Name = ""); |
1494 | | static Instruction *CreateMalloc(BasicBlock *InsertAtEnd, |
1495 | | Type *IntPtrTy, Type *AllocTy, |
1496 | | Value *AllocSize, Value *ArraySize = nullptr, |
1497 | | Function* MallocF = nullptr, |
1498 | | const Twine &Name = ""); |
1499 | | static Instruction *CreateMalloc(Instruction *InsertBefore, |
1500 | | Type *IntPtrTy, Type *AllocTy, |
1501 | | Value *AllocSize, Value *ArraySize = nullptr, |
1502 | | ArrayRef<OperandBundleDef> Bundles = None, |
1503 | | Function* MallocF = nullptr, |
1504 | | const Twine &Name = ""); |
1505 | | static Instruction *CreateMalloc(BasicBlock *InsertAtEnd, |
1506 | | Type *IntPtrTy, Type *AllocTy, |
1507 | | Value *AllocSize, Value *ArraySize = nullptr, |
1508 | | ArrayRef<OperandBundleDef> Bundles = None, |
1509 | | Function* MallocF = nullptr, |
1510 | | const Twine &Name = ""); |
1511 | | /// Generate the IR for a call to the builtin free function. |
1512 | | static Instruction *CreateFree(Value *Source, |
1513 | | Instruction *InsertBefore); |
1514 | | static Instruction *CreateFree(Value *Source, |
1515 | | BasicBlock *InsertAtEnd); |
1516 | | static Instruction *CreateFree(Value *Source, |
1517 | | ArrayRef<OperandBundleDef> Bundles, |
1518 | | Instruction *InsertBefore); |
1519 | | static Instruction *CreateFree(Value *Source, |
1520 | | ArrayRef<OperandBundleDef> Bundles, |
1521 | | BasicBlock *InsertAtEnd); |
1522 | | |
1523 | 3.82M | FunctionType *getFunctionType() const { return FTy; } |
1524 | | |
1525 | 528 | void mutateFunctionType(FunctionType *FTy) { |
1526 | 528 | mutateType(FTy->getReturnType()); |
1527 | 528 | this->FTy = FTy; |
1528 | 528 | } |
1529 | | |
1530 | | // Note that 'musttail' implies 'tail'. |
1531 | | enum TailCallKind { TCK_None = 0, TCK_Tail = 1, TCK_MustTail = 2, |
1532 | | TCK_NoTail = 3 }; |
1533 | 657k | TailCallKind getTailCallKind() const { |
1534 | 657k | return TailCallKind(getSubclassDataFromInstruction() & 3); |
1535 | 657k | } |
1536 | | |
1537 | 9.59M | bool isTailCall() const { |
1538 | 9.59M | unsigned Kind = getSubclassDataFromInstruction() & 3; |
1539 | 3.74M | return Kind == TCK_Tail || Kind == TCK_MustTail; |
1540 | 9.59M | } |
1541 | | |
1542 | 3.08M | bool isMustTailCall() const { |
1543 | 3.08M | return (getSubclassDataFromInstruction() & 3) == TCK_MustTail; |
1544 | 3.08M | } |
1545 | | |
1546 | 1.27M | bool isNoTailCall() const { |
1547 | 1.27M | return (getSubclassDataFromInstruction() & 3) == TCK_NoTail; |
1548 | 1.27M | } |
1549 | | |
1550 | 522k | void setTailCall(bool isTC = true) { |
1551 | 522k | setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) | |
1552 | 522k | unsigned(isTC ? TCK_Tail522k : TCK_None65 )); |
1553 | 522k | } |
1554 | | |
1555 | 3.04M | void setTailCallKind(TailCallKind TCK) { |
1556 | 3.04M | setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) | |
1557 | 3.04M | unsigned(TCK)); |
1558 | 3.04M | } |
1559 | | |
1560 | | /// Provide fast operand accessors |
1561 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
1562 | | |
1563 | | /// Return the number of call arguments. |
1564 | | /// |
1565 | 22.3M | unsigned getNumArgOperands() const { |
1566 | 22.3M | return getNumOperands() - getNumTotalBundleOperands() - 1; |
1567 | 22.3M | } |
1568 | | |
1569 | | /// getArgOperand/setArgOperand - Return/set the i-th call argument. |
1570 | | /// |
1571 | 249M | Value *getArgOperand(unsigned i) const { |
1572 | 249M | assert(i < getNumArgOperands() && "Out of bounds!"); |
1573 | 249M | return getOperand(i); |
1574 | 249M | } |
1575 | 7.47k | void setArgOperand(unsigned i, Value *v) { |
1576 | 7.47k | assert(i < getNumArgOperands() && "Out of bounds!"); |
1577 | 7.47k | setOperand(i, v); |
1578 | 7.47k | } |
1579 | | |
1580 | | /// Return the iterator pointing to the beginning of the argument list. |
1581 | 109M | op_iterator arg_begin() { return op_begin(); } |
1582 | | |
1583 | | /// Return the iterator pointing to the end of the argument list. |
1584 | 106M | op_iterator arg_end() { |
1585 | 106M | // [ call args ], [ operand bundles ], callee |
1586 | 106M | return op_end() - getNumTotalBundleOperands() - 1; |
1587 | 106M | } |
1588 | | |
1589 | | /// Iteration adapter for range-for loops. |
1590 | 28.0M | iterator_range<op_iterator> arg_operands() { |
1591 | 28.0M | return make_range(arg_begin(), arg_end()); |
1592 | 28.0M | } |
1593 | | |
1594 | | /// Return the iterator pointing to the beginning of the argument list. |
1595 | 20.7M | const_op_iterator arg_begin() const { return op_begin(); } |
1596 | | |
1597 | | /// Return the iterator pointing to the end of the argument list. |
1598 | 12.8M | const_op_iterator arg_end() const { |
1599 | 12.8M | // [ call args ], [ operand bundles ], callee |
1600 | 12.8M | return op_end() - getNumTotalBundleOperands() - 1; |
1601 | 12.8M | } |
1602 | | |
1603 | | /// Iteration adapter for range-for loops. |
1604 | 1.27M | iterator_range<const_op_iterator> arg_operands() const { |
1605 | 1.27M | return make_range(arg_begin(), arg_end()); |
1606 | 1.27M | } |
1607 | | |
1608 | | /// Wrappers for getting the \c Use of a call argument. |
1609 | 0 | const Use &getArgOperandUse(unsigned i) const { |
1610 | 0 | assert(i < getNumArgOperands() && "Out of bounds!"); |
1611 | 0 | return getOperandUse(i); |
1612 | 0 | } |
1613 | 9.42k | Use &getArgOperandUse(unsigned i) { |
1614 | 9.42k | assert(i < getNumArgOperands() && "Out of bounds!"); |
1615 | 9.42k | return getOperandUse(i); |
1616 | 9.42k | } |
1617 | | |
1618 | | /// If one of the arguments has the 'returned' attribute, return its |
1619 | | /// operand value. Otherwise, return nullptr. |
1620 | | Value *getReturnedArgOperand() const; |
1621 | | |
1622 | | /// getCallingConv/setCallingConv - Get or set the calling convention of this |
1623 | | /// function call. |
1624 | 53.3M | CallingConv::ID getCallingConv() const { |
1625 | 53.3M | return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2); |
1626 | 53.3M | } |
1627 | 3.53M | void setCallingConv(CallingConv::ID CC) { |
1628 | 3.53M | auto ID = static_cast<unsigned>(CC); |
1629 | 3.53M | assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention"); |
1630 | 3.53M | setInstructionSubclassData((getSubclassDataFromInstruction() & 3) | |
1631 | 3.53M | (ID << 2)); |
1632 | 3.53M | } |
1633 | | |
1634 | | /// Return the parameter attributes for this call. |
1635 | | /// |
1636 | 34.4M | AttributeList getAttributes() const { return Attrs; } |
1637 | | |
1638 | | /// Set the parameter attributes for this call. |
1639 | | /// |
1640 | 4.99M | void setAttributes(AttributeList A) { Attrs = A; } |
1641 | | |
1642 | | /// adds the attribute to the list of attributes. |
1643 | | void addAttribute(unsigned i, Attribute::AttrKind Kind); |
1644 | | |
1645 | | /// adds the attribute to the list of attributes. |
1646 | | void addAttribute(unsigned i, Attribute Attr); |
1647 | | |
1648 | | /// Adds the attribute to the indicated argument |
1649 | | void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind); |
1650 | | |
1651 | | /// Adds the attribute to the indicated argument |
1652 | | void addParamAttr(unsigned ArgNo, Attribute Attr); |
1653 | | |
1654 | | /// removes the attribute from the list of attributes. |
1655 | | void removeAttribute(unsigned i, Attribute::AttrKind Kind); |
1656 | | |
1657 | | /// removes the attribute from the list of attributes. |
1658 | | void removeAttribute(unsigned i, StringRef Kind); |
1659 | | |
1660 | | /// Removes the attribute from the given argument |
1661 | | void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind); |
1662 | | |
1663 | | /// Removes the attribute from the given argument |
1664 | | void removeParamAttr(unsigned ArgNo, StringRef Kind); |
1665 | | |
1666 | | /// adds the dereferenceable attribute to the list of attributes. |
1667 | | void addDereferenceableAttr(unsigned i, uint64_t Bytes); |
1668 | | |
1669 | | /// adds the dereferenceable_or_null attribute to the list of |
1670 | | /// attributes. |
1671 | | void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes); |
1672 | | |
1673 | | /// Determine whether this call has the given attribute. |
1674 | 498M | bool hasFnAttr(Attribute::AttrKind Kind) const { |
1675 | 498M | assert(Kind != Attribute::NoBuiltin && |
1676 | 498M | "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin"); |
1677 | 498M | return hasFnAttrImpl(Kind); |
1678 | 498M | } |
1679 | | |
1680 | | /// Determine whether this call has the given attribute. |
1681 | 28.2k | bool hasFnAttr(StringRef Kind) const { |
1682 | 28.2k | return hasFnAttrImpl(Kind); |
1683 | 28.2k | } |
1684 | | |
1685 | | /// Determine whether the return value has the given attribute. |
1686 | | bool hasRetAttr(Attribute::AttrKind Kind) const; |
1687 | | |
1688 | | /// Determine whether the argument or parameter has the given attribute. |
1689 | | bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const; |
1690 | | |
1691 | | /// Get the attribute of a given kind at a position. |
1692 | 0 | Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const { |
1693 | 0 | return getAttributes().getAttribute(i, Kind); |
1694 | 0 | } |
1695 | | |
1696 | | /// Get the attribute of a given kind at a position. |
1697 | 0 | Attribute getAttribute(unsigned i, StringRef Kind) const { |
1698 | 0 | return getAttributes().getAttribute(i, Kind); |
1699 | 0 | } |
1700 | | |
1701 | | /// Get the attribute of a given kind from a given arg |
1702 | 0 | Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const { |
1703 | 0 | assert(ArgNo < getNumArgOperands() && "Out of bounds"); |
1704 | 0 | return getAttributes().getParamAttr(ArgNo, Kind); |
1705 | 0 | } |
1706 | | |
1707 | | /// Get the attribute of a given kind from a given arg |
1708 | 0 | Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const { |
1709 | 0 | assert(ArgNo < getNumArgOperands() && "Out of bounds"); |
1710 | 0 | return getAttributes().getParamAttr(ArgNo, Kind); |
1711 | 0 | } |
1712 | | |
1713 | | /// Return true if the data operand at index \p i has the attribute \p |
1714 | | /// A. |
1715 | | /// |
1716 | | /// Data operands include call arguments and values used in operand bundles, |
1717 | | /// but does not include the callee operand. This routine dispatches to the |
1718 | | /// underlying AttributeList or the OperandBundleUser as appropriate. |
1719 | | /// |
1720 | | /// The index \p i is interpreted as |
1721 | | /// |
1722 | | /// \p i == Attribute::ReturnIndex -> the return value |
1723 | | /// \p i in [1, arg_size + 1) -> argument number (\p i - 1) |
1724 | | /// \p i in [arg_size + 1, data_operand_size + 1) -> bundle operand at index |
1725 | | /// (\p i - 1) in the operand list. |
1726 | | bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const; |
1727 | | |
1728 | | /// Extract the alignment of the return value. |
1729 | 0 | unsigned getRetAlignment() const { return Attrs.getRetAlignment(); } |
1730 | | |
1731 | | /// Extract the alignment for a call or parameter (0=unknown). |
1732 | 3.97M | unsigned getParamAlignment(unsigned ArgNo) const { |
1733 | 3.97M | return Attrs.getParamAlignment(ArgNo); |
1734 | 3.97M | } |
1735 | | |
1736 | | /// Extract the number of dereferenceable bytes for a call or |
1737 | | /// parameter (0=unknown). |
1738 | 13.4M | uint64_t getDereferenceableBytes(unsigned i) const { |
1739 | 13.4M | return Attrs.getDereferenceableBytes(i); |
1740 | 13.4M | } |
1741 | | |
1742 | | /// Extract the number of dereferenceable_or_null bytes for a call or |
1743 | | /// parameter (0=unknown). |
1744 | 211k | uint64_t getDereferenceableOrNullBytes(unsigned i) const { |
1745 | 211k | return Attrs.getDereferenceableOrNullBytes(i); |
1746 | 211k | } |
1747 | | |
1748 | | /// @brief Determine if the return value is marked with NoAlias attribute. |
1749 | 0 | bool returnDoesNotAlias() const { |
1750 | 0 | return Attrs.hasAttribute(AttributeList::ReturnIndex, Attribute::NoAlias); |
1751 | 0 | } |
1752 | | |
1753 | | /// Return true if the call should not be treated as a call to a |
1754 | | /// builtin. |
1755 | 199M | bool isNoBuiltin() const { |
1756 | 199M | return hasFnAttrImpl(Attribute::NoBuiltin) && |
1757 | 131M | !hasFnAttrImpl(Attribute::Builtin); |
1758 | 199M | } |
1759 | | |
1760 | | /// Determine if the call requires strict floating point semantics. |
1761 | 40.4M | bool isStrictFP() const { return hasFnAttr(Attribute::StrictFP); } |
1762 | | |
1763 | | /// Return true if the call should not be inlined. |
1764 | 2.95M | bool isNoInline() const { return hasFnAttr(Attribute::NoInline); } |
1765 | 0 | void setIsNoInline() { |
1766 | 0 | addAttribute(AttributeList::FunctionIndex, Attribute::NoInline); |
1767 | 0 | } |
1768 | | |
1769 | | /// Return true if the call can return twice |
1770 | 28.1k | bool canReturnTwice() const { |
1771 | 28.1k | return hasFnAttr(Attribute::ReturnsTwice); |
1772 | 28.1k | } |
1773 | 21 | void setCanReturnTwice() { |
1774 | 21 | addAttribute(AttributeList::FunctionIndex, Attribute::ReturnsTwice); |
1775 | 21 | } |
1776 | | |
1777 | | /// Determine if the call does not access memory. |
1778 | 164M | bool doesNotAccessMemory() const { |
1779 | 164M | return hasFnAttr(Attribute::ReadNone); |
1780 | 164M | } |
1781 | 2.08k | void setDoesNotAccessMemory() { |
1782 | 2.08k | addAttribute(AttributeList::FunctionIndex, Attribute::ReadNone); |
1783 | 2.08k | } |
1784 | | |
1785 | | /// Determine if the call does not access or only reads memory. |
1786 | 98.6M | bool onlyReadsMemory() const { |
1787 | 98.1M | return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly); |
1788 | 98.6M | } |
1789 | 5 | void setOnlyReadsMemory() { |
1790 | 5 | addAttribute(AttributeList::FunctionIndex, Attribute::ReadOnly); |
1791 | 5 | } |
1792 | | |
1793 | | /// Determine if the call does not access or only writes memory. |
1794 | 21.8M | bool doesNotReadMemory() const { |
1795 | 21.8M | return doesNotAccessMemory() || hasFnAttr(Attribute::WriteOnly); |
1796 | 21.8M | } |
1797 | 0 | void setDoesNotReadMemory() { |
1798 | 0 | addAttribute(AttributeList::FunctionIndex, Attribute::WriteOnly); |
1799 | 0 | } |
1800 | | |
1801 | | /// @brief Determine if the call can access memmory only using pointers based |
1802 | | /// on its arguments. |
1803 | 23.2M | bool onlyAccessesArgMemory() const { |
1804 | 23.2M | return hasFnAttr(Attribute::ArgMemOnly); |
1805 | 23.2M | } |
1806 | 0 | void setOnlyAccessesArgMemory() { |
1807 | 0 | addAttribute(AttributeList::FunctionIndex, Attribute::ArgMemOnly); |
1808 | 0 | } |
1809 | | |
1810 | | /// Determine if the call cannot return. |
1811 | 51.3M | bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); } |
1812 | 5.18k | void setDoesNotReturn() { |
1813 | 5.18k | addAttribute(AttributeList::FunctionIndex, Attribute::NoReturn); |
1814 | 5.18k | } |
1815 | | |
1816 | | /// Determine if the call cannot unwind. |
1817 | 32.3M | bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); } |
1818 | 865k | void setDoesNotThrow() { |
1819 | 865k | addAttribute(AttributeList::FunctionIndex, Attribute::NoUnwind); |
1820 | 865k | } |
1821 | | |
1822 | | /// Determine if the call cannot be duplicated. |
1823 | 6.20M | bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); } |
1824 | 30 | void setCannotDuplicate() { |
1825 | 30 | addAttribute(AttributeList::FunctionIndex, Attribute::NoDuplicate); |
1826 | 30 | } |
1827 | | |
1828 | | /// Determine if the call is convergent |
1829 | 30.6M | bool isConvergent() const { return hasFnAttr(Attribute::Convergent); } |
1830 | 2 | void setConvergent() { |
1831 | 2 | addAttribute(AttributeList::FunctionIndex, Attribute::Convergent); |
1832 | 2 | } |
1833 | 1 | void setNotConvergent() { |
1834 | 1 | removeAttribute(AttributeList::FunctionIndex, Attribute::Convergent); |
1835 | 1 | } |
1836 | | |
1837 | | /// Determine if the call returns a structure through first |
1838 | | /// pointer argument. |
1839 | | bool hasStructRetAttr() const { |
1840 | | if (getNumArgOperands() == 0) |
1841 | | return false; |
1842 | | |
1843 | | // Be friendly and also check the callee. |
1844 | | return paramHasAttr(0, Attribute::StructRet); |
1845 | | } |
1846 | | |
1847 | | /// Determine if any call argument is an aggregate passed by value. |
1848 | 0 | bool hasByValArgument() const { |
1849 | 0 | return Attrs.hasAttrSomewhere(Attribute::ByVal); |
1850 | 0 | } |
1851 | | |
1852 | | /// Return the function called, or null if this is an |
1853 | | /// indirect function invocation. |
1854 | | /// |
1855 | 1.88G | Function *getCalledFunction() const { |
1856 | 1.88G | return dyn_cast<Function>(Op<-1>()); |
1857 | 1.88G | } |
1858 | | |
1859 | | /// Get a pointer to the function that is invoked by this |
1860 | | /// instruction. |
1861 | 6.25M | const Value *getCalledValue() const { return Op<-1>(); } |
1862 | 78.0M | Value *getCalledValue() { return Op<-1>(); } |
1863 | | |
1864 | | /// Set the function called. |
1865 | 122k | void setCalledFunction(Value* Fn) { |
1866 | 122k | setCalledFunction( |
1867 | 122k | cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()), |
1868 | 122k | Fn); |
1869 | 122k | } |
1870 | 122k | void setCalledFunction(FunctionType *FTy, Value *Fn) { |
1871 | 122k | this->FTy = FTy; |
1872 | 122k | assert(FTy == cast<FunctionType>( |
1873 | 122k | cast<PointerType>(Fn->getType())->getElementType())); |
1874 | 122k | Op<-1>() = Fn; |
1875 | 122k | } |
1876 | | |
1877 | | /// Check if this call is an inline asm statement. |
1878 | 19.3M | bool isInlineAsm() const { |
1879 | 19.3M | return isa<InlineAsm>(Op<-1>()); |
1880 | 19.3M | } |
1881 | | |
1882 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
1883 | 3.84G | static bool classof(const Instruction *I) { |
1884 | 3.84G | return I->getOpcode() == Instruction::Call; |
1885 | 3.84G | } |
1886 | 2.68G | static bool classof(const Value *V) { |
1887 | 2.60G | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
1888 | 2.68G | } |
1889 | | |
1890 | | private: |
1891 | 829M | template <typename AttrKind> bool hasFnAttrImpl(AttrKind Kind) const { |
1892 | 829M | if (Attrs.hasAttribute(AttributeList::FunctionIndex, Kind)) |
1893 | 156M | return true; |
1894 | 829M | |
1895 | 829M | // Operand bundles override attributes on the called function, but don't |
1896 | 829M | // override attributes directly present on the call instruction. |
1897 | 672M | if (672M isFnAttrDisallowedByOpBundle(Kind)672M ) |
1898 | 1.32k | return false; |
1899 | 672M | |
1900 | 672M | if (const Function *672M F672M = getCalledFunction()) |
1901 | 649M | return F->getAttributes().hasAttribute(AttributeList::FunctionIndex, |
1902 | 649M | Kind); |
1903 | 22.9M | return false; |
1904 | 829M | } bool llvm::CallInst::hasFnAttrImpl<llvm::Attribute::AttrKind>(llvm::Attribute::AttrKind) const Line | Count | Source | 1891 | 829M | template <typename AttrKind> bool hasFnAttrImpl(AttrKind Kind) const { | 1892 | 829M | if (Attrs.hasAttribute(AttributeList::FunctionIndex, Kind)) | 1893 | 156M | return true; | 1894 | 829M | | 1895 | 829M | // Operand bundles override attributes on the called function, but don't | 1896 | 829M | // override attributes directly present on the call instruction. | 1897 | 672M | if (672M isFnAttrDisallowedByOpBundle(Kind)672M ) | 1898 | 1.32k | return false; | 1899 | 672M | | 1900 | 672M | if (const Function *672M F672M = getCalledFunction()) | 1901 | 649M | return F->getAttributes().hasAttribute(AttributeList::FunctionIndex, | 1902 | 649M | Kind); | 1903 | 22.9M | return false; | 1904 | 829M | } |
bool llvm::CallInst::hasFnAttrImpl<llvm::StringRef>(llvm::StringRef) const Line | Count | Source | 1891 | 28.2k | template <typename AttrKind> bool hasFnAttrImpl(AttrKind Kind) const { | 1892 | 28.2k | if (Attrs.hasAttribute(AttributeList::FunctionIndex, Kind)) | 1893 | 8 | return true; | 1894 | 28.2k | | 1895 | 28.2k | // Operand bundles override attributes on the called function, but don't | 1896 | 28.2k | // override attributes directly present on the call instruction. | 1897 | 28.2k | if (28.2k isFnAttrDisallowedByOpBundle(Kind)28.2k ) | 1898 | 0 | return false; | 1899 | 28.2k | | 1900 | 28.2k | if (const Function *28.2k F28.2k = getCalledFunction()) | 1901 | 26.7k | return F->getAttributes().hasAttribute(AttributeList::FunctionIndex, | 1902 | 26.7k | Kind); | 1903 | 1.50k | return false; | 1904 | 28.2k | } |
|
1905 | | |
1906 | | // Shadow Instruction::setInstructionSubclassData with a private forwarding |
1907 | | // method so that subclasses cannot accidentally use it. |
1908 | 7.10M | void setInstructionSubclassData(unsigned short D) { |
1909 | 7.10M | Instruction::setInstructionSubclassData(D); |
1910 | 7.10M | } |
1911 | | }; |
1912 | | |
1913 | | template <> |
1914 | | struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> { |
1915 | | }; |
1916 | | |
1917 | | CallInst::CallInst(Value *Func, ArrayRef<Value *> Args, |
1918 | | ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr, |
1919 | | BasicBlock *InsertAtEnd) |
1920 | | : Instruction( |
1921 | | cast<FunctionType>(cast<PointerType>(Func->getType()) |
1922 | | ->getElementType())->getReturnType(), |
1923 | | Instruction::Call, OperandTraits<CallInst>::op_end(this) - |
1924 | | (Args.size() + CountBundleInputs(Bundles) + 1), |
1925 | 6.07k | unsigned(Args.size() + CountBundleInputs(Bundles) + 1), InsertAtEnd) { |
1926 | 6.07k | init(Func, Args, Bundles, NameStr); |
1927 | 6.07k | } |
1928 | | |
1929 | | CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args, |
1930 | | ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr, |
1931 | | Instruction *InsertBefore) |
1932 | | : Instruction(Ty->getReturnType(), Instruction::Call, |
1933 | | OperandTraits<CallInst>::op_end(this) - |
1934 | | (Args.size() + CountBundleInputs(Bundles) + 1), |
1935 | | unsigned(Args.size() + CountBundleInputs(Bundles) + 1), |
1936 | 4.44M | InsertBefore) { |
1937 | 4.44M | init(Ty, Func, Args, Bundles, NameStr); |
1938 | 4.44M | } |
1939 | | |
1940 | | // Note: if you get compile errors about private methods then |
1941 | | // please update your code to use the high-level operand |
1942 | | // interfaces. See line 943 above. |
1943 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value) |
1944 | | |
1945 | | //===----------------------------------------------------------------------===// |
1946 | | // SelectInst Class |
1947 | | //===----------------------------------------------------------------------===// |
1948 | | |
1949 | | /// This class represents the LLVM 'select' instruction. |
1950 | | /// |
1951 | | class SelectInst : public Instruction { |
1952 | | SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr, |
1953 | | Instruction *InsertBefore) |
1954 | | : Instruction(S1->getType(), Instruction::Select, |
1955 | 238k | &Op<0>(), 3, InsertBefore) { |
1956 | 238k | init(C, S1, S2); |
1957 | 238k | setName(NameStr); |
1958 | 238k | } |
1959 | | |
1960 | | SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr, |
1961 | | BasicBlock *InsertAtEnd) |
1962 | | : Instruction(S1->getType(), Instruction::Select, |
1963 | 0 | &Op<0>(), 3, InsertAtEnd) { |
1964 | 0 | init(C, S1, S2); |
1965 | 0 | setName(NameStr); |
1966 | 0 | } |
1967 | | |
1968 | 238k | void init(Value *C, Value *S1, Value *S2) { |
1969 | 238k | assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select"); |
1970 | 238k | Op<0>() = C; |
1971 | 238k | Op<1>() = S1; |
1972 | 238k | Op<2>() = S2; |
1973 | 238k | } |
1974 | | |
1975 | | protected: |
1976 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
1977 | | friend class Instruction; |
1978 | | |
1979 | | SelectInst *cloneImpl() const; |
1980 | | |
1981 | | public: |
1982 | | static SelectInst *Create(Value *C, Value *S1, Value *S2, |
1983 | | const Twine &NameStr = "", |
1984 | | Instruction *InsertBefore = nullptr, |
1985 | 238k | Instruction *MDFrom = nullptr) { |
1986 | 238k | SelectInst *Sel = new(3) SelectInst(C, S1, S2, NameStr, InsertBefore); |
1987 | 238k | if (MDFrom) |
1988 | 1.84k | Sel->copyMetadata(*MDFrom); |
1989 | 238k | return Sel; |
1990 | 238k | } |
1991 | | |
1992 | | static SelectInst *Create(Value *C, Value *S1, Value *S2, |
1993 | | const Twine &NameStr, |
1994 | 0 | BasicBlock *InsertAtEnd) { |
1995 | 0 | return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd); |
1996 | 0 | } |
1997 | | |
1998 | 18.8k | const Value *getCondition() const { return Op<0>(); } |
1999 | 1.43M | const Value *getTrueValue() const { return Op<1>(); } |
2000 | 460k | const Value *getFalseValue() const { return Op<2>(); } |
2001 | 58.5M | Value *getCondition() { return Op<0>(); } |
2002 | 59.6M | Value *getTrueValue() { return Op<1>(); } |
2003 | 54.0M | Value *getFalseValue() { return Op<2>(); } |
2004 | | |
2005 | 15.0k | void setCondition(Value *V) { Op<0>() = V; } |
2006 | 14.9k | void setTrueValue(Value *V) { Op<1>() = V; } |
2007 | 14.9k | void setFalseValue(Value *V) { Op<2>() = V; } |
2008 | | |
2009 | | /// Return a string if the specified operands are invalid |
2010 | | /// for a select operation, otherwise return null. |
2011 | | static const char *areInvalidOperands(Value *Cond, Value *True, Value *False); |
2012 | | |
2013 | | /// Transparently provide more efficient getOperand methods. |
2014 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
2015 | | |
2016 | 0 | OtherOps getOpcode() const { |
2017 | 0 | return static_cast<OtherOps>(Instruction::getOpcode()); |
2018 | 0 | } |
2019 | | |
2020 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
2021 | 918M | static bool classof(const Instruction *I) { |
2022 | 918M | return I->getOpcode() == Instruction::Select; |
2023 | 918M | } |
2024 | 1.13G | static bool classof(const Value *V) { |
2025 | 796M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
2026 | 1.13G | } |
2027 | | }; |
2028 | | |
2029 | | template <> |
2030 | | struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> { |
2031 | | }; |
2032 | | |
2033 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value) |
2034 | | |
2035 | | //===----------------------------------------------------------------------===// |
2036 | | // VAArgInst Class |
2037 | | //===----------------------------------------------------------------------===// |
2038 | | |
2039 | | /// This class represents the va_arg llvm instruction, which returns |
2040 | | /// an argument of the specified type given a va_list and increments that list |
2041 | | /// |
2042 | | class VAArgInst : public UnaryInstruction { |
2043 | | protected: |
2044 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
2045 | | friend class Instruction; |
2046 | | |
2047 | | VAArgInst *cloneImpl() const; |
2048 | | |
2049 | | public: |
2050 | | VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "", |
2051 | | Instruction *InsertBefore = nullptr) |
2052 | 403 | : UnaryInstruction(Ty, VAArg, List, InsertBefore) { |
2053 | 403 | setName(NameStr); |
2054 | 403 | } |
2055 | | |
2056 | | VAArgInst(Value *List, Type *Ty, const Twine &NameStr, |
2057 | | BasicBlock *InsertAtEnd) |
2058 | 0 | : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) { |
2059 | 0 | setName(NameStr); |
2060 | 0 | } |
2061 | | |
2062 | 0 | Value *getPointerOperand() { return getOperand(0); } |
2063 | 650 | const Value *getPointerOperand() const { return getOperand(0); } |
2064 | 0 | static unsigned getPointerOperandIndex() { return 0U; } |
2065 | | |
2066 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
2067 | 27.8M | static bool classof(const Instruction *I) { |
2068 | 27.8M | return I->getOpcode() == VAArg; |
2069 | 27.8M | } |
2070 | 0 | static bool classof(const Value *V) { |
2071 | 0 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
2072 | 0 | } |
2073 | | }; |
2074 | | |
2075 | | //===----------------------------------------------------------------------===// |
2076 | | // ExtractElementInst Class |
2077 | | //===----------------------------------------------------------------------===// |
2078 | | |
2079 | | /// This instruction extracts a single (scalar) |
2080 | | /// element from a VectorType value |
2081 | | /// |
2082 | | class ExtractElementInst : public Instruction { |
2083 | | ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "", |
2084 | | Instruction *InsertBefore = nullptr); |
2085 | | ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr, |
2086 | | BasicBlock *InsertAtEnd); |
2087 | | |
2088 | | protected: |
2089 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
2090 | | friend class Instruction; |
2091 | | |
2092 | | ExtractElementInst *cloneImpl() const; |
2093 | | |
2094 | | public: |
2095 | | static ExtractElementInst *Create(Value *Vec, Value *Idx, |
2096 | | const Twine &NameStr = "", |
2097 | 60.2k | Instruction *InsertBefore = nullptr) { |
2098 | 60.2k | return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore); |
2099 | 60.2k | } |
2100 | | |
2101 | | static ExtractElementInst *Create(Value *Vec, Value *Idx, |
2102 | | const Twine &NameStr, |
2103 | 0 | BasicBlock *InsertAtEnd) { |
2104 | 0 | return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd); |
2105 | 0 | } |
2106 | | |
2107 | | /// Return true if an extractelement instruction can be |
2108 | | /// formed with the specified operands. |
2109 | | static bool isValidOperands(const Value *Vec, const Value *Idx); |
2110 | | |
2111 | 255k | Value *getVectorOperand() { return Op<0>(); } |
2112 | 259k | Value *getIndexOperand() { return Op<1>(); } |
2113 | 167k | const Value *getVectorOperand() const { return Op<0>(); } |
2114 | 0 | const Value *getIndexOperand() const { return Op<1>(); } |
2115 | | |
2116 | 167k | VectorType *getVectorOperandType() const { |
2117 | 167k | return cast<VectorType>(getVectorOperand()->getType()); |
2118 | 167k | } |
2119 | | |
2120 | | /// Transparently provide more efficient getOperand methods. |
2121 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
2122 | | |
2123 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
2124 | 116M | static bool classof(const Instruction *I) { |
2125 | 116M | return I->getOpcode() == Instruction::ExtractElement; |
2126 | 116M | } |
2127 | 11.0M | static bool classof(const Value *V) { |
2128 | 10.5M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
2129 | 11.0M | } |
2130 | | }; |
2131 | | |
2132 | | template <> |
2133 | | struct OperandTraits<ExtractElementInst> : |
2134 | | public FixedNumOperandTraits<ExtractElementInst, 2> { |
2135 | | }; |
2136 | | |
2137 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value) |
2138 | | |
2139 | | //===----------------------------------------------------------------------===// |
2140 | | // InsertElementInst Class |
2141 | | //===----------------------------------------------------------------------===// |
2142 | | |
2143 | | /// This instruction inserts a single (scalar) |
2144 | | /// element into a VectorType value |
2145 | | /// |
2146 | | class InsertElementInst : public Instruction { |
2147 | | InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, |
2148 | | const Twine &NameStr = "", |
2149 | | Instruction *InsertBefore = nullptr); |
2150 | | InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr, |
2151 | | BasicBlock *InsertAtEnd); |
2152 | | |
2153 | | protected: |
2154 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
2155 | | friend class Instruction; |
2156 | | |
2157 | | InsertElementInst *cloneImpl() const; |
2158 | | |
2159 | | public: |
2160 | | static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, |
2161 | | const Twine &NameStr = "", |
2162 | 77.2k | Instruction *InsertBefore = nullptr) { |
2163 | 77.2k | return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore); |
2164 | 77.2k | } |
2165 | | |
2166 | | static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, |
2167 | | const Twine &NameStr, |
2168 | 0 | BasicBlock *InsertAtEnd) { |
2169 | 0 | return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd); |
2170 | 0 | } |
2171 | | |
2172 | | /// Return true if an insertelement instruction can be |
2173 | | /// formed with the specified operands. |
2174 | | static bool isValidOperands(const Value *Vec, const Value *NewElt, |
2175 | | const Value *Idx); |
2176 | | |
2177 | | /// Overload to return most specific vector type. |
2178 | | /// |
2179 | 132k | VectorType *getType() const { |
2180 | 132k | return cast<VectorType>(Instruction::getType()); |
2181 | 132k | } |
2182 | | |
2183 | | /// Transparently provide more efficient getOperand methods. |
2184 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
2185 | | |
2186 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
2187 | 46.6M | static bool classof(const Instruction *I) { |
2188 | 46.6M | return I->getOpcode() == Instruction::InsertElement; |
2189 | 46.6M | } |
2190 | 2.74M | static bool classof(const Value *V) { |
2191 | 2.62M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
2192 | 2.74M | } |
2193 | | }; |
2194 | | |
2195 | | template <> |
2196 | | struct OperandTraits<InsertElementInst> : |
2197 | | public FixedNumOperandTraits<InsertElementInst, 3> { |
2198 | | }; |
2199 | | |
2200 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value) |
2201 | | |
2202 | | //===----------------------------------------------------------------------===// |
2203 | | // ShuffleVectorInst Class |
2204 | | //===----------------------------------------------------------------------===// |
2205 | | |
2206 | | /// This instruction constructs a fixed permutation of two |
2207 | | /// input vectors. |
2208 | | /// |
2209 | | class ShuffleVectorInst : public Instruction { |
2210 | | protected: |
2211 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
2212 | | friend class Instruction; |
2213 | | |
2214 | | ShuffleVectorInst *cloneImpl() const; |
2215 | | |
2216 | | public: |
2217 | | ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, |
2218 | | const Twine &NameStr = "", |
2219 | | Instruction *InsertBefor = nullptr); |
2220 | | ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, |
2221 | | const Twine &NameStr, BasicBlock *InsertAtEnd); |
2222 | | |
2223 | | // allocate space for exactly three operands |
2224 | 103k | void *operator new(size_t s) { |
2225 | 103k | return User::operator new(s, 3); |
2226 | 103k | } |
2227 | | |
2228 | | /// Return true if a shufflevector instruction can be |
2229 | | /// formed with the specified operands. |
2230 | | static bool isValidOperands(const Value *V1, const Value *V2, |
2231 | | const Value *Mask); |
2232 | | |
2233 | | /// Overload to return most specific vector type. |
2234 | | /// |
2235 | 1.36M | VectorType *getType() const { |
2236 | 1.36M | return cast<VectorType>(Instruction::getType()); |
2237 | 1.36M | } |
2238 | | |
2239 | | /// Transparently provide more efficient getOperand methods. |
2240 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
2241 | | |
2242 | 4.20M | Constant *getMask() const { |
2243 | 4.20M | return cast<Constant>(getOperand(2)); |
2244 | 4.20M | } |
2245 | | |
2246 | | /// Return the shuffle mask value for the specified element of the mask. |
2247 | | /// Return -1 if the element is undef. |
2248 | | static int getMaskValue(Constant *Mask, unsigned Elt); |
2249 | | |
2250 | | /// Return the shuffle mask value of this instruction for the given element |
2251 | | /// index. Return -1 if the element is undef. |
2252 | 3.37M | int getMaskValue(unsigned Elt) const { |
2253 | 3.37M | return getMaskValue(getMask(), Elt); |
2254 | 3.37M | } |
2255 | | |
2256 | | /// Convert the input shuffle mask operand to a vector of integers. Undefined |
2257 | | /// elements of the mask are returned as -1. |
2258 | | static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result); |
2259 | | |
2260 | | /// Return the mask for this instruction as a vector of integers. Undefined |
2261 | | /// elements of the mask are returned as -1. |
2262 | 353k | void getShuffleMask(SmallVectorImpl<int> &Result) const { |
2263 | 353k | return getShuffleMask(getMask(), Result); |
2264 | 353k | } |
2265 | | |
2266 | 352k | SmallVector<int, 16> getShuffleMask() const { |
2267 | 352k | SmallVector<int, 16> Mask; |
2268 | 352k | getShuffleMask(Mask); |
2269 | 352k | return Mask; |
2270 | 352k | } |
2271 | | |
2272 | | /// Change values in a shuffle permute mask assuming the two vector operands |
2273 | | /// of length InVecNumElts have swapped position. |
2274 | | static void commuteShuffleMask(MutableArrayRef<int> Mask, |
2275 | 5.32k | unsigned InVecNumElts) { |
2276 | 38.9k | for (int &Idx : Mask) { |
2277 | 38.9k | if (Idx == -1) |
2278 | 1.68k | continue; |
2279 | 37.2k | Idx = Idx < (int)InVecNumElts ? 37.2k Idx + InVecNumElts13.4k : Idx - InVecNumElts23.7k ; |
2280 | 38.9k | assert(Idx >= 0 && Idx < (int)InVecNumElts * 2 && |
2281 | 38.9k | "shufflevector mask index out of range"); |
2282 | 38.9k | } |
2283 | 5.32k | } |
2284 | | |
2285 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
2286 | 59.1M | static bool classof(const Instruction *I) { |
2287 | 59.1M | return I->getOpcode() == Instruction::ShuffleVector; |
2288 | 59.1M | } |
2289 | 21.6M | static bool classof(const Value *V) { |
2290 | 19.6M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
2291 | 21.6M | } |
2292 | | }; |
2293 | | |
2294 | | template <> |
2295 | | struct OperandTraits<ShuffleVectorInst> : |
2296 | | public FixedNumOperandTraits<ShuffleVectorInst, 3> { |
2297 | | }; |
2298 | | |
2299 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value) |
2300 | | |
2301 | | //===----------------------------------------------------------------------===// |
2302 | | // ExtractValueInst Class |
2303 | | //===----------------------------------------------------------------------===// |
2304 | | |
2305 | | /// This instruction extracts a struct member or array |
2306 | | /// element value from an aggregate value. |
2307 | | /// |
2308 | | class ExtractValueInst : public UnaryInstruction { |
2309 | | SmallVector<unsigned, 4> Indices; |
2310 | | |
2311 | | ExtractValueInst(const ExtractValueInst &EVI); |
2312 | | |
2313 | | /// Constructors - Create a extractvalue instruction with a base aggregate |
2314 | | /// value and a list of indices. The first ctor can optionally insert before |
2315 | | /// an existing instruction, the second appends the new instruction to the |
2316 | | /// specified BasicBlock. |
2317 | | inline ExtractValueInst(Value *Agg, |
2318 | | ArrayRef<unsigned> Idxs, |
2319 | | const Twine &NameStr, |
2320 | | Instruction *InsertBefore); |
2321 | | inline ExtractValueInst(Value *Agg, |
2322 | | ArrayRef<unsigned> Idxs, |
2323 | | const Twine &NameStr, BasicBlock *InsertAtEnd); |
2324 | | |
2325 | | void init(ArrayRef<unsigned> Idxs, const Twine &NameStr); |
2326 | | |
2327 | | protected: |
2328 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
2329 | | friend class Instruction; |
2330 | | |
2331 | | ExtractValueInst *cloneImpl() const; |
2332 | | |
2333 | | public: |
2334 | | static ExtractValueInst *Create(Value *Agg, |
2335 | | ArrayRef<unsigned> Idxs, |
2336 | | const Twine &NameStr = "", |
2337 | 60.5k | Instruction *InsertBefore = nullptr) { |
2338 | 60.5k | return new |
2339 | 60.5k | ExtractValueInst(Agg, Idxs, NameStr, InsertBefore); |
2340 | 60.5k | } |
2341 | | |
2342 | | static ExtractValueInst *Create(Value *Agg, |
2343 | | ArrayRef<unsigned> Idxs, |
2344 | | const Twine &NameStr, |
2345 | 0 | BasicBlock *InsertAtEnd) { |
2346 | 0 | return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd); |
2347 | 0 | } |
2348 | | |
2349 | | /// Returns the type of the element that would be extracted |
2350 | | /// with an extractvalue instruction with the specified parameters. |
2351 | | /// |
2352 | | /// Null is returned if the indices are invalid for the specified type. |
2353 | | static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs); |
2354 | | |
2355 | | using idx_iterator = const unsigned*; |
2356 | | |
2357 | 574k | inline idx_iterator idx_begin() const { return Indices.begin(); } |
2358 | 326k | inline idx_iterator idx_end() const { return Indices.end(); } |
2359 | 9.99k | inline iterator_range<idx_iterator> indices() const { |
2360 | 9.99k | return make_range(idx_begin(), idx_end()); |
2361 | 9.99k | } |
2362 | | |
2363 | 984k | Value *getAggregateOperand() { |
2364 | 984k | return getOperand(0); |
2365 | 984k | } |
2366 | 262 | const Value *getAggregateOperand() const { |
2367 | 262 | return getOperand(0); |
2368 | 262 | } |
2369 | 0 | static unsigned getAggregateOperandIndex() { |
2370 | 0 | return 0U; // get index for modifying correct operand |
2371 | 0 | } |
2372 | | |
2373 | 1.04M | ArrayRef<unsigned> getIndices() const { |
2374 | 1.04M | return Indices; |
2375 | 1.04M | } |
2376 | | |
2377 | 448k | unsigned getNumIndices() const { |
2378 | 448k | return (unsigned)Indices.size(); |
2379 | 448k | } |
2380 | | |
2381 | 410k | bool hasIndices() const { |
2382 | 410k | return true; |
2383 | 410k | } |
2384 | | |
2385 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
2386 | 89.3M | static bool classof(const Instruction *I) { |
2387 | 89.3M | return I->getOpcode() == Instruction::ExtractValue; |
2388 | 89.3M | } |
2389 | 13.8M | static bool classof(const Value *V) { |
2390 | 12.0M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
2391 | 13.8M | } |
2392 | | }; |
2393 | | |
2394 | | ExtractValueInst::ExtractValueInst(Value *Agg, |
2395 | | ArrayRef<unsigned> Idxs, |
2396 | | const Twine &NameStr, |
2397 | | Instruction *InsertBefore) |
2398 | | : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)), |
2399 | 60.5k | ExtractValue, Agg, InsertBefore) { |
2400 | 60.5k | init(Idxs, NameStr); |
2401 | 60.5k | } |
2402 | | |
2403 | | ExtractValueInst::ExtractValueInst(Value *Agg, |
2404 | | ArrayRef<unsigned> Idxs, |
2405 | | const Twine &NameStr, |
2406 | | BasicBlock *InsertAtEnd) |
2407 | | : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)), |
2408 | | ExtractValue, Agg, InsertAtEnd) { |
2409 | | init(Idxs, NameStr); |
2410 | | } |
2411 | | |
2412 | | //===----------------------------------------------------------------------===// |
2413 | | // InsertValueInst Class |
2414 | | //===----------------------------------------------------------------------===// |
2415 | | |
2416 | | /// This instruction inserts a struct field of array element |
2417 | | /// value into an aggregate value. |
2418 | | /// |
2419 | | class InsertValueInst : public Instruction { |
2420 | | SmallVector<unsigned, 4> Indices; |
2421 | | |
2422 | | InsertValueInst(const InsertValueInst &IVI); |
2423 | | |
2424 | | /// Constructors - Create a insertvalue instruction with a base aggregate |
2425 | | /// value, a value to insert, and a list of indices. The first ctor can |
2426 | | /// optionally insert before an existing instruction, the second appends |
2427 | | /// the new instruction to the specified BasicBlock. |
2428 | | inline InsertValueInst(Value *Agg, Value *Val, |
2429 | | ArrayRef<unsigned> Idxs, |
2430 | | const Twine &NameStr, |
2431 | | Instruction *InsertBefore); |
2432 | | inline InsertValueInst(Value *Agg, Value *Val, |
2433 | | ArrayRef<unsigned> Idxs, |
2434 | | const Twine &NameStr, BasicBlock *InsertAtEnd); |
2435 | | |
2436 | | /// Constructors - These two constructors are convenience methods because one |
2437 | | /// and two index insertvalue instructions are so common. |
2438 | | InsertValueInst(Value *Agg, Value *Val, unsigned Idx, |
2439 | | const Twine &NameStr = "", |
2440 | | Instruction *InsertBefore = nullptr); |
2441 | | InsertValueInst(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr, |
2442 | | BasicBlock *InsertAtEnd); |
2443 | | |
2444 | | void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs, |
2445 | | const Twine &NameStr); |
2446 | | |
2447 | | protected: |
2448 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
2449 | | friend class Instruction; |
2450 | | |
2451 | | InsertValueInst *cloneImpl() const; |
2452 | | |
2453 | | public: |
2454 | | // allocate space for exactly two operands |
2455 | 16.2k | void *operator new(size_t s) { |
2456 | 16.2k | return User::operator new(s, 2); |
2457 | 16.2k | } |
2458 | | |
2459 | | static InsertValueInst *Create(Value *Agg, Value *Val, |
2460 | | ArrayRef<unsigned> Idxs, |
2461 | | const Twine &NameStr = "", |
2462 | 14.9k | Instruction *InsertBefore = nullptr) { |
2463 | 14.9k | return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore); |
2464 | 14.9k | } |
2465 | | |
2466 | | static InsertValueInst *Create(Value *Agg, Value *Val, |
2467 | | ArrayRef<unsigned> Idxs, |
2468 | | const Twine &NameStr, |
2469 | 0 | BasicBlock *InsertAtEnd) { |
2470 | 0 | return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd); |
2471 | 0 | } |
2472 | | |
2473 | | /// Transparently provide more efficient getOperand methods. |
2474 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
2475 | | |
2476 | | using idx_iterator = const unsigned*; |
2477 | | |
2478 | 55.4k | inline idx_iterator idx_begin() const { return Indices.begin(); } |
2479 | 37.7k | inline idx_iterator idx_end() const { return Indices.end(); } |
2480 | 308 | inline iterator_range<idx_iterator> indices() const { |
2481 | 308 | return make_range(idx_begin(), idx_end()); |
2482 | 308 | } |
2483 | | |
2484 | 49.9k | Value *getAggregateOperand() { |
2485 | 49.9k | return getOperand(0); |
2486 | 49.9k | } |
2487 | 0 | const Value *getAggregateOperand() const { |
2488 | 0 | return getOperand(0); |
2489 | 0 | } |
2490 | 230 | static unsigned getAggregateOperandIndex() { |
2491 | 230 | return 0U; // get index for modifying correct operand |
2492 | 230 | } |
2493 | | |
2494 | 44.7k | Value *getInsertedValueOperand() { |
2495 | 44.7k | return getOperand(1); |
2496 | 44.7k | } |
2497 | 91 | const Value *getInsertedValueOperand() const { |
2498 | 91 | return getOperand(1); |
2499 | 91 | } |
2500 | 0 | static unsigned getInsertedValueOperandIndex() { |
2501 | 0 | return 1U; // get index for modifying correct operand |
2502 | 0 | } |
2503 | | |
2504 | 123k | ArrayRef<unsigned> getIndices() const { |
2505 | 123k | return Indices; |
2506 | 123k | } |
2507 | | |
2508 | 18.1k | unsigned getNumIndices() const { |
2509 | 18.1k | return (unsigned)Indices.size(); |
2510 | 18.1k | } |
2511 | | |
2512 | 110 | bool hasIndices() const { |
2513 | 110 | return true; |
2514 | 110 | } |
2515 | | |
2516 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
2517 | 116M | static bool classof(const Instruction *I) { |
2518 | 116M | return I->getOpcode() == Instruction::InsertValue; |
2519 | 116M | } |
2520 | 18.6M | static bool classof(const Value *V) { |
2521 | 10.1M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
2522 | 18.6M | } |
2523 | | }; |
2524 | | |
2525 | | template <> |
2526 | | struct OperandTraits<InsertValueInst> : |
2527 | | public FixedNumOperandTraits<InsertValueInst, 2> { |
2528 | | }; |
2529 | | |
2530 | | InsertValueInst::InsertValueInst(Value *Agg, |
2531 | | Value *Val, |
2532 | | ArrayRef<unsigned> Idxs, |
2533 | | const Twine &NameStr, |
2534 | | Instruction *InsertBefore) |
2535 | | : Instruction(Agg->getType(), InsertValue, |
2536 | | OperandTraits<InsertValueInst>::op_begin(this), |
2537 | 14.9k | 2, InsertBefore) { |
2538 | 14.9k | init(Agg, Val, Idxs, NameStr); |
2539 | 14.9k | } |
2540 | | |
2541 | | InsertValueInst::InsertValueInst(Value *Agg, |
2542 | | Value *Val, |
2543 | | ArrayRef<unsigned> Idxs, |
2544 | | const Twine &NameStr, |
2545 | | BasicBlock *InsertAtEnd) |
2546 | | : Instruction(Agg->getType(), InsertValue, |
2547 | | OperandTraits<InsertValueInst>::op_begin(this), |
2548 | | 2, InsertAtEnd) { |
2549 | | init(Agg, Val, Idxs, NameStr); |
2550 | | } |
2551 | | |
2552 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value) |
2553 | | |
2554 | | //===----------------------------------------------------------------------===// |
2555 | | // PHINode Class |
2556 | | //===----------------------------------------------------------------------===// |
2557 | | |
2558 | | // PHINode - The PHINode class is used to represent the magical mystical PHI |
2559 | | // node, that can not exist in nature, but can be synthesized in a computer |
2560 | | // scientist's overactive imagination. |
2561 | | // |
2562 | | class PHINode : public Instruction { |
2563 | | /// The number of operands actually allocated. NumOperands is |
2564 | | /// the number actually in use. |
2565 | | unsigned ReservedSpace; |
2566 | | |
2567 | | PHINode(const PHINode &PN); |
2568 | | |
2569 | | explicit PHINode(Type *Ty, unsigned NumReservedValues, |
2570 | | const Twine &NameStr = "", |
2571 | | Instruction *InsertBefore = nullptr) |
2572 | | : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore), |
2573 | 3.03M | ReservedSpace(NumReservedValues) { |
2574 | 3.03M | setName(NameStr); |
2575 | 3.03M | allocHungoffUses(ReservedSpace); |
2576 | 3.03M | } |
2577 | | |
2578 | | PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr, |
2579 | | BasicBlock *InsertAtEnd) |
2580 | | : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd), |
2581 | 6.55k | ReservedSpace(NumReservedValues) { |
2582 | 6.55k | setName(NameStr); |
2583 | 6.55k | allocHungoffUses(ReservedSpace); |
2584 | 6.55k | } |
2585 | | |
2586 | | protected: |
2587 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
2588 | | friend class Instruction; |
2589 | | |
2590 | | PHINode *cloneImpl() const; |
2591 | | |
2592 | | // allocHungoffUses - this is more complicated than the generic |
2593 | | // User::allocHungoffUses, because we have to allocate Uses for the incoming |
2594 | | // values and pointers to the incoming blocks, all in one allocation. |
2595 | 3.71M | void allocHungoffUses(unsigned N) { |
2596 | 3.71M | User::allocHungoffUses(N, /* IsPhi */ true); |
2597 | 3.71M | } |
2598 | | |
2599 | | public: |
2600 | | /// Constructors - NumReservedValues is a hint for the number of incoming |
2601 | | /// edges that this phi node will have (use 0 if you really have no idea). |
2602 | | static PHINode *Create(Type *Ty, unsigned NumReservedValues, |
2603 | | const Twine &NameStr = "", |
2604 | 3.03M | Instruction *InsertBefore = nullptr) { |
2605 | 3.03M | return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore); |
2606 | 3.03M | } |
2607 | | |
2608 | | static PHINode *Create(Type *Ty, unsigned NumReservedValues, |
2609 | 6.55k | const Twine &NameStr, BasicBlock *InsertAtEnd) { |
2610 | 6.55k | return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd); |
2611 | 6.55k | } |
2612 | | |
2613 | | /// Provide fast operand accessors |
2614 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
2615 | | |
2616 | | // Block iterator interface. This provides access to the list of incoming |
2617 | | // basic blocks, which parallels the list of incoming values. |
2618 | | |
2619 | | using block_iterator = BasicBlock **; |
2620 | | using const_block_iterator = BasicBlock * const *; |
2621 | | |
2622 | 47.5M | block_iterator block_begin() { |
2623 | 47.5M | Use::UserRef *ref = |
2624 | 47.5M | reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace); |
2625 | 47.5M | return reinterpret_cast<block_iterator>(ref + 1); |
2626 | 47.5M | } |
2627 | | |
2628 | 216M | const_block_iterator block_begin() const { |
2629 | 216M | const Use::UserRef *ref = |
2630 | 216M | reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace); |
2631 | 216M | return reinterpret_cast<const_block_iterator>(ref + 1); |
2632 | 216M | } |
2633 | | |
2634 | 17.2M | block_iterator block_end() { |
2635 | 17.2M | return block_begin() + getNumOperands(); |
2636 | 17.2M | } |
2637 | | |
2638 | 677k | const_block_iterator block_end() const { |
2639 | 677k | return block_begin() + getNumOperands(); |
2640 | 677k | } |
2641 | | |
2642 | 764k | iterator_range<block_iterator> blocks() { |
2643 | 764k | return make_range(block_begin(), block_end()); |
2644 | 764k | } |
2645 | | |
2646 | 0 | iterator_range<const_block_iterator> blocks() const { |
2647 | 0 | return make_range(block_begin(), block_end()); |
2648 | 0 | } |
2649 | | |
2650 | 142M | op_range incoming_values() { return operands(); } |
2651 | | |
2652 | 107M | const_op_range incoming_values() const { return operands(); } |
2653 | | |
2654 | | /// Return the number of incoming edges |
2655 | | /// |
2656 | 429M | unsigned getNumIncomingValues() const { return getNumOperands(); } |
2657 | | |
2658 | | /// Return incoming value number x |
2659 | | /// |
2660 | 820M | Value *getIncomingValue(unsigned i) const { |
2661 | 820M | return getOperand(i); |
2662 | 820M | } |
2663 | 8.65M | void setIncomingValue(unsigned i, Value *V) { |
2664 | 8.65M | assert(V && "PHI node got a null value!"); |
2665 | 8.65M | assert(getType() == V->getType() && |
2666 | 8.65M | "All operands to PHI node must be the same type as the PHI node!"); |
2667 | 8.65M | setOperand(i, V); |
2668 | 8.65M | } |
2669 | | |
2670 | 38 | static unsigned getOperandNumForIncomingValue(unsigned i) { |
2671 | 38 | return i; |
2672 | 38 | } |
2673 | | |
2674 | 191k | static unsigned getIncomingValueNumForOperand(unsigned i) { |
2675 | 191k | return i; |
2676 | 191k | } |
2677 | | |
2678 | | /// Return incoming basic block number @p i. |
2679 | | /// |
2680 | 127M | BasicBlock *getIncomingBlock(unsigned i) const { |
2681 | 127M | return block_begin()[i]; |
2682 | 127M | } |
2683 | | |
2684 | | /// Return incoming basic block corresponding |
2685 | | /// to an operand of the PHI. |
2686 | | /// |
2687 | 39.0M | BasicBlock *getIncomingBlock(const Use &U) const { |
2688 | 39.0M | assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?"); |
2689 | 39.0M | return getIncomingBlock(unsigned(&U - op_begin())); |
2690 | 39.0M | } |
2691 | | |
2692 | | /// Return incoming basic block corresponding |
2693 | | /// to value use iterator. |
2694 | | /// |
2695 | 0 | BasicBlock *getIncomingBlock(Value::const_user_iterator I) const { |
2696 | 0 | return getIncomingBlock(I.getUse()); |
2697 | 0 | } |
2698 | | |
2699 | 9.51M | void setIncomingBlock(unsigned i, BasicBlock *BB) { |
2700 | 9.51M | assert(BB && "PHI node got a null basic block!"); |
2701 | 9.51M | block_begin()[i] = BB; |
2702 | 9.51M | } |
2703 | | |
2704 | | /// Add an incoming value to the end of the PHI list |
2705 | | /// |
2706 | 7.96M | void addIncoming(Value *V, BasicBlock *BB) { |
2707 | 7.96M | if (getNumOperands() == ReservedSpace) |
2708 | 223k | growOperands(); // Get more space! |
2709 | 7.96M | // Initialize some new operands. |
2710 | 7.96M | setNumHungOffUseOperands(getNumOperands() + 1); |
2711 | 7.96M | setIncomingValue(getNumOperands() - 1, V); |
2712 | 7.96M | setIncomingBlock(getNumOperands() - 1, BB); |
2713 | 7.96M | } |
2714 | | |
2715 | | /// Remove an incoming value. This is useful if a |
2716 | | /// predecessor basic block is deleted. The value removed is returned. |
2717 | | /// |
2718 | | /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty |
2719 | | /// is true), the PHI node is destroyed and any uses of it are replaced with |
2720 | | /// dummy values. The only time there should be zero incoming values to a PHI |
2721 | | /// node is when the block is dead, so this strategy is sound. |
2722 | | /// |
2723 | | Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true); |
2724 | | |
2725 | 1.68M | Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) { |
2726 | 1.68M | int Idx = getBasicBlockIndex(BB); |
2727 | 1.68M | assert(Idx >= 0 && "Invalid basic block argument to remove!"); |
2728 | 1.68M | return removeIncomingValue(Idx, DeletePHIIfEmpty); |
2729 | 1.68M | } |
2730 | | |
2731 | | /// Return the first index of the specified basic |
2732 | | /// block in the value list for this PHI. Returns -1 if no instance. |
2733 | | /// |
2734 | 21.1M | int getBasicBlockIndex(const BasicBlock *BB) const { |
2735 | 88.4M | for (unsigned i = 0, e = getNumOperands(); i != e88.4M ; ++i67.3M ) |
2736 | 87.6M | if (87.6M block_begin()[i] == BB87.6M ) |
2737 | 20.2M | return i; |
2738 | 850k | return -1; |
2739 | 21.1M | } |
2740 | | |
2741 | 17.1M | Value *getIncomingValueForBlock(const BasicBlock *BB) const { |
2742 | 17.1M | int Idx = getBasicBlockIndex(BB); |
2743 | 17.1M | assert(Idx >= 0 && "Invalid basic block argument!"); |
2744 | 17.1M | return getIncomingValue(Idx); |
2745 | 17.1M | } |
2746 | | |
2747 | | /// If the specified PHI node always merges together the |
2748 | | /// same value, return the value, otherwise return null. |
2749 | | Value *hasConstantValue() const; |
2750 | | |
2751 | | /// Whether the specified PHI node always merges |
2752 | | /// together the same value, assuming undefs are equal to a unique |
2753 | | /// non-undef value. |
2754 | | bool hasConstantOrUndefValue() const; |
2755 | | |
2756 | | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
2757 | 1.84G | static bool classof(const Instruction *I) { |
2758 | 1.84G | return I->getOpcode() == Instruction::PHI; |
2759 | 1.84G | } |
2760 | 649M | static bool classof(const Value *V) { |
2761 | 518M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
2762 | 649M | } |
2763 | | |
2764 | | private: |
2765 | | void growOperands(); |
2766 | | }; |
2767 | | |
2768 | | template <> |
2769 | | struct OperandTraits<PHINode> : public HungoffOperandTraits<2> { |
2770 | | }; |
2771 | | |
2772 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value) |
2773 | | |
2774 | | //===----------------------------------------------------------------------===// |
2775 | | // LandingPadInst Class |
2776 | | //===----------------------------------------------------------------------===// |
2777 | | |
2778 | | //===--------------------------------------------------------------------------- |
2779 | | /// The landingpad instruction holds all of the information |
2780 | | /// necessary to generate correct exception handling. The landingpad instruction |
2781 | | /// cannot be moved from the top of a landing pad block, which itself is |
2782 | | /// accessible only from the 'unwind' edge of an invoke. This uses the |
2783 | | /// SubclassData field in Value to store whether or not the landingpad is a |
2784 | | /// cleanup. |
2785 | | /// |
2786 | | class LandingPadInst : public Instruction { |
2787 | | /// The number of operands actually allocated. NumOperands is |
2788 | | /// the number actually in use. |
2789 | | unsigned ReservedSpace; |
2790 | | |
2791 | | LandingPadInst(const LandingPadInst &LP); |
2792 | | |
2793 | | public: |
2794 | | enum ClauseType { Catch, Filter }; |
2795 | | |
2796 | | private: |
2797 | | explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues, |
2798 | | const Twine &NameStr, Instruction *InsertBefore); |
2799 | | explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues, |
2800 | | const Twine &NameStr, BasicBlock *InsertAtEnd); |
2801 | | |
2802 | | // Allocate space for exactly zero operands. |
2803 | 24.3k | void *operator new(size_t s) { |
2804 | 24.3k | return User::operator new(s); |
2805 | 24.3k | } |
2806 | | |
2807 | | void growOperands(unsigned Size); |
2808 | | void init(unsigned NumReservedValues, const Twine &NameStr); |
2809 | | |
2810 | | protected: |
2811 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
2812 | | friend class Instruction; |
2813 | | |
2814 | | LandingPadInst *cloneImpl() const; |
2815 | | |
2816 | | public: |
2817 | | /// Constructors - NumReservedClauses is a hint for the number of incoming |
2818 | | /// clauses that this landingpad will have (use 0 if you really have no idea). |
2819 | | static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses, |
2820 | | const Twine &NameStr = "", |
2821 | | Instruction *InsertBefore = nullptr); |
2822 | | static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses, |
2823 | | const Twine &NameStr, BasicBlock *InsertAtEnd); |
2824 | | |
2825 | | /// Provide fast operand accessors |
2826 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
2827 | | |
2828 | | /// Return 'true' if this landingpad instruction is a |
2829 | | /// cleanup. I.e., it should be run when unwinding even if its landing pad |
2830 | | /// doesn't catch the exception. |
2831 | 437k | bool isCleanup() const { return getSubclassDataFromInstruction() & 1; } |
2832 | | |
2833 | | /// Indicate that this landingpad instruction is a cleanup. |
2834 | 39.9k | void setCleanup(bool V) { |
2835 | 39.9k | setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | |
2836 | 39.9k | (V ? 118.3k : 021.5k )); |
2837 | 39.9k | } |
2838 | | |
2839 | | /// Add a catch or filter clause to the landing pad. |
2840 | | void addClause(Constant *ClauseVal); |
2841 | | |
2842 | | /// Get the value of the clause at index Idx. Use isCatch/isFilter to |
2843 | | /// determine what type of clause this is. |
2844 | 102k | Constant *getClause(unsigned Idx) const { |
2845 | 102k | return cast<Constant>(getOperandList()[Idx]); |
2846 | 102k | } |
2847 | | |
2848 | | /// Return 'true' if the clause and index Idx is a catch clause. |
2849 | 100k | bool isCatch(unsigned Idx) const { |
2850 | 100k | return !isa<ArrayType>(getOperandList()[Idx]->getType()); |
2851 | 100k | } |
2852 | | |
2853 | | /// Return 'true' if the clause and index Idx is a filter clause. |
2854 | 101 | bool isFilter(unsigned Idx) const { |
2855 | 101 | return isa<ArrayType>(getOperandList()[Idx]->getType()); |
2856 | 101 | } |
2857 | | |
2858 | | /// Get the number of clauses for this landing pad. |
2859 | 225k | unsigned getNumClauses() const { return getNumOperands(); } |
2860 | | |
2861 | | /// Grow the size of the operand list to accommodate the new |
2862 | | /// number of clauses. |
2863 | 3.90k | void reserveClauses(unsigned Size) { growOperands(Size); } |
2864 | | |
2865 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
2866 | 25.9M | static bool classof(const Instruction *I) { |
2867 | 25.9M | return I->getOpcode() == Instruction::LandingPad; |
2868 | 25.9M | } |
2869 | 3.24k | static bool classof(const Value *V) { |
2870 | 3.24k | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
2871 | 3.24k | } |
2872 | | }; |
2873 | | |
2874 | | template <> |
2875 | | struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<1> { |
2876 | | }; |
2877 | | |
2878 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value) |
2879 | | |
2880 | | //===----------------------------------------------------------------------===// |
2881 | | // ReturnInst Class |
2882 | | //===----------------------------------------------------------------------===// |
2883 | | |
2884 | | //===--------------------------------------------------------------------------- |
2885 | | /// Return a value (possibly void), from a function. Execution |
2886 | | /// does not continue in this function any longer. |
2887 | | /// |
2888 | | class ReturnInst : public TerminatorInst { |
2889 | | ReturnInst(const ReturnInst &RI); |
2890 | | |
2891 | | private: |
2892 | | // ReturnInst constructors: |
2893 | | // ReturnInst() - 'ret void' instruction |
2894 | | // ReturnInst( null) - 'ret void' instruction |
2895 | | // ReturnInst(Value* X) - 'ret X' instruction |
2896 | | // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I |
2897 | | // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I |
2898 | | // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B |
2899 | | // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B |
2900 | | // |
2901 | | // NOTE: If the Value* passed is of type void then the constructor behaves as |
2902 | | // if it was passed NULL. |
2903 | | explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr, |
2904 | | Instruction *InsertBefore = nullptr); |
2905 | | ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd); |
2906 | | explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd); |
2907 | | |
2908 | | protected: |
2909 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
2910 | | friend class Instruction; |
2911 | | |
2912 | | ReturnInst *cloneImpl() const; |
2913 | | |
2914 | | public: |
2915 | | static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr, |
2916 | 1.03M | Instruction *InsertBefore = nullptr) { |
2917 | 1.03M | return new(!!retVal) ReturnInst(C, retVal, InsertBefore); |
2918 | 1.03M | } |
2919 | | |
2920 | | static ReturnInst* Create(LLVMContext &C, Value *retVal, |
2921 | 195 | BasicBlock *InsertAtEnd) { |
2922 | 195 | return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd); |
2923 | 195 | } |
2924 | | |
2925 | 348 | static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) { |
2926 | 348 | return new(0) ReturnInst(C, InsertAtEnd); |
2927 | 348 | } |
2928 | | |
2929 | | /// Provide fast operand accessors |
2930 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
2931 | | |
2932 | | /// Convenience accessor. Returns null if there is no return value. |
2933 | 3.70M | Value *getReturnValue() const { |
2934 | 3.70M | return getNumOperands() != 0 ? getOperand(0)3.01M : nullptr687k ; |
2935 | 3.70M | } |
2936 | | |
2937 | 74.0M | unsigned getNumSuccessors() const { return 0; } |
2938 | | |
2939 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
2940 | 124M | static bool classof(const Instruction *I) { |
2941 | 124M | return (I->getOpcode() == Instruction::Ret); |
2942 | 124M | } |
2943 | 12.2M | static bool classof(const Value *V) { |
2944 | 10.1M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
2945 | 12.2M | } |
2946 | | |
2947 | | private: |
2948 | | friend TerminatorInst; |
2949 | | |
2950 | 0 | BasicBlock *getSuccessor(unsigned idx) const { |
2951 | 0 | llvm_unreachable("ReturnInst has no successors!"); |
2952 | 0 | } |
2953 | | |
2954 | 0 | void setSuccessor(unsigned idx, BasicBlock *B) { |
2955 | 0 | llvm_unreachable("ReturnInst has no successors!"); |
2956 | 0 | } |
2957 | | }; |
2958 | | |
2959 | | template <> |
2960 | | struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> { |
2961 | | }; |
2962 | | |
2963 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value) |
2964 | | |
2965 | | //===----------------------------------------------------------------------===// |
2966 | | // BranchInst Class |
2967 | | //===----------------------------------------------------------------------===// |
2968 | | |
2969 | | //===--------------------------------------------------------------------------- |
2970 | | /// Conditional or Unconditional Branch instruction. |
2971 | | /// |
2972 | | class BranchInst : public TerminatorInst { |
2973 | | /// Ops list - Branches are strange. The operands are ordered: |
2974 | | /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because |
2975 | | /// they don't have to check for cond/uncond branchness. These are mostly |
2976 | | /// accessed relative from op_end(). |
2977 | | BranchInst(const BranchInst &BI); |
2978 | | // BranchInst constructors (where {B, T, F} are blocks, and C is a condition): |
2979 | | // BranchInst(BB *B) - 'br B' |
2980 | | // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F' |
2981 | | // BranchInst(BB* B, Inst *I) - 'br B' insert before I |
2982 | | // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I |
2983 | | // BranchInst(BB* B, BB *I) - 'br B' insert at end |
2984 | | // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end |
2985 | | explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr); |
2986 | | BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, |
2987 | | Instruction *InsertBefore = nullptr); |
2988 | | BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd); |
2989 | | BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, |
2990 | | BasicBlock *InsertAtEnd); |
2991 | | |
2992 | | void AssertOK(); |
2993 | | |
2994 | | protected: |
2995 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
2996 | | friend class Instruction; |
2997 | | |
2998 | | BranchInst *cloneImpl() const; |
2999 | | |
3000 | | public: |
3001 | | static BranchInst *Create(BasicBlock *IfTrue, |
3002 | 2.55M | Instruction *InsertBefore = nullptr) { |
3003 | 2.55M | return new(1) BranchInst(IfTrue, InsertBefore); |
3004 | 2.55M | } |
3005 | | |
3006 | | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, |
3007 | 1.84M | Value *Cond, Instruction *InsertBefore = nullptr) { |
3008 | 1.84M | return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore); |
3009 | 1.84M | } |
3010 | | |
3011 | 2.11M | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) { |
3012 | 2.11M | return new(1) BranchInst(IfTrue, InsertAtEnd); |
3013 | 2.11M | } |
3014 | | |
3015 | | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, |
3016 | 1.37k | Value *Cond, BasicBlock *InsertAtEnd) { |
3017 | 1.37k | return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd); |
3018 | 1.37k | } |
3019 | | |
3020 | | /// Transparently provide more efficient getOperand methods. |
3021 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
3022 | | |
3023 | 283M | bool isUnconditional() const { return getNumOperands() == 1; } |
3024 | 1.59G | bool isConditional() const { return getNumOperands() == 3; } |
3025 | | |
3026 | 510M | Value *getCondition() const { |
3027 | 510M | assert(isConditional() && "Cannot get condition of an uncond branch!"); |
3028 | 510M | return Op<-3>(); |
3029 | 510M | } |
3030 | | |
3031 | 100k | void setCondition(Value *V) { |
3032 | 100k | assert(isConditional() && "Cannot set condition of unconditional branch!"); |
3033 | 100k | Op<-3>() = V; |
3034 | 100k | } |
3035 | | |
3036 | 1.15G | unsigned getNumSuccessors() const { return 1+isConditional(); } |
3037 | | |
3038 | 1.90G | BasicBlock *getSuccessor(unsigned i) const { |
3039 | 1.90G | assert(i < getNumSuccessors() && "Successor # out of range for Branch!"); |
3040 | 1.90G | return cast_or_null<BasicBlock>((&Op<-1>() - i)->get()); |
3041 | 1.90G | } |
3042 | | |
3043 | 296k | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
3044 | 296k | assert(idx < getNumSuccessors() && "Successor # out of range for Branch!"); |
3045 | 296k | *(&Op<-1>() - idx) = NewSucc; |
3046 | 296k | } |
3047 | | |
3048 | | /// Swap the successors of this branch instruction. |
3049 | | /// |
3050 | | /// Swaps the successors of the branch instruction. This also swaps any |
3051 | | /// branch weight metadata associated with the instruction so that it |
3052 | | /// continues to map correctly to each operand. |
3053 | | void swapSuccessors(); |
3054 | | |
3055 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
3056 | 688M | static bool classof(const Instruction *I) { |
3057 | 688M | return (I->getOpcode() == Instruction::Br); |
3058 | 688M | } |
3059 | 9.81M | static bool classof(const Value *V) { |
3060 | 9.81M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
3061 | 9.81M | } |
3062 | | }; |
3063 | | |
3064 | | template <> |
3065 | | struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> { |
3066 | | }; |
3067 | | |
3068 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value) |
3069 | | |
3070 | | //===----------------------------------------------------------------------===// |
3071 | | // SwitchInst Class |
3072 | | //===----------------------------------------------------------------------===// |
3073 | | |
3074 | | //===--------------------------------------------------------------------------- |
3075 | | /// Multiway switch |
3076 | | /// |
3077 | | class SwitchInst : public TerminatorInst { |
3078 | | unsigned ReservedSpace; |
3079 | | |
3080 | | // Operand[0] = Value to switch on |
3081 | | // Operand[1] = Default basic block destination |
3082 | | // Operand[2n ] = Value to match |
3083 | | // Operand[2n+1] = BasicBlock to go to on match |
3084 | | SwitchInst(const SwitchInst &SI); |
3085 | | |
3086 | | /// Create a new switch instruction, specifying a value to switch on and a |
3087 | | /// default destination. The number of additional cases can be specified here |
3088 | | /// to make memory allocation more efficient. This constructor can also |
3089 | | /// auto-insert before another instruction. |
3090 | | SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, |
3091 | | Instruction *InsertBefore); |
3092 | | |
3093 | | /// Create a new switch instruction, specifying a value to switch on and a |
3094 | | /// default destination. The number of additional cases can be specified here |
3095 | | /// to make memory allocation more efficient. This constructor also |
3096 | | /// auto-inserts at the end of the specified BasicBlock. |
3097 | | SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, |
3098 | | BasicBlock *InsertAtEnd); |
3099 | | |
3100 | | // allocate space for exactly zero operands |
3101 | 61.6k | void *operator new(size_t s) { |
3102 | 61.6k | return User::operator new(s); |
3103 | 61.6k | } |
3104 | | |
3105 | | void init(Value *Value, BasicBlock *Default, unsigned NumReserved); |
3106 | | void growOperands(); |
3107 | | |
3108 | | protected: |
3109 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
3110 | | friend class Instruction; |
3111 | | |
3112 | | SwitchInst *cloneImpl() const; |
3113 | | |
3114 | | public: |
3115 | | // -2 |
3116 | | static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1); |
3117 | | |
3118 | | template <typename CaseHandleT> class CaseIteratorImpl; |
3119 | | |
3120 | | /// A handle to a particular switch case. It exposes a convenient interface |
3121 | | /// to both the case value and the successor block. |
3122 | | /// |
3123 | | /// We define this as a template and instantiate it to form both a const and |
3124 | | /// non-const handle. |
3125 | | template <typename SwitchInstT, typename ConstantIntT, typename BasicBlockT> |
3126 | | class CaseHandleImpl { |
3127 | | // Directly befriend both const and non-const iterators. |
3128 | | friend class SwitchInst::CaseIteratorImpl< |
3129 | | CaseHandleImpl<SwitchInstT, ConstantIntT, BasicBlockT>>; |
3130 | | |
3131 | | protected: |
3132 | | // Expose the switch type we're parameterized with to the iterator. |
3133 | | using SwitchInstType = SwitchInstT; |
3134 | | |
3135 | | SwitchInstT *SI; |
3136 | | ptrdiff_t Index; |
3137 | | |
3138 | | CaseHandleImpl() = default; |
3139 | 8.13M | CaseHandleImpl(SwitchInstT *SI, ptrdiff_t Index) : SI(SI), Index(Index) {} llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst, llvm::ConstantInt, llvm::BasicBlock>::CaseHandleImpl(llvm::SwitchInst*, long) Line | Count | Source | 3139 | 7.64M | CaseHandleImpl(SwitchInstT *SI, ptrdiff_t Index) : SI(SI), Index(Index) {} |
llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst const, llvm::ConstantInt const, llvm::BasicBlock const>::CaseHandleImpl(llvm::SwitchInst const*, long) Line | Count | Source | 3139 | 488k | CaseHandleImpl(SwitchInstT *SI, ptrdiff_t Index) : SI(SI), Index(Index) {} |
|
3140 | | |
3141 | | public: |
3142 | | /// Resolves case value for current case. |
3143 | 12.4M | ConstantIntT *getCaseValue() const { |
3144 | 12.4M | assert((unsigned)Index < SI->getNumCases() && |
3145 | 12.4M | "Index out the number of cases."); |
3146 | 12.4M | return reinterpret_cast<ConstantIntT *>(SI->getOperand(2 + Index * 2)); |
3147 | 12.4M | } llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst, llvm::ConstantInt, llvm::BasicBlock>::getCaseValue() const Line | Count | Source | 3143 | 11.2M | ConstantIntT *getCaseValue() const { | 3144 | 11.2M | assert((unsigned)Index < SI->getNumCases() && | 3145 | 11.2M | "Index out the number of cases."); | 3146 | 11.2M | return reinterpret_cast<ConstantIntT *>(SI->getOperand(2 + Index * 2)); | 3147 | 11.2M | } |
llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst const, llvm::ConstantInt const, llvm::BasicBlock const>::getCaseValue() const Line | Count | Source | 3143 | 1.17M | ConstantIntT *getCaseValue() const { | 3144 | 1.17M | assert((unsigned)Index < SI->getNumCases() && | 3145 | 1.17M | "Index out the number of cases."); | 3146 | 1.17M | return reinterpret_cast<ConstantIntT *>(SI->getOperand(2 + Index * 2)); | 3147 | 1.17M | } |
|
3148 | | |
3149 | | /// Resolves successor for current case. |
3150 | 10.8M | BasicBlockT *getCaseSuccessor() const { |
3151 | 10.8M | assert(((unsigned)Index < SI->getNumCases() || |
3152 | 10.8M | (unsigned)Index == DefaultPseudoIndex) && |
3153 | 10.8M | "Index out the number of cases."); |
3154 | 10.8M | return SI->getSuccessor(getSuccessorIndex()); |
3155 | 10.8M | } llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst, llvm::ConstantInt, llvm::BasicBlock>::getCaseSuccessor() const Line | Count | Source | 3150 | 10.1M | BasicBlockT *getCaseSuccessor() const { | 3151 | 10.1M | assert(((unsigned)Index < SI->getNumCases() || | 3152 | 10.1M | (unsigned)Index == DefaultPseudoIndex) && | 3153 | 10.1M | "Index out the number of cases."); | 3154 | 10.1M | return SI->getSuccessor(getSuccessorIndex()); | 3155 | 10.1M | } |
llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst const, llvm::ConstantInt const, llvm::BasicBlock const>::getCaseSuccessor() const Line | Count | Source | 3150 | 683k | BasicBlockT *getCaseSuccessor() const { | 3151 | 683k | assert(((unsigned)Index < SI->getNumCases() || | 3152 | 683k | (unsigned)Index == DefaultPseudoIndex) && | 3153 | 683k | "Index out the number of cases."); | 3154 | 683k | return SI->getSuccessor(getSuccessorIndex()); | 3155 | 683k | } |
|
3156 | | |
3157 | | /// Returns number of current case. |
3158 | 2.10k | unsigned getCaseIndex() const { return Index; } |
3159 | | |
3160 | | /// Returns TerminatorInst's successor index for current case successor. |
3161 | 11.1M | unsigned getSuccessorIndex() const { |
3162 | 11.1M | assert(((unsigned)Index == DefaultPseudoIndex || |
3163 | 11.1M | (unsigned)Index < SI->getNumCases()) && |
3164 | 11.1M | "Index out the number of cases."); |
3165 | 11.1M | return (unsigned)Index != DefaultPseudoIndex ? Index + 111.1M : 033.1k ; |
3166 | 11.1M | } llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst const, llvm::ConstantInt const, llvm::BasicBlock const>::getSuccessorIndex() const Line | Count | Source | 3161 | 776k | unsigned getSuccessorIndex() const { | 3162 | 776k | assert(((unsigned)Index == DefaultPseudoIndex || | 3163 | 776k | (unsigned)Index < SI->getNumCases()) && | 3164 | 776k | "Index out the number of cases."); | 3165 | 776k | return (unsigned)Index != DefaultPseudoIndex ? Index + 1761k : 015.2k ; | 3166 | 776k | } |
llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst, llvm::ConstantInt, llvm::BasicBlock>::getSuccessorIndex() const Line | Count | Source | 3161 | 10.4M | unsigned getSuccessorIndex() const { | 3162 | 10.4M | assert(((unsigned)Index == DefaultPseudoIndex || | 3163 | 10.4M | (unsigned)Index < SI->getNumCases()) && | 3164 | 10.4M | "Index out the number of cases."); | 3165 | 10.4M | return (unsigned)Index != DefaultPseudoIndex ? Index + 110.3M : 017.9k ; | 3166 | 10.4M | } |
|
3167 | | |
3168 | 15.1M | bool operator==(const CaseHandleImpl &RHS) const { |
3169 | 15.1M | assert(SI == RHS.SI && "Incompatible operators."); |
3170 | 15.1M | return Index == RHS.Index; |
3171 | 15.1M | } llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst, llvm::ConstantInt, llvm::BasicBlock>::operator==(llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst, llvm::ConstantInt, llvm::BasicBlock> const&) const Line | Count | Source | 3168 | 13.2M | bool operator==(const CaseHandleImpl &RHS) const { | 3169 | 13.2M | assert(SI == RHS.SI && "Incompatible operators."); | 3170 | 13.2M | return Index == RHS.Index; | 3171 | 13.2M | } |
llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst const, llvm::ConstantInt const, llvm::BasicBlock const>::operator==(llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst const, llvm::ConstantInt const, llvm::BasicBlock const> const&) const Line | Count | Source | 3168 | 1.84M | bool operator==(const CaseHandleImpl &RHS) const { | 3169 | 1.84M | assert(SI == RHS.SI && "Incompatible operators."); | 3170 | 1.84M | return Index == RHS.Index; | 3171 | 1.84M | } |
|
3172 | | }; |
3173 | | |
3174 | | using ConstCaseHandle = |
3175 | | CaseHandleImpl<const SwitchInst, const ConstantInt, const BasicBlock>; |
3176 | | |
3177 | | class CaseHandle |
3178 | | : public CaseHandleImpl<SwitchInst, ConstantInt, BasicBlock> { |
3179 | | friend class SwitchInst::CaseIteratorImpl<CaseHandle>; |
3180 | | |
3181 | | public: |
3182 | 7.64M | CaseHandle(SwitchInst *SI, ptrdiff_t Index) : CaseHandleImpl(SI, Index) {} |
3183 | | |
3184 | | /// Sets the new value for current case. |
3185 | 274k | void setValue(ConstantInt *V) { |
3186 | 274k | assert((unsigned)Index < SI->getNumCases() && |
3187 | 274k | "Index out the number of cases."); |
3188 | 274k | SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V)); |
3189 | 274k | } |
3190 | | |
3191 | | /// Sets the new successor for current case. |
3192 | 214k | void setSuccessor(BasicBlock *S) { |
3193 | 214k | SI->setSuccessor(getSuccessorIndex(), S); |
3194 | 214k | } |
3195 | | }; |
3196 | | |
3197 | | template <typename CaseHandleT> |
3198 | | class CaseIteratorImpl |
3199 | | : public iterator_facade_base<CaseIteratorImpl<CaseHandleT>, |
3200 | | std::random_access_iterator_tag, |
3201 | | CaseHandleT> { |
3202 | | using SwitchInstT = typename CaseHandleT::SwitchInstType; |
3203 | | |
3204 | | CaseHandleT Case; |
3205 | | |
3206 | | public: |
3207 | | /// Default constructed iterator is in an invalid state until assigned to |
3208 | | /// a case for a particular switch. |
3209 | | CaseIteratorImpl() = default; |
3210 | | |
3211 | | /// Initializes case iterator for given SwitchInst and for given |
3212 | | /// case number. |
3213 | 7.92M | CaseIteratorImpl(SwitchInstT *SI, unsigned CaseNum) : Case(SI, CaseNum) {} llvm::SwitchInst::CaseIteratorImpl<llvm::SwitchInst::CaseHandle>::CaseIteratorImpl(llvm::SwitchInst*, unsigned int) Line | Count | Source | 3213 | 7.43M | CaseIteratorImpl(SwitchInstT *SI, unsigned CaseNum) : Case(SI, CaseNum) {} |
llvm::SwitchInst::CaseIteratorImpl<llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst const, llvm::ConstantInt const, llvm::BasicBlock const> >::CaseIteratorImpl(llvm::SwitchInst const*, unsigned int) Line | Count | Source | 3213 | 488k | CaseIteratorImpl(SwitchInstT *SI, unsigned CaseNum) : Case(SI, CaseNum) {} |
|
3214 | | |
3215 | | /// Initializes case iterator for given SwitchInst and for given |
3216 | | /// TerminatorInst's successor index. |
3217 | | static CaseIteratorImpl fromSuccessorIndex(SwitchInstT *SI, |
3218 | 0 | unsigned SuccessorIndex) { |
3219 | 0 | assert(SuccessorIndex < SI->getNumSuccessors() && |
3220 | 0 | "Successor index # out of range!"); |
3221 | 0 | return SuccessorIndex != 0 ? CaseIteratorImpl(SI, SuccessorIndex - 1) |
3222 | 0 | : CaseIteratorImpl(SI, DefaultPseudoIndex); |
3223 | 0 | } |
3224 | | |
3225 | | /// Support converting to the const variant. This will be a no-op for const |
3226 | | /// variant. |
3227 | | operator CaseIteratorImpl<ConstCaseHandle>() const { |
3228 | | return CaseIteratorImpl<ConstCaseHandle>(Case.SI, Case.Index); |
3229 | | } |
3230 | | |
3231 | 11.1M | CaseIteratorImpl &operator+=(ptrdiff_t N) { |
3232 | 11.1M | // Check index correctness after addition. |
3233 | 11.1M | // Note: Index == getNumCases() means end(). |
3234 | 11.1M | assert(Case.Index + N >= 0 && |
3235 | 11.1M | (unsigned)(Case.Index + N) <= Case.SI->getNumCases() && |
3236 | 11.1M | "Case.Index out the number of cases."); |
3237 | 11.1M | Case.Index += N; |
3238 | 11.1M | return *this; |
3239 | 11.1M | } llvm::SwitchInst::CaseIteratorImpl<llvm::SwitchInst::CaseHandle>::operator+=(long) Line | Count | Source | 3231 | 9.53M | CaseIteratorImpl &operator+=(ptrdiff_t N) { | 3232 | 9.53M | // Check index correctness after addition. | 3233 | 9.53M | // Note: Index == getNumCases() means end(). | 3234 | 9.53M | assert(Case.Index + N >= 0 && | 3235 | 9.53M | (unsigned)(Case.Index + N) <= Case.SI->getNumCases() && | 3236 | 9.53M | "Case.Index out the number of cases."); | 3237 | 9.53M | Case.Index += N; | 3238 | 9.53M | return *this; | 3239 | 9.53M | } |
llvm::SwitchInst::CaseIteratorImpl<llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst const, llvm::ConstantInt const, llvm::BasicBlock const> >::operator+=(long) Line | Count | Source | 3231 | 1.61M | CaseIteratorImpl &operator+=(ptrdiff_t N) { | 3232 | 1.61M | // Check index correctness after addition. | 3233 | 1.61M | // Note: Index == getNumCases() means end(). | 3234 | 1.61M | assert(Case.Index + N >= 0 && | 3235 | 1.61M | (unsigned)(Case.Index + N) <= Case.SI->getNumCases() && | 3236 | 1.61M | "Case.Index out the number of cases."); | 3237 | 1.61M | Case.Index += N; | 3238 | 1.61M | return *this; | 3239 | 1.61M | } |
|
3240 | 163 | CaseIteratorImpl &operator-=(ptrdiff_t N) { |
3241 | 163 | // Check index correctness after subtraction. |
3242 | 163 | // Note: Case.Index == getNumCases() means end(). |
3243 | 163 | assert(Case.Index - N >= 0 && |
3244 | 163 | (unsigned)(Case.Index - N) <= Case.SI->getNumCases() && |
3245 | 163 | "Case.Index out the number of cases."); |
3246 | 163 | Case.Index -= N; |
3247 | 163 | return *this; |
3248 | 163 | } |
3249 | | ptrdiff_t operator-(const CaseIteratorImpl &RHS) const { |
3250 | | assert(Case.SI == RHS.Case.SI && "Incompatible operators."); |
3251 | | return Case.Index - RHS.Case.Index; |
3252 | | } |
3253 | 15.1M | bool operator==(const CaseIteratorImpl &RHS) const { |
3254 | 15.1M | return Case == RHS.Case; |
3255 | 15.1M | } llvm::SwitchInst::CaseIteratorImpl<llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst const, llvm::ConstantInt const, llvm::BasicBlock const> >::operator==(llvm::SwitchInst::CaseIteratorImpl<llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst const, llvm::ConstantInt const, llvm::BasicBlock const> > const&) const Line | Count | Source | 3253 | 1.84M | bool operator==(const CaseIteratorImpl &RHS) const { | 3254 | 1.84M | return Case == RHS.Case; | 3255 | 1.84M | } |
llvm::SwitchInst::CaseIteratorImpl<llvm::SwitchInst::CaseHandle>::operator==(llvm::SwitchInst::CaseIteratorImpl<llvm::SwitchInst::CaseHandle> const&) const Line | Count | Source | 3253 | 13.2M | bool operator==(const CaseIteratorImpl &RHS) const { | 3254 | 13.2M | return Case == RHS.Case; | 3255 | 13.2M | } |
|
3256 | | bool operator<(const CaseIteratorImpl &RHS) const { |
3257 | | assert(Case.SI == RHS.Case.SI && "Incompatible operators."); |
3258 | | return Case.Index < RHS.Case.Index; |
3259 | | } |
3260 | 18.8M | CaseHandleT &operator*() { return Case; } llvm::SwitchInst::CaseIteratorImpl<llvm::SwitchInst::CaseHandleImpl<llvm::SwitchInst const, llvm::ConstantInt const, llvm::BasicBlock const> >::operator*() Line | Count | Source | 3260 | 1.72M | CaseHandleT &operator*() { return Case; } |
llvm::SwitchInst::CaseIteratorImpl<llvm::SwitchInst::CaseHandle>::operator*() Line | Count | Source | 3260 | 17.1M | CaseHandleT &operator*() { return Case; } |
|
3261 | | const CaseHandleT &operator*() const { return Case; } |
3262 | | }; |
3263 | | |
3264 | | using CaseIt = CaseIteratorImpl<CaseHandle>; |
3265 | | using ConstCaseIt = CaseIteratorImpl<ConstCaseHandle>; |
3266 | | |
3267 | | static SwitchInst *Create(Value *Value, BasicBlock *Default, |
3268 | | unsigned NumCases, |
3269 | 56.5k | Instruction *InsertBefore = nullptr) { |
3270 | 56.5k | return new SwitchInst(Value, Default, NumCases, InsertBefore); |
3271 | 56.5k | } |
3272 | | |
3273 | | static SwitchInst *Create(Value *Value, BasicBlock *Default, |
3274 | 107 | unsigned NumCases, BasicBlock *InsertAtEnd) { |
3275 | 107 | return new SwitchInst(Value, Default, NumCases, InsertAtEnd); |
3276 | 107 | } |
3277 | | |
3278 | | /// Provide fast operand accessors |
3279 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
3280 | | |
3281 | | // Accessor Methods for Switch stmt |
3282 | 7.55M | Value *getCondition() const { return getOperand(0); } |
3283 | 19.1k | void setCondition(Value *V) { setOperand(0, V); } |
3284 | | |
3285 | 2.66M | BasicBlock *getDefaultDest() const { |
3286 | 2.66M | return cast<BasicBlock>(getOperand(1)); |
3287 | 2.66M | } |
3288 | | |
3289 | 3.41k | void setDefaultDest(BasicBlock *DefaultCase) { |
3290 | 3.41k | setOperand(1, reinterpret_cast<Value*>(DefaultCase)); |
3291 | 3.41k | } |
3292 | | |
3293 | | /// Return the number of 'cases' in this switch instruction, excluding the |
3294 | | /// default case. |
3295 | 6.67M | unsigned getNumCases() const { |
3296 | 6.67M | return getNumOperands()/2 - 1; |
3297 | 6.67M | } |
3298 | | |
3299 | | /// Returns a read/write iterator that points to the first case in the |
3300 | | /// SwitchInst. |
3301 | 3.69M | CaseIt case_begin() { |
3302 | 3.69M | return CaseIt(this, 0); |
3303 | 3.69M | } |
3304 | | |
3305 | | /// Returns a read-only iterator that points to the first case in the |
3306 | | /// SwitchInst. |
3307 | 251k | ConstCaseIt case_begin() const { |
3308 | 251k | return ConstCaseIt(this, 0); |
3309 | 251k | } |
3310 | | |
3311 | | /// Returns a read/write iterator that points one past the last in the |
3312 | | /// SwitchInst. |
3313 | 3.72M | CaseIt case_end() { |
3314 | 3.72M | return CaseIt(this, getNumCases()); |
3315 | 3.72M | } |
3316 | | |
3317 | | /// Returns a read-only iterator that points one past the last in the |
3318 | | /// SwitchInst. |
3319 | 222k | ConstCaseIt case_end() const { |
3320 | 222k | return ConstCaseIt(this, getNumCases()); |
3321 | 222k | } |
3322 | | |
3323 | | /// Iteration adapter for range-for loops. |
3324 | 2.50M | iterator_range<CaseIt> cases() { |
3325 | 2.50M | return make_range(case_begin(), case_end()); |
3326 | 2.50M | } |
3327 | | |
3328 | | /// Constant iteration adapter for range-for loops. |
3329 | 192k | iterator_range<ConstCaseIt> cases() const { |
3330 | 192k | return make_range(case_begin(), case_end()); |
3331 | 192k | } |
3332 | | |
3333 | | /// Returns an iterator that points to the default case. |
3334 | | /// Note: this iterator allows to resolve successor only. Attempt |
3335 | | /// to resolve case value causes an assertion. |
3336 | | /// Also note, that increment and decrement also causes an assertion and |
3337 | | /// makes iterator invalid. |
3338 | 18.3k | CaseIt case_default() { |
3339 | 18.3k | return CaseIt(this, DefaultPseudoIndex); |
3340 | 18.3k | } |
3341 | 15.2k | ConstCaseIt case_default() const { |
3342 | 15.2k | return ConstCaseIt(this, DefaultPseudoIndex); |
3343 | 15.2k | } |
3344 | | |
3345 | | /// Search all of the case values for the specified constant. If it is |
3346 | | /// explicitly handled, return the case iterator of it, otherwise return |
3347 | | /// default case iterator to indicate that it is handled by the default |
3348 | | /// handler. |
3349 | 41.2k | CaseIt findCaseValue(const ConstantInt *C) { |
3350 | 41.2k | CaseIt I = llvm::find_if( |
3351 | 77.9k | cases(), [C](CaseHandle &Case) { return Case.getCaseValue() == C; }); |
3352 | 41.2k | if (I != case_end()) |
3353 | 23.1k | return I; |
3354 | 41.2k | |
3355 | 18.0k | return case_default(); |
3356 | 41.2k | } |
3357 | 30.1k | ConstCaseIt findCaseValue(const ConstantInt *C) const { |
3358 | 52.9k | ConstCaseIt I = llvm::find_if(cases(), [C](ConstCaseHandle &Case) { |
3359 | 52.9k | return Case.getCaseValue() == C; |
3360 | 52.9k | }); |
3361 | 30.1k | if (I != case_end()) |
3362 | 14.9k | return I; |
3363 | 30.1k | |
3364 | 15.2k | return case_default(); |
3365 | 30.1k | } |
3366 | | |
3367 | | /// Finds the unique case value for a given successor. Returns null if the |
3368 | | /// successor is not found, not unique, or is the default case. |
3369 | 1.14k | ConstantInt *findCaseDest(BasicBlock *BB) { |
3370 | 1.14k | if (BB == getDefaultDest()) |
3371 | 0 | return nullptr; |
3372 | 1.14k | |
3373 | 1.14k | ConstantInt *CI = nullptr; |
3374 | 4.78k | for (auto Case : cases()) { |
3375 | 4.78k | if (Case.getCaseSuccessor() != BB) |
3376 | 3.59k | continue; |
3377 | 4.78k | |
3378 | 1.19k | if (1.19k CI1.19k ) |
3379 | 51 | return nullptr; // Multiple cases lead to BB. |
3380 | 1.19k | |
3381 | 1.14k | CI = Case.getCaseValue(); |
3382 | 1.14k | } |
3383 | 1.14k | |
3384 | 1.09k | return CI; |
3385 | 1.14k | } |
3386 | | |
3387 | | /// Add an entry to the switch instruction. |
3388 | | /// Note: |
3389 | | /// This action invalidates case_end(). Old case_end() iterator will |
3390 | | /// point to the added case. |
3391 | | void addCase(ConstantInt *OnVal, BasicBlock *Dest); |
3392 | | |
3393 | | /// This method removes the specified case and its successor from the switch |
3394 | | /// instruction. Note that this operation may reorder the remaining cases at |
3395 | | /// index idx and above. |
3396 | | /// Note: |
3397 | | /// This action invalidates iterators for all cases following the one removed, |
3398 | | /// including the case_end() iterator. It returns an iterator for the next |
3399 | | /// case. |
3400 | | CaseIt removeCase(CaseIt I); |
3401 | | |
3402 | 19.0M | unsigned getNumSuccessors() const { return getNumOperands()/2; } |
3403 | 49.2M | BasicBlock *getSuccessor(unsigned idx) const { |
3404 | 49.2M | assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!"); |
3405 | 49.2M | return cast<BasicBlock>(getOperand(idx*2+1)); |
3406 | 49.2M | } |
3407 | 215k | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
3408 | 215k | assert(idx < getNumSuccessors() && "Successor # out of range for switch!"); |
3409 | 215k | setOperand(idx * 2 + 1, NewSucc); |
3410 | 215k | } |
3411 | | |
3412 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
3413 | 151M | static bool classof(const Instruction *I) { |
3414 | 151M | return I->getOpcode() == Instruction::Switch; |
3415 | 151M | } |
3416 | 91.4k | static bool classof(const Value *V) { |
3417 | 91.4k | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
3418 | 91.4k | } |
3419 | | }; |
3420 | | |
3421 | | template <> |
3422 | | struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> { |
3423 | | }; |
3424 | | |
3425 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value) |
3426 | | |
3427 | | //===----------------------------------------------------------------------===// |
3428 | | // IndirectBrInst Class |
3429 | | //===----------------------------------------------------------------------===// |
3430 | | |
3431 | | //===--------------------------------------------------------------------------- |
3432 | | /// Indirect Branch Instruction. |
3433 | | /// |
3434 | | class IndirectBrInst : public TerminatorInst { |
3435 | | unsigned ReservedSpace; |
3436 | | |
3437 | | // Operand[0] = Address to jump to |
3438 | | // Operand[n+1] = n-th destination |
3439 | | IndirectBrInst(const IndirectBrInst &IBI); |
3440 | | |
3441 | | /// Create a new indirectbr instruction, specifying an |
3442 | | /// Address to jump to. The number of expected destinations can be specified |
3443 | | /// here to make memory allocation more efficient. This constructor can also |
3444 | | /// autoinsert before another instruction. |
3445 | | IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore); |
3446 | | |
3447 | | /// Create a new indirectbr instruction, specifying an |
3448 | | /// Address to jump to. The number of expected destinations can be specified |
3449 | | /// here to make memory allocation more efficient. This constructor also |
3450 | | /// autoinserts at the end of the specified BasicBlock. |
3451 | | IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd); |
3452 | | |
3453 | | // allocate space for exactly zero operands |
3454 | 333 | void *operator new(size_t s) { |
3455 | 333 | return User::operator new(s); |
3456 | 333 | } |
3457 | | |
3458 | | void init(Value *Address, unsigned NumDests); |
3459 | | void growOperands(); |
3460 | | |
3461 | | protected: |
3462 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
3463 | | friend class Instruction; |
3464 | | |
3465 | | IndirectBrInst *cloneImpl() const; |
3466 | | |
3467 | | public: |
3468 | | static IndirectBrInst *Create(Value *Address, unsigned NumDests, |
3469 | 333 | Instruction *InsertBefore = nullptr) { |
3470 | 333 | return new IndirectBrInst(Address, NumDests, InsertBefore); |
3471 | 333 | } |
3472 | | |
3473 | | static IndirectBrInst *Create(Value *Address, unsigned NumDests, |
3474 | 0 | BasicBlock *InsertAtEnd) { |
3475 | 0 | return new IndirectBrInst(Address, NumDests, InsertAtEnd); |
3476 | 0 | } |
3477 | | |
3478 | | /// Provide fast operand accessors. |
3479 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
3480 | | |
3481 | | // Accessor Methods for IndirectBrInst instruction. |
3482 | 1.22k | Value *getAddress() { return getOperand(0); } |
3483 | 81 | const Value *getAddress() const { return getOperand(0); } |
3484 | 1 | void setAddress(Value *V) { setOperand(0, V); } |
3485 | | |
3486 | | /// return the number of possible destinations in this |
3487 | | /// indirectbr instruction. |
3488 | 887 | unsigned getNumDestinations() const { return getNumOperands()-1; } |
3489 | | |
3490 | | /// Return the specified destination. |
3491 | 3.02k | BasicBlock *getDestination(unsigned i) { return getSuccessor(i); } |
3492 | 0 | const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); } |
3493 | | |
3494 | | /// Add a destination. |
3495 | | /// |
3496 | | void addDestination(BasicBlock *Dest); |
3497 | | |
3498 | | /// This method removes the specified successor from the |
3499 | | /// indirectbr instruction. |
3500 | | void removeDestination(unsigned i); |
3501 | | |
3502 | 14.4k | unsigned getNumSuccessors() const { return getNumOperands()-1; } |
3503 | 49.4k | BasicBlock *getSuccessor(unsigned i) const { |
3504 | 49.4k | return cast<BasicBlock>(getOperand(i+1)); |
3505 | 49.4k | } |
3506 | 0 | void setSuccessor(unsigned i, BasicBlock *NewSucc) { |
3507 | 0 | setOperand(i + 1, NewSucc); |
3508 | 0 | } |
3509 | | |
3510 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
3511 | 45.4M | static bool classof(const Instruction *I) { |
3512 | 45.4M | return I->getOpcode() == Instruction::IndirectBr; |
3513 | 45.4M | } |
3514 | 0 | static bool classof(const Value *V) { |
3515 | 0 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
3516 | 0 | } |
3517 | | }; |
3518 | | |
3519 | | template <> |
3520 | | struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> { |
3521 | | }; |
3522 | | |
3523 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value) |
3524 | | |
3525 | | //===----------------------------------------------------------------------===// |
3526 | | // InvokeInst Class |
3527 | | //===----------------------------------------------------------------------===// |
3528 | | |
3529 | | /// Invoke instruction. The SubclassData field is used to hold the |
3530 | | /// calling convention of the call. |
3531 | | /// |
3532 | | class InvokeInst : public TerminatorInst, |
3533 | | public OperandBundleUser<InvokeInst, User::op_iterator> { |
3534 | | friend class OperandBundleUser<InvokeInst, User::op_iterator>; |
3535 | | |
3536 | | AttributeList Attrs; |
3537 | | FunctionType *FTy; |
3538 | | |
3539 | | InvokeInst(const InvokeInst &BI); |
3540 | | |
3541 | | /// Construct an InvokeInst given a range of arguments. |
3542 | | /// |
3543 | | /// Construct an InvokeInst from a range of arguments |
3544 | | inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
3545 | | ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles, |
3546 | | unsigned Values, const Twine &NameStr, |
3547 | | Instruction *InsertBefore) |
3548 | | : InvokeInst(cast<FunctionType>( |
3549 | | cast<PointerType>(Func->getType())->getElementType()), |
3550 | | Func, IfNormal, IfException, Args, Bundles, Values, NameStr, |
3551 | 0 | InsertBefore) {} |
3552 | | |
3553 | | inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, |
3554 | | BasicBlock *IfException, ArrayRef<Value *> Args, |
3555 | | ArrayRef<OperandBundleDef> Bundles, unsigned Values, |
3556 | | const Twine &NameStr, Instruction *InsertBefore); |
3557 | | /// Construct an InvokeInst given a range of arguments. |
3558 | | /// |
3559 | | /// Construct an InvokeInst from a range of arguments |
3560 | | inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
3561 | | ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles, |
3562 | | unsigned Values, const Twine &NameStr, |
3563 | | BasicBlock *InsertAtEnd); |
3564 | | |
3565 | 8.73M | bool hasDescriptor() const { return HasDescriptor; } |
3566 | | |
3567 | | void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
3568 | | ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles, |
3569 | 11.3k | const Twine &NameStr) { |
3570 | 11.3k | init(cast<FunctionType>( |
3571 | 11.3k | cast<PointerType>(Func->getType())->getElementType()), |
3572 | 11.3k | Func, IfNormal, IfException, Args, Bundles, NameStr); |
3573 | 11.3k | } |
3574 | | |
3575 | | void init(FunctionType *FTy, Value *Func, BasicBlock *IfNormal, |
3576 | | BasicBlock *IfException, ArrayRef<Value *> Args, |
3577 | | ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr); |
3578 | | |
3579 | | protected: |
3580 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
3581 | | friend class Instruction; |
3582 | | |
3583 | | InvokeInst *cloneImpl() const; |
3584 | | |
3585 | | public: |
3586 | | static InvokeInst *Create(Value *Func, BasicBlock *IfNormal, |
3587 | | BasicBlock *IfException, ArrayRef<Value *> Args, |
3588 | | const Twine &NameStr, |
3589 | 16 | Instruction *InsertBefore = nullptr) { |
3590 | 16 | return Create(cast<FunctionType>( |
3591 | 16 | cast<PointerType>(Func->getType())->getElementType()), |
3592 | 16 | Func, IfNormal, IfException, Args, None, NameStr, |
3593 | 16 | InsertBefore); |
3594 | 16 | } |
3595 | | |
3596 | | static InvokeInst *Create(Value *Func, BasicBlock *IfNormal, |
3597 | | BasicBlock *IfException, ArrayRef<Value *> Args, |
3598 | | ArrayRef<OperandBundleDef> Bundles = None, |
3599 | | const Twine &NameStr = "", |
3600 | 26.8k | Instruction *InsertBefore = nullptr) { |
3601 | 26.8k | return Create(cast<FunctionType>( |
3602 | 26.8k | cast<PointerType>(Func->getType())->getElementType()), |
3603 | 26.8k | Func, IfNormal, IfException, Args, Bundles, NameStr, |
3604 | 26.8k | InsertBefore); |
3605 | 26.8k | } |
3606 | | |
3607 | | static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, |
3608 | | BasicBlock *IfException, ArrayRef<Value *> Args, |
3609 | | const Twine &NameStr, |
3610 | 0 | Instruction *InsertBefore = nullptr) { |
3611 | 0 | unsigned Values = unsigned(Args.size()) + 3; |
3612 | 0 | return new (Values) InvokeInst(Ty, Func, IfNormal, IfException, Args, None, |
3613 | 0 | Values, NameStr, InsertBefore); |
3614 | 0 | } |
3615 | | |
3616 | | static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, |
3617 | | BasicBlock *IfException, ArrayRef<Value *> Args, |
3618 | | ArrayRef<OperandBundleDef> Bundles = None, |
3619 | | const Twine &NameStr = "", |
3620 | 28.6k | Instruction *InsertBefore = nullptr) { |
3621 | 28.6k | unsigned Values = unsigned(Args.size()) + CountBundleInputs(Bundles) + 3; |
3622 | 28.6k | unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo); |
3623 | 28.6k | |
3624 | 28.6k | return new (Values, DescriptorBytes) |
3625 | 28.6k | InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, Values, |
3626 | 28.6k | NameStr, InsertBefore); |
3627 | 28.6k | } |
3628 | | |
3629 | | static InvokeInst *Create(Value *Func, |
3630 | | BasicBlock *IfNormal, BasicBlock *IfException, |
3631 | | ArrayRef<Value *> Args, const Twine &NameStr, |
3632 | 13 | BasicBlock *InsertAtEnd) { |
3633 | 13 | unsigned Values = unsigned(Args.size()) + 3; |
3634 | 13 | return new (Values) InvokeInst(Func, IfNormal, IfException, Args, None, |
3635 | 13 | Values, NameStr, InsertAtEnd); |
3636 | 13 | } |
3637 | | |
3638 | | static InvokeInst *Create(Value *Func, BasicBlock *IfNormal, |
3639 | | BasicBlock *IfException, ArrayRef<Value *> Args, |
3640 | | ArrayRef<OperandBundleDef> Bundles, |
3641 | 11.3k | const Twine &NameStr, BasicBlock *InsertAtEnd) { |
3642 | 11.3k | unsigned Values = unsigned(Args.size()) + CountBundleInputs(Bundles) + 3; |
3643 | 11.3k | unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo); |
3644 | 11.3k | |
3645 | 11.3k | return new (Values, DescriptorBytes) |
3646 | 11.3k | InvokeInst(Func, IfNormal, IfException, Args, Bundles, Values, NameStr, |
3647 | 11.3k | InsertAtEnd); |
3648 | 11.3k | } |
3649 | | |
3650 | | /// Create a clone of \p II with a different set of operand bundles and |
3651 | | /// insert it before \p InsertPt. |
3652 | | /// |
3653 | | /// The returned invoke instruction is identical to \p II in every way except |
3654 | | /// that the operand bundles for the new instruction are set to the operand |
3655 | | /// bundles in \p Bundles. |
3656 | | static InvokeInst *Create(InvokeInst *II, ArrayRef<OperandBundleDef> Bundles, |
3657 | | Instruction *InsertPt = nullptr); |
3658 | | |
3659 | | /// Provide fast operand accessors |
3660 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
3661 | | |
3662 | 40.0k | FunctionType *getFunctionType() const { return FTy; } |
3663 | | |
3664 | 7 | void mutateFunctionType(FunctionType *FTy) { |
3665 | 7 | mutateType(FTy->getReturnType()); |
3666 | 7 | this->FTy = FTy; |
3667 | 7 | } |
3668 | | |
3669 | | /// Return the number of invoke arguments. |
3670 | | /// |
3671 | 565k | unsigned getNumArgOperands() const { |
3672 | 565k | return getNumOperands() - getNumTotalBundleOperands() - 3; |
3673 | 565k | } |
3674 | | |
3675 | | /// getArgOperand/setArgOperand - Return/set the i-th invoke argument. |
3676 | | /// |
3677 | 372k | Value *getArgOperand(unsigned i) const { |
3678 | 372k | assert(i < getNumArgOperands() && "Out of bounds!"); |
3679 | 372k | return getOperand(i); |
3680 | 372k | } |
3681 | 0 | void setArgOperand(unsigned i, Value *v) { |
3682 | 0 | assert(i < getNumArgOperands() && "Out of bounds!"); |
3683 | 0 | setOperand(i, v); |
3684 | 0 | } |
3685 | | |
3686 | | /// Return the iterator pointing to the beginning of the argument list. |
3687 | 866k | op_iterator arg_begin() { return op_begin(); } |
3688 | | |
3689 | | /// Return the iterator pointing to the end of the argument list. |
3690 | 611k | op_iterator arg_end() { |
3691 | 611k | // [ invoke args ], [ operand bundles ], normal dest, unwind dest, callee |
3692 | 611k | return op_end() - getNumTotalBundleOperands() - 3; |
3693 | 611k | } |
3694 | | |
3695 | | /// Iteration adapter for range-for loops. |
3696 | 0 | iterator_range<op_iterator> arg_operands() { |
3697 | 0 | return make_range(arg_begin(), arg_end()); |
3698 | 0 | } |
3699 | | |
3700 | | /// Return the iterator pointing to the beginning of the argument list. |
3701 | 271k | const_op_iterator arg_begin() const { return op_begin(); } |
3702 | | |
3703 | | /// Return the iterator pointing to the end of the argument list. |
3704 | 241k | const_op_iterator arg_end() const { |
3705 | 241k | // [ invoke args ], [ operand bundles ], normal dest, unwind dest, callee |
3706 | 241k | return op_end() - getNumTotalBundleOperands() - 3; |
3707 | 241k | } |
3708 | | |
3709 | | /// Iteration adapter for range-for loops. |
3710 | 7.79k | iterator_range<const_op_iterator> arg_operands() const { |
3711 | 7.79k | return make_range(arg_begin(), arg_end()); |
3712 | 7.79k | } |
3713 | | |
3714 | | /// Wrappers for getting the \c Use of a invoke argument. |
3715 | 0 | const Use &getArgOperandUse(unsigned i) const { |
3716 | 0 | assert(i < getNumArgOperands() && "Out of bounds!"); |
3717 | 0 | return getOperandUse(i); |
3718 | 0 | } |
3719 | 0 | Use &getArgOperandUse(unsigned i) { |
3720 | 0 | assert(i < getNumArgOperands() && "Out of bounds!"); |
3721 | 0 | return getOperandUse(i); |
3722 | 0 | } |
3723 | | |
3724 | | /// If one of the arguments has the 'returned' attribute, return its |
3725 | | /// operand value. Otherwise, return nullptr. |
3726 | | Value *getReturnedArgOperand() const; |
3727 | | |
3728 | | /// getCallingConv/setCallingConv - Get or set the calling convention of this |
3729 | | /// function call. |
3730 | 256k | CallingConv::ID getCallingConv() const { |
3731 | 256k | return static_cast<CallingConv::ID>(getSubclassDataFromInstruction()); |
3732 | 256k | } |
3733 | 48.2k | void setCallingConv(CallingConv::ID CC) { |
3734 | 48.2k | auto ID = static_cast<unsigned>(CC); |
3735 | 48.2k | assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention"); |
3736 | 48.2k | setInstructionSubclassData(ID); |
3737 | 48.2k | } |
3738 | | |
3739 | | /// Return the parameter attributes for this invoke. |
3740 | | /// |
3741 | 231k | AttributeList getAttributes() const { return Attrs; } |
3742 | | |
3743 | | /// Set the parameter attributes for this invoke. |
3744 | | /// |
3745 | 62.3k | void setAttributes(AttributeList A) { Attrs = A; } |
3746 | | |
3747 | | /// adds the attribute to the list of attributes. |
3748 | | void addAttribute(unsigned i, Attribute::AttrKind Kind); |
3749 | | |
3750 | | /// adds the attribute to the list of attributes. |
3751 | | void addAttribute(unsigned i, Attribute Attr); |
3752 | | |
3753 | | /// Adds the attribute to the indicated argument |
3754 | | void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind); |
3755 | | |
3756 | | /// removes the attribute from the list of attributes. |
3757 | | void removeAttribute(unsigned i, Attribute::AttrKind Kind); |
3758 | | |
3759 | | /// removes the attribute from the list of attributes. |
3760 | | void removeAttribute(unsigned i, StringRef Kind); |
3761 | | |
3762 | | /// Removes the attribute from the given argument |
3763 | | void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind); |
3764 | | |
3765 | | /// adds the dereferenceable attribute to the list of attributes. |
3766 | | void addDereferenceableAttr(unsigned i, uint64_t Bytes); |
3767 | | |
3768 | | /// adds the dereferenceable_or_null attribute to the list of |
3769 | | /// attributes. |
3770 | | void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes); |
3771 | | |
3772 | | /// Determine whether this call has the given attribute. |
3773 | 3.84M | bool hasFnAttr(Attribute::AttrKind Kind) const { |
3774 | 3.84M | assert(Kind != Attribute::NoBuiltin && |
3775 | 3.84M | "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin"); |
3776 | 3.84M | return hasFnAttrImpl(Kind); |
3777 | 3.84M | } |
3778 | | |
3779 | | /// Determine whether this call has the given attribute. |
3780 | 34 | bool hasFnAttr(StringRef Kind) const { |
3781 | 34 | return hasFnAttrImpl(Kind); |
3782 | 34 | } |
3783 | | |
3784 | | /// Determine whether the return value has the given attribute. |
3785 | | bool hasRetAttr(Attribute::AttrKind Kind) const; |
3786 | | |
3787 | | /// Determine whether the argument or parameter has the given attribute. |
3788 | | bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const; |
3789 | | |
3790 | | /// Get the attribute of a given kind at a position. |
3791 | 0 | Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const { |
3792 | 0 | return getAttributes().getAttribute(i, Kind); |
3793 | 0 | } |
3794 | | |
3795 | | /// Get the attribute of a given kind at a position. |
3796 | 0 | Attribute getAttribute(unsigned i, StringRef Kind) const { |
3797 | 0 | return getAttributes().getAttribute(i, Kind); |
3798 | 0 | } |
3799 | | |
3800 | | /// Return true if the data operand at index \p i has the attribute \p |
3801 | | /// A. |
3802 | | /// |
3803 | | /// Data operands include invoke arguments and values used in operand bundles, |
3804 | | /// but does not include the invokee operand, or the two successor blocks. |
3805 | | /// This routine dispatches to the underlying AttributeList or the |
3806 | | /// OperandBundleUser as appropriate. |
3807 | | /// |
3808 | | /// The index \p i is interpreted as |
3809 | | /// |
3810 | | /// \p i == Attribute::ReturnIndex -> the return value |
3811 | | /// \p i in [1, arg_size + 1) -> argument number (\p i - 1) |
3812 | | /// \p i in [arg_size + 1, data_operand_size + 1) -> bundle operand at index |
3813 | | /// (\p i - 1) in the operand list. |
3814 | | bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const; |
3815 | | |
3816 | | /// Extract the alignment of the return value. |
3817 | 0 | unsigned getRetAlignment() const { return Attrs.getRetAlignment(); } |
3818 | | |
3819 | | /// Extract the alignment for a call or parameter (0=unknown). |
3820 | 27.3k | unsigned getParamAlignment(unsigned ArgNo) const { |
3821 | 27.3k | return Attrs.getParamAlignment(ArgNo); |
3822 | 27.3k | } |
3823 | | |
3824 | | /// Extract the number of dereferenceable bytes for a call or |
3825 | | /// parameter (0=unknown). |
3826 | 15.0k | uint64_t getDereferenceableBytes(unsigned i) const { |
3827 | 15.0k | return Attrs.getDereferenceableBytes(i); |
3828 | 15.0k | } |
3829 | | |
3830 | | /// Extract the number of dereferenceable_or_null bytes for a call or |
3831 | | /// parameter (0=unknown). |
3832 | 2.77k | uint64_t getDereferenceableOrNullBytes(unsigned i) const { |
3833 | 2.77k | return Attrs.getDereferenceableOrNullBytes(i); |
3834 | 2.77k | } |
3835 | | |
3836 | | /// @brief Determine if the return value is marked with NoAlias attribute. |
3837 | 0 | bool returnDoesNotAlias() const { |
3838 | 0 | return Attrs.hasAttribute(AttributeList::ReturnIndex, Attribute::NoAlias); |
3839 | 0 | } |
3840 | | |
3841 | | /// Return true if the call should not be treated as a call to a |
3842 | | /// builtin. |
3843 | 844k | bool isNoBuiltin() const { |
3844 | 844k | // We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have |
3845 | 844k | // to check it by hand. |
3846 | 844k | return hasFnAttrImpl(Attribute::NoBuiltin) && |
3847 | 279k | !hasFnAttrImpl(Attribute::Builtin); |
3848 | 844k | } |
3849 | | |
3850 | | /// Determine if the call requires strict floating point semantics. |
3851 | 169k | bool isStrictFP() const { return hasFnAttr(Attribute::StrictFP); } |
3852 | | |
3853 | | /// Return true if the call should not be inlined. |
3854 | 57.4k | bool isNoInline() const { return hasFnAttr(Attribute::NoInline); } |
3855 | 0 | void setIsNoInline() { |
3856 | 0 | addAttribute(AttributeList::FunctionIndex, Attribute::NoInline); |
3857 | 0 | } |
3858 | | |
3859 | | /// Determine if the call does not access memory. |
3860 | 1.35M | bool doesNotAccessMemory() const { |
3861 | 1.35M | return hasFnAttr(Attribute::ReadNone); |
3862 | 1.35M | } |
3863 | 0 | void setDoesNotAccessMemory() { |
3864 | 0 | addAttribute(AttributeList::FunctionIndex, Attribute::ReadNone); |
3865 | 0 | } |
3866 | | |
3867 | | /// Determine if the call does not access or only reads memory. |
3868 | 852k | bool onlyReadsMemory() const { |
3869 | 852k | return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly); |
3870 | 852k | } |
3871 | 0 | void setOnlyReadsMemory() { |
3872 | 0 | addAttribute(AttributeList::FunctionIndex, Attribute::ReadOnly); |
3873 | 0 | } |
3874 | | |
3875 | | /// Determine if the call does not access or only writes memory. |
3876 | 192k | bool doesNotReadMemory() const { |
3877 | 192k | return doesNotAccessMemory() || hasFnAttr(Attribute::WriteOnly); |
3878 | 192k | } |
3879 | 0 | void setDoesNotReadMemory() { |
3880 | 0 | addAttribute(AttributeList::FunctionIndex, Attribute::WriteOnly); |
3881 | 0 | } |
3882 | | |
3883 | | /// @brief Determine if the call access memmory only using it's pointer |
3884 | | /// arguments. |
3885 | 192k | bool onlyAccessesArgMemory() const { |
3886 | 192k | return hasFnAttr(Attribute::ArgMemOnly); |
3887 | 192k | } |
3888 | 0 | void setOnlyAccessesArgMemory() { |
3889 | 0 | addAttribute(AttributeList::FunctionIndex, Attribute::ArgMemOnly); |
3890 | 0 | } |
3891 | | |
3892 | | /// Determine if the call cannot return. |
3893 | 44.7k | bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); } |
3894 | 278 | void setDoesNotReturn() { |
3895 | 278 | addAttribute(AttributeList::FunctionIndex, Attribute::NoReturn); |
3896 | 278 | } |
3897 | | |
3898 | | /// Determine if the call cannot unwind. |
3899 | 460k | bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); } |
3900 | 0 | void setDoesNotThrow() { |
3901 | 0 | addAttribute(AttributeList::FunctionIndex, Attribute::NoUnwind); |
3902 | 0 | } |
3903 | | |
3904 | | /// Determine if the invoke cannot be duplicated. |
3905 | 29.4k | bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); } |
3906 | 0 | void setCannotDuplicate() { |
3907 | 0 | addAttribute(AttributeList::FunctionIndex, Attribute::NoDuplicate); |
3908 | 0 | } |
3909 | | |
3910 | | /// Determine if the invoke is convergent |
3911 | 232k | bool isConvergent() const { return hasFnAttr(Attribute::Convergent); } |
3912 | 0 | void setConvergent() { |
3913 | 0 | addAttribute(AttributeList::FunctionIndex, Attribute::Convergent); |
3914 | 0 | } |
3915 | 0 | void setNotConvergent() { |
3916 | 0 | removeAttribute(AttributeList::FunctionIndex, Attribute::Convergent); |
3917 | 0 | } |
3918 | | |
3919 | | /// Determine if the call returns a structure through first |
3920 | | /// pointer argument. |
3921 | 0 | bool hasStructRetAttr() const { |
3922 | 0 | if (getNumArgOperands() == 0) |
3923 | 0 | return false; |
3924 | 0 |
|
3925 | 0 | // Be friendly and also check the callee. |
3926 | 0 | return paramHasAttr(0, Attribute::StructRet); |
3927 | 0 | } |
3928 | | |
3929 | | /// Determine if any call argument is an aggregate passed by value. |
3930 | 0 | bool hasByValArgument() const { |
3931 | 0 | return Attrs.hasAttrSomewhere(Attribute::ByVal); |
3932 | 0 | } |
3933 | | |
3934 | | /// Return the function called, or null if this is an |
3935 | | /// indirect function invocation. |
3936 | | /// |
3937 | 9.12M | Function *getCalledFunction() const { |
3938 | 9.12M | return dyn_cast<Function>(Op<-3>()); |
3939 | 9.12M | } |
3940 | | |
3941 | | /// Get a pointer to the function that is invoked by this |
3942 | | /// instruction |
3943 | 30.4k | const Value *getCalledValue() const { return Op<-3>(); } |
3944 | 399k | Value *getCalledValue() { return Op<-3>(); } |
3945 | | |
3946 | | /// Set the function called. |
3947 | 7 | void setCalledFunction(Value* Fn) { |
3948 | 7 | setCalledFunction( |
3949 | 7 | cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()), |
3950 | 7 | Fn); |
3951 | 7 | } |
3952 | 7 | void setCalledFunction(FunctionType *FTy, Value *Fn) { |
3953 | 7 | this->FTy = FTy; |
3954 | 7 | assert(FTy == cast<FunctionType>( |
3955 | 7 | cast<PointerType>(Fn->getType())->getElementType())); |
3956 | 7 | Op<-3>() = Fn; |
3957 | 7 | } |
3958 | | |
3959 | | // get*Dest - Return the destination basic blocks... |
3960 | 5.94M | BasicBlock *getNormalDest() const { |
3961 | 5.94M | return cast<BasicBlock>(Op<-2>()); |
3962 | 5.94M | } |
3963 | 5.03M | BasicBlock *getUnwindDest() const { |
3964 | 5.03M | return cast<BasicBlock>(Op<-1>()); |
3965 | 5.03M | } |
3966 | 7 | void setNormalDest(BasicBlock *B) { |
3967 | 7 | Op<-2>() = reinterpret_cast<Value*>(B); |
3968 | 7 | } |
3969 | 10 | void setUnwindDest(BasicBlock *B) { |
3970 | 10 | Op<-1>() = reinterpret_cast<Value*>(B); |
3971 | 10 | } |
3972 | | |
3973 | | /// Get the landingpad instruction from the landing pad |
3974 | | /// block (the unwind destination). |
3975 | | LandingPadInst *getLandingPadInst() const; |
3976 | | |
3977 | 10.2M | BasicBlock *getSuccessor(unsigned i) const { |
3978 | 10.2M | assert(i < 2 && "Successor # out of range for invoke!"); |
3979 | 10.2M | return i == 0 ? getNormalDest()5.30M : getUnwindDest()4.94M ; |
3980 | 10.2M | } |
3981 | | |
3982 | 157 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
3983 | 157 | assert(idx < 2 && "Successor # out of range for invoke!"); |
3984 | 157 | *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc); |
3985 | 157 | } |
3986 | | |
3987 | 8.35M | unsigned getNumSuccessors() const { return 2; } |
3988 | | |
3989 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
3990 | 334M | static bool classof(const Instruction *I) { |
3991 | 334M | return (I->getOpcode() == Instruction::Invoke); |
3992 | 334M | } |
3993 | 114M | static bool classof(const Value *V) { |
3994 | 85.2M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
3995 | 114M | } |
3996 | | |
3997 | | private: |
3998 | 4.97M | template <typename AttrKind> bool hasFnAttrImpl(AttrKind Kind) const { |
3999 | 4.97M | if (Attrs.hasAttribute(AttributeList::FunctionIndex, Kind)) |
4000 | 280k | return true; |
4001 | 4.97M | |
4002 | 4.97M | // Operand bundles override attributes on the called function, but don't |
4003 | 4.97M | // override attributes directly present on the invoke instruction. |
4004 | 4.69M | if (4.69M isFnAttrDisallowedByOpBundle(Kind)4.69M ) |
4005 | 15 | return false; |
4006 | 4.69M | |
4007 | 4.69M | if (const Function *4.69M F4.69M = getCalledFunction()) |
4008 | 3.98M | return F->getAttributes().hasAttribute(AttributeList::FunctionIndex, |
4009 | 3.98M | Kind); |
4010 | 706k | return false; |
4011 | 4.97M | } bool llvm::InvokeInst::hasFnAttrImpl<llvm::StringRef>(llvm::StringRef) const Line | Count | Source | 3998 | 34 | template <typename AttrKind> bool hasFnAttrImpl(AttrKind Kind) const { | 3999 | 34 | if (Attrs.hasAttribute(AttributeList::FunctionIndex, Kind)) | 4000 | 0 | return true; | 4001 | 34 | | 4002 | 34 | // Operand bundles override attributes on the called function, but don't | 4003 | 34 | // override attributes directly present on the invoke instruction. | 4004 | 34 | if (34 isFnAttrDisallowedByOpBundle(Kind)34 ) | 4005 | 0 | return false; | 4006 | 34 | | 4007 | 34 | if (const Function *34 F34 = getCalledFunction()) | 4008 | 34 | return F->getAttributes().hasAttribute(AttributeList::FunctionIndex, | 4009 | 34 | Kind); | 4010 | 0 | return false; | 4011 | 34 | } |
bool llvm::InvokeInst::hasFnAttrImpl<llvm::Attribute::AttrKind>(llvm::Attribute::AttrKind) const Line | Count | Source | 3998 | 4.97M | template <typename AttrKind> bool hasFnAttrImpl(AttrKind Kind) const { | 3999 | 4.97M | if (Attrs.hasAttribute(AttributeList::FunctionIndex, Kind)) | 4000 | 280k | return true; | 4001 | 4.97M | | 4002 | 4.97M | // Operand bundles override attributes on the called function, but don't | 4003 | 4.97M | // override attributes directly present on the invoke instruction. | 4004 | 4.69M | if (4.69M isFnAttrDisallowedByOpBundle(Kind)4.69M ) | 4005 | 15 | return false; | 4006 | 4.69M | | 4007 | 4.69M | if (const Function *4.69M F4.69M = getCalledFunction()) | 4008 | 3.98M | return F->getAttributes().hasAttribute(AttributeList::FunctionIndex, | 4009 | 3.98M | Kind); | 4010 | 706k | return false; | 4011 | 4.97M | } |
|
4012 | | |
4013 | | // Shadow Instruction::setInstructionSubclassData with a private forwarding |
4014 | | // method so that subclasses cannot accidentally use it. |
4015 | 48.2k | void setInstructionSubclassData(unsigned short D) { |
4016 | 48.2k | Instruction::setInstructionSubclassData(D); |
4017 | 48.2k | } |
4018 | | }; |
4019 | | |
4020 | | template <> |
4021 | | struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> { |
4022 | | }; |
4023 | | |
4024 | | InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, |
4025 | | BasicBlock *IfException, ArrayRef<Value *> Args, |
4026 | | ArrayRef<OperandBundleDef> Bundles, unsigned Values, |
4027 | | const Twine &NameStr, Instruction *InsertBefore) |
4028 | | : TerminatorInst(Ty->getReturnType(), Instruction::Invoke, |
4029 | | OperandTraits<InvokeInst>::op_end(this) - Values, Values, |
4030 | 28.6k | InsertBefore) { |
4031 | 28.6k | init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr); |
4032 | 28.6k | } |
4033 | | |
4034 | | InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal, |
4035 | | BasicBlock *IfException, ArrayRef<Value *> Args, |
4036 | | ArrayRef<OperandBundleDef> Bundles, unsigned Values, |
4037 | | const Twine &NameStr, BasicBlock *InsertAtEnd) |
4038 | | : TerminatorInst( |
4039 | | cast<FunctionType>(cast<PointerType>(Func->getType()) |
4040 | | ->getElementType())->getReturnType(), |
4041 | | Instruction::Invoke, OperandTraits<InvokeInst>::op_end(this) - Values, |
4042 | 11.3k | Values, InsertAtEnd) { |
4043 | 11.3k | init(Func, IfNormal, IfException, Args, Bundles, NameStr); |
4044 | 11.3k | } |
4045 | | |
4046 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value) |
4047 | | |
4048 | | //===----------------------------------------------------------------------===// |
4049 | | // ResumeInst Class |
4050 | | //===----------------------------------------------------------------------===// |
4051 | | |
4052 | | //===--------------------------------------------------------------------------- |
4053 | | /// Resume the propagation of an exception. |
4054 | | /// |
4055 | | class ResumeInst : public TerminatorInst { |
4056 | | ResumeInst(const ResumeInst &RI); |
4057 | | |
4058 | | explicit ResumeInst(Value *Exn, Instruction *InsertBefore=nullptr); |
4059 | | ResumeInst(Value *Exn, BasicBlock *InsertAtEnd); |
4060 | | |
4061 | | protected: |
4062 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
4063 | | friend class Instruction; |
4064 | | |
4065 | | ResumeInst *cloneImpl() const; |
4066 | | |
4067 | | public: |
4068 | 4.58k | static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = nullptr) { |
4069 | 4.58k | return new(1) ResumeInst(Exn, InsertBefore); |
4070 | 4.58k | } |
4071 | | |
4072 | 4 | static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) { |
4073 | 4 | return new(1) ResumeInst(Exn, InsertAtEnd); |
4074 | 4 | } |
4075 | | |
4076 | | /// Provide fast operand accessors |
4077 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
4078 | | |
4079 | | /// Convenience accessor. |
4080 | 59.7k | Value *getValue() const { return Op<0>(); } |
4081 | | |
4082 | 538k | unsigned getNumSuccessors() const { return 0; } |
4083 | | |
4084 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
4085 | 194M | static bool classof(const Instruction *I) { |
4086 | 194M | return I->getOpcode() == Instruction::Resume; |
4087 | 194M | } |
4088 | 0 | static bool classof(const Value *V) { |
4089 | 0 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4090 | 0 | } |
4091 | | |
4092 | | private: |
4093 | | friend TerminatorInst; |
4094 | | |
4095 | 0 | BasicBlock *getSuccessor(unsigned idx) const { |
4096 | 0 | llvm_unreachable("ResumeInst has no successors!"); |
4097 | 0 | } |
4098 | | |
4099 | 0 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
4100 | 0 | llvm_unreachable("ResumeInst has no successors!"); |
4101 | 0 | } |
4102 | | }; |
4103 | | |
4104 | | template <> |
4105 | | struct OperandTraits<ResumeInst> : |
4106 | | public FixedNumOperandTraits<ResumeInst, 1> { |
4107 | | }; |
4108 | | |
4109 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value) |
4110 | | |
4111 | | //===----------------------------------------------------------------------===// |
4112 | | // CatchSwitchInst Class |
4113 | | //===----------------------------------------------------------------------===// |
4114 | | class CatchSwitchInst : public TerminatorInst { |
4115 | | /// The number of operands actually allocated. NumOperands is |
4116 | | /// the number actually in use. |
4117 | | unsigned ReservedSpace; |
4118 | | |
4119 | | // Operand[0] = Outer scope |
4120 | | // Operand[1] = Unwind block destination |
4121 | | // Operand[n] = BasicBlock to go to on match |
4122 | | CatchSwitchInst(const CatchSwitchInst &CSI); |
4123 | | |
4124 | | /// Create a new switch instruction, specifying a |
4125 | | /// default destination. The number of additional handlers can be specified |
4126 | | /// here to make memory allocation more efficient. |
4127 | | /// This constructor can also autoinsert before another instruction. |
4128 | | CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest, |
4129 | | unsigned NumHandlers, const Twine &NameStr, |
4130 | | Instruction *InsertBefore); |
4131 | | |
4132 | | /// Create a new switch instruction, specifying a |
4133 | | /// default destination. The number of additional handlers can be specified |
4134 | | /// here to make memory allocation more efficient. |
4135 | | /// This constructor also autoinserts at the end of the specified BasicBlock. |
4136 | | CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest, |
4137 | | unsigned NumHandlers, const Twine &NameStr, |
4138 | | BasicBlock *InsertAtEnd); |
4139 | | |
4140 | | // allocate space for exactly zero operands |
4141 | 367 | void *operator new(size_t s) { return User::operator new(s); } |
4142 | | |
4143 | | void init(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumReserved); |
4144 | | void growOperands(unsigned Size); |
4145 | | |
4146 | | protected: |
4147 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
4148 | | friend class Instruction; |
4149 | | |
4150 | | CatchSwitchInst *cloneImpl() const; |
4151 | | |
4152 | | public: |
4153 | | static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest, |
4154 | | unsigned NumHandlers, |
4155 | | const Twine &NameStr = "", |
4156 | 343 | Instruction *InsertBefore = nullptr) { |
4157 | 343 | return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr, |
4158 | 343 | InsertBefore); |
4159 | 343 | } |
4160 | | |
4161 | | static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest, |
4162 | | unsigned NumHandlers, const Twine &NameStr, |
4163 | 0 | BasicBlock *InsertAtEnd) { |
4164 | 0 | return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr, |
4165 | 0 | InsertAtEnd); |
4166 | 0 | } |
4167 | | |
4168 | | /// Provide fast operand accessors |
4169 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
4170 | | |
4171 | | // Accessor Methods for CatchSwitch stmt |
4172 | 2.80k | Value *getParentPad() const { return getOperand(0); } |
4173 | 0 | void setParentPad(Value *ParentPad) { setOperand(0, ParentPad); } |
4174 | | |
4175 | | // Accessor Methods for CatchSwitch stmt |
4176 | 4.41k | bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; } |
4177 | 336 | bool unwindsToCaller() const { return !hasUnwindDest(); } |
4178 | 1.94k | BasicBlock *getUnwindDest() const { |
4179 | 1.94k | if (hasUnwindDest()) |
4180 | 679 | return cast<BasicBlock>(getOperand(1)); |
4181 | 1.26k | return nullptr; |
4182 | 1.94k | } |
4183 | 98 | void setUnwindDest(BasicBlock *UnwindDest) { |
4184 | 98 | assert(UnwindDest); |
4185 | 98 | assert(hasUnwindDest()); |
4186 | 98 | setOperand(1, UnwindDest); |
4187 | 98 | } |
4188 | | |
4189 | | /// return the number of 'handlers' in this catchswitch |
4190 | | /// instruction, except the default handler |
4191 | 652 | unsigned getNumHandlers() const { |
4192 | 652 | if (hasUnwindDest()) |
4193 | 163 | return getNumOperands() - 2; |
4194 | 489 | return getNumOperands() - 1; |
4195 | 652 | } |
4196 | | |
4197 | | private: |
4198 | 1.01k | static BasicBlock *handler_helper(Value *V) { return cast<BasicBlock>(V); } |
4199 | 527 | static const BasicBlock *handler_helper(const Value *V) { |
4200 | 527 | return cast<BasicBlock>(V); |
4201 | 527 | } |
4202 | | |
4203 | | public: |
4204 | | using DerefFnTy = BasicBlock *(*)(Value *); |
4205 | | using handler_iterator = mapped_iterator<op_iterator, DerefFnTy>; |
4206 | | using handler_range = iterator_range<handler_iterator>; |
4207 | | using ConstDerefFnTy = const BasicBlock *(*)(const Value *); |
4208 | | using const_handler_iterator = |
4209 | | mapped_iterator<const_op_iterator, ConstDerefFnTy>; |
4210 | | using const_handler_range = iterator_range<const_handler_iterator>; |
4211 | | |
4212 | | /// Returns an iterator that points to the first handler in CatchSwitchInst. |
4213 | 944 | handler_iterator handler_begin() { |
4214 | 944 | op_iterator It = op_begin() + 1; |
4215 | 944 | if (hasUnwindDest()) |
4216 | 224 | ++It; |
4217 | 944 | return handler_iterator(It, DerefFnTy(handler_helper)); |
4218 | 944 | } |
4219 | | |
4220 | | /// Returns an iterator that points to the first handler in the |
4221 | | /// CatchSwitchInst. |
4222 | 498 | const_handler_iterator handler_begin() const { |
4223 | 498 | const_op_iterator It = op_begin() + 1; |
4224 | 498 | if (hasUnwindDest()) |
4225 | 127 | ++It; |
4226 | 498 | return const_handler_iterator(It, ConstDerefFnTy(handler_helper)); |
4227 | 498 | } |
4228 | | |
4229 | | /// Returns a read-only iterator that points one past the last |
4230 | | /// handler in the CatchSwitchInst. |
4231 | 944 | handler_iterator handler_end() { |
4232 | 944 | return handler_iterator(op_end(), DerefFnTy(handler_helper)); |
4233 | 944 | } |
4234 | | |
4235 | | /// Returns an iterator that points one past the last handler in the |
4236 | | /// CatchSwitchInst. |
4237 | 451 | const_handler_iterator handler_end() const { |
4238 | 451 | return const_handler_iterator(op_end(), ConstDerefFnTy(handler_helper)); |
4239 | 451 | } |
4240 | | |
4241 | | /// iteration adapter for range-for loops. |
4242 | 647 | handler_range handlers() { |
4243 | 647 | return make_range(handler_begin(), handler_end()); |
4244 | 647 | } |
4245 | | |
4246 | | /// iteration adapter for range-for loops. |
4247 | 451 | const_handler_range handlers() const { |
4248 | 451 | return make_range(handler_begin(), handler_end()); |
4249 | 451 | } |
4250 | | |
4251 | | /// Add an entry to the switch instruction... |
4252 | | /// Note: |
4253 | | /// This action invalidates handler_end(). Old handler_end() iterator will |
4254 | | /// point to the added handler. |
4255 | | void addHandler(BasicBlock *Dest); |
4256 | | |
4257 | | void removeHandler(handler_iterator HI); |
4258 | | |
4259 | 5.96k | unsigned getNumSuccessors() const { return getNumOperands() - 1; } |
4260 | 4.99k | BasicBlock *getSuccessor(unsigned Idx) const { |
4261 | 4.99k | assert(Idx < getNumSuccessors() && |
4262 | 4.99k | "Successor # out of range for catchswitch!"); |
4263 | 4.99k | return cast<BasicBlock>(getOperand(Idx + 1)); |
4264 | 4.99k | } |
4265 | 0 | void setSuccessor(unsigned Idx, BasicBlock *NewSucc) { |
4266 | 0 | assert(Idx < getNumSuccessors() && |
4267 | 0 | "Successor # out of range for catchswitch!"); |
4268 | 0 | setOperand(Idx + 1, NewSucc); |
4269 | 0 | } |
4270 | | |
4271 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
4272 | 259M | static bool classof(const Instruction *I) { |
4273 | 259M | return I->getOpcode() == Instruction::CatchSwitch; |
4274 | 259M | } |
4275 | 3.14k | static bool classof(const Value *V) { |
4276 | 2.71k | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4277 | 3.14k | } |
4278 | | }; |
4279 | | |
4280 | | template <> |
4281 | | struct OperandTraits<CatchSwitchInst> : public HungoffOperandTraits<2> {}; |
4282 | | |
4283 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchSwitchInst, Value) |
4284 | | |
4285 | | //===----------------------------------------------------------------------===// |
4286 | | // CleanupPadInst Class |
4287 | | //===----------------------------------------------------------------------===// |
4288 | | class CleanupPadInst : public FuncletPadInst { |
4289 | | private: |
4290 | | explicit CleanupPadInst(Value *ParentPad, ArrayRef<Value *> Args, |
4291 | | unsigned Values, const Twine &NameStr, |
4292 | | Instruction *InsertBefore) |
4293 | | : FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, Values, |
4294 | 377 | NameStr, InsertBefore) {} |
4295 | | explicit CleanupPadInst(Value *ParentPad, ArrayRef<Value *> Args, |
4296 | | unsigned Values, const Twine &NameStr, |
4297 | | BasicBlock *InsertAtEnd) |
4298 | | : FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, Values, |
4299 | 7 | NameStr, InsertAtEnd) {} |
4300 | | |
4301 | | public: |
4302 | | static CleanupPadInst *Create(Value *ParentPad, ArrayRef<Value *> Args = None, |
4303 | | const Twine &NameStr = "", |
4304 | 377 | Instruction *InsertBefore = nullptr) { |
4305 | 377 | unsigned Values = 1 + Args.size(); |
4306 | 377 | return new (Values) |
4307 | 377 | CleanupPadInst(ParentPad, Args, Values, NameStr, InsertBefore); |
4308 | 377 | } |
4309 | | |
4310 | | static CleanupPadInst *Create(Value *ParentPad, ArrayRef<Value *> Args, |
4311 | 7 | const Twine &NameStr, BasicBlock *InsertAtEnd) { |
4312 | 7 | unsigned Values = 1 + Args.size(); |
4313 | 7 | return new (Values) |
4314 | 7 | CleanupPadInst(ParentPad, Args, Values, NameStr, InsertAtEnd); |
4315 | 7 | } |
4316 | | |
4317 | | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
4318 | 2.94k | static bool classof(const Instruction *I) { |
4319 | 2.94k | return I->getOpcode() == Instruction::CleanupPad; |
4320 | 2.94k | } |
4321 | 1.27k | static bool classof(const Value *V) { |
4322 | 1.27k | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4323 | 1.27k | } |
4324 | | }; |
4325 | | |
4326 | | //===----------------------------------------------------------------------===// |
4327 | | // CatchPadInst Class |
4328 | | //===----------------------------------------------------------------------===// |
4329 | | class CatchPadInst : public FuncletPadInst { |
4330 | | private: |
4331 | | explicit CatchPadInst(Value *CatchSwitch, ArrayRef<Value *> Args, |
4332 | | unsigned Values, const Twine &NameStr, |
4333 | | Instruction *InsertBefore) |
4334 | | : FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, Values, |
4335 | 351 | NameStr, InsertBefore) {} |
4336 | | explicit CatchPadInst(Value *CatchSwitch, ArrayRef<Value *> Args, |
4337 | | unsigned Values, const Twine &NameStr, |
4338 | | BasicBlock *InsertAtEnd) |
4339 | | : FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, Values, |
4340 | 0 | NameStr, InsertAtEnd) {} |
4341 | | |
4342 | | public: |
4343 | | static CatchPadInst *Create(Value *CatchSwitch, ArrayRef<Value *> Args, |
4344 | | const Twine &NameStr = "", |
4345 | 351 | Instruction *InsertBefore = nullptr) { |
4346 | 351 | unsigned Values = 1 + Args.size(); |
4347 | 351 | return new (Values) |
4348 | 351 | CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertBefore); |
4349 | 351 | } |
4350 | | |
4351 | | static CatchPadInst *Create(Value *CatchSwitch, ArrayRef<Value *> Args, |
4352 | 0 | const Twine &NameStr, BasicBlock *InsertAtEnd) { |
4353 | 0 | unsigned Values = 1 + Args.size(); |
4354 | 0 | return new (Values) |
4355 | 0 | CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertAtEnd); |
4356 | 0 | } |
4357 | | |
4358 | | /// Convenience accessors |
4359 | 1.72k | CatchSwitchInst *getCatchSwitch() const { |
4360 | 1.72k | return cast<CatchSwitchInst>(Op<-1>()); |
4361 | 1.72k | } |
4362 | 0 | void setCatchSwitch(Value *CatchSwitch) { |
4363 | 0 | assert(CatchSwitch); |
4364 | 0 | Op<-1>() = CatchSwitch; |
4365 | 0 | } |
4366 | | |
4367 | | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
4368 | 16.6k | static bool classof(const Instruction *I) { |
4369 | 16.6k | return I->getOpcode() == Instruction::CatchPad; |
4370 | 16.6k | } |
4371 | 545 | static bool classof(const Value *V) { |
4372 | 543 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4373 | 545 | } |
4374 | | }; |
4375 | | |
4376 | | //===----------------------------------------------------------------------===// |
4377 | | // CatchReturnInst Class |
4378 | | //===----------------------------------------------------------------------===// |
4379 | | |
4380 | | class CatchReturnInst : public TerminatorInst { |
4381 | | CatchReturnInst(const CatchReturnInst &RI); |
4382 | | CatchReturnInst(Value *CatchPad, BasicBlock *BB, Instruction *InsertBefore); |
4383 | | CatchReturnInst(Value *CatchPad, BasicBlock *BB, BasicBlock *InsertAtEnd); |
4384 | | |
4385 | | void init(Value *CatchPad, BasicBlock *BB); |
4386 | | |
4387 | | protected: |
4388 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
4389 | | friend class Instruction; |
4390 | | |
4391 | | CatchReturnInst *cloneImpl() const; |
4392 | | |
4393 | | public: |
4394 | | static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB, |
4395 | 248 | Instruction *InsertBefore = nullptr) { |
4396 | 248 | assert(CatchPad); |
4397 | 248 | assert(BB); |
4398 | 248 | return new (2) CatchReturnInst(CatchPad, BB, InsertBefore); |
4399 | 248 | } |
4400 | | |
4401 | | static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB, |
4402 | 0 | BasicBlock *InsertAtEnd) { |
4403 | 0 | assert(CatchPad); |
4404 | 0 | assert(BB); |
4405 | 0 | return new (2) CatchReturnInst(CatchPad, BB, InsertAtEnd); |
4406 | 0 | } |
4407 | | |
4408 | | /// Provide fast operand accessors |
4409 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
4410 | | |
4411 | | /// Convenience accessors. |
4412 | 454 | CatchPadInst *getCatchPad() const { return cast<CatchPadInst>(Op<0>()); } |
4413 | 0 | void setCatchPad(CatchPadInst *CatchPad) { |
4414 | 0 | assert(CatchPad); |
4415 | 0 | Op<0>() = CatchPad; |
4416 | 0 | } |
4417 | | |
4418 | 3.33k | BasicBlock *getSuccessor() const { return cast<BasicBlock>(Op<1>()); } |
4419 | 2 | void setSuccessor(BasicBlock *NewSucc) { |
4420 | 2 | assert(NewSucc); |
4421 | 2 | Op<1>() = NewSucc; |
4422 | 2 | } |
4423 | 4.82k | unsigned getNumSuccessors() const { return 1; } |
4424 | | |
4425 | | /// Get the parentPad of this catchret's catchpad's catchswitch. |
4426 | | /// The successor block is implicitly a member of this funclet. |
4427 | 347 | Value *getCatchSwitchParentPad() const { |
4428 | 347 | return getCatchPad()->getCatchSwitch()->getParentPad(); |
4429 | 347 | } |
4430 | | |
4431 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
4432 | 1.24M | static bool classof(const Instruction *I) { |
4433 | 1.24M | return (I->getOpcode() == Instruction::CatchRet); |
4434 | 1.24M | } |
4435 | 486 | static bool classof(const Value *V) { |
4436 | 486 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4437 | 486 | } |
4438 | | |
4439 | | private: |
4440 | | friend TerminatorInst; |
4441 | | |
4442 | 3.24k | BasicBlock *getSuccessor(unsigned Idx) const { |
4443 | 3.24k | assert(Idx < getNumSuccessors() && "Successor # out of range for catchret!"); |
4444 | 3.24k | return getSuccessor(); |
4445 | 3.24k | } |
4446 | | |
4447 | 0 | void setSuccessor(unsigned Idx, BasicBlock *B) { |
4448 | 0 | assert(Idx < getNumSuccessors() && "Successor # out of range for catchret!"); |
4449 | 0 | setSuccessor(B); |
4450 | 0 | } |
4451 | | }; |
4452 | | |
4453 | | template <> |
4454 | | struct OperandTraits<CatchReturnInst> |
4455 | | : public FixedNumOperandTraits<CatchReturnInst, 2> {}; |
4456 | | |
4457 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchReturnInst, Value) |
4458 | | |
4459 | | //===----------------------------------------------------------------------===// |
4460 | | // CleanupReturnInst Class |
4461 | | //===----------------------------------------------------------------------===// |
4462 | | |
4463 | | class CleanupReturnInst : public TerminatorInst { |
4464 | | private: |
4465 | | CleanupReturnInst(const CleanupReturnInst &RI); |
4466 | | CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values, |
4467 | | Instruction *InsertBefore = nullptr); |
4468 | | CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values, |
4469 | | BasicBlock *InsertAtEnd); |
4470 | | |
4471 | | void init(Value *CleanupPad, BasicBlock *UnwindBB); |
4472 | | |
4473 | | protected: |
4474 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
4475 | | friend class Instruction; |
4476 | | |
4477 | | CleanupReturnInst *cloneImpl() const; |
4478 | | |
4479 | | public: |
4480 | | static CleanupReturnInst *Create(Value *CleanupPad, |
4481 | | BasicBlock *UnwindBB = nullptr, |
4482 | 277 | Instruction *InsertBefore = nullptr) { |
4483 | 277 | assert(CleanupPad); |
4484 | 277 | unsigned Values = 1; |
4485 | 277 | if (UnwindBB) |
4486 | 94 | ++Values; |
4487 | 277 | return new (Values) |
4488 | 277 | CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertBefore); |
4489 | 277 | } |
4490 | | |
4491 | | static CleanupReturnInst *Create(Value *CleanupPad, BasicBlock *UnwindBB, |
4492 | 7 | BasicBlock *InsertAtEnd) { |
4493 | 7 | assert(CleanupPad); |
4494 | 7 | unsigned Values = 1; |
4495 | 7 | if (UnwindBB) |
4496 | 7 | ++Values; |
4497 | 7 | return new (Values) |
4498 | 7 | CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertAtEnd); |
4499 | 7 | } |
4500 | | |
4501 | | /// Provide fast operand accessors |
4502 | | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
4503 | | |
4504 | 4.75k | bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; } |
4505 | 55 | bool unwindsToCaller() const { return !hasUnwindDest(); } |
4506 | | |
4507 | | /// Convenience accessor. |
4508 | 158 | CleanupPadInst *getCleanupPad() const { |
4509 | 158 | return cast<CleanupPadInst>(Op<0>()); |
4510 | 158 | } |
4511 | 0 | void setCleanupPad(CleanupPadInst *CleanupPad) { |
4512 | 0 | assert(CleanupPad); |
4513 | 0 | Op<0>() = CleanupPad; |
4514 | 0 | } |
4515 | | |
4516 | 2.45k | unsigned getNumSuccessors() const { return hasUnwindDest() ? 2.45k 1954 : 01.50k ; } |
4517 | | |
4518 | 1.94k | BasicBlock *getUnwindDest() const { |
4519 | 1.94k | return hasUnwindDest() ? cast<BasicBlock>(Op<1>())1.26k : nullptr687 ; |
4520 | 1.94k | } |
4521 | 0 | void setUnwindDest(BasicBlock *NewDest) { |
4522 | 0 | assert(NewDest); |
4523 | 0 | assert(hasUnwindDest()); |
4524 | 0 | Op<1>() = NewDest; |
4525 | 0 | } |
4526 | | |
4527 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
4528 | 191M | static bool classof(const Instruction *I) { |
4529 | 191M | return (I->getOpcode() == Instruction::CleanupRet); |
4530 | 191M | } |
4531 | 2.45k | static bool classof(const Value *V) { |
4532 | 2.45k | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4533 | 2.45k | } |
4534 | | |
4535 | | private: |
4536 | | friend TerminatorInst; |
4537 | | |
4538 | 692 | BasicBlock *getSuccessor(unsigned Idx) const { |
4539 | 692 | assert(Idx == 0); |
4540 | 692 | return getUnwindDest(); |
4541 | 692 | } |
4542 | | |
4543 | 0 | void setSuccessor(unsigned Idx, BasicBlock *B) { |
4544 | 0 | assert(Idx == 0); |
4545 | 0 | setUnwindDest(B); |
4546 | 0 | } |
4547 | | |
4548 | | // Shadow Instruction::setInstructionSubclassData with a private forwarding |
4549 | | // method so that subclasses cannot accidentally use it. |
4550 | 158 | void setInstructionSubclassData(unsigned short D) { |
4551 | 158 | Instruction::setInstructionSubclassData(D); |
4552 | 158 | } |
4553 | | }; |
4554 | | |
4555 | | template <> |
4556 | | struct OperandTraits<CleanupReturnInst> |
4557 | | : public VariadicOperandTraits<CleanupReturnInst, /*MINARITY=*/1> {}; |
4558 | | |
4559 | | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CleanupReturnInst, Value) |
4560 | | |
4561 | | //===----------------------------------------------------------------------===// |
4562 | | // UnreachableInst Class |
4563 | | //===----------------------------------------------------------------------===// |
4564 | | |
4565 | | //===--------------------------------------------------------------------------- |
4566 | | /// This function has undefined behavior. In particular, the |
4567 | | /// presence of this instruction indicates some higher level knowledge that the |
4568 | | /// end of the block cannot be reached. |
4569 | | /// |
4570 | | class UnreachableInst : public TerminatorInst { |
4571 | | protected: |
4572 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
4573 | | friend class Instruction; |
4574 | | |
4575 | | UnreachableInst *cloneImpl() const; |
4576 | | |
4577 | | public: |
4578 | | explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = nullptr); |
4579 | | explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd); |
4580 | | |
4581 | | // allocate space for exactly zero operands |
4582 | 2.03M | void *operator new(size_t s) { |
4583 | 2.03M | return User::operator new(s, 0); |
4584 | 2.03M | } |
4585 | | |
4586 | 5.46M | unsigned getNumSuccessors() const { return 0; } |
4587 | | |
4588 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
4589 | 46.6M | static bool classof(const Instruction *I) { |
4590 | 46.6M | return I->getOpcode() == Instruction::Unreachable; |
4591 | 46.6M | } |
4592 | 0 | static bool classof(const Value *V) { |
4593 | 0 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4594 | 0 | } |
4595 | | |
4596 | | private: |
4597 | | friend TerminatorInst; |
4598 | | |
4599 | 0 | BasicBlock *getSuccessor(unsigned idx) const { |
4600 | 0 | llvm_unreachable("UnreachableInst has no successors!"); |
4601 | 0 | } |
4602 | | |
4603 | 0 | void setSuccessor(unsigned idx, BasicBlock *B) { |
4604 | 0 | llvm_unreachable("UnreachableInst has no successors!"); |
4605 | 0 | } |
4606 | | }; |
4607 | | |
4608 | | //===----------------------------------------------------------------------===// |
4609 | | // TruncInst Class |
4610 | | //===----------------------------------------------------------------------===// |
4611 | | |
4612 | | /// This class represents a truncation of integer types. |
4613 | | class TruncInst : public CastInst { |
4614 | | protected: |
4615 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
4616 | | friend class Instruction; |
4617 | | |
4618 | | /// Clone an identical TruncInst |
4619 | | TruncInst *cloneImpl() const; |
4620 | | |
4621 | | public: |
4622 | | /// Constructor with insert-before-instruction semantics |
4623 | | TruncInst( |
4624 | | Value *S, ///< The value to be truncated |
4625 | | Type *Ty, ///< The (smaller) type to truncate to |
4626 | | const Twine &NameStr = "", ///< A name for the new instruction |
4627 | | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction |
4628 | | ); |
4629 | | |
4630 | | /// Constructor with insert-at-end-of-block semantics |
4631 | | TruncInst( |
4632 | | Value *S, ///< The value to be truncated |
4633 | | Type *Ty, ///< The (smaller) type to truncate to |
4634 | | const Twine &NameStr, ///< A name for the new instruction |
4635 | | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
4636 | | ); |
4637 | | |
4638 | | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
4639 | 31.0M | static bool classof(const Instruction *I) { |
4640 | 31.0M | return I->getOpcode() == Trunc; |
4641 | 31.0M | } |
4642 | 17.2M | static bool classof(const Value *V) { |
4643 | 16.1M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4644 | 17.2M | } |
4645 | | }; |
4646 | | |
4647 | | //===----------------------------------------------------------------------===// |
4648 | | // ZExtInst Class |
4649 | | //===----------------------------------------------------------------------===// |
4650 | | |
4651 | | /// This class represents zero extension of integer types. |
4652 | | class ZExtInst : public CastInst { |
4653 | | protected: |
4654 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
4655 | | friend class Instruction; |
4656 | | |
4657 | | /// Clone an identical ZExtInst |
4658 | | ZExtInst *cloneImpl() const; |
4659 | | |
4660 | | public: |
4661 | | /// Constructor with insert-before-instruction semantics |
4662 | | ZExtInst( |
4663 | | Value *S, ///< The value to be zero extended |
4664 | | Type *Ty, ///< The type to zero extend to |
4665 | | const Twine &NameStr = "", ///< A name for the new instruction |
4666 | | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction |
4667 | | ); |
4668 | | |
4669 | | /// Constructor with insert-at-end semantics. |
4670 | | ZExtInst( |
4671 | | Value *S, ///< The value to be zero extended |
4672 | | Type *Ty, ///< The type to zero extend to |
4673 | | const Twine &NameStr, ///< A name for the new instruction |
4674 | | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
4675 | | ); |
4676 | | |
4677 | | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
4678 | 124M | static bool classof(const Instruction *I) { |
4679 | 124M | return I->getOpcode() == ZExt; |
4680 | 124M | } |
4681 | 130M | static bool classof(const Value *V) { |
4682 | 107M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4683 | 130M | } |
4684 | | }; |
4685 | | |
4686 | | //===----------------------------------------------------------------------===// |
4687 | | // SExtInst Class |
4688 | | //===----------------------------------------------------------------------===// |
4689 | | |
4690 | | /// This class represents a sign extension of integer types. |
4691 | | class SExtInst : public CastInst { |
4692 | | protected: |
4693 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
4694 | | friend class Instruction; |
4695 | | |
4696 | | /// Clone an identical SExtInst |
4697 | | SExtInst *cloneImpl() const; |
4698 | | |
4699 | | public: |
4700 | | /// Constructor with insert-before-instruction semantics |
4701 | | SExtInst( |
4702 | | Value *S, ///< The value to be sign extended |
4703 | | Type *Ty, ///< The type to sign extend to |
4704 | | const Twine &NameStr = "", ///< A name for the new instruction |
4705 | | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction |
4706 | | ); |
4707 | | |
4708 | | /// Constructor with insert-at-end-of-block semantics |
4709 | | SExtInst( |
4710 | | Value *S, ///< The value to be sign extended |
4711 | | Type *Ty, ///< The type to sign extend to |
4712 | | const Twine &NameStr, ///< A name for the new instruction |
4713 | | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
4714 | | ); |
4715 | | |
4716 | | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
4717 | 126M | static bool classof(const Instruction *I) { |
4718 | 126M | return I->getOpcode() == SExt; |
4719 | 126M | } |
4720 | 126M | static bool classof(const Value *V) { |
4721 | 106M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4722 | 126M | } |
4723 | | }; |
4724 | | |
4725 | | //===----------------------------------------------------------------------===// |
4726 | | // FPTruncInst Class |
4727 | | //===----------------------------------------------------------------------===// |
4728 | | |
4729 | | /// This class represents a truncation of floating point types. |
4730 | | class FPTruncInst : public CastInst { |
4731 | | protected: |
4732 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
4733 | | friend class Instruction; |
4734 | | |
4735 | | /// Clone an identical FPTruncInst |
4736 | | FPTruncInst *cloneImpl() const; |
4737 | | |
4738 | | public: |
4739 | | /// Constructor with insert-before-instruction semantics |
4740 | | FPTruncInst( |
4741 | | Value *S, ///< The value to be truncated |
4742 | | Type *Ty, ///< The type to truncate to |
4743 | | const Twine &NameStr = "", ///< A name for the new instruction |
4744 | | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction |
4745 | | ); |
4746 | | |
4747 | | /// Constructor with insert-before-instruction semantics |
4748 | | FPTruncInst( |
4749 | | Value *S, ///< The value to be truncated |
4750 | | Type *Ty, ///< The type to truncate to |
4751 | | const Twine &NameStr, ///< A name for the new instruction |
4752 | | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
4753 | | ); |
4754 | | |
4755 | | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
4756 | 157k | static bool classof(const Instruction *I) { |
4757 | 157k | return I->getOpcode() == FPTrunc; |
4758 | 157k | } |
4759 | 191k | static bool classof(const Value *V) { |
4760 | 157k | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4761 | 191k | } |
4762 | | }; |
4763 | | |
4764 | | //===----------------------------------------------------------------------===// |
4765 | | // FPExtInst Class |
4766 | | //===----------------------------------------------------------------------===// |
4767 | | |
4768 | | /// This class represents an extension of floating point types. |
4769 | | class FPExtInst : public CastInst { |
4770 | | protected: |
4771 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
4772 | | friend class Instruction; |
4773 | | |
4774 | | /// Clone an identical FPExtInst |
4775 | | FPExtInst *cloneImpl() const; |
4776 | | |
4777 | | public: |
4778 | | /// Constructor with insert-before-instruction semantics |
4779 | | FPExtInst( |
4780 | | Value *S, ///< The value to be extended |
4781 | | Type *Ty, ///< The type to extend to |
4782 | | const Twine &NameStr = "", ///< A name for the new instruction |
4783 | | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction |
4784 | | ); |
4785 | | |
4786 | | /// Constructor with insert-at-end-of-block semantics |
4787 | | FPExtInst( |
4788 | | Value *S, ///< The value to be extended |
4789 | | Type *Ty, ///< The type to extend to |
4790 | | const Twine &NameStr, ///< A name for the new instruction |
4791 | | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
4792 | | ); |
4793 | | |
4794 | | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
4795 | 6.62M | static bool classof(const Instruction *I) { |
4796 | 6.62M | return I->getOpcode() == FPExt; |
4797 | 6.62M | } |
4798 | 734k | static bool classof(const Value *V) { |
4799 | 682k | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4800 | 734k | } |
4801 | | }; |
4802 | | |
4803 | | //===----------------------------------------------------------------------===// |
4804 | | // UIToFPInst Class |
4805 | | //===----------------------------------------------------------------------===// |
4806 | | |
4807 | | /// This class represents a cast unsigned integer to floating point. |
4808 | | class UIToFPInst : public CastInst { |
4809 | | protected: |
4810 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
4811 | | friend class Instruction; |
4812 | | |
4813 | | /// Clone an identical UIToFPInst |
4814 | | UIToFPInst *cloneImpl() const; |
4815 | | |
4816 | | public: |
4817 | | /// Constructor with insert-before-instruction semantics |
4818 | | UIToFPInst( |
4819 | | Value *S, ///< The value to be converted |
4820 | | Type *Ty, ///< The type to convert to |
4821 | | const Twine &NameStr = "", ///< A name for the new instruction |
4822 | | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction |
4823 | | ); |
4824 | | |
4825 | | /// Constructor with insert-at-end-of-block semantics |
4826 | | UIToFPInst( |
4827 | | Value *S, ///< The value to be converted |
4828 | | Type *Ty, ///< The type to convert to |
4829 | | const Twine &NameStr, ///< A name for the new instruction |
4830 | | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
4831 | | ); |
4832 | | |
4833 | | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
4834 | 669k | static bool classof(const Instruction *I) { |
4835 | 669k | return I->getOpcode() == UIToFP; |
4836 | 669k | } |
4837 | 135k | static bool classof(const Value *V) { |
4838 | 135k | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4839 | 135k | } |
4840 | | }; |
4841 | | |
4842 | | //===----------------------------------------------------------------------===// |
4843 | | // SIToFPInst Class |
4844 | | //===----------------------------------------------------------------------===// |
4845 | | |
4846 | | /// This class represents a cast from signed integer to floating point. |
4847 | | class SIToFPInst : public CastInst { |
4848 | | protected: |
4849 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
4850 | | friend class Instruction; |
4851 | | |
4852 | | /// Clone an identical SIToFPInst |
4853 | | SIToFPInst *cloneImpl() const; |
4854 | | |
4855 | | public: |
4856 | | /// Constructor with insert-before-instruction semantics |
4857 | | SIToFPInst( |
4858 | | Value *S, ///< The value to be converted |
4859 | | Type *Ty, ///< The type to convert to |
4860 | | const Twine &NameStr = "", ///< A name for the new instruction |
4861 | | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction |
4862 | | ); |
4863 | | |
4864 | | /// Constructor with insert-at-end-of-block semantics |
4865 | | SIToFPInst( |
4866 | | Value *S, ///< The value to be converted |
4867 | | Type *Ty, ///< The type to convert to |
4868 | | const Twine &NameStr, ///< A name for the new instruction |
4869 | | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
4870 | | ); |
4871 | | |
4872 | | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
4873 | 1.37M | static bool classof(const Instruction *I) { |
4874 | 1.37M | return I->getOpcode() == SIToFP; |
4875 | 1.37M | } |
4876 | 842k | static bool classof(const Value *V) { |
4877 | 837k | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4878 | 842k | } |
4879 | | }; |
4880 | | |
4881 | | //===----------------------------------------------------------------------===// |
4882 | | // FPToUIInst Class |
4883 | | //===----------------------------------------------------------------------===// |
4884 | | |
4885 | | /// This class represents a cast from floating point to unsigned integer |
4886 | | class FPToUIInst : public CastInst { |
4887 | | protected: |
4888 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
4889 | | friend class Instruction; |
4890 | | |
4891 | | /// Clone an identical FPToUIInst |
4892 | | FPToUIInst *cloneImpl() const; |
4893 | | |
4894 | | public: |
4895 | | /// Constructor with insert-before-instruction semantics |
4896 | | FPToUIInst( |
4897 | | Value *S, ///< The value to be converted |
4898 | | Type *Ty, ///< The type to convert to |
4899 | | const Twine &NameStr = "", ///< A name for the new instruction |
4900 | | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction |
4901 | | ); |
4902 | | |
4903 | | /// Constructor with insert-at-end-of-block semantics |
4904 | | FPToUIInst( |
4905 | | Value *S, ///< The value to be converted |
4906 | | Type *Ty, ///< The type to convert to |
4907 | | const Twine &NameStr, ///< A name for the new instruction |
4908 | | BasicBlock *InsertAtEnd ///< Where to insert the new instruction |
4909 | | ); |
4910 | | |
4911 | | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
4912 | 4.02k | static bool classof(const Instruction *I) { |
4913 | 4.02k | return I->getOpcode() == FPToUI; |
4914 | 4.02k | } |
4915 | 0 | static bool classof(const Value *V) { |
4916 | 0 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4917 | 0 | } |
4918 | | }; |
4919 | | |
4920 | | //===----------------------------------------------------------------------===// |
4921 | | // FPToSIInst Class |
4922 | | //===----------------------------------------------------------------------===// |
4923 | | |
4924 | | /// This class represents a cast from floating point to signed integer. |
4925 | | class FPToSIInst : public CastInst { |
4926 | | protected: |
4927 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
4928 | | friend class Instruction; |
4929 | | |
4930 | | /// Clone an identical FPToSIInst |
4931 | | FPToSIInst *cloneImpl() const; |
4932 | | |
4933 | | public: |
4934 | | /// Constructor with insert-before-instruction semantics |
4935 | | FPToSIInst( |
4936 | | Value *S, ///< The value to be converted |
4937 | | Type *Ty, ///< The type to convert to |
4938 | | const Twine &NameStr = "", ///< A name for the new instruction |
4939 | | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction |
4940 | | ); |
4941 | | |
4942 | | /// Constructor with insert-at-end-of-block semantics |
4943 | | FPToSIInst( |
4944 | | Value *S, ///< The value to be converted |
4945 | | Type *Ty, ///< The type to convert to |
4946 | | const Twine &NameStr, ///< A name for the new instruction |
4947 | | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
4948 | | ); |
4949 | | |
4950 | | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
4951 | 4.23k | static bool classof(const Instruction *I) { |
4952 | 4.23k | return I->getOpcode() == FPToSI; |
4953 | 4.23k | } |
4954 | 0 | static bool classof(const Value *V) { |
4955 | 0 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4956 | 0 | } |
4957 | | }; |
4958 | | |
4959 | | //===----------------------------------------------------------------------===// |
4960 | | // IntToPtrInst Class |
4961 | | //===----------------------------------------------------------------------===// |
4962 | | |
4963 | | /// This class represents a cast from an integer to a pointer. |
4964 | | class IntToPtrInst : public CastInst { |
4965 | | public: |
4966 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
4967 | | friend class Instruction; |
4968 | | |
4969 | | /// Constructor with insert-before-instruction semantics |
4970 | | IntToPtrInst( |
4971 | | Value *S, ///< The value to be converted |
4972 | | Type *Ty, ///< The type to convert to |
4973 | | const Twine &NameStr = "", ///< A name for the new instruction |
4974 | | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction |
4975 | | ); |
4976 | | |
4977 | | /// Constructor with insert-at-end-of-block semantics |
4978 | | IntToPtrInst( |
4979 | | Value *S, ///< The value to be converted |
4980 | | Type *Ty, ///< The type to convert to |
4981 | | const Twine &NameStr, ///< A name for the new instruction |
4982 | | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
4983 | | ); |
4984 | | |
4985 | | /// Clone an identical IntToPtrInst. |
4986 | | IntToPtrInst *cloneImpl() const; |
4987 | | |
4988 | | /// Returns the address space of this instruction's pointer type. |
4989 | 462k | unsigned getAddressSpace() const { |
4990 | 462k | return getType()->getPointerAddressSpace(); |
4991 | 462k | } |
4992 | | |
4993 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
4994 | 985k | static bool classof(const Instruction *I) { |
4995 | 985k | return I->getOpcode() == IntToPtr; |
4996 | 985k | } |
4997 | 637k | static bool classof(const Value *V) { |
4998 | 537k | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
4999 | 637k | } |
5000 | | }; |
5001 | | |
5002 | | //===----------------------------------------------------------------------===// |
5003 | | // PtrToIntInst Class |
5004 | | //===----------------------------------------------------------------------===// |
5005 | | |
5006 | | /// This class represents a cast from a pointer to an integer. |
5007 | | class PtrToIntInst : public CastInst { |
5008 | | protected: |
5009 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
5010 | | friend class Instruction; |
5011 | | |
5012 | | /// Clone an identical PtrToIntInst. |
5013 | | PtrToIntInst *cloneImpl() const; |
5014 | | |
5015 | | public: |
5016 | | /// Constructor with insert-before-instruction semantics |
5017 | | PtrToIntInst( |
5018 | | Value *S, ///< The value to be converted |
5019 | | Type *Ty, ///< The type to convert to |
5020 | | const Twine &NameStr = "", ///< A name for the new instruction |
5021 | | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction |
5022 | | ); |
5023 | | |
5024 | | /// Constructor with insert-at-end-of-block semantics |
5025 | | PtrToIntInst( |
5026 | | Value *S, ///< The value to be converted |
5027 | | Type *Ty, ///< The type to convert to |
5028 | | const Twine &NameStr, ///< A name for the new instruction |
5029 | | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
5030 | | ); |
5031 | | |
5032 | | /// Gets the pointer operand. |
5033 | 1.03k | Value *getPointerOperand() { return getOperand(0); } |
5034 | | /// Gets the pointer operand. |
5035 | 882k | const Value *getPointerOperand() const { return getOperand(0); } |
5036 | | /// Gets the operand index of the pointer operand. |
5037 | 0 | static unsigned getPointerOperandIndex() { return 0U; } |
5038 | | |
5039 | | /// Returns the address space of the pointer operand. |
5040 | 882k | unsigned getPointerAddressSpace() const { |
5041 | 882k | return getPointerOperand()->getType()->getPointerAddressSpace(); |
5042 | 882k | } |
5043 | | |
5044 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
5045 | 19.7M | static bool classof(const Instruction *I) { |
5046 | 19.7M | return I->getOpcode() == PtrToInt; |
5047 | 19.7M | } |
5048 | 25.9M | static bool classof(const Value *V) { |
5049 | 17.9M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
5050 | 25.9M | } |
5051 | | }; |
5052 | | |
5053 | | //===----------------------------------------------------------------------===// |
5054 | | // BitCastInst Class |
5055 | | //===----------------------------------------------------------------------===// |
5056 | | |
5057 | | /// This class represents a no-op cast from one type to another. |
5058 | | class BitCastInst : public CastInst { |
5059 | | protected: |
5060 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
5061 | | friend class Instruction; |
5062 | | |
5063 | | /// Clone an identical BitCastInst. |
5064 | | BitCastInst *cloneImpl() const; |
5065 | | |
5066 | | public: |
5067 | | /// Constructor with insert-before-instruction semantics |
5068 | | BitCastInst( |
5069 | | Value *S, ///< The value to be casted |
5070 | | Type *Ty, ///< The type to casted to |
5071 | | const Twine &NameStr = "", ///< A name for the new instruction |
5072 | | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction |
5073 | | ); |
5074 | | |
5075 | | /// Constructor with insert-at-end-of-block semantics |
5076 | | BitCastInst( |
5077 | | Value *S, ///< The value to be casted |
5078 | | Type *Ty, ///< The type to casted to |
5079 | | const Twine &NameStr, ///< A name for the new instruction |
5080 | | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
5081 | | ); |
5082 | | |
5083 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
5084 | 126M | static bool classof(const Instruction *I) { |
5085 | 126M | return I->getOpcode() == BitCast; |
5086 | 126M | } |
5087 | 72.4M | static bool classof(const Value *V) { |
5088 | 50.4M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
5089 | 72.4M | } |
5090 | | }; |
5091 | | |
5092 | | //===----------------------------------------------------------------------===// |
5093 | | // AddrSpaceCastInst Class |
5094 | | //===----------------------------------------------------------------------===// |
5095 | | |
5096 | | /// This class represents a conversion between pointers from one address space |
5097 | | /// to another. |
5098 | | class AddrSpaceCastInst : public CastInst { |
5099 | | protected: |
5100 | | // Note: Instruction needs to be a friend here to call cloneImpl. |
5101 | | friend class Instruction; |
5102 | | |
5103 | | /// Clone an identical AddrSpaceCastInst. |
5104 | | AddrSpaceCastInst *cloneImpl() const; |
5105 | | |
5106 | | public: |
5107 | | /// Constructor with insert-before-instruction semantics |
5108 | | AddrSpaceCastInst( |
5109 | | Value *S, ///< The value to be casted |
5110 | | Type *Ty, ///< The type to casted to |
5111 | | const Twine &NameStr = "", ///< A name for the new instruction |
5112 | | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction |
5113 | | ); |
5114 | | |
5115 | | /// Constructor with insert-at-end-of-block semantics |
5116 | | AddrSpaceCastInst( |
5117 | | Value *S, ///< The value to be casted |
5118 | | Type *Ty, ///< The type to casted to |
5119 | | const Twine &NameStr, ///< A name for the new instruction |
5120 | | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
5121 | | ); |
5122 | | |
5123 | | // Methods for support type inquiry through isa, cast, and dyn_cast: |
5124 | 36.2M | static bool classof(const Instruction *I) { |
5125 | 36.2M | return I->getOpcode() == AddrSpaceCast; |
5126 | 36.2M | } |
5127 | 29.6M | static bool classof(const Value *V) { |
5128 | 18.1M | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
5129 | 29.6M | } |
5130 | | |
5131 | | /// Gets the pointer operand. |
5132 | 501 | Value *getPointerOperand() { |
5133 | 501 | return getOperand(0); |
5134 | 501 | } |
5135 | | |
5136 | | /// Gets the pointer operand. |
5137 | 347 | const Value *getPointerOperand() const { |
5138 | 347 | return getOperand(0); |
5139 | 347 | } |
5140 | | |
5141 | | /// Gets the operand index of the pointer operand. |
5142 | 0 | static unsigned getPointerOperandIndex() { |
5143 | 0 | return 0U; |
5144 | 0 | } |
5145 | | |
5146 | | /// Returns the address space of the pointer operand. |
5147 | 347 | unsigned getSrcAddressSpace() const { |
5148 | 347 | return getPointerOperand()->getType()->getPointerAddressSpace(); |
5149 | 347 | } |
5150 | | |
5151 | | /// Returns the address space of the result. |
5152 | 283 | unsigned getDestAddressSpace() const { |
5153 | 283 | return getType()->getPointerAddressSpace(); |
5154 | 283 | } |
5155 | | }; |
5156 | | |
5157 | | } // end namespace llvm |
5158 | | |
5159 | | #endif // LLVM_IR_INSTRUCTIONS_H |