LLVM 20.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"
32#include <optional>
33
34using namespace llvm;
35
36static cl::opt<int>
37 PrintRegMaskNumRegs("print-regmask-num-regs",
38 cl::desc("Number of registers to limit to when "
39 "printing regmask operands in IR dumps. "
40 "unlimited = -1"),
41 cl::init(32), cl::Hidden);
42
44 if (const MachineInstr *MI = MO.getParent())
45 if (const MachineBasicBlock *MBB = MI->getParent())
46 if (const MachineFunction *MF = MBB->getParent())
47 return MF;
48 return nullptr;
49}
50
52 return const_cast<MachineFunction *>(
53 getMFIfAvailable(const_cast<const MachineOperand &>(MO)));
54}
55
57 assert(getParent() && "Operand does not belong to any instruction!");
58 return getParent()->getOperandNo(this);
59}
60
62 if (getReg() == Reg)
63 return; // No change.
64
65 // Clear the IsRenamable bit to keep it conservatively correct.
66 IsRenamable = false;
67
68 // Otherwise, we have to change the register. If this operand is embedded
69 // into a machine function, we need to update the old and new register's
70 // use/def lists.
71 if (MachineFunction *MF = getMFIfAvailable(*this)) {
72 MachineRegisterInfo &MRI = MF->getRegInfo();
73 MRI.removeRegOperandFromUseList(this);
74 SmallContents.RegNo = Reg;
75 MRI.addRegOperandToUseList(this);
76 return;
77 }
78
79 // Otherwise, just change the register, no problem. :)
80 SmallContents.RegNo = Reg;
81}
82
83void MachineOperand::substVirtReg(Register Reg, unsigned SubIdx,
84 const TargetRegisterInfo &TRI) {
85 assert(Reg.isVirtual());
86 if (SubIdx && getSubReg())
87 SubIdx = TRI.composeSubRegIndices(SubIdx, getSubReg());
88 setReg(Reg);
89 if (SubIdx)
90 setSubReg(SubIdx);
91}
92
95 if (getSubReg()) {
96 Reg = TRI.getSubReg(Reg, getSubReg());
97 // Note that getSubReg() may return 0 if the sub-register doesn't exist.
98 // That won't happen in legal code.
99 setSubReg(0);
100 if (isDef())
101 setIsUndef(false);
102 }
103 setReg(Reg);
104}
105
106/// Change a def to a use, or a use to a def.
108 assert(isReg() && "Wrong MachineOperand accessor");
109 assert((!Val || !isDebug()) && "Marking a debug operation as def");
110 if (IsDef == Val)
111 return;
112 assert(!IsDeadOrKill && "Changing def/use with dead/kill set not supported");
113 // MRI may keep uses and defs in different list positions.
114 if (MachineFunction *MF = getMFIfAvailable(*this)) {
115 MachineRegisterInfo &MRI = MF->getRegInfo();
116 MRI.removeRegOperandFromUseList(this);
117 IsDef = Val;
118 MRI.addRegOperandToUseList(this);
119 return;
120 }
121 IsDef = Val;
122}
123
125 assert(isReg() && "Wrong MachineOperand accessor");
126 assert(getReg().isPhysical() &&
127 "isRenamable should only be checked on physical registers");
128 if (!IsRenamable)
129 return false;
130
131 const MachineInstr *MI = getParent();
132 if (!MI)
133 return true;
134
135 if (isDef())
136 return !MI->hasExtraDefRegAllocReq(MachineInstr::IgnoreBundle);
137
138 assert(isUse() && "Reg is not def or use");
139 return !MI->hasExtraSrcRegAllocReq(MachineInstr::IgnoreBundle);
140}
141
143 assert(isReg() && "Wrong MachineOperand accessor");
144 assert(getReg().isPhysical() &&
145 "setIsRenamable should only be called on physical registers");
146 IsRenamable = Val;
147}
148
149// If this operand is currently a register operand, and if this is in a
150// function, deregister the operand from the register's use/def list.
151void MachineOperand::removeRegFromUses() {
152 if (!isReg() || !isOnRegUseList())
153 return;
154
155 if (MachineFunction *MF = getMFIfAvailable(*this))
156 MF->getRegInfo().removeRegOperandFromUseList(this);
157}
158
159/// ChangeToImmediate - Replace this operand with a new immediate operand of
160/// the specified value. If an operand is known to be an immediate already,
161/// the setImm method should be used.
162void MachineOperand::ChangeToImmediate(int64_t ImmVal, unsigned TargetFlags) {
163 assert((!isReg() || !isTied()) && "Cannot change a tied operand into an imm");
164
165 removeRegFromUses();
166
167 OpKind = MO_Immediate;
168 Contents.ImmVal = ImmVal;
169 setTargetFlags(TargetFlags);
170}
171
173 unsigned TargetFlags) {
174 assert((!isReg() || !isTied()) && "Cannot change a tied operand into an imm");
175
176 removeRegFromUses();
177
178 OpKind = MO_FPImmediate;
179 Contents.CFP = FPImm;
180 setTargetFlags(TargetFlags);
181}
182
183void MachineOperand::ChangeToES(const char *SymName,
184 unsigned TargetFlags) {
185 assert((!isReg() || !isTied()) &&
186 "Cannot change a tied operand into an external symbol");
187
188 removeRegFromUses();
189
190 OpKind = MO_ExternalSymbol;
191 Contents.OffsetedInfo.Val.SymbolName = SymName;
192 setOffset(0); // Offset is always 0.
193 setTargetFlags(TargetFlags);
194}
195
197 unsigned TargetFlags) {
198 assert((!isReg() || !isTied()) &&
199 "Cannot change a tied operand into a global address");
200
201 removeRegFromUses();
202
203 OpKind = MO_GlobalAddress;
204 Contents.OffsetedInfo.Val.GV = GV;
206 setTargetFlags(TargetFlags);
207}
208
210 unsigned TargetFlags) {
211 assert((!isReg() || !isTied()) &&
212 "Cannot change a tied operand into a block address");
213
214 removeRegFromUses();
215
216 OpKind = MO_BlockAddress;
217 Contents.OffsetedInfo.Val.BA = BA;
219 setTargetFlags(TargetFlags);
220}
221
222void MachineOperand::ChangeToMCSymbol(MCSymbol *Sym, unsigned TargetFlags) {
223 assert((!isReg() || !isTied()) &&
224 "Cannot change a tied operand into an MCSymbol");
225
226 removeRegFromUses();
227
228 OpKind = MO_MCSymbol;
229 Contents.Sym = Sym;
230 setTargetFlags(TargetFlags);
231}
232
233void MachineOperand::ChangeToFrameIndex(int Idx, unsigned TargetFlags) {
234 assert((!isReg() || !isTied()) &&
235 "Cannot change a tied operand into a FrameIndex");
236
237 removeRegFromUses();
238
239 OpKind = MO_FrameIndex;
240 setIndex(Idx);
241 setTargetFlags(TargetFlags);
242}
243
245 unsigned TargetFlags) {
246 assert((!isReg() || !isTied()) &&
247 "Cannot change a tied operand into a FrameIndex");
248
249 removeRegFromUses();
250
251 OpKind = MO_TargetIndex;
252 setIndex(Idx);
254 setTargetFlags(TargetFlags);
255}
256
257void MachineOperand::ChangeToDbgInstrRef(unsigned InstrIdx, unsigned OpIdx,
258 unsigned TargetFlags) {
259 assert((!isReg() || !isTied()) &&
260 "Cannot change a tied operand into a DbgInstrRef");
261
262 removeRegFromUses();
263
264 OpKind = MO_DbgInstrRef;
265 setInstrRefInstrIndex(InstrIdx);
266 setInstrRefOpIndex(OpIdx);
267 setTargetFlags(TargetFlags);
268}
269
270/// ChangeToRegister - Replace this operand with a new register operand of
271/// the specified value. If an operand is known to be an register already,
272/// the setReg method should be used.
273void MachineOperand::ChangeToRegister(Register Reg, bool isDef, bool isImp,
274 bool isKill, bool isDead, bool isUndef,
275 bool isDebug) {
276 MachineRegisterInfo *RegInfo = nullptr;
277 if (MachineFunction *MF = getMFIfAvailable(*this))
278 RegInfo = &MF->getRegInfo();
279 // If this operand is already a register operand, remove it from the
280 // register's use/def lists.
281 bool WasReg = isReg();
282 if (RegInfo && WasReg)
283 RegInfo->removeRegOperandFromUseList(this);
284
285 // Ensure debug instructions set debug flag on register uses.
286 const MachineInstr *MI = getParent();
287 if (!isDef && MI && MI->isDebugInstr())
288 isDebug = true;
289
290 // Change this to a register and set the reg#.
291 assert(!(isDead && !isDef) && "Dead flag on non-def");
292 assert(!(isKill && isDef) && "Kill flag on def");
293 OpKind = MO_Register;
294 SmallContents.RegNo = Reg;
295 SubReg_TargetFlags = 0;
296 IsDef = isDef;
297 IsImp = isImp;
298 IsDeadOrKill = isKill | isDead;
299 IsRenamable = false;
300 IsUndef = isUndef;
301 IsInternalRead = false;
302 IsEarlyClobber = false;
303 IsDebug = isDebug;
304 // Ensure isOnRegUseList() returns false.
305 Contents.Reg.Prev = nullptr;
306 // Preserve the tie when the operand was already a register.
307 if (!WasReg)
308 TiedTo = 0;
309
310 // If this operand is embedded in a function, add the operand to the
311 // register's use/def list.
312 if (RegInfo)
313 RegInfo->addRegOperandToUseList(this);
314}
315
316/// isIdenticalTo - Return true if this operand is identical to the specified
317/// operand. Note that this should stay in sync with the hash_value overload
318/// below.
320 if (getType() != Other.getType() ||
321 getTargetFlags() != Other.getTargetFlags())
322 return false;
323
324 switch (getType()) {
326 return getReg() == Other.getReg() && isDef() == Other.isDef() &&
327 getSubReg() == Other.getSubReg();
329 return getImm() == Other.getImm();
331 return getCImm() == Other.getCImm();
333 return getFPImm() == Other.getFPImm();
335 return getMBB() == Other.getMBB();
337 return getIndex() == Other.getIndex();
340 return getIndex() == Other.getIndex() && getOffset() == Other.getOffset();
342 return getIndex() == Other.getIndex();
344 return getGlobal() == Other.getGlobal() && getOffset() == Other.getOffset();
346 return strcmp(getSymbolName(), Other.getSymbolName()) == 0 &&
347 getOffset() == Other.getOffset();
349 return getBlockAddress() == Other.getBlockAddress() &&
350 getOffset() == Other.getOffset();
353 // Shallow compare of the two RegMasks
354 const uint32_t *RegMask = getRegMask();
355 const uint32_t *OtherRegMask = Other.getRegMask();
356 if (RegMask == OtherRegMask)
357 return true;
358
359 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
360 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
361 unsigned RegMaskSize = MachineOperand::getRegMaskSize(TRI->getNumRegs());
362 // Deep compare of the two RegMasks
363 return std::equal(RegMask, RegMask + RegMaskSize, OtherRegMask);
364 }
365 // We don't know the size of the RegMask, so we can't deep compare the two
366 // reg masks.
367 return false;
368 }
370 return getMCSymbol() == Other.getMCSymbol();
372 return getInstrRefInstrIndex() == Other.getInstrRefInstrIndex() &&
373 getInstrRefOpIndex() == Other.getInstrRefOpIndex();
375 return getCFIIndex() == Other.getCFIIndex();
377 return getMetadata() == Other.getMetadata();
379 return getIntrinsicID() == Other.getIntrinsicID();
381 return getPredicate() == Other.getPredicate();
383 return getShuffleMask() == Other.getShuffleMask();
384 }
385 llvm_unreachable("Invalid machine operand type");
386}
387
388// Note: this must stay exactly in sync with isIdenticalTo above.
390 switch (MO.getType()) {
392 // Register operands don't have target flags.
393 return hash_combine(MO.getType(), (unsigned)MO.getReg(), MO.getSubReg(), 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 and IntrinsicInfo from
453// it.
454static void tryToGetTargetInfo(const MachineOperand &MO,
455 const TargetRegisterInfo *&TRI,
456 const TargetIntrinsicInfo *&IntrinsicInfo) {
457 if (const MachineFunction *MF = getMFIfAvailable(MO)) {
458 TRI = MF->getSubtarget().getRegisterInfo();
459 IntrinsicInfo = MF->getTarget().getIntrinsicInfo();
460 }
461}
462
463static const char *getTargetIndexName(const MachineFunction &MF, int Index) {
464 const auto *TII = MF.getSubtarget().getInstrInfo();
465 assert(TII && "expected instruction info");
466 auto Indices = TII->getSerializableTargetIndices();
467 auto Found = find_if(Indices, [&](const std::pair<int, const char *> &I) {
468 return I.first == Index;
469 });
470 if (Found != Indices.end())
471 return Found->second;
472 return nullptr;
473}
474
476 const MachineFunction *MF = getMFIfAvailable(*this);
477 return MF ? ::getTargetIndexName(*MF, this->getIndex()) : nullptr;
478}
479
480static const char *getTargetFlagName(const TargetInstrInfo *TII, unsigned TF) {
482 for (const auto &I : Flags) {
483 if (I.first == TF) {
484 return I.second;
485 }
486 }
487 return nullptr;
488}
489
490static void printCFIRegister(unsigned DwarfReg, raw_ostream &OS,
491 const TargetRegisterInfo *TRI) {
492 if (!TRI) {
493 OS << "%dwarfreg." << DwarfReg;
494 return;
495 }
496
497 if (std::optional<MCRegister> Reg = TRI->getLLVMRegNum(DwarfReg, true))
498 OS << printReg(*Reg, TRI);
499 else
500 OS << "<badreg>";
501}
502
504 ModuleSlotTracker &MST) {
505 OS << "%ir-block.";
506 if (BB.hasName()) {
508 return;
509 }
510 std::optional<int> Slot;
511 if (const Function *F = BB.getParent()) {
512 if (F == MST.getCurrentFunction()) {
513 Slot = MST.getLocalSlot(&BB);
514 } else if (const Module *M = F->getParent()) {
515 ModuleSlotTracker CustomMST(M, /*ShouldInitializeAllMetadata=*/false);
516 CustomMST.incorporateFunction(*F);
517 Slot = CustomMST.getLocalSlot(&BB);
518 }
519 }
520 if (Slot)
522 else
523 OS << "<unknown>";
524}
525
526static void printSyncScope(raw_ostream &OS, const LLVMContext &Context,
527 SyncScope::ID SSID,
529 switch (SSID) {
531 break;
532 default:
533 if (SSNs.empty())
534 Context.getSyncScopeNames(SSNs);
535
536 OS << "syncscope(\"";
537 printEscapedString(SSNs[SSID], OS);
538 OS << "\") ";
539 break;
540 }
541}
542
543static const char *getTargetMMOFlagName(const TargetInstrInfo &TII,
544 unsigned TMMOFlag) {
545 auto Flags = TII.getSerializableMachineMemOperandTargetFlags();
546 for (const auto &I : Flags) {
547 if (I.first == TMMOFlag) {
548 return I.second;
549 }
550 }
551 return nullptr;
552}
553
554static void printFrameIndex(raw_ostream& OS, int FrameIndex, bool IsFixed,
555 const MachineFrameInfo *MFI) {
557 if (MFI) {
558 IsFixed = MFI->isFixedObjectIndex(FrameIndex);
559 if (const AllocaInst *Alloca = MFI->getObjectAllocation(FrameIndex))
560 if (Alloca->hasName())
561 Name = Alloca->getName();
562 if (IsFixed)
563 FrameIndex -= MFI->getObjectIndexBegin();
564 }
566}
567
569 const TargetRegisterInfo *TRI) {
570 OS << "%subreg.";
571 if (TRI && Index != 0 && Index < TRI->getNumSubRegIndices())
572 OS << TRI->getSubRegIndexName(Index);
573 else
574 OS << Index;
575}
576
578 const MachineOperand &Op) {
579 if (!Op.getTargetFlags())
580 return;
582 if (!MF)
583 return;
584
585 const auto *TII = MF->getSubtarget().getInstrInfo();
586 assert(TII && "expected instruction info");
587 auto Flags = TII->decomposeMachineOperandsTargetFlags(Op.getTargetFlags());
588 OS << "target-flags(";
589 const bool HasDirectFlags = Flags.first;
590 const bool HasBitmaskFlags = Flags.second;
591 if (!HasDirectFlags && !HasBitmaskFlags) {
592 OS << "<unknown>) ";
593 return;
594 }
595 if (HasDirectFlags) {
596 if (const auto *Name = getTargetFlagName(TII, Flags.first))
597 OS << Name;
598 else
599 OS << "<unknown target flag>";
600 }
601 if (!HasBitmaskFlags) {
602 OS << ") ";
603 return;
604 }
605 bool IsCommaNeeded = HasDirectFlags;
606 unsigned BitMask = Flags.second;
608 for (const auto &Mask : BitMasks) {
609 // Check if the flag's bitmask has the bits of the current mask set.
610 if ((BitMask & Mask.first) == Mask.first) {
611 if (IsCommaNeeded)
612 OS << ", ";
613 IsCommaNeeded = true;
614 OS << Mask.second;
615 // Clear the bits which were serialized from the flag's bitmask.
616 BitMask &= ~(Mask.first);
617 }
618 }
619 if (BitMask) {
620 // When the resulting flag's bitmask isn't zero, we know that we didn't
621 // serialize all of the bit flags.
622 if (IsCommaNeeded)
623 OS << ", ";
624 OS << "<unknown bitmask target flag>";
625 }
626 OS << ") ";
627}
628
630 OS << "<mcsymbol " << Sym << ">";
631}
632
634 unsigned FrameIndex,
635 bool IsFixed, StringRef Name) {
636 if (IsFixed) {
637 OS << "%fixed-stack." << FrameIndex;
638 return;
639 }
640
641 OS << "%stack." << FrameIndex;
642 if (!Name.empty())
643 OS << '.' << Name;
644}
645
647 if (Offset == 0)
648 return;
649 if (Offset < 0) {
650 OS << " - " << -Offset;
651 return;
652 }
653 OS << " + " << Offset;
654}
655
657 if (Slot == -1)
658 OS << "<badref>";
659 else
660 OS << Slot;
661}
662
663static void printCFI(raw_ostream &OS, const MCCFIInstruction &CFI,
664 const TargetRegisterInfo *TRI) {
665 switch (CFI.getOperation()) {
667 OS << "same_value ";
668 if (MCSymbol *Label = CFI.getLabel())
671 break;
673 OS << "remember_state ";
674 if (MCSymbol *Label = CFI.getLabel())
676 break;
678 OS << "restore_state ";
679 if (MCSymbol *Label = CFI.getLabel())
681 break;
683 OS << "offset ";
684 if (MCSymbol *Label = CFI.getLabel())
687 OS << ", " << CFI.getOffset();
688 break;
690 OS << "def_cfa_register ";
691 if (MCSymbol *Label = CFI.getLabel())
694 break;
696 OS << "def_cfa_offset ";
697 if (MCSymbol *Label = CFI.getLabel())
699 OS << CFI.getOffset();
700 break;
702 OS << "def_cfa ";
703 if (MCSymbol *Label = CFI.getLabel())
706 OS << ", " << CFI.getOffset();
707 break;
709 OS << "llvm_def_aspace_cfa ";
710 if (MCSymbol *Label = CFI.getLabel())
713 OS << ", " << CFI.getOffset();
714 OS << ", " << CFI.getAddressSpace();
715 break;
717 OS << "rel_offset ";
718 if (MCSymbol *Label = CFI.getLabel())
721 OS << ", " << CFI.getOffset();
722 break;
724 OS << "adjust_cfa_offset ";
725 if (MCSymbol *Label = CFI.getLabel())
727 OS << CFI.getOffset();
728 break;
730 OS << "restore ";
731 if (MCSymbol *Label = CFI.getLabel())
734 break;
736 OS << "escape ";
737 if (MCSymbol *Label = CFI.getLabel())
739 if (!CFI.getValues().empty()) {
740 size_t e = CFI.getValues().size() - 1;
741 for (size_t i = 0; i < e; ++i)
742 OS << format("0x%02x", uint8_t(CFI.getValues()[i])) << ", ";
743 OS << format("0x%02x", uint8_t(CFI.getValues()[e]));
744 }
745 break;
746 }
748 OS << "undefined ";
749 if (MCSymbol *Label = CFI.getLabel())
752 break;
754 OS << "register ";
755 if (MCSymbol *Label = CFI.getLabel())
758 OS << ", ";
760 break;
762 OS << "window_save ";
763 if (MCSymbol *Label = CFI.getLabel())
765 break;
767 OS << "negate_ra_sign_state ";
768 if (MCSymbol *Label = CFI.getLabel())
770 break;
772 OS << "negate_ra_sign_state_with_pc ";
773 if (MCSymbol *Label = CFI.getLabel())
775 break;
776 default:
777 // TODO: Print the other CFI Operations.
778 OS << "<unserializable cfi directive>";
779 break;
780 }
781}
782
784 const TargetIntrinsicInfo *IntrinsicInfo) const {
785 print(OS, LLT{}, TRI, IntrinsicInfo);
786}
787
789 const TargetRegisterInfo *TRI,
790 const TargetIntrinsicInfo *IntrinsicInfo) const {
791 tryToGetTargetInfo(*this, TRI, IntrinsicInfo);
792 ModuleSlotTracker DummyMST(nullptr);
793 print(OS, DummyMST, TypeToPrint, std::nullopt, /*PrintDef=*/false,
794 /*IsStandalone=*/true,
795 /*ShouldPrintRegisterTies=*/true,
796 /*TiedOperandIdx=*/0, TRI, IntrinsicInfo);
797}
798
800 LLT TypeToPrint, std::optional<unsigned> OpIdx,
801 bool PrintDef, bool IsStandalone,
802 bool ShouldPrintRegisterTies,
803 unsigned TiedOperandIdx,
804 const TargetRegisterInfo *TRI,
805 const TargetIntrinsicInfo *IntrinsicInfo) const {
806 printTargetFlags(OS, *this);
807 switch (getType()) {
809 Register Reg = getReg();
810 if (isImplicit())
811 OS << (isDef() ? "implicit-def " : "implicit ");
812 else if (PrintDef && isDef())
813 // Print the 'def' flag only when the operand is defined after '='.
814 OS << "def ";
815 if (isInternalRead())
816 OS << "internal ";
817 if (isDead())
818 OS << "dead ";
819 if (isKill())
820 OS << "killed ";
821 if (isUndef())
822 OS << "undef ";
823 if (isEarlyClobber())
824 OS << "early-clobber ";
825 if (getReg().isPhysical() && isRenamable())
826 OS << "renamable ";
827 // isDebug() is exactly true for register operands of a DBG_VALUE. So we
828 // simply infer it when parsing and do not need to print it.
829
830 const MachineRegisterInfo *MRI = nullptr;
831 if (Reg.isVirtual()) {
832 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
833 MRI = &MF->getRegInfo();
834 }
835 }
836
837 OS << printReg(Reg, TRI, 0, MRI);
838 // Print the sub register.
839 if (unsigned SubReg = getSubReg()) {
840 if (TRI)
841 OS << '.' << TRI->getSubRegIndexName(SubReg);
842 else
843 OS << ".subreg" << SubReg;
844 }
845 // Print the register class / bank.
846 if (Reg.isVirtual()) {
847 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
848 const MachineRegisterInfo &MRI = MF->getRegInfo();
849 if (IsStandalone || !PrintDef || MRI.def_empty(Reg)) {
850 OS << ':';
851 OS << printRegClassOrBank(Reg, MRI, TRI);
852 }
853 }
854 }
855 // Print ties.
856 if (ShouldPrintRegisterTies && isTied() && !isDef())
857 OS << "(tied-def " << TiedOperandIdx << ")";
858 // Print types.
859 if (TypeToPrint.isValid())
860 OS << '(' << TypeToPrint << ')';
861 break;
862 }
864 const MIRFormatter *Formatter = nullptr;
865 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
866 const auto *TII = MF->getSubtarget().getInstrInfo();
867 assert(TII && "expected instruction info");
868 Formatter = TII->getMIRFormatter();
869 }
870 if (Formatter)
871 Formatter->printImm(OS, *getParent(), OpIdx, getImm());
872 else
873 OS << getImm();
874 break;
875 }
877 getCImm()->printAsOperand(OS, /*PrintType=*/true, MST);
878 break;
880 getFPImm()->printAsOperand(OS, /*PrintType=*/true, MST);
881 break;
884 break;
886 int FrameIndex = getIndex();
887 bool IsFixed = false;
888 const MachineFrameInfo *MFI = nullptr;
889 if (const MachineFunction *MF = getMFIfAvailable(*this))
890 MFI = &MF->getFrameInfo();
891 printFrameIndex(OS, FrameIndex, IsFixed, MFI);
892 break;
893 }
895 OS << "%const." << getIndex();
897 break;
899 OS << "target-index(";
900 const char *Name = "<unknown>";
901 if (const MachineFunction *MF = getMFIfAvailable(*this))
902 if (const auto *TargetIndexName = ::getTargetIndexName(*MF, getIndex()))
903 Name = TargetIndexName;
904 OS << Name << ')';
906 break;
907 }
910 break;
912 if (auto *GV = getGlobal())
913 GV->printAsOperand(OS, /*PrintType=*/false, MST);
914 else // Invalid, but may appear in debugging scenarios.
915 OS << "globaladdress(null)";
916
918 break;
921 OS << '&';
922 if (Name.empty()) {
923 OS << "\"\"";
924 } else {
926 }
928 break;
929 }
931 OS << "blockaddress(";
932 getBlockAddress()->getFunction()->printAsOperand(OS, /*PrintType=*/false,
933 MST);
934 OS << ", ";
935 printIRBlockReference(OS, *getBlockAddress()->getBasicBlock(), MST);
936 OS << ')';
938 break;
939 }
941 OS << "<regmask";
942 if (TRI) {
943 unsigned NumRegsInMask = 0;
944 unsigned NumRegsEmitted = 0;
945 for (unsigned i = 0; i < TRI->getNumRegs(); ++i) {
946 unsigned MaskWord = i / 32;
947 unsigned MaskBit = i % 32;
948 if (getRegMask()[MaskWord] & (1 << MaskBit)) {
949 if (PrintRegMaskNumRegs < 0 ||
950 NumRegsEmitted <= static_cast<unsigned>(PrintRegMaskNumRegs)) {
951 OS << " " << printReg(i, TRI);
952 NumRegsEmitted++;
953 }
954 NumRegsInMask++;
955 }
956 }
957 if (NumRegsEmitted != NumRegsInMask)
958 OS << " and " << (NumRegsInMask - NumRegsEmitted) << " more...";
959 } else {
960 OS << " ...";
961 }
962 OS << ">";
963 break;
964 }
966 const uint32_t *RegMask = getRegLiveOut();
967 OS << "liveout(";
968 if (!TRI) {
969 OS << "<unknown>";
970 } else {
971 bool IsCommaNeeded = false;
972 for (unsigned Reg = 0, E = TRI->getNumRegs(); Reg < E; ++Reg) {
973 if (RegMask[Reg / 32] & (1U << (Reg % 32))) {
974 if (IsCommaNeeded)
975 OS << ", ";
976 OS << printReg(Reg, TRI);
977 IsCommaNeeded = true;
978 }
979 }
980 }
981 OS << ")";
982 break;
983 }
986 break;
989 break;
991 OS << "dbg-instr-ref(" << getInstrRefInstrIndex() << ", "
992 << getInstrRefOpIndex() << ')';
993 break;
994 }
996 if (const MachineFunction *MF = getMFIfAvailable(*this))
997 printCFI(OS, MF->getFrameInstructions()[getCFIIndex()], TRI);
998 else
999 OS << "<cfi directive>";
1000 break;
1001 }
1004 if (ID < Intrinsic::num_intrinsics)
1005 OS << "intrinsic(@" << Intrinsic::getBaseName(ID) << ')';
1006 else if (IntrinsicInfo)
1007 OS << "intrinsic(@" << IntrinsicInfo->getName(ID) << ')';
1008 else
1009 OS << "intrinsic(" << ID << ')';
1010 break;
1011 }
1013 auto Pred = static_cast<CmpInst::Predicate>(getPredicate());
1014 OS << (CmpInst::isIntPredicate(Pred) ? "int" : "float") << "pred("
1015 << Pred << ')';
1016 break;
1017 }
1019 OS << "shufflemask(";
1021 StringRef Separator;
1022 for (int Elt : Mask) {
1023 if (Elt == -1)
1024 OS << Separator << "undef";
1025 else
1026 OS << Separator << Elt;
1027 Separator = ", ";
1028 }
1029
1030 OS << ')';
1031 break;
1032 }
1033}
1034
1035#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1036LLVM_DUMP_METHOD void MachineOperand::dump() const { dbgs() << *this << '\n'; }
1037#endif
1038
1039//===----------------------------------------------------------------------===//
1040// MachineMemOperand Implementation
1041//===----------------------------------------------------------------------===//
1042
1043/// getAddrSpace - Return the LLVM IR address space number that this pointer
1044/// points into.
1046
1047/// isDereferenceable - Return true if V is always dereferenceable for
1048/// Offset + Size byte.
1050 const DataLayout &DL) const {
1051 if (!isa<const Value *>(V))
1052 return false;
1053
1054 const Value *BasePtr = cast<const Value *>(V);
1055 if (BasePtr == nullptr)
1056 return false;
1057
1059 BasePtr, Align(1), APInt(DL.getPointerSizeInBits(), Offset + Size), DL,
1060 dyn_cast<Instruction>(BasePtr));
1061}
1062
1063/// getConstantPool - Return a MachinePointerInfo record that refers to the
1064/// constant pool.
1067}
1068
1069/// getFixedStack - Return a MachinePointerInfo record that refers to the
1070/// the specified FrameIndex.
1072 int FI, int64_t Offset) {
1074}
1075
1078}
1079
1082}
1083
1085 int64_t Offset, uint8_t ID) {
1087}
1088
1091}
1092
1094 LLT type, Align a, const AAMDNodes &AAInfo,
1095 const MDNode *Ranges, SyncScope::ID SSID,
1096 AtomicOrdering Ordering,
1097 AtomicOrdering FailureOrdering)
1098 : PtrInfo(ptrinfo), MemoryType(type), FlagVals(f), BaseAlign(a),
1099 AAInfo(AAInfo), Ranges(Ranges) {
1100 assert((PtrInfo.V.isNull() || isa<const PseudoSourceValue *>(PtrInfo.V) ||
1101 isa<PointerType>(cast<const Value *>(PtrInfo.V)->getType())) &&
1102 "invalid pointer value");
1103 assert((isLoad() || isStore()) && "Not a load/store!");
1104
1105 AtomicInfo.SSID = static_cast<unsigned>(SSID);
1106 assert(getSyncScopeID() == SSID && "Value truncated");
1107 AtomicInfo.Ordering = static_cast<unsigned>(Ordering);
1108 assert(getSuccessOrdering() == Ordering && "Value truncated");
1109 AtomicInfo.FailureOrdering = static_cast<unsigned>(FailureOrdering);
1110 assert(getFailureOrdering() == FailureOrdering && "Value truncated");
1111}
1112
1114 LocationSize TS, Align BaseAlignment,
1115 const AAMDNodes &AAInfo,
1116 const MDNode *Ranges, SyncScope::ID SSID,
1117 AtomicOrdering Ordering,
1118 AtomicOrdering FailureOrdering)
1120 ptrinfo, F,
1121 !TS.hasValue() ? LLT()
1122 : TS.isScalable()
1123 ? LLT::scalable_vector(1, 8 * TS.getValue().getKnownMinValue())
1124 : LLT::scalar(8 * TS.getValue().getKnownMinValue()),
1125 BaseAlignment, AAInfo, Ranges, SSID, Ordering, FailureOrdering) {}
1126
1128 // The Value and Offset may differ due to CSE. But the flags and size
1129 // should be the same.
1130 assert(MMO->getFlags() == getFlags() && "Flags mismatch!");
1131 assert((!MMO->getSize().hasValue() || !getSize().hasValue() ||
1132 MMO->getSize() == getSize()) &&
1133 "Size mismatch!");
1134 if (MMO->getBaseAlign() >= getBaseAlign()) {
1135 // Update the alignment value.
1136 BaseAlign = MMO->getBaseAlign();
1137 // Also update the base and offset, because the new alignment may
1138 // not be applicable with the old ones.
1139 PtrInfo = MMO->PtrInfo;
1140 }
1141}
1142
1143/// getAlign - Return the minimum known alignment in bytes of the
1144/// actual memory reference.
1147}
1148
1151 const LLVMContext &Context,
1152 const MachineFrameInfo *MFI,
1153 const TargetInstrInfo *TII) const {
1154 OS << '(';
1155 if (isVolatile())
1156 OS << "volatile ";
1157 if (isNonTemporal())
1158 OS << "non-temporal ";
1159 if (isDereferenceable())
1160 OS << "dereferenceable ";
1161 if (isInvariant())
1162 OS << "invariant ";
1163 if (TII) {
1166 << "\" ";
1169 << "\" ";
1172 << "\" ";
1173 } else {
1175 OS << "\"MOTargetFlag1\" ";
1177 OS << "\"MOTargetFlag2\" ";
1179 OS << "\"MOTargetFlag3\" ";
1180 }
1181
1182 assert((isLoad() || isStore()) &&
1183 "machine memory operand must be a load or store (or both)");
1184 if (isLoad())
1185 OS << "load ";
1186 if (isStore())
1187 OS << "store ";
1188
1189 printSyncScope(OS, Context, getSyncScopeID(), SSNs);
1190
1192 OS << toIRString(getSuccessOrdering()) << ' ';
1194 OS << toIRString(getFailureOrdering()) << ' ';
1195
1196 if (getMemoryType().isValid())
1197 OS << '(' << getMemoryType() << ')';
1198 else
1199 OS << "unknown-size";
1200
1201 if (const Value *Val = getValue()) {
1202 OS << ((isLoad() && isStore()) ? " on " : isLoad() ? " from " : " into ");
1203 MIRFormatter::printIRValue(OS, *Val, MST);
1204 } else if (const PseudoSourceValue *PVal = getPseudoValue()) {
1205 OS << ((isLoad() && isStore()) ? " on " : isLoad() ? " from " : " into ");
1206 assert(PVal && "Expected a pseudo source value");
1207 switch (PVal->kind()) {
1209 OS << "stack";
1210 break;
1212 OS << "got";
1213 break;
1215 OS << "jump-table";
1216 break;
1218 OS << "constant-pool";
1219 break;
1221 int FrameIndex = cast<FixedStackPseudoSourceValue>(PVal)->getFrameIndex();
1222 bool IsFixed = true;
1223 printFrameIndex(OS, FrameIndex, IsFixed, MFI);
1224 break;
1225 }
1227 OS << "call-entry ";
1228 cast<GlobalValuePseudoSourceValue>(PVal)->getValue()->printAsOperand(
1229 OS, /*PrintType=*/false, MST);
1230 break;
1232 OS << "call-entry &";
1234 OS, cast<ExternalSymbolPseudoSourceValue>(PVal)->getSymbol());
1235 break;
1236 default: {
1237 const MIRFormatter *Formatter = TII->getMIRFormatter();
1238 // FIXME: This is not necessarily the correct MIR serialization format for
1239 // a custom pseudo source value, but at least it allows
1240 // MIR printing to work on a target with custom pseudo source
1241 // values.
1242 OS << "custom \"";
1243 Formatter->printCustomPseudoSourceValue(OS, MST, *PVal);
1244 OS << '\"';
1245 break;
1246 }
1247 }
1248 } else if (getOpaqueValue() == nullptr && getOffset() != 0) {
1249 OS << ((isLoad() && isStore()) ? " on "
1250 : isLoad() ? " from "
1251 : " into ")
1252 << "unknown-address";
1253 }
1255 if (!getSize().hasValue() ||
1256 (!getSize().isZero() &&
1257 getAlign() != getSize().getValue().getKnownMinValue()))
1258 OS << ", align " << getAlign().value();
1259 if (getAlign() != getBaseAlign())
1260 OS << ", basealign " << getBaseAlign().value();
1261 auto AAInfo = getAAInfo();
1262 if (AAInfo.TBAA) {
1263 OS << ", !tbaa ";
1264 AAInfo.TBAA->printAsOperand(OS, MST);
1265 }
1266 if (AAInfo.Scope) {
1267 OS << ", !alias.scope ";
1268 AAInfo.Scope->printAsOperand(OS, MST);
1269 }
1270 if (AAInfo.NoAlias) {
1271 OS << ", !noalias ";
1272 AAInfo.NoAlias->printAsOperand(OS, MST);
1273 }
1274 if (getRanges()) {
1275 OS << ", !range ";
1276 getRanges()->printAsOperand(OS, MST);
1277 }
1278 // FIXME: Implement addrspace printing/parsing in MIR.
1279 // For now, print this even though parsing it is not available in MIR.
1280 if (unsigned AS = getAddrSpace())
1281 OS << ", addrspace " << AS;
1282
1283 OS << ')';
1284}
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()
static bool isUndef(ArrayRef< int > Mask)
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:533
#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 TargetIntrinsicInfo *&IntrinsicInfo, 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)
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:219
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:1069
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:69
unsigned getOperandNo(const_mop_iterator I) const
Returns the number of the operand iterator I points to.
Definition: MachineInstr.h:781
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.
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.
void print(raw_ostream &os, const TargetRegisterInfo *TRI=nullptr, const TargetIntrinsicInfo *IntrinsicInfo=nullptr) const
Print the MachineOperand to os.
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:5250
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
static constexpr bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Definition: Register.h:65
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.
TargetIntrinsicInfo - Interface to description of machine instruction set.
virtual std::string getName(unsigned IID, Type **Tys=nullptr, unsigned numTys=0) const =0
Return the name of a target intrinsic, e.g.
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:5144
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:41
@ 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:215
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:760
MDNode * Scope
The tag for alias scope specification (used with noalias).
Definition: Metadata.h:783
MDNode * TBAA
The tag for type-based alias analysis.
Definition: Metadata.h:777
MDNode * NoAlias
The tag specifying the noalias scope.
Definition: Metadata.h:786
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.