MachineOperand.cpp 38 KB

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