Francis Visoiu Mistrih | aa73969 | 2017-11-28 17:58:43 +0000 | [diff] [blame] | 1 | //===- lib/CodeGen/MachineOperand.cpp -------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Francis Visoiu Mistrih | d4b340b | 2017-11-28 19:15:46 +0000 | [diff] [blame^] | 10 | // /// \file Methods common to all machine operands. |
Francis Visoiu Mistrih | aa73969 | 2017-11-28 17:58:43 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/CodeGen/MachineOperand.h" |
| 15 | #include "llvm/Analysis/Loads.h" |
| 16 | #include "llvm/CodeGen/MIRPrinter.h" |
| 17 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 18 | #include "llvm/Target/TargetIntrinsicInfo.h" |
| 19 | #include "llvm/CodeGen/TargetRegisterInfo.h" |
| 20 | #include "llvm/IR/Constants.h" |
| 21 | #include "llvm/IR/ModuleSlotTracker.h" |
| 22 | |
| 23 | using namespace llvm; |
| 24 | |
| 25 | static cl::opt<int> |
| 26 | PrintRegMaskNumRegs("print-regmask-num-regs", |
| 27 | cl::desc("Number of registers to limit to when " |
| 28 | "printing regmask operands in IR dumps. " |
| 29 | "unlimited = -1"), |
| 30 | cl::init(32), cl::Hidden); |
| 31 | |
| 32 | void MachineOperand::setReg(unsigned Reg) { |
| 33 | if (getReg() == Reg) |
| 34 | return; // No change. |
| 35 | |
| 36 | // Otherwise, we have to change the register. If this operand is embedded |
| 37 | // into a machine function, we need to update the old and new register's |
| 38 | // use/def lists. |
| 39 | if (MachineInstr *MI = getParent()) |
| 40 | if (MachineBasicBlock *MBB = MI->getParent()) |
| 41 | if (MachineFunction *MF = MBB->getParent()) { |
| 42 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
| 43 | MRI.removeRegOperandFromUseList(this); |
| 44 | SmallContents.RegNo = Reg; |
| 45 | MRI.addRegOperandToUseList(this); |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | // Otherwise, just change the register, no problem. :) |
| 50 | SmallContents.RegNo = Reg; |
| 51 | } |
| 52 | |
| 53 | void MachineOperand::substVirtReg(unsigned Reg, unsigned SubIdx, |
| 54 | const TargetRegisterInfo &TRI) { |
| 55 | assert(TargetRegisterInfo::isVirtualRegister(Reg)); |
| 56 | if (SubIdx && getSubReg()) |
| 57 | SubIdx = TRI.composeSubRegIndices(SubIdx, getSubReg()); |
| 58 | setReg(Reg); |
| 59 | if (SubIdx) |
| 60 | setSubReg(SubIdx); |
| 61 | } |
| 62 | |
| 63 | void MachineOperand::substPhysReg(unsigned Reg, const TargetRegisterInfo &TRI) { |
| 64 | assert(TargetRegisterInfo::isPhysicalRegister(Reg)); |
| 65 | if (getSubReg()) { |
| 66 | Reg = TRI.getSubReg(Reg, getSubReg()); |
| 67 | // Note that getSubReg() may return 0 if the sub-register doesn't exist. |
| 68 | // That won't happen in legal code. |
| 69 | setSubReg(0); |
| 70 | if (isDef()) |
| 71 | setIsUndef(false); |
| 72 | } |
| 73 | setReg(Reg); |
| 74 | } |
| 75 | |
| 76 | /// Change a def to a use, or a use to a def. |
| 77 | void MachineOperand::setIsDef(bool Val) { |
| 78 | assert(isReg() && "Wrong MachineOperand accessor"); |
| 79 | assert((!Val || !isDebug()) && "Marking a debug operation as def"); |
| 80 | if (IsDef == Val) |
| 81 | return; |
| 82 | // MRI may keep uses and defs in different list positions. |
| 83 | if (MachineInstr *MI = getParent()) |
| 84 | if (MachineBasicBlock *MBB = MI->getParent()) |
| 85 | if (MachineFunction *MF = MBB->getParent()) { |
| 86 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
| 87 | MRI.removeRegOperandFromUseList(this); |
| 88 | IsDef = Val; |
| 89 | MRI.addRegOperandToUseList(this); |
| 90 | return; |
| 91 | } |
| 92 | IsDef = Val; |
| 93 | } |
| 94 | |
| 95 | // If this operand is currently a register operand, and if this is in a |
| 96 | // function, deregister the operand from the register's use/def list. |
| 97 | void MachineOperand::removeRegFromUses() { |
| 98 | if (!isReg() || !isOnRegUseList()) |
| 99 | return; |
| 100 | |
| 101 | if (MachineInstr *MI = getParent()) { |
| 102 | if (MachineBasicBlock *MBB = MI->getParent()) { |
| 103 | if (MachineFunction *MF = MBB->getParent()) |
| 104 | MF->getRegInfo().removeRegOperandFromUseList(this); |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /// ChangeToImmediate - Replace this operand with a new immediate operand of |
| 110 | /// the specified value. If an operand is known to be an immediate already, |
| 111 | /// the setImm method should be used. |
| 112 | void MachineOperand::ChangeToImmediate(int64_t ImmVal) { |
| 113 | assert((!isReg() || !isTied()) && "Cannot change a tied operand into an imm"); |
| 114 | |
| 115 | removeRegFromUses(); |
| 116 | |
| 117 | OpKind = MO_Immediate; |
| 118 | Contents.ImmVal = ImmVal; |
| 119 | } |
| 120 | |
| 121 | void MachineOperand::ChangeToFPImmediate(const ConstantFP *FPImm) { |
| 122 | assert((!isReg() || !isTied()) && "Cannot change a tied operand into an imm"); |
| 123 | |
| 124 | removeRegFromUses(); |
| 125 | |
| 126 | OpKind = MO_FPImmediate; |
| 127 | Contents.CFP = FPImm; |
| 128 | } |
| 129 | |
| 130 | void MachineOperand::ChangeToES(const char *SymName, |
| 131 | unsigned char TargetFlags) { |
| 132 | assert((!isReg() || !isTied()) && |
| 133 | "Cannot change a tied operand into an external symbol"); |
| 134 | |
| 135 | removeRegFromUses(); |
| 136 | |
| 137 | OpKind = MO_ExternalSymbol; |
| 138 | Contents.OffsetedInfo.Val.SymbolName = SymName; |
| 139 | setOffset(0); // Offset is always 0. |
| 140 | setTargetFlags(TargetFlags); |
| 141 | } |
| 142 | |
| 143 | void MachineOperand::ChangeToMCSymbol(MCSymbol *Sym) { |
| 144 | assert((!isReg() || !isTied()) && |
| 145 | "Cannot change a tied operand into an MCSymbol"); |
| 146 | |
| 147 | removeRegFromUses(); |
| 148 | |
| 149 | OpKind = MO_MCSymbol; |
| 150 | Contents.Sym = Sym; |
| 151 | } |
| 152 | |
| 153 | void MachineOperand::ChangeToFrameIndex(int Idx) { |
| 154 | assert((!isReg() || !isTied()) && |
| 155 | "Cannot change a tied operand into a FrameIndex"); |
| 156 | |
| 157 | removeRegFromUses(); |
| 158 | |
| 159 | OpKind = MO_FrameIndex; |
| 160 | setIndex(Idx); |
| 161 | } |
| 162 | |
| 163 | void MachineOperand::ChangeToTargetIndex(unsigned Idx, int64_t Offset, |
| 164 | unsigned char TargetFlags) { |
| 165 | assert((!isReg() || !isTied()) && |
| 166 | "Cannot change a tied operand into a FrameIndex"); |
| 167 | |
| 168 | removeRegFromUses(); |
| 169 | |
| 170 | OpKind = MO_TargetIndex; |
| 171 | setIndex(Idx); |
| 172 | setOffset(Offset); |
| 173 | setTargetFlags(TargetFlags); |
| 174 | } |
| 175 | |
| 176 | /// ChangeToRegister - Replace this operand with a new register operand of |
| 177 | /// the specified value. If an operand is known to be an register already, |
| 178 | /// the setReg method should be used. |
| 179 | void MachineOperand::ChangeToRegister(unsigned Reg, bool isDef, bool isImp, |
| 180 | bool isKill, bool isDead, bool isUndef, |
| 181 | bool isDebug) { |
| 182 | MachineRegisterInfo *RegInfo = nullptr; |
| 183 | if (MachineInstr *MI = getParent()) |
| 184 | if (MachineBasicBlock *MBB = MI->getParent()) |
| 185 | if (MachineFunction *MF = MBB->getParent()) |
| 186 | RegInfo = &MF->getRegInfo(); |
| 187 | // If this operand is already a register operand, remove it from the |
| 188 | // register's use/def lists. |
| 189 | bool WasReg = isReg(); |
| 190 | if (RegInfo && WasReg) |
| 191 | RegInfo->removeRegOperandFromUseList(this); |
| 192 | |
| 193 | // Change this to a register and set the reg#. |
| 194 | OpKind = MO_Register; |
| 195 | SmallContents.RegNo = Reg; |
| 196 | SubReg_TargetFlags = 0; |
| 197 | IsDef = isDef; |
| 198 | IsImp = isImp; |
| 199 | IsKill = isKill; |
| 200 | IsDead = isDead; |
| 201 | IsUndef = isUndef; |
| 202 | IsInternalRead = false; |
| 203 | IsEarlyClobber = false; |
| 204 | IsDebug = isDebug; |
| 205 | // Ensure isOnRegUseList() returns false. |
| 206 | Contents.Reg.Prev = nullptr; |
| 207 | // Preserve the tie when the operand was already a register. |
| 208 | if (!WasReg) |
| 209 | TiedTo = 0; |
| 210 | |
| 211 | // If this operand is embedded in a function, add the operand to the |
| 212 | // register's use/def list. |
| 213 | if (RegInfo) |
| 214 | RegInfo->addRegOperandToUseList(this); |
| 215 | } |
| 216 | |
| 217 | /// isIdenticalTo - Return true if this operand is identical to the specified |
| 218 | /// operand. Note that this should stay in sync with the hash_value overload |
| 219 | /// below. |
| 220 | bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const { |
| 221 | if (getType() != Other.getType() || |
| 222 | getTargetFlags() != Other.getTargetFlags()) |
| 223 | return false; |
| 224 | |
| 225 | switch (getType()) { |
| 226 | case MachineOperand::MO_Register: |
| 227 | return getReg() == Other.getReg() && isDef() == Other.isDef() && |
| 228 | getSubReg() == Other.getSubReg(); |
| 229 | case MachineOperand::MO_Immediate: |
| 230 | return getImm() == Other.getImm(); |
| 231 | case MachineOperand::MO_CImmediate: |
| 232 | return getCImm() == Other.getCImm(); |
| 233 | case MachineOperand::MO_FPImmediate: |
| 234 | return getFPImm() == Other.getFPImm(); |
| 235 | case MachineOperand::MO_MachineBasicBlock: |
| 236 | return getMBB() == Other.getMBB(); |
| 237 | case MachineOperand::MO_FrameIndex: |
| 238 | return getIndex() == Other.getIndex(); |
| 239 | case MachineOperand::MO_ConstantPoolIndex: |
| 240 | case MachineOperand::MO_TargetIndex: |
| 241 | return getIndex() == Other.getIndex() && getOffset() == Other.getOffset(); |
| 242 | case MachineOperand::MO_JumpTableIndex: |
| 243 | return getIndex() == Other.getIndex(); |
| 244 | case MachineOperand::MO_GlobalAddress: |
| 245 | return getGlobal() == Other.getGlobal() && getOffset() == Other.getOffset(); |
| 246 | case MachineOperand::MO_ExternalSymbol: |
| 247 | return strcmp(getSymbolName(), Other.getSymbolName()) == 0 && |
| 248 | getOffset() == Other.getOffset(); |
| 249 | case MachineOperand::MO_BlockAddress: |
| 250 | return getBlockAddress() == Other.getBlockAddress() && |
| 251 | getOffset() == Other.getOffset(); |
| 252 | case MachineOperand::MO_RegisterMask: |
| 253 | case MachineOperand::MO_RegisterLiveOut: { |
| 254 | // Shallow compare of the two RegMasks |
| 255 | const uint32_t *RegMask = getRegMask(); |
| 256 | const uint32_t *OtherRegMask = Other.getRegMask(); |
| 257 | if (RegMask == OtherRegMask) |
| 258 | return true; |
| 259 | |
| 260 | // Calculate the size of the RegMask |
| 261 | const MachineFunction *MF = getParent()->getMF(); |
| 262 | const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo(); |
| 263 | unsigned RegMaskSize = (TRI->getNumRegs() + 31) / 32; |
| 264 | |
| 265 | // Deep compare of the two RegMasks |
| 266 | return std::equal(RegMask, RegMask + RegMaskSize, OtherRegMask); |
| 267 | } |
| 268 | case MachineOperand::MO_MCSymbol: |
| 269 | return getMCSymbol() == Other.getMCSymbol(); |
| 270 | case MachineOperand::MO_CFIIndex: |
| 271 | return getCFIIndex() == Other.getCFIIndex(); |
| 272 | case MachineOperand::MO_Metadata: |
| 273 | return getMetadata() == Other.getMetadata(); |
| 274 | case MachineOperand::MO_IntrinsicID: |
| 275 | return getIntrinsicID() == Other.getIntrinsicID(); |
| 276 | case MachineOperand::MO_Predicate: |
| 277 | return getPredicate() == Other.getPredicate(); |
| 278 | } |
| 279 | llvm_unreachable("Invalid machine operand type"); |
| 280 | } |
| 281 | |
| 282 | // Note: this must stay exactly in sync with isIdenticalTo above. |
| 283 | hash_code llvm::hash_value(const MachineOperand &MO) { |
| 284 | switch (MO.getType()) { |
| 285 | case MachineOperand::MO_Register: |
| 286 | // Register operands don't have target flags. |
| 287 | return hash_combine(MO.getType(), MO.getReg(), MO.getSubReg(), MO.isDef()); |
| 288 | case MachineOperand::MO_Immediate: |
| 289 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getImm()); |
| 290 | case MachineOperand::MO_CImmediate: |
| 291 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getCImm()); |
| 292 | case MachineOperand::MO_FPImmediate: |
| 293 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getFPImm()); |
| 294 | case MachineOperand::MO_MachineBasicBlock: |
| 295 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMBB()); |
| 296 | case MachineOperand::MO_FrameIndex: |
| 297 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex()); |
| 298 | case MachineOperand::MO_ConstantPoolIndex: |
| 299 | case MachineOperand::MO_TargetIndex: |
| 300 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex(), |
| 301 | MO.getOffset()); |
| 302 | case MachineOperand::MO_JumpTableIndex: |
| 303 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex()); |
| 304 | case MachineOperand::MO_ExternalSymbol: |
| 305 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getOffset(), |
| 306 | MO.getSymbolName()); |
| 307 | case MachineOperand::MO_GlobalAddress: |
| 308 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getGlobal(), |
| 309 | MO.getOffset()); |
| 310 | case MachineOperand::MO_BlockAddress: |
| 311 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getBlockAddress(), |
| 312 | MO.getOffset()); |
| 313 | case MachineOperand::MO_RegisterMask: |
| 314 | case MachineOperand::MO_RegisterLiveOut: |
| 315 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getRegMask()); |
| 316 | case MachineOperand::MO_Metadata: |
| 317 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMetadata()); |
| 318 | case MachineOperand::MO_MCSymbol: |
| 319 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMCSymbol()); |
| 320 | case MachineOperand::MO_CFIIndex: |
| 321 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getCFIIndex()); |
| 322 | case MachineOperand::MO_IntrinsicID: |
| 323 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIntrinsicID()); |
| 324 | case MachineOperand::MO_Predicate: |
| 325 | return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getPredicate()); |
| 326 | } |
| 327 | llvm_unreachable("Invalid machine operand type"); |
| 328 | } |
| 329 | |
| 330 | void MachineOperand::print(raw_ostream &OS, const TargetRegisterInfo *TRI, |
| 331 | const TargetIntrinsicInfo *IntrinsicInfo) const { |
| 332 | ModuleSlotTracker DummyMST(nullptr); |
| 333 | print(OS, DummyMST, TRI, IntrinsicInfo); |
| 334 | } |
| 335 | |
| 336 | void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST, |
| 337 | const TargetRegisterInfo *TRI, |
| 338 | const TargetIntrinsicInfo *IntrinsicInfo) const { |
| 339 | switch (getType()) { |
| 340 | case MachineOperand::MO_Register: |
| 341 | OS << printReg(getReg(), TRI, getSubReg()); |
| 342 | |
| 343 | if (isDef() || isKill() || isDead() || isImplicit() || isUndef() || |
| 344 | isInternalRead() || isEarlyClobber() || isTied()) { |
| 345 | OS << '<'; |
| 346 | bool NeedComma = false; |
| 347 | if (isDef()) { |
| 348 | if (NeedComma) |
| 349 | OS << ','; |
| 350 | if (isEarlyClobber()) |
| 351 | OS << "earlyclobber,"; |
| 352 | if (isImplicit()) |
| 353 | OS << "imp-"; |
| 354 | OS << "def"; |
| 355 | NeedComma = true; |
| 356 | // <def,read-undef> only makes sense when getSubReg() is set. |
| 357 | // Don't clutter the output otherwise. |
| 358 | if (isUndef() && getSubReg()) |
| 359 | OS << ",read-undef"; |
| 360 | } else if (isImplicit()) { |
| 361 | OS << "imp-use"; |
| 362 | NeedComma = true; |
| 363 | } |
| 364 | |
| 365 | if (isKill()) { |
| 366 | if (NeedComma) |
| 367 | OS << ','; |
| 368 | OS << "kill"; |
| 369 | NeedComma = true; |
| 370 | } |
| 371 | if (isDead()) { |
| 372 | if (NeedComma) |
| 373 | OS << ','; |
| 374 | OS << "dead"; |
| 375 | NeedComma = true; |
| 376 | } |
| 377 | if (isUndef() && isUse()) { |
| 378 | if (NeedComma) |
| 379 | OS << ','; |
| 380 | OS << "undef"; |
| 381 | NeedComma = true; |
| 382 | } |
| 383 | if (isInternalRead()) { |
| 384 | if (NeedComma) |
| 385 | OS << ','; |
| 386 | OS << "internal"; |
| 387 | NeedComma = true; |
| 388 | } |
| 389 | if (isTied()) { |
| 390 | if (NeedComma) |
| 391 | OS << ','; |
| 392 | OS << "tied"; |
| 393 | if (TiedTo != 15) |
| 394 | OS << unsigned(TiedTo - 1); |
| 395 | } |
| 396 | OS << '>'; |
| 397 | } |
| 398 | break; |
| 399 | case MachineOperand::MO_Immediate: |
| 400 | OS << getImm(); |
| 401 | break; |
| 402 | case MachineOperand::MO_CImmediate: |
| 403 | getCImm()->getValue().print(OS, false); |
| 404 | break; |
| 405 | case MachineOperand::MO_FPImmediate: |
| 406 | if (getFPImm()->getType()->isFloatTy()) { |
| 407 | OS << getFPImm()->getValueAPF().convertToFloat(); |
| 408 | } else if (getFPImm()->getType()->isHalfTy()) { |
| 409 | APFloat APF = getFPImm()->getValueAPF(); |
| 410 | bool Unused; |
| 411 | APF.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven, &Unused); |
| 412 | OS << "half " << APF.convertToFloat(); |
| 413 | } else if (getFPImm()->getType()->isFP128Ty()) { |
| 414 | APFloat APF = getFPImm()->getValueAPF(); |
| 415 | SmallString<16> Str; |
| 416 | getFPImm()->getValueAPF().toString(Str); |
| 417 | OS << "quad " << Str; |
| 418 | } else if (getFPImm()->getType()->isX86_FP80Ty()) { |
| 419 | APFloat APF = getFPImm()->getValueAPF(); |
| 420 | OS << "x86_fp80 0xK"; |
| 421 | APInt API = APF.bitcastToAPInt(); |
| 422 | OS << format_hex_no_prefix(API.getHiBits(16).getZExtValue(), 4, |
| 423 | /*Upper=*/true); |
| 424 | OS << format_hex_no_prefix(API.getLoBits(64).getZExtValue(), 16, |
| 425 | /*Upper=*/true); |
| 426 | } else { |
| 427 | OS << getFPImm()->getValueAPF().convertToDouble(); |
| 428 | } |
| 429 | break; |
| 430 | case MachineOperand::MO_MachineBasicBlock: |
| 431 | OS << "<BB#" << getMBB()->getNumber() << ">"; |
| 432 | break; |
| 433 | case MachineOperand::MO_FrameIndex: |
| 434 | OS << "<fi#" << getIndex() << '>'; |
| 435 | break; |
| 436 | case MachineOperand::MO_ConstantPoolIndex: |
| 437 | OS << "<cp#" << getIndex(); |
| 438 | if (getOffset()) |
| 439 | OS << "+" << getOffset(); |
| 440 | OS << '>'; |
| 441 | break; |
| 442 | case MachineOperand::MO_TargetIndex: |
| 443 | OS << "<ti#" << getIndex(); |
| 444 | if (getOffset()) |
| 445 | OS << "+" << getOffset(); |
| 446 | OS << '>'; |
| 447 | break; |
| 448 | case MachineOperand::MO_JumpTableIndex: |
| 449 | OS << "<jt#" << getIndex() << '>'; |
| 450 | break; |
| 451 | case MachineOperand::MO_GlobalAddress: |
| 452 | OS << "<ga:"; |
| 453 | getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST); |
| 454 | if (getOffset()) |
| 455 | OS << "+" << getOffset(); |
| 456 | OS << '>'; |
| 457 | break; |
| 458 | case MachineOperand::MO_ExternalSymbol: |
| 459 | OS << "<es:" << getSymbolName(); |
| 460 | if (getOffset()) |
| 461 | OS << "+" << getOffset(); |
| 462 | OS << '>'; |
| 463 | break; |
| 464 | case MachineOperand::MO_BlockAddress: |
| 465 | OS << '<'; |
| 466 | getBlockAddress()->printAsOperand(OS, /*PrintType=*/false, MST); |
| 467 | if (getOffset()) |
| 468 | OS << "+" << getOffset(); |
| 469 | OS << '>'; |
| 470 | break; |
| 471 | case MachineOperand::MO_RegisterMask: { |
| 472 | unsigned NumRegsInMask = 0; |
| 473 | unsigned NumRegsEmitted = 0; |
| 474 | OS << "<regmask"; |
| 475 | for (unsigned i = 0; i < TRI->getNumRegs(); ++i) { |
| 476 | unsigned MaskWord = i / 32; |
| 477 | unsigned MaskBit = i % 32; |
| 478 | if (getRegMask()[MaskWord] & (1 << MaskBit)) { |
| 479 | if (PrintRegMaskNumRegs < 0 || |
| 480 | NumRegsEmitted <= static_cast<unsigned>(PrintRegMaskNumRegs)) { |
| 481 | OS << " " << printReg(i, TRI); |
| 482 | NumRegsEmitted++; |
| 483 | } |
| 484 | NumRegsInMask++; |
| 485 | } |
| 486 | } |
| 487 | if (NumRegsEmitted != NumRegsInMask) |
| 488 | OS << " and " << (NumRegsInMask - NumRegsEmitted) << " more..."; |
| 489 | OS << ">"; |
| 490 | break; |
| 491 | } |
| 492 | case MachineOperand::MO_RegisterLiveOut: |
| 493 | OS << "<regliveout>"; |
| 494 | break; |
| 495 | case MachineOperand::MO_Metadata: |
| 496 | OS << '<'; |
| 497 | getMetadata()->printAsOperand(OS, MST); |
| 498 | OS << '>'; |
| 499 | break; |
| 500 | case MachineOperand::MO_MCSymbol: |
| 501 | OS << "<MCSym=" << *getMCSymbol() << '>'; |
| 502 | break; |
| 503 | case MachineOperand::MO_CFIIndex: |
| 504 | OS << "<call frame instruction>"; |
| 505 | break; |
| 506 | case MachineOperand::MO_IntrinsicID: { |
| 507 | Intrinsic::ID ID = getIntrinsicID(); |
| 508 | if (ID < Intrinsic::num_intrinsics) |
| 509 | OS << "<intrinsic:@" << Intrinsic::getName(ID, None) << '>'; |
| 510 | else if (IntrinsicInfo) |
| 511 | OS << "<intrinsic:@" << IntrinsicInfo->getName(ID) << '>'; |
| 512 | else |
| 513 | OS << "<intrinsic:" << ID << '>'; |
| 514 | break; |
| 515 | } |
| 516 | case MachineOperand::MO_Predicate: { |
| 517 | auto Pred = static_cast<CmpInst::Predicate>(getPredicate()); |
| 518 | OS << '<' << (CmpInst::isIntPredicate(Pred) ? "intpred" : "floatpred") |
| 519 | << CmpInst::getPredicateName(Pred) << '>'; |
| 520 | break; |
| 521 | } |
| 522 | } |
| 523 | if (unsigned TF = getTargetFlags()) |
| 524 | OS << "[TF=" << TF << ']'; |
| 525 | } |
| 526 | |
| 527 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
| 528 | LLVM_DUMP_METHOD void MachineOperand::dump() const { dbgs() << *this << '\n'; } |
| 529 | #endif |
| 530 | |
| 531 | //===----------------------------------------------------------------------===// |
| 532 | // MachineMemOperand Implementation |
| 533 | //===----------------------------------------------------------------------===// |
| 534 | |
| 535 | /// getAddrSpace - Return the LLVM IR address space number that this pointer |
| 536 | /// points into. |
| 537 | unsigned MachinePointerInfo::getAddrSpace() const { |
| 538 | if (V.isNull()) |
| 539 | return 0; |
| 540 | |
| 541 | if (V.is<const PseudoSourceValue *>()) |
| 542 | return V.get<const PseudoSourceValue *>()->getAddressSpace(); |
| 543 | |
| 544 | return cast<PointerType>(V.get<const Value *>()->getType()) |
| 545 | ->getAddressSpace(); |
| 546 | } |
| 547 | |
| 548 | /// isDereferenceable - Return true if V is always dereferenceable for |
| 549 | /// Offset + Size byte. |
| 550 | bool MachinePointerInfo::isDereferenceable(unsigned Size, LLVMContext &C, |
| 551 | const DataLayout &DL) const { |
| 552 | if (!V.is<const Value *>()) |
| 553 | return false; |
| 554 | |
| 555 | const Value *BasePtr = V.get<const Value *>(); |
| 556 | if (BasePtr == nullptr) |
| 557 | return false; |
| 558 | |
| 559 | return isDereferenceableAndAlignedPointer( |
| 560 | BasePtr, 1, APInt(DL.getPointerSizeInBits(), Offset + Size), DL); |
| 561 | } |
| 562 | |
| 563 | /// getConstantPool - Return a MachinePointerInfo record that refers to the |
| 564 | /// constant pool. |
| 565 | MachinePointerInfo MachinePointerInfo::getConstantPool(MachineFunction &MF) { |
| 566 | return MachinePointerInfo(MF.getPSVManager().getConstantPool()); |
| 567 | } |
| 568 | |
| 569 | /// getFixedStack - Return a MachinePointerInfo record that refers to the |
| 570 | /// the specified FrameIndex. |
| 571 | MachinePointerInfo MachinePointerInfo::getFixedStack(MachineFunction &MF, |
| 572 | int FI, int64_t Offset) { |
| 573 | return MachinePointerInfo(MF.getPSVManager().getFixedStack(FI), Offset); |
| 574 | } |
| 575 | |
| 576 | MachinePointerInfo MachinePointerInfo::getJumpTable(MachineFunction &MF) { |
| 577 | return MachinePointerInfo(MF.getPSVManager().getJumpTable()); |
| 578 | } |
| 579 | |
| 580 | MachinePointerInfo MachinePointerInfo::getGOT(MachineFunction &MF) { |
| 581 | return MachinePointerInfo(MF.getPSVManager().getGOT()); |
| 582 | } |
| 583 | |
| 584 | MachinePointerInfo MachinePointerInfo::getStack(MachineFunction &MF, |
| 585 | int64_t Offset, uint8_t ID) { |
| 586 | return MachinePointerInfo(MF.getPSVManager().getStack(), Offset, ID); |
| 587 | } |
| 588 | |
| 589 | MachineMemOperand::MachineMemOperand(MachinePointerInfo ptrinfo, Flags f, |
| 590 | uint64_t s, unsigned int a, |
| 591 | const AAMDNodes &AAInfo, |
| 592 | const MDNode *Ranges, SyncScope::ID SSID, |
| 593 | AtomicOrdering Ordering, |
| 594 | AtomicOrdering FailureOrdering) |
| 595 | : PtrInfo(ptrinfo), Size(s), FlagVals(f), BaseAlignLog2(Log2_32(a) + 1), |
| 596 | AAInfo(AAInfo), Ranges(Ranges) { |
| 597 | assert((PtrInfo.V.isNull() || PtrInfo.V.is<const PseudoSourceValue *>() || |
| 598 | isa<PointerType>(PtrInfo.V.get<const Value *>()->getType())) && |
| 599 | "invalid pointer value"); |
| 600 | assert(getBaseAlignment() == a && "Alignment is not a power of 2!"); |
| 601 | assert((isLoad() || isStore()) && "Not a load/store!"); |
| 602 | |
| 603 | AtomicInfo.SSID = static_cast<unsigned>(SSID); |
| 604 | assert(getSyncScopeID() == SSID && "Value truncated"); |
| 605 | AtomicInfo.Ordering = static_cast<unsigned>(Ordering); |
| 606 | assert(getOrdering() == Ordering && "Value truncated"); |
| 607 | AtomicInfo.FailureOrdering = static_cast<unsigned>(FailureOrdering); |
| 608 | assert(getFailureOrdering() == FailureOrdering && "Value truncated"); |
| 609 | } |
| 610 | |
| 611 | /// Profile - Gather unique data for the object. |
| 612 | /// |
| 613 | void MachineMemOperand::Profile(FoldingSetNodeID &ID) const { |
| 614 | ID.AddInteger(getOffset()); |
| 615 | ID.AddInteger(Size); |
| 616 | ID.AddPointer(getOpaqueValue()); |
| 617 | ID.AddInteger(getFlags()); |
| 618 | ID.AddInteger(getBaseAlignment()); |
| 619 | } |
| 620 | |
| 621 | void MachineMemOperand::refineAlignment(const MachineMemOperand *MMO) { |
| 622 | // The Value and Offset may differ due to CSE. But the flags and size |
| 623 | // should be the same. |
| 624 | assert(MMO->getFlags() == getFlags() && "Flags mismatch!"); |
| 625 | assert(MMO->getSize() == getSize() && "Size mismatch!"); |
| 626 | |
| 627 | if (MMO->getBaseAlignment() >= getBaseAlignment()) { |
| 628 | // Update the alignment value. |
| 629 | BaseAlignLog2 = Log2_32(MMO->getBaseAlignment()) + 1; |
| 630 | // Also update the base and offset, because the new alignment may |
| 631 | // not be applicable with the old ones. |
| 632 | PtrInfo = MMO->PtrInfo; |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | /// getAlignment - Return the minimum known alignment in bytes of the |
| 637 | /// actual memory reference. |
| 638 | uint64_t MachineMemOperand::getAlignment() const { |
| 639 | return MinAlign(getBaseAlignment(), getOffset()); |
| 640 | } |
| 641 | |
| 642 | void MachineMemOperand::print(raw_ostream &OS) const { |
| 643 | ModuleSlotTracker DummyMST(nullptr); |
| 644 | print(OS, DummyMST); |
| 645 | } |
| 646 | void MachineMemOperand::print(raw_ostream &OS, ModuleSlotTracker &MST) const { |
| 647 | assert((isLoad() || isStore()) && "SV has to be a load, store or both."); |
| 648 | |
| 649 | if (isVolatile()) |
| 650 | OS << "Volatile "; |
| 651 | |
| 652 | if (isLoad()) |
| 653 | OS << "LD"; |
| 654 | if (isStore()) |
| 655 | OS << "ST"; |
| 656 | OS << getSize(); |
| 657 | |
| 658 | // Print the address information. |
| 659 | OS << "["; |
| 660 | if (const Value *V = getValue()) |
| 661 | V->printAsOperand(OS, /*PrintType=*/false, MST); |
| 662 | else if (const PseudoSourceValue *PSV = getPseudoValue()) |
| 663 | PSV->printCustom(OS); |
| 664 | else |
| 665 | OS << "<unknown>"; |
| 666 | |
| 667 | unsigned AS = getAddrSpace(); |
| 668 | if (AS != 0) |
| 669 | OS << "(addrspace=" << AS << ')'; |
| 670 | |
| 671 | // If the alignment of the memory reference itself differs from the alignment |
| 672 | // of the base pointer, print the base alignment explicitly, next to the base |
| 673 | // pointer. |
| 674 | if (getBaseAlignment() != getAlignment()) |
| 675 | OS << "(align=" << getBaseAlignment() << ")"; |
| 676 | |
| 677 | if (getOffset() != 0) |
| 678 | OS << "+" << getOffset(); |
| 679 | OS << "]"; |
| 680 | |
| 681 | // Print the alignment of the reference. |
| 682 | if (getBaseAlignment() != getAlignment() || getBaseAlignment() != getSize()) |
| 683 | OS << "(align=" << getAlignment() << ")"; |
| 684 | |
| 685 | // Print TBAA info. |
| 686 | if (const MDNode *TBAAInfo = getAAInfo().TBAA) { |
| 687 | OS << "(tbaa="; |
| 688 | if (TBAAInfo->getNumOperands() > 0) |
| 689 | TBAAInfo->getOperand(0)->printAsOperand(OS, MST); |
| 690 | else |
| 691 | OS << "<unknown>"; |
| 692 | OS << ")"; |
| 693 | } |
| 694 | |
| 695 | // Print AA scope info. |
| 696 | if (const MDNode *ScopeInfo = getAAInfo().Scope) { |
| 697 | OS << "(alias.scope="; |
| 698 | if (ScopeInfo->getNumOperands() > 0) |
| 699 | for (unsigned i = 0, ie = ScopeInfo->getNumOperands(); i != ie; ++i) { |
| 700 | ScopeInfo->getOperand(i)->printAsOperand(OS, MST); |
| 701 | if (i != ie - 1) |
| 702 | OS << ","; |
| 703 | } |
| 704 | else |
| 705 | OS << "<unknown>"; |
| 706 | OS << ")"; |
| 707 | } |
| 708 | |
| 709 | // Print AA noalias scope info. |
| 710 | if (const MDNode *NoAliasInfo = getAAInfo().NoAlias) { |
| 711 | OS << "(noalias="; |
| 712 | if (NoAliasInfo->getNumOperands() > 0) |
| 713 | for (unsigned i = 0, ie = NoAliasInfo->getNumOperands(); i != ie; ++i) { |
| 714 | NoAliasInfo->getOperand(i)->printAsOperand(OS, MST); |
| 715 | if (i != ie - 1) |
| 716 | OS << ","; |
| 717 | } |
| 718 | else |
| 719 | OS << "<unknown>"; |
| 720 | OS << ")"; |
| 721 | } |
| 722 | |
| 723 | if (const MDNode *Ranges = getRanges()) { |
| 724 | unsigned NumRanges = Ranges->getNumOperands(); |
| 725 | if (NumRanges != 0) { |
| 726 | OS << "(ranges="; |
| 727 | |
| 728 | for (unsigned I = 0; I != NumRanges; ++I) { |
| 729 | Ranges->getOperand(I)->printAsOperand(OS, MST); |
| 730 | if (I != NumRanges - 1) |
| 731 | OS << ','; |
| 732 | } |
| 733 | |
| 734 | OS << ')'; |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | if (isNonTemporal()) |
| 739 | OS << "(nontemporal)"; |
| 740 | if (isDereferenceable()) |
| 741 | OS << "(dereferenceable)"; |
| 742 | if (isInvariant()) |
| 743 | OS << "(invariant)"; |
| 744 | if (getFlags() & MOTargetFlag1) |
| 745 | OS << "(flag1)"; |
| 746 | if (getFlags() & MOTargetFlag2) |
| 747 | OS << "(flag2)"; |
| 748 | if (getFlags() & MOTargetFlag3) |
| 749 | OS << "(flag3)"; |
| 750 | } |