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