MachineOperand.cpp 38 KB

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