LLVM 21.0.0git
MachineOperand.cpp
Go to the documentation of this file.
1//===- lib/CodeGen/MachineOperand.cpp -------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file Methods common to all machine operands.
10//
11//===----------------------------------------------------------------------===//
12
16#include "llvm/Analysis/Loads.h"
24#include "llvm/Config/llvm-config.h"
25#include "llvm/IR/Constants.h"
29#include "llvm/MC/MCDwarf.h"
31#include <optional>
32
33using namespace llvm;
34
35static cl::opt<int>
36 PrintRegMaskNumRegs("print-regmask-num-regs",
37 cl::desc("Number of registers to limit to when "
38 "printing regmask operands in IR dumps. "
39 "unlimited = -1"),
40 cl::init(32), cl::Hidden);
41
43 if (const MachineInstr *MI = MO.getParent())
44 if (const MachineBasicBlock *MBB = MI->getParent())
45 if (const MachineFunction *MF = MBB->getParent())
46 return MF;
47 return nullptr;
48}
49
51 return const_cast<MachineFunction *>(
52 getMFIfAvailable(const_cast<const MachineOperand &>(MO)));
53}
54
56 assert(getParent() && "Operand does not belong to any instruction!");
57 return getParent()->getOperandNo(this);
58}
59
61 if (getReg() == Reg)
62 return; // No change.
63
64 // Clear the IsRenamable bit to keep it conservatively correct.
65 IsRenamable = false;
66
67 // Otherwise, we have to change the register. If this operand is embedded
68 // into a machine function, we need to update the old and new register's
69 // use/def lists.
70 if (MachineFunction *MF = getMFIfAvailable(*this)) {
71 MachineRegisterInfo &MRI = MF->getRegInfo();
72 MRI.removeRegOperandFromUseList(this);
73 SmallContents.RegNo = Reg.id();
74 MRI.addRegOperandToUseList(this);
75 return;
76 }
77
78 // Otherwise, just change the register, no problem. :)
79 SmallContents.RegNo = Reg.id();
80}
81
82void MachineOperand::substVirtReg(Register Reg, unsigned SubIdx,
83 const TargetRegisterInfo &TRI) {
84 assert(Reg.isVirtual());
85 if (SubIdx && getSubReg())
86 SubIdx = TRI.composeSubRegIndices(SubIdx, getSubReg());
87 setReg(Reg);
88 if (SubIdx)
89 setSubReg(SubIdx);
90}
91
93 assert(Reg.isPhysical());
94 if (getSubReg()) {
95 Reg = TRI.getSubReg(Reg, getSubReg());
96 // Note that getSubReg() may return 0 if the sub-register doesn't exist.
97 // That won't happen in legal code.
98 setSubReg(0);
99 if (isDef())
100 setIsUndef(false);
101 }
102 setReg(Reg);
103}
104
105/// Change a def to a use, or a use to a def.
107 assert(isReg() && "Wrong MachineOperand accessor");
108 assert((!Val || !isDebug()) && "Marking a debug operation as def");
109 if (IsDef == Val)
110 return;
111 assert(!IsDeadOrKill && "Changing def/use with dead/kill set not supported");
112 // MRI may keep uses and defs in different list positions.
113 if (MachineFunction *MF = getMFIfAvailable(*this)) {
114 MachineRegisterInfo &MRI = MF->getRegInfo();
115 MRI.removeRegOperandFromUseList(this);
116 IsDef = Val;
117 MRI.addRegOperandToUseList(this);
118 return;
119 }
120 IsDef = Val;
121}
122
124 assert(isReg() && "Wrong MachineOperand accessor");
125 assert(getReg().isPhysical() &&
126 "isRenamable should only be checked on physical registers");
127 if (!IsRenamable)
128 return false;
129
130 const MachineInstr *MI = getParent();
131 if (!MI)
132 return true;
133
134 if (isDef())
135 return !MI->hasExtraDefRegAllocReq(MachineInstr::IgnoreBundle);
136
137 assert(isUse() && "Reg is not def or use");
138 return !MI->hasExtraSrcRegAllocReq(MachineInstr::IgnoreBundle);
139}
140
142 assert(isReg() && "Wrong MachineOperand accessor");
143 assert(getReg().isPhysical() &&
144 "setIsRenamable should only be called on physical registers");
145 IsRenamable = Val;
146}
147
148// If this operand is currently a register operand, and if this is in a
149// function, deregister the operand from the register's use/def list.
150void MachineOperand::removeRegFromUses() {
151 if (!isReg() || !isOnRegUseList())
152 return;
153
154 if (MachineFunction *MF = getMFIfAvailable(*this))
155 MF->getRegInfo().removeRegOperandFromUseList(this);
156}
157
158/// ChangeToImmediate - Replace this operand with a new immediate operand of
159/// the specified value. If an operand is known to be an immediate already,
160/// the setImm method should be used.
161void MachineOperand::ChangeToImmediate(int64_t ImmVal, unsigned TargetFlags) {
162 assert((!isReg() || !isTied()) && "Cannot change a tied operand into an imm");
163
164 removeRegFromUses();
165
166 OpKind = MO_Immediate;
167 Contents.ImmVal = ImmVal;
168 setTargetFlags(TargetFlags);
169}
170
172 unsigned TargetFlags) {
173 assert((!isReg() || !isTied()) && "Cannot change a tied operand into an imm");
174
175 removeRegFromUses();
176
177 OpKind = MO_FPImmediate;
178 Contents.CFP = FPImm;
179 setTargetFlags(TargetFlags);
180}
181
182void MachineOperand::ChangeToES(const char *SymName,
183 unsigned TargetFlags) {
184 assert((!isReg() || !isTied()) &&
185 "Cannot change a tied operand into an external symbol");
186
187 removeRegFromUses();
188
189 OpKind = MO_ExternalSymbol;
190 Contents.OffsetedInfo.Val.SymbolName = SymName;
191 setOffset(0); // Offset is always 0.
192 setTargetFlags(TargetFlags);
193}
194
196 unsigned TargetFlags) {
197 assert((!isReg() || !isTied()) &&
198 "Cannot change a tied operand into a global address");
199
200 removeRegFromUses();
201
202 OpKind = MO_GlobalAddress;
203 Contents.OffsetedInfo.Val.GV = GV;
205 setTargetFlags(TargetFlags);
206}
207
209 unsigned TargetFlags) {
210 assert((!isReg() || !isTied()) &&
211 "Cannot change a tied operand into a block address");
212
213 removeRegFromUses();
214
215 OpKind = MO_BlockAddress;
216 Contents.OffsetedInfo.Val.BA = BA;
218 setTargetFlags(TargetFlags);
219}
220
221void MachineOperand::ChangeToMCSymbol(MCSymbol *Sym, unsigned TargetFlags) {
222 assert((!isReg() || !isTied()) &&
223 "Cannot change a tied operand into an MCSymbol");
224
225 removeRegFromUses();
226
227 OpKind = MO_MCSymbol;
228 Contents.Sym = Sym;
229 setTargetFlags(TargetFlags);
230}
231
232void MachineOperand::ChangeToFrameIndex(int Idx, unsigned TargetFlags) {
233 assert((!isReg() || !isTied()) &&
234 "Cannot change a tied operand into a FrameIndex");
235
236 removeRegFromUses();
237
238 OpKind = MO_FrameIndex;
239 setIndex(Idx);
240 setTargetFlags(TargetFlags);
241}
242
244 unsigned TargetFlags) {
245 assert((!isReg() || !isTied()) &&
246 "Cannot change a tied operand into a FrameIndex");
247
248 removeRegFromUses();
249
250 OpKind = MO_TargetIndex;
251 setIndex(Idx);
253 setTargetFlags(TargetFlags);
254}
255
256void MachineOperand::ChangeToDbgInstrRef(unsigned InstrIdx, unsigned OpIdx,
257 unsigned TargetFlags) {
258 assert((!isReg() || !isTied()) &&
259 "Cannot change a tied operand into a DbgInstrRef");
260
261 removeRegFromUses();
262
263 OpKind = MO_DbgInstrRef;
264 setInstrRefInstrIndex(InstrIdx);
265 setInstrRefOpIndex(OpIdx);
266 setTargetFlags(TargetFlags);
267}
268
269/// ChangeToRegister - Replace this operand with a new register operand of
270/// the specified value. If an operand is known to be an register already,
271/// the setReg method should be used.
272void MachineOperand::ChangeToRegister(Register Reg, bool isDef, bool isImp,
273 bool isKill, bool isDead, bool isUndef,
274 bool isDebug) {
275 MachineRegisterInfo *RegInfo = nullptr;
276 if (MachineFunction *MF = getMFIfAvailable(*this))
277 RegInfo = &MF->getRegInfo();
278 // If this operand is already a register operand, remove it from the
279 // register's use/def lists.
280 bool WasReg = isReg();
281 if (RegInfo && WasReg)
282 RegInfo->removeRegOperandFromUseList(this);
283
284 // Ensure debug instructions set debug flag on register uses.
285 const MachineInstr *MI = getParent();
286 if (!isDef && MI && MI->isDebugInstr())
287 isDebug = true;
288
289 // Change this to a register and set the reg#.
290 assert(!(isDead && !isDef) && "Dead flag on non-def");
291 assert(!(isKill && isDef) && "Kill flag on def");
292 OpKind = MO_Register;
293 SmallContents.RegNo = Reg.id();
294 SubReg_TargetFlags = 0;
295 IsDef = isDef;
296 IsImp = isImp;
297 IsDeadOrKill = isKill | isDead;
298 IsRenamable = false;
299 IsUndef = isUndef;
300 IsInternalRead = false;
301 IsEarlyClobber = false;
302 IsDebug = isDebug;
303 // Ensure isOnRegUseList() returns false.
304 Contents.Reg.Prev = nullptr;
305 // Preserve the tie when the operand was already a register.
306 if (!WasReg)
307 TiedTo = 0;
308
309 // If this operand is embedded in a function, add the operand to the
310 // register's use/def list.
311 if (RegInfo)
312 RegInfo->addRegOperandToUseList(this);
313}
314
315/// isIdenticalTo - Return true if this operand is identical to the specified
316/// operand. Note that this should stay in sync with the hash_value overload
317/// below.
319 if (getType() != Other.getType() ||
320 getTargetFlags() != Other.getTargetFlags())
321 return false;
322
323 switch (getType()) {
325 return getReg() == Other.getReg() && isDef() == Other.isDef() &&
326 getSubReg() == Other.getSubReg();
328 return getImm() == Other.getImm();
330 return getCImm() == Other.getCImm();
332 return getFPImm() == Other.getFPImm();
334 return getMBB() == Other.getMBB();
336 return getIndex() == Other.getIndex();
339 return getIndex() == Other.getIndex() && getOffset() == Other.getOffset();
341 return getIndex() == Other.getIndex();
343 return getGlobal() == Other.getGlobal() && getOffset() == Other.getOffset();
345 return strcmp(getSymbolName(), Other.getSymbolName()) == 0 &&
346 getOffset() == Other.getOffset();
348 return getBlockAddress() == Other.getBlockAddress() &&
349 getOffset() == Other.getOffset();
352 // Shallow compare of the two RegMasks
353 const uint32_t *RegMask = getRegMask();
354 const uint32_t *OtherRegMask = Other.getRegMask();
355 if (RegMask == OtherRegMask)
356 return true;
357
358 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
359 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
360 unsigned RegMaskSize = MachineOperand::getRegMaskSize(TRI->getNumRegs());
361 // Deep compare of the two RegMasks
362 return std::equal(RegMask, RegMask + RegMaskSize, OtherRegMask);
363 }
364 // We don't know the size of the RegMask, so we can't deep compare the two
365 // reg masks.
366 return false;
367 }
369 return getMCSymbol() == Other.getMCSymbol();
371 return getInstrRefInstrIndex() == Other.getInstrRefInstrIndex() &&
372 getInstrRefOpIndex() == Other.getInstrRefOpIndex();
374 return getCFIIndex() == Other.getCFIIndex();
376 return getMetadata() == Other.getMetadata();
378 return getIntrinsicID() == Other.getIntrinsicID();
380 return getPredicate() == Other.getPredicate();
382 return getShuffleMask() == Other.getShuffleMask();
383 }
384 llvm_unreachable("Invalid machine operand type");
385}
386
387// Note: this must stay exactly in sync with isIdenticalTo above.
389 switch (MO.getType()) {
391 // Register operands don't have target flags.
392 return hash_combine(MO.getType(), MO.getReg().id(), MO.getSubReg(),
393 MO.isDef());
395 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getImm());
397 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getCImm());
399 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getFPImm());
401 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMBB());
403 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex());
406 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex(),
407 MO.getOffset());
409 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex());
411 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getOffset(),
414 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getGlobal(),
415 MO.getOffset());
417 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getBlockAddress(),
418 MO.getOffset());
421 if (const MachineFunction *MF = getMFIfAvailable(MO)) {
422 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
423 unsigned RegMaskSize = MachineOperand::getRegMaskSize(TRI->getNumRegs());
424 const uint32_t *RegMask = MO.getRegMask();
425 std::vector<stable_hash> RegMaskHashes(RegMask, RegMask + RegMaskSize);
426 return hash_combine(MO.getType(), MO.getTargetFlags(),
427 stable_hash_combine(RegMaskHashes));
428 }
429
430 assert(0 && "MachineOperand not associated with any MachineFunction");
431 return hash_combine(MO.getType(), MO.getTargetFlags());
432 }
434 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMetadata());
436 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMCSymbol());
438 return hash_combine(MO.getType(), MO.getTargetFlags(),
441 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getCFIIndex());
443 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIntrinsicID());
445 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getPredicate());
447 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getShuffleMask());
448 }
449 llvm_unreachable("Invalid machine operand type");
450}
451
452// Try to crawl up to the machine function and get TRI from it.
453static void tryToGetTargetInfo(const MachineOperand &MO,
454 const TargetRegisterInfo *&TRI) {
455 if (const MachineFunction *MF = getMFIfAvailable(MO)) {
456 TRI = MF->getSubtarget().getRegisterInfo();
457 }
458}
459
460static const char *getTargetIndexName(const MachineFunction &MF, int Index) {
461 const auto *TII = MF.getSubtarget().getInstrInfo();
462 assert(TII && "expected instruction info");
463 auto Indices = TII->getSerializableTargetIndices();
464 auto Found = find_if(Indices, [&](const std::pair<int, const char *> &I) {
465 return I.first == Index;
466 });
467 if (Found != Indices.end())
468 return Found->second;
469 return nullptr;
470}
471
473 const MachineFunction *MF = getMFIfAvailable(*this);
474 return MF ? ::getTargetIndexName(*MF, this->getIndex()) : nullptr;
475}
476
477static const char *getTargetFlagName(const TargetInstrInfo *TII, unsigned TF) {
479 for (const auto &I : Flags) {
480 if (I.first == TF) {
481 return I.second;
482 }
483 }
484 return nullptr;
485}
486
487static void printCFIRegister(unsigned DwarfReg, raw_ostream &OS,
488 const TargetRegisterInfo *TRI) {
489 if (!TRI) {
490 OS << "%dwarfreg." << DwarfReg;
491 return;
492 }
493
494 if (std::optional<MCRegister> Reg = TRI->getLLVMRegNum(DwarfReg, true))
495 OS << printReg(*Reg, TRI);
496 else
497 OS << "<badreg>";
498}
499
501 ModuleSlotTracker &MST) {
502 OS << "%ir-block.";
503 if (BB.hasName()) {
505 return;
506 }
507 std::optional<int> Slot;
508 if (const Function *F = BB.getParent()) {
509 if (F == MST.getCurrentFunction()) {
510 Slot = MST.getLocalSlot(&BB);
511 } else if (const Module *M = F->getParent()) {
512 ModuleSlotTracker CustomMST(M, /*ShouldInitializeAllMetadata=*/false);
513 CustomMST.incorporateFunction(*F);
514 Slot = CustomMST.getLocalSlot(&BB);
515 }
516 }
517 if (Slot)
519 else
520 OS << "<unknown>";
521}
522
523static void printSyncScope(raw_ostream &OS, const LLVMContext &Context,
524 SyncScope::ID SSID,
526 switch (SSID) {
528 break;
529 default:
530 if (SSNs.empty())
531 Context.getSyncScopeNames(SSNs);
532
533 OS << "syncscope(\"";
534 printEscapedString(SSNs[SSID], OS);
535 OS << "\") ";
536 break;
537 }
538}
539
540static const char *getTargetMMOFlagName(const TargetInstrInfo &TII,
541 unsigned TMMOFlag) {
542 auto Flags = TII.getSerializableMachineMemOperandTargetFlags();
543 for (const auto &I : Flags) {
544 if (I.first == TMMOFlag) {
545 return I.second;
546 }
547 }
548 return nullptr;
549}
550
551static void printFrameIndex(raw_ostream& OS, int FrameIndex, bool IsFixed,
552 const MachineFrameInfo *MFI) {
554 if (MFI) {
555 IsFixed = MFI->isFixedObjectIndex(FrameIndex);
556 if (const AllocaInst *Alloca = MFI->getObjectAllocation(FrameIndex))
557 if (Alloca->hasName())
558 Name = Alloca->getName();
559 if (IsFixed)
560 FrameIndex -= MFI->getObjectIndexBegin();
561 }
563}
564
566 const TargetRegisterInfo *TRI) {
567 OS << "%subreg.";
568 if (TRI && Index != 0 && Index < TRI->getNumSubRegIndices())
569 OS << TRI->getSubRegIndexName(Index);
570 else
571 OS << Index;
572}
573
575 const MachineOperand &Op) {
576 if (!Op.getTargetFlags())
577 return;
579 if (!MF)
580 return;
581
582 const auto *TII = MF->getSubtarget().getInstrInfo();
583 assert(TII && "expected instruction info");
584 auto Flags = TII->decomposeMachineOperandsTargetFlags(Op.getTargetFlags());
585 OS << "target-flags(";
586 const bool HasDirectFlags = Flags.first;
587 const bool HasBitmaskFlags = Flags.second;
588 if (!HasDirectFlags && !HasBitmaskFlags) {
589 OS << "<unknown>) ";
590 return;
591 }
592 if (HasDirectFlags) {
593 if (const auto *Name = getTargetFlagName(TII, Flags.first))
594 OS << Name;
595 else
596 OS << "<unknown target flag>";
597 }
598 if (!HasBitmaskFlags) {
599 OS << ") ";
600 return;
601 }
602 bool IsCommaNeeded = HasDirectFlags;
603 unsigned BitMask = Flags.second;
605 for (const auto &Mask : BitMasks) {
606 // Check if the flag's bitmask has the bits of the current mask set.
607 if ((BitMask & Mask.first) == Mask.first) {
608 if (IsCommaNeeded)
609 OS << ", ";
610 IsCommaNeeded = true;
611 OS << Mask.second;
612 // Clear the bits which were serialized from the flag's bitmask.
613 BitMask &= ~(Mask.first);
614 }
615 }
616 if (BitMask) {
617 // When the resulting flag's bitmask isn't zero, we know that we didn't
618 // serialize all of the bit flags.
619 if (IsCommaNeeded)
620 OS << ", ";
621 OS << "<unknown bitmask target flag>";
622 }
623 OS << ") ";
624}
625
627 OS << "<mcsymbol " << Sym << ">";
628}
629
631 unsigned FrameIndex,
632 bool IsFixed, StringRef Name) {
633 if (IsFixed) {
634 OS << "%fixed-stack." << FrameIndex;
635 return;
636 }
637
638 OS << "%stack." << FrameIndex;
639 if (!Name.empty())
640 OS << '.' << Name;
641}
642
644 if (Offset == 0)
645 return;
646 if (Offset < 0) {
647 OS << " - " << -Offset;
648 return;
649 }
650 OS << " + " << Offset;
651}
652
654 if (Slot == -1)
655 OS << "<badref>";
656 else
657 OS << Slot;
658}
659
660static void printCFI(raw_ostream &OS, const MCCFIInstruction &CFI,
661 const TargetRegisterInfo *TRI) {
662 switch (CFI.getOperation()) {
664 OS << "same_value ";
665 if (MCSymbol *Label = CFI.getLabel())
668 break;
670 OS << "remember_state ";
671 if (MCSymbol *Label = CFI.getLabel())
673 break;
675 OS << "restore_state ";
676 if (MCSymbol *Label = CFI.getLabel())
678 break;
680 OS << "offset ";
681 if (MCSymbol *Label = CFI.getLabel())
684 OS << ", " << CFI.getOffset();
685 break;
687 OS << "def_cfa_register ";
688 if (MCSymbol *Label = CFI.getLabel())
691 break;
693 OS << "def_cfa_offset ";
694 if (MCSymbol *Label = CFI.getLabel())
696 OS << CFI.getOffset();
697 break;
699 OS << "def_cfa ";
700 if (MCSymbol *Label = CFI.getLabel())
703 OS << ", " << CFI.getOffset();
704 break;
706 OS << "llvm_def_aspace_cfa ";
707 if (MCSymbol *Label = CFI.getLabel())
710 OS << ", " << CFI.getOffset();
711 OS << ", " << CFI.getAddressSpace();
712 break;
714 OS << "rel_offset ";
715 if (MCSymbol *Label = CFI.getLabel())
718 OS << ", " << CFI.getOffset();
719 break;
721 OS << "adjust_cfa_offset ";
722 if (MCSymbol *Label = CFI.getLabel())
724 OS << CFI.getOffset();
725 break;
727 OS << "restore ";
728 if (MCSymbol *Label = CFI.getLabel())
731 break;
733 OS << "escape ";
734 if (MCSymbol *Label = CFI.getLabel())
736 if (!CFI.getValues().empty()) {
737 size_t e = CFI.getValues().size() - 1;
738 for (size_t i = 0; i < e; ++i)
739 OS << format("0x%02x", uint8_t(CFI.getValues()[i])) << ", ";
740 OS << format("0x%02x", uint8_t(CFI.getValues()[e]));
741 }
742 break;
743 }
745 OS << "undefined ";
746 if (MCSymbol *Label = CFI.getLabel())
749 break;
751 OS << "register ";
752 if (MCSymbol *Label = CFI.getLabel())
755 OS << ", ";
757 break;
759 OS << "window_save ";
760 if (MCSymbol *Label = CFI.getLabel())
762 break;
764 OS << "negate_ra_sign_state ";
765 if (MCSymbol *Label = CFI.getLabel())
767 break;
769 OS << "negate_ra_sign_state_with_pc ";
770 if (MCSymbol *Label = CFI.getLabel())
772 break;
773 default:
774 // TODO: Print the other CFI Operations.
775 OS << "<unserializable cfi directive>";
776 break;
777 }
778}
779
781 const TargetRegisterInfo *TRI) const {
782 print(OS, LLT{}, TRI);
783}
784
786 const TargetRegisterInfo *TRI) const {
787 tryToGetTargetInfo(*this, TRI);
788 ModuleSlotTracker DummyMST(nullptr);
789 print(OS, DummyMST, TypeToPrint, std::nullopt, /*PrintDef=*/false,
790 /*IsStandalone=*/true,
791 /*ShouldPrintRegisterTies=*/true,
792 /*TiedOperandIdx=*/0, TRI);
793}
794
796 LLT TypeToPrint, std::optional<unsigned> OpIdx,
797 bool PrintDef, bool IsStandalone,
798 bool ShouldPrintRegisterTies,
799 unsigned TiedOperandIdx,
800 const TargetRegisterInfo *TRI) const {
801 printTargetFlags(OS, *this);
802 switch (getType()) {
804 Register Reg = getReg();
805 if (isImplicit())
806 OS << (isDef() ? "implicit-def " : "implicit ");
807 else if (PrintDef && isDef())
808 // Print the 'def' flag only when the operand is defined after '='.
809 OS << "def ";
810 if (isInternalRead())
811 OS << "internal ";
812 if (isDead())
813 OS << "dead ";
814 if (isKill())
815 OS << "killed ";
816 if (isUndef())
817 OS << "undef ";
818 if (isEarlyClobber())
819 OS << "early-clobber ";
820 if (getReg().isPhysical() && isRenamable())
821 OS << "renamable ";
822 // isDebug() is exactly true for register operands of a DBG_VALUE. So we
823 // simply infer it when parsing and do not need to print it.
824
825 const MachineRegisterInfo *MRI = nullptr;
826 if (Reg.isVirtual()) {
827 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
828 MRI = &MF->getRegInfo();
829 }
830 }
831
832 OS << printReg(Reg, TRI, 0, MRI);
833 // Print the sub register.
834 if (unsigned SubReg = getSubReg()) {
835 if (TRI)
836 OS << '.' << TRI->getSubRegIndexName(SubReg);
837 else
838 OS << ".subreg" << SubReg;
839 }
840 // Print the register class / bank.
841 if (Reg.isVirtual()) {
842 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
843 const MachineRegisterInfo &MRI = MF->getRegInfo();
844 if (IsStandalone || !PrintDef || MRI.def_empty(Reg)) {
845 OS << ':';
846 OS << printRegClassOrBank(Reg, MRI, TRI);
847 }
848 }
849 }
850 // Print ties.
851 if (ShouldPrintRegisterTies && isTied() && !isDef())
852 OS << "(tied-def " << TiedOperandIdx << ")";
853 // Print types.
854 if (TypeToPrint.isValid())
855 OS << '(' << TypeToPrint << ')';
856 break;
857 }
859 const MIRFormatter *Formatter = nullptr;
860 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
861 const auto *TII = MF->getSubtarget().getInstrInfo();
862 assert(TII && "expected instruction info");
863 Formatter = TII->getMIRFormatter();
864 }
865 if (Formatter)
866 Formatter->printImm(OS, *getParent(), OpIdx, getImm());
867 else
868 OS << getImm();
869 break;
870 }
872 getCImm()->printAsOperand(OS, /*PrintType=*/true, MST);
873 break;
875 getFPImm()->printAsOperand(OS, /*PrintType=*/true, MST);
876 break;
879 break;
881 int FrameIndex = getIndex();
882 bool IsFixed = false;
883 const MachineFrameInfo *MFI = nullptr;
884 if (const MachineFunction *MF = getMFIfAvailable(*this))
885 MFI = &MF->getFrameInfo();
886 printFrameIndex(OS, FrameIndex, IsFixed, MFI);
887 break;
888 }
890 OS << "%const." << getIndex();
892 break;
894 OS << "target-index(";
895 const char *Name = "<unknown>";
896 if (const MachineFunction *MF = getMFIfAvailable(*this))
897 if (const auto *TargetIndexName = ::getTargetIndexName(*MF, getIndex()))
898 Name = TargetIndexName;
899 OS << Name << ')';
901 break;
902 }
905 break;
907 if (auto *GV = getGlobal())
908 GV->printAsOperand(OS, /*PrintType=*/false, MST);
909 else // Invalid, but may appear in debugging scenarios.
910 OS << "globaladdress(null)";
911
913 break;
916 OS << '&';
917 if (Name.empty()) {
918 OS << "\"\"";
919 } else {
921 }
923 break;
924 }
926 OS << "blockaddress(";
927 getBlockAddress()->getFunction()->printAsOperand(OS, /*PrintType=*/false,
928 MST);
929 OS << ", ";
930 printIRBlockReference(OS, *getBlockAddress()->getBasicBlock(), MST);
931 OS << ')';
933 break;
934 }
936 OS << "<regmask";
937 if (TRI) {
938 unsigned NumRegsInMask = 0;
939 unsigned NumRegsEmitted = 0;
940 for (unsigned i = 0; i < TRI->getNumRegs(); ++i) {
941 unsigned MaskWord = i / 32;
942 unsigned MaskBit = i % 32;
943 if (getRegMask()[MaskWord] & (1 << MaskBit)) {
944 if (PrintRegMaskNumRegs < 0 ||
945 NumRegsEmitted <= static_cast<unsigned>(PrintRegMaskNumRegs)) {
946 OS << " " << printReg(i, TRI);
947 NumRegsEmitted++;
948 }
949 NumRegsInMask++;
950 }
951 }
952 if (NumRegsEmitted != NumRegsInMask)
953 OS << " and " << (NumRegsInMask - NumRegsEmitted) << " more...";
954 } else {
955 OS << " ...";
956 }
957 OS << ">";
958 break;
959 }
961 const uint32_t *RegMask = getRegLiveOut();
962 OS << "liveout(";
963 if (!TRI) {
964 OS << "<unknown>";
965 } else {
966 bool IsCommaNeeded = false;
967 for (unsigned Reg = 0, E = TRI->getNumRegs(); Reg < E; ++Reg) {
968 if (RegMask[Reg / 32] & (1U << (Reg % 32))) {
969 if (IsCommaNeeded)
970 OS << ", ";
971 OS << printReg(Reg, TRI);
972 IsCommaNeeded = true;
973 }
974 }
975 }
976 OS << ")";
977 break;
978 }
981 break;
984 break;
986 OS << "dbg-instr-ref(" << getInstrRefInstrIndex() << ", "
987 << getInstrRefOpIndex() << ')';
988 break;
989 }
991 if (const MachineFunction *MF = getMFIfAvailable(*this))
992 printCFI(OS, MF->getFrameInstructions()[getCFIIndex()], TRI);
993 else
994 OS << "<cfi directive>";
995 break;
996 }
999 if (ID < Intrinsic::num_intrinsics)
1000 OS << "intrinsic(@" << Intrinsic::getBaseName(ID) << ')';
1001 else
1002 OS << "intrinsic(" << ID << ')';
1003 break;
1004 }
1006 auto Pred = static_cast<CmpInst::Predicate>(getPredicate());
1007 OS << (CmpInst::isIntPredicate(Pred) ? "int" : "float") << "pred("
1008 << Pred << ')';
1009 break;
1010 }
1012 OS << "shufflemask(";
1014 StringRef Separator;
1015 for (int Elt : Mask) {
1016 if (Elt == -1)
1017 OS << Separator << "undef";
1018 else
1019 OS << Separator << Elt;
1020 Separator = ", ";
1021 }
1022
1023 OS << ')';
1024 break;
1025 }
1026}
1027
1028#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1029LLVM_DUMP_METHOD void MachineOperand::dump() const { dbgs() << *this << '\n'; }
1030#endif
1031
1032//===----------------------------------------------------------------------===//
1033// MachineMemOperand Implementation
1034//===----------------------------------------------------------------------===//
1035
1036/// getAddrSpace - Return the LLVM IR address space number that this pointer
1037/// points into.
1039
1040/// isDereferenceable - Return true if V is always dereferenceable for
1041/// Offset + Size byte.
1043 const DataLayout &DL) const {
1044 if (!isa<const Value *>(V))
1045 return false;
1046
1047 const Value *BasePtr = cast<const Value *>(V);
1048 if (BasePtr == nullptr)
1049 return false;
1050
1052 BasePtr, Align(1), APInt(DL.getPointerSizeInBits(), Offset + Size), DL,
1053 dyn_cast<Instruction>(BasePtr));
1054}
1055
1056/// getConstantPool - Return a MachinePointerInfo record that refers to the
1057/// constant pool.
1060}
1061
1062/// getFixedStack - Return a MachinePointerInfo record that refers to the
1063/// the specified FrameIndex.
1065 int FI, int64_t Offset) {
1067}
1068
1071}
1072
1075}
1076
1078 int64_t Offset, uint8_t ID) {
1080}
1081
1084}
1085
1087 LLT type, Align a, const AAMDNodes &AAInfo,
1088 const MDNode *Ranges, SyncScope::ID SSID,
1089 AtomicOrdering Ordering,
1090 AtomicOrdering FailureOrdering)
1091 : PtrInfo(ptrinfo), MemoryType(type), FlagVals(f), BaseAlign(a),
1092 AAInfo(AAInfo), Ranges(Ranges) {
1093 assert((PtrInfo.V.isNull() || isa<const PseudoSourceValue *>(PtrInfo.V) ||
1094 isa<PointerType>(cast<const Value *>(PtrInfo.V)->getType())) &&
1095 "invalid pointer value");
1096 assert((isLoad() || isStore()) && "Not a load/store!");
1097
1098 AtomicInfo.SSID = static_cast<unsigned>(SSID);
1099 assert(getSyncScopeID() == SSID && "Value truncated");
1100 AtomicInfo.Ordering = static_cast<unsigned>(Ordering);
1101 assert(getSuccessOrdering() == Ordering && "Value truncated");
1102 AtomicInfo.FailureOrdering = static_cast<unsigned>(FailureOrdering);
1103 assert(getFailureOrdering() == FailureOrdering && "Value truncated");
1104}
1105
1107 LocationSize TS, Align BaseAlignment,
1108 const AAMDNodes &AAInfo,
1109 const MDNode *Ranges, SyncScope::ID SSID,
1110 AtomicOrdering Ordering,
1111 AtomicOrdering FailureOrdering)
1113 ptrinfo, F,
1114 !TS.hasValue() ? LLT()
1115 : TS.isScalable()
1116 ? LLT::scalable_vector(1, 8 * TS.getValue().getKnownMinValue())
1117 : LLT::scalar(8 * TS.getValue().getKnownMinValue()),
1118 BaseAlignment, AAInfo, Ranges, SSID, Ordering, FailureOrdering) {}
1119
1121 // The Value and Offset may differ due to CSE. But the flags and size
1122 // should be the same.
1123 assert(MMO->getFlags() == getFlags() && "Flags mismatch!");
1124 assert((!MMO->getSize().hasValue() || !getSize().hasValue() ||
1125 MMO->getSize() == getSize()) &&
1126 "Size mismatch!");
1127 if (MMO->getBaseAlign() >= getBaseAlign()) {
1128 // Update the alignment value.
1129 BaseAlign = MMO->getBaseAlign();
1130 // Also update the base and offset, because the new alignment may
1131 // not be applicable with the old ones.
1132 PtrInfo = MMO->PtrInfo;
1133 }
1134}
1135
1136/// getAlign - Return the minimum known alignment in bytes of the
1137/// actual memory reference.
1140}
1141
1144 const LLVMContext &Context,
1145 const MachineFrameInfo *MFI,
1146 const TargetInstrInfo *TII) const {
1147 OS << '(';
1148 if (isVolatile())
1149 OS << "volatile ";
1150 if (isNonTemporal())
1151 OS << "non-temporal ";
1152 if (isDereferenceable())
1153 OS << "dereferenceable ";
1154 if (isInvariant())
1155 OS << "invariant ";
1156 if (TII) {
1159 << "\" ";
1162 << "\" ";
1165 << "\" ";
1168 << "\" ";
1169 } else {
1171 OS << "\"MOTargetFlag1\" ";
1173 OS << "\"MOTargetFlag2\" ";
1175 OS << "\"MOTargetFlag3\" ";
1177 OS << "\"MOTargetFlag4\" ";
1178 }
1179
1180 assert((isLoad() || isStore()) &&
1181 "machine memory operand must be a load or store (or both)");
1182 if (isLoad())
1183 OS << "load ";
1184 if (isStore())
1185 OS << "store ";
1186
1187 printSyncScope(OS, Context, getSyncScopeID(), SSNs);
1188
1190 OS << toIRString(getSuccessOrdering()) << ' ';
1192 OS << toIRString(getFailureOrdering()) << ' ';
1193
1194 if (getMemoryType().isValid())
1195 OS << '(' << getMemoryType() << ')';
1196 else
1197 OS << "unknown-size";
1198
1199 if (const Value *Val = getValue()) {
1200 OS << ((isLoad() && isStore()) ? " on " : isLoad() ? " from " : " into ");
1201 MIRFormatter::printIRValue(OS, *Val, MST);
1202 } else if (const PseudoSourceValue *PVal = getPseudoValue()) {
1203 OS << ((isLoad() && isStore()) ? " on " : isLoad() ? " from " : " into ");
1204 assert(PVal && "Expected a pseudo source value");
1205 switch (PVal->kind()) {
1207 OS << "stack";
1208 break;
1210 OS << "got";
1211 break;
1213 OS << "jump-table";
1214 break;
1216 OS << "constant-pool";
1217 break;
1219 int FrameIndex = cast<FixedStackPseudoSourceValue>(PVal)->getFrameIndex();
1220 bool IsFixed = true;
1221 printFrameIndex(OS, FrameIndex, IsFixed, MFI);
1222 break;
1223 }
1225 OS << "call-entry ";
1226 cast<GlobalValuePseudoSourceValue>(PVal)->getValue()->printAsOperand(
1227 OS, /*PrintType=*/false, MST);
1228 break;
1230 OS << "call-entry &";
1232 OS, cast<ExternalSymbolPseudoSourceValue>(PVal)->getSymbol());
1233 break;
1234 default: {
1235 const MIRFormatter *Formatter = TII->getMIRFormatter();
1236 // FIXME: This is not necessarily the correct MIR serialization format for
1237 // a custom pseudo source value, but at least it allows
1238 // MIR printing to work on a target with custom pseudo source
1239 // values.
1240 OS << "custom \"";
1241 Formatter->printCustomPseudoSourceValue(OS, MST, *PVal);
1242 OS << '\"';
1243 break;
1244 }
1245 }
1246 } else if (getOpaqueValue() == nullptr && getOffset() != 0) {
1247 OS << ((isLoad() && isStore()) ? " on "
1248 : isLoad() ? " from "
1249 : " into ")
1250 << "unknown-address";
1251 }
1253 if (!getSize().hasValue() ||
1254 (!getSize().isZero() &&
1255 getAlign() != getSize().getValue().getKnownMinValue()))
1256 OS << ", align " << getAlign().value();
1257 if (getAlign() != getBaseAlign())
1258 OS << ", basealign " << getBaseAlign().value();
1259 auto AAInfo = getAAInfo();
1260 if (AAInfo.TBAA) {
1261 OS << ", !tbaa ";
1262 AAInfo.TBAA->printAsOperand(OS, MST);
1263 }
1264 if (AAInfo.Scope) {
1265 OS << ", !alias.scope ";
1266 AAInfo.Scope->printAsOperand(OS, MST);
1267 }
1268 if (AAInfo.NoAlias) {
1269 OS << ", !noalias ";
1270 AAInfo.NoAlias->printAsOperand(OS, MST);
1271 }
1272 if (getRanges()) {
1273 OS << ", !range ";
1274 getRanges()->printAsOperand(OS, MST);
1275 }
1276 // FIXME: Implement addrspace printing/parsing in MIR.
1277 // For now, print this even though parsing it is not available in MIR.
1278 if (unsigned AS = getAddrSpace())
1279 OS << ", addrspace " << AS;
1280
1281 OS << ')';
1282}
unsigned SubReg
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:622
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
std::string Name
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:479
const HexagonInstrInfo * TII
static bool isDebug()
IRTranslator LLVM IR MI
This file contains an interface for creating legacy passes to print out IR in various granularities.
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
Definition: Lint.cpp:557
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
static void tryToGetTargetInfo(const MachineInstr &MI, const TargetRegisterInfo *&TRI, const MachineRegisterInfo *&MRI, const TargetInstrInfo *&TII)
static const MachineFunction * getMFIfAvailable(const MachineInstr &MI)
static void printSyncScope(raw_ostream &OS, const LLVMContext &Context, SyncScope::ID SSID, SmallVectorImpl< StringRef > &SSNs)
static const MachineFunction * getMFIfAvailable(const MachineOperand &MO)
static const char * getTargetIndexName(const MachineFunction &MF, int Index)
static void printFrameIndex(raw_ostream &OS, int FrameIndex, bool IsFixed, const MachineFrameInfo *MFI)
static cl::opt< int > PrintRegMaskNumRegs("print-regmask-num-regs", cl::desc("Number of registers to limit to when " "printing regmask operands in IR dumps. " "unlimited = -1"), cl::init(32), cl::Hidden)
static void printIRBlockReference(raw_ostream &OS, const BasicBlock &BB, ModuleSlotTracker &MST)
static const char * getTargetFlagName(const TargetInstrInfo *TII, unsigned TF)
static void printCFIRegister(unsigned DwarfReg, raw_ostream &OS, const TargetRegisterInfo *TRI)
static const char * getTargetMMOFlagName(const TargetInstrInfo &TII, unsigned TMMOFlag)
static void printCFI(raw_ostream &OS, const MCCFIInstruction &CFI, const TargetRegisterInfo *TRI)
static bool isUndef(const MachineInstr &MI)
unsigned const TargetRegisterInfo * TRI
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isDead(const MachineInstr &MI, const MachineRegisterInfo &MRI)
raw_pwrite_stream & OS
This file contains some functions that are useful when dealing with strings.
Class for arbitrary precision integers.
Definition: APInt.h:78
an instruction to allocate memory on the stack
Definition: Instructions.h:63
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:220
The address of a basic block.
Definition: Constants.h:893
Function * getFunction() const
Definition: Constants.h:923
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:673
bool isIntPredicate() const
Definition: InstrTypes.h:781
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:271
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
unsigned getAllocaAddrSpace() const
Definition: DataLayout.h:229
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
Decompose the machine operand's target flags into two values - the direct target flag value and any o...
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
Return an array that contains the direct target flag values and their names.
ArrayRef< std::pair< unsigned, const char * > > getSerializableBitmaskMachineOperandTargetFlags() const override
Return an array that contains the bitmask target flag values and their names.
constexpr bool isValid() const
Definition: LowLevelType.h:145
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
void getSyncScopeNames(SmallVectorImpl< StringRef > &SSNs) const
getSyncScopeNames - Populates client supplied SmallVector with synchronization scope names registered...
bool hasValue() const
MCSymbol * getLabel() const
Definition: MCDwarf.h:711
unsigned getAddressSpace() const
Definition: MCDwarf.h:730
unsigned getRegister2() const
Definition: MCDwarf.h:725
unsigned getRegister() const
Definition: MCDwarf.h:713
OpType getOperation() const
Definition: MCDwarf.h:710
StringRef getValues() const
Definition: MCDwarf.h:750
int64_t getOffset() const
Definition: MCDwarf.h:735
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
Metadata node.
Definition: Metadata.h:1073
MIRFormater - Interface to format MIR operand based on target.
Definition: MIRFormatter.h:32
virtual void printImm(raw_ostream &OS, const MachineInstr &MI, std::optional< unsigned > OpIdx, int64_t Imm) const
Implement target specific printing for machine operand immediate value, so that we can have more mean...
Definition: MIRFormatter.h:43
virtual void printCustomPseudoSourceValue(raw_ostream &OS, ModuleSlotTracker &MST, const PseudoSourceValue &PSV) const
Implement target specific printing of target custom pseudo source value.
Definition: MIRFormatter.h:60
static void printIRValue(raw_ostream &OS, const Value &V, ModuleSlotTracker &MST)
Helper functions to print IR value as MIR serialization format which will be useful for target specif...
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
const AllocaInst * getObjectAllocation(int ObjectIdx) const
Return the underlying Alloca of the specified stack object if it exists.
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
int getObjectIndexBegin() const
Return the minimum frame object index.
PseudoSourceValueManager & getPSVManager() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Representation of each machine instruction.
Definition: MachineInstr.h:71
unsigned getOperandNo(const_mop_iterator I) const
Returns the number of the operand iterator I points to.
Definition: MachineInstr.h:783
A description of a memory reference used in the backend.
LocationSize getSize() const
Return the size in bytes of the memory reference.
AtomicOrdering getFailureOrdering() const
For cmpxchg atomic operations, return the atomic ordering requirements when store does not occur.
const PseudoSourceValue * getPseudoValue() const
LLT getMemoryType() const
Return the memory type of the memory reference.
unsigned getAddrSpace() const
void print(raw_ostream &OS, ModuleSlotTracker &MST, SmallVectorImpl< StringRef > &SSNs, const LLVMContext &Context, const MachineFrameInfo *MFI, const TargetInstrInfo *TII) const
Support for operator<<.
const MDNode * getRanges() const
Return the range tag for the memory reference.
void refineAlignment(const MachineMemOperand *MMO)
Update this MachineMemOperand to reflect the alignment of MMO, if it has a greater alignment.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID for this memory operation.
const void * getOpaqueValue() const
MachineMemOperand(MachinePointerInfo PtrInfo, Flags flags, LocationSize TS, Align a, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
Construct a MachineMemOperand object with the specified PtrInfo, flags, size, and base alignment.
Flags
Flags values. These may be or'd together.
AtomicOrdering getSuccessOrdering() const
Return the atomic ordering requirements for this memory operation.
Flags getFlags() const
Return the raw flags of the source value,.
Align getAlign() const
Return the minimum known alignment in bytes of the actual memory reference.
AAMDNodes getAAInfo() const
Return the AA tags for the memory reference.
const Value * getValue() const
Return the base address of the memory access.
Align getBaseAlign() const
Return the minimum known alignment in bytes of the base address, without the offset.
int64_t getOffset() const
For normal values, this is a byte offset added to the base address.
MachineOperand class - Representation of each machine instruction operand.
void setSubReg(unsigned subReg)
unsigned getSubReg() const
unsigned getInstrRefOpIndex() const
void setInstrRefInstrIndex(unsigned InstrIdx)
unsigned getOperandNo() const
Returns the index of this operand in the instruction that it belongs to.
const GlobalValue * getGlobal() const
void substVirtReg(Register Reg, unsigned SubIdx, const TargetRegisterInfo &)
substVirtReg - Substitute the current register with the virtual subregister Reg:SubReg.
void ChangeToFrameIndex(int Idx, unsigned TargetFlags=0)
Replace this operand with a frame index.
const uint32_t * getRegLiveOut() const
getRegLiveOut - Returns a bit mask of live-out registers.
void setInstrRefOpIndex(unsigned OpIdx)
const ConstantInt * getCImm() const
const char * getTargetIndexName() const
getTargetIndexName - If this MachineOperand is a TargetIndex that has a name, attempt to get the name...
static void printStackObjectReference(raw_ostream &OS, unsigned FrameIndex, bool IsFixed, StringRef Name)
Print a stack object reference.
static void printSubRegIdx(raw_ostream &OS, uint64_t Index, const TargetRegisterInfo *TRI)
Print a subreg index operand.
int64_t getImm() const
unsigned getInstrRefInstrIndex() const
static void printTargetFlags(raw_ostream &OS, const MachineOperand &Op)
Print operand target flags.
bool isImplicit() const
void ChangeToFPImmediate(const ConstantFP *FPImm, unsigned TargetFlags=0)
ChangeToFPImmediate - Replace this operand with a new FP immediate operand of the specified value.
void setIsRenamable(bool Val=true)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
const MDNode * getMetadata() const
MachineBasicBlock * getMBB() const
ArrayRef< int > getShuffleMask() const
void ChangeToMCSymbol(MCSymbol *Sym, unsigned TargetFlags=0)
ChangeToMCSymbol - Replace this operand with a new MC symbol operand.
void ChangeToTargetIndex(unsigned Idx, int64_t Offset, unsigned TargetFlags=0)
Replace this operand with a target index.
void setReg(Register Reg)
Change the register this operand corresponds to.
void ChangeToImmediate(int64_t ImmVal, unsigned TargetFlags=0)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value.
void ChangeToES(const char *SymName, unsigned TargetFlags=0)
ChangeToES - Replace this operand with a new external symbol operand.
void ChangeToGA(const GlobalValue *GV, int64_t Offset, unsigned TargetFlags=0)
ChangeToGA - Replace this operand with a new global address operand.
void print(raw_ostream &os, const TargetRegisterInfo *TRI=nullptr) const
Print the MachineOperand to os.
unsigned getCFIIndex() const
bool isRenamable() const
isRenamable - Returns true if this register may be renamed, i.e.
void ChangeToBA(const BlockAddress *BA, int64_t Offset, unsigned TargetFlags=0)
ChangeToBA - Replace this operand with a new block address operand.
static void printOperandOffset(raw_ostream &OS, int64_t Offset)
Print the offset with explicit +/- signs.
void ChangeToDbgInstrRef(unsigned InstrIdx, unsigned OpIdx, unsigned TargetFlags=0)
Replace this operand with an Instruction Reference.
void ChangeToRegister(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isDebug=false)
ChangeToRegister - Replace this operand with a new register operand of the specified value.
const BlockAddress * getBlockAddress() const
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
void substPhysReg(MCRegister Reg, const TargetRegisterInfo &)
substPhysReg - Substitute the current register with the physical register Reg, taking any existing Su...
static unsigned getRegMaskSize(unsigned NumRegs)
Returns number of elements needed for a regmask array.
void setOffset(int64_t Offset)
static void printIRSlotNumber(raw_ostream &OS, int Slot)
Print an IRSlotNumber.
unsigned getTargetFlags() const
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const char * getSymbolName() const
void setIsUndef(bool Val=true)
bool isEarlyClobber() const
Register getReg() const
getReg - Returns the register number.
Intrinsic::ID getIntrinsicID() const
bool isInternalRead() const
void setTargetFlags(unsigned F)
bool isIdenticalTo(const MachineOperand &Other) const
Returns true if this operand is identical to the specified operand except for liveness related flags ...
const uint32_t * getRegMask() const
getRegMask - Returns a bit mask of registers preserved by this RegMask operand.
void setIndex(int Idx)
void setIsDef(bool Val=true)
Change a def to a use, or a use to a def.
const ConstantFP * getFPImm() const
static void printSymbol(raw_ostream &OS, MCSymbol &Sym)
Print a MCSymbol as an operand.
unsigned getPredicate() const
MCSymbol * getMCSymbol() const
@ MO_CFIIndex
MCCFIInstruction index.
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_MCSymbol
MCSymbol reference (for debug/eh info)
@ MO_Predicate
Generic predicate for ISel.
@ MO_GlobalAddress
Address of a global value.
@ MO_RegisterMask
Mask of preserved registers.
@ MO_ShuffleMask
Other IR Constant for ISel (shuffle masks)
@ MO_CImmediate
Immediate >64bit operand.
@ MO_BlockAddress
Address of a basic block.
@ MO_DbgInstrRef
Integer indices referring to an instruction+operand.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_FrameIndex
Abstract Stack Frame Index.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_IntrinsicID
Intrinsic ID for ISel.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
@ MO_TargetIndex
Target-dependent index+offset operand.
@ MO_Metadata
Metadata reference (for debug info)
@ MO_FPImmediate
Floating-point immediate operand.
@ MO_RegisterLiveOut
Mask of live-out registers.
int64_t getOffset() const
Return the offset from the symbol in this operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
void removeRegOperandFromUseList(MachineOperand *MO)
Remove MO from its use-def list.
void addRegOperandToUseList(MachineOperand *MO)
Add MO to the linked list of operands for its register.
void printAsOperand(raw_ostream &OS, const Module *M=nullptr) const
Print as operand.
Definition: AsmWriter.cpp:5255
Manage lifetime of a slot tracker for printing IR.
int getLocalSlot(const Value *V)
Return the slot number of the specified local value.
Definition: AsmWriter.cpp:918
const Function * getCurrentFunction() const
void incorporateFunction(const Function &F)
Incorporate the given function.
Definition: AsmWriter.cpp:904
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
bool isNull() const
Test if the pointer held in the union is null, regardless of which type it is.
Definition: PointerUnion.h:142
const PseudoSourceValue * getJumpTable()
Return a pseudo source value referencing a jump table.
const PseudoSourceValue * getFixedStack(int FI)
Return a pseudo source value referencing a fixed stack frame entry, e.g., a spill slot.
const PseudoSourceValue * getGOT()
Return a pseudo source value referencing the global offset table (or something the like).
const PseudoSourceValue * getStack()
Return a pseudo source value referencing the area below the stack frame of a function,...
const PseudoSourceValue * getConstantPool()
Return a pseudo source value referencing the constant pool.
Special value supplied for machine level alias analysis.
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
constexpr unsigned id() const
Definition: Register.h:109
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition: Register.h:95
bool empty() const
Definition: SmallVector.h:81
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:150
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetInstrInfo * getInstrInfo() const
LLVM Value Representation.
Definition: Value.h:74
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
Definition: AsmWriter.cpp:5149
bool hasName() const
Definition: Value.h:261
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
An opaque object representing a hash code.
Definition: Hashing.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
StringRef getBaseName(ID id)
Return the LLVM name for an intrinsic, without encoded types for overloading, such as "llvm....
Definition: Intrinsics.cpp:42
@ System
Synchronized with respect to all concurrently executing threads.
Definition: LLVMContext.h:57
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
hash_code hash_value(const FixedPointSemantics &Val)
Definition: APFixedPoint.h:136
bool isDereferenceableAndAlignedPointer(const Value *V, Type *Ty, Align Alignment, const DataLayout &DL, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
Returns true if V is always a dereferenceable pointer with alignment greater or equal than requested.
Definition: Loads.cpp:217
Printable printJumpTableEntryReference(unsigned Idx)
Prints a jump table entry reference.
const char * toIRString(AtomicOrdering ao)
String used by LLVM IR to represent atomic ordering.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
Printable printRegClassOrBank(Register Reg, const MachineRegisterInfo &RegInfo, const TargetRegisterInfo *TRI)
Create Printable object to print register classes or register banks on a raw_ostream.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:125
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Other
Any other memory.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1766
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
Definition: Alignment.h:212
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:590
stable_hash stable_hash_combine(ArrayRef< stable_hash > Buffer)
Definition: StableHashing.h:30
void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name)
Print out a name of an LLVM value without any prefixes.
Definition: AsmWriter.cpp:382
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:764
MDNode * Scope
The tag for alias scope specification (used with noalias).
Definition: Metadata.h:787
MDNode * TBAA
The tag for type-based alias analysis.
Definition: Metadata.h:781
MDNode * NoAlias
The tag specifying the noalias scope.
Definition: Metadata.h:790
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
This class contains a discriminated union of information about pointers in memory operands,...
static MachinePointerInfo getJumpTable(MachineFunction &MF)
Return a MachinePointerInfo record that refers to a jump table entry.
bool isDereferenceable(unsigned Size, LLVMContext &C, const DataLayout &DL) const
Return true if memory region [V, V+Offset+Size) is known to be dereferenceable.
unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
static MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, uint8_t ID=0)
Stack pointer relative access.
int64_t Offset
Offset - This is an offset from the base Value*.
PointerUnion< const Value *, const PseudoSourceValue * > V
This is the IR pointer value for the access, or it is null if unknown.
static MachinePointerInfo getConstantPool(MachineFunction &MF)
Return a MachinePointerInfo record that refers to the constant pool.
static MachinePointerInfo getUnknownStack(MachineFunction &MF)
Stack memory without other information.
static MachinePointerInfo getGOT(MachineFunction &MF)
Return a MachinePointerInfo record that refers to a GOT entry.
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.