MachineOperand.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  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. //
  10. /// \file Methods common to all machine operands.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/CodeGen/MachineOperand.h"
  14. #include "llvm/ADT/StringExtras.h"
  15. #include "llvm/Analysis/Loads.h"
  16. #include "llvm/Analysis/MemoryLocation.h"
  17. #include "llvm/CodeGen/MIRPrinter.h"
  18. #include "llvm/CodeGen/MachineFrameInfo.h"
  19. #include "llvm/CodeGen/MachineJumpTableInfo.h"
  20. #include "llvm/CodeGen/MachineRegisterInfo.h"
  21. #include "llvm/CodeGen/TargetInstrInfo.h"
  22. #include "llvm/CodeGen/TargetRegisterInfo.h"
  23. #include "llvm/Config/llvm-config.h"
  24. #include "llvm/IR/Constants.h"
  25. #include "llvm/IR/IRPrintingPasses.h"
  26. #include "llvm/IR/ModuleSlotTracker.h"
  27. #include "llvm/Target/TargetIntrinsicInfo.h"
  28. #include "llvm/Target/TargetMachine.h"
  29. using namespace llvm;
  30. static cl::opt<int>
  31. PrintRegMaskNumRegs("print-regmask-num-regs",
  32. cl::desc("Number of registers to limit to when "
  33. "printing regmask operands in IR dumps. "
  34. "unlimited = -1"),
  35. cl::init(32), cl::Hidden);
  36. static const MachineFunction *getMFIfAvailable(const MachineOperand &MO) {
  37. if (const MachineInstr *MI = MO.getParent())
  38. if (const MachineBasicBlock *MBB = MI->getParent())
  39. if (const MachineFunction *MF = MBB->getParent())
  40. return MF;
  41. return nullptr;
  42. }
  43. static MachineFunction *getMFIfAvailable(MachineOperand &MO) {
  44. return const_cast<MachineFunction *>(
  45. getMFIfAvailable(const_cast<const MachineOperand &>(MO)));
  46. }
  47. void MachineOperand::setReg(unsigned Reg) {
  48. if (getReg() == Reg)
  49. return; // No change.
  50. // Clear the IsRenamable bit to keep it conservatively correct.
  51. IsRenamable = false;
  52. // Otherwise, we have to change the register. If this operand is embedded
  53. // into a machine function, we need to update the old and new register's
  54. // use/def lists.
  55. if (MachineFunction *MF = getMFIfAvailable(*this)) {
  56. MachineRegisterInfo &MRI = MF->getRegInfo();
  57. MRI.removeRegOperandFromUseList(this);
  58. SmallContents.RegNo = Reg;
  59. MRI.addRegOperandToUseList(this);
  60. return;
  61. }
  62. // Otherwise, just change the register, no problem. :)
  63. SmallContents.RegNo = Reg;
  64. }
  65. void MachineOperand::substVirtReg(unsigned Reg, unsigned SubIdx,
  66. const TargetRegisterInfo &TRI) {
  67. assert(TargetRegisterInfo::isVirtualRegister(Reg));
  68. if (SubIdx && getSubReg())
  69. SubIdx = TRI.composeSubRegIndices(SubIdx, getSubReg());
  70. setReg(Reg);
  71. if (SubIdx)
  72. setSubReg(SubIdx);
  73. }
  74. void MachineOperand::substPhysReg(unsigned Reg, const TargetRegisterInfo &TRI) {
  75. assert(TargetRegisterInfo::isPhysicalRegister(Reg));
  76. if (getSubReg()) {
  77. Reg = TRI.getSubReg(Reg, getSubReg());
  78. // Note that getSubReg() may return 0 if the sub-register doesn't exist.
  79. // That won't happen in legal code.
  80. setSubReg(0);
  81. if (isDef())
  82. setIsUndef(false);
  83. }
  84. setReg(Reg);
  85. }
  86. /// Change a def to a use, or a use to a def.
  87. void MachineOperand::setIsDef(bool Val) {
  88. assert(isReg() && "Wrong MachineOperand accessor");
  89. assert((!Val || !isDebug()) && "Marking a debug operation as def");
  90. if (IsDef == Val)
  91. return;
  92. assert(!IsDeadOrKill && "Changing def/use with dead/kill set not supported");
  93. // MRI may keep uses and defs in different list positions.
  94. if (MachineFunction *MF = getMFIfAvailable(*this)) {
  95. MachineRegisterInfo &MRI = MF->getRegInfo();
  96. MRI.removeRegOperandFromUseList(this);
  97. IsDef = Val;
  98. MRI.addRegOperandToUseList(this);
  99. return;
  100. }
  101. IsDef = Val;
  102. }
  103. bool MachineOperand::isRenamable() const {
  104. assert(isReg() && "Wrong MachineOperand accessor");
  105. assert(TargetRegisterInfo::isPhysicalRegister(getReg()) &&
  106. "isRenamable should only be checked on physical registers");
  107. if (!IsRenamable)
  108. return false;
  109. const MachineInstr *MI = getParent();
  110. if (!MI)
  111. return true;
  112. if (isDef())
  113. return !MI->hasExtraDefRegAllocReq(MachineInstr::IgnoreBundle);
  114. assert(isUse() && "Reg is not def or use");
  115. return !MI->hasExtraSrcRegAllocReq(MachineInstr::IgnoreBundle);
  116. }
  117. void MachineOperand::setIsRenamable(bool Val) {
  118. assert(isReg() && "Wrong MachineOperand accessor");
  119. assert(TargetRegisterInfo::isPhysicalRegister(getReg()) &&
  120. "setIsRenamable should only be called on physical registers");
  121. IsRenamable = Val;
  122. }
  123. // If this operand is currently a register operand, and if this is in a
  124. // function, deregister the operand from the register's use/def list.
  125. void MachineOperand::removeRegFromUses() {
  126. if (!isReg() || !isOnRegUseList())
  127. return;
  128. if (MachineFunction *MF = getMFIfAvailable(*this))
  129. MF->getRegInfo().removeRegOperandFromUseList(this);
  130. }
  131. /// ChangeToImmediate - Replace this operand with a new immediate operand of
  132. /// the specified value. If an operand is known to be an immediate already,
  133. /// the setImm method should be used.
  134. void MachineOperand::ChangeToImmediate(int64_t ImmVal) {
  135. assert((!isReg() || !isTied()) && "Cannot change a tied operand into an imm");
  136. removeRegFromUses();
  137. OpKind = MO_Immediate;
  138. Contents.ImmVal = ImmVal;
  139. }
  140. void MachineOperand::ChangeToFPImmediate(const ConstantFP *FPImm) {
  141. assert((!isReg() || !isTied()) && "Cannot change a tied operand into an imm");
  142. removeRegFromUses();
  143. OpKind = MO_FPImmediate;
  144. Contents.CFP = FPImm;
  145. }
  146. void MachineOperand::ChangeToES(const char *SymName,
  147. unsigned char TargetFlags) {
  148. assert((!isReg() || !isTied()) &&
  149. "Cannot change a tied operand into an external symbol");
  150. removeRegFromUses();
  151. OpKind = MO_ExternalSymbol;
  152. Contents.OffsetedInfo.Val.SymbolName = SymName;
  153. setOffset(0); // Offset is always 0.
  154. setTargetFlags(TargetFlags);
  155. }
  156. void MachineOperand::ChangeToMCSymbol(MCSymbol *Sym) {
  157. assert((!isReg() || !isTied()) &&
  158. "Cannot change a tied operand into an MCSymbol");
  159. removeRegFromUses();
  160. OpKind = MO_MCSymbol;
  161. Contents.Sym = Sym;
  162. }
  163. void MachineOperand::ChangeToFrameIndex(int Idx) {
  164. assert((!isReg() || !isTied()) &&
  165. "Cannot change a tied operand into a FrameIndex");
  166. removeRegFromUses();
  167. OpKind = MO_FrameIndex;
  168. setIndex(Idx);
  169. }
  170. void MachineOperand::ChangeToTargetIndex(unsigned Idx, int64_t Offset,
  171. unsigned char TargetFlags) {
  172. assert((!isReg() || !isTied()) &&
  173. "Cannot change a tied operand into a FrameIndex");
  174. removeRegFromUses();
  175. OpKind = MO_TargetIndex;
  176. setIndex(Idx);
  177. setOffset(Offset);
  178. setTargetFlags(TargetFlags);
  179. }
  180. /// ChangeToRegister - Replace this operand with a new register operand of
  181. /// the specified value. If an operand is known to be an register already,
  182. /// the setReg method should be used.
  183. void MachineOperand::ChangeToRegister(unsigned Reg, bool isDef, bool isImp,
  184. bool isKill, bool isDead, bool isUndef,
  185. bool isDebug) {
  186. MachineRegisterInfo *RegInfo = nullptr;
  187. if (MachineFunction *MF = getMFIfAvailable(*this))
  188. RegInfo = &MF->getRegInfo();
  189. // If this operand is already a register operand, remove it from the
  190. // register's use/def lists.
  191. bool WasReg = isReg();
  192. if (RegInfo && WasReg)
  193. RegInfo->removeRegOperandFromUseList(this);
  194. // Change this to a register and set the reg#.
  195. assert(!(isDead && !isDef) && "Dead flag on non-def");
  196. assert(!(isKill && isDef) && "Kill flag on def");
  197. OpKind = MO_Register;
  198. SmallContents.RegNo = Reg;
  199. SubReg_TargetFlags = 0;
  200. IsDef = isDef;
  201. IsImp = isImp;
  202. IsDeadOrKill = isKill | isDead;
  203. IsRenamable = false;
  204. IsUndef = isUndef;
  205. IsInternalRead = false;
  206. IsEarlyClobber = false;
  207. IsDebug = isDebug;
  208. // Ensure isOnRegUseList() returns false.
  209. Contents.Reg.Prev = nullptr;
  210. // Preserve the tie when the operand was already a register.
  211. if (!WasReg)
  212. TiedTo = 0;
  213. // If this operand is embedded in a function, add the operand to the
  214. // register's use/def list.
  215. if (RegInfo)
  216. RegInfo->addRegOperandToUseList(this);
  217. }
  218. /// isIdenticalTo - Return true if this operand is identical to the specified
  219. /// operand. Note that this should stay in sync with the hash_value overload
  220. /// below.
  221. bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {
  222. if (getType() != Other.getType() ||
  223. getTargetFlags() != Other.getTargetFlags())
  224. return false;
  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. if (const MachineFunction *MF = getMFIfAvailable(*this)) {
  260. // Calculate the size of the RegMask
  261. const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
  262. unsigned RegMaskSize = (TRI->getNumRegs() + 31) / 32;
  263. // Deep compare of the two RegMasks
  264. return std::equal(RegMask, RegMask + RegMaskSize, OtherRegMask);
  265. }
  266. // We don't know the size of the RegMask, so we can't deep compare the two
  267. // reg masks.
  268. return false;
  269. }
  270. case MachineOperand::MO_MCSymbol:
  271. return getMCSymbol() == Other.getMCSymbol();
  272. case MachineOperand::MO_CFIIndex:
  273. return getCFIIndex() == Other.getCFIIndex();
  274. case MachineOperand::MO_Metadata:
  275. return getMetadata() == Other.getMetadata();
  276. case MachineOperand::MO_IntrinsicID:
  277. return getIntrinsicID() == Other.getIntrinsicID();
  278. case MachineOperand::MO_Predicate:
  279. return getPredicate() == Other.getPredicate();
  280. }
  281. llvm_unreachable("Invalid machine operand type");
  282. }
  283. // Note: this must stay exactly in sync with isIdenticalTo above.
  284. hash_code llvm::hash_value(const MachineOperand &MO) {
  285. switch (MO.getType()) {
  286. case MachineOperand::MO_Register:
  287. // Register operands don't have target flags.
  288. return hash_combine(MO.getType(), MO.getReg(), MO.getSubReg(), MO.isDef());
  289. case MachineOperand::MO_Immediate:
  290. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getImm());
  291. case MachineOperand::MO_CImmediate:
  292. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getCImm());
  293. case MachineOperand::MO_FPImmediate:
  294. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getFPImm());
  295. case MachineOperand::MO_MachineBasicBlock:
  296. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMBB());
  297. case MachineOperand::MO_FrameIndex:
  298. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex());
  299. case MachineOperand::MO_ConstantPoolIndex:
  300. case MachineOperand::MO_TargetIndex:
  301. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex(),
  302. MO.getOffset());
  303. case MachineOperand::MO_JumpTableIndex:
  304. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex());
  305. case MachineOperand::MO_ExternalSymbol:
  306. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getOffset(),
  307. MO.getSymbolName());
  308. case MachineOperand::MO_GlobalAddress:
  309. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getGlobal(),
  310. MO.getOffset());
  311. case MachineOperand::MO_BlockAddress:
  312. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getBlockAddress(),
  313. MO.getOffset());
  314. case MachineOperand::MO_RegisterMask:
  315. case MachineOperand::MO_RegisterLiveOut:
  316. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getRegMask());
  317. case MachineOperand::MO_Metadata:
  318. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMetadata());
  319. case MachineOperand::MO_MCSymbol:
  320. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMCSymbol());
  321. case MachineOperand::MO_CFIIndex:
  322. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getCFIIndex());
  323. case MachineOperand::MO_IntrinsicID:
  324. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIntrinsicID());
  325. case MachineOperand::MO_Predicate:
  326. return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getPredicate());
  327. }
  328. llvm_unreachable("Invalid machine operand type");
  329. }
  330. // Try to crawl up to the machine function and get TRI and IntrinsicInfo from
  331. // it.
  332. static void tryToGetTargetInfo(const MachineOperand &MO,
  333. const TargetRegisterInfo *&TRI,
  334. const TargetIntrinsicInfo *&IntrinsicInfo) {
  335. if (const MachineFunction *MF = getMFIfAvailable(MO)) {
  336. TRI = MF->getSubtarget().getRegisterInfo();
  337. IntrinsicInfo = MF->getTarget().getIntrinsicInfo();
  338. }
  339. }
  340. static const char *getTargetIndexName(const MachineFunction &MF, int Index) {
  341. const auto *TII = MF.getSubtarget().getInstrInfo();
  342. assert(TII && "expected instruction info");
  343. auto Indices = TII->getSerializableTargetIndices();
  344. auto Found = find_if(Indices, [&](const std::pair<int, const char *> &I) {
  345. return I.first == Index;
  346. });
  347. if (Found != Indices.end())
  348. return Found->second;
  349. return nullptr;
  350. }
  351. static const char *getTargetFlagName(const TargetInstrInfo *TII, unsigned TF) {
  352. auto Flags = TII->getSerializableDirectMachineOperandTargetFlags();
  353. for (const auto &I : Flags) {
  354. if (I.first == TF) {
  355. return I.second;
  356. }
  357. }
  358. return nullptr;
  359. }
  360. static void printCFIRegister(unsigned DwarfReg, raw_ostream &OS,
  361. const TargetRegisterInfo *TRI) {
  362. if (!TRI) {
  363. OS << "%dwarfreg." << DwarfReg;
  364. return;
  365. }
  366. int Reg = TRI->getLLVMRegNum(DwarfReg, true);
  367. if (Reg == -1) {
  368. OS << "<badreg>";
  369. return;
  370. }
  371. OS << printReg(Reg, TRI);
  372. }
  373. static void printIRBlockReference(raw_ostream &OS, const BasicBlock &BB,
  374. ModuleSlotTracker &MST) {
  375. OS << "%ir-block.";
  376. if (BB.hasName()) {
  377. printLLVMNameWithoutPrefix(OS, BB.getName());
  378. return;
  379. }
  380. Optional<int> Slot;
  381. if (const Function *F = BB.getParent()) {
  382. if (F == MST.getCurrentFunction()) {
  383. Slot = MST.getLocalSlot(&BB);
  384. } else if (const Module *M = F->getParent()) {
  385. ModuleSlotTracker CustomMST(M, /*ShouldInitializeAllMetadata=*/false);
  386. CustomMST.incorporateFunction(*F);
  387. Slot = CustomMST.getLocalSlot(&BB);
  388. }
  389. }
  390. if (Slot)
  391. MachineOperand::printIRSlotNumber(OS, *Slot);
  392. else
  393. OS << "<unknown>";
  394. }
  395. static void printIRValueReference(raw_ostream &OS, const Value &V,
  396. ModuleSlotTracker &MST) {
  397. if (isa<GlobalValue>(V)) {
  398. V.printAsOperand(OS, /*PrintType=*/false, MST);
  399. return;
  400. }
  401. if (isa<Constant>(V)) {
  402. // Machine memory operands can load/store to/from constant value pointers.
  403. OS << '`';
  404. V.printAsOperand(OS, /*PrintType=*/true, MST);
  405. OS << '`';
  406. return;
  407. }
  408. OS << "%ir.";
  409. if (V.hasName()) {
  410. printLLVMNameWithoutPrefix(OS, V.getName());
  411. return;
  412. }
  413. MachineOperand::printIRSlotNumber(OS, MST.getLocalSlot(&V));
  414. }
  415. static void printSyncScope(raw_ostream &OS, const LLVMContext &Context,
  416. SyncScope::ID SSID,
  417. SmallVectorImpl<StringRef> &SSNs) {
  418. switch (SSID) {
  419. case SyncScope::System:
  420. break;
  421. default:
  422. if (SSNs.empty())
  423. Context.getSyncScopeNames(SSNs);
  424. OS << "syncscope(\"";
  425. printEscapedString(SSNs[SSID], OS);
  426. OS << "\") ";
  427. break;
  428. }
  429. }
  430. static const char *getTargetMMOFlagName(const TargetInstrInfo &TII,
  431. unsigned TMMOFlag) {
  432. auto Flags = TII.getSerializableMachineMemOperandTargetFlags();
  433. for (const auto &I : Flags) {
  434. if (I.first == TMMOFlag) {
  435. return I.second;
  436. }
  437. }
  438. return nullptr;
  439. }
  440. static void printFrameIndex(raw_ostream& OS, int FrameIndex, bool IsFixed,
  441. const MachineFrameInfo *MFI) {
  442. StringRef Name;
  443. if (MFI) {
  444. IsFixed = MFI->isFixedObjectIndex(FrameIndex);
  445. if (const AllocaInst *Alloca = MFI->getObjectAllocation(FrameIndex))
  446. if (Alloca->hasName())
  447. Name = Alloca->getName();
  448. if (IsFixed)
  449. FrameIndex -= MFI->getObjectIndexBegin();
  450. }
  451. MachineOperand::printStackObjectReference(OS, FrameIndex, IsFixed, Name);
  452. }
  453. void MachineOperand::printSubRegIdx(raw_ostream &OS, uint64_t Index,
  454. const TargetRegisterInfo *TRI) {
  455. OS << "%subreg.";
  456. if (TRI)
  457. OS << TRI->getSubRegIndexName(Index);
  458. else
  459. OS << Index;
  460. }
  461. void MachineOperand::printTargetFlags(raw_ostream &OS,
  462. const MachineOperand &Op) {
  463. if (!Op.getTargetFlags())
  464. return;
  465. const MachineFunction *MF = getMFIfAvailable(Op);
  466. if (!MF)
  467. return;
  468. const auto *TII = MF->getSubtarget().getInstrInfo();
  469. assert(TII && "expected instruction info");
  470. auto Flags = TII->decomposeMachineOperandsTargetFlags(Op.getTargetFlags());
  471. OS << "target-flags(";
  472. const bool HasDirectFlags = Flags.first;
  473. const bool HasBitmaskFlags = Flags.second;
  474. if (!HasDirectFlags && !HasBitmaskFlags) {
  475. OS << "<unknown>) ";
  476. return;
  477. }
  478. if (HasDirectFlags) {
  479. if (const auto *Name = getTargetFlagName(TII, Flags.first))
  480. OS << Name;
  481. else
  482. OS << "<unknown target flag>";
  483. }
  484. if (!HasBitmaskFlags) {
  485. OS << ") ";
  486. return;
  487. }
  488. bool IsCommaNeeded = HasDirectFlags;
  489. unsigned BitMask = Flags.second;
  490. auto BitMasks = TII->getSerializableBitmaskMachineOperandTargetFlags();
  491. for (const auto &Mask : BitMasks) {
  492. // Check if the flag's bitmask has the bits of the current mask set.
  493. if ((BitMask & Mask.first) == Mask.first) {
  494. if (IsCommaNeeded)
  495. OS << ", ";
  496. IsCommaNeeded = true;
  497. OS << Mask.second;
  498. // Clear the bits which were serialized from the flag's bitmask.
  499. BitMask &= ~(Mask.first);
  500. }
  501. }
  502. if (BitMask) {
  503. // When the resulting flag's bitmask isn't zero, we know that we didn't
  504. // serialize all of the bit flags.
  505. if (IsCommaNeeded)
  506. OS << ", ";
  507. OS << "<unknown bitmask target flag>";
  508. }
  509. OS << ") ";
  510. }
  511. void MachineOperand::printSymbol(raw_ostream &OS, MCSymbol &Sym) {
  512. OS << "<mcsymbol " << Sym << ">";
  513. }
  514. void MachineOperand::printStackObjectReference(raw_ostream &OS,
  515. unsigned FrameIndex,
  516. bool IsFixed, StringRef Name) {
  517. if (IsFixed) {
  518. OS << "%fixed-stack." << FrameIndex;
  519. return;
  520. }
  521. OS << "%stack." << FrameIndex;
  522. if (!Name.empty())
  523. OS << '.' << Name;
  524. }
  525. void MachineOperand::printOperandOffset(raw_ostream &OS, int64_t Offset) {
  526. if (Offset == 0)
  527. return;
  528. if (Offset < 0) {
  529. OS << " - " << -Offset;
  530. return;
  531. }
  532. OS << " + " << Offset;
  533. }
  534. void MachineOperand::printIRSlotNumber(raw_ostream &OS, int Slot) {
  535. if (Slot == -1)
  536. OS << "<badref>";
  537. else
  538. OS << Slot;
  539. }
  540. static void printCFI(raw_ostream &OS, const MCCFIInstruction &CFI,
  541. const TargetRegisterInfo *TRI) {
  542. switch (CFI.getOperation()) {
  543. case MCCFIInstruction::OpSameValue:
  544. OS << "same_value ";
  545. if (MCSymbol *Label = CFI.getLabel())
  546. MachineOperand::printSymbol(OS, *Label);
  547. printCFIRegister(CFI.getRegister(), OS, TRI);
  548. break;
  549. case MCCFIInstruction::OpRememberState:
  550. OS << "remember_state ";
  551. if (MCSymbol *Label = CFI.getLabel())
  552. MachineOperand::printSymbol(OS, *Label);
  553. break;
  554. case MCCFIInstruction::OpRestoreState:
  555. OS << "restore_state ";
  556. if (MCSymbol *Label = CFI.getLabel())
  557. MachineOperand::printSymbol(OS, *Label);
  558. break;
  559. case MCCFIInstruction::OpOffset:
  560. OS << "offset ";
  561. if (MCSymbol *Label = CFI.getLabel())
  562. MachineOperand::printSymbol(OS, *Label);
  563. printCFIRegister(CFI.getRegister(), OS, TRI);
  564. OS << ", " << CFI.getOffset();
  565. break;
  566. case MCCFIInstruction::OpDefCfaRegister:
  567. OS << "def_cfa_register ";
  568. if (MCSymbol *Label = CFI.getLabel())
  569. MachineOperand::printSymbol(OS, *Label);
  570. printCFIRegister(CFI.getRegister(), OS, TRI);
  571. break;
  572. case MCCFIInstruction::OpDefCfaOffset:
  573. OS << "def_cfa_offset ";
  574. if (MCSymbol *Label = CFI.getLabel())
  575. MachineOperand::printSymbol(OS, *Label);
  576. OS << CFI.getOffset();
  577. break;
  578. case MCCFIInstruction::OpDefCfa:
  579. OS << "def_cfa ";
  580. if (MCSymbol *Label = CFI.getLabel())
  581. MachineOperand::printSymbol(OS, *Label);
  582. printCFIRegister(CFI.getRegister(), OS, TRI);
  583. OS << ", " << CFI.getOffset();
  584. break;
  585. case MCCFIInstruction::OpRelOffset:
  586. OS << "rel_offset ";
  587. if (MCSymbol *Label = CFI.getLabel())
  588. MachineOperand::printSymbol(OS, *Label);
  589. printCFIRegister(CFI.getRegister(), OS, TRI);
  590. OS << ", " << CFI.getOffset();
  591. break;
  592. case MCCFIInstruction::OpAdjustCfaOffset:
  593. OS << "adjust_cfa_offset ";
  594. if (MCSymbol *Label = CFI.getLabel())
  595. MachineOperand::printSymbol(OS, *Label);
  596. OS << CFI.getOffset();
  597. break;
  598. case MCCFIInstruction::OpRestore:
  599. OS << "restore ";
  600. if (MCSymbol *Label = CFI.getLabel())
  601. MachineOperand::printSymbol(OS, *Label);
  602. printCFIRegister(CFI.getRegister(), OS, TRI);
  603. break;
  604. case MCCFIInstruction::OpEscape: {
  605. OS << "escape ";
  606. if (MCSymbol *Label = CFI.getLabel())
  607. MachineOperand::printSymbol(OS, *Label);
  608. if (!CFI.getValues().empty()) {
  609. size_t e = CFI.getValues().size() - 1;
  610. for (size_t i = 0; i < e; ++i)
  611. OS << format("0x%02x", uint8_t(CFI.getValues()[i])) << ", ";
  612. OS << format("0x%02x", uint8_t(CFI.getValues()[e])) << ", ";
  613. }
  614. break;
  615. }
  616. case MCCFIInstruction::OpUndefined:
  617. OS << "undefined ";
  618. if (MCSymbol *Label = CFI.getLabel())
  619. MachineOperand::printSymbol(OS, *Label);
  620. printCFIRegister(CFI.getRegister(), OS, TRI);
  621. break;
  622. case MCCFIInstruction::OpRegister:
  623. OS << "register ";
  624. if (MCSymbol *Label = CFI.getLabel())
  625. MachineOperand::printSymbol(OS, *Label);
  626. printCFIRegister(CFI.getRegister(), OS, TRI);
  627. OS << ", ";
  628. printCFIRegister(CFI.getRegister2(), OS, TRI);
  629. break;
  630. case MCCFIInstruction::OpWindowSave:
  631. OS << "window_save ";
  632. if (MCSymbol *Label = CFI.getLabel())
  633. MachineOperand::printSymbol(OS, *Label);
  634. break;
  635. default:
  636. // TODO: Print the other CFI Operations.
  637. OS << "<unserializable cfi directive>";
  638. break;
  639. }
  640. }
  641. void MachineOperand::print(raw_ostream &OS, const TargetRegisterInfo *TRI,
  642. const TargetIntrinsicInfo *IntrinsicInfo) const {
  643. print(OS, LLT{}, TRI, IntrinsicInfo);
  644. }
  645. void MachineOperand::print(raw_ostream &OS, LLT TypeToPrint,
  646. const TargetRegisterInfo *TRI,
  647. const TargetIntrinsicInfo *IntrinsicInfo) const {
  648. tryToGetTargetInfo(*this, TRI, IntrinsicInfo);
  649. ModuleSlotTracker DummyMST(nullptr);
  650. print(OS, DummyMST, TypeToPrint, /*PrintDef=*/false, /*IsStandalone=*/true,
  651. /*ShouldPrintRegisterTies=*/true,
  652. /*TiedOperandIdx=*/0, TRI, IntrinsicInfo);
  653. }
  654. void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
  655. LLT TypeToPrint, bool PrintDef, bool IsStandalone,
  656. bool ShouldPrintRegisterTies,
  657. unsigned TiedOperandIdx,
  658. const TargetRegisterInfo *TRI,
  659. const TargetIntrinsicInfo *IntrinsicInfo) const {
  660. printTargetFlags(OS, *this);
  661. switch (getType()) {
  662. case MachineOperand::MO_Register: {
  663. unsigned Reg = getReg();
  664. if (isImplicit())
  665. OS << (isDef() ? "implicit-def " : "implicit ");
  666. else if (PrintDef && isDef())
  667. // Print the 'def' flag only when the operand is defined after '='.
  668. OS << "def ";
  669. if (isInternalRead())
  670. OS << "internal ";
  671. if (isDead())
  672. OS << "dead ";
  673. if (isKill())
  674. OS << "killed ";
  675. if (isUndef())
  676. OS << "undef ";
  677. if (isEarlyClobber())
  678. OS << "early-clobber ";
  679. if (isDebug())
  680. OS << "debug-use ";
  681. if (TargetRegisterInfo::isPhysicalRegister(getReg()) && isRenamable())
  682. OS << "renamable ";
  683. const MachineRegisterInfo *MRI = nullptr;
  684. if (TargetRegisterInfo::isVirtualRegister(Reg)) {
  685. if (const MachineFunction *MF = getMFIfAvailable(*this)) {
  686. MRI = &MF->getRegInfo();
  687. }
  688. }
  689. OS << printReg(Reg, TRI, 0, MRI);
  690. // Print the sub register.
  691. if (unsigned SubReg = getSubReg()) {
  692. if (TRI)
  693. OS << '.' << TRI->getSubRegIndexName(SubReg);
  694. else
  695. OS << ".subreg" << SubReg;
  696. }
  697. // Print the register class / bank.
  698. if (TargetRegisterInfo::isVirtualRegister(Reg)) {
  699. if (const MachineFunction *MF = getMFIfAvailable(*this)) {
  700. const MachineRegisterInfo &MRI = MF->getRegInfo();
  701. if (IsStandalone || !PrintDef || MRI.def_empty(Reg)) {
  702. OS << ':';
  703. OS << printRegClassOrBank(Reg, MRI, TRI);
  704. }
  705. }
  706. }
  707. // Print ties.
  708. if (ShouldPrintRegisterTies && isTied() && !isDef())
  709. OS << "(tied-def " << TiedOperandIdx << ")";
  710. // Print types.
  711. if (TypeToPrint.isValid())
  712. OS << '(' << TypeToPrint << ')';
  713. break;
  714. }
  715. case MachineOperand::MO_Immediate:
  716. OS << getImm();
  717. break;
  718. case MachineOperand::MO_CImmediate:
  719. getCImm()->printAsOperand(OS, /*PrintType=*/true, MST);
  720. break;
  721. case MachineOperand::MO_FPImmediate:
  722. getFPImm()->printAsOperand(OS, /*PrintType=*/true, MST);
  723. break;
  724. case MachineOperand::MO_MachineBasicBlock:
  725. OS << printMBBReference(*getMBB());
  726. break;
  727. case MachineOperand::MO_FrameIndex: {
  728. int FrameIndex = getIndex();
  729. bool IsFixed = false;
  730. const MachineFrameInfo *MFI = nullptr;
  731. if (const MachineFunction *MF = getMFIfAvailable(*this))
  732. MFI = &MF->getFrameInfo();
  733. printFrameIndex(OS, FrameIndex, IsFixed, MFI);
  734. break;
  735. }
  736. case MachineOperand::MO_ConstantPoolIndex:
  737. OS << "%const." << getIndex();
  738. printOperandOffset(OS, getOffset());
  739. break;
  740. case MachineOperand::MO_TargetIndex: {
  741. OS << "target-index(";
  742. const char *Name = "<unknown>";
  743. if (const MachineFunction *MF = getMFIfAvailable(*this))
  744. if (const auto *TargetIndexName = getTargetIndexName(*MF, getIndex()))
  745. Name = TargetIndexName;
  746. OS << Name << ')';
  747. printOperandOffset(OS, getOffset());
  748. break;
  749. }
  750. case MachineOperand::MO_JumpTableIndex:
  751. OS << printJumpTableEntryReference(getIndex());
  752. break;
  753. case MachineOperand::MO_GlobalAddress:
  754. getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST);
  755. printOperandOffset(OS, getOffset());
  756. break;
  757. case MachineOperand::MO_ExternalSymbol: {
  758. StringRef Name = getSymbolName();
  759. OS << '&';
  760. if (Name.empty()) {
  761. OS << "\"\"";
  762. } else {
  763. printLLVMNameWithoutPrefix(OS, Name);
  764. }
  765. printOperandOffset(OS, getOffset());
  766. break;
  767. }
  768. case MachineOperand::MO_BlockAddress: {
  769. OS << "blockaddress(";
  770. getBlockAddress()->getFunction()->printAsOperand(OS, /*PrintType=*/false,
  771. MST);
  772. OS << ", ";
  773. printIRBlockReference(OS, *getBlockAddress()->getBasicBlock(), MST);
  774. OS << ')';
  775. MachineOperand::printOperandOffset(OS, getOffset());
  776. break;
  777. }
  778. case MachineOperand::MO_RegisterMask: {
  779. OS << "<regmask";
  780. if (TRI) {
  781. unsigned NumRegsInMask = 0;
  782. unsigned NumRegsEmitted = 0;
  783. for (unsigned i = 0; i < TRI->getNumRegs(); ++i) {
  784. unsigned MaskWord = i / 32;
  785. unsigned MaskBit = i % 32;
  786. if (getRegMask()[MaskWord] & (1 << MaskBit)) {
  787. if (PrintRegMaskNumRegs < 0 ||
  788. NumRegsEmitted <= static_cast<unsigned>(PrintRegMaskNumRegs)) {
  789. OS << " " << printReg(i, TRI);
  790. NumRegsEmitted++;
  791. }
  792. NumRegsInMask++;
  793. }
  794. }
  795. if (NumRegsEmitted != NumRegsInMask)
  796. OS << " and " << (NumRegsInMask - NumRegsEmitted) << " more...";
  797. } else {
  798. OS << " ...";
  799. }
  800. OS << ">";
  801. break;
  802. }
  803. case MachineOperand::MO_RegisterLiveOut: {
  804. const uint32_t *RegMask = getRegLiveOut();
  805. OS << "liveout(";
  806. if (!TRI) {
  807. OS << "<unknown>";
  808. } else {
  809. bool IsCommaNeeded = false;
  810. for (unsigned Reg = 0, E = TRI->getNumRegs(); Reg < E; ++Reg) {
  811. if (RegMask[Reg / 32] & (1U << (Reg % 32))) {
  812. if (IsCommaNeeded)
  813. OS << ", ";
  814. OS << printReg(Reg, TRI);
  815. IsCommaNeeded = true;
  816. }
  817. }
  818. }
  819. OS << ")";
  820. break;
  821. }
  822. case MachineOperand::MO_Metadata:
  823. getMetadata()->printAsOperand(OS, MST);
  824. break;
  825. case MachineOperand::MO_MCSymbol:
  826. printSymbol(OS, *getMCSymbol());
  827. break;
  828. case MachineOperand::MO_CFIIndex: {
  829. if (const MachineFunction *MF = getMFIfAvailable(*this))
  830. printCFI(OS, MF->getFrameInstructions()[getCFIIndex()], TRI);
  831. else
  832. OS << "<cfi directive>";
  833. break;
  834. }
  835. case MachineOperand::MO_IntrinsicID: {
  836. Intrinsic::ID ID = getIntrinsicID();
  837. if (ID < Intrinsic::num_intrinsics)
  838. OS << "intrinsic(@" << Intrinsic::getName(ID, None) << ')';
  839. else if (IntrinsicInfo)
  840. OS << "intrinsic(@" << IntrinsicInfo->getName(ID) << ')';
  841. else
  842. OS << "intrinsic(" << ID << ')';
  843. break;
  844. }
  845. case MachineOperand::MO_Predicate: {
  846. auto Pred = static_cast<CmpInst::Predicate>(getPredicate());
  847. OS << (CmpInst::isIntPredicate(Pred) ? "int" : "float") << "pred("
  848. << CmpInst::getPredicateName(Pred) << ')';
  849. break;
  850. }
  851. }
  852. }
  853. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  854. LLVM_DUMP_METHOD void MachineOperand::dump() const { dbgs() << *this << '\n'; }
  855. #endif
  856. //===----------------------------------------------------------------------===//
  857. // MachineMemOperand Implementation
  858. //===----------------------------------------------------------------------===//
  859. /// getAddrSpace - Return the LLVM IR address space number that this pointer
  860. /// points into.
  861. unsigned MachinePointerInfo::getAddrSpace() const { return AddrSpace; }
  862. /// isDereferenceable - Return true if V is always dereferenceable for
  863. /// Offset + Size byte.
  864. bool MachinePointerInfo::isDereferenceable(unsigned Size, LLVMContext &C,
  865. const DataLayout &DL) const {
  866. if (!V.is<const Value *>())
  867. return false;
  868. const Value *BasePtr = V.get<const Value *>();
  869. if (BasePtr == nullptr)
  870. return false;
  871. return isDereferenceableAndAlignedPointer(
  872. BasePtr, 1, APInt(DL.getPointerSizeInBits(), Offset + Size), DL);
  873. }
  874. /// getConstantPool - Return a MachinePointerInfo record that refers to the
  875. /// constant pool.
  876. MachinePointerInfo MachinePointerInfo::getConstantPool(MachineFunction &MF) {
  877. return MachinePointerInfo(MF.getPSVManager().getConstantPool());
  878. }
  879. /// getFixedStack - Return a MachinePointerInfo record that refers to the
  880. /// the specified FrameIndex.
  881. MachinePointerInfo MachinePointerInfo::getFixedStack(MachineFunction &MF,
  882. int FI, int64_t Offset) {
  883. return MachinePointerInfo(MF.getPSVManager().getFixedStack(FI), Offset);
  884. }
  885. MachinePointerInfo MachinePointerInfo::getJumpTable(MachineFunction &MF) {
  886. return MachinePointerInfo(MF.getPSVManager().getJumpTable());
  887. }
  888. MachinePointerInfo MachinePointerInfo::getGOT(MachineFunction &MF) {
  889. return MachinePointerInfo(MF.getPSVManager().getGOT());
  890. }
  891. MachinePointerInfo MachinePointerInfo::getStack(MachineFunction &MF,
  892. int64_t Offset, uint8_t ID) {
  893. return MachinePointerInfo(MF.getPSVManager().getStack(), Offset, ID);
  894. }
  895. MachinePointerInfo MachinePointerInfo::getUnknownStack(MachineFunction &MF) {
  896. return MachinePointerInfo(MF.getDataLayout().getAllocaAddrSpace());
  897. }
  898. MachineMemOperand::MachineMemOperand(MachinePointerInfo ptrinfo, Flags f,
  899. uint64_t s, uint64_t a,
  900. const AAMDNodes &AAInfo,
  901. const MDNode *Ranges, SyncScope::ID SSID,
  902. AtomicOrdering Ordering,
  903. AtomicOrdering FailureOrdering)
  904. : PtrInfo(ptrinfo), Size(s), FlagVals(f), BaseAlignLog2(Log2_32(a) + 1),
  905. AAInfo(AAInfo), Ranges(Ranges) {
  906. assert((PtrInfo.V.isNull() || PtrInfo.V.is<const PseudoSourceValue *>() ||
  907. isa<PointerType>(PtrInfo.V.get<const Value *>()->getType())) &&
  908. "invalid pointer value");
  909. assert(getBaseAlignment() == a && "Alignment is not a power of 2!");
  910. assert((isLoad() || isStore()) && "Not a load/store!");
  911. AtomicInfo.SSID = static_cast<unsigned>(SSID);
  912. assert(getSyncScopeID() == SSID && "Value truncated");
  913. AtomicInfo.Ordering = static_cast<unsigned>(Ordering);
  914. assert(getOrdering() == Ordering && "Value truncated");
  915. AtomicInfo.FailureOrdering = static_cast<unsigned>(FailureOrdering);
  916. assert(getFailureOrdering() == FailureOrdering && "Value truncated");
  917. }
  918. /// Profile - Gather unique data for the object.
  919. ///
  920. void MachineMemOperand::Profile(FoldingSetNodeID &ID) const {
  921. ID.AddInteger(getOffset());
  922. ID.AddInteger(Size);
  923. ID.AddPointer(getOpaqueValue());
  924. ID.AddInteger(getFlags());
  925. ID.AddInteger(getBaseAlignment());
  926. }
  927. void MachineMemOperand::refineAlignment(const MachineMemOperand *MMO) {
  928. // The Value and Offset may differ due to CSE. But the flags and size
  929. // should be the same.
  930. assert(MMO->getFlags() == getFlags() && "Flags mismatch!");
  931. assert(MMO->getSize() == getSize() && "Size mismatch!");
  932. if (MMO->getBaseAlignment() >= getBaseAlignment()) {
  933. // Update the alignment value.
  934. BaseAlignLog2 = Log2_32(MMO->getBaseAlignment()) + 1;
  935. // Also update the base and offset, because the new alignment may
  936. // not be applicable with the old ones.
  937. PtrInfo = MMO->PtrInfo;
  938. }
  939. }
  940. /// getAlignment - Return the minimum known alignment in bytes of the
  941. /// actual memory reference.
  942. uint64_t MachineMemOperand::getAlignment() const {
  943. return MinAlign(getBaseAlignment(), getOffset());
  944. }
  945. void MachineMemOperand::print(raw_ostream &OS) const {
  946. ModuleSlotTracker DummyMST(nullptr);
  947. print(OS, DummyMST);
  948. }
  949. void MachineMemOperand::print(raw_ostream &OS, ModuleSlotTracker &MST) const {
  950. SmallVector<StringRef, 0> SSNs;
  951. LLVMContext Ctx;
  952. print(OS, MST, SSNs, Ctx, nullptr, nullptr);
  953. }
  954. void MachineMemOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
  955. SmallVectorImpl<StringRef> &SSNs,
  956. const LLVMContext &Context,
  957. const MachineFrameInfo *MFI,
  958. const TargetInstrInfo *TII) const {
  959. OS << '(';
  960. if (isVolatile())
  961. OS << "volatile ";
  962. if (isNonTemporal())
  963. OS << "non-temporal ";
  964. if (isDereferenceable())
  965. OS << "dereferenceable ";
  966. if (isInvariant())
  967. OS << "invariant ";
  968. if (getFlags() & MachineMemOperand::MOTargetFlag1)
  969. OS << '"' << getTargetMMOFlagName(*TII, MachineMemOperand::MOTargetFlag1)
  970. << "\" ";
  971. if (getFlags() & MachineMemOperand::MOTargetFlag2)
  972. OS << '"' << getTargetMMOFlagName(*TII, MachineMemOperand::MOTargetFlag2)
  973. << "\" ";
  974. if (getFlags() & MachineMemOperand::MOTargetFlag3)
  975. OS << '"' << getTargetMMOFlagName(*TII, MachineMemOperand::MOTargetFlag3)
  976. << "\" ";
  977. assert((isLoad() || isStore()) &&
  978. "machine memory operand must be a load or store (or both)");
  979. if (isLoad())
  980. OS << "load ";
  981. if (isStore())
  982. OS << "store ";
  983. printSyncScope(OS, Context, getSyncScopeID(), SSNs);
  984. if (getOrdering() != AtomicOrdering::NotAtomic)
  985. OS << toIRString(getOrdering()) << ' ';
  986. if (getFailureOrdering() != AtomicOrdering::NotAtomic)
  987. OS << toIRString(getFailureOrdering()) << ' ';
  988. if (getSize() == MemoryLocation::UnknownSize)
  989. OS << "unknown-size";
  990. else
  991. OS << getSize();
  992. if (const Value *Val = getValue()) {
  993. OS << ((isLoad() && isStore()) ? " on " : isLoad() ? " from " : " into ");
  994. printIRValueReference(OS, *Val, MST);
  995. } else if (const PseudoSourceValue *PVal = getPseudoValue()) {
  996. OS << ((isLoad() && isStore()) ? " on " : isLoad() ? " from " : " into ");
  997. assert(PVal && "Expected a pseudo source value");
  998. switch (PVal->kind()) {
  999. case PseudoSourceValue::Stack:
  1000. OS << "stack";
  1001. break;
  1002. case PseudoSourceValue::GOT:
  1003. OS << "got";
  1004. break;
  1005. case PseudoSourceValue::JumpTable:
  1006. OS << "jump-table";
  1007. break;
  1008. case PseudoSourceValue::ConstantPool:
  1009. OS << "constant-pool";
  1010. break;
  1011. case PseudoSourceValue::FixedStack: {
  1012. int FrameIndex = cast<FixedStackPseudoSourceValue>(PVal)->getFrameIndex();
  1013. bool IsFixed = true;
  1014. printFrameIndex(OS, FrameIndex, IsFixed, MFI);
  1015. break;
  1016. }
  1017. case PseudoSourceValue::GlobalValueCallEntry:
  1018. OS << "call-entry ";
  1019. cast<GlobalValuePseudoSourceValue>(PVal)->getValue()->printAsOperand(
  1020. OS, /*PrintType=*/false, MST);
  1021. break;
  1022. case PseudoSourceValue::ExternalSymbolCallEntry:
  1023. OS << "call-entry &";
  1024. printLLVMNameWithoutPrefix(
  1025. OS, cast<ExternalSymbolPseudoSourceValue>(PVal)->getSymbol());
  1026. break;
  1027. case PseudoSourceValue::TargetCustom:
  1028. // FIXME: This is not necessarily the correct MIR serialization format for
  1029. // a custom pseudo source value, but at least it allows
  1030. // -print-machineinstrs to work on a target with custom pseudo source
  1031. // values.
  1032. OS << "custom ";
  1033. PVal->printCustom(OS);
  1034. break;
  1035. }
  1036. }
  1037. MachineOperand::printOperandOffset(OS, getOffset());
  1038. if (getBaseAlignment() != getSize())
  1039. OS << ", align " << getBaseAlignment();
  1040. auto AAInfo = getAAInfo();
  1041. if (AAInfo.TBAA) {
  1042. OS << ", !tbaa ";
  1043. AAInfo.TBAA->printAsOperand(OS, MST);
  1044. }
  1045. if (AAInfo.Scope) {
  1046. OS << ", !alias.scope ";
  1047. AAInfo.Scope->printAsOperand(OS, MST);
  1048. }
  1049. if (AAInfo.NoAlias) {
  1050. OS << ", !noalias ";
  1051. AAInfo.NoAlias->printAsOperand(OS, MST);
  1052. }
  1053. if (getRanges()) {
  1054. OS << ", !range ";
  1055. getRanges()->printAsOperand(OS, MST);
  1056. }
  1057. // FIXME: Implement addrspace printing/parsing in MIR.
  1058. // For now, print this even though parsing it is not available in MIR.
  1059. if (unsigned AS = getAddrSpace())
  1060. OS << ", addrspace " << AS;
  1061. OS << ')';
  1062. }