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