Coverage Report

Created: 2019-07-24 05:18

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