| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef LLVM_IR_CONSTANTS_H |
| 21 |
#define LLVM_IR_CONSTANTS_H |
| 22 |
|
| 23 |
#include "llvm/ADT/APFloat.h" |
| 24 |
#include "llvm/ADT/APInt.h" |
| 25 |
#include "llvm/ADT/ArrayRef.h" |
| 26 |
#include "llvm/ADT/None.h" |
| 27 |
#include "llvm/ADT/Optional.h" |
| 28 |
#include "llvm/ADT/STLExtras.h" |
| 29 |
#include "llvm/ADT/StringRef.h" |
| 30 |
#include "llvm/IR/Constant.h" |
| 31 |
#include "llvm/IR/DerivedTypes.h" |
| 32 |
#include "llvm/IR/OperandTraits.h" |
| 33 |
#include "llvm/IR/User.h" |
| 34 |
#include "llvm/IR/Value.h" |
| 35 |
#include "llvm/Support/Casting.h" |
| 36 |
#include "llvm/Support/Compiler.h" |
| 37 |
#include "llvm/Support/ErrorHandling.h" |
| 38 |
#include <cassert> |
| 39 |
#include <cstddef> |
| 40 |
#include <cstdint> |
| 41 |
|
| 42 |
namespace llvm { |
| 43 |
|
| 44 |
template <class ConstantClass> struct ConstantAggrKeyType; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
class ConstantData : public Constant { |
| 52 |
friend class Constant; |
| 53 |
|
| 54 |
Value *handleOperandChangeImpl(Value *From, Value *To) { |
| 55 |
llvm_unreachable("Constant data does not have operands!"); |
| 56 |
} |
| 57 |
|
| 58 |
protected: |
| 59 |
explicit ConstantData(Type *Ty, ValueTy VT) : Constant(Ty, VT, nullptr, 0) {} |
| 60 |
|
| 61 |
void *operator new(size_t S) { return User::operator new(S, 0); } |
| 62 |
|
| 63 |
public: |
| 64 |
void operator delete(void *Ptr) { User::operator delete(Ptr); } |
| 65 |
|
| 66 |
ConstantData(const ConstantData &) = delete; |
| 67 |
|
| 68 |
|
| 69 |
static bool classof(const Value *V) { |
| 70 |
return V->getValueID() >= ConstantDataFirstVal && |
| 71 |
V->getValueID() <= ConstantDataLastVal; |
| 72 |
} |
| 73 |
}; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
class ConstantInt final : public ConstantData { |
| 80 |
friend class Constant; |
| 81 |
|
| 82 |
APInt Val; |
| 83 |
|
| 84 |
ConstantInt(IntegerType *Ty, const APInt &V); |
| 85 |
|
| 86 |
void destroyConstantImpl(); |
| 87 |
|
| 88 |
public: |
| 89 |
ConstantInt(const ConstantInt &) = delete; |
| 90 |
|
| 91 |
static ConstantInt *getTrue(LLVMContext &Context); |
| 92 |
static ConstantInt *getFalse(LLVMContext &Context); |
| 93 |
static ConstantInt *getBool(LLVMContext &Context, bool V); |
| 94 |
static Constant *getTrue(Type *Ty); |
| 95 |
static Constant *getFalse(Type *Ty); |
| 96 |
static Constant *getBool(Type *Ty, bool V); |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
static Constant *get(Type *Ty, uint64_t V, bool IsSigned = false); |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
static ConstantInt *get(IntegerType *Ty, uint64_t V, bool IsSigned = false); |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
static ConstantInt *getSigned(IntegerType *Ty, int64_t V); |
| 116 |
static Constant *getSigned(Type *Ty, int64_t V); |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
static ConstantInt *get(LLVMContext &Context, const APInt &V); |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
static ConstantInt *get(IntegerType *Ty, StringRef Str, uint8_t Radix); |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
static Constant *get(Type *Ty, const APInt &V); |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
inline const APInt &getValue() const { return Val; } |
| 134 |
|
| 135 |
|
| 136 |
unsigned getBitWidth() const { return Val.getBitWidth(); } |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
inline uint64_t getZExtValue() const { return Val.getZExtValue(); } |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
inline int64_t getSExtValue() const { return Val.getSExtValue(); } |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
inline MaybeAlign getMaybeAlignValue() const { |
| 154 |
return MaybeAlign(getZExtValue()); |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
inline Align getAlignValue() const { |
| 161 |
return getMaybeAlignValue().valueOrOne(); |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
bool equalsInt(uint64_t V) const { return Val == V; } |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
inline IntegerType *getType() const { |
| 174 |
return cast<IntegerType>(Value::getType()); |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
static bool isValueValidForType(Type *Ty, uint64_t V); |
| 187 |
static bool isValueValidForType(Type *Ty, int64_t V); |
| 188 |
|
| 189 |
bool isNegative() const { return Val.isNegative(); } |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
bool isZero() const { return Val.isZero(); } |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
bool isOne() const { return Val.isOne(); } |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
bool isMinusOne() const { return Val.isAllOnes(); } |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
bool isMaxValue(bool IsSigned) const { |
| 214 |
if (IsSigned) |
| 215 |
return Val.isMaxSignedValue(); |
| 216 |
else |
| 217 |
return Val.isMaxValue(); |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
bool isMinValue(bool IsSigned) const { |
| 226 |
if (IsSigned) |
| 227 |
return Val.isMinSignedValue(); |
| 228 |
else |
| 229 |
return Val.isMinValue(); |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
bool uge(uint64_t Num) const { return Val.uge(Num); } |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const { |
| 245 |
return Val.getLimitedValue(Limit); |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
static bool classof(const Value *V) { |
| 250 |
return V->getValueID() == ConstantIntVal; |
| 251 |
} |
| 252 |
}; |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
class ConstantFP final : public ConstantData { |
| 258 |
friend class Constant; |
| 259 |
|
| 260 |
APFloat Val; |
| 261 |
|
| 262 |
ConstantFP(Type *Ty, const APFloat &V); |
| 263 |
|
| 264 |
void destroyConstantImpl(); |
| 265 |
|
| 266 |
public: |
| 267 |
ConstantFP(const ConstantFP &) = delete; |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
static Constant *getZeroValueForNegation(Type *Ty); |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
static Constant *get(Type *Ty, double V); |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
static Constant *get(Type *Ty, const APFloat &V); |
| 283 |
|
| 284 |
static Constant *get(Type *Ty, StringRef Str); |
| 285 |
static ConstantFP *get(LLVMContext &Context, const APFloat &V); |
| 286 |
static Constant *getNaN(Type *Ty, bool Negative = false, |
| 287 |
uint64_t Payload = 0); |
| 288 |
static Constant *getQNaN(Type *Ty, bool Negative = false, |
| 289 |
APInt *Payload = nullptr); |
| 290 |
static Constant *getSNaN(Type *Ty, bool Negative = false, |
| 291 |
APInt *Payload = nullptr); |
| 292 |
static Constant *getNegativeZero(Type *Ty); |
| 293 |
static Constant *getInfinity(Type *Ty, bool Negative = false); |
| 294 |
|
| 295 |
|
| 296 |
static bool isValueValidForType(Type *Ty, const APFloat &V); |
| 297 |
inline const APFloat &getValueAPF() const { return Val; } |
| 298 |
inline const APFloat &getValue() const { return Val; } |
| 299 |
|
| 300 |
|
| 301 |
bool isZero() const { return Val.isZero(); } |
| 302 |
|
| 303 |
|
| 304 |
bool isNegative() const { return Val.isNegative(); } |
| 305 |
|
| 306 |
|
| 307 |
bool isInfinity() const { return Val.isInfinity(); } |
| 308 |
|
| 309 |
|
| 310 |
bool isNaN() const { return Val.isNaN(); } |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
bool isExactlyValue(const APFloat &V) const; |
| 319 |
|
| 320 |
bool isExactlyValue(double V) const { |
| 321 |
bool ignored; |
| 322 |
APFloat FV(V); |
| 323 |
FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored); |
| 324 |
return isExactlyValue(FV); |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
static bool classof(const Value *V) { |
| 329 |
return V->getValueID() == ConstantFPVal; |
| 330 |
} |
| 331 |
}; |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
class ConstantAggregateZero final : public ConstantData { |
| 337 |
friend class Constant; |
| 338 |
|
| 339 |
explicit ConstantAggregateZero(Type *Ty) |
| 340 |
: ConstantData(Ty, ConstantAggregateZeroVal) {} |
| 341 |
|
| 342 |
void destroyConstantImpl(); |
| 343 |
|
| 344 |
public: |
| 345 |
ConstantAggregateZero(const ConstantAggregateZero &) = delete; |
| 346 |
|
| 347 |
static ConstantAggregateZero *get(Type *Ty); |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
Constant *getSequentialElement() const; |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
Constant *getStructElement(unsigned Elt) const; |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
Constant *getElementValue(Constant *C) const; |
| 360 |
|
| 361 |
|
| 362 |
Constant *getElementValue(unsigned Idx) const; |
| 363 |
|
| 364 |
|
| 365 |
ElementCount getElementCount() const; |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
static bool classof(const Value *V) { |
| 370 |
return V->getValueID() == ConstantAggregateZeroVal; |
| 371 |
} |
| 372 |
}; |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
class ConstantAggregate : public Constant { |
| 386 |
protected: |
| 387 |
ConstantAggregate(Type *T, ValueTy VT, ArrayRef<Constant *> V); |
| 388 |
|
| 389 |
public: |
| 390 |
|
| 391 |
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); |
| 392 |
|
| 393 |
|
| 394 |
static bool classof(const Value *V) { |
| 395 |
return V->getValueID() >= ConstantAggregateFirstVal && |
| 396 |
V->getValueID() <= ConstantAggregateLastVal; |
| 397 |
} |
| 398 |
}; |
| 399 |
|
| 400 |
template <> |
| 401 |
struct OperandTraits<ConstantAggregate> |
| 402 |
: public VariadicOperandTraits<ConstantAggregate> {}; |
| 403 |
|
| 404 |
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantAggregate, Constant) |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
class ConstantArray final : public ConstantAggregate { |
| 410 |
friend struct ConstantAggrKeyType<ConstantArray>; |
| 411 |
friend class Constant; |
| 412 |
|
| 413 |
ConstantArray(ArrayType *T, ArrayRef<Constant *> Val); |
| 414 |
|
| 415 |
void destroyConstantImpl(); |
| 416 |
Value *handleOperandChangeImpl(Value *From, Value *To); |
| 417 |
|
| 418 |
public: |
| 419 |
|
| 420 |
static Constant *get(ArrayType *T, ArrayRef<Constant *> V); |
| 421 |
|
| 422 |
private: |
| 423 |
static Constant *getImpl(ArrayType *T, ArrayRef<Constant *> V); |
| 424 |
|
| 425 |
public: |
| 426 |
|
| 427 |
|
| 428 |
inline ArrayType *getType() const { |
| 429 |
return cast<ArrayType>(Value::getType()); |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
static bool classof(const Value *V) { |
| 434 |
return V->getValueID() == ConstantArrayVal; |
| 435 |
} |
| 436 |
}; |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
class ConstantStruct final : public ConstantAggregate { |
| 442 |
friend struct ConstantAggrKeyType<ConstantStruct>; |
| 443 |
friend class Constant; |
| 444 |
|
| 445 |
ConstantStruct(StructType *T, ArrayRef<Constant *> Val); |
| 446 |
|
| 447 |
void destroyConstantImpl(); |
| 448 |
Value *handleOperandChangeImpl(Value *From, Value *To); |
| 449 |
|
| 450 |
public: |
| 451 |
|
| 452 |
static Constant *get(StructType *T, ArrayRef<Constant *> V); |
| 453 |
|
| 454 |
template <typename... Csts> |
| 455 |
static std::enable_if_t<are_base_of<Constant, Csts...>::value, Constant *> |
| 456 |
get(StructType *T, Csts *...Vs) { |
| 457 |
return get(T, ArrayRef<Constant *>({Vs...})); |
| 458 |
} |
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
static Constant *getAnon(ArrayRef<Constant *> V, bool Packed = false) { |
| 463 |
return get(getTypeForElements(V, Packed), V); |
| 464 |
} |
| 465 |
static Constant *getAnon(LLVMContext &Ctx, ArrayRef<Constant *> V, |
| 466 |
bool Packed = false) { |
| 467 |
return get(getTypeForElements(Ctx, V, Packed), V); |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
static StructType *getTypeForElements(ArrayRef<Constant *> V, |
| 473 |
bool Packed = false); |
| 474 |
|
| 475 |
static StructType *getTypeForElements(LLVMContext &Ctx, |
| 476 |
ArrayRef<Constant *> V, |
| 477 |
bool Packed = false); |
| 478 |
|
| 479 |
|
| 480 |
inline StructType *getType() const { |
| 481 |
return cast<StructType>(Value::getType()); |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
static bool classof(const Value *V) { |
| 486 |
return V->getValueID() == ConstantStructVal; |
| 487 |
} |
| 488 |
}; |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
class ConstantVector final : public ConstantAggregate { |
| 494 |
friend struct ConstantAggrKeyType<ConstantVector>; |
| 495 |
friend class Constant; |
| 496 |
|
| 497 |
ConstantVector(VectorType *T, ArrayRef<Constant *> Val); |
| 498 |
|
| 499 |
void destroyConstantImpl(); |
| 500 |
Value *handleOperandChangeImpl(Value *From, Value *To); |
| 501 |
|
| 502 |
public: |
| 503 |
|
| 504 |
static Constant *get(ArrayRef<Constant *> V); |
| 505 |
|
| 506 |
private: |
| 507 |
static Constant *getImpl(ArrayRef<Constant *> V); |
| 508 |
|
| 509 |
public: |
| 510 |
|
| 511 |
|
| 512 |
static Constant *getSplat(ElementCount EC, Constant *Elt); |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
inline FixedVectorType *getType() const { |
| 517 |
return cast<FixedVectorType>(Value::getType()); |
| 518 |
} |
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
Constant *getSplatValue(bool AllowUndefs = false) const; |
| 524 |
|
| 525 |
|
| 526 |
static bool classof(const Value *V) { |
| 527 |
return V->getValueID() == ConstantVectorVal; |
| 528 |
} |
| 529 |
}; |
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
class ConstantPointerNull final : public ConstantData { |
| 535 |
friend class Constant; |
| 536 |
|
| 537 |
explicit ConstantPointerNull(PointerType *T) |
| 538 |
: ConstantData(T, Value::ConstantPointerNullVal) {} |
| 539 |
|
| 540 |
void destroyConstantImpl(); |
| 541 |
|
| 542 |
public: |
| 543 |
ConstantPointerNull(const ConstantPointerNull &) = delete; |
| 544 |
|
| 545 |
|
| 546 |
static ConstantPointerNull *get(PointerType *T); |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
inline PointerType *getType() const { |
| 551 |
return cast<PointerType>(Value::getType()); |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
static bool classof(const Value *V) { |
| 556 |
return V->getValueID() == ConstantPointerNullVal; |
| 557 |
} |
| 558 |
}; |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
class ConstantDataSequential : public ConstantData { |
| 570 |
friend class LLVMContextImpl; |
| 571 |
friend class Constant; |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
const char *DataElements; |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
std::unique_ptr<ConstantDataSequential> Next; |
| 582 |
|
| 583 |
void destroyConstantImpl(); |
| 584 |
|
| 585 |
protected: |
| 586 |
explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data) |
| 587 |
: ConstantData(ty, VT), DataElements(Data) {} |
| 588 |
|
| 589 |
static Constant *getImpl(StringRef Bytes, Type *Ty); |
| 590 |
|
| 591 |
public: |
| 592 |
ConstantDataSequential(const ConstantDataSequential &) = delete; |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
static bool isElementTypeCompatible(Type *Ty); |
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
uint64_t getElementAsInteger(unsigned i) const; |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
APInt getElementAsAPInt(unsigned i) const; |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
APFloat getElementAsAPFloat(unsigned i) const; |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
float getElementAsFloat(unsigned i) const; |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
double getElementAsDouble(unsigned i) const; |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
Constant *getElementAsConstant(unsigned i) const; |
| 624 |
|
| 625 |
|
| 626 |
Type *getElementType() const; |
| 627 |
|
| 628 |
|
| 629 |
unsigned getNumElements() const; |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
uint64_t getElementByteSize() const; |
| 634 |
|
| 635 |
|
| 636 |
bool isString(unsigned CharSize = 8) const; |
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
bool isCString() const; |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
StringRef getAsString() const { |
| 645 |
assert(isString() && "Not a string"); |
| 646 |
return getRawDataValues(); |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
StringRef getAsCString() const { |
| 652 |
assert(isCString() && "Isn't a C string"); |
| 653 |
StringRef Str = getAsString(); |
| 654 |
return Str.substr(0, Str.size() - 1); |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
StringRef getRawDataValues() const; |
| 661 |
|
| 662 |
|
| 663 |
static bool classof(const Value *V) { |
| 664 |
return V->getValueID() == ConstantDataArrayVal || |
| 665 |
V->getValueID() == ConstantDataVectorVal; |
| 666 |
} |
| 667 |
|
| 668 |
private: |
| 669 |
const char *getElementPointer(unsigned Elt) const; |
| 670 |
}; |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
class ConstantDataArray final : public ConstantDataSequential { |
| 679 |
friend class ConstantDataSequential; |
| 680 |
|
| 681 |
explicit ConstantDataArray(Type *ty, const char *Data) |
| 682 |
: ConstantDataSequential(ty, ConstantDataArrayVal, Data) {} |
| 683 |
|
| 684 |
public: |
| 685 |
ConstantDataArray(const ConstantDataArray &) = delete; |
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
template <typename ElementTy> |
| 691 |
static Constant *get(LLVMContext &Context, ArrayRef<ElementTy> Elts) { |
| 692 |
const char *Data = reinterpret_cast<const char *>(Elts.data()); |
| 693 |
return getRaw(StringRef(Data, Elts.size() * sizeof(ElementTy)), Elts.size(), |
| 694 |
Type::getScalarTy<ElementTy>(Context)); |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
template <typename ArrayTy> |
| 700 |
static Constant *get(LLVMContext &Context, ArrayTy &Elts) { |
| 701 |
return ConstantDataArray::get(Context, makeArrayRef(Elts)); |
| 702 |
} |
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
static Constant *getRaw(StringRef Data, uint64_t NumElements, |
| 711 |
Type *ElementTy) { |
| 712 |
Type *Ty = ArrayType::get(ElementTy, NumElements); |
| 713 |
return getImpl(Data, Ty); |
| 714 |
} |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
static Constant *getFP(Type *ElementType, ArrayRef<uint16_t> Elts); |
| 723 |
static Constant *getFP(Type *ElementType, ArrayRef<uint32_t> Elts); |
| 724 |
static Constant *getFP(Type *ElementType, ArrayRef<uint64_t> Elts); |
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
static Constant *getString(LLVMContext &Context, StringRef Initializer, |
| 732 |
bool AddNull = true); |
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
inline ArrayType *getType() const { |
| 737 |
return cast<ArrayType>(Value::getType()); |
| 738 |
} |
| 739 |
|
| 740 |
|
| 741 |
static bool classof(const Value *V) { |
| 742 |
return V->getValueID() == ConstantDataArrayVal; |
| 743 |
} |
| 744 |
}; |
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
class ConstantDataVector final : public ConstantDataSequential { |
| 753 |
friend class ConstantDataSequential; |
| 754 |
|
| 755 |
explicit ConstantDataVector(Type *ty, const char *Data) |
| 756 |
: ConstantDataSequential(ty, ConstantDataVectorVal, Data), |
| 757 |
IsSplatSet(false) {} |
| 758 |
|
| 759 |
mutable bool IsSplatSet : 1; |
| 760 |
mutable bool IsSplat : 1; |
| 761 |
bool isSplatData() const; |
| 762 |
|
| 763 |
public: |
| 764 |
ConstantDataVector(const ConstantDataVector &) = delete; |
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts); |
| 770 |
static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts); |
| 771 |
static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts); |
| 772 |
static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts); |
| 773 |
static Constant *get(LLVMContext &Context, ArrayRef<float> Elts); |
| 774 |
static Constant *get(LLVMContext &Context, ArrayRef<double> Elts); |
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
static Constant *getRaw(StringRef Data, uint64_t NumElements, |
| 783 |
Type *ElementTy) { |
| 784 |
Type *Ty = VectorType::get(ElementTy, ElementCount::getFixed(NumElements)); |
| 785 |
return getImpl(Data, Ty); |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
static Constant *getFP(Type *ElementType, ArrayRef<uint16_t> Elts); |
| 795 |
static Constant *getFP(Type *ElementType, ArrayRef<uint32_t> Elts); |
| 796 |
static Constant *getFP(Type *ElementType, ArrayRef<uint64_t> Elts); |
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
static Constant *getSplat(unsigned NumElts, Constant *Elt); |
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
bool isSplat() const; |
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
Constant *getSplatValue() const; |
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
inline FixedVectorType *getType() const { |
| 814 |
return cast<FixedVectorType>(Value::getType()); |
| 815 |
} |
| 816 |
|
| 817 |
|
| 818 |
static bool classof(const Value *V) { |
| 819 |
return V->getValueID() == ConstantDataVectorVal; |
| 820 |
} |
| 821 |
}; |
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
class ConstantTokenNone final : public ConstantData { |
| 827 |
friend class Constant; |
| 828 |
|
| 829 |
explicit ConstantTokenNone(LLVMContext &Context) |
| 830 |
: ConstantData(Type::getTokenTy(Context), ConstantTokenNoneVal) {} |
| 831 |
|
| 832 |
void destroyConstantImpl(); |
| 833 |
|
| 834 |
public: |
| 835 |
ConstantTokenNone(const ConstantTokenNone &) = delete; |
| 836 |
|
| 837 |
|
| 838 |
static ConstantTokenNone *get(LLVMContext &Context); |
| 839 |
|
| 840 |
|
| 841 |
static bool classof(const Value *V) { |
| 842 |
return V->getValueID() == ConstantTokenNoneVal; |
| 843 |
} |
| 844 |
}; |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
class BlockAddress final : public Constant { |
| 849 |
friend class Constant; |
| 850 |
|
| 851 |
BlockAddress(Function *F, BasicBlock *BB); |
| 852 |
|
| 853 |
void *operator new(size_t S) { return User::operator new(S, 2); } |
| 854 |
|
| 855 |
void destroyConstantImpl(); |
| 856 |
Value *handleOperandChangeImpl(Value *From, Value *To); |
| 857 |
|
| 858 |
public: |
| 859 |
void operator delete(void *Ptr) { User::operator delete(Ptr); } |
| 860 |
|
| 861 |
|
| 862 |
static BlockAddress *get(Function *F, BasicBlock *BB); |
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
static BlockAddress *get(BasicBlock *BB); |
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
static BlockAddress *lookup(const BasicBlock *BB); |
| 872 |
|
| 873 |
|
| 874 |
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 875 |
|
| 876 |
Function *getFunction() const { return (Function *)Op<0>().get(); } |
| 877 |
BasicBlock *getBasicBlock() const { return (BasicBlock *)Op<1>().get(); } |
| 878 |
|
| 879 |
|
| 880 |
static bool classof(const Value *V) { |
| 881 |
return V->getValueID() == BlockAddressVal; |
| 882 |
} |
| 883 |
}; |
| 884 |
|
| 885 |
template <> |
| 886 |
struct OperandTraits<BlockAddress> |
| 887 |
: public FixedNumOperandTraits<BlockAddress, 2> {}; |
| 888 |
|
| 889 |
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BlockAddress, Value) |
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
class DSOLocalEquivalent final : public Constant { |
| 895 |
friend class Constant; |
| 896 |
|
| 897 |
DSOLocalEquivalent(GlobalValue *GV); |
| 898 |
|
| 899 |
void *operator new(size_t S) { return User::operator new(S, 1); } |
| 900 |
|
| 901 |
void destroyConstantImpl(); |
| 902 |
Value *handleOperandChangeImpl(Value *From, Value *To); |
| 903 |
|
| 904 |
public: |
| 905 |
void operator delete(void *Ptr) { User::operator delete(Ptr); } |
| 906 |
|
| 907 |
|
| 908 |
static DSOLocalEquivalent *get(GlobalValue *GV); |
| 909 |
|
| 910 |
|
| 911 |
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 912 |
|
| 913 |
GlobalValue *getGlobalValue() const { |
| 914 |
return cast<GlobalValue>(Op<0>().get()); |
| 915 |
} |
| 916 |
|
| 917 |
|
| 918 |
static bool classof(const Value *V) { |
| 919 |
return V->getValueID() == DSOLocalEquivalentVal; |
| 920 |
} |
| 921 |
}; |
| 922 |
|
| 923 |
template <> |
| 924 |
struct OperandTraits<DSOLocalEquivalent> |
| 925 |
: public FixedNumOperandTraits<DSOLocalEquivalent, 1> {}; |
| 926 |
|
| 927 |
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(DSOLocalEquivalent, Value) |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
class NoCFIValue final : public Constant { |
| 932 |
friend class Constant; |
| 933 |
|
| 934 |
NoCFIValue(GlobalValue *GV); |
| 935 |
|
| 936 |
void *operator new(size_t S) { return User::operator new(S, 1); } |
| 937 |
|
| 938 |
void destroyConstantImpl(); |
| 939 |
Value *handleOperandChangeImpl(Value *From, Value *To); |
| 940 |
|
| 941 |
public: |
| 942 |
|
| 943 |
static NoCFIValue *get(GlobalValue *GV); |
| 944 |
|
| 945 |
|
| 946 |
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 947 |
|
| 948 |
GlobalValue *getGlobalValue() const { |
| 949 |
return cast<GlobalValue>(Op<0>().get()); |
| 950 |
} |
| 951 |
|
| 952 |
|
| 953 |
static bool classof(const Value *V) { |
| 954 |
return V->getValueID() == NoCFIValueVal; |
| 955 |
} |
| 956 |
}; |
| 957 |
|
| 958 |
template <> |
| 959 |
struct OperandTraits<NoCFIValue> : public FixedNumOperandTraits<NoCFIValue, 1> { |
| 960 |
}; |
| 961 |
|
| 962 |
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(NoCFIValue, Value) |
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
class ConstantExpr : public Constant { |
| 972 |
friend struct ConstantExprKeyType; |
| 973 |
friend class Constant; |
| 974 |
|
| 975 |
void destroyConstantImpl(); |
| 976 |
Value *handleOperandChangeImpl(Value *From, Value *To); |
| 977 |
|
| 978 |
protected: |
| 979 |
ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps) |
| 980 |
: Constant(ty, ConstantExprVal, Ops, NumOps) { |
| 981 |
|
| 982 |
setValueSubclassData(Opcode); |
| 983 |
} |
| 984 |
|
| 985 |
~ConstantExpr() = default; |
| 986 |
|
| 987 |
public: |
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
static Constant *getAlignOf(Type *Ty); |
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
static Constant *getSizeOf(Type *Ty); |
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
static Constant *getOffsetOf(StructType *STy, unsigned FieldNo); |
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
static Constant *getOffsetOf(Type *Ty, Constant *FieldNo); |
| 1012 |
|
| 1013 |
static Constant *getNeg(Constant *C, bool HasNUW = false, |
| 1014 |
bool HasNSW = false); |
| 1015 |
static Constant *getFNeg(Constant *C); |
| 1016 |
static Constant *getNot(Constant *C); |
| 1017 |
static Constant *getAdd(Constant *C1, Constant *C2, bool HasNUW = false, |
| 1018 |
bool HasNSW = false); |
| 1019 |
static Constant *getFAdd(Constant *C1, Constant *C2); |
| 1020 |
static Constant *getSub(Constant *C1, Constant *C2, bool HasNUW = false, |
| 1021 |
bool HasNSW = false); |
| 1022 |
static Constant *getFSub(Constant *C1, Constant *C2); |
| 1023 |
static Constant *getMul(Constant *C1, Constant *C2, bool HasNUW = false, |
| 1024 |
bool HasNSW = false); |
| 1025 |
static Constant *getFMul(Constant *C1, Constant *C2); |
| 1026 |
static Constant *getUDiv(Constant *C1, Constant *C2, bool isExact = false); |
| 1027 |
static Constant *getSDiv(Constant *C1, Constant *C2, bool isExact = false); |
| 1028 |
static Constant *getFDiv(Constant *C1, Constant *C2); |
| 1029 |
static Constant *getURem(Constant *C1, Constant *C2); |
| 1030 |
static Constant *getSRem(Constant *C1, Constant *C2); |
| 1031 |
static Constant *getFRem(Constant *C1, Constant *C2); |
| 1032 |
static Constant *getAnd(Constant *C1, Constant *C2); |
| 1033 |
static Constant *getOr(Constant *C1, Constant *C2); |
| 1034 |
static Constant *getXor(Constant *C1, Constant *C2); |
| 1035 |
static Constant *getUMin(Constant *C1, Constant *C2); |
| 1036 |
static Constant *getShl(Constant *C1, Constant *C2, bool HasNUW = false, |
| 1037 |
bool HasNSW = false); |
| 1038 |
static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false); |
| 1039 |
static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false); |
| 1040 |
static Constant *getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced = false); |
| 1041 |
static Constant *getSExt(Constant *C, Type *Ty, bool OnlyIfReduced = false); |
| 1042 |
static Constant *getZExt(Constant *C, Type *Ty, bool OnlyIfReduced = false); |
| 1043 |
static Constant *getFPTrunc(Constant *C, Type *Ty, |
| 1044 |
bool OnlyIfReduced = false); |
| 1045 |
static Constant *getFPExtend(Constant *C, Type *Ty, |
| 1046 |
bool OnlyIfReduced = false); |
| 1047 |
static Constant *getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false); |
| 1048 |
static Constant *getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false); |
| 1049 |
static Constant *getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced = false); |
| 1050 |
static Constant *getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced = false); |
| 1051 |
static Constant *getPtrToInt(Constant *C, Type *Ty, |
| 1052 |
bool OnlyIfReduced = false); |
| 1053 |
static Constant *getIntToPtr(Constant *C, Type *Ty, |
| 1054 |
bool OnlyIfReduced = false); |
| 1055 |
static Constant *getBitCast(Constant *C, Type *Ty, |
| 1056 |
bool OnlyIfReduced = false); |
| 1057 |
static Constant *getAddrSpaceCast(Constant *C, Type *Ty, |
| 1058 |
bool OnlyIfReduced = false); |
| 1059 |
|
| 1060 |
static Constant *getNSWNeg(Constant *C) { return getNeg(C, false, true); } |
| 1061 |
static Constant *getNUWNeg(Constant *C) { return getNeg(C, true, false); } |
| 1062 |
|
| 1063 |
static Constant *getNSWAdd(Constant *C1, Constant *C2) { |
| 1064 |
return getAdd(C1, C2, false, true); |
| 1065 |
} |
| 1066 |
|
| 1067 |
static Constant *getNUWAdd(Constant *C1, Constant *C2) { |
| 1068 |
return getAdd(C1, C2, true, false); |
| 1069 |
} |
| 1070 |
|
| 1071 |
static Constant *getNSWSub(Constant *C1, Constant *C2) { |
| 1072 |
return getSub(C1, C2, false, true); |
| 1073 |
} |
| 1074 |
|
| 1075 |
static Constant *getNUWSub(Constant *C1, Constant *C2) { |
| 1076 |
return getSub(C1, C2, true, false); |
| 1077 |
} |
| 1078 |
|
| 1079 |
static Constant *getNSWMul(Constant *C1, Constant *C2) { |
| 1080 |
return getMul(C1, C2, false, true); |
| 1081 |
} |
| 1082 |
|
| 1083 |
static Constant *getNUWMul(Constant *C1, Constant *C2) { |
| 1084 |
return getMul(C1, C2, true, false); |
| 1085 |
} |
| 1086 |
|
| 1087 |
static Constant *getNSWShl(Constant *C1, Constant *C2) { |
| 1088 |
return getShl(C1, C2, false, true); |
| 1089 |
} |
| 1090 |
|
| 1091 |
static Constant *getNUWShl(Constant *C1, Constant *C2) { |
| 1092 |
return getShl(C1, C2, true, false); |
| 1093 |
} |
| 1094 |
|
| 1095 |
static Constant *getExactSDiv(Constant *C1, Constant *C2) { |
| 1096 |
return getSDiv(C1, C2, true); |
| 1097 |
} |
| 1098 |
|
| 1099 |
static Constant *getExactUDiv(Constant *C1, Constant *C2) { |
| 1100 |
return getUDiv(C1, C2, true); |
| 1101 |
} |
| 1102 |
|
| 1103 |
static Constant *getExactAShr(Constant *C1, Constant *C2) { |
| 1104 |
return getAShr(C1, C2, true); |
| 1105 |
} |
| 1106 |
|
| 1107 |
static Constant *getExactLShr(Constant *C1, Constant *C2) { |
| 1108 |
return getLShr(C1, C2, true); |
| 1109 |
} |
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
static Constant *getExactLogBase2(Constant *C); |
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
static Constant *getBinOpIdentity(unsigned Opcode, Type *Ty, |
| 1125 |
bool AllowRHSConstant = false); |
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
static Constant *getBinOpAbsorber(unsigned Opcode, Type *Ty); |
| 1132 |
|
| 1133 |
|
| 1134 |
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); |
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
static Constant *getCast(unsigned ops, Constant *C, Type *Ty, |
| 1143 |
bool OnlyIfReduced = false); |
| 1144 |
|
| 1145 |
|
| 1146 |
static Constant * |
| 1147 |
getZExtOrBitCast(Constant *C, |
| 1148 |
Type *Ty |
| 1149 |
); |
| 1150 |
|
| 1151 |
|
| 1152 |
static Constant * |
| 1153 |
getSExtOrBitCast(Constant *C, |
| 1154 |
Type *Ty |
| 1155 |
); |
| 1156 |
|
| 1157 |
|
| 1158 |
static Constant * |
| 1159 |
getTruncOrBitCast(Constant *C, |
| 1160 |
Type *Ty |
| 1161 |
); |
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
static Constant * |
| 1166 |
getPointerCast(Constant *C, |
| 1167 |
Type *Ty |
| 1168 |
); |
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
static Constant *getPointerBitCastOrAddrSpaceCast( |
| 1173 |
Constant *C, |
| 1174 |
Type *Ty |
| 1175 |
); |
| 1176 |
|
| 1177 |
|
| 1178 |
static Constant * |
| 1179 |
getIntegerCast(Constant *C, |
| 1180 |
Type *Ty, |
| 1181 |
bool IsSigned |
| 1182 |
); |
| 1183 |
|
| 1184 |
|
| 1185 |
static Constant *getFPCast(Constant *C, |
| 1186 |
Type *Ty |
| 1187 |
); |
| 1188 |
|
| 1189 |
|
| 1190 |
bool isCast() const; |
| 1191 |
|
| 1192 |
|
| 1193 |
bool isCompare() const; |
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
bool hasIndices() const; |
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
static Constant *getSelect(Constant *C, Constant *V1, Constant *V2, |
| 1203 |
Type *OnlyIfReducedTy = nullptr); |
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
static Constant *get(unsigned Opcode, Constant *C1, unsigned Flags = 0, |
| 1210 |
Type *OnlyIfReducedTy = nullptr); |
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
static Constant *get(unsigned Opcode, Constant *C1, Constant *C2, |
| 1217 |
unsigned Flags = 0, Type *OnlyIfReducedTy = nullptr); |
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2, |
| 1223 |
bool OnlyIfReduced = false); |
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS, |
| 1229 |
bool OnlyIfReduced = false); |
| 1230 |
static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, |
| 1231 |
bool OnlyIfReduced = false); |
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
static Constant *getGetElementPtr(Type *Ty, Constant *C, |
| 1239 |
ArrayRef<Constant *> IdxList, |
| 1240 |
bool InBounds = false, |
| 1241 |
Optional<unsigned> InRangeIndex = None, |
| 1242 |
Type *OnlyIfReducedTy = nullptr) { |
| 1243 |
return getGetElementPtr( |
| 1244 |
Ty, C, makeArrayRef((Value *const *)IdxList.data(), IdxList.size()), |
| 1245 |
InBounds, InRangeIndex, OnlyIfReducedTy); |
| 1246 |
} |
| 1247 |
static Constant *getGetElementPtr(Type *Ty, Constant *C, Constant *Idx, |
| 1248 |
bool InBounds = false, |
| 1249 |
Optional<unsigned> InRangeIndex = None, |
| 1250 |
Type *OnlyIfReducedTy = nullptr) { |
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
return getGetElementPtr(Ty, C, cast<Value>(Idx), InBounds, InRangeIndex, |
| 1255 |
OnlyIfReducedTy); |
| 1256 |
} |
| 1257 |
static Constant *getGetElementPtr(Type *Ty, Constant *C, |
| 1258 |
ArrayRef<Value *> IdxList, |
| 1259 |
bool InBounds = false, |
| 1260 |
Optional<unsigned> InRangeIndex = None, |
| 1261 |
Type *OnlyIfReducedTy = nullptr); |
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
static Constant *getInBoundsGetElementPtr(Type *Ty, Constant *C, |
| 1266 |
ArrayRef<Constant *> IdxList) { |
| 1267 |
return getGetElementPtr(Ty, C, IdxList, true); |
| 1268 |
} |
| 1269 |
static Constant *getInBoundsGetElementPtr(Type *Ty, Constant *C, |
| 1270 |
Constant *Idx) { |
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
return getGetElementPtr(Ty, C, Idx, true); |
| 1275 |
} |
| 1276 |
static Constant *getInBoundsGetElementPtr(Type *Ty, Constant *C, |
| 1277 |
ArrayRef<Value *> IdxList) { |
| 1278 |
return getGetElementPtr(Ty, C, IdxList, true); |
| 1279 |
} |
| 1280 |
|
| 1281 |
static Constant *getExtractElement(Constant *Vec, Constant *Idx, |
| 1282 |
Type *OnlyIfReducedTy = nullptr); |
| 1283 |
static Constant *getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, |
| 1284 |
Type *OnlyIfReducedTy = nullptr); |
| 1285 |
static Constant *getShuffleVector(Constant *V1, Constant *V2, |
| 1286 |
ArrayRef<int> Mask, |
| 1287 |
Type *OnlyIfReducedTy = nullptr); |
| 1288 |
static Constant *getExtractValue(Constant *Agg, ArrayRef<unsigned> Idxs, |
| 1289 |
Type *OnlyIfReducedTy = nullptr); |
| 1290 |
static Constant *getInsertValue(Constant *Agg, Constant *Val, |
| 1291 |
ArrayRef<unsigned> Idxs, |
| 1292 |
Type *OnlyIfReducedTy = nullptr); |
| 1293 |
|
| 1294 |
|
| 1295 |
unsigned getOpcode() const { return getSubclassDataFromValue(); } |
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
unsigned getPredicate() const; |
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
ArrayRef<unsigned> getIndices() const; |
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
ArrayRef<int> getShuffleMask() const; |
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
Constant *getShuffleMaskForBitcode() const; |
| 1314 |
|
| 1315 |
|
| 1316 |
const char *getOpcodeName() const; |
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
Constant *getWithOperands(ArrayRef<Constant *> Ops) const { |
| 1322 |
return getWithOperands(Ops, getType()); |
| 1323 |
} |
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
Constant *getWithOperands(ArrayRef<Constant *> Ops, Type *Ty, |
| 1335 |
bool OnlyIfReduced = false, |
| 1336 |
Type *SrcTy = nullptr) const; |
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
Instruction *getAsInstruction(Instruction *InsertBefore = nullptr) const; |
| 1347 |
|
| 1348 |
|
| 1349 |
static bool classof(const Value *V) { |
| 1350 |
return V->getValueID() == ConstantExprVal; |
| 1351 |
} |
| 1352 |
|
| 1353 |
private: |
| 1354 |
|
| 1355 |
|
| 1356 |
void setValueSubclassData(unsigned short D) { |
| 1357 |
Value::setValueSubclassData(D); |
| 1358 |
} |
| 1359 |
}; |
| 1360 |
|
| 1361 |
template <> |
| 1362 |
struct OperandTraits<ConstantExpr> |
| 1363 |
: public VariadicOperandTraits<ConstantExpr, 1> {}; |
| 1364 |
|
| 1365 |
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant) |
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
class UndefValue : public ConstantData { |
| 1378 |
friend class Constant; |
| 1379 |
|
| 1380 |
explicit UndefValue(Type *T) : ConstantData(T, UndefValueVal) {} |
| 1381 |
|
| 1382 |
void destroyConstantImpl(); |
| 1383 |
|
| 1384 |
protected: |
| 1385 |
explicit UndefValue(Type *T, ValueTy vty) : ConstantData(T, vty) {} |
| 1386 |
|
| 1387 |
public: |
| 1388 |
UndefValue(const UndefValue &) = delete; |
| 1389 |
|
| 1390 |
|
| 1391 |
static UndefValue *get(Type *T); |
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
UndefValue *getSequentialElement() const; |
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
UndefValue *getStructElement(unsigned Elt) const; |
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
UndefValue *getElementValue(Constant *C) const; |
| 1404 |
|
| 1405 |
|
| 1406 |
UndefValue *getElementValue(unsigned Idx) const; |
| 1407 |
|
| 1408 |
|
| 1409 |
unsigned getNumElements() const; |
| 1410 |
|
| 1411 |
|
| 1412 |
static bool classof(const Value *V) { |
| 1413 |
return V->getValueID() == UndefValueVal || |
| 1414 |
V->getValueID() == PoisonValueVal; |
| 1415 |
} |
| 1416 |
}; |
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
class PoisonValue final : public UndefValue { |
| 1426 |
friend class Constant; |
| 1427 |
|
| 1428 |
explicit PoisonValue(Type *T) : UndefValue(T, PoisonValueVal) {} |
| 1429 |
|
| 1430 |
void destroyConstantImpl(); |
| 1431 |
|
| 1432 |
public: |
| 1433 |
PoisonValue(const PoisonValue &) = delete; |
| 1434 |
|
| 1435 |
|
| 1436 |
static PoisonValue *get(Type *T); |
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
PoisonValue *getSequentialElement() const; |
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
PoisonValue *getStructElement(unsigned Elt) const; |
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
PoisonValue *getElementValue(Constant *C) const; |
| 1449 |
|
| 1450 |
|
| 1451 |
PoisonValue *getElementValue(unsigned Idx) const; |
| 1452 |
|
| 1453 |
|
| 1454 |
static bool classof(const Value *V) { |
| 1455 |
return V->getValueID() == PoisonValueVal; |
| 1456 |
} |
| 1457 |
}; |
| 1458 |
|
| 1459 |
} |
| 1460 |
|
| 1461 |
#endif |