]>
Commit | Line | Data |
---|---|---|
223e47cc LB |
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 | ||
970d7e83 LB |
16 | #ifndef LLVM_IR_INSTRUCTIONS_H |
17 | #define LLVM_IR_INSTRUCTIONS_H | |
223e47cc | 18 | |
223e47cc LB |
19 | #include "llvm/ADT/ArrayRef.h" |
20 | #include "llvm/ADT/SmallVector.h" | |
85aaf69f | 21 | #include "llvm/ADT/iterator_range.h" |
970d7e83 LB |
22 | #include "llvm/IR/Attributes.h" |
23 | #include "llvm/IR/CallingConv.h" | |
24 | #include "llvm/IR/DerivedTypes.h" | |
25 | #include "llvm/IR/InstrTypes.h" | |
223e47cc LB |
26 | #include "llvm/Support/ErrorHandling.h" |
27 | #include <iterator> | |
28 | ||
29 | namespace llvm { | |
30 | ||
970d7e83 | 31 | class APInt; |
223e47cc LB |
32 | class ConstantInt; |
33 | class ConstantRange; | |
970d7e83 | 34 | class DataLayout; |
223e47cc LB |
35 | class LLVMContext; |
36 | ||
37 | enum AtomicOrdering { | |
38 | NotAtomic = 0, | |
39 | Unordered = 1, | |
40 | Monotonic = 2, | |
41 | // Consume = 3, // Not specified yet. | |
42 | Acquire = 4, | |
43 | Release = 5, | |
44 | AcquireRelease = 6, | |
45 | SequentiallyConsistent = 7 | |
46 | }; | |
47 | ||
48 | enum SynchronizationScope { | |
49 | SingleThread = 0, | |
50 | CrossThread = 1 | |
51 | }; | |
52 | ||
1a4d82fc JJ |
53 | /// Returns true if the ordering is at least as strong as acquire |
54 | /// (i.e. acquire, acq_rel or seq_cst) | |
55 | inline bool isAtLeastAcquire(AtomicOrdering Ord) { | |
56 | return (Ord == Acquire || | |
57 | Ord == AcquireRelease || | |
58 | Ord == SequentiallyConsistent); | |
59 | } | |
60 | ||
61 | /// Returns true if the ordering is at least as strong as release | |
62 | /// (i.e. release, acq_rel or seq_cst) | |
63 | inline bool isAtLeastRelease(AtomicOrdering Ord) { | |
64 | return (Ord == Release || | |
65 | Ord == AcquireRelease || | |
66 | Ord == SequentiallyConsistent); | |
67 | } | |
68 | ||
223e47cc LB |
69 | //===----------------------------------------------------------------------===// |
70 | // AllocaInst Class | |
71 | //===----------------------------------------------------------------------===// | |
72 | ||
73 | /// AllocaInst - an instruction to allocate memory on the stack | |
74 | /// | |
75 | class AllocaInst : public UnaryInstruction { | |
76 | protected: | |
1a4d82fc | 77 | AllocaInst *clone_impl() const override; |
223e47cc | 78 | public: |
1a4d82fc JJ |
79 | explicit AllocaInst(Type *Ty, Value *ArraySize = nullptr, |
80 | const Twine &Name = "", | |
81 | Instruction *InsertBefore = nullptr); | |
223e47cc LB |
82 | AllocaInst(Type *Ty, Value *ArraySize, |
83 | const Twine &Name, BasicBlock *InsertAtEnd); | |
84 | ||
1a4d82fc | 85 | AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = nullptr); |
223e47cc LB |
86 | AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd); |
87 | ||
88 | AllocaInst(Type *Ty, Value *ArraySize, unsigned Align, | |
1a4d82fc | 89 | const Twine &Name = "", Instruction *InsertBefore = nullptr); |
223e47cc LB |
90 | AllocaInst(Type *Ty, Value *ArraySize, unsigned Align, |
91 | const Twine &Name, BasicBlock *InsertAtEnd); | |
92 | ||
93 | // Out of line virtual method, so the vtable, etc. has a home. | |
94 | virtual ~AllocaInst(); | |
95 | ||
96 | /// isArrayAllocation - Return true if there is an allocation size parameter | |
97 | /// to the allocation instruction that is not 1. | |
98 | /// | |
99 | bool isArrayAllocation() const; | |
100 | ||
101 | /// getArraySize - Get the number of elements allocated. For a simple | |
102 | /// allocation of a single element, this will return a constant 1 value. | |
103 | /// | |
104 | const Value *getArraySize() const { return getOperand(0); } | |
105 | Value *getArraySize() { return getOperand(0); } | |
106 | ||
107 | /// getType - Overload to return most specific pointer type | |
108 | /// | |
109 | PointerType *getType() const { | |
970d7e83 | 110 | return cast<PointerType>(Instruction::getType()); |
223e47cc LB |
111 | } |
112 | ||
113 | /// getAllocatedType - Return the type that is being allocated by the | |
114 | /// instruction. | |
115 | /// | |
116 | Type *getAllocatedType() const; | |
117 | ||
118 | /// getAlignment - Return the alignment of the memory that is being allocated | |
119 | /// by the instruction. | |
120 | /// | |
121 | unsigned getAlignment() const { | |
1a4d82fc | 122 | return (1u << (getSubclassDataFromInstruction() & 31)) >> 1; |
223e47cc LB |
123 | } |
124 | void setAlignment(unsigned Align); | |
125 | ||
126 | /// isStaticAlloca - Return true if this alloca is in the entry block of the | |
127 | /// function and is a constant size. If so, the code generator will fold it | |
128 | /// into the prolog/epilog code, so it is basically free. | |
129 | bool isStaticAlloca() const; | |
130 | ||
1a4d82fc JJ |
131 | /// \brief Return true if this alloca is used as an inalloca argument to a |
132 | /// call. Such allocas are never considered static even if they are in the | |
133 | /// entry block. | |
134 | bool isUsedWithInAlloca() const { | |
135 | return getSubclassDataFromInstruction() & 32; | |
136 | } | |
137 | ||
138 | /// \brief Specify whether this alloca is used to represent the arguments to | |
139 | /// a call. | |
140 | void setUsedWithInAlloca(bool V) { | |
141 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~32) | | |
142 | (V ? 32 : 0)); | |
143 | } | |
144 | ||
223e47cc | 145 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
146 | static inline bool classof(const Instruction *I) { |
147 | return (I->getOpcode() == Instruction::Alloca); | |
148 | } | |
149 | static inline bool classof(const Value *V) { | |
150 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
151 | } | |
152 | private: | |
153 | // Shadow Instruction::setInstructionSubclassData with a private forwarding | |
154 | // method so that subclasses cannot accidentally use it. | |
155 | void setInstructionSubclassData(unsigned short D) { | |
156 | Instruction::setInstructionSubclassData(D); | |
157 | } | |
158 | }; | |
159 | ||
160 | ||
161 | //===----------------------------------------------------------------------===// | |
162 | // LoadInst Class | |
163 | //===----------------------------------------------------------------------===// | |
164 | ||
165 | /// LoadInst - an instruction for reading from memory. This uses the | |
166 | /// SubclassData field in Value to store whether or not the load is volatile. | |
167 | /// | |
168 | class LoadInst : public UnaryInstruction { | |
169 | void AssertOK(); | |
170 | protected: | |
1a4d82fc | 171 | LoadInst *clone_impl() const override; |
223e47cc LB |
172 | public: |
173 | LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore); | |
174 | LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd); | |
175 | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false, | |
1a4d82fc | 176 | Instruction *InsertBefore = nullptr); |
223e47cc LB |
177 | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, |
178 | BasicBlock *InsertAtEnd); | |
179 | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, | |
1a4d82fc | 180 | unsigned Align, Instruction *InsertBefore = nullptr); |
223e47cc LB |
181 | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, |
182 | unsigned Align, BasicBlock *InsertAtEnd); | |
183 | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, | |
184 | unsigned Align, AtomicOrdering Order, | |
185 | SynchronizationScope SynchScope = CrossThread, | |
1a4d82fc | 186 | Instruction *InsertBefore = nullptr); |
223e47cc LB |
187 | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, |
188 | unsigned Align, AtomicOrdering Order, | |
189 | SynchronizationScope SynchScope, | |
190 | BasicBlock *InsertAtEnd); | |
191 | ||
192 | LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore); | |
193 | LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd); | |
1a4d82fc JJ |
194 | explicit LoadInst(Value *Ptr, const char *NameStr = nullptr, |
195 | bool isVolatile = false, | |
196 | Instruction *InsertBefore = nullptr); | |
223e47cc LB |
197 | LoadInst(Value *Ptr, const char *NameStr, bool isVolatile, |
198 | BasicBlock *InsertAtEnd); | |
199 | ||
200 | /// isVolatile - Return true if this is a load from a volatile memory | |
201 | /// location. | |
202 | /// | |
203 | bool isVolatile() const { return getSubclassDataFromInstruction() & 1; } | |
204 | ||
205 | /// setVolatile - Specify whether this is a volatile load or not. | |
206 | /// | |
207 | void setVolatile(bool V) { | |
208 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | | |
209 | (V ? 1 : 0)); | |
210 | } | |
211 | ||
212 | /// getAlignment - Return the alignment of the access that is being performed | |
213 | /// | |
214 | unsigned getAlignment() const { | |
215 | return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1; | |
216 | } | |
217 | ||
218 | void setAlignment(unsigned Align); | |
219 | ||
220 | /// Returns the ordering effect of this fence. | |
221 | AtomicOrdering getOrdering() const { | |
222 | return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7); | |
223 | } | |
224 | ||
225 | /// Set the ordering constraint on this load. May not be Release or | |
226 | /// AcquireRelease. | |
227 | void setOrdering(AtomicOrdering Ordering) { | |
228 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) | | |
229 | (Ordering << 7)); | |
230 | } | |
231 | ||
232 | SynchronizationScope getSynchScope() const { | |
233 | return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1); | |
234 | } | |
235 | ||
236 | /// Specify whether this load is ordered with respect to all | |
237 | /// concurrently executing threads, or only with respect to signal handlers | |
238 | /// executing in the same thread. | |
239 | void setSynchScope(SynchronizationScope xthread) { | |
240 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) | | |
241 | (xthread << 6)); | |
242 | } | |
243 | ||
223e47cc LB |
244 | void setAtomic(AtomicOrdering Ordering, |
245 | SynchronizationScope SynchScope = CrossThread) { | |
246 | setOrdering(Ordering); | |
247 | setSynchScope(SynchScope); | |
248 | } | |
249 | ||
250 | bool isSimple() const { return !isAtomic() && !isVolatile(); } | |
251 | bool isUnordered() const { | |
252 | return getOrdering() <= Unordered && !isVolatile(); | |
253 | } | |
254 | ||
255 | Value *getPointerOperand() { return getOperand(0); } | |
256 | const Value *getPointerOperand() const { return getOperand(0); } | |
257 | static unsigned getPointerOperandIndex() { return 0U; } | |
258 | ||
970d7e83 | 259 | /// \brief Returns the address space of the pointer operand. |
223e47cc | 260 | unsigned getPointerAddressSpace() const { |
970d7e83 | 261 | return getPointerOperand()->getType()->getPointerAddressSpace(); |
223e47cc LB |
262 | } |
263 | ||
264 | ||
265 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
266 | static inline bool classof(const Instruction *I) { |
267 | return I->getOpcode() == Instruction::Load; | |
268 | } | |
269 | static inline bool classof(const Value *V) { | |
270 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
271 | } | |
272 | private: | |
273 | // Shadow Instruction::setInstructionSubclassData with a private forwarding | |
274 | // method so that subclasses cannot accidentally use it. | |
275 | void setInstructionSubclassData(unsigned short D) { | |
276 | Instruction::setInstructionSubclassData(D); | |
277 | } | |
278 | }; | |
279 | ||
280 | ||
281 | //===----------------------------------------------------------------------===// | |
282 | // StoreInst Class | |
283 | //===----------------------------------------------------------------------===// | |
284 | ||
285 | /// StoreInst - an instruction for storing to memory | |
286 | /// | |
287 | class StoreInst : public Instruction { | |
288 | void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; | |
289 | void AssertOK(); | |
290 | protected: | |
1a4d82fc | 291 | StoreInst *clone_impl() const override; |
223e47cc LB |
292 | public: |
293 | // allocate space for exactly two operands | |
294 | void *operator new(size_t s) { | |
295 | return User::operator new(s, 2); | |
296 | } | |
297 | StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore); | |
298 | StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd); | |
299 | StoreInst(Value *Val, Value *Ptr, bool isVolatile = false, | |
1a4d82fc | 300 | Instruction *InsertBefore = nullptr); |
223e47cc LB |
301 | StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd); |
302 | StoreInst(Value *Val, Value *Ptr, bool isVolatile, | |
1a4d82fc | 303 | unsigned Align, Instruction *InsertBefore = nullptr); |
223e47cc LB |
304 | StoreInst(Value *Val, Value *Ptr, bool isVolatile, |
305 | unsigned Align, BasicBlock *InsertAtEnd); | |
306 | StoreInst(Value *Val, Value *Ptr, bool isVolatile, | |
307 | unsigned Align, AtomicOrdering Order, | |
308 | SynchronizationScope SynchScope = CrossThread, | |
1a4d82fc | 309 | Instruction *InsertBefore = nullptr); |
223e47cc LB |
310 | StoreInst(Value *Val, Value *Ptr, bool isVolatile, |
311 | unsigned Align, AtomicOrdering Order, | |
312 | SynchronizationScope SynchScope, | |
313 | BasicBlock *InsertAtEnd); | |
970d7e83 | 314 | |
223e47cc LB |
315 | |
316 | /// isVolatile - Return true if this is a store to a volatile memory | |
317 | /// location. | |
318 | /// | |
319 | bool isVolatile() const { return getSubclassDataFromInstruction() & 1; } | |
320 | ||
321 | /// setVolatile - Specify whether this is a volatile store or not. | |
322 | /// | |
323 | void setVolatile(bool V) { | |
324 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | | |
325 | (V ? 1 : 0)); | |
326 | } | |
327 | ||
328 | /// Transparently provide more efficient getOperand methods. | |
329 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
330 | ||
331 | /// getAlignment - Return the alignment of the access that is being performed | |
332 | /// | |
333 | unsigned getAlignment() const { | |
334 | return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1; | |
335 | } | |
336 | ||
337 | void setAlignment(unsigned Align); | |
338 | ||
339 | /// Returns the ordering effect of this store. | |
340 | AtomicOrdering getOrdering() const { | |
341 | return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7); | |
342 | } | |
343 | ||
344 | /// Set the ordering constraint on this store. May not be Acquire or | |
345 | /// AcquireRelease. | |
346 | void setOrdering(AtomicOrdering Ordering) { | |
347 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) | | |
348 | (Ordering << 7)); | |
349 | } | |
350 | ||
351 | SynchronizationScope getSynchScope() const { | |
352 | return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1); | |
353 | } | |
354 | ||
355 | /// Specify whether this store instruction is ordered with respect to all | |
356 | /// concurrently executing threads, or only with respect to signal handlers | |
357 | /// executing in the same thread. | |
358 | void setSynchScope(SynchronizationScope xthread) { | |
359 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) | | |
360 | (xthread << 6)); | |
361 | } | |
362 | ||
223e47cc LB |
363 | void setAtomic(AtomicOrdering Ordering, |
364 | SynchronizationScope SynchScope = CrossThread) { | |
365 | setOrdering(Ordering); | |
366 | setSynchScope(SynchScope); | |
367 | } | |
368 | ||
369 | bool isSimple() const { return !isAtomic() && !isVolatile(); } | |
370 | bool isUnordered() const { | |
371 | return getOrdering() <= Unordered && !isVolatile(); | |
372 | } | |
373 | ||
374 | Value *getValueOperand() { return getOperand(0); } | |
375 | const Value *getValueOperand() const { return getOperand(0); } | |
376 | ||
377 | Value *getPointerOperand() { return getOperand(1); } | |
378 | const Value *getPointerOperand() const { return getOperand(1); } | |
379 | static unsigned getPointerOperandIndex() { return 1U; } | |
380 | ||
970d7e83 | 381 | /// \brief Returns the address space of the pointer operand. |
223e47cc | 382 | unsigned getPointerAddressSpace() const { |
970d7e83 | 383 | return getPointerOperand()->getType()->getPointerAddressSpace(); |
223e47cc LB |
384 | } |
385 | ||
386 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
387 | static inline bool classof(const Instruction *I) { |
388 | return I->getOpcode() == Instruction::Store; | |
389 | } | |
390 | static inline bool classof(const Value *V) { | |
391 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
392 | } | |
393 | private: | |
394 | // Shadow Instruction::setInstructionSubclassData with a private forwarding | |
395 | // method so that subclasses cannot accidentally use it. | |
396 | void setInstructionSubclassData(unsigned short D) { | |
397 | Instruction::setInstructionSubclassData(D); | |
398 | } | |
399 | }; | |
400 | ||
401 | template <> | |
402 | struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> { | |
403 | }; | |
404 | ||
405 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value) | |
406 | ||
407 | //===----------------------------------------------------------------------===// | |
408 | // FenceInst Class | |
409 | //===----------------------------------------------------------------------===// | |
410 | ||
411 | /// FenceInst - an instruction for ordering other memory operations | |
412 | /// | |
413 | class FenceInst : public Instruction { | |
414 | void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; | |
415 | void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope); | |
416 | protected: | |
1a4d82fc | 417 | FenceInst *clone_impl() const override; |
223e47cc LB |
418 | public: |
419 | // allocate space for exactly zero operands | |
420 | void *operator new(size_t s) { | |
421 | return User::operator new(s, 0); | |
422 | } | |
423 | ||
424 | // Ordering may only be Acquire, Release, AcquireRelease, or | |
425 | // SequentiallyConsistent. | |
426 | FenceInst(LLVMContext &C, AtomicOrdering Ordering, | |
427 | SynchronizationScope SynchScope = CrossThread, | |
1a4d82fc | 428 | Instruction *InsertBefore = nullptr); |
223e47cc LB |
429 | FenceInst(LLVMContext &C, AtomicOrdering Ordering, |
430 | SynchronizationScope SynchScope, | |
431 | BasicBlock *InsertAtEnd); | |
432 | ||
433 | /// Returns the ordering effect of this fence. | |
434 | AtomicOrdering getOrdering() const { | |
435 | return AtomicOrdering(getSubclassDataFromInstruction() >> 1); | |
436 | } | |
437 | ||
438 | /// Set the ordering constraint on this fence. May only be Acquire, Release, | |
439 | /// AcquireRelease, or SequentiallyConsistent. | |
440 | void setOrdering(AtomicOrdering Ordering) { | |
441 | setInstructionSubclassData((getSubclassDataFromInstruction() & 1) | | |
442 | (Ordering << 1)); | |
443 | } | |
444 | ||
445 | SynchronizationScope getSynchScope() const { | |
446 | return SynchronizationScope(getSubclassDataFromInstruction() & 1); | |
447 | } | |
448 | ||
449 | /// Specify whether this fence orders other operations with respect to all | |
450 | /// concurrently executing threads, or only with respect to signal handlers | |
451 | /// executing in the same thread. | |
452 | void setSynchScope(SynchronizationScope xthread) { | |
453 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | | |
454 | xthread); | |
455 | } | |
456 | ||
457 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
458 | static inline bool classof(const Instruction *I) { |
459 | return I->getOpcode() == Instruction::Fence; | |
460 | } | |
461 | static inline bool classof(const Value *V) { | |
462 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
463 | } | |
464 | private: | |
465 | // Shadow Instruction::setInstructionSubclassData with a private forwarding | |
466 | // method so that subclasses cannot accidentally use it. | |
467 | void setInstructionSubclassData(unsigned short D) { | |
468 | Instruction::setInstructionSubclassData(D); | |
469 | } | |
470 | }; | |
471 | ||
472 | //===----------------------------------------------------------------------===// | |
473 | // AtomicCmpXchgInst Class | |
474 | //===----------------------------------------------------------------------===// | |
475 | ||
476 | /// AtomicCmpXchgInst - an instruction that atomically checks whether a | |
477 | /// specified value is in a memory location, and, if it is, stores a new value | |
478 | /// there. Returns the value that was loaded. | |
479 | /// | |
480 | class AtomicCmpXchgInst : public Instruction { | |
481 | void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; | |
482 | void Init(Value *Ptr, Value *Cmp, Value *NewVal, | |
1a4d82fc JJ |
483 | AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, |
484 | SynchronizationScope SynchScope); | |
223e47cc | 485 | protected: |
1a4d82fc | 486 | AtomicCmpXchgInst *clone_impl() const override; |
223e47cc LB |
487 | public: |
488 | // allocate space for exactly three operands | |
489 | void *operator new(size_t s) { | |
490 | return User::operator new(s, 3); | |
491 | } | |
492 | AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, | |
1a4d82fc JJ |
493 | AtomicOrdering SuccessOrdering, |
494 | AtomicOrdering FailureOrdering, | |
495 | SynchronizationScope SynchScope, | |
496 | Instruction *InsertBefore = nullptr); | |
223e47cc | 497 | AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, |
1a4d82fc JJ |
498 | AtomicOrdering SuccessOrdering, |
499 | AtomicOrdering FailureOrdering, | |
500 | SynchronizationScope SynchScope, | |
223e47cc LB |
501 | BasicBlock *InsertAtEnd); |
502 | ||
503 | /// isVolatile - Return true if this is a cmpxchg from a volatile memory | |
504 | /// location. | |
505 | /// | |
506 | bool isVolatile() const { | |
507 | return getSubclassDataFromInstruction() & 1; | |
508 | } | |
509 | ||
510 | /// setVolatile - Specify whether this is a volatile cmpxchg. | |
511 | /// | |
512 | void setVolatile(bool V) { | |
513 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | | |
514 | (unsigned)V); | |
515 | } | |
516 | ||
1a4d82fc JJ |
517 | /// Return true if this cmpxchg may spuriously fail. |
518 | bool isWeak() const { | |
519 | return getSubclassDataFromInstruction() & 0x100; | |
520 | } | |
521 | ||
522 | void setWeak(bool IsWeak) { | |
523 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x100) | | |
524 | (IsWeak << 8)); | |
525 | } | |
526 | ||
223e47cc LB |
527 | /// Transparently provide more efficient getOperand methods. |
528 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
529 | ||
530 | /// Set the ordering constraint on this cmpxchg. | |
1a4d82fc | 531 | void setSuccessOrdering(AtomicOrdering Ordering) { |
223e47cc LB |
532 | assert(Ordering != NotAtomic && |
533 | "CmpXchg instructions can only be atomic."); | |
1a4d82fc | 534 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x1c) | |
223e47cc LB |
535 | (Ordering << 2)); |
536 | } | |
537 | ||
1a4d82fc JJ |
538 | void setFailureOrdering(AtomicOrdering Ordering) { |
539 | assert(Ordering != NotAtomic && | |
540 | "CmpXchg instructions can only be atomic."); | |
541 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~0xe0) | | |
542 | (Ordering << 5)); | |
543 | } | |
544 | ||
223e47cc LB |
545 | /// Specify whether this cmpxchg is atomic and orders other operations with |
546 | /// respect to all concurrently executing threads, or only with respect to | |
547 | /// signal handlers executing in the same thread. | |
548 | void setSynchScope(SynchronizationScope SynchScope) { | |
549 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) | | |
550 | (SynchScope << 1)); | |
551 | } | |
552 | ||
553 | /// Returns the ordering constraint on this cmpxchg. | |
1a4d82fc JJ |
554 | AtomicOrdering getSuccessOrdering() const { |
555 | return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7); | |
556 | } | |
557 | ||
558 | /// Returns the ordering constraint on this cmpxchg. | |
559 | AtomicOrdering getFailureOrdering() const { | |
560 | return AtomicOrdering((getSubclassDataFromInstruction() >> 5) & 7); | |
223e47cc LB |
561 | } |
562 | ||
563 | /// Returns whether this cmpxchg is atomic between threads or only within a | |
564 | /// single thread. | |
565 | SynchronizationScope getSynchScope() const { | |
566 | return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1); | |
567 | } | |
568 | ||
569 | Value *getPointerOperand() { return getOperand(0); } | |
570 | const Value *getPointerOperand() const { return getOperand(0); } | |
571 | static unsigned getPointerOperandIndex() { return 0U; } | |
572 | ||
573 | Value *getCompareOperand() { return getOperand(1); } | |
574 | const Value *getCompareOperand() const { return getOperand(1); } | |
970d7e83 | 575 | |
223e47cc LB |
576 | Value *getNewValOperand() { return getOperand(2); } |
577 | const Value *getNewValOperand() const { return getOperand(2); } | |
970d7e83 LB |
578 | |
579 | /// \brief Returns the address space of the pointer operand. | |
223e47cc | 580 | unsigned getPointerAddressSpace() const { |
970d7e83 | 581 | return getPointerOperand()->getType()->getPointerAddressSpace(); |
223e47cc | 582 | } |
970d7e83 | 583 | |
1a4d82fc JJ |
584 | /// \brief Returns the strongest permitted ordering on failure, given the |
585 | /// desired ordering on success. | |
586 | /// | |
587 | /// If the comparison in a cmpxchg operation fails, there is no atomic store | |
588 | /// so release semantics cannot be provided. So this function drops explicit | |
589 | /// Release requests from the AtomicOrdering. A SequentiallyConsistent | |
590 | /// operation would remain SequentiallyConsistent. | |
591 | static AtomicOrdering | |
592 | getStrongestFailureOrdering(AtomicOrdering SuccessOrdering) { | |
593 | switch (SuccessOrdering) { | |
594 | default: llvm_unreachable("invalid cmpxchg success ordering"); | |
595 | case Release: | |
596 | case Monotonic: | |
597 | return Monotonic; | |
598 | case AcquireRelease: | |
599 | case Acquire: | |
600 | return Acquire; | |
601 | case SequentiallyConsistent: | |
602 | return SequentiallyConsistent; | |
603 | } | |
604 | } | |
605 | ||
223e47cc | 606 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
607 | static inline bool classof(const Instruction *I) { |
608 | return I->getOpcode() == Instruction::AtomicCmpXchg; | |
609 | } | |
610 | static inline bool classof(const Value *V) { | |
611 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
612 | } | |
613 | private: | |
614 | // Shadow Instruction::setInstructionSubclassData with a private forwarding | |
615 | // method so that subclasses cannot accidentally use it. | |
616 | void setInstructionSubclassData(unsigned short D) { | |
617 | Instruction::setInstructionSubclassData(D); | |
618 | } | |
619 | }; | |
620 | ||
621 | template <> | |
622 | struct OperandTraits<AtomicCmpXchgInst> : | |
623 | public FixedNumOperandTraits<AtomicCmpXchgInst, 3> { | |
624 | }; | |
625 | ||
626 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value) | |
627 | ||
628 | //===----------------------------------------------------------------------===// | |
629 | // AtomicRMWInst Class | |
630 | //===----------------------------------------------------------------------===// | |
631 | ||
632 | /// AtomicRMWInst - an instruction that atomically reads a memory location, | |
633 | /// combines it with another value, and then stores the result back. Returns | |
634 | /// the old value. | |
635 | /// | |
636 | class AtomicRMWInst : public Instruction { | |
637 | void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; | |
638 | protected: | |
1a4d82fc | 639 | AtomicRMWInst *clone_impl() const override; |
223e47cc LB |
640 | public: |
641 | /// This enumeration lists the possible modifications atomicrmw can make. In | |
642 | /// the descriptions, 'p' is the pointer to the instruction's memory location, | |
643 | /// 'old' is the initial value of *p, and 'v' is the other value passed to the | |
644 | /// instruction. These instructions always return 'old'. | |
645 | enum BinOp { | |
646 | /// *p = v | |
647 | Xchg, | |
648 | /// *p = old + v | |
649 | Add, | |
650 | /// *p = old - v | |
651 | Sub, | |
652 | /// *p = old & v | |
653 | And, | |
1a4d82fc | 654 | /// *p = ~(old & v) |
223e47cc LB |
655 | Nand, |
656 | /// *p = old | v | |
657 | Or, | |
658 | /// *p = old ^ v | |
659 | Xor, | |
660 | /// *p = old >signed v ? old : v | |
661 | Max, | |
662 | /// *p = old <signed v ? old : v | |
663 | Min, | |
664 | /// *p = old >unsigned v ? old : v | |
665 | UMax, | |
666 | /// *p = old <unsigned v ? old : v | |
667 | UMin, | |
668 | ||
669 | FIRST_BINOP = Xchg, | |
670 | LAST_BINOP = UMin, | |
671 | BAD_BINOP | |
672 | }; | |
673 | ||
674 | // allocate space for exactly two operands | |
675 | void *operator new(size_t s) { | |
676 | return User::operator new(s, 2); | |
677 | } | |
678 | AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, | |
679 | AtomicOrdering Ordering, SynchronizationScope SynchScope, | |
1a4d82fc | 680 | Instruction *InsertBefore = nullptr); |
223e47cc LB |
681 | AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, |
682 | AtomicOrdering Ordering, SynchronizationScope SynchScope, | |
683 | BasicBlock *InsertAtEnd); | |
684 | ||
685 | BinOp getOperation() const { | |
686 | return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5); | |
687 | } | |
688 | ||
689 | void setOperation(BinOp Operation) { | |
690 | unsigned short SubclassData = getSubclassDataFromInstruction(); | |
691 | setInstructionSubclassData((SubclassData & 31) | | |
692 | (Operation << 5)); | |
693 | } | |
694 | ||
695 | /// isVolatile - Return true if this is a RMW on a volatile memory location. | |
696 | /// | |
697 | bool isVolatile() const { | |
698 | return getSubclassDataFromInstruction() & 1; | |
699 | } | |
700 | ||
701 | /// setVolatile - Specify whether this is a volatile RMW or not. | |
702 | /// | |
703 | void setVolatile(bool V) { | |
704 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | | |
705 | (unsigned)V); | |
706 | } | |
707 | ||
708 | /// Transparently provide more efficient getOperand methods. | |
709 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
710 | ||
711 | /// Set the ordering constraint on this RMW. | |
712 | void setOrdering(AtomicOrdering Ordering) { | |
713 | assert(Ordering != NotAtomic && | |
714 | "atomicrmw instructions can only be atomic."); | |
715 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) | | |
716 | (Ordering << 2)); | |
717 | } | |
718 | ||
719 | /// Specify whether this RMW orders other operations with respect to all | |
720 | /// concurrently executing threads, or only with respect to signal handlers | |
721 | /// executing in the same thread. | |
722 | void setSynchScope(SynchronizationScope SynchScope) { | |
723 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) | | |
724 | (SynchScope << 1)); | |
725 | } | |
726 | ||
727 | /// Returns the ordering constraint on this RMW. | |
728 | AtomicOrdering getOrdering() const { | |
729 | return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7); | |
730 | } | |
731 | ||
732 | /// Returns whether this RMW is atomic between threads or only within a | |
733 | /// single thread. | |
734 | SynchronizationScope getSynchScope() const { | |
735 | return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1); | |
736 | } | |
737 | ||
738 | Value *getPointerOperand() { return getOperand(0); } | |
739 | const Value *getPointerOperand() const { return getOperand(0); } | |
740 | static unsigned getPointerOperandIndex() { return 0U; } | |
741 | ||
742 | Value *getValOperand() { return getOperand(1); } | |
743 | const Value *getValOperand() const { return getOperand(1); } | |
744 | ||
970d7e83 | 745 | /// \brief Returns the address space of the pointer operand. |
223e47cc | 746 | unsigned getPointerAddressSpace() const { |
970d7e83 | 747 | return getPointerOperand()->getType()->getPointerAddressSpace(); |
223e47cc LB |
748 | } |
749 | ||
750 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
751 | static inline bool classof(const Instruction *I) { |
752 | return I->getOpcode() == Instruction::AtomicRMW; | |
753 | } | |
754 | static inline bool classof(const Value *V) { | |
755 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
756 | } | |
757 | private: | |
758 | void Init(BinOp Operation, Value *Ptr, Value *Val, | |
759 | AtomicOrdering Ordering, SynchronizationScope SynchScope); | |
760 | // Shadow Instruction::setInstructionSubclassData with a private forwarding | |
761 | // method so that subclasses cannot accidentally use it. | |
762 | void setInstructionSubclassData(unsigned short D) { | |
763 | Instruction::setInstructionSubclassData(D); | |
764 | } | |
765 | }; | |
766 | ||
767 | template <> | |
768 | struct OperandTraits<AtomicRMWInst> | |
769 | : public FixedNumOperandTraits<AtomicRMWInst,2> { | |
770 | }; | |
771 | ||
772 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value) | |
773 | ||
774 | //===----------------------------------------------------------------------===// | |
775 | // GetElementPtrInst Class | |
776 | //===----------------------------------------------------------------------===// | |
777 | ||
778 | // checkGEPType - Simple wrapper function to give a better assertion failure | |
779 | // message on bad indexes for a gep instruction. | |
780 | // | |
781 | inline Type *checkGEPType(Type *Ty) { | |
782 | assert(Ty && "Invalid GetElementPtrInst indices for type!"); | |
783 | return Ty; | |
784 | } | |
785 | ||
786 | /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to | |
787 | /// access elements of arrays and structs | |
788 | /// | |
789 | class GetElementPtrInst : public Instruction { | |
790 | GetElementPtrInst(const GetElementPtrInst &GEPI); | |
791 | void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr); | |
792 | ||
793 | /// Constructors - Create a getelementptr instruction with a base pointer an | |
794 | /// list of indices. The first ctor can optionally insert before an existing | |
795 | /// instruction, the second appends the new instruction to the specified | |
796 | /// BasicBlock. | |
797 | inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList, | |
798 | unsigned Values, const Twine &NameStr, | |
799 | Instruction *InsertBefore); | |
800 | inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList, | |
801 | unsigned Values, const Twine &NameStr, | |
802 | BasicBlock *InsertAtEnd); | |
803 | protected: | |
1a4d82fc | 804 | GetElementPtrInst *clone_impl() const override; |
223e47cc LB |
805 | public: |
806 | static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList, | |
807 | const Twine &NameStr = "", | |
1a4d82fc | 808 | Instruction *InsertBefore = nullptr) { |
223e47cc LB |
809 | unsigned Values = 1 + unsigned(IdxList.size()); |
810 | return new(Values) | |
811 | GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore); | |
812 | } | |
813 | static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList, | |
814 | const Twine &NameStr, | |
815 | BasicBlock *InsertAtEnd) { | |
816 | unsigned Values = 1 + unsigned(IdxList.size()); | |
817 | return new(Values) | |
818 | GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd); | |
819 | } | |
820 | ||
821 | /// Create an "inbounds" getelementptr. See the documentation for the | |
822 | /// "inbounds" flag in LangRef.html for details. | |
823 | static GetElementPtrInst *CreateInBounds(Value *Ptr, | |
824 | ArrayRef<Value *> IdxList, | |
825 | const Twine &NameStr = "", | |
1a4d82fc | 826 | Instruction *InsertBefore = nullptr){ |
223e47cc LB |
827 | GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore); |
828 | GEP->setIsInBounds(true); | |
829 | return GEP; | |
830 | } | |
831 | static GetElementPtrInst *CreateInBounds(Value *Ptr, | |
832 | ArrayRef<Value *> IdxList, | |
833 | const Twine &NameStr, | |
834 | BasicBlock *InsertAtEnd) { | |
835 | GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd); | |
836 | GEP->setIsInBounds(true); | |
837 | return GEP; | |
838 | } | |
839 | ||
840 | /// Transparently provide more efficient getOperand methods. | |
841 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
842 | ||
970d7e83 LB |
843 | // getType - Overload to return most specific sequential type. |
844 | SequentialType *getType() const { | |
845 | return cast<SequentialType>(Instruction::getType()); | |
846 | } | |
847 | ||
848 | /// \brief Returns the address space of this instruction's pointer type. | |
849 | unsigned getAddressSpace() const { | |
850 | // Note that this is always the same as the pointer operand's address space | |
851 | // and that is cheaper to compute, so cheat here. | |
852 | return getPointerAddressSpace(); | |
223e47cc LB |
853 | } |
854 | ||
855 | /// getIndexedType - Returns the type of the element that would be loaded with | |
856 | /// a load instruction with the specified parameters. | |
857 | /// | |
858 | /// Null is returned if the indices are invalid for the specified | |
859 | /// pointer type. | |
860 | /// | |
861 | static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList); | |
862 | static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList); | |
863 | static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList); | |
864 | ||
223e47cc LB |
865 | inline op_iterator idx_begin() { return op_begin()+1; } |
866 | inline const_op_iterator idx_begin() const { return op_begin()+1; } | |
867 | inline op_iterator idx_end() { return op_end(); } | |
868 | inline const_op_iterator idx_end() const { return op_end(); } | |
869 | ||
870 | Value *getPointerOperand() { | |
871 | return getOperand(0); | |
872 | } | |
873 | const Value *getPointerOperand() const { | |
874 | return getOperand(0); | |
875 | } | |
876 | static unsigned getPointerOperandIndex() { | |
877 | return 0U; // get index for modifying correct operand. | |
878 | } | |
879 | ||
223e47cc LB |
880 | /// getPointerOperandType - Method to return the pointer operand as a |
881 | /// PointerType. | |
882 | Type *getPointerOperandType() const { | |
883 | return getPointerOperand()->getType(); | |
884 | } | |
885 | ||
970d7e83 LB |
886 | /// \brief Returns the address space of the pointer operand. |
887 | unsigned getPointerAddressSpace() const { | |
888 | return getPointerOperandType()->getPointerAddressSpace(); | |
889 | } | |
890 | ||
223e47cc LB |
891 | /// GetGEPReturnType - Returns the pointer type returned by the GEP |
892 | /// instruction, which may be a vector of pointers. | |
893 | static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) { | |
894 | Type *PtrTy = PointerType::get(checkGEPType( | |
895 | getIndexedType(Ptr->getType(), IdxList)), | |
970d7e83 | 896 | Ptr->getType()->getPointerAddressSpace()); |
223e47cc LB |
897 | // Vector GEP |
898 | if (Ptr->getType()->isVectorTy()) { | |
899 | unsigned NumElem = cast<VectorType>(Ptr->getType())->getNumElements(); | |
900 | return VectorType::get(PtrTy, NumElem); | |
901 | } | |
902 | ||
903 | // Scalar GEP | |
904 | return PtrTy; | |
905 | } | |
906 | ||
907 | unsigned getNumIndices() const { // Note: always non-negative | |
908 | return getNumOperands() - 1; | |
909 | } | |
910 | ||
911 | bool hasIndices() const { | |
912 | return getNumOperands() > 1; | |
913 | } | |
914 | ||
915 | /// hasAllZeroIndices - Return true if all of the indices of this GEP are | |
916 | /// zeros. If so, the result pointer and the first operand have the same | |
917 | /// value, just potentially different types. | |
918 | bool hasAllZeroIndices() const; | |
919 | ||
920 | /// hasAllConstantIndices - Return true if all of the indices of this GEP are | |
921 | /// constant integers. If so, the result pointer and the first operand have | |
922 | /// a constant offset between them. | |
923 | bool hasAllConstantIndices() const; | |
924 | ||
925 | /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction. | |
926 | /// See LangRef.html for the meaning of inbounds on a getelementptr. | |
927 | void setIsInBounds(bool b = true); | |
928 | ||
929 | /// isInBounds - Determine whether the GEP has the inbounds flag. | |
930 | bool isInBounds() const; | |
931 | ||
970d7e83 LB |
932 | /// \brief Accumulate the constant address offset of this GEP if possible. |
933 | /// | |
934 | /// This routine accepts an APInt into which it will accumulate the constant | |
935 | /// offset of this GEP if the GEP is in fact constant. If the GEP is not | |
936 | /// all-constant, it returns false and the value of the offset APInt is | |
937 | /// undefined (it is *not* preserved!). The APInt passed into this routine | |
938 | /// must be at least as wide as the IntPtr type for the address space of | |
939 | /// the base GEP pointer. | |
940 | bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const; | |
941 | ||
223e47cc | 942 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
943 | static inline bool classof(const Instruction *I) { |
944 | return (I->getOpcode() == Instruction::GetElementPtr); | |
945 | } | |
946 | static inline bool classof(const Value *V) { | |
947 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
948 | } | |
949 | }; | |
950 | ||
951 | template <> | |
952 | struct OperandTraits<GetElementPtrInst> : | |
953 | public VariadicOperandTraits<GetElementPtrInst, 1> { | |
954 | }; | |
955 | ||
956 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, | |
957 | ArrayRef<Value *> IdxList, | |
958 | unsigned Values, | |
959 | const Twine &NameStr, | |
960 | Instruction *InsertBefore) | |
961 | : Instruction(getGEPReturnType(Ptr, IdxList), | |
962 | GetElementPtr, | |
963 | OperandTraits<GetElementPtrInst>::op_end(this) - Values, | |
964 | Values, InsertBefore) { | |
965 | init(Ptr, IdxList, NameStr); | |
966 | } | |
967 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, | |
968 | ArrayRef<Value *> IdxList, | |
969 | unsigned Values, | |
970 | const Twine &NameStr, | |
971 | BasicBlock *InsertAtEnd) | |
972 | : Instruction(getGEPReturnType(Ptr, IdxList), | |
973 | GetElementPtr, | |
974 | OperandTraits<GetElementPtrInst>::op_end(this) - Values, | |
975 | Values, InsertAtEnd) { | |
976 | init(Ptr, IdxList, NameStr); | |
977 | } | |
978 | ||
979 | ||
980 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value) | |
981 | ||
982 | ||
983 | //===----------------------------------------------------------------------===// | |
984 | // ICmpInst Class | |
985 | //===----------------------------------------------------------------------===// | |
986 | ||
987 | /// This instruction compares its operands according to the predicate given | |
988 | /// to the constructor. It only operates on integers or pointers. The operands | |
989 | /// must be identical types. | |
970d7e83 | 990 | /// \brief Represent an integer comparison operator. |
223e47cc | 991 | class ICmpInst: public CmpInst { |
1a4d82fc JJ |
992 | void AssertOK() { |
993 | assert(getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE && | |
994 | getPredicate() <= CmpInst::LAST_ICMP_PREDICATE && | |
995 | "Invalid ICmp predicate value"); | |
996 | assert(getOperand(0)->getType() == getOperand(1)->getType() && | |
997 | "Both operands to ICmp instruction are not of the same type!"); | |
998 | // Check that the operands are the right type | |
999 | assert((getOperand(0)->getType()->isIntOrIntVectorTy() || | |
1000 | getOperand(0)->getType()->isPtrOrPtrVectorTy()) && | |
1001 | "Invalid operand types for ICmp instruction"); | |
1002 | } | |
1003 | ||
223e47cc | 1004 | protected: |
970d7e83 | 1005 | /// \brief Clone an identical ICmpInst |
1a4d82fc | 1006 | ICmpInst *clone_impl() const override; |
223e47cc | 1007 | public: |
970d7e83 | 1008 | /// \brief Constructor with insert-before-instruction semantics. |
223e47cc LB |
1009 | ICmpInst( |
1010 | Instruction *InsertBefore, ///< Where to insert | |
1011 | Predicate pred, ///< The predicate to use for the comparison | |
1012 | Value *LHS, ///< The left-hand-side of the expression | |
1013 | Value *RHS, ///< The right-hand-side of the expression | |
1014 | const Twine &NameStr = "" ///< Name of the instruction | |
1015 | ) : CmpInst(makeCmpResultType(LHS->getType()), | |
1016 | Instruction::ICmp, pred, LHS, RHS, NameStr, | |
1017 | InsertBefore) { | |
1a4d82fc JJ |
1018 | #ifndef NDEBUG |
1019 | AssertOK(); | |
1020 | #endif | |
223e47cc LB |
1021 | } |
1022 | ||
970d7e83 | 1023 | /// \brief Constructor with insert-at-end semantics. |
223e47cc LB |
1024 | ICmpInst( |
1025 | BasicBlock &InsertAtEnd, ///< Block to insert into. | |
1026 | Predicate pred, ///< The predicate to use for the comparison | |
1027 | Value *LHS, ///< The left-hand-side of the expression | |
1028 | Value *RHS, ///< The right-hand-side of the expression | |
1029 | const Twine &NameStr = "" ///< Name of the instruction | |
1030 | ) : CmpInst(makeCmpResultType(LHS->getType()), | |
1031 | Instruction::ICmp, pred, LHS, RHS, NameStr, | |
1032 | &InsertAtEnd) { | |
1a4d82fc JJ |
1033 | #ifndef NDEBUG |
1034 | AssertOK(); | |
1035 | #endif | |
223e47cc LB |
1036 | } |
1037 | ||
970d7e83 | 1038 | /// \brief Constructor with no-insertion semantics |
223e47cc LB |
1039 | ICmpInst( |
1040 | Predicate pred, ///< The predicate to use for the comparison | |
1041 | Value *LHS, ///< The left-hand-side of the expression | |
1042 | Value *RHS, ///< The right-hand-side of the expression | |
1043 | const Twine &NameStr = "" ///< Name of the instruction | |
1044 | ) : CmpInst(makeCmpResultType(LHS->getType()), | |
1045 | Instruction::ICmp, pred, LHS, RHS, NameStr) { | |
1a4d82fc JJ |
1046 | #ifndef NDEBUG |
1047 | AssertOK(); | |
1048 | #endif | |
223e47cc LB |
1049 | } |
1050 | ||
1051 | /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc. | |
1052 | /// @returns the predicate that would be the result if the operand were | |
1053 | /// regarded as signed. | |
970d7e83 | 1054 | /// \brief Return the signed version of the predicate |
223e47cc LB |
1055 | Predicate getSignedPredicate() const { |
1056 | return getSignedPredicate(getPredicate()); | |
1057 | } | |
1058 | ||
1059 | /// This is a static version that you can use without an instruction. | |
970d7e83 | 1060 | /// \brief Return the signed version of the predicate. |
223e47cc LB |
1061 | static Predicate getSignedPredicate(Predicate pred); |
1062 | ||
1063 | /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc. | |
1064 | /// @returns the predicate that would be the result if the operand were | |
1065 | /// regarded as unsigned. | |
970d7e83 | 1066 | /// \brief Return the unsigned version of the predicate |
223e47cc LB |
1067 | Predicate getUnsignedPredicate() const { |
1068 | return getUnsignedPredicate(getPredicate()); | |
1069 | } | |
1070 | ||
1071 | /// This is a static version that you can use without an instruction. | |
970d7e83 | 1072 | /// \brief Return the unsigned version of the predicate. |
223e47cc LB |
1073 | static Predicate getUnsignedPredicate(Predicate pred); |
1074 | ||
1075 | /// isEquality - Return true if this predicate is either EQ or NE. This also | |
1076 | /// tests for commutativity. | |
1077 | static bool isEquality(Predicate P) { | |
1078 | return P == ICMP_EQ || P == ICMP_NE; | |
1079 | } | |
1080 | ||
1081 | /// isEquality - Return true if this predicate is either EQ or NE. This also | |
1082 | /// tests for commutativity. | |
1083 | bool isEquality() const { | |
1084 | return isEquality(getPredicate()); | |
1085 | } | |
1086 | ||
1087 | /// @returns true if the predicate of this ICmpInst is commutative | |
970d7e83 | 1088 | /// \brief Determine if this relation is commutative. |
223e47cc LB |
1089 | bool isCommutative() const { return isEquality(); } |
1090 | ||
1091 | /// isRelational - Return true if the predicate is relational (not EQ or NE). | |
1092 | /// | |
1093 | bool isRelational() const { | |
1094 | return !isEquality(); | |
1095 | } | |
1096 | ||
1097 | /// isRelational - Return true if the predicate is relational (not EQ or NE). | |
1098 | /// | |
1099 | static bool isRelational(Predicate P) { | |
1100 | return !isEquality(P); | |
1101 | } | |
1102 | ||
1103 | /// Initialize a set of values that all satisfy the predicate with C. | |
970d7e83 | 1104 | /// \brief Make a ConstantRange for a relation with a constant value. |
223e47cc LB |
1105 | static ConstantRange makeConstantRange(Predicate pred, const APInt &C); |
1106 | ||
1107 | /// Exchange the two operands to this instruction in such a way that it does | |
1108 | /// not modify the semantics of the instruction. The predicate value may be | |
1109 | /// changed to retain the same result if the predicate is order dependent | |
1110 | /// (e.g. ult). | |
970d7e83 | 1111 | /// \brief Swap operands and adjust predicate. |
223e47cc LB |
1112 | void swapOperands() { |
1113 | setPredicate(getSwappedPredicate()); | |
1114 | Op<0>().swap(Op<1>()); | |
1115 | } | |
1116 | ||
1117 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
1118 | static inline bool classof(const Instruction *I) { |
1119 | return I->getOpcode() == Instruction::ICmp; | |
1120 | } | |
1121 | static inline bool classof(const Value *V) { | |
1122 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
1123 | } | |
1124 | ||
1125 | }; | |
1126 | ||
1127 | //===----------------------------------------------------------------------===// | |
1128 | // FCmpInst Class | |
1129 | //===----------------------------------------------------------------------===// | |
1130 | ||
1131 | /// This instruction compares its operands according to the predicate given | |
1132 | /// to the constructor. It only operates on floating point values or packed | |
1133 | /// vectors of floating point values. The operands must be identical types. | |
970d7e83 | 1134 | /// \brief Represents a floating point comparison operator. |
223e47cc LB |
1135 | class FCmpInst: public CmpInst { |
1136 | protected: | |
970d7e83 | 1137 | /// \brief Clone an identical FCmpInst |
1a4d82fc | 1138 | FCmpInst *clone_impl() const override; |
223e47cc | 1139 | public: |
970d7e83 | 1140 | /// \brief Constructor with insert-before-instruction semantics. |
223e47cc LB |
1141 | FCmpInst( |
1142 | Instruction *InsertBefore, ///< Where to insert | |
1143 | Predicate pred, ///< The predicate to use for the comparison | |
1144 | Value *LHS, ///< The left-hand-side of the expression | |
1145 | Value *RHS, ///< The right-hand-side of the expression | |
1146 | const Twine &NameStr = "" ///< Name of the instruction | |
1147 | ) : CmpInst(makeCmpResultType(LHS->getType()), | |
1148 | Instruction::FCmp, pred, LHS, RHS, NameStr, | |
1149 | InsertBefore) { | |
1150 | assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && | |
1151 | "Invalid FCmp predicate value"); | |
1152 | assert(getOperand(0)->getType() == getOperand(1)->getType() && | |
1153 | "Both operands to FCmp instruction are not of the same type!"); | |
1154 | // Check that the operands are the right type | |
1155 | assert(getOperand(0)->getType()->isFPOrFPVectorTy() && | |
1156 | "Invalid operand types for FCmp instruction"); | |
1157 | } | |
1158 | ||
970d7e83 | 1159 | /// \brief Constructor with insert-at-end semantics. |
223e47cc LB |
1160 | FCmpInst( |
1161 | BasicBlock &InsertAtEnd, ///< Block to insert into. | |
1162 | Predicate pred, ///< The predicate to use for the comparison | |
1163 | Value *LHS, ///< The left-hand-side of the expression | |
1164 | Value *RHS, ///< The right-hand-side of the expression | |
1165 | const Twine &NameStr = "" ///< Name of the instruction | |
1166 | ) : CmpInst(makeCmpResultType(LHS->getType()), | |
1167 | Instruction::FCmp, pred, LHS, RHS, NameStr, | |
1168 | &InsertAtEnd) { | |
1169 | assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && | |
1170 | "Invalid FCmp predicate value"); | |
1171 | assert(getOperand(0)->getType() == getOperand(1)->getType() && | |
1172 | "Both operands to FCmp instruction are not of the same type!"); | |
1173 | // Check that the operands are the right type | |
1174 | assert(getOperand(0)->getType()->isFPOrFPVectorTy() && | |
1175 | "Invalid operand types for FCmp instruction"); | |
1176 | } | |
1177 | ||
970d7e83 | 1178 | /// \brief Constructor with no-insertion semantics |
223e47cc LB |
1179 | FCmpInst( |
1180 | Predicate pred, ///< The predicate to use for the comparison | |
1181 | Value *LHS, ///< The left-hand-side of the expression | |
1182 | Value *RHS, ///< The right-hand-side of the expression | |
1183 | const Twine &NameStr = "" ///< Name of the instruction | |
1184 | ) : CmpInst(makeCmpResultType(LHS->getType()), | |
1185 | Instruction::FCmp, pred, LHS, RHS, NameStr) { | |
1186 | assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && | |
1187 | "Invalid FCmp predicate value"); | |
1188 | assert(getOperand(0)->getType() == getOperand(1)->getType() && | |
1189 | "Both operands to FCmp instruction are not of the same type!"); | |
1190 | // Check that the operands are the right type | |
1191 | assert(getOperand(0)->getType()->isFPOrFPVectorTy() && | |
1192 | "Invalid operand types for FCmp instruction"); | |
1193 | } | |
1194 | ||
1195 | /// @returns true if the predicate of this instruction is EQ or NE. | |
970d7e83 | 1196 | /// \brief Determine if this is an equality predicate. |
223e47cc LB |
1197 | bool isEquality() const { |
1198 | return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE || | |
1199 | getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE; | |
1200 | } | |
1201 | ||
1202 | /// @returns true if the predicate of this instruction is commutative. | |
970d7e83 | 1203 | /// \brief Determine if this is a commutative predicate. |
223e47cc LB |
1204 | bool isCommutative() const { |
1205 | return isEquality() || | |
1206 | getPredicate() == FCMP_FALSE || | |
1207 | getPredicate() == FCMP_TRUE || | |
1208 | getPredicate() == FCMP_ORD || | |
1209 | getPredicate() == FCMP_UNO; | |
1210 | } | |
1211 | ||
1212 | /// @returns true if the predicate is relational (not EQ or NE). | |
970d7e83 | 1213 | /// \brief Determine if this a relational predicate. |
223e47cc LB |
1214 | bool isRelational() const { return !isEquality(); } |
1215 | ||
1216 | /// Exchange the two operands to this instruction in such a way that it does | |
1217 | /// not modify the semantics of the instruction. The predicate value may be | |
1218 | /// changed to retain the same result if the predicate is order dependent | |
1219 | /// (e.g. ult). | |
970d7e83 | 1220 | /// \brief Swap operands and adjust predicate. |
223e47cc LB |
1221 | void swapOperands() { |
1222 | setPredicate(getSwappedPredicate()); | |
1223 | Op<0>().swap(Op<1>()); | |
1224 | } | |
1225 | ||
970d7e83 | 1226 | /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
1227 | static inline bool classof(const Instruction *I) { |
1228 | return I->getOpcode() == Instruction::FCmp; | |
1229 | } | |
1230 | static inline bool classof(const Value *V) { | |
1231 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
1232 | } | |
1233 | }; | |
1234 | ||
1235 | //===----------------------------------------------------------------------===// | |
1236 | /// CallInst - This class represents a function call, abstracting a target | |
1237 | /// machine's calling convention. This class uses low bit of the SubClassData | |
1238 | /// field to indicate whether or not this is a tail call. The rest of the bits | |
1239 | /// hold the calling convention of the call. | |
1240 | /// | |
1241 | class CallInst : public Instruction { | |
970d7e83 | 1242 | AttributeSet AttributeList; ///< parameter attributes for call |
223e47cc LB |
1243 | CallInst(const CallInst &CI); |
1244 | void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr); | |
1245 | void init(Value *Func, const Twine &NameStr); | |
1246 | ||
1247 | /// Construct a CallInst given a range of arguments. | |
970d7e83 | 1248 | /// \brief Construct a CallInst from a range of arguments |
223e47cc LB |
1249 | inline CallInst(Value *Func, ArrayRef<Value *> Args, |
1250 | const Twine &NameStr, Instruction *InsertBefore); | |
1251 | ||
1252 | /// Construct a CallInst given a range of arguments. | |
970d7e83 | 1253 | /// \brief Construct a CallInst from a range of arguments |
223e47cc LB |
1254 | inline CallInst(Value *Func, ArrayRef<Value *> Args, |
1255 | const Twine &NameStr, BasicBlock *InsertAtEnd); | |
1256 | ||
223e47cc LB |
1257 | explicit CallInst(Value *F, const Twine &NameStr, |
1258 | Instruction *InsertBefore); | |
1259 | CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd); | |
1260 | protected: | |
1a4d82fc | 1261 | CallInst *clone_impl() const override; |
223e47cc LB |
1262 | public: |
1263 | static CallInst *Create(Value *Func, | |
1264 | ArrayRef<Value *> Args, | |
1265 | const Twine &NameStr = "", | |
1a4d82fc | 1266 | Instruction *InsertBefore = nullptr) { |
223e47cc LB |
1267 | return new(unsigned(Args.size() + 1)) |
1268 | CallInst(Func, Args, NameStr, InsertBefore); | |
1269 | } | |
1270 | static CallInst *Create(Value *Func, | |
1271 | ArrayRef<Value *> Args, | |
1272 | const Twine &NameStr, BasicBlock *InsertAtEnd) { | |
1273 | return new(unsigned(Args.size() + 1)) | |
1274 | CallInst(Func, Args, NameStr, InsertAtEnd); | |
1275 | } | |
1276 | static CallInst *Create(Value *F, const Twine &NameStr = "", | |
1a4d82fc | 1277 | Instruction *InsertBefore = nullptr) { |
223e47cc LB |
1278 | return new(1) CallInst(F, NameStr, InsertBefore); |
1279 | } | |
1280 | static CallInst *Create(Value *F, const Twine &NameStr, | |
1281 | BasicBlock *InsertAtEnd) { | |
1282 | return new(1) CallInst(F, NameStr, InsertAtEnd); | |
1283 | } | |
1284 | /// CreateMalloc - Generate the IR for a call to malloc: | |
1285 | /// 1. Compute the malloc call's argument as the specified type's size, | |
1286 | /// possibly multiplied by the array size if the array size is not | |
1287 | /// constant 1. | |
1288 | /// 2. Call malloc with that argument. | |
1289 | /// 3. Bitcast the result of the malloc call to the specified type. | |
1290 | static Instruction *CreateMalloc(Instruction *InsertBefore, | |
1291 | Type *IntPtrTy, Type *AllocTy, | |
1a4d82fc JJ |
1292 | Value *AllocSize, Value *ArraySize = nullptr, |
1293 | Function* MallocF = nullptr, | |
223e47cc LB |
1294 | const Twine &Name = ""); |
1295 | static Instruction *CreateMalloc(BasicBlock *InsertAtEnd, | |
1296 | Type *IntPtrTy, Type *AllocTy, | |
1a4d82fc JJ |
1297 | Value *AllocSize, Value *ArraySize = nullptr, |
1298 | Function* MallocF = nullptr, | |
223e47cc LB |
1299 | const Twine &Name = ""); |
1300 | /// CreateFree - Generate the IR for a call to the builtin free function. | |
1301 | static Instruction* CreateFree(Value* Source, Instruction *InsertBefore); | |
1302 | static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd); | |
1303 | ||
1304 | ~CallInst(); | |
1305 | ||
1a4d82fc JJ |
1306 | // Note that 'musttail' implies 'tail'. |
1307 | enum TailCallKind { TCK_None = 0, TCK_Tail = 1, TCK_MustTail = 2 }; | |
1308 | TailCallKind getTailCallKind() const { | |
1309 | return TailCallKind(getSubclassDataFromInstruction() & 3); | |
1310 | } | |
1311 | bool isTailCall() const { | |
1312 | return (getSubclassDataFromInstruction() & 3) != TCK_None; | |
1313 | } | |
1314 | bool isMustTailCall() const { | |
1315 | return (getSubclassDataFromInstruction() & 3) == TCK_MustTail; | |
1316 | } | |
223e47cc | 1317 | void setTailCall(bool isTC = true) { |
1a4d82fc JJ |
1318 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) | |
1319 | unsigned(isTC ? TCK_Tail : TCK_None)); | |
1320 | } | |
1321 | void setTailCallKind(TailCallKind TCK) { | |
1322 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) | | |
1323 | unsigned(TCK)); | |
223e47cc LB |
1324 | } |
1325 | ||
1326 | /// Provide fast operand accessors | |
1327 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
1328 | ||
1329 | /// getNumArgOperands - Return the number of call arguments. | |
1330 | /// | |
1331 | unsigned getNumArgOperands() const { return getNumOperands() - 1; } | |
1332 | ||
1333 | /// getArgOperand/setArgOperand - Return/set the i-th call argument. | |
1334 | /// | |
1335 | Value *getArgOperand(unsigned i) const { return getOperand(i); } | |
1336 | void setArgOperand(unsigned i, Value *v) { setOperand(i, v); } | |
1337 | ||
1a4d82fc JJ |
1338 | /// arg_operands - iteration adapter for range-for loops. |
1339 | iterator_range<op_iterator> arg_operands() { | |
1340 | // The last operand in the op list is the callee - it's not one of the args | |
1341 | // so we don't want to iterate over it. | |
1342 | return iterator_range<op_iterator>(op_begin(), op_end() - 1); | |
1343 | } | |
1344 | ||
1345 | /// arg_operands - iteration adapter for range-for loops. | |
1346 | iterator_range<const_op_iterator> arg_operands() const { | |
1347 | return iterator_range<const_op_iterator>(op_begin(), op_end() - 1); | |
1348 | } | |
1349 | ||
1350 | /// \brief Wrappers for getting the \c Use of a call argument. | |
1351 | const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); } | |
1352 | Use &getArgOperandUse(unsigned i) { return getOperandUse(i); } | |
1353 | ||
223e47cc LB |
1354 | /// getCallingConv/setCallingConv - Get or set the calling convention of this |
1355 | /// function call. | |
1356 | CallingConv::ID getCallingConv() const { | |
1a4d82fc | 1357 | return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2); |
223e47cc LB |
1358 | } |
1359 | void setCallingConv(CallingConv::ID CC) { | |
1a4d82fc JJ |
1360 | setInstructionSubclassData((getSubclassDataFromInstruction() & 3) | |
1361 | (static_cast<unsigned>(CC) << 2)); | |
223e47cc LB |
1362 | } |
1363 | ||
1364 | /// getAttributes - Return the parameter attributes for this call. | |
1365 | /// | |
970d7e83 | 1366 | const AttributeSet &getAttributes() const { return AttributeList; } |
223e47cc LB |
1367 | |
1368 | /// setAttributes - Set the parameter attributes for this call. | |
1369 | /// | |
970d7e83 | 1370 | void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; } |
223e47cc LB |
1371 | |
1372 | /// addAttribute - adds the attribute to the list of attributes. | |
970d7e83 | 1373 | void addAttribute(unsigned i, Attribute::AttrKind attr); |
223e47cc LB |
1374 | |
1375 | /// removeAttribute - removes the attribute from the list of attributes. | |
970d7e83 | 1376 | void removeAttribute(unsigned i, Attribute attr); |
223e47cc | 1377 | |
970d7e83 | 1378 | /// \brief Determine whether this call has the given attribute. |
1a4d82fc JJ |
1379 | bool hasFnAttr(Attribute::AttrKind A) const { |
1380 | assert(A != Attribute::NoBuiltin && | |
1381 | "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin"); | |
1382 | return hasFnAttrImpl(A); | |
1383 | } | |
223e47cc | 1384 | |
970d7e83 LB |
1385 | /// \brief Determine whether the call or the callee has the given attributes. |
1386 | bool paramHasAttr(unsigned i, Attribute::AttrKind A) const; | |
223e47cc | 1387 | |
970d7e83 | 1388 | /// \brief Extract the alignment for a call or parameter (0=unknown). |
223e47cc LB |
1389 | unsigned getParamAlignment(unsigned i) const { |
1390 | return AttributeList.getParamAlignment(i); | |
1391 | } | |
1392 | ||
1a4d82fc JJ |
1393 | /// \brief Extract the number of dereferenceable bytes for a call or |
1394 | /// parameter (0=unknown). | |
1395 | uint64_t getDereferenceableBytes(unsigned i) const { | |
1396 | return AttributeList.getDereferenceableBytes(i); | |
1397 | } | |
1398 | ||
1399 | /// \brief Return true if the call should not be treated as a call to a | |
1400 | /// builtin. | |
1401 | bool isNoBuiltin() const { | |
1402 | return hasFnAttrImpl(Attribute::NoBuiltin) && | |
1403 | !hasFnAttrImpl(Attribute::Builtin); | |
1404 | } | |
1405 | ||
970d7e83 | 1406 | /// \brief Return true if the call should not be inlined. |
223e47cc | 1407 | bool isNoInline() const { return hasFnAttr(Attribute::NoInline); } |
970d7e83 LB |
1408 | void setIsNoInline() { |
1409 | addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline); | |
223e47cc LB |
1410 | } |
1411 | ||
970d7e83 | 1412 | /// \brief Return true if the call can return twice |
223e47cc LB |
1413 | bool canReturnTwice() const { |
1414 | return hasFnAttr(Attribute::ReturnsTwice); | |
1415 | } | |
970d7e83 LB |
1416 | void setCanReturnTwice() { |
1417 | addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice); | |
223e47cc LB |
1418 | } |
1419 | ||
970d7e83 | 1420 | /// \brief Determine if the call does not access memory. |
223e47cc LB |
1421 | bool doesNotAccessMemory() const { |
1422 | return hasFnAttr(Attribute::ReadNone); | |
1423 | } | |
970d7e83 LB |
1424 | void setDoesNotAccessMemory() { |
1425 | addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone); | |
223e47cc LB |
1426 | } |
1427 | ||
970d7e83 | 1428 | /// \brief Determine if the call does not access or only reads memory. |
223e47cc LB |
1429 | bool onlyReadsMemory() const { |
1430 | return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly); | |
1431 | } | |
970d7e83 LB |
1432 | void setOnlyReadsMemory() { |
1433 | addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly); | |
223e47cc LB |
1434 | } |
1435 | ||
970d7e83 | 1436 | /// \brief Determine if the call cannot return. |
223e47cc | 1437 | bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); } |
970d7e83 LB |
1438 | void setDoesNotReturn() { |
1439 | addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn); | |
223e47cc LB |
1440 | } |
1441 | ||
970d7e83 | 1442 | /// \brief Determine if the call cannot unwind. |
223e47cc | 1443 | bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); } |
970d7e83 LB |
1444 | void setDoesNotThrow() { |
1445 | addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind); | |
223e47cc LB |
1446 | } |
1447 | ||
970d7e83 LB |
1448 | /// \brief Determine if the call cannot be duplicated. |
1449 | bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); } | |
1450 | void setCannotDuplicate() { | |
1451 | addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate); | |
1452 | } | |
1453 | ||
1454 | /// \brief Determine if the call returns a structure through first | |
223e47cc LB |
1455 | /// pointer argument. |
1456 | bool hasStructRetAttr() const { | |
1457 | // Be friendly and also check the callee. | |
1458 | return paramHasAttr(1, Attribute::StructRet); | |
1459 | } | |
1460 | ||
970d7e83 | 1461 | /// \brief Determine if any call argument is an aggregate passed by value. |
223e47cc LB |
1462 | bool hasByValArgument() const { |
1463 | return AttributeList.hasAttrSomewhere(Attribute::ByVal); | |
1464 | } | |
1465 | ||
1466 | /// getCalledFunction - Return the function called, or null if this is an | |
1467 | /// indirect function invocation. | |
1468 | /// | |
1469 | Function *getCalledFunction() const { | |
1470 | return dyn_cast<Function>(Op<-1>()); | |
1471 | } | |
1472 | ||
1473 | /// getCalledValue - Get a pointer to the function that is invoked by this | |
1474 | /// instruction. | |
1475 | const Value *getCalledValue() const { return Op<-1>(); } | |
1476 | Value *getCalledValue() { return Op<-1>(); } | |
1477 | ||
1478 | /// setCalledFunction - Set the function called. | |
1479 | void setCalledFunction(Value* Fn) { | |
1480 | Op<-1>() = Fn; | |
1481 | } | |
1482 | ||
1483 | /// isInlineAsm - Check if this call is an inline asm statement. | |
1484 | bool isInlineAsm() const { | |
1485 | return isa<InlineAsm>(Op<-1>()); | |
1486 | } | |
1487 | ||
1488 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
1489 | static inline bool classof(const Instruction *I) { |
1490 | return I->getOpcode() == Instruction::Call; | |
1491 | } | |
1492 | static inline bool classof(const Value *V) { | |
1493 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
1494 | } | |
1495 | private: | |
1a4d82fc JJ |
1496 | |
1497 | bool hasFnAttrImpl(Attribute::AttrKind A) const; | |
1498 | ||
223e47cc LB |
1499 | // Shadow Instruction::setInstructionSubclassData with a private forwarding |
1500 | // method so that subclasses cannot accidentally use it. | |
1501 | void setInstructionSubclassData(unsigned short D) { | |
1502 | Instruction::setInstructionSubclassData(D); | |
1503 | } | |
1504 | }; | |
1505 | ||
1506 | template <> | |
1507 | struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> { | |
1508 | }; | |
1509 | ||
1510 | CallInst::CallInst(Value *Func, ArrayRef<Value *> Args, | |
1511 | const Twine &NameStr, BasicBlock *InsertAtEnd) | |
1512 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) | |
1513 | ->getElementType())->getReturnType(), | |
1514 | Instruction::Call, | |
1515 | OperandTraits<CallInst>::op_end(this) - (Args.size() + 1), | |
1516 | unsigned(Args.size() + 1), InsertAtEnd) { | |
1517 | init(Func, Args, NameStr); | |
1518 | } | |
1519 | ||
1520 | CallInst::CallInst(Value *Func, ArrayRef<Value *> Args, | |
1521 | const Twine &NameStr, Instruction *InsertBefore) | |
1522 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) | |
1523 | ->getElementType())->getReturnType(), | |
1524 | Instruction::Call, | |
1525 | OperandTraits<CallInst>::op_end(this) - (Args.size() + 1), | |
1526 | unsigned(Args.size() + 1), InsertBefore) { | |
1527 | init(Func, Args, NameStr); | |
1528 | } | |
1529 | ||
1530 | ||
1531 | // Note: if you get compile errors about private methods then | |
1532 | // please update your code to use the high-level operand | |
1533 | // interfaces. See line 943 above. | |
1534 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value) | |
1535 | ||
1536 | //===----------------------------------------------------------------------===// | |
1537 | // SelectInst Class | |
1538 | //===----------------------------------------------------------------------===// | |
1539 | ||
1540 | /// SelectInst - This class represents the LLVM 'select' instruction. | |
1541 | /// | |
1542 | class SelectInst : public Instruction { | |
1543 | void init(Value *C, Value *S1, Value *S2) { | |
1544 | assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select"); | |
1545 | Op<0>() = C; | |
1546 | Op<1>() = S1; | |
1547 | Op<2>() = S2; | |
1548 | } | |
1549 | ||
1550 | SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr, | |
1551 | Instruction *InsertBefore) | |
1552 | : Instruction(S1->getType(), Instruction::Select, | |
1553 | &Op<0>(), 3, InsertBefore) { | |
1554 | init(C, S1, S2); | |
1555 | setName(NameStr); | |
1556 | } | |
1557 | SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr, | |
1558 | BasicBlock *InsertAtEnd) | |
1559 | : Instruction(S1->getType(), Instruction::Select, | |
1560 | &Op<0>(), 3, InsertAtEnd) { | |
1561 | init(C, S1, S2); | |
1562 | setName(NameStr); | |
1563 | } | |
1564 | protected: | |
1a4d82fc | 1565 | SelectInst *clone_impl() const override; |
223e47cc LB |
1566 | public: |
1567 | static SelectInst *Create(Value *C, Value *S1, Value *S2, | |
1568 | const Twine &NameStr = "", | |
1a4d82fc | 1569 | Instruction *InsertBefore = nullptr) { |
223e47cc LB |
1570 | return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore); |
1571 | } | |
1572 | static SelectInst *Create(Value *C, Value *S1, Value *S2, | |
1573 | const Twine &NameStr, | |
1574 | BasicBlock *InsertAtEnd) { | |
1575 | return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd); | |
1576 | } | |
1577 | ||
1578 | const Value *getCondition() const { return Op<0>(); } | |
1579 | const Value *getTrueValue() const { return Op<1>(); } | |
1580 | const Value *getFalseValue() const { return Op<2>(); } | |
1581 | Value *getCondition() { return Op<0>(); } | |
1582 | Value *getTrueValue() { return Op<1>(); } | |
1583 | Value *getFalseValue() { return Op<2>(); } | |
1584 | ||
1585 | /// areInvalidOperands - Return a string if the specified operands are invalid | |
1586 | /// for a select operation, otherwise return null. | |
1587 | static const char *areInvalidOperands(Value *Cond, Value *True, Value *False); | |
1588 | ||
1589 | /// Transparently provide more efficient getOperand methods. | |
1590 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
1591 | ||
1592 | OtherOps getOpcode() const { | |
1593 | return static_cast<OtherOps>(Instruction::getOpcode()); | |
1594 | } | |
1595 | ||
1596 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
1597 | static inline bool classof(const Instruction *I) { |
1598 | return I->getOpcode() == Instruction::Select; | |
1599 | } | |
1600 | static inline bool classof(const Value *V) { | |
1601 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
1602 | } | |
1603 | }; | |
1604 | ||
1605 | template <> | |
1606 | struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> { | |
1607 | }; | |
1608 | ||
1609 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value) | |
1610 | ||
1611 | //===----------------------------------------------------------------------===// | |
1612 | // VAArgInst Class | |
1613 | //===----------------------------------------------------------------------===// | |
1614 | ||
1615 | /// VAArgInst - This class represents the va_arg llvm instruction, which returns | |
1616 | /// an argument of the specified type given a va_list and increments that list | |
1617 | /// | |
1618 | class VAArgInst : public UnaryInstruction { | |
1619 | protected: | |
1a4d82fc | 1620 | VAArgInst *clone_impl() const override; |
223e47cc LB |
1621 | |
1622 | public: | |
1623 | VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "", | |
1a4d82fc | 1624 | Instruction *InsertBefore = nullptr) |
223e47cc LB |
1625 | : UnaryInstruction(Ty, VAArg, List, InsertBefore) { |
1626 | setName(NameStr); | |
1627 | } | |
1628 | VAArgInst(Value *List, Type *Ty, const Twine &NameStr, | |
1629 | BasicBlock *InsertAtEnd) | |
1630 | : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) { | |
1631 | setName(NameStr); | |
1632 | } | |
1633 | ||
1634 | Value *getPointerOperand() { return getOperand(0); } | |
1635 | const Value *getPointerOperand() const { return getOperand(0); } | |
1636 | static unsigned getPointerOperandIndex() { return 0U; } | |
1637 | ||
1638 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
1639 | static inline bool classof(const Instruction *I) { |
1640 | return I->getOpcode() == VAArg; | |
1641 | } | |
1642 | static inline bool classof(const Value *V) { | |
1643 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
1644 | } | |
1645 | }; | |
1646 | ||
1647 | //===----------------------------------------------------------------------===// | |
1648 | // ExtractElementInst Class | |
1649 | //===----------------------------------------------------------------------===// | |
1650 | ||
1651 | /// ExtractElementInst - This instruction extracts a single (scalar) | |
1652 | /// element from a VectorType value | |
1653 | /// | |
1654 | class ExtractElementInst : public Instruction { | |
1655 | ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "", | |
1a4d82fc | 1656 | Instruction *InsertBefore = nullptr); |
223e47cc LB |
1657 | ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr, |
1658 | BasicBlock *InsertAtEnd); | |
1659 | protected: | |
1a4d82fc | 1660 | ExtractElementInst *clone_impl() const override; |
223e47cc LB |
1661 | |
1662 | public: | |
1663 | static ExtractElementInst *Create(Value *Vec, Value *Idx, | |
1664 | const Twine &NameStr = "", | |
1a4d82fc | 1665 | Instruction *InsertBefore = nullptr) { |
223e47cc LB |
1666 | return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore); |
1667 | } | |
1668 | static ExtractElementInst *Create(Value *Vec, Value *Idx, | |
1669 | const Twine &NameStr, | |
1670 | BasicBlock *InsertAtEnd) { | |
1671 | return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd); | |
1672 | } | |
1673 | ||
1674 | /// isValidOperands - Return true if an extractelement instruction can be | |
1675 | /// formed with the specified operands. | |
1676 | static bool isValidOperands(const Value *Vec, const Value *Idx); | |
1677 | ||
1678 | Value *getVectorOperand() { return Op<0>(); } | |
1679 | Value *getIndexOperand() { return Op<1>(); } | |
1680 | const Value *getVectorOperand() const { return Op<0>(); } | |
1681 | const Value *getIndexOperand() const { return Op<1>(); } | |
1682 | ||
1683 | VectorType *getVectorOperandType() const { | |
970d7e83 | 1684 | return cast<VectorType>(getVectorOperand()->getType()); |
223e47cc LB |
1685 | } |
1686 | ||
1687 | ||
1688 | /// Transparently provide more efficient getOperand methods. | |
1689 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
1690 | ||
1691 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
1692 | static inline bool classof(const Instruction *I) { |
1693 | return I->getOpcode() == Instruction::ExtractElement; | |
1694 | } | |
1695 | static inline bool classof(const Value *V) { | |
1696 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
1697 | } | |
1698 | }; | |
1699 | ||
1700 | template <> | |
1701 | struct OperandTraits<ExtractElementInst> : | |
1702 | public FixedNumOperandTraits<ExtractElementInst, 2> { | |
1703 | }; | |
1704 | ||
1705 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value) | |
1706 | ||
1707 | //===----------------------------------------------------------------------===// | |
1708 | // InsertElementInst Class | |
1709 | //===----------------------------------------------------------------------===// | |
1710 | ||
1711 | /// InsertElementInst - This instruction inserts a single (scalar) | |
1712 | /// element into a VectorType value | |
1713 | /// | |
1714 | class InsertElementInst : public Instruction { | |
1715 | InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, | |
1716 | const Twine &NameStr = "", | |
1a4d82fc | 1717 | Instruction *InsertBefore = nullptr); |
223e47cc LB |
1718 | InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, |
1719 | const Twine &NameStr, BasicBlock *InsertAtEnd); | |
1720 | protected: | |
1a4d82fc | 1721 | InsertElementInst *clone_impl() const override; |
223e47cc LB |
1722 | |
1723 | public: | |
1724 | static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, | |
1725 | const Twine &NameStr = "", | |
1a4d82fc | 1726 | Instruction *InsertBefore = nullptr) { |
223e47cc LB |
1727 | return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore); |
1728 | } | |
1729 | static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, | |
1730 | const Twine &NameStr, | |
1731 | BasicBlock *InsertAtEnd) { | |
1732 | return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd); | |
1733 | } | |
1734 | ||
1735 | /// isValidOperands - Return true if an insertelement instruction can be | |
1736 | /// formed with the specified operands. | |
1737 | static bool isValidOperands(const Value *Vec, const Value *NewElt, | |
1738 | const Value *Idx); | |
1739 | ||
1740 | /// getType - Overload to return most specific vector type. | |
1741 | /// | |
1742 | VectorType *getType() const { | |
970d7e83 | 1743 | return cast<VectorType>(Instruction::getType()); |
223e47cc LB |
1744 | } |
1745 | ||
1746 | /// Transparently provide more efficient getOperand methods. | |
1747 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
1748 | ||
1749 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
1750 | static inline bool classof(const Instruction *I) { |
1751 | return I->getOpcode() == Instruction::InsertElement; | |
1752 | } | |
1753 | static inline bool classof(const Value *V) { | |
1754 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
1755 | } | |
1756 | }; | |
1757 | ||
1758 | template <> | |
1759 | struct OperandTraits<InsertElementInst> : | |
1760 | public FixedNumOperandTraits<InsertElementInst, 3> { | |
1761 | }; | |
1762 | ||
1763 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value) | |
1764 | ||
1765 | //===----------------------------------------------------------------------===// | |
1766 | // ShuffleVectorInst Class | |
1767 | //===----------------------------------------------------------------------===// | |
1768 | ||
1769 | /// ShuffleVectorInst - This instruction constructs a fixed permutation of two | |
1770 | /// input vectors. | |
1771 | /// | |
1772 | class ShuffleVectorInst : public Instruction { | |
1773 | protected: | |
1a4d82fc | 1774 | ShuffleVectorInst *clone_impl() const override; |
223e47cc LB |
1775 | |
1776 | public: | |
1777 | // allocate space for exactly three operands | |
1778 | void *operator new(size_t s) { | |
1779 | return User::operator new(s, 3); | |
1780 | } | |
1781 | ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, | |
1782 | const Twine &NameStr = "", | |
1a4d82fc | 1783 | Instruction *InsertBefor = nullptr); |
223e47cc LB |
1784 | ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, |
1785 | const Twine &NameStr, BasicBlock *InsertAtEnd); | |
1786 | ||
1787 | /// isValidOperands - Return true if a shufflevector instruction can be | |
1788 | /// formed with the specified operands. | |
1789 | static bool isValidOperands(const Value *V1, const Value *V2, | |
1790 | const Value *Mask); | |
1791 | ||
1792 | /// getType - Overload to return most specific vector type. | |
1793 | /// | |
1794 | VectorType *getType() const { | |
970d7e83 | 1795 | return cast<VectorType>(Instruction::getType()); |
223e47cc LB |
1796 | } |
1797 | ||
1798 | /// Transparently provide more efficient getOperand methods. | |
1799 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
1800 | ||
1801 | Constant *getMask() const { | |
970d7e83 | 1802 | return cast<Constant>(getOperand(2)); |
223e47cc | 1803 | } |
970d7e83 | 1804 | |
223e47cc LB |
1805 | /// getMaskValue - Return the index from the shuffle mask for the specified |
1806 | /// output result. This is either -1 if the element is undef or a number less | |
1807 | /// than 2*numelements. | |
1808 | static int getMaskValue(Constant *Mask, unsigned i); | |
1809 | ||
1810 | int getMaskValue(unsigned i) const { | |
1811 | return getMaskValue(getMask(), i); | |
1812 | } | |
970d7e83 | 1813 | |
223e47cc LB |
1814 | /// getShuffleMask - Return the full mask for this instruction, where each |
1815 | /// element is the element number and undef's are returned as -1. | |
1816 | static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result); | |
1817 | ||
1818 | void getShuffleMask(SmallVectorImpl<int> &Result) const { | |
1819 | return getShuffleMask(getMask(), Result); | |
1820 | } | |
1821 | ||
1822 | SmallVector<int, 16> getShuffleMask() const { | |
1823 | SmallVector<int, 16> Mask; | |
1824 | getShuffleMask(Mask); | |
1825 | return Mask; | |
1826 | } | |
1827 | ||
1828 | ||
1829 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
1830 | static inline bool classof(const Instruction *I) { |
1831 | return I->getOpcode() == Instruction::ShuffleVector; | |
1832 | } | |
1833 | static inline bool classof(const Value *V) { | |
1834 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
1835 | } | |
1836 | }; | |
1837 | ||
1838 | template <> | |
1839 | struct OperandTraits<ShuffleVectorInst> : | |
1840 | public FixedNumOperandTraits<ShuffleVectorInst, 3> { | |
1841 | }; | |
1842 | ||
1843 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value) | |
1844 | ||
1845 | //===----------------------------------------------------------------------===// | |
1846 | // ExtractValueInst Class | |
1847 | //===----------------------------------------------------------------------===// | |
1848 | ||
1849 | /// ExtractValueInst - This instruction extracts a struct member or array | |
1850 | /// element value from an aggregate value. | |
1851 | /// | |
1852 | class ExtractValueInst : public UnaryInstruction { | |
1853 | SmallVector<unsigned, 4> Indices; | |
1854 | ||
1855 | ExtractValueInst(const ExtractValueInst &EVI); | |
1856 | void init(ArrayRef<unsigned> Idxs, const Twine &NameStr); | |
1857 | ||
1858 | /// Constructors - Create a extractvalue instruction with a base aggregate | |
1859 | /// value and a list of indices. The first ctor can optionally insert before | |
1860 | /// an existing instruction, the second appends the new instruction to the | |
1861 | /// specified BasicBlock. | |
1862 | inline ExtractValueInst(Value *Agg, | |
1863 | ArrayRef<unsigned> Idxs, | |
1864 | const Twine &NameStr, | |
1865 | Instruction *InsertBefore); | |
1866 | inline ExtractValueInst(Value *Agg, | |
1867 | ArrayRef<unsigned> Idxs, | |
1868 | const Twine &NameStr, BasicBlock *InsertAtEnd); | |
1869 | ||
1870 | // allocate space for exactly one operand | |
1871 | void *operator new(size_t s) { | |
1872 | return User::operator new(s, 1); | |
1873 | } | |
1874 | protected: | |
1a4d82fc | 1875 | ExtractValueInst *clone_impl() const override; |
223e47cc LB |
1876 | |
1877 | public: | |
1878 | static ExtractValueInst *Create(Value *Agg, | |
1879 | ArrayRef<unsigned> Idxs, | |
1880 | const Twine &NameStr = "", | |
1a4d82fc | 1881 | Instruction *InsertBefore = nullptr) { |
223e47cc LB |
1882 | return new |
1883 | ExtractValueInst(Agg, Idxs, NameStr, InsertBefore); | |
1884 | } | |
1885 | static ExtractValueInst *Create(Value *Agg, | |
1886 | ArrayRef<unsigned> Idxs, | |
1887 | const Twine &NameStr, | |
1888 | BasicBlock *InsertAtEnd) { | |
1889 | return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd); | |
1890 | } | |
1891 | ||
1892 | /// getIndexedType - Returns the type of the element that would be extracted | |
1893 | /// with an extractvalue instruction with the specified parameters. | |
1894 | /// | |
1895 | /// Null is returned if the indices are invalid for the specified type. | |
1896 | static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs); | |
1897 | ||
1898 | typedef const unsigned* idx_iterator; | |
1899 | inline idx_iterator idx_begin() const { return Indices.begin(); } | |
1900 | inline idx_iterator idx_end() const { return Indices.end(); } | |
1901 | ||
1902 | Value *getAggregateOperand() { | |
1903 | return getOperand(0); | |
1904 | } | |
1905 | const Value *getAggregateOperand() const { | |
1906 | return getOperand(0); | |
1907 | } | |
1908 | static unsigned getAggregateOperandIndex() { | |
1909 | return 0U; // get index for modifying correct operand | |
1910 | } | |
1911 | ||
1912 | ArrayRef<unsigned> getIndices() const { | |
1913 | return Indices; | |
1914 | } | |
1915 | ||
1916 | unsigned getNumIndices() const { | |
1917 | return (unsigned)Indices.size(); | |
1918 | } | |
1919 | ||
1920 | bool hasIndices() const { | |
1921 | return true; | |
1922 | } | |
1923 | ||
1924 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
1925 | static inline bool classof(const Instruction *I) { |
1926 | return I->getOpcode() == Instruction::ExtractValue; | |
1927 | } | |
1928 | static inline bool classof(const Value *V) { | |
1929 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
1930 | } | |
1931 | }; | |
1932 | ||
1933 | ExtractValueInst::ExtractValueInst(Value *Agg, | |
1934 | ArrayRef<unsigned> Idxs, | |
1935 | const Twine &NameStr, | |
1936 | Instruction *InsertBefore) | |
1937 | : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)), | |
1938 | ExtractValue, Agg, InsertBefore) { | |
1939 | init(Idxs, NameStr); | |
1940 | } | |
1941 | ExtractValueInst::ExtractValueInst(Value *Agg, | |
1942 | ArrayRef<unsigned> Idxs, | |
1943 | const Twine &NameStr, | |
1944 | BasicBlock *InsertAtEnd) | |
1945 | : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)), | |
1946 | ExtractValue, Agg, InsertAtEnd) { | |
1947 | init(Idxs, NameStr); | |
1948 | } | |
1949 | ||
1950 | ||
1951 | //===----------------------------------------------------------------------===// | |
1952 | // InsertValueInst Class | |
1953 | //===----------------------------------------------------------------------===// | |
1954 | ||
1955 | /// InsertValueInst - This instruction inserts a struct field of array element | |
1956 | /// value into an aggregate value. | |
1957 | /// | |
1958 | class InsertValueInst : public Instruction { | |
1959 | SmallVector<unsigned, 4> Indices; | |
1960 | ||
1961 | void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; | |
1962 | InsertValueInst(const InsertValueInst &IVI); | |
1963 | void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs, | |
1964 | const Twine &NameStr); | |
1965 | ||
1966 | /// Constructors - Create a insertvalue instruction with a base aggregate | |
1967 | /// value, a value to insert, and a list of indices. The first ctor can | |
1968 | /// optionally insert before an existing instruction, the second appends | |
1969 | /// the new instruction to the specified BasicBlock. | |
1970 | inline InsertValueInst(Value *Agg, Value *Val, | |
1971 | ArrayRef<unsigned> Idxs, | |
1972 | const Twine &NameStr, | |
1973 | Instruction *InsertBefore); | |
1974 | inline InsertValueInst(Value *Agg, Value *Val, | |
1975 | ArrayRef<unsigned> Idxs, | |
1976 | const Twine &NameStr, BasicBlock *InsertAtEnd); | |
1977 | ||
1978 | /// Constructors - These two constructors are convenience methods because one | |
1979 | /// and two index insertvalue instructions are so common. | |
1980 | InsertValueInst(Value *Agg, Value *Val, | |
1981 | unsigned Idx, const Twine &NameStr = "", | |
1a4d82fc | 1982 | Instruction *InsertBefore = nullptr); |
223e47cc LB |
1983 | InsertValueInst(Value *Agg, Value *Val, unsigned Idx, |
1984 | const Twine &NameStr, BasicBlock *InsertAtEnd); | |
1985 | protected: | |
1a4d82fc | 1986 | InsertValueInst *clone_impl() const override; |
223e47cc LB |
1987 | public: |
1988 | // allocate space for exactly two operands | |
1989 | void *operator new(size_t s) { | |
1990 | return User::operator new(s, 2); | |
1991 | } | |
1992 | ||
1993 | static InsertValueInst *Create(Value *Agg, Value *Val, | |
1994 | ArrayRef<unsigned> Idxs, | |
1995 | const Twine &NameStr = "", | |
1a4d82fc | 1996 | Instruction *InsertBefore = nullptr) { |
223e47cc LB |
1997 | return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore); |
1998 | } | |
1999 | static InsertValueInst *Create(Value *Agg, Value *Val, | |
2000 | ArrayRef<unsigned> Idxs, | |
2001 | const Twine &NameStr, | |
2002 | BasicBlock *InsertAtEnd) { | |
2003 | return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd); | |
2004 | } | |
2005 | ||
2006 | /// Transparently provide more efficient getOperand methods. | |
2007 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
2008 | ||
2009 | typedef const unsigned* idx_iterator; | |
2010 | inline idx_iterator idx_begin() const { return Indices.begin(); } | |
2011 | inline idx_iterator idx_end() const { return Indices.end(); } | |
2012 | ||
2013 | Value *getAggregateOperand() { | |
2014 | return getOperand(0); | |
2015 | } | |
2016 | const Value *getAggregateOperand() const { | |
2017 | return getOperand(0); | |
2018 | } | |
2019 | static unsigned getAggregateOperandIndex() { | |
2020 | return 0U; // get index for modifying correct operand | |
2021 | } | |
2022 | ||
2023 | Value *getInsertedValueOperand() { | |
2024 | return getOperand(1); | |
2025 | } | |
2026 | const Value *getInsertedValueOperand() const { | |
2027 | return getOperand(1); | |
2028 | } | |
2029 | static unsigned getInsertedValueOperandIndex() { | |
2030 | return 1U; // get index for modifying correct operand | |
2031 | } | |
2032 | ||
2033 | ArrayRef<unsigned> getIndices() const { | |
2034 | return Indices; | |
2035 | } | |
2036 | ||
2037 | unsigned getNumIndices() const { | |
2038 | return (unsigned)Indices.size(); | |
2039 | } | |
2040 | ||
2041 | bool hasIndices() const { | |
2042 | return true; | |
2043 | } | |
2044 | ||
2045 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
2046 | static inline bool classof(const Instruction *I) { |
2047 | return I->getOpcode() == Instruction::InsertValue; | |
2048 | } | |
2049 | static inline bool classof(const Value *V) { | |
2050 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
2051 | } | |
2052 | }; | |
2053 | ||
2054 | template <> | |
2055 | struct OperandTraits<InsertValueInst> : | |
2056 | public FixedNumOperandTraits<InsertValueInst, 2> { | |
2057 | }; | |
2058 | ||
2059 | InsertValueInst::InsertValueInst(Value *Agg, | |
2060 | Value *Val, | |
2061 | ArrayRef<unsigned> Idxs, | |
2062 | const Twine &NameStr, | |
2063 | Instruction *InsertBefore) | |
2064 | : Instruction(Agg->getType(), InsertValue, | |
2065 | OperandTraits<InsertValueInst>::op_begin(this), | |
2066 | 2, InsertBefore) { | |
2067 | init(Agg, Val, Idxs, NameStr); | |
2068 | } | |
2069 | InsertValueInst::InsertValueInst(Value *Agg, | |
2070 | Value *Val, | |
2071 | ArrayRef<unsigned> Idxs, | |
2072 | const Twine &NameStr, | |
2073 | BasicBlock *InsertAtEnd) | |
2074 | : Instruction(Agg->getType(), InsertValue, | |
2075 | OperandTraits<InsertValueInst>::op_begin(this), | |
2076 | 2, InsertAtEnd) { | |
2077 | init(Agg, Val, Idxs, NameStr); | |
2078 | } | |
2079 | ||
2080 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value) | |
2081 | ||
2082 | //===----------------------------------------------------------------------===// | |
2083 | // PHINode Class | |
2084 | //===----------------------------------------------------------------------===// | |
2085 | ||
2086 | // PHINode - The PHINode class is used to represent the magical mystical PHI | |
2087 | // node, that can not exist in nature, but can be synthesized in a computer | |
2088 | // scientist's overactive imagination. | |
2089 | // | |
2090 | class PHINode : public Instruction { | |
2091 | void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; | |
2092 | /// ReservedSpace - The number of operands actually allocated. NumOperands is | |
2093 | /// the number actually in use. | |
2094 | unsigned ReservedSpace; | |
2095 | PHINode(const PHINode &PN); | |
2096 | // allocate space for exactly zero operands | |
2097 | void *operator new(size_t s) { | |
2098 | return User::operator new(s, 0); | |
2099 | } | |
2100 | explicit PHINode(Type *Ty, unsigned NumReservedValues, | |
1a4d82fc JJ |
2101 | const Twine &NameStr = "", |
2102 | Instruction *InsertBefore = nullptr) | |
2103 | : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore), | |
223e47cc LB |
2104 | ReservedSpace(NumReservedValues) { |
2105 | setName(NameStr); | |
2106 | OperandList = allocHungoffUses(ReservedSpace); | |
2107 | } | |
2108 | ||
2109 | PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr, | |
2110 | BasicBlock *InsertAtEnd) | |
1a4d82fc | 2111 | : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd), |
223e47cc LB |
2112 | ReservedSpace(NumReservedValues) { |
2113 | setName(NameStr); | |
2114 | OperandList = allocHungoffUses(ReservedSpace); | |
2115 | } | |
2116 | protected: | |
2117 | // allocHungoffUses - this is more complicated than the generic | |
2118 | // User::allocHungoffUses, because we have to allocate Uses for the incoming | |
2119 | // values and pointers to the incoming blocks, all in one allocation. | |
2120 | Use *allocHungoffUses(unsigned) const; | |
2121 | ||
1a4d82fc | 2122 | PHINode *clone_impl() const override; |
223e47cc LB |
2123 | public: |
2124 | /// Constructors - NumReservedValues is a hint for the number of incoming | |
2125 | /// edges that this phi node will have (use 0 if you really have no idea). | |
2126 | static PHINode *Create(Type *Ty, unsigned NumReservedValues, | |
2127 | const Twine &NameStr = "", | |
1a4d82fc | 2128 | Instruction *InsertBefore = nullptr) { |
223e47cc LB |
2129 | return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore); |
2130 | } | |
970d7e83 | 2131 | static PHINode *Create(Type *Ty, unsigned NumReservedValues, |
223e47cc LB |
2132 | const Twine &NameStr, BasicBlock *InsertAtEnd) { |
2133 | return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd); | |
2134 | } | |
2135 | ~PHINode(); | |
2136 | ||
2137 | /// Provide fast operand accessors | |
2138 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
2139 | ||
2140 | // Block iterator interface. This provides access to the list of incoming | |
2141 | // basic blocks, which parallels the list of incoming values. | |
2142 | ||
2143 | typedef BasicBlock **block_iterator; | |
2144 | typedef BasicBlock * const *const_block_iterator; | |
2145 | ||
2146 | block_iterator block_begin() { | |
2147 | Use::UserRef *ref = | |
2148 | reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace); | |
2149 | return reinterpret_cast<block_iterator>(ref + 1); | |
2150 | } | |
2151 | ||
2152 | const_block_iterator block_begin() const { | |
2153 | const Use::UserRef *ref = | |
2154 | reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace); | |
2155 | return reinterpret_cast<const_block_iterator>(ref + 1); | |
2156 | } | |
2157 | ||
2158 | block_iterator block_end() { | |
2159 | return block_begin() + getNumOperands(); | |
2160 | } | |
2161 | ||
2162 | const_block_iterator block_end() const { | |
2163 | return block_begin() + getNumOperands(); | |
2164 | } | |
2165 | ||
2166 | /// getNumIncomingValues - Return the number of incoming edges | |
2167 | /// | |
2168 | unsigned getNumIncomingValues() const { return getNumOperands(); } | |
2169 | ||
2170 | /// getIncomingValue - Return incoming value number x | |
2171 | /// | |
2172 | Value *getIncomingValue(unsigned i) const { | |
2173 | return getOperand(i); | |
2174 | } | |
2175 | void setIncomingValue(unsigned i, Value *V) { | |
2176 | setOperand(i, V); | |
2177 | } | |
2178 | static unsigned getOperandNumForIncomingValue(unsigned i) { | |
2179 | return i; | |
2180 | } | |
2181 | static unsigned getIncomingValueNumForOperand(unsigned i) { | |
2182 | return i; | |
2183 | } | |
2184 | ||
2185 | /// getIncomingBlock - Return incoming basic block number @p i. | |
2186 | /// | |
2187 | BasicBlock *getIncomingBlock(unsigned i) const { | |
2188 | return block_begin()[i]; | |
2189 | } | |
2190 | ||
2191 | /// getIncomingBlock - Return incoming basic block corresponding | |
2192 | /// to an operand of the PHI. | |
2193 | /// | |
2194 | BasicBlock *getIncomingBlock(const Use &U) const { | |
2195 | assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?"); | |
2196 | return getIncomingBlock(unsigned(&U - op_begin())); | |
2197 | } | |
2198 | ||
2199 | /// getIncomingBlock - Return incoming basic block corresponding | |
2200 | /// to value use iterator. | |
2201 | /// | |
1a4d82fc | 2202 | BasicBlock *getIncomingBlock(Value::const_user_iterator I) const { |
223e47cc LB |
2203 | return getIncomingBlock(I.getUse()); |
2204 | } | |
2205 | ||
2206 | void setIncomingBlock(unsigned i, BasicBlock *BB) { | |
2207 | block_begin()[i] = BB; | |
2208 | } | |
2209 | ||
2210 | /// addIncoming - Add an incoming value to the end of the PHI list | |
2211 | /// | |
2212 | void addIncoming(Value *V, BasicBlock *BB) { | |
2213 | assert(V && "PHI node got a null value!"); | |
2214 | assert(BB && "PHI node got a null basic block!"); | |
2215 | assert(getType() == V->getType() && | |
2216 | "All operands to PHI node must be the same type as the PHI node!"); | |
2217 | if (NumOperands == ReservedSpace) | |
2218 | growOperands(); // Get more space! | |
2219 | // Initialize some new operands. | |
2220 | ++NumOperands; | |
2221 | setIncomingValue(NumOperands - 1, V); | |
2222 | setIncomingBlock(NumOperands - 1, BB); | |
2223 | } | |
2224 | ||
2225 | /// removeIncomingValue - Remove an incoming value. This is useful if a | |
2226 | /// predecessor basic block is deleted. The value removed is returned. | |
2227 | /// | |
2228 | /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty | |
2229 | /// is true), the PHI node is destroyed and any uses of it are replaced with | |
2230 | /// dummy values. The only time there should be zero incoming values to a PHI | |
2231 | /// node is when the block is dead, so this strategy is sound. | |
2232 | /// | |
2233 | Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true); | |
2234 | ||
2235 | Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) { | |
2236 | int Idx = getBasicBlockIndex(BB); | |
2237 | assert(Idx >= 0 && "Invalid basic block argument to remove!"); | |
2238 | return removeIncomingValue(Idx, DeletePHIIfEmpty); | |
2239 | } | |
2240 | ||
2241 | /// getBasicBlockIndex - Return the first index of the specified basic | |
2242 | /// block in the value list for this PHI. Returns -1 if no instance. | |
2243 | /// | |
2244 | int getBasicBlockIndex(const BasicBlock *BB) const { | |
2245 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) | |
2246 | if (block_begin()[i] == BB) | |
2247 | return i; | |
2248 | return -1; | |
2249 | } | |
2250 | ||
2251 | Value *getIncomingValueForBlock(const BasicBlock *BB) const { | |
2252 | int Idx = getBasicBlockIndex(BB); | |
2253 | assert(Idx >= 0 && "Invalid basic block argument!"); | |
2254 | return getIncomingValue(Idx); | |
2255 | } | |
2256 | ||
2257 | /// hasConstantValue - If the specified PHI node always merges together the | |
2258 | /// same value, return the value, otherwise return null. | |
2259 | Value *hasConstantValue() const; | |
2260 | ||
2261 | /// Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
2262 | static inline bool classof(const Instruction *I) { |
2263 | return I->getOpcode() == Instruction::PHI; | |
2264 | } | |
2265 | static inline bool classof(const Value *V) { | |
2266 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
2267 | } | |
2268 | private: | |
2269 | void growOperands(); | |
2270 | }; | |
2271 | ||
2272 | template <> | |
2273 | struct OperandTraits<PHINode> : public HungoffOperandTraits<2> { | |
2274 | }; | |
2275 | ||
2276 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value) | |
2277 | ||
2278 | //===----------------------------------------------------------------------===// | |
2279 | // LandingPadInst Class | |
2280 | //===----------------------------------------------------------------------===// | |
2281 | ||
2282 | //===--------------------------------------------------------------------------- | |
2283 | /// LandingPadInst - The landingpad instruction holds all of the information | |
2284 | /// necessary to generate correct exception handling. The landingpad instruction | |
2285 | /// cannot be moved from the top of a landing pad block, which itself is | |
2286 | /// accessible only from the 'unwind' edge of an invoke. This uses the | |
2287 | /// SubclassData field in Value to store whether or not the landingpad is a | |
2288 | /// cleanup. | |
2289 | /// | |
2290 | class LandingPadInst : public Instruction { | |
2291 | /// ReservedSpace - The number of operands actually allocated. NumOperands is | |
2292 | /// the number actually in use. | |
2293 | unsigned ReservedSpace; | |
2294 | LandingPadInst(const LandingPadInst &LP); | |
2295 | public: | |
2296 | enum ClauseType { Catch, Filter }; | |
2297 | private: | |
2298 | void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; | |
2299 | // Allocate space for exactly zero operands. | |
2300 | void *operator new(size_t s) { | |
2301 | return User::operator new(s, 0); | |
2302 | } | |
2303 | void growOperands(unsigned Size); | |
2304 | void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr); | |
2305 | ||
2306 | explicit LandingPadInst(Type *RetTy, Value *PersonalityFn, | |
2307 | unsigned NumReservedValues, const Twine &NameStr, | |
2308 | Instruction *InsertBefore); | |
2309 | explicit LandingPadInst(Type *RetTy, Value *PersonalityFn, | |
2310 | unsigned NumReservedValues, const Twine &NameStr, | |
2311 | BasicBlock *InsertAtEnd); | |
2312 | protected: | |
1a4d82fc | 2313 | LandingPadInst *clone_impl() const override; |
223e47cc LB |
2314 | public: |
2315 | /// Constructors - NumReservedClauses is a hint for the number of incoming | |
2316 | /// clauses that this landingpad will have (use 0 if you really have no idea). | |
2317 | static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn, | |
2318 | unsigned NumReservedClauses, | |
2319 | const Twine &NameStr = "", | |
1a4d82fc | 2320 | Instruction *InsertBefore = nullptr); |
223e47cc LB |
2321 | static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn, |
2322 | unsigned NumReservedClauses, | |
2323 | const Twine &NameStr, BasicBlock *InsertAtEnd); | |
2324 | ~LandingPadInst(); | |
2325 | ||
2326 | /// Provide fast operand accessors | |
2327 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
2328 | ||
2329 | /// getPersonalityFn - Get the personality function associated with this | |
2330 | /// landing pad. | |
2331 | Value *getPersonalityFn() const { return getOperand(0); } | |
2332 | ||
2333 | /// isCleanup - Return 'true' if this landingpad instruction is a | |
2334 | /// cleanup. I.e., it should be run when unwinding even if its landing pad | |
2335 | /// doesn't catch the exception. | |
2336 | bool isCleanup() const { return getSubclassDataFromInstruction() & 1; } | |
2337 | ||
2338 | /// setCleanup - Indicate that this landingpad instruction is a cleanup. | |
2339 | void setCleanup(bool V) { | |
2340 | setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) | | |
2341 | (V ? 1 : 0)); | |
2342 | } | |
2343 | ||
1a4d82fc JJ |
2344 | /// Add a catch or filter clause to the landing pad. |
2345 | void addClause(Constant *ClauseVal); | |
223e47cc | 2346 | |
1a4d82fc JJ |
2347 | /// Get the value of the clause at index Idx. Use isCatch/isFilter to |
2348 | /// determine what type of clause this is. | |
2349 | Constant *getClause(unsigned Idx) const { | |
2350 | return cast<Constant>(OperandList[Idx + 1]); | |
2351 | } | |
223e47cc LB |
2352 | |
2353 | /// isCatch - Return 'true' if the clause and index Idx is a catch clause. | |
2354 | bool isCatch(unsigned Idx) const { | |
2355 | return !isa<ArrayType>(OperandList[Idx + 1]->getType()); | |
2356 | } | |
2357 | ||
2358 | /// isFilter - Return 'true' if the clause and index Idx is a filter clause. | |
2359 | bool isFilter(unsigned Idx) const { | |
2360 | return isa<ArrayType>(OperandList[Idx + 1]->getType()); | |
2361 | } | |
2362 | ||
2363 | /// getNumClauses - Get the number of clauses for this landing pad. | |
2364 | unsigned getNumClauses() const { return getNumOperands() - 1; } | |
2365 | ||
2366 | /// reserveClauses - Grow the size of the operand list to accommodate the new | |
2367 | /// number of clauses. | |
2368 | void reserveClauses(unsigned Size) { growOperands(Size); } | |
2369 | ||
2370 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
2371 | static inline bool classof(const Instruction *I) { |
2372 | return I->getOpcode() == Instruction::LandingPad; | |
2373 | } | |
2374 | static inline bool classof(const Value *V) { | |
2375 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
2376 | } | |
2377 | }; | |
2378 | ||
2379 | template <> | |
2380 | struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> { | |
2381 | }; | |
2382 | ||
2383 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value) | |
2384 | ||
2385 | //===----------------------------------------------------------------------===// | |
2386 | // ReturnInst Class | |
2387 | //===----------------------------------------------------------------------===// | |
2388 | ||
2389 | //===--------------------------------------------------------------------------- | |
2390 | /// ReturnInst - Return a value (possibly void), from a function. Execution | |
2391 | /// does not continue in this function any longer. | |
2392 | /// | |
2393 | class ReturnInst : public TerminatorInst { | |
2394 | ReturnInst(const ReturnInst &RI); | |
2395 | ||
2396 | private: | |
2397 | // ReturnInst constructors: | |
2398 | // ReturnInst() - 'ret void' instruction | |
2399 | // ReturnInst( null) - 'ret void' instruction | |
2400 | // ReturnInst(Value* X) - 'ret X' instruction | |
2401 | // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I | |
2402 | // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I | |
2403 | // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B | |
2404 | // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B | |
2405 | // | |
2406 | // NOTE: If the Value* passed is of type void then the constructor behaves as | |
2407 | // if it was passed NULL. | |
1a4d82fc JJ |
2408 | explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr, |
2409 | Instruction *InsertBefore = nullptr); | |
223e47cc LB |
2410 | ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd); |
2411 | explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd); | |
2412 | protected: | |
1a4d82fc | 2413 | ReturnInst *clone_impl() const override; |
223e47cc | 2414 | public: |
1a4d82fc JJ |
2415 | static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr, |
2416 | Instruction *InsertBefore = nullptr) { | |
223e47cc LB |
2417 | return new(!!retVal) ReturnInst(C, retVal, InsertBefore); |
2418 | } | |
2419 | static ReturnInst* Create(LLVMContext &C, Value *retVal, | |
2420 | BasicBlock *InsertAtEnd) { | |
2421 | return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd); | |
2422 | } | |
2423 | static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) { | |
2424 | return new(0) ReturnInst(C, InsertAtEnd); | |
2425 | } | |
2426 | virtual ~ReturnInst(); | |
2427 | ||
2428 | /// Provide fast operand accessors | |
2429 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
2430 | ||
2431 | /// Convenience accessor. Returns null if there is no return value. | |
2432 | Value *getReturnValue() const { | |
1a4d82fc | 2433 | return getNumOperands() != 0 ? getOperand(0) : nullptr; |
223e47cc LB |
2434 | } |
2435 | ||
2436 | unsigned getNumSuccessors() const { return 0; } | |
2437 | ||
2438 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
2439 | static inline bool classof(const Instruction *I) { |
2440 | return (I->getOpcode() == Instruction::Ret); | |
2441 | } | |
2442 | static inline bool classof(const Value *V) { | |
2443 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
2444 | } | |
2445 | private: | |
1a4d82fc JJ |
2446 | BasicBlock *getSuccessorV(unsigned idx) const override; |
2447 | unsigned getNumSuccessorsV() const override; | |
2448 | void setSuccessorV(unsigned idx, BasicBlock *B) override; | |
223e47cc LB |
2449 | }; |
2450 | ||
2451 | template <> | |
2452 | struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> { | |
2453 | }; | |
2454 | ||
2455 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value) | |
2456 | ||
2457 | //===----------------------------------------------------------------------===// | |
2458 | // BranchInst Class | |
2459 | //===----------------------------------------------------------------------===// | |
2460 | ||
2461 | //===--------------------------------------------------------------------------- | |
2462 | /// BranchInst - Conditional or Unconditional Branch instruction. | |
2463 | /// | |
2464 | class BranchInst : public TerminatorInst { | |
2465 | /// Ops list - Branches are strange. The operands are ordered: | |
2466 | /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because | |
2467 | /// they don't have to check for cond/uncond branchness. These are mostly | |
2468 | /// accessed relative from op_end(). | |
2469 | BranchInst(const BranchInst &BI); | |
2470 | void AssertOK(); | |
2471 | // BranchInst constructors (where {B, T, F} are blocks, and C is a condition): | |
2472 | // BranchInst(BB *B) - 'br B' | |
2473 | // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F' | |
2474 | // BranchInst(BB* B, Inst *I) - 'br B' insert before I | |
2475 | // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I | |
2476 | // BranchInst(BB* B, BB *I) - 'br B' insert at end | |
2477 | // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end | |
1a4d82fc | 2478 | explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr); |
223e47cc | 2479 | BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, |
1a4d82fc | 2480 | Instruction *InsertBefore = nullptr); |
223e47cc LB |
2481 | BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd); |
2482 | BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, | |
2483 | BasicBlock *InsertAtEnd); | |
2484 | protected: | |
1a4d82fc | 2485 | BranchInst *clone_impl() const override; |
223e47cc | 2486 | public: |
1a4d82fc JJ |
2487 | static BranchInst *Create(BasicBlock *IfTrue, |
2488 | Instruction *InsertBefore = nullptr) { | |
223e47cc LB |
2489 | return new(1) BranchInst(IfTrue, InsertBefore); |
2490 | } | |
2491 | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, | |
1a4d82fc | 2492 | Value *Cond, Instruction *InsertBefore = nullptr) { |
223e47cc LB |
2493 | return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore); |
2494 | } | |
2495 | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) { | |
2496 | return new(1) BranchInst(IfTrue, InsertAtEnd); | |
2497 | } | |
2498 | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, | |
2499 | Value *Cond, BasicBlock *InsertAtEnd) { | |
2500 | return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd); | |
2501 | } | |
2502 | ||
2503 | /// Transparently provide more efficient getOperand methods. | |
2504 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
2505 | ||
2506 | bool isUnconditional() const { return getNumOperands() == 1; } | |
2507 | bool isConditional() const { return getNumOperands() == 3; } | |
2508 | ||
2509 | Value *getCondition() const { | |
2510 | assert(isConditional() && "Cannot get condition of an uncond branch!"); | |
2511 | return Op<-3>(); | |
2512 | } | |
2513 | ||
2514 | void setCondition(Value *V) { | |
2515 | assert(isConditional() && "Cannot set condition of unconditional branch!"); | |
2516 | Op<-3>() = V; | |
2517 | } | |
2518 | ||
2519 | unsigned getNumSuccessors() const { return 1+isConditional(); } | |
2520 | ||
2521 | BasicBlock *getSuccessor(unsigned i) const { | |
2522 | assert(i < getNumSuccessors() && "Successor # out of range for Branch!"); | |
2523 | return cast_or_null<BasicBlock>((&Op<-1>() - i)->get()); | |
2524 | } | |
2525 | ||
2526 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { | |
2527 | assert(idx < getNumSuccessors() && "Successor # out of range for Branch!"); | |
2528 | *(&Op<-1>() - idx) = (Value*)NewSucc; | |
2529 | } | |
2530 | ||
2531 | /// \brief Swap the successors of this branch instruction. | |
2532 | /// | |
2533 | /// Swaps the successors of the branch instruction. This also swaps any | |
2534 | /// branch weight metadata associated with the instruction so that it | |
2535 | /// continues to map correctly to each operand. | |
2536 | void swapSuccessors(); | |
2537 | ||
2538 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
2539 | static inline bool classof(const Instruction *I) { |
2540 | return (I->getOpcode() == Instruction::Br); | |
2541 | } | |
2542 | static inline bool classof(const Value *V) { | |
2543 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
2544 | } | |
2545 | private: | |
1a4d82fc JJ |
2546 | BasicBlock *getSuccessorV(unsigned idx) const override; |
2547 | unsigned getNumSuccessorsV() const override; | |
2548 | void setSuccessorV(unsigned idx, BasicBlock *B) override; | |
223e47cc LB |
2549 | }; |
2550 | ||
2551 | template <> | |
2552 | struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> { | |
2553 | }; | |
2554 | ||
2555 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value) | |
2556 | ||
2557 | //===----------------------------------------------------------------------===// | |
2558 | // SwitchInst Class | |
2559 | //===----------------------------------------------------------------------===// | |
2560 | ||
2561 | //===--------------------------------------------------------------------------- | |
2562 | /// SwitchInst - Multiway switch | |
2563 | /// | |
2564 | class SwitchInst : public TerminatorInst { | |
2565 | void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; | |
2566 | unsigned ReservedSpace; | |
223e47cc LB |
2567 | // Operand[0] = Value to switch on |
2568 | // Operand[1] = Default basic block destination | |
2569 | // Operand[2n ] = Value to match | |
2570 | // Operand[2n+1] = BasicBlock to go to on match | |
223e47cc LB |
2571 | SwitchInst(const SwitchInst &SI); |
2572 | void init(Value *Value, BasicBlock *Default, unsigned NumReserved); | |
2573 | void growOperands(); | |
2574 | // allocate space for exactly zero operands | |
2575 | void *operator new(size_t s) { | |
2576 | return User::operator new(s, 0); | |
2577 | } | |
2578 | /// SwitchInst ctor - Create a new switch instruction, specifying a value to | |
2579 | /// switch on and a default destination. The number of additional cases can | |
2580 | /// be specified here to make memory allocation more efficient. This | |
2581 | /// constructor can also autoinsert before another instruction. | |
2582 | SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, | |
2583 | Instruction *InsertBefore); | |
2584 | ||
2585 | /// SwitchInst ctor - Create a new switch instruction, specifying a value to | |
2586 | /// switch on and a default destination. The number of additional cases can | |
2587 | /// be specified here to make memory allocation more efficient. This | |
2588 | /// constructor also autoinserts at the end of the specified BasicBlock. | |
2589 | SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, | |
2590 | BasicBlock *InsertAtEnd); | |
2591 | protected: | |
1a4d82fc | 2592 | SwitchInst *clone_impl() const override; |
223e47cc | 2593 | public: |
970d7e83 | 2594 | |
223e47cc LB |
2595 | // -2 |
2596 | static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1); | |
970d7e83 | 2597 | |
1a4d82fc JJ |
2598 | template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy> |
2599 | class CaseIteratorT { | |
2600 | protected: | |
2601 | ||
2602 | SwitchInstTy *SI; | |
2603 | unsigned Index; | |
2604 | ||
2605 | public: | |
2606 | ||
2607 | typedef CaseIteratorT<SwitchInstTy, ConstantIntTy, BasicBlockTy> Self; | |
2608 | ||
2609 | /// Initializes case iterator for given SwitchInst and for given | |
2610 | /// case number. | |
2611 | CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) { | |
2612 | this->SI = SI; | |
2613 | Index = CaseNum; | |
2614 | } | |
2615 | ||
2616 | /// Initializes case iterator for given SwitchInst and for given | |
2617 | /// TerminatorInst's successor index. | |
2618 | static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) { | |
2619 | assert(SuccessorIndex < SI->getNumSuccessors() && | |
2620 | "Successor index # out of range!"); | |
2621 | return SuccessorIndex != 0 ? | |
2622 | Self(SI, SuccessorIndex - 1) : | |
2623 | Self(SI, DefaultPseudoIndex); | |
2624 | } | |
2625 | ||
2626 | /// Resolves case value for current case. | |
2627 | ConstantIntTy *getCaseValue() { | |
2628 | assert(Index < SI->getNumCases() && "Index out the number of cases."); | |
2629 | return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2)); | |
2630 | } | |
2631 | ||
2632 | /// Resolves successor for current case. | |
2633 | BasicBlockTy *getCaseSuccessor() { | |
2634 | assert((Index < SI->getNumCases() || | |
2635 | Index == DefaultPseudoIndex) && | |
2636 | "Index out the number of cases."); | |
2637 | return SI->getSuccessor(getSuccessorIndex()); | |
2638 | } | |
2639 | ||
2640 | /// Returns number of current case. | |
2641 | unsigned getCaseIndex() const { return Index; } | |
2642 | ||
2643 | /// Returns TerminatorInst's successor index for current case successor. | |
2644 | unsigned getSuccessorIndex() const { | |
2645 | assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) && | |
2646 | "Index out the number of cases."); | |
2647 | return Index != DefaultPseudoIndex ? Index + 1 : 0; | |
2648 | } | |
2649 | ||
2650 | Self operator++() { | |
2651 | // Check index correctness after increment. | |
2652 | // Note: Index == getNumCases() means end(). | |
2653 | assert(Index+1 <= SI->getNumCases() && "Index out the number of cases."); | |
2654 | ++Index; | |
2655 | return *this; | |
2656 | } | |
2657 | Self operator++(int) { | |
2658 | Self tmp = *this; | |
2659 | ++(*this); | |
2660 | return tmp; | |
2661 | } | |
2662 | Self operator--() { | |
2663 | // Check index correctness after decrement. | |
2664 | // Note: Index == getNumCases() means end(). | |
2665 | // Also allow "-1" iterator here. That will became valid after ++. | |
2666 | assert((Index == 0 || Index-1 <= SI->getNumCases()) && | |
2667 | "Index out the number of cases."); | |
2668 | --Index; | |
2669 | return *this; | |
2670 | } | |
2671 | Self operator--(int) { | |
2672 | Self tmp = *this; | |
2673 | --(*this); | |
2674 | return tmp; | |
2675 | } | |
2676 | bool operator==(const Self& RHS) const { | |
2677 | assert(RHS.SI == SI && "Incompatible operators."); | |
2678 | return RHS.Index == Index; | |
2679 | } | |
2680 | bool operator!=(const Self& RHS) const { | |
2681 | assert(RHS.SI == SI && "Incompatible operators."); | |
2682 | return RHS.Index != Index; | |
2683 | } | |
2684 | Self &operator*() { | |
2685 | return *this; | |
2686 | } | |
2687 | }; | |
2688 | ||
2689 | typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock> | |
2690 | ConstCaseIt; | |
2691 | ||
2692 | class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> { | |
2693 | ||
2694 | typedef CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> ParentTy; | |
2695 | ||
2696 | public: | |
2697 | ||
2698 | CaseIt(const ParentTy& Src) : ParentTy(Src) {} | |
2699 | CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {} | |
2700 | ||
2701 | /// Sets the new value for current case. | |
2702 | void setValue(ConstantInt *V) { | |
2703 | assert(Index < SI->getNumCases() && "Index out the number of cases."); | |
2704 | SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V)); | |
2705 | } | |
2706 | ||
2707 | /// Sets the new successor for current case. | |
2708 | void setSuccessor(BasicBlock *S) { | |
2709 | SI->setSuccessor(getSuccessorIndex(), S); | |
2710 | } | |
2711 | }; | |
2712 | ||
223e47cc | 2713 | static SwitchInst *Create(Value *Value, BasicBlock *Default, |
1a4d82fc JJ |
2714 | unsigned NumCases, |
2715 | Instruction *InsertBefore = nullptr) { | |
223e47cc LB |
2716 | return new SwitchInst(Value, Default, NumCases, InsertBefore); |
2717 | } | |
2718 | static SwitchInst *Create(Value *Value, BasicBlock *Default, | |
2719 | unsigned NumCases, BasicBlock *InsertAtEnd) { | |
2720 | return new SwitchInst(Value, Default, NumCases, InsertAtEnd); | |
2721 | } | |
970d7e83 | 2722 | |
223e47cc LB |
2723 | ~SwitchInst(); |
2724 | ||
2725 | /// Provide fast operand accessors | |
2726 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
2727 | ||
2728 | // Accessor Methods for Switch stmt | |
2729 | Value *getCondition() const { return getOperand(0); } | |
2730 | void setCondition(Value *V) { setOperand(0, V); } | |
2731 | ||
2732 | BasicBlock *getDefaultDest() const { | |
2733 | return cast<BasicBlock>(getOperand(1)); | |
2734 | } | |
2735 | ||
2736 | void setDefaultDest(BasicBlock *DefaultCase) { | |
2737 | setOperand(1, reinterpret_cast<Value*>(DefaultCase)); | |
2738 | } | |
2739 | ||
2740 | /// getNumCases - return the number of 'cases' in this switch instruction, | |
2741 | /// except the default case | |
2742 | unsigned getNumCases() const { | |
2743 | return getNumOperands()/2 - 1; | |
2744 | } | |
2745 | ||
2746 | /// Returns a read/write iterator that points to the first | |
2747 | /// case in SwitchInst. | |
2748 | CaseIt case_begin() { | |
1a4d82fc | 2749 | return CaseIt(this, 0); |
223e47cc LB |
2750 | } |
2751 | /// Returns a read-only iterator that points to the first | |
2752 | /// case in the SwitchInst. | |
2753 | ConstCaseIt case_begin() const { | |
1a4d82fc | 2754 | return ConstCaseIt(this, 0); |
223e47cc | 2755 | } |
970d7e83 | 2756 | |
223e47cc LB |
2757 | /// Returns a read/write iterator that points one past the last |
2758 | /// in the SwitchInst. | |
2759 | CaseIt case_end() { | |
1a4d82fc | 2760 | return CaseIt(this, getNumCases()); |
223e47cc LB |
2761 | } |
2762 | /// Returns a read-only iterator that points one past the last | |
2763 | /// in the SwitchInst. | |
2764 | ConstCaseIt case_end() const { | |
1a4d82fc | 2765 | return ConstCaseIt(this, getNumCases()); |
223e47cc | 2766 | } |
1a4d82fc JJ |
2767 | |
2768 | /// cases - iteration adapter for range-for loops. | |
2769 | iterator_range<CaseIt> cases() { | |
2770 | return iterator_range<CaseIt>(case_begin(), case_end()); | |
2771 | } | |
2772 | ||
2773 | /// cases - iteration adapter for range-for loops. | |
2774 | iterator_range<ConstCaseIt> cases() const { | |
2775 | return iterator_range<ConstCaseIt>(case_begin(), case_end()); | |
2776 | } | |
2777 | ||
223e47cc LB |
2778 | /// Returns an iterator that points to the default case. |
2779 | /// Note: this iterator allows to resolve successor only. Attempt | |
2780 | /// to resolve case value causes an assertion. | |
2781 | /// Also note, that increment and decrement also causes an assertion and | |
970d7e83 | 2782 | /// makes iterator invalid. |
223e47cc | 2783 | CaseIt case_default() { |
1a4d82fc | 2784 | return CaseIt(this, DefaultPseudoIndex); |
223e47cc LB |
2785 | } |
2786 | ConstCaseIt case_default() const { | |
1a4d82fc | 2787 | return ConstCaseIt(this, DefaultPseudoIndex); |
223e47cc | 2788 | } |
970d7e83 | 2789 | |
223e47cc LB |
2790 | /// findCaseValue - Search all of the case values for the specified constant. |
2791 | /// If it is explicitly handled, return the case iterator of it, otherwise | |
2792 | /// return default case iterator to indicate | |
2793 | /// that it is handled by the default handler. | |
2794 | CaseIt findCaseValue(const ConstantInt *C) { | |
2795 | for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) | |
1a4d82fc | 2796 | if (i.getCaseValue() == C) |
223e47cc LB |
2797 | return i; |
2798 | return case_default(); | |
2799 | } | |
2800 | ConstCaseIt findCaseValue(const ConstantInt *C) const { | |
2801 | for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i) | |
1a4d82fc | 2802 | if (i.getCaseValue() == C) |
223e47cc LB |
2803 | return i; |
2804 | return case_default(); | |
970d7e83 LB |
2805 | } |
2806 | ||
223e47cc LB |
2807 | /// findCaseDest - Finds the unique case value for a given successor. Returns |
2808 | /// null if the successor is not found, not unique, or is the default case. | |
2809 | ConstantInt *findCaseDest(BasicBlock *BB) { | |
1a4d82fc | 2810 | if (BB == getDefaultDest()) return nullptr; |
223e47cc | 2811 | |
1a4d82fc | 2812 | ConstantInt *CI = nullptr; |
223e47cc LB |
2813 | for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) { |
2814 | if (i.getCaseSuccessor() == BB) { | |
1a4d82fc | 2815 | if (CI) return nullptr; // Multiple cases lead to BB. |
223e47cc LB |
2816 | else CI = i.getCaseValue(); |
2817 | } | |
2818 | } | |
2819 | return CI; | |
2820 | } | |
2821 | ||
2822 | /// addCase - Add an entry to the switch instruction... | |
223e47cc LB |
2823 | /// Note: |
2824 | /// This action invalidates case_end(). Old case_end() iterator will | |
2825 | /// point to the added case. | |
2826 | void addCase(ConstantInt *OnVal, BasicBlock *Dest); | |
970d7e83 | 2827 | |
223e47cc LB |
2828 | /// removeCase - This method removes the specified case and its successor |
2829 | /// from the switch instruction. Note that this operation may reorder the | |
2830 | /// remaining cases at index idx and above. | |
2831 | /// Note: | |
2832 | /// This action invalidates iterators for all cases following the one removed, | |
2833 | /// including the case_end() iterator. | |
1a4d82fc | 2834 | void removeCase(CaseIt i); |
223e47cc LB |
2835 | |
2836 | unsigned getNumSuccessors() const { return getNumOperands()/2; } | |
2837 | BasicBlock *getSuccessor(unsigned idx) const { | |
2838 | assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!"); | |
2839 | return cast<BasicBlock>(getOperand(idx*2+1)); | |
2840 | } | |
2841 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { | |
2842 | assert(idx < getNumSuccessors() && "Successor # out of range for switch!"); | |
2843 | setOperand(idx*2+1, (Value*)NewSucc); | |
2844 | } | |
970d7e83 | 2845 | |
223e47cc | 2846 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
2847 | static inline bool classof(const Instruction *I) { |
2848 | return I->getOpcode() == Instruction::Switch; | |
2849 | } | |
2850 | static inline bool classof(const Value *V) { | |
2851 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
2852 | } | |
2853 | private: | |
1a4d82fc JJ |
2854 | BasicBlock *getSuccessorV(unsigned idx) const override; |
2855 | unsigned getNumSuccessorsV() const override; | |
2856 | void setSuccessorV(unsigned idx, BasicBlock *B) override; | |
223e47cc LB |
2857 | }; |
2858 | ||
2859 | template <> | |
2860 | struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> { | |
2861 | }; | |
2862 | ||
2863 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value) | |
2864 | ||
2865 | ||
2866 | //===----------------------------------------------------------------------===// | |
2867 | // IndirectBrInst Class | |
2868 | //===----------------------------------------------------------------------===// | |
2869 | ||
2870 | //===--------------------------------------------------------------------------- | |
2871 | /// IndirectBrInst - Indirect Branch Instruction. | |
2872 | /// | |
2873 | class IndirectBrInst : public TerminatorInst { | |
2874 | void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; | |
2875 | unsigned ReservedSpace; | |
2876 | // Operand[0] = Value to switch on | |
2877 | // Operand[1] = Default basic block destination | |
2878 | // Operand[2n ] = Value to match | |
2879 | // Operand[2n+1] = BasicBlock to go to on match | |
2880 | IndirectBrInst(const IndirectBrInst &IBI); | |
2881 | void init(Value *Address, unsigned NumDests); | |
2882 | void growOperands(); | |
2883 | // allocate space for exactly zero operands | |
2884 | void *operator new(size_t s) { | |
2885 | return User::operator new(s, 0); | |
2886 | } | |
2887 | /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an | |
2888 | /// Address to jump to. The number of expected destinations can be specified | |
2889 | /// here to make memory allocation more efficient. This constructor can also | |
2890 | /// autoinsert before another instruction. | |
2891 | IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore); | |
2892 | ||
2893 | /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an | |
2894 | /// Address to jump to. The number of expected destinations can be specified | |
2895 | /// here to make memory allocation more efficient. This constructor also | |
2896 | /// autoinserts at the end of the specified BasicBlock. | |
2897 | IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd); | |
2898 | protected: | |
1a4d82fc | 2899 | IndirectBrInst *clone_impl() const override; |
223e47cc LB |
2900 | public: |
2901 | static IndirectBrInst *Create(Value *Address, unsigned NumDests, | |
1a4d82fc | 2902 | Instruction *InsertBefore = nullptr) { |
223e47cc LB |
2903 | return new IndirectBrInst(Address, NumDests, InsertBefore); |
2904 | } | |
2905 | static IndirectBrInst *Create(Value *Address, unsigned NumDests, | |
2906 | BasicBlock *InsertAtEnd) { | |
2907 | return new IndirectBrInst(Address, NumDests, InsertAtEnd); | |
2908 | } | |
2909 | ~IndirectBrInst(); | |
2910 | ||
2911 | /// Provide fast operand accessors. | |
2912 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
2913 | ||
2914 | // Accessor Methods for IndirectBrInst instruction. | |
2915 | Value *getAddress() { return getOperand(0); } | |
2916 | const Value *getAddress() const { return getOperand(0); } | |
2917 | void setAddress(Value *V) { setOperand(0, V); } | |
2918 | ||
2919 | ||
2920 | /// getNumDestinations - return the number of possible destinations in this | |
2921 | /// indirectbr instruction. | |
2922 | unsigned getNumDestinations() const { return getNumOperands()-1; } | |
2923 | ||
2924 | /// getDestination - Return the specified destination. | |
2925 | BasicBlock *getDestination(unsigned i) { return getSuccessor(i); } | |
2926 | const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); } | |
2927 | ||
2928 | /// addDestination - Add a destination. | |
2929 | /// | |
2930 | void addDestination(BasicBlock *Dest); | |
2931 | ||
2932 | /// removeDestination - This method removes the specified successor from the | |
2933 | /// indirectbr instruction. | |
2934 | void removeDestination(unsigned i); | |
2935 | ||
2936 | unsigned getNumSuccessors() const { return getNumOperands()-1; } | |
2937 | BasicBlock *getSuccessor(unsigned i) const { | |
2938 | return cast<BasicBlock>(getOperand(i+1)); | |
2939 | } | |
2940 | void setSuccessor(unsigned i, BasicBlock *NewSucc) { | |
2941 | setOperand(i+1, (Value*)NewSucc); | |
2942 | } | |
2943 | ||
2944 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
2945 | static inline bool classof(const Instruction *I) { |
2946 | return I->getOpcode() == Instruction::IndirectBr; | |
2947 | } | |
2948 | static inline bool classof(const Value *V) { | |
2949 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
2950 | } | |
2951 | private: | |
1a4d82fc JJ |
2952 | BasicBlock *getSuccessorV(unsigned idx) const override; |
2953 | unsigned getNumSuccessorsV() const override; | |
2954 | void setSuccessorV(unsigned idx, BasicBlock *B) override; | |
223e47cc LB |
2955 | }; |
2956 | ||
2957 | template <> | |
2958 | struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> { | |
2959 | }; | |
2960 | ||
2961 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value) | |
2962 | ||
2963 | ||
2964 | //===----------------------------------------------------------------------===// | |
2965 | // InvokeInst Class | |
2966 | //===----------------------------------------------------------------------===// | |
2967 | ||
2968 | /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the | |
2969 | /// calling convention of the call. | |
2970 | /// | |
2971 | class InvokeInst : public TerminatorInst { | |
970d7e83 | 2972 | AttributeSet AttributeList; |
223e47cc LB |
2973 | InvokeInst(const InvokeInst &BI); |
2974 | void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, | |
2975 | ArrayRef<Value *> Args, const Twine &NameStr); | |
2976 | ||
2977 | /// Construct an InvokeInst given a range of arguments. | |
2978 | /// | |
970d7e83 | 2979 | /// \brief Construct an InvokeInst from a range of arguments |
223e47cc LB |
2980 | inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
2981 | ArrayRef<Value *> Args, unsigned Values, | |
2982 | const Twine &NameStr, Instruction *InsertBefore); | |
2983 | ||
2984 | /// Construct an InvokeInst given a range of arguments. | |
2985 | /// | |
970d7e83 | 2986 | /// \brief Construct an InvokeInst from a range of arguments |
223e47cc LB |
2987 | inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
2988 | ArrayRef<Value *> Args, unsigned Values, | |
2989 | const Twine &NameStr, BasicBlock *InsertAtEnd); | |
2990 | protected: | |
1a4d82fc | 2991 | InvokeInst *clone_impl() const override; |
223e47cc LB |
2992 | public: |
2993 | static InvokeInst *Create(Value *Func, | |
2994 | BasicBlock *IfNormal, BasicBlock *IfException, | |
2995 | ArrayRef<Value *> Args, const Twine &NameStr = "", | |
1a4d82fc | 2996 | Instruction *InsertBefore = nullptr) { |
223e47cc LB |
2997 | unsigned Values = unsigned(Args.size()) + 3; |
2998 | return new(Values) InvokeInst(Func, IfNormal, IfException, Args, | |
2999 | Values, NameStr, InsertBefore); | |
3000 | } | |
3001 | static InvokeInst *Create(Value *Func, | |
3002 | BasicBlock *IfNormal, BasicBlock *IfException, | |
3003 | ArrayRef<Value *> Args, const Twine &NameStr, | |
3004 | BasicBlock *InsertAtEnd) { | |
3005 | unsigned Values = unsigned(Args.size()) + 3; | |
3006 | return new(Values) InvokeInst(Func, IfNormal, IfException, Args, | |
3007 | Values, NameStr, InsertAtEnd); | |
3008 | } | |
3009 | ||
3010 | /// Provide fast operand accessors | |
3011 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
3012 | ||
3013 | /// getNumArgOperands - Return the number of invoke arguments. | |
3014 | /// | |
3015 | unsigned getNumArgOperands() const { return getNumOperands() - 3; } | |
3016 | ||
3017 | /// getArgOperand/setArgOperand - Return/set the i-th invoke argument. | |
3018 | /// | |
3019 | Value *getArgOperand(unsigned i) const { return getOperand(i); } | |
3020 | void setArgOperand(unsigned i, Value *v) { setOperand(i, v); } | |
3021 | ||
1a4d82fc JJ |
3022 | /// arg_operands - iteration adapter for range-for loops. |
3023 | iterator_range<op_iterator> arg_operands() { | |
3024 | return iterator_range<op_iterator>(op_begin(), op_end() - 3); | |
3025 | } | |
3026 | ||
3027 | /// arg_operands - iteration adapter for range-for loops. | |
3028 | iterator_range<const_op_iterator> arg_operands() const { | |
3029 | return iterator_range<const_op_iterator>(op_begin(), op_end() - 3); | |
3030 | } | |
3031 | ||
3032 | /// \brief Wrappers for getting the \c Use of a invoke argument. | |
3033 | const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); } | |
3034 | Use &getArgOperandUse(unsigned i) { return getOperandUse(i); } | |
3035 | ||
223e47cc LB |
3036 | /// getCallingConv/setCallingConv - Get or set the calling convention of this |
3037 | /// function call. | |
3038 | CallingConv::ID getCallingConv() const { | |
3039 | return static_cast<CallingConv::ID>(getSubclassDataFromInstruction()); | |
3040 | } | |
3041 | void setCallingConv(CallingConv::ID CC) { | |
3042 | setInstructionSubclassData(static_cast<unsigned>(CC)); | |
3043 | } | |
3044 | ||
3045 | /// getAttributes - Return the parameter attributes for this invoke. | |
3046 | /// | |
970d7e83 | 3047 | const AttributeSet &getAttributes() const { return AttributeList; } |
223e47cc LB |
3048 | |
3049 | /// setAttributes - Set the parameter attributes for this invoke. | |
3050 | /// | |
970d7e83 | 3051 | void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; } |
223e47cc LB |
3052 | |
3053 | /// addAttribute - adds the attribute to the list of attributes. | |
970d7e83 | 3054 | void addAttribute(unsigned i, Attribute::AttrKind attr); |
223e47cc LB |
3055 | |
3056 | /// removeAttribute - removes the attribute from the list of attributes. | |
970d7e83 | 3057 | void removeAttribute(unsigned i, Attribute attr); |
223e47cc | 3058 | |
1a4d82fc JJ |
3059 | /// \brief Determine whether this call has the given attribute. |
3060 | bool hasFnAttr(Attribute::AttrKind A) const { | |
3061 | assert(A != Attribute::NoBuiltin && | |
3062 | "Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin"); | |
3063 | return hasFnAttrImpl(A); | |
3064 | } | |
223e47cc | 3065 | |
970d7e83 LB |
3066 | /// \brief Determine whether the call or the callee has the given attributes. |
3067 | bool paramHasAttr(unsigned i, Attribute::AttrKind A) const; | |
223e47cc | 3068 | |
970d7e83 | 3069 | /// \brief Extract the alignment for a call or parameter (0=unknown). |
223e47cc LB |
3070 | unsigned getParamAlignment(unsigned i) const { |
3071 | return AttributeList.getParamAlignment(i); | |
3072 | } | |
3073 | ||
1a4d82fc JJ |
3074 | /// \brief Extract the number of dereferenceable bytes for a call or |
3075 | /// parameter (0=unknown). | |
3076 | uint64_t getDereferenceableBytes(unsigned i) const { | |
3077 | return AttributeList.getDereferenceableBytes(i); | |
3078 | } | |
3079 | ||
3080 | /// \brief Return true if the call should not be treated as a call to a | |
3081 | /// builtin. | |
3082 | bool isNoBuiltin() const { | |
3083 | // We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have | |
3084 | // to check it by hand. | |
3085 | return hasFnAttrImpl(Attribute::NoBuiltin) && | |
3086 | !hasFnAttrImpl(Attribute::Builtin); | |
3087 | } | |
3088 | ||
970d7e83 | 3089 | /// \brief Return true if the call should not be inlined. |
223e47cc | 3090 | bool isNoInline() const { return hasFnAttr(Attribute::NoInline); } |
970d7e83 LB |
3091 | void setIsNoInline() { |
3092 | addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline); | |
223e47cc LB |
3093 | } |
3094 | ||
970d7e83 | 3095 | /// \brief Determine if the call does not access memory. |
223e47cc LB |
3096 | bool doesNotAccessMemory() const { |
3097 | return hasFnAttr(Attribute::ReadNone); | |
3098 | } | |
970d7e83 LB |
3099 | void setDoesNotAccessMemory() { |
3100 | addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone); | |
223e47cc LB |
3101 | } |
3102 | ||
970d7e83 | 3103 | /// \brief Determine if the call does not access or only reads memory. |
223e47cc LB |
3104 | bool onlyReadsMemory() const { |
3105 | return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly); | |
3106 | } | |
970d7e83 LB |
3107 | void setOnlyReadsMemory() { |
3108 | addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly); | |
223e47cc LB |
3109 | } |
3110 | ||
970d7e83 | 3111 | /// \brief Determine if the call cannot return. |
223e47cc | 3112 | bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); } |
970d7e83 LB |
3113 | void setDoesNotReturn() { |
3114 | addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn); | |
223e47cc LB |
3115 | } |
3116 | ||
970d7e83 | 3117 | /// \brief Determine if the call cannot unwind. |
223e47cc | 3118 | bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); } |
970d7e83 LB |
3119 | void setDoesNotThrow() { |
3120 | addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind); | |
223e47cc LB |
3121 | } |
3122 | ||
1a4d82fc JJ |
3123 | /// \brief Determine if the invoke cannot be duplicated. |
3124 | bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); } | |
3125 | void setCannotDuplicate() { | |
3126 | addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate); | |
3127 | } | |
3128 | ||
970d7e83 | 3129 | /// \brief Determine if the call returns a structure through first |
223e47cc LB |
3130 | /// pointer argument. |
3131 | bool hasStructRetAttr() const { | |
3132 | // Be friendly and also check the callee. | |
3133 | return paramHasAttr(1, Attribute::StructRet); | |
3134 | } | |
3135 | ||
970d7e83 | 3136 | /// \brief Determine if any call argument is an aggregate passed by value. |
223e47cc LB |
3137 | bool hasByValArgument() const { |
3138 | return AttributeList.hasAttrSomewhere(Attribute::ByVal); | |
3139 | } | |
3140 | ||
3141 | /// getCalledFunction - Return the function called, or null if this is an | |
3142 | /// indirect function invocation. | |
3143 | /// | |
3144 | Function *getCalledFunction() const { | |
3145 | return dyn_cast<Function>(Op<-3>()); | |
3146 | } | |
3147 | ||
3148 | /// getCalledValue - Get a pointer to the function that is invoked by this | |
3149 | /// instruction | |
3150 | const Value *getCalledValue() const { return Op<-3>(); } | |
3151 | Value *getCalledValue() { return Op<-3>(); } | |
3152 | ||
3153 | /// setCalledFunction - Set the function called. | |
3154 | void setCalledFunction(Value* Fn) { | |
3155 | Op<-3>() = Fn; | |
3156 | } | |
3157 | ||
3158 | // get*Dest - Return the destination basic blocks... | |
3159 | BasicBlock *getNormalDest() const { | |
3160 | return cast<BasicBlock>(Op<-2>()); | |
3161 | } | |
3162 | BasicBlock *getUnwindDest() const { | |
3163 | return cast<BasicBlock>(Op<-1>()); | |
3164 | } | |
3165 | void setNormalDest(BasicBlock *B) { | |
3166 | Op<-2>() = reinterpret_cast<Value*>(B); | |
3167 | } | |
3168 | void setUnwindDest(BasicBlock *B) { | |
3169 | Op<-1>() = reinterpret_cast<Value*>(B); | |
3170 | } | |
3171 | ||
3172 | /// getLandingPadInst - Get the landingpad instruction from the landing pad | |
3173 | /// block (the unwind destination). | |
3174 | LandingPadInst *getLandingPadInst() const; | |
3175 | ||
3176 | BasicBlock *getSuccessor(unsigned i) const { | |
3177 | assert(i < 2 && "Successor # out of range for invoke!"); | |
3178 | return i == 0 ? getNormalDest() : getUnwindDest(); | |
3179 | } | |
3180 | ||
3181 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { | |
3182 | assert(idx < 2 && "Successor # out of range for invoke!"); | |
3183 | *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc); | |
3184 | } | |
3185 | ||
3186 | unsigned getNumSuccessors() const { return 2; } | |
3187 | ||
3188 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
3189 | static inline bool classof(const Instruction *I) { |
3190 | return (I->getOpcode() == Instruction::Invoke); | |
3191 | } | |
3192 | static inline bool classof(const Value *V) { | |
3193 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3194 | } | |
3195 | ||
3196 | private: | |
1a4d82fc JJ |
3197 | BasicBlock *getSuccessorV(unsigned idx) const override; |
3198 | unsigned getNumSuccessorsV() const override; | |
3199 | void setSuccessorV(unsigned idx, BasicBlock *B) override; | |
3200 | ||
3201 | bool hasFnAttrImpl(Attribute::AttrKind A) const; | |
223e47cc LB |
3202 | |
3203 | // Shadow Instruction::setInstructionSubclassData with a private forwarding | |
3204 | // method so that subclasses cannot accidentally use it. | |
3205 | void setInstructionSubclassData(unsigned short D) { | |
3206 | Instruction::setInstructionSubclassData(D); | |
3207 | } | |
3208 | }; | |
3209 | ||
3210 | template <> | |
3211 | struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> { | |
3212 | }; | |
3213 | ||
3214 | InvokeInst::InvokeInst(Value *Func, | |
3215 | BasicBlock *IfNormal, BasicBlock *IfException, | |
3216 | ArrayRef<Value *> Args, unsigned Values, | |
3217 | const Twine &NameStr, Instruction *InsertBefore) | |
3218 | : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) | |
3219 | ->getElementType())->getReturnType(), | |
3220 | Instruction::Invoke, | |
3221 | OperandTraits<InvokeInst>::op_end(this) - Values, | |
3222 | Values, InsertBefore) { | |
3223 | init(Func, IfNormal, IfException, Args, NameStr); | |
3224 | } | |
3225 | InvokeInst::InvokeInst(Value *Func, | |
3226 | BasicBlock *IfNormal, BasicBlock *IfException, | |
3227 | ArrayRef<Value *> Args, unsigned Values, | |
3228 | const Twine &NameStr, BasicBlock *InsertAtEnd) | |
3229 | : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) | |
3230 | ->getElementType())->getReturnType(), | |
3231 | Instruction::Invoke, | |
3232 | OperandTraits<InvokeInst>::op_end(this) - Values, | |
3233 | Values, InsertAtEnd) { | |
3234 | init(Func, IfNormal, IfException, Args, NameStr); | |
3235 | } | |
3236 | ||
3237 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value) | |
3238 | ||
3239 | //===----------------------------------------------------------------------===// | |
3240 | // ResumeInst Class | |
3241 | //===----------------------------------------------------------------------===// | |
3242 | ||
3243 | //===--------------------------------------------------------------------------- | |
3244 | /// ResumeInst - Resume the propagation of an exception. | |
3245 | /// | |
3246 | class ResumeInst : public TerminatorInst { | |
3247 | ResumeInst(const ResumeInst &RI); | |
3248 | ||
1a4d82fc | 3249 | explicit ResumeInst(Value *Exn, Instruction *InsertBefore=nullptr); |
223e47cc LB |
3250 | ResumeInst(Value *Exn, BasicBlock *InsertAtEnd); |
3251 | protected: | |
1a4d82fc | 3252 | ResumeInst *clone_impl() const override; |
223e47cc | 3253 | public: |
1a4d82fc | 3254 | static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = nullptr) { |
223e47cc LB |
3255 | return new(1) ResumeInst(Exn, InsertBefore); |
3256 | } | |
3257 | static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) { | |
3258 | return new(1) ResumeInst(Exn, InsertAtEnd); | |
3259 | } | |
3260 | ||
3261 | /// Provide fast operand accessors | |
3262 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); | |
3263 | ||
3264 | /// Convenience accessor. | |
3265 | Value *getValue() const { return Op<0>(); } | |
3266 | ||
3267 | unsigned getNumSuccessors() const { return 0; } | |
3268 | ||
3269 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
3270 | static inline bool classof(const Instruction *I) { |
3271 | return I->getOpcode() == Instruction::Resume; | |
3272 | } | |
3273 | static inline bool classof(const Value *V) { | |
3274 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3275 | } | |
3276 | private: | |
1a4d82fc JJ |
3277 | BasicBlock *getSuccessorV(unsigned idx) const override; |
3278 | unsigned getNumSuccessorsV() const override; | |
3279 | void setSuccessorV(unsigned idx, BasicBlock *B) override; | |
223e47cc LB |
3280 | }; |
3281 | ||
3282 | template <> | |
3283 | struct OperandTraits<ResumeInst> : | |
3284 | public FixedNumOperandTraits<ResumeInst, 1> { | |
3285 | }; | |
3286 | ||
3287 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value) | |
3288 | ||
3289 | //===----------------------------------------------------------------------===// | |
3290 | // UnreachableInst Class | |
3291 | //===----------------------------------------------------------------------===// | |
3292 | ||
3293 | //===--------------------------------------------------------------------------- | |
3294 | /// UnreachableInst - This function has undefined behavior. In particular, the | |
3295 | /// presence of this instruction indicates some higher level knowledge that the | |
3296 | /// end of the block cannot be reached. | |
3297 | /// | |
3298 | class UnreachableInst : public TerminatorInst { | |
3299 | void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; | |
3300 | protected: | |
1a4d82fc | 3301 | UnreachableInst *clone_impl() const override; |
223e47cc LB |
3302 | |
3303 | public: | |
3304 | // allocate space for exactly zero operands | |
3305 | void *operator new(size_t s) { | |
3306 | return User::operator new(s, 0); | |
3307 | } | |
1a4d82fc | 3308 | explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = nullptr); |
223e47cc LB |
3309 | explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd); |
3310 | ||
3311 | unsigned getNumSuccessors() const { return 0; } | |
3312 | ||
3313 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
3314 | static inline bool classof(const Instruction *I) { |
3315 | return I->getOpcode() == Instruction::Unreachable; | |
3316 | } | |
3317 | static inline bool classof(const Value *V) { | |
3318 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3319 | } | |
3320 | private: | |
1a4d82fc JJ |
3321 | BasicBlock *getSuccessorV(unsigned idx) const override; |
3322 | unsigned getNumSuccessorsV() const override; | |
3323 | void setSuccessorV(unsigned idx, BasicBlock *B) override; | |
223e47cc LB |
3324 | }; |
3325 | ||
3326 | //===----------------------------------------------------------------------===// | |
3327 | // TruncInst Class | |
3328 | //===----------------------------------------------------------------------===// | |
3329 | ||
970d7e83 | 3330 | /// \brief This class represents a truncation of integer types. |
223e47cc LB |
3331 | class TruncInst : public CastInst { |
3332 | protected: | |
970d7e83 | 3333 | /// \brief Clone an identical TruncInst |
1a4d82fc | 3334 | TruncInst *clone_impl() const override; |
223e47cc LB |
3335 | |
3336 | public: | |
970d7e83 | 3337 | /// \brief Constructor with insert-before-instruction semantics |
223e47cc | 3338 | TruncInst( |
1a4d82fc JJ |
3339 | Value *S, ///< The value to be truncated |
3340 | Type *Ty, ///< The (smaller) type to truncate to | |
3341 | const Twine &NameStr = "", ///< A name for the new instruction | |
3342 | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction | |
223e47cc LB |
3343 | ); |
3344 | ||
970d7e83 | 3345 | /// \brief Constructor with insert-at-end-of-block semantics |
223e47cc LB |
3346 | TruncInst( |
3347 | Value *S, ///< The value to be truncated | |
1a4d82fc | 3348 | Type *Ty, ///< The (smaller) type to truncate to |
223e47cc LB |
3349 | const Twine &NameStr, ///< A name for the new instruction |
3350 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into | |
3351 | ); | |
3352 | ||
970d7e83 | 3353 | /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
3354 | static inline bool classof(const Instruction *I) { |
3355 | return I->getOpcode() == Trunc; | |
3356 | } | |
3357 | static inline bool classof(const Value *V) { | |
3358 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3359 | } | |
3360 | }; | |
3361 | ||
3362 | //===----------------------------------------------------------------------===// | |
3363 | // ZExtInst Class | |
3364 | //===----------------------------------------------------------------------===// | |
3365 | ||
970d7e83 | 3366 | /// \brief This class represents zero extension of integer types. |
223e47cc LB |
3367 | class ZExtInst : public CastInst { |
3368 | protected: | |
970d7e83 | 3369 | /// \brief Clone an identical ZExtInst |
1a4d82fc | 3370 | ZExtInst *clone_impl() const override; |
223e47cc LB |
3371 | |
3372 | public: | |
970d7e83 | 3373 | /// \brief Constructor with insert-before-instruction semantics |
223e47cc | 3374 | ZExtInst( |
1a4d82fc JJ |
3375 | Value *S, ///< The value to be zero extended |
3376 | Type *Ty, ///< The type to zero extend to | |
3377 | const Twine &NameStr = "", ///< A name for the new instruction | |
3378 | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction | |
223e47cc LB |
3379 | ); |
3380 | ||
970d7e83 | 3381 | /// \brief Constructor with insert-at-end semantics. |
223e47cc LB |
3382 | ZExtInst( |
3383 | Value *S, ///< The value to be zero extended | |
1a4d82fc | 3384 | Type *Ty, ///< The type to zero extend to |
223e47cc LB |
3385 | const Twine &NameStr, ///< A name for the new instruction |
3386 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into | |
3387 | ); | |
3388 | ||
970d7e83 | 3389 | /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
3390 | static inline bool classof(const Instruction *I) { |
3391 | return I->getOpcode() == ZExt; | |
3392 | } | |
3393 | static inline bool classof(const Value *V) { | |
3394 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3395 | } | |
3396 | }; | |
3397 | ||
3398 | //===----------------------------------------------------------------------===// | |
3399 | // SExtInst Class | |
3400 | //===----------------------------------------------------------------------===// | |
3401 | ||
970d7e83 | 3402 | /// \brief This class represents a sign extension of integer types. |
223e47cc LB |
3403 | class SExtInst : public CastInst { |
3404 | protected: | |
970d7e83 | 3405 | /// \brief Clone an identical SExtInst |
1a4d82fc | 3406 | SExtInst *clone_impl() const override; |
223e47cc LB |
3407 | |
3408 | public: | |
970d7e83 | 3409 | /// \brief Constructor with insert-before-instruction semantics |
223e47cc | 3410 | SExtInst( |
1a4d82fc JJ |
3411 | Value *S, ///< The value to be sign extended |
3412 | Type *Ty, ///< The type to sign extend to | |
3413 | const Twine &NameStr = "", ///< A name for the new instruction | |
3414 | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction | |
223e47cc LB |
3415 | ); |
3416 | ||
970d7e83 | 3417 | /// \brief Constructor with insert-at-end-of-block semantics |
223e47cc LB |
3418 | SExtInst( |
3419 | Value *S, ///< The value to be sign extended | |
1a4d82fc | 3420 | Type *Ty, ///< The type to sign extend to |
223e47cc LB |
3421 | const Twine &NameStr, ///< A name for the new instruction |
3422 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into | |
3423 | ); | |
3424 | ||
970d7e83 | 3425 | /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
3426 | static inline bool classof(const Instruction *I) { |
3427 | return I->getOpcode() == SExt; | |
3428 | } | |
3429 | static inline bool classof(const Value *V) { | |
3430 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3431 | } | |
3432 | }; | |
3433 | ||
3434 | //===----------------------------------------------------------------------===// | |
3435 | // FPTruncInst Class | |
3436 | //===----------------------------------------------------------------------===// | |
3437 | ||
970d7e83 | 3438 | /// \brief This class represents a truncation of floating point types. |
223e47cc LB |
3439 | class FPTruncInst : public CastInst { |
3440 | protected: | |
970d7e83 | 3441 | /// \brief Clone an identical FPTruncInst |
1a4d82fc | 3442 | FPTruncInst *clone_impl() const override; |
223e47cc LB |
3443 | |
3444 | public: | |
970d7e83 | 3445 | /// \brief Constructor with insert-before-instruction semantics |
223e47cc | 3446 | FPTruncInst( |
1a4d82fc JJ |
3447 | Value *S, ///< The value to be truncated |
3448 | Type *Ty, ///< The type to truncate to | |
3449 | const Twine &NameStr = "", ///< A name for the new instruction | |
3450 | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction | |
223e47cc LB |
3451 | ); |
3452 | ||
970d7e83 | 3453 | /// \brief Constructor with insert-before-instruction semantics |
223e47cc LB |
3454 | FPTruncInst( |
3455 | Value *S, ///< The value to be truncated | |
1a4d82fc | 3456 | Type *Ty, ///< The type to truncate to |
223e47cc LB |
3457 | const Twine &NameStr, ///< A name for the new instruction |
3458 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into | |
3459 | ); | |
3460 | ||
970d7e83 | 3461 | /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
3462 | static inline bool classof(const Instruction *I) { |
3463 | return I->getOpcode() == FPTrunc; | |
3464 | } | |
3465 | static inline bool classof(const Value *V) { | |
3466 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3467 | } | |
3468 | }; | |
3469 | ||
3470 | //===----------------------------------------------------------------------===// | |
3471 | // FPExtInst Class | |
3472 | //===----------------------------------------------------------------------===// | |
3473 | ||
970d7e83 | 3474 | /// \brief This class represents an extension of floating point types. |
223e47cc LB |
3475 | class FPExtInst : public CastInst { |
3476 | protected: | |
970d7e83 | 3477 | /// \brief Clone an identical FPExtInst |
1a4d82fc | 3478 | FPExtInst *clone_impl() const override; |
223e47cc LB |
3479 | |
3480 | public: | |
970d7e83 | 3481 | /// \brief Constructor with insert-before-instruction semantics |
223e47cc | 3482 | FPExtInst( |
1a4d82fc JJ |
3483 | Value *S, ///< The value to be extended |
3484 | Type *Ty, ///< The type to extend to | |
3485 | const Twine &NameStr = "", ///< A name for the new instruction | |
3486 | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction | |
223e47cc LB |
3487 | ); |
3488 | ||
970d7e83 | 3489 | /// \brief Constructor with insert-at-end-of-block semantics |
223e47cc LB |
3490 | FPExtInst( |
3491 | Value *S, ///< The value to be extended | |
1a4d82fc | 3492 | Type *Ty, ///< The type to extend to |
223e47cc LB |
3493 | const Twine &NameStr, ///< A name for the new instruction |
3494 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into | |
3495 | ); | |
3496 | ||
970d7e83 | 3497 | /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
3498 | static inline bool classof(const Instruction *I) { |
3499 | return I->getOpcode() == FPExt; | |
3500 | } | |
3501 | static inline bool classof(const Value *V) { | |
3502 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3503 | } | |
3504 | }; | |
3505 | ||
3506 | //===----------------------------------------------------------------------===// | |
3507 | // UIToFPInst Class | |
3508 | //===----------------------------------------------------------------------===// | |
3509 | ||
970d7e83 | 3510 | /// \brief This class represents a cast unsigned integer to floating point. |
223e47cc LB |
3511 | class UIToFPInst : public CastInst { |
3512 | protected: | |
970d7e83 | 3513 | /// \brief Clone an identical UIToFPInst |
1a4d82fc | 3514 | UIToFPInst *clone_impl() const override; |
223e47cc LB |
3515 | |
3516 | public: | |
970d7e83 | 3517 | /// \brief Constructor with insert-before-instruction semantics |
223e47cc | 3518 | UIToFPInst( |
1a4d82fc JJ |
3519 | Value *S, ///< The value to be converted |
3520 | Type *Ty, ///< The type to convert to | |
3521 | const Twine &NameStr = "", ///< A name for the new instruction | |
3522 | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction | |
223e47cc LB |
3523 | ); |
3524 | ||
970d7e83 | 3525 | /// \brief Constructor with insert-at-end-of-block semantics |
223e47cc LB |
3526 | UIToFPInst( |
3527 | Value *S, ///< The value to be converted | |
1a4d82fc | 3528 | Type *Ty, ///< The type to convert to |
223e47cc LB |
3529 | const Twine &NameStr, ///< A name for the new instruction |
3530 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into | |
3531 | ); | |
3532 | ||
970d7e83 | 3533 | /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
3534 | static inline bool classof(const Instruction *I) { |
3535 | return I->getOpcode() == UIToFP; | |
3536 | } | |
3537 | static inline bool classof(const Value *V) { | |
3538 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3539 | } | |
3540 | }; | |
3541 | ||
3542 | //===----------------------------------------------------------------------===// | |
3543 | // SIToFPInst Class | |
3544 | //===----------------------------------------------------------------------===// | |
3545 | ||
970d7e83 | 3546 | /// \brief This class represents a cast from signed integer to floating point. |
223e47cc LB |
3547 | class SIToFPInst : public CastInst { |
3548 | protected: | |
970d7e83 | 3549 | /// \brief Clone an identical SIToFPInst |
1a4d82fc | 3550 | SIToFPInst *clone_impl() const override; |
223e47cc LB |
3551 | |
3552 | public: | |
970d7e83 | 3553 | /// \brief Constructor with insert-before-instruction semantics |
223e47cc | 3554 | SIToFPInst( |
1a4d82fc JJ |
3555 | Value *S, ///< The value to be converted |
3556 | Type *Ty, ///< The type to convert to | |
3557 | const Twine &NameStr = "", ///< A name for the new instruction | |
3558 | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction | |
223e47cc LB |
3559 | ); |
3560 | ||
970d7e83 | 3561 | /// \brief Constructor with insert-at-end-of-block semantics |
223e47cc LB |
3562 | SIToFPInst( |
3563 | Value *S, ///< The value to be converted | |
1a4d82fc | 3564 | Type *Ty, ///< The type to convert to |
223e47cc LB |
3565 | const Twine &NameStr, ///< A name for the new instruction |
3566 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into | |
3567 | ); | |
3568 | ||
970d7e83 | 3569 | /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
3570 | static inline bool classof(const Instruction *I) { |
3571 | return I->getOpcode() == SIToFP; | |
3572 | } | |
3573 | static inline bool classof(const Value *V) { | |
3574 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3575 | } | |
3576 | }; | |
3577 | ||
3578 | //===----------------------------------------------------------------------===// | |
3579 | // FPToUIInst Class | |
3580 | //===----------------------------------------------------------------------===// | |
3581 | ||
970d7e83 | 3582 | /// \brief This class represents a cast from floating point to unsigned integer |
223e47cc LB |
3583 | class FPToUIInst : public CastInst { |
3584 | protected: | |
970d7e83 | 3585 | /// \brief Clone an identical FPToUIInst |
1a4d82fc | 3586 | FPToUIInst *clone_impl() const override; |
223e47cc LB |
3587 | |
3588 | public: | |
970d7e83 | 3589 | /// \brief Constructor with insert-before-instruction semantics |
223e47cc | 3590 | FPToUIInst( |
1a4d82fc JJ |
3591 | Value *S, ///< The value to be converted |
3592 | Type *Ty, ///< The type to convert to | |
3593 | const Twine &NameStr = "", ///< A name for the new instruction | |
3594 | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction | |
223e47cc LB |
3595 | ); |
3596 | ||
970d7e83 | 3597 | /// \brief Constructor with insert-at-end-of-block semantics |
223e47cc LB |
3598 | FPToUIInst( |
3599 | Value *S, ///< The value to be converted | |
1a4d82fc | 3600 | Type *Ty, ///< The type to convert to |
223e47cc LB |
3601 | const Twine &NameStr, ///< A name for the new instruction |
3602 | BasicBlock *InsertAtEnd ///< Where to insert the new instruction | |
3603 | ); | |
3604 | ||
970d7e83 | 3605 | /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
3606 | static inline bool classof(const Instruction *I) { |
3607 | return I->getOpcode() == FPToUI; | |
3608 | } | |
3609 | static inline bool classof(const Value *V) { | |
3610 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3611 | } | |
3612 | }; | |
3613 | ||
3614 | //===----------------------------------------------------------------------===// | |
3615 | // FPToSIInst Class | |
3616 | //===----------------------------------------------------------------------===// | |
3617 | ||
970d7e83 | 3618 | /// \brief This class represents a cast from floating point to signed integer. |
223e47cc LB |
3619 | class FPToSIInst : public CastInst { |
3620 | protected: | |
970d7e83 | 3621 | /// \brief Clone an identical FPToSIInst |
1a4d82fc | 3622 | FPToSIInst *clone_impl() const override; |
223e47cc LB |
3623 | |
3624 | public: | |
970d7e83 | 3625 | /// \brief Constructor with insert-before-instruction semantics |
223e47cc | 3626 | FPToSIInst( |
1a4d82fc JJ |
3627 | Value *S, ///< The value to be converted |
3628 | Type *Ty, ///< The type to convert to | |
3629 | const Twine &NameStr = "", ///< A name for the new instruction | |
3630 | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction | |
223e47cc LB |
3631 | ); |
3632 | ||
970d7e83 | 3633 | /// \brief Constructor with insert-at-end-of-block semantics |
223e47cc LB |
3634 | FPToSIInst( |
3635 | Value *S, ///< The value to be converted | |
1a4d82fc | 3636 | Type *Ty, ///< The type to convert to |
223e47cc LB |
3637 | const Twine &NameStr, ///< A name for the new instruction |
3638 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into | |
3639 | ); | |
3640 | ||
970d7e83 | 3641 | /// \brief Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
3642 | static inline bool classof(const Instruction *I) { |
3643 | return I->getOpcode() == FPToSI; | |
3644 | } | |
3645 | static inline bool classof(const Value *V) { | |
3646 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3647 | } | |
3648 | }; | |
3649 | ||
3650 | //===----------------------------------------------------------------------===// | |
3651 | // IntToPtrInst Class | |
3652 | //===----------------------------------------------------------------------===// | |
3653 | ||
970d7e83 | 3654 | /// \brief This class represents a cast from an integer to a pointer. |
223e47cc LB |
3655 | class IntToPtrInst : public CastInst { |
3656 | public: | |
970d7e83 | 3657 | /// \brief Constructor with insert-before-instruction semantics |
223e47cc | 3658 | IntToPtrInst( |
1a4d82fc JJ |
3659 | Value *S, ///< The value to be converted |
3660 | Type *Ty, ///< The type to convert to | |
3661 | const Twine &NameStr = "", ///< A name for the new instruction | |
3662 | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction | |
223e47cc LB |
3663 | ); |
3664 | ||
970d7e83 | 3665 | /// \brief Constructor with insert-at-end-of-block semantics |
223e47cc LB |
3666 | IntToPtrInst( |
3667 | Value *S, ///< The value to be converted | |
1a4d82fc | 3668 | Type *Ty, ///< The type to convert to |
223e47cc LB |
3669 | const Twine &NameStr, ///< A name for the new instruction |
3670 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into | |
3671 | ); | |
3672 | ||
970d7e83 | 3673 | /// \brief Clone an identical IntToPtrInst |
1a4d82fc | 3674 | IntToPtrInst *clone_impl() const override; |
223e47cc | 3675 | |
970d7e83 LB |
3676 | /// \brief Returns the address space of this instruction's pointer type. |
3677 | unsigned getAddressSpace() const { | |
3678 | return getType()->getPointerAddressSpace(); | |
3679 | } | |
3680 | ||
223e47cc | 3681 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
3682 | static inline bool classof(const Instruction *I) { |
3683 | return I->getOpcode() == IntToPtr; | |
3684 | } | |
3685 | static inline bool classof(const Value *V) { | |
3686 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3687 | } | |
3688 | }; | |
3689 | ||
3690 | //===----------------------------------------------------------------------===// | |
3691 | // PtrToIntInst Class | |
3692 | //===----------------------------------------------------------------------===// | |
3693 | ||
970d7e83 | 3694 | /// \brief This class represents a cast from a pointer to an integer |
223e47cc LB |
3695 | class PtrToIntInst : public CastInst { |
3696 | protected: | |
970d7e83 | 3697 | /// \brief Clone an identical PtrToIntInst |
1a4d82fc | 3698 | PtrToIntInst *clone_impl() const override; |
223e47cc LB |
3699 | |
3700 | public: | |
970d7e83 | 3701 | /// \brief Constructor with insert-before-instruction semantics |
223e47cc | 3702 | PtrToIntInst( |
1a4d82fc JJ |
3703 | Value *S, ///< The value to be converted |
3704 | Type *Ty, ///< The type to convert to | |
3705 | const Twine &NameStr = "", ///< A name for the new instruction | |
3706 | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction | |
223e47cc LB |
3707 | ); |
3708 | ||
970d7e83 | 3709 | /// \brief Constructor with insert-at-end-of-block semantics |
223e47cc LB |
3710 | PtrToIntInst( |
3711 | Value *S, ///< The value to be converted | |
1a4d82fc | 3712 | Type *Ty, ///< The type to convert to |
223e47cc LB |
3713 | const Twine &NameStr, ///< A name for the new instruction |
3714 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into | |
3715 | ); | |
3716 | ||
970d7e83 LB |
3717 | /// \brief Gets the pointer operand. |
3718 | Value *getPointerOperand() { return getOperand(0); } | |
3719 | /// \brief Gets the pointer operand. | |
3720 | const Value *getPointerOperand() const { return getOperand(0); } | |
3721 | /// \brief Gets the operand index of the pointer operand. | |
3722 | static unsigned getPointerOperandIndex() { return 0U; } | |
3723 | ||
3724 | /// \brief Returns the address space of the pointer operand. | |
3725 | unsigned getPointerAddressSpace() const { | |
3726 | return getPointerOperand()->getType()->getPointerAddressSpace(); | |
3727 | } | |
3728 | ||
223e47cc | 3729 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
223e47cc LB |
3730 | static inline bool classof(const Instruction *I) { |
3731 | return I->getOpcode() == PtrToInt; | |
3732 | } | |
3733 | static inline bool classof(const Value *V) { | |
3734 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3735 | } | |
3736 | }; | |
3737 | ||
3738 | //===----------------------------------------------------------------------===// | |
3739 | // BitCastInst Class | |
3740 | //===----------------------------------------------------------------------===// | |
3741 | ||
970d7e83 | 3742 | /// \brief This class represents a no-op cast from one type to another. |
223e47cc LB |
3743 | class BitCastInst : public CastInst { |
3744 | protected: | |
970d7e83 | 3745 | /// \brief Clone an identical BitCastInst |
1a4d82fc | 3746 | BitCastInst *clone_impl() const override; |
223e47cc LB |
3747 | |
3748 | public: | |
970d7e83 | 3749 | /// \brief Constructor with insert-before-instruction semantics |
223e47cc | 3750 | BitCastInst( |
1a4d82fc JJ |
3751 | Value *S, ///< The value to be casted |
3752 | Type *Ty, ///< The type to casted to | |
3753 | const Twine &NameStr = "", ///< A name for the new instruction | |
3754 | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction | |
223e47cc LB |
3755 | ); |
3756 | ||
970d7e83 | 3757 | /// \brief Constructor with insert-at-end-of-block semantics |
223e47cc LB |
3758 | BitCastInst( |
3759 | Value *S, ///< The value to be casted | |
1a4d82fc | 3760 | Type *Ty, ///< The type to casted to |
223e47cc LB |
3761 | const Twine &NameStr, ///< A name for the new instruction |
3762 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into | |
3763 | ); | |
3764 | ||
3765 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
223e47cc LB |
3766 | static inline bool classof(const Instruction *I) { |
3767 | return I->getOpcode() == BitCast; | |
3768 | } | |
3769 | static inline bool classof(const Value *V) { | |
3770 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3771 | } | |
3772 | }; | |
3773 | ||
1a4d82fc JJ |
3774 | //===----------------------------------------------------------------------===// |
3775 | // AddrSpaceCastInst Class | |
3776 | //===----------------------------------------------------------------------===// | |
3777 | ||
3778 | /// \brief This class represents a conversion between pointers from | |
3779 | /// one address space to another. | |
3780 | class AddrSpaceCastInst : public CastInst { | |
3781 | protected: | |
3782 | /// \brief Clone an identical AddrSpaceCastInst | |
3783 | AddrSpaceCastInst *clone_impl() const override; | |
3784 | ||
3785 | public: | |
3786 | /// \brief Constructor with insert-before-instruction semantics | |
3787 | AddrSpaceCastInst( | |
3788 | Value *S, ///< The value to be casted | |
3789 | Type *Ty, ///< The type to casted to | |
3790 | const Twine &NameStr = "", ///< A name for the new instruction | |
3791 | Instruction *InsertBefore = nullptr ///< Where to insert the new instruction | |
3792 | ); | |
3793 | ||
3794 | /// \brief Constructor with insert-at-end-of-block semantics | |
3795 | AddrSpaceCastInst( | |
3796 | Value *S, ///< The value to be casted | |
3797 | Type *Ty, ///< The type to casted to | |
3798 | const Twine &NameStr, ///< A name for the new instruction | |
3799 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into | |
3800 | ); | |
3801 | ||
3802 | // Methods for support type inquiry through isa, cast, and dyn_cast: | |
3803 | static inline bool classof(const Instruction *I) { | |
3804 | return I->getOpcode() == AddrSpaceCast; | |
3805 | } | |
3806 | static inline bool classof(const Value *V) { | |
3807 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); | |
3808 | } | |
3809 | }; | |
3810 | ||
223e47cc LB |
3811 | } // End llvm namespace |
3812 | ||
3813 | #endif |