| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#ifndef LLVM_CODEGEN_MACHINEOPERAND_H |
| 14 |
#define LLVM_CODEGEN_MACHINEOPERAND_H |
| 15 |
|
| 16 |
#include "llvm/ADT/DenseMap.h" |
| 17 |
#include "llvm/CodeGen/Register.h" |
| 18 |
#include "llvm/IR/Intrinsics.h" |
| 19 |
#include "llvm/Support/DataTypes.h" |
| 20 |
#include "llvm/Support/LowLevelTypeImpl.h" |
| 21 |
#include <cassert> |
| 22 |
|
| 23 |
namespace llvm { |
| 24 |
|
| 25 |
class BlockAddress; |
| 26 |
class Constant; |
| 27 |
class ConstantFP; |
| 28 |
class ConstantInt; |
| 29 |
class GlobalValue; |
| 30 |
class MachineBasicBlock; |
| 31 |
class MachineInstr; |
| 32 |
class MachineRegisterInfo; |
| 33 |
class MCCFIInstruction; |
| 34 |
class MDNode; |
| 35 |
class ModuleSlotTracker; |
| 36 |
class TargetIntrinsicInfo; |
| 37 |
class TargetRegisterInfo; |
| 38 |
class hash_code; |
| 39 |
class raw_ostream; |
| 40 |
class MCSymbol; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
class MachineOperand { |
| 50 |
public: |
| 51 |
enum MachineOperandType : unsigned char { |
| 52 |
MO_Register, |
| 53 |
MO_Immediate, |
| 54 |
MO_CImmediate, |
| 55 |
MO_FPImmediate, |
| 56 |
MO_MachineBasicBlock, |
| 57 |
MO_FrameIndex, |
| 58 |
MO_ConstantPoolIndex, |
| 59 |
MO_TargetIndex, |
| 60 |
MO_JumpTableIndex, |
| 61 |
MO_ExternalSymbol, |
| 62 |
MO_GlobalAddress, |
| 63 |
MO_BlockAddress, |
| 64 |
MO_RegisterMask, |
| 65 |
MO_RegisterLiveOut, |
| 66 |
MO_Metadata, |
| 67 |
MO_MCSymbol, |
| 68 |
MO_CFIIndex, |
| 69 |
MO_IntrinsicID, |
| 70 |
MO_Predicate, |
| 71 |
MO_ShuffleMask, |
| 72 |
MO_Last = MO_ShuffleMask |
| 73 |
}; |
| 74 |
|
| 75 |
private: |
| 76 |
|
| 77 |
|
| 78 |
unsigned OpKind : 8; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
unsigned SubReg_TargetFlags : 12; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
unsigned TiedTo : 4; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
unsigned IsDef : 1; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
unsigned IsImp : 1; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
unsigned IsDeadOrKill : 1; |
| 111 |
|
| 112 |
|
| 113 |
unsigned IsRenamable : 1; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
unsigned IsUndef : 1; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
unsigned IsInternalRead : 1; |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
unsigned IsEarlyClobber : 1; |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
unsigned IsDebug : 1; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
union { |
| 159 |
unsigned RegNo; |
| 160 |
unsigned OffsetLo; |
| 161 |
} SmallContents; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
MachineInstr *ParentMI = nullptr; |
| 166 |
|
| 167 |
|
| 168 |
union ContentsUnion { |
| 169 |
ContentsUnion() {} |
| 170 |
MachineBasicBlock *MBB; |
| 171 |
const ConstantFP *CFP; |
| 172 |
const ConstantInt *CI; |
| 173 |
int64_t ImmVal; |
| 174 |
const uint32_t *RegMask; |
| 175 |
const MDNode *MD; |
| 176 |
MCSymbol *Sym; |
| 177 |
unsigned CFIIndex; |
| 178 |
Intrinsic::ID IntrinsicID; |
| 179 |
unsigned Pred; |
| 180 |
ArrayRef<int> ShuffleMask; |
| 181 |
|
| 182 |
struct { |
| 183 |
|
| 184 |
MachineOperand *Prev; |
| 185 |
MachineOperand *Next; |
| 186 |
} Reg; |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
struct { |
| 191 |
union { |
| 192 |
int Index; |
| 193 |
const char *SymbolName; |
| 194 |
const GlobalValue *GV; |
| 195 |
const BlockAddress *BA; |
| 196 |
} Val; |
| 197 |
|
| 198 |
int OffsetHi; |
| 199 |
} OffsetedInfo; |
| 200 |
} Contents; |
| 201 |
|
| 202 |
explicit MachineOperand(MachineOperandType K) |
| 203 |
: OpKind(K), SubReg_TargetFlags(0) { |
| 204 |
|
| 205 |
static_assert(alignof(MachineOperand) <= alignof(int64_t), |
| 206 |
"MachineOperand shouldn't be more than 8 byte aligned"); |
| 207 |
static_assert(sizeof(Contents) <= 2 * sizeof(void *), |
| 208 |
"Contents should be at most two pointers"); |
| 209 |
static_assert(sizeof(MachineOperand) <= |
| 210 |
alignTo<alignof(int64_t)>(2 * sizeof(unsigned) + |
| 211 |
3 * sizeof(void *)), |
| 212 |
"MachineOperand too big. Should be Kind, SmallContents, " |
| 213 |
"ParentMI, and Contents"); |
| 214 |
} |
| 215 |
|
| 216 |
public: |
| 217 |
|
| 218 |
|
| 219 |
MachineOperandType getType() const { return (MachineOperandType)OpKind; } |
| 220 |
|
| 221 |
unsigned getTargetFlags() const { |
| 222 |
return isReg() ? 0 : SubReg_TargetFlags; |
| 223 |
} |
| 224 |
void setTargetFlags(unsigned F) { |
| 225 |
assert(!isReg() && "Register operands can't have target flags"); |
| 226 |
SubReg_TargetFlags = F; |
| 227 |
assert(SubReg_TargetFlags == F && "Target flags out of range"); |
| 228 |
} |
| 229 |
void addTargetFlag(unsigned F) { |
| 230 |
assert(!isReg() && "Register operands can't have target flags"); |
| 231 |
SubReg_TargetFlags |= F; |
| 232 |
assert((SubReg_TargetFlags & F) && "Target flags out of range"); |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
MachineInstr *getParent() { return ParentMI; } |
| 239 |
const MachineInstr *getParent() const { return ParentMI; } |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
void clearParent() { ParentMI = nullptr; } |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
static void printSubRegIdx(raw_ostream &OS, uint64_t Index, |
| 256 |
const TargetRegisterInfo *TRI); |
| 257 |
|
| 258 |
|
| 259 |
static void printTargetFlags(raw_ostream& OS, const MachineOperand &Op); |
| 260 |
|
| 261 |
|
| 262 |
static void printSymbol(raw_ostream &OS, MCSymbol &Sym); |
| 263 |
|
| 264 |
|
| 265 |
static void printStackObjectReference(raw_ostream &OS, unsigned FrameIndex, |
| 266 |
bool IsFixed, StringRef Name); |
| 267 |
|
| 268 |
|
| 269 |
static void printOperandOffset(raw_ostream &OS, int64_t Offset); |
| 270 |
|
| 271 |
|
| 272 |
static void printIRSlotNumber(raw_ostream &OS, int Slot); |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
void print(raw_ostream &os, const TargetRegisterInfo *TRI = nullptr, |
| 279 |
const TargetIntrinsicInfo *IntrinsicInfo = nullptr) const; |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
void print(raw_ostream &os, ModuleSlotTracker &MST, LLT TypeToPrint, |
| 303 |
Optional<unsigned> OpIdx, bool PrintDef, bool IsStandalone, |
| 304 |
bool ShouldPrintRegisterTies, unsigned TiedOperandIdx, |
| 305 |
const TargetRegisterInfo *TRI, |
| 306 |
const TargetIntrinsicInfo *IntrinsicInfo) const; |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
void print(raw_ostream &os, LLT TypeToPrint, |
| 311 |
const TargetRegisterInfo *TRI = nullptr, |
| 312 |
const TargetIntrinsicInfo *IntrinsicInfo = nullptr) const; |
| 313 |
|
| 314 |
void dump() const; |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
bool isReg() const { return OpKind == MO_Register; } |
| 322 |
|
| 323 |
bool isImm() const { return OpKind == MO_Immediate; } |
| 324 |
|
| 325 |
bool isCImm() const { return OpKind == MO_CImmediate; } |
| 326 |
|
| 327 |
bool isFPImm() const { return OpKind == MO_FPImmediate; } |
| 328 |
|
| 329 |
bool isMBB() const { return OpKind == MO_MachineBasicBlock; } |
| 330 |
|
| 331 |
bool isFI() const { return OpKind == MO_FrameIndex; } |
| 332 |
|
| 333 |
bool isCPI() const { return OpKind == MO_ConstantPoolIndex; } |
| 334 |
|
| 335 |
bool isTargetIndex() const { return OpKind == MO_TargetIndex; } |
| 336 |
|
| 337 |
bool isJTI() const { return OpKind == MO_JumpTableIndex; } |
| 338 |
|
| 339 |
bool isGlobal() const { return OpKind == MO_GlobalAddress; } |
| 340 |
|
| 341 |
bool isSymbol() const { return OpKind == MO_ExternalSymbol; } |
| 342 |
|
| 343 |
bool isBlockAddress() const { return OpKind == MO_BlockAddress; } |
| 344 |
|
| 345 |
bool isRegMask() const { return OpKind == MO_RegisterMask; } |
| 346 |
|
| 347 |
bool isRegLiveOut() const { return OpKind == MO_RegisterLiveOut; } |
| 348 |
|
| 349 |
bool isMetadata() const { return OpKind == MO_Metadata; } |
| 350 |
bool isMCSymbol() const { return OpKind == MO_MCSymbol; } |
| 351 |
bool isCFIIndex() const { return OpKind == MO_CFIIndex; } |
| 352 |
bool isIntrinsicID() const { return OpKind == MO_IntrinsicID; } |
| 353 |
bool isPredicate() const { return OpKind == MO_Predicate; } |
| 354 |
bool isShuffleMask() const { return OpKind == MO_ShuffleMask; } |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
Register getReg() const { |
| 361 |
assert(isReg() && "This is not a register operand!"); |
| 362 |
return Register(SmallContents.RegNo); |
| 363 |
} |
| 364 |
|
| 365 |
unsigned getSubReg() const { |
| 366 |
assert(isReg() && "Wrong MachineOperand accessor"); |
| 367 |
return SubReg_TargetFlags; |
| 368 |
} |
| 369 |
|
| 370 |
bool isUse() const { |
| 371 |
assert(isReg() && "Wrong MachineOperand accessor"); |
| 372 |
return !IsDef; |
| 373 |
} |
| 374 |
|
| 375 |
bool isDef() const { |
| 376 |
assert(isReg() && "Wrong MachineOperand accessor"); |
| 377 |
return IsDef; |
| 378 |
} |
| 379 |
|
| 380 |
bool isImplicit() const { |
| 381 |
assert(isReg() && "Wrong MachineOperand accessor"); |
| 382 |
return IsImp; |
| 383 |
} |
| 384 |
|
| 385 |
bool isDead() const { |
| 386 |
assert(isReg() && "Wrong MachineOperand accessor"); |
| 387 |
return IsDeadOrKill & IsDef; |
| 388 |
} |
| 389 |
|
| 390 |
bool isKill() const { |
| 391 |
assert(isReg() && "Wrong MachineOperand accessor"); |
| 392 |
return IsDeadOrKill & !IsDef; |
| 393 |
} |
| 394 |
|
| 395 |
bool isUndef() const { |
| 396 |
assert(isReg() && "Wrong MachineOperand accessor"); |
| 397 |
return IsUndef; |
| 398 |
} |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
e. |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
bool isRenamable() const; |
| 430 |
|
| 431 |
bool isInternalRead() const { |
| 432 |
assert(isReg() && "Wrong MachineOperand accessor"); |
| 433 |
return IsInternalRead; |
| 434 |
} |
| 435 |
|
| 436 |
bool isEarlyClobber() const { |
| 437 |
assert(isReg() && "Wrong MachineOperand accessor"); |
| 438 |
return IsEarlyClobber; |
| 439 |
} |
| 440 |
|
| 441 |
bool isTied() const { |
| 442 |
assert(isReg() && "Wrong MachineOperand accessor"); |
| 443 |
return TiedTo; |
| 444 |
} |
| 445 |
|
| 446 |
bool isDebug() const { |
| 447 |
assert(isReg() && "Wrong MachineOperand accessor"); |
| 448 |
return IsDebug; |
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
bool readsReg() const { |
| 459 |
assert(isReg() && "Wrong MachineOperand accessor"); |
| 460 |
return !isUndef() && !isInternalRead() && (isUse() || getSubReg()); |
| 461 |
} |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
void setReg(Register Reg); |
| 470 |
|
| 471 |
void setSubReg(unsigned subReg) { |
| 472 |
assert(isReg() && "Wrong MachineOperand mutator"); |
| 473 |
SubReg_TargetFlags = subReg; |
| 474 |
assert(SubReg_TargetFlags == subReg && "SubReg out of range"); |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
void substVirtReg(Register Reg, unsigned SubIdx, const TargetRegisterInfo&); |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
void substPhysReg(MCRegister Reg, const TargetRegisterInfo&); |
| 489 |
|
| 490 |
void setIsUse(bool Val = true) { setIsDef(!Val); } |
| 491 |
|
| 492 |
|
| 493 |
void setIsDef(bool Val = true); |
| 494 |
|
| 495 |
void setImplicit(bool Val = true) { |
| 496 |
assert(isReg() && "Wrong MachineOperand mutator"); |
| 497 |
IsImp = Val; |
| 498 |
} |
| 499 |
|
| 500 |
void setIsKill(bool Val = true) { |
| 501 |
assert(isReg() && !IsDef && "Wrong MachineOperand mutator"); |
| 502 |
assert((!Val || !isDebug()) && "Marking a debug operation as kill"); |
| 503 |
IsDeadOrKill = Val; |
| 504 |
} |
| 505 |
|
| 506 |
void setIsDead(bool Val = true) { |
| 507 |
assert(isReg() && IsDef && "Wrong MachineOperand mutator"); |
| 508 |
IsDeadOrKill = Val; |
| 509 |
} |
| 510 |
|
| 511 |
void setIsUndef(bool Val = true) { |
| 512 |
assert(isReg() && "Wrong MachineOperand mutator"); |
| 513 |
IsUndef = Val; |
| 514 |
} |
| 515 |
|
| 516 |
void setIsRenamable(bool Val = true); |
| 517 |
|
| 518 |
void setIsInternalRead(bool Val = true) { |
| 519 |
assert(isReg() && "Wrong MachineOperand mutator"); |
| 520 |
IsInternalRead = Val; |
| 521 |
} |
| 522 |
|
| 523 |
void setIsEarlyClobber(bool Val = true) { |
| 524 |
assert(isReg() && IsDef && "Wrong MachineOperand mutator"); |
| 525 |
IsEarlyClobber = Val; |
| 526 |
} |
| 527 |
|
| 528 |
void setIsDebug(bool Val = true) { |
| 529 |
assert(isReg() && !IsDef && "Wrong MachineOperand mutator"); |
| 530 |
IsDebug = Val; |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
int64_t getImm() const { |
| 538 |
assert(isImm() && "Wrong MachineOperand accessor"); |
| 539 |
return Contents.ImmVal; |
| 540 |
} |
| 541 |
|
| 542 |
const ConstantInt *getCImm() const { |
| 543 |
assert(isCImm() && "Wrong MachineOperand accessor"); |
| 544 |
return Contents.CI; |
| 545 |
} |
| 546 |
|
| 547 |
const ConstantFP *getFPImm() const { |
| 548 |
assert(isFPImm() && "Wrong MachineOperand accessor"); |
| 549 |
return Contents.CFP; |
| 550 |
} |
| 551 |
|
| 552 |
MachineBasicBlock *getMBB() const { |
| 553 |
assert(isMBB() && "Wrong MachineOperand accessor"); |
| 554 |
return Contents.MBB; |
| 555 |
} |
| 556 |
|
| 557 |
int getIndex() const { |
| 558 |
assert((isFI() || isCPI() || isTargetIndex() || isJTI()) && |
| 559 |
"Wrong MachineOperand accessor"); |
| 560 |
return Contents.OffsetedInfo.Val.Index; |
| 561 |
} |
| 562 |
|
| 563 |
const GlobalValue *getGlobal() const { |
| 564 |
assert(isGlobal() && "Wrong MachineOperand accessor"); |
| 565 |
return Contents.OffsetedInfo.Val.GV; |
| 566 |
} |
| 567 |
|
| 568 |
const BlockAddress *getBlockAddress() const { |
| 569 |
assert(isBlockAddress() && "Wrong MachineOperand accessor"); |
| 570 |
return Contents.OffsetedInfo.Val.BA; |
| 571 |
} |
| 572 |
|
| 573 |
MCSymbol *getMCSymbol() const { |
| 574 |
assert(isMCSymbol() && "Wrong MachineOperand accessor"); |
| 575 |
return Contents.Sym; |
| 576 |
} |
| 577 |
|
| 578 |
unsigned getCFIIndex() const { |
| 579 |
assert(isCFIIndex() && "Wrong MachineOperand accessor"); |
| 580 |
return Contents.CFIIndex; |
| 581 |
} |
| 582 |
|
| 583 |
Intrinsic::ID getIntrinsicID() const { |
| 584 |
assert(isIntrinsicID() && "Wrong MachineOperand accessor"); |
| 585 |
return Contents.IntrinsicID; |
| 586 |
} |
| 587 |
|
| 588 |
unsigned getPredicate() const { |
| 589 |
assert(isPredicate() && "Wrong MachineOperand accessor"); |
| 590 |
return Contents.Pred; |
| 591 |
} |
| 592 |
|
| 593 |
ArrayRef<int> getShuffleMask() const { |
| 594 |
assert(isShuffleMask() && "Wrong MachineOperand accessor"); |
| 595 |
return Contents.ShuffleMask; |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
int64_t getOffset() const { |
| 601 |
assert((isGlobal() || isSymbol() || isMCSymbol() || isCPI() || |
| 602 |
isTargetIndex() || isBlockAddress()) && |
| 603 |
"Wrong MachineOperand accessor"); |
| 604 |
return int64_t(uint64_t(Contents.OffsetedInfo.OffsetHi) << 32) | |
| 605 |
SmallContents.OffsetLo; |
| 606 |
} |
| 607 |
|
| 608 |
const char *getSymbolName() const { |
| 609 |
assert(isSymbol() && "Wrong MachineOperand accessor"); |
| 610 |
return Contents.OffsetedInfo.Val.SymbolName; |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg) { |
| 618 |
|
| 619 |
assert(PhysReg < (1u << 30) && "Not a physical register"); |
| 620 |
return !(RegMask[PhysReg / 32] & (1u << PhysReg % 32)); |
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
bool clobbersPhysReg(MCRegister PhysReg) const { |
| 625 |
return clobbersPhysReg(getRegMask(), PhysReg); |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
const uint32_t *getRegMask() const { |
| 631 |
assert(isRegMask() && "Wrong MachineOperand accessor"); |
| 632 |
return Contents.RegMask; |
| 633 |
} |
| 634 |
|
| 635 |
|
| 636 |
static unsigned getRegMaskSize(unsigned NumRegs) { |
| 637 |
return (NumRegs + 31) / 32; |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
const uint32_t *getRegLiveOut() const { |
| 642 |
assert(isRegLiveOut() && "Wrong MachineOperand accessor"); |
| 643 |
return Contents.RegMask; |
| 644 |
} |
| 645 |
|
| 646 |
const MDNode *getMetadata() const { |
| 647 |
assert(isMetadata() && "Wrong MachineOperand accessor"); |
| 648 |
return Contents.MD; |
| 649 |
} |
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
void setImm(int64_t immVal) { |
| 656 |
assert(isImm() && "Wrong MachineOperand mutator"); |
| 657 |
Contents.ImmVal = immVal; |
| 658 |
} |
| 659 |
|
| 660 |
void setCImm(const ConstantInt *CI) { |
| 661 |
assert(isCImm() && "Wrong MachineOperand mutator"); |
| 662 |
Contents.CI = CI; |
| 663 |
} |
| 664 |
|
| 665 |
void setFPImm(const ConstantFP *CFP) { |
| 666 |
assert(isFPImm() && "Wrong MachineOperand mutator"); |
| 667 |
Contents.CFP = CFP; |
| 668 |
} |
| 669 |
|
| 670 |
void setOffset(int64_t Offset) { |
| 671 |
assert((isGlobal() || isSymbol() || isMCSymbol() || isCPI() || |
| 672 |
isTargetIndex() || isBlockAddress()) && |
| 673 |
"Wrong MachineOperand mutator"); |
| 674 |
SmallContents.OffsetLo = unsigned(Offset); |
| 675 |
Contents.OffsetedInfo.OffsetHi = int(Offset >> 32); |
| 676 |
} |
| 677 |
|
| 678 |
void setIndex(int Idx) { |
| 679 |
assert((isFI() || isCPI() || isTargetIndex() || isJTI()) && |
| 680 |
"Wrong MachineOperand mutator"); |
| 681 |
Contents.OffsetedInfo.Val.Index = Idx; |
| 682 |
} |
| 683 |
|
| 684 |
void setMetadata(const MDNode *MD) { |
| 685 |
assert(isMetadata() && "Wrong MachineOperand mutator"); |
| 686 |
Contents.MD = MD; |
| 687 |
} |
| 688 |
|
| 689 |
void setMBB(MachineBasicBlock *MBB) { |
| 690 |
assert(isMBB() && "Wrong MachineOperand mutator"); |
| 691 |
Contents.MBB = MBB; |
| 692 |
} |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
void setRegMask(const uint32_t *RegMaskPtr) { |
| 699 |
assert(isRegMask() && "Wrong MachineOperand mutator"); |
| 700 |
Contents.RegMask = RegMaskPtr; |
| 701 |
} |
| 702 |
|
| 703 |
void setIntrinsicID(Intrinsic::ID IID) { |
| 704 |
assert(isIntrinsicID() && "Wrong MachineOperand mutator"); |
| 705 |
Contents.IntrinsicID = IID; |
| 706 |
} |
| 707 |
|
| 708 |
void setPredicate(unsigned Predicate) { |
| 709 |
assert(isPredicate() && "Wrong MachineOperand mutator"); |
| 710 |
Contents.Pred = Predicate; |
| 711 |
} |
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
bool isIdenticalTo(const MachineOperand &Other) const; |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
friend hash_code hash_value(const MachineOperand &MO); |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
void ChangeToImmediate(int64_t ImmVal, unsigned TargetFlags = 0); |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
void ChangeToFPImmediate(const ConstantFP *FPImm, unsigned TargetFlags = 0); |
| 739 |
|
| 740 |
|
| 741 |
void ChangeToES(const char *SymName, unsigned TargetFlags = 0); |
| 742 |
|
| 743 |
|
| 744 |
void ChangeToGA(const GlobalValue *GV, int64_t Offset, |
| 745 |
unsigned TargetFlags = 0); |
| 746 |
|
| 747 |
|
| 748 |
void ChangeToMCSymbol(MCSymbol *Sym, unsigned TargetFlags = 0); |
| 749 |
|
| 750 |
|
| 751 |
void ChangeToFrameIndex(int Idx, unsigned TargetFlags = 0); |
| 752 |
|
| 753 |
|
| 754 |
void ChangeToTargetIndex(unsigned Idx, int64_t Offset, |
| 755 |
unsigned TargetFlags = 0); |
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
void ChangeToRegister(Register Reg, bool isDef, bool isImp = false, |
| 761 |
bool isKill = false, bool isDead = false, |
| 762 |
bool isUndef = false, bool isDebug = false); |
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
const char *getTargetIndexName() const; |
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
static MachineOperand CreateImm(int64_t Val) { |
| 774 |
MachineOperand Op(MachineOperand::MO_Immediate); |
| 775 |
Op.setImm(Val); |
| 776 |
return Op; |
| 777 |
} |
| 778 |
|
| 779 |
static MachineOperand CreateCImm(const ConstantInt *CI) { |
| 780 |
MachineOperand Op(MachineOperand::MO_CImmediate); |
| 781 |
Op.Contents.CI = CI; |
| 782 |
return Op; |
| 783 |
} |
| 784 |
|
| 785 |
static MachineOperand CreateFPImm(const ConstantFP *CFP) { |
| 786 |
MachineOperand Op(MachineOperand::MO_FPImmediate); |
| 787 |
Op.Contents.CFP = CFP; |
| 788 |
return Op; |
| 789 |
} |
| 790 |
|
| 791 |
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp = false, |
| 792 |
bool isKill = false, bool isDead = false, |
| 793 |
bool isUndef = false, |
| 794 |
bool isEarlyClobber = false, |
| 795 |
unsigned SubReg = 0, bool isDebug = false, |
| 796 |
bool isInternalRead = false, |
| 797 |
bool isRenamable = false) { |
| 798 |
assert(!(isDead && !isDef) && "Dead flag on non-def"); |
| 799 |
assert(!(isKill && isDef) && "Kill flag on def"); |
| 800 |
MachineOperand Op(MachineOperand::MO_Register); |
| 801 |
Op.IsDef = isDef; |
| 802 |
Op.IsImp = isImp; |
| 803 |
Op.IsDeadOrKill = isKill | isDead; |
| 804 |
Op.IsRenamable = isRenamable; |
| 805 |
Op.IsUndef = isUndef; |
| 806 |
Op.IsInternalRead = isInternalRead; |
| 807 |
Op.IsEarlyClobber = isEarlyClobber; |
| 808 |
Op.TiedTo = 0; |
| 809 |
Op.IsDebug = isDebug; |
| 810 |
Op.SmallContents.RegNo = Reg; |
| 811 |
Op.Contents.Reg.Prev = nullptr; |
| 812 |
Op.Contents.Reg.Next = nullptr; |
| 813 |
Op.setSubReg(SubReg); |
| 814 |
return Op; |
| 815 |
} |
| 816 |
static MachineOperand CreateMBB(MachineBasicBlock *MBB, |
| 817 |
unsigned TargetFlags = 0) { |
| 818 |
MachineOperand Op(MachineOperand::MO_MachineBasicBlock); |
| 819 |
Op.setMBB(MBB); |
| 820 |
Op.setTargetFlags(TargetFlags); |
| 821 |
return Op; |
| 822 |
} |
| 823 |
static MachineOperand CreateFI(int Idx) { |
| 824 |
MachineOperand Op(MachineOperand::MO_FrameIndex); |
| 825 |
Op.setIndex(Idx); |
| 826 |
return Op; |
| 827 |
} |
| 828 |
static MachineOperand CreateCPI(unsigned Idx, int Offset, |
| 829 |
unsigned TargetFlags = 0) { |
| 830 |
MachineOperand Op(MachineOperand::MO_ConstantPoolIndex); |
| 831 |
Op.setIndex(Idx); |
| 832 |
Op.setOffset(Offset); |
| 833 |
Op.setTargetFlags(TargetFlags); |
| 834 |
return Op; |
| 835 |
} |
| 836 |
static MachineOperand CreateTargetIndex(unsigned Idx, int64_t Offset, |
| 837 |
unsigned TargetFlags = 0) { |
| 838 |
MachineOperand Op(MachineOperand::MO_TargetIndex); |
| 839 |
Op.setIndex(Idx); |
| 840 |
Op.setOffset(Offset); |
| 841 |
Op.setTargetFlags(TargetFlags); |
| 842 |
return Op; |
| 843 |
} |
| 844 |
static MachineOperand CreateJTI(unsigned Idx, unsigned TargetFlags = 0) { |
| 845 |
MachineOperand Op(MachineOperand::MO_JumpTableIndex); |
| 846 |
Op.setIndex(Idx); |
| 847 |
Op.setTargetFlags(TargetFlags); |
| 848 |
return Op; |
| 849 |
} |
| 850 |
static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset, |
| 851 |
unsigned TargetFlags = 0) { |
| 852 |
MachineOperand Op(MachineOperand::MO_GlobalAddress); |
| 853 |
Op.Contents.OffsetedInfo.Val.GV = GV; |
| 854 |
Op.setOffset(Offset); |
| 855 |
Op.setTargetFlags(TargetFlags); |
| 856 |
return Op; |
| 857 |
} |
| 858 |
static MachineOperand CreateES(const char *SymName, |
| 859 |
unsigned TargetFlags = 0) { |
| 860 |
MachineOperand Op(MachineOperand::MO_ExternalSymbol); |
| 861 |
Op.Contents.OffsetedInfo.Val.SymbolName = SymName; |
| 862 |
Op.setOffset(0); |
| 863 |
Op.setTargetFlags(TargetFlags); |
| 864 |
return Op; |
| 865 |
} |
| 866 |
static MachineOperand CreateBA(const BlockAddress *BA, int64_t Offset, |
| 867 |
unsigned TargetFlags = 0) { |
| 868 |
MachineOperand Op(MachineOperand::MO_BlockAddress); |
| 869 |
Op.Contents.OffsetedInfo.Val.BA = BA; |
| 870 |
Op.setOffset(Offset); |
| 871 |
Op.setTargetFlags(TargetFlags); |
| 872 |
return Op; |
| 873 |
} |
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
static MachineOperand CreateRegMask(const uint32_t *Mask) { |
| 887 |
assert(Mask && "Missing register mask"); |
| 888 |
MachineOperand Op(MachineOperand::MO_RegisterMask); |
| 889 |
Op.Contents.RegMask = Mask; |
| 890 |
return Op; |
| 891 |
} |
| 892 |
static MachineOperand CreateRegLiveOut(const uint32_t *Mask) { |
| 893 |
assert(Mask && "Missing live-out register mask"); |
| 894 |
MachineOperand Op(MachineOperand::MO_RegisterLiveOut); |
| 895 |
Op.Contents.RegMask = Mask; |
| 896 |
return Op; |
| 897 |
} |
| 898 |
static MachineOperand CreateMetadata(const MDNode *Meta) { |
| 899 |
MachineOperand Op(MachineOperand::MO_Metadata); |
| 900 |
Op.Contents.MD = Meta; |
| 901 |
return Op; |
| 902 |
} |
| 903 |
|
| 904 |
static MachineOperand CreateMCSymbol(MCSymbol *Sym, |
| 905 |
unsigned TargetFlags = 0) { |
| 906 |
MachineOperand Op(MachineOperand::MO_MCSymbol); |
| 907 |
Op.Contents.Sym = Sym; |
| 908 |
Op.setOffset(0); |
| 909 |
Op.setTargetFlags(TargetFlags); |
| 910 |
return Op; |
| 911 |
} |
| 912 |
|
| 913 |
static MachineOperand CreateCFIIndex(unsigned CFIIndex) { |
| 914 |
MachineOperand Op(MachineOperand::MO_CFIIndex); |
| 915 |
Op.Contents.CFIIndex = CFIIndex; |
| 916 |
return Op; |
| 917 |
} |
| 918 |
|
| 919 |
static MachineOperand CreateIntrinsicID(Intrinsic::ID ID) { |
| 920 |
MachineOperand Op(MachineOperand::MO_IntrinsicID); |
| 921 |
Op.Contents.IntrinsicID = ID; |
| 922 |
return Op; |
| 923 |
} |
| 924 |
|
| 925 |
static MachineOperand CreatePredicate(unsigned Pred) { |
| 926 |
MachineOperand Op(MachineOperand::MO_Predicate); |
| 927 |
Op.Contents.Pred = Pred; |
| 928 |
return Op; |
| 929 |
} |
| 930 |
|
| 931 |
static MachineOperand CreateShuffleMask(ArrayRef<int> Mask) { |
| 932 |
MachineOperand Op(MachineOperand::MO_ShuffleMask); |
| 933 |
Op.Contents.ShuffleMask = Mask; |
| 934 |
return Op; |
| 935 |
} |
| 936 |
|
| 937 |
friend class MachineInstr; |
| 938 |
friend class MachineRegisterInfo; |
| 939 |
|
| 940 |
private: |
| 941 |
|
| 942 |
|
| 943 |
void removeRegFromUses(); |
| 944 |
|
| 945 |
|
| 946 |
enum : unsigned char { |
| 947 |
MO_Empty = MO_Last + 1, |
| 948 |
MO_Tombstone, |
| 949 |
}; |
| 950 |
|
| 951 |
friend struct DenseMapInfo<MachineOperand>; |
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
bool isOnRegUseList() const { |
| 961 |
assert(isReg() && "Can only add reg operand to use lists"); |
| 962 |
return Contents.Reg.Prev != nullptr; |
| 963 |
} |
| 964 |
}; |
| 965 |
|
| 966 |
template <> struct DenseMapInfo<MachineOperand> { |
| 967 |
static MachineOperand getEmptyKey() { |
| 968 |
return MachineOperand(static_cast<MachineOperand::MachineOperandType>( |
| 969 |
MachineOperand::MO_Empty)); |
| 970 |
} |
| 971 |
static MachineOperand getTombstoneKey() { |
| 972 |
return MachineOperand(static_cast<MachineOperand::MachineOperandType>( |
| 973 |
MachineOperand::MO_Tombstone)); |
| 974 |
} |
| 975 |
static unsigned getHashValue(const MachineOperand &MO) { |
| 976 |
return hash_value(MO); |
| 977 |
} |
| 978 |
static bool isEqual(const MachineOperand &LHS, const MachineOperand &RHS) { |
| 979 |
if (LHS.getType() == static_cast<MachineOperand::MachineOperandType>( |
| 980 |
MachineOperand::MO_Empty) || |
| 981 |
LHS.getType() == static_cast<MachineOperand::MachineOperandType>( |
| 982 |
MachineOperand::MO_Tombstone)) |
| 983 |
return LHS.getType() == RHS.getType(); |
| 984 |
return LHS.isIdenticalTo(RHS); |
| 985 |
} |
| 986 |
}; |
| 987 |
|
| 988 |
inline raw_ostream &operator<<(raw_ostream &OS, const MachineOperand &MO) { |
| 989 |
MO.print(OS); |
| 990 |
return OS; |
| 991 |
} |
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
hash_code hash_value(const MachineOperand &MO); |
| 996 |
} |
| 997 |
|
| 998 |
#endif |