LLVM 24.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 assert(isReg() && "Wrong MachineOperand accessor");
62 if (isDef())
63 return isEarlyClobber();
64 if (!isTied())
65 return false;
66
67 const MachineInstr *MI = getParent();
68 return MI->getOperand(MI->findTiedOperandIdx(getOperandNo()))
69 .isEarlyClobber();
70}
71
73 if (getReg() == Reg)
74 return; // No change.
75
76 // Clear the IsRenamable bit to keep it conservatively correct.
77 IsRenamable = false;
78
79 // Otherwise, we have to change the register. If this operand is embedded
80 // into a machine function, we need to update the old and new register's
81 // use/def lists.
82 if (MachineFunction *MF = getMFIfAvailable(*this)) {
83 MachineRegisterInfo &MRI = MF->getRegInfo();
84 MRI.removeRegOperandFromUseList(this);
85 SmallContents.RegNo = Reg.id();
86 MRI.addRegOperandToUseList(this);
87 return;
88 }
89
90 // Otherwise, just change the register, no problem. :)
91 SmallContents.RegNo = Reg.id();
92}
93
94void MachineOperand::substVirtReg(Register Reg, unsigned SubIdx,
95 const TargetRegisterInfo &TRI) {
96 assert(Reg.isVirtual());
97 if (SubIdx && getSubReg())
98 SubIdx = TRI.composeSubRegIndices(SubIdx, getSubReg());
99 setReg(Reg);
100 if (SubIdx)
101 setSubReg(SubIdx);
102}
103
105 assert(Reg.isPhysical());
106 if (getSubReg()) {
107 Reg = TRI.getSubReg(Reg, getSubReg());
108 // Note that getSubReg() may return 0 if the sub-register doesn't exist.
109 // That won't happen in legal code.
110 setSubReg(0);
111 if (isDef())
112 setIsUndef(false);
113 }
114 setReg(Reg);
115}
116
117/// Change a def to a use, or a use to a def.
119 assert(isReg() && "Wrong MachineOperand accessor");
120 assert((!Val || !isDebug()) && "Marking a debug operation as def");
121 if (IsDef == Val)
122 return;
123 assert(!IsDeadOrKill && "Changing def/use with dead/kill set not supported");
124 // MRI may keep uses and defs in different list positions.
125 if (MachineFunction *MF = getMFIfAvailable(*this)) {
126 MachineRegisterInfo &MRI = MF->getRegInfo();
127 MRI.removeRegOperandFromUseList(this);
128 IsDef = Val;
129 MRI.addRegOperandToUseList(this);
130 return;
131 }
132 IsDef = Val;
133}
134
136 assert(isReg() && "Wrong MachineOperand accessor");
138 "isRenamable should only be checked on physical registers");
139 if (!IsRenamable)
140 return false;
141
142 const MachineInstr *MI = getParent();
143 if (!MI)
144 return true;
145
146 if (isDef())
147 return !MI->hasExtraDefRegAllocReq(MachineInstr::IgnoreBundle);
148
149 assert(isUse() && "Reg is not def or use");
150 return !MI->hasExtraSrcRegAllocReq(MachineInstr::IgnoreBundle);
151}
152
154 assert(isReg() && "Wrong MachineOperand accessor");
156 "setIsRenamable should only be called on physical registers");
157 IsRenamable = Val;
158}
159
160// If this operand is currently a register operand, and if this is in a
161// function, deregister the operand from the register's use/def list.
162void MachineOperand::removeRegFromUses() {
163 if (!isReg() || !isOnRegUseList())
164 return;
165
166 if (MachineFunction *MF = getMFIfAvailable(*this))
167 MF->getRegInfo().removeRegOperandFromUseList(this);
168}
169
170/// ChangeToImmediate - Replace this operand with a new immediate operand of
171/// the specified value. If an operand is known to be an immediate already,
172/// the setImm method should be used.
173void MachineOperand::ChangeToImmediate(int64_t ImmVal, unsigned TargetFlags) {
174 assert((!isReg() || !isTied()) && "Cannot change a tied operand into an imm");
175
176 removeRegFromUses();
177
178 OpKind = MO_Immediate;
179 Contents.ImmVal = ImmVal;
180 setTargetFlags(TargetFlags);
181}
182
184 unsigned TargetFlags) {
185 assert((!isReg() || !isTied()) && "Cannot change a tied operand into an imm");
186
187 removeRegFromUses();
188
189 OpKind = MO_FPImmediate;
190 Contents.CFP = FPImm;
191 setTargetFlags(TargetFlags);
192}
193
194void MachineOperand::ChangeToES(const char *SymName,
195 unsigned TargetFlags) {
196 assert((!isReg() || !isTied()) &&
197 "Cannot change a tied operand into an external symbol");
198
199 removeRegFromUses();
200
201 OpKind = MO_ExternalSymbol;
202 Contents.OffsetedInfo.Val.SymbolName = SymName;
203 setOffset(0); // Offset is always 0.
204 setTargetFlags(TargetFlags);
205}
206
208 unsigned TargetFlags) {
209 assert((!isReg() || !isTied()) &&
210 "Cannot change a tied operand into a global address");
211
212 removeRegFromUses();
213
214 OpKind = MO_GlobalAddress;
215 Contents.OffsetedInfo.Val.GV = GV;
217 setTargetFlags(TargetFlags);
218}
219
221 unsigned TargetFlags) {
222 assert((!isReg() || !isTied()) &&
223 "Cannot change a tied operand into a block address");
224
225 removeRegFromUses();
226
227 OpKind = MO_BlockAddress;
228 Contents.OffsetedInfo.Val.BA = BA;
230 setTargetFlags(TargetFlags);
231}
232
233void MachineOperand::ChangeToCPI(unsigned Idx, int Offset,
234 unsigned TargetFlags) {
235 assert((!isReg() || !isTied()) &&
236 "Cannot change a tied operand into a constant pool index");
237
238 removeRegFromUses();
239
240 OpKind = MO_ConstantPoolIndex;
241 setIndex(Idx);
243 setTargetFlags(TargetFlags);
244}
245
246void MachineOperand::ChangeToMCSymbol(MCSymbol *Sym, unsigned TargetFlags) {
247 assert((!isReg() || !isTied()) &&
248 "Cannot change a tied operand into an MCSymbol");
249
250 removeRegFromUses();
251
252 OpKind = MO_MCSymbol;
253 Contents.Sym = Sym;
254 setTargetFlags(TargetFlags);
255}
256
257void MachineOperand::ChangeToFrameIndex(int Idx, unsigned TargetFlags) {
258 assert((!isReg() || !isTied()) &&
259 "Cannot change a tied operand into a FrameIndex");
260
261 removeRegFromUses();
262
263 OpKind = MO_FrameIndex;
264 setIndex(Idx);
265 setTargetFlags(TargetFlags);
266}
267
269 unsigned TargetFlags) {
270 assert((!isReg() || !isTied()) &&
271 "Cannot change a tied operand into a FrameIndex");
272
273 removeRegFromUses();
274
275 OpKind = MO_TargetIndex;
276 setIndex(Idx);
278 setTargetFlags(TargetFlags);
279}
280
281void MachineOperand::ChangeToDbgInstrRef(unsigned InstrIdx, unsigned OpIdx,
282 unsigned TargetFlags) {
283 assert((!isReg() || !isTied()) &&
284 "Cannot change a tied operand into a DbgInstrRef");
285
286 removeRegFromUses();
287
288 OpKind = MO_DbgInstrRef;
289 setInstrRefInstrIndex(InstrIdx);
290 setInstrRefOpIndex(OpIdx);
291 setTargetFlags(TargetFlags);
292}
293
294/// ChangeToRegister - Replace this operand with a new register operand of
295/// the specified value. If an operand is known to be an register already,
296/// the setReg method should be used.
298 bool isKill, bool isDead, bool isUndef,
299 bool isDebug) {
300 MachineRegisterInfo *RegInfo = nullptr;
301 if (MachineFunction *MF = getMFIfAvailable(*this))
302 RegInfo = &MF->getRegInfo();
303 // If this operand is already a register operand, remove it from the
304 // register's use/def lists.
305 bool WasReg = isReg();
306 if (RegInfo && WasReg)
307 RegInfo->removeRegOperandFromUseList(this);
308
309 // Ensure debug instructions set debug flag on register uses.
310 const MachineInstr *MI = getParent();
311 if (!isDef && MI && MI->isDebugInstr())
312 isDebug = true;
313
314 // Change this to a register and set the reg#.
315 assert(!(isDead && !isDef) && "Dead flag on non-def");
316 assert(!(isKill && isDef) && "Kill flag on def");
317 OpKind = MO_Register;
318 SmallContents.RegNo = Reg.id();
319 SubReg_TargetFlags = 0;
320 IsDef = isDef;
321 IsImp = isImp;
322 IsDeadOrKill = isKill | isDead;
323 IsRenamable = false;
324 IsUndef = isUndef;
325 IsInternalRead = false;
326 IsEarlyClobber = false;
327 IsDebug = isDebug;
328 // Ensure isOnRegUseList() returns false.
329 Contents.Reg.Prev = nullptr;
330 // Preserve the tie when the operand was already a register.
331 if (!WasReg)
332 TiedTo = 0;
333
334 // If this operand is embedded in a function, add the operand to the
335 // register's use/def list.
336 if (RegInfo)
337 RegInfo->addRegOperandToUseList(this);
338}
339
340/// isIdenticalTo - Return true if this operand is identical to the specified
341/// operand. Note that this should stay in sync with the hash_value overload
342/// below.
343bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {
344 if (getType() != Other.getType() ||
345 getTargetFlags() != Other.getTargetFlags())
346 return false;
347
348 switch (getType()) {
350 return getReg() == Other.getReg() && isDef() == Other.isDef() &&
351 getSubReg() == Other.getSubReg();
353 return getImm() == Other.getImm();
355 return getCImm() == Other.getCImm();
357 return getFPImm() == Other.getFPImm();
359 return getMBB() == Other.getMBB();
361 return getIndex() == Other.getIndex();
364 return getIndex() == Other.getIndex() && getOffset() == Other.getOffset();
366 return getIndex() == Other.getIndex();
368 return getGlobal() == Other.getGlobal() && getOffset() == Other.getOffset();
370 return strcmp(getSymbolName(), Other.getSymbolName()) == 0 &&
371 getOffset() == Other.getOffset();
373 return getBlockAddress() == Other.getBlockAddress() &&
374 getOffset() == Other.getOffset();
377 // Shallow compare of the two RegMasks
378 const uint32_t *RegMask = isRegMask() ? getRegMask() : getRegLiveOut();
379 const uint32_t *OtherRegMask =
380 isRegMask() ? Other.getRegMask() : Other.getRegLiveOut();
381 if (RegMask == OtherRegMask)
382 return true;
383
384 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
385 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
386 unsigned RegMaskSize = MachineOperand::getRegMaskSize(TRI->getNumRegs());
387 // Deep compare of the two RegMasks
388 return std::equal(RegMask, RegMask + RegMaskSize, OtherRegMask);
389 }
390 // We don't know the size of the RegMask, so we can't deep compare the two
391 // reg masks.
392 return false;
393 }
395 return getMCSymbol() == Other.getMCSymbol();
397 return getInstrRefInstrIndex() == Other.getInstrRefInstrIndex() &&
398 getInstrRefOpIndex() == Other.getInstrRefOpIndex();
400 return getCFIIndex() == Other.getCFIIndex();
402 return getMetadata() == Other.getMetadata();
404 return getIntrinsicID() == Other.getIntrinsicID();
406 return getPredicate() == Other.getPredicate();
408 return getShuffleMask() == Other.getShuffleMask();
410 return getLaneMask() == Other.getLaneMask();
411 }
412 llvm_unreachable("Invalid machine operand type");
413}
414
415// Note: this must stay exactly in sync with isIdenticalTo above.
417 switch (MO.getType()) {
419 // Register operands don't have target flags.
420 return hash_combine(MO.getType(), MO.getReg().id(), MO.getSubReg(),
421 MO.isDef());
423 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getImm());
425 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getCImm());
427 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getFPImm());
429 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMBB());
431 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex());
434 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex(),
435 MO.getOffset());
437 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex());
439 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getOffset(),
442 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getGlobal(),
443 MO.getOffset());
445 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getBlockAddress(),
446 MO.getOffset());
449 if (const MachineFunction *MF = getMFIfAvailable(MO)) {
450 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
451 unsigned RegMaskSize = MachineOperand::getRegMaskSize(TRI->getNumRegs());
452 const uint32_t *RegMask =
453 MO.isRegMask() ? MO.getRegMask() : MO.getRegLiveOut();
454 std::vector<stable_hash> RegMaskHashes(RegMask, RegMask + RegMaskSize);
455 return hash_combine(MO.getType(), MO.getTargetFlags(),
456 stable_hash_combine(RegMaskHashes));
457 }
458
459 assert(0 && "MachineOperand not associated with any MachineFunction");
460 return hash_combine(MO.getType(), MO.getTargetFlags());
461 }
463 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMetadata());
465 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMCSymbol());
467 return hash_combine(MO.getType(), MO.getTargetFlags(),
470 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getCFIIndex());
472 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIntrinsicID());
474 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getPredicate());
476 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getShuffleMask());
478 return hash_combine(MO.getType(), MO.getTargetFlags(),
480 }
481 llvm_unreachable("Invalid machine operand type");
482}
483
484// Try to crawl up to the machine function and get TRI from it.
485static void tryToGetTargetInfo(const MachineOperand &MO,
486 const TargetRegisterInfo *&TRI) {
487 if (const MachineFunction *MF = getMFIfAvailable(MO)) {
488 TRI = MF->getSubtarget().getRegisterInfo();
489 }
490}
491
492static const char *getTargetIndexName(const MachineFunction &MF, int Index) {
493 const auto *TII = MF.getSubtarget().getInstrInfo();
494 assert(TII && "expected instruction info");
495 auto Indices = TII->getSerializableTargetIndices();
496 auto Found = find_if(Indices, [&](const std::pair<int, const char *> &I) {
497 return I.first == Index;
498 });
499 if (Found != Indices.end())
500 return Found->second;
501 return nullptr;
502}
503
505 const MachineFunction *MF = getMFIfAvailable(*this);
506 return MF ? ::getTargetIndexName(*MF, this->getIndex()) : nullptr;
507}
508
509static const char *getTargetFlagName(const TargetInstrInfo *TII, unsigned TF) {
510 auto Flags = TII->getSerializableDirectMachineOperandTargetFlags();
511 for (const auto &I : Flags) {
512 if (I.first == TF) {
513 return I.second;
514 }
515 }
516 return nullptr;
517}
518
519static void printCFIRegister(unsigned DwarfReg, raw_ostream &OS,
520 const TargetRegisterInfo *TRI) {
521 if (!TRI) {
522 OS << "%dwarfreg." << DwarfReg;
523 return;
524 }
525
526 if (std::optional<MCRegister> Reg = TRI->getLLVMRegNum(DwarfReg, true))
527 OS << printReg(*Reg, TRI);
528 else
529 OS << "<badreg>";
530}
531
533 ModuleSlotTracker &MST) {
534 OS << "%ir-block.";
535 if (BB.hasName()) {
537 return;
538 }
539 std::optional<int> Slot;
540 if (const Function *F = BB.getParent()) {
541 if (F == MST.getCurrentFunction()) {
542 Slot = MST.getLocalSlot(&BB);
543 } else if (const Module *M = F->getParent()) {
544 ModuleSlotTracker CustomMST(M);
545 CustomMST.incorporateFunction(*F);
546 Slot = CustomMST.getLocalSlot(&BB);
547 }
548 }
549 if (Slot)
551 else
552 OS << "<unknown>";
553}
554
555static void printSyncScope(raw_ostream &OS, const LLVMContext &Context,
556 SyncScope::ID SSID,
558 switch (SSID) {
560 break;
561 default:
562 if (SSNs.empty())
563 Context.getSyncScopeNames(SSNs);
564
565 OS << "syncscope(\"";
566 printEscapedString(SSNs[SSID], OS);
567 OS << "\") ";
568 break;
569 }
570}
571
572static const char *getTargetMMOFlagName(const TargetInstrInfo &TII,
573 unsigned TMMOFlag) {
574 auto Flags = TII.getSerializableMachineMemOperandTargetFlags();
575 for (const auto &I : Flags) {
576 if (I.first == TMMOFlag) {
577 return I.second;
578 }
579 }
580 return nullptr;
581}
582
583static void printFrameIndex(raw_ostream& OS, int FrameIndex, bool IsFixed,
584 const MachineFrameInfo *MFI) {
585 StringRef Name;
586 if (MFI) {
587 IsFixed = MFI->isFixedObjectIndex(FrameIndex);
588 if (const AllocaInst *Alloca = MFI->getObjectAllocation(FrameIndex))
589 if (Alloca->hasName())
590 Name = Alloca->getName();
591 if (IsFixed)
592 FrameIndex -= MFI->getObjectIndexBegin();
593 }
594 MachineOperand::printStackObjectReference(OS, FrameIndex, IsFixed, Name);
595}
596
598 const TargetRegisterInfo *TRI) {
599 OS << "%subreg.";
600 if (TRI && Index != 0 && Index < TRI->getNumSubRegIndices())
601 OS << TRI->getSubRegIndexName(Index);
602 else
603 OS << Index;
604}
605
607 const MachineOperand &Op) {
608 if (!Op.getTargetFlags())
609 return;
611 if (!MF)
612 return;
613
614 const auto *TII = MF->getSubtarget().getInstrInfo();
615 assert(TII && "expected instruction info");
616 auto Flags = TII->decomposeMachineOperandsTargetFlags(Op.getTargetFlags());
617 OS << "target-flags(";
618 const bool HasDirectFlags = Flags.first;
619 const bool HasBitmaskFlags = Flags.second;
620 if (!HasDirectFlags && !HasBitmaskFlags) {
621 OS << "<unknown>) ";
622 return;
623 }
624 if (HasDirectFlags) {
625 if (const auto *Name = getTargetFlagName(TII, Flags.first))
626 OS << Name;
627 else
628 OS << "<unknown target flag>";
629 }
630 if (!HasBitmaskFlags) {
631 OS << ") ";
632 return;
633 }
634 bool IsCommaNeeded = HasDirectFlags;
635 unsigned BitMask = Flags.second;
636 auto BitMasks = TII->getSerializableBitmaskMachineOperandTargetFlags();
637 for (const auto &Mask : BitMasks) {
638 // Check if the flag's bitmask has the bits of the current mask set.
639 if ((BitMask & Mask.first) == Mask.first) {
640 if (IsCommaNeeded)
641 OS << ", ";
642 IsCommaNeeded = true;
643 OS << Mask.second;
644 // Clear the bits which were serialized from the flag's bitmask.
645 BitMask &= ~(Mask.first);
646 }
647 }
648 if (BitMask) {
649 // When the resulting flag's bitmask isn't zero, we know that we didn't
650 // serialize all of the bit flags.
651 if (IsCommaNeeded)
652 OS << ", ";
653 OS << "<unknown bitmask target flag>";
654 }
655 OS << ") ";
656}
657
659 OS << "<mcsymbol " << Sym << ">";
660}
661
663 unsigned FrameIndex,
664 bool IsFixed, StringRef Name) {
665 if (IsFixed) {
666 OS << "%fixed-stack." << FrameIndex;
667 return;
668 }
669
670 OS << "%stack." << FrameIndex;
671 if (!Name.empty())
672 OS << '.' << Name;
673}
674
676 if (Offset == 0)
677 return;
678 if (Offset < 0) {
679 OS << " - " << -Offset;
680 return;
681 }
682 OS << " + " << Offset;
683}
684
686 if (Slot == -1)
687 OS << "<badref>";
688 else
689 OS << Slot;
690}
691
692static void printCFI(raw_ostream &OS, const MCCFIInstruction &CFI,
693 const TargetRegisterInfo *TRI) {
694 switch (CFI.getOperation()) {
696 OS << "same_value ";
697 if (MCSymbol *Label = CFI.getLabel())
698 MachineOperand::printSymbol(OS, *Label);
699 printCFIRegister(CFI.getRegister(), OS, TRI);
700 break;
702 OS << "remember_state ";
703 if (MCSymbol *Label = CFI.getLabel())
704 MachineOperand::printSymbol(OS, *Label);
705 break;
707 OS << "restore_state ";
708 if (MCSymbol *Label = CFI.getLabel())
709 MachineOperand::printSymbol(OS, *Label);
710 break;
712 OS << "offset ";
713 if (MCSymbol *Label = CFI.getLabel())
714 MachineOperand::printSymbol(OS, *Label);
715 printCFIRegister(CFI.getRegister(), OS, TRI);
716 OS << ", " << CFI.getOffset();
717 break;
719 OS << "def_cfa_register ";
720 if (MCSymbol *Label = CFI.getLabel())
721 MachineOperand::printSymbol(OS, *Label);
722 printCFIRegister(CFI.getRegister(), OS, TRI);
723 break;
725 OS << "def_cfa_offset ";
726 if (MCSymbol *Label = CFI.getLabel())
727 MachineOperand::printSymbol(OS, *Label);
728 OS << CFI.getOffset();
729 break;
731 OS << "def_cfa ";
732 if (MCSymbol *Label = CFI.getLabel())
733 MachineOperand::printSymbol(OS, *Label);
734 printCFIRegister(CFI.getRegister(), OS, TRI);
735 OS << ", " << CFI.getOffset();
736 break;
738 OS << "llvm_def_aspace_cfa ";
739 if (MCSymbol *Label = CFI.getLabel())
740 MachineOperand::printSymbol(OS, *Label);
741 printCFIRegister(CFI.getRegister(), OS, TRI);
742 OS << ", " << CFI.getOffset();
743 OS << ", " << CFI.getAddressSpace();
744 break;
746 OS << "rel_offset ";
747 if (MCSymbol *Label = CFI.getLabel())
748 MachineOperand::printSymbol(OS, *Label);
749 printCFIRegister(CFI.getRegister(), OS, TRI);
750 OS << ", " << CFI.getOffset();
751 break;
753 OS << "adjust_cfa_offset ";
754 if (MCSymbol *Label = CFI.getLabel())
755 MachineOperand::printSymbol(OS, *Label);
756 OS << CFI.getOffset();
757 break;
759 OS << "restore ";
760 if (MCSymbol *Label = CFI.getLabel())
761 MachineOperand::printSymbol(OS, *Label);
762 printCFIRegister(CFI.getRegister(), OS, TRI);
763 break;
765 OS << "escape ";
766 if (MCSymbol *Label = CFI.getLabel())
767 MachineOperand::printSymbol(OS, *Label);
768 if (!CFI.getValues().empty()) {
769 size_t e = CFI.getValues().size() - 1;
770 for (size_t i = 0; i < e; ++i)
771 OS << format("0x%02x", uint8_t(CFI.getValues()[i])) << ", ";
772 OS << format("0x%02x", uint8_t(CFI.getValues()[e]));
773 }
774 break;
775 }
777 OS << "undefined ";
778 if (MCSymbol *Label = CFI.getLabel())
779 MachineOperand::printSymbol(OS, *Label);
780 printCFIRegister(CFI.getRegister(), OS, TRI);
781 break;
783 OS << "register ";
784 if (MCSymbol *Label = CFI.getLabel())
785 MachineOperand::printSymbol(OS, *Label);
786 printCFIRegister(CFI.getRegister(), OS, TRI);
787 OS << ", ";
789 break;
791 OS << "window_save ";
792 if (MCSymbol *Label = CFI.getLabel())
793 MachineOperand::printSymbol(OS, *Label);
794 break;
796 OS << "negate_ra_sign_state ";
797 if (MCSymbol *Label = CFI.getLabel())
798 MachineOperand::printSymbol(OS, *Label);
799 break;
801 OS << "negate_ra_sign_state_with_pc ";
802 if (MCSymbol *Label = CFI.getLabel())
803 MachineOperand::printSymbol(OS, *Label);
804 break;
806 OS << "llvm_set_ra_state ";
807 if (MCSymbol *Label = CFI.getLabel())
808 MachineOperand::printSymbol(OS, *Label);
809 OS << CFI.getRASignState() << ", ";
810 if (MCSymbol *PACSym = CFI.getRASignSymbol())
811 MachineOperand::printSymbol(OS, *PACSym);
812 else
813 OS << CFI.getRASignOffset();
814 break;
815 }
817 const auto &Fields =
819
820 OS << "llvm_register_pair ";
821 if (MCSymbol *Label = CFI.getLabel())
822 MachineOperand::printSymbol(OS, *Label);
823 printCFIRegister(Fields.Register, OS, TRI);
824 OS << ", ";
825 printCFIRegister(Fields.Reg1, OS, TRI);
826 OS << ", " << Fields.Reg1SizeInBits << ", ";
827 printCFIRegister(Fields.Reg2, OS, TRI);
828 OS << ", " << Fields.Reg2SizeInBits;
829 break;
830 }
832 const auto &Fields =
834
835 OS << "llvm_vector_registers ";
836 if (MCSymbol *Label = CFI.getLabel())
837 MachineOperand::printSymbol(OS, *Label);
838 printCFIRegister(Fields.Register, OS, TRI);
839 for (auto [Reg, Lane, Size] : Fields.VectorRegisters) {
840 OS << ", ";
842 OS << ", " << Lane << ", " << Size;
843 }
844 break;
845 }
847 const auto &Fields =
849
850 OS << "llvm_vector_offset ";
851 if (MCSymbol *Label = CFI.getLabel())
852 MachineOperand::printSymbol(OS, *Label);
853 printCFIRegister(Fields.Register, OS, TRI);
854 OS << ", " << Fields.RegisterSizeInBits << ", ";
855 printCFIRegister(Fields.MaskRegister, OS, TRI);
856 OS << ", " << Fields.MaskRegisterSizeInBits << ", " << Fields.Offset;
857 break;
858 }
860 const auto &Fields =
862
863 OS << "llvm_vector_register_mask ";
864 if (MCSymbol *Label = CFI.getLabel())
865 MachineOperand::printSymbol(OS, *Label);
866 printCFIRegister(Fields.Register, OS, TRI);
867 OS << ", ";
868 printCFIRegister(Fields.SpillRegister, OS, TRI);
869 OS << ", " << Fields.SpillRegisterLaneSizeInBits << ", ";
870 printCFIRegister(Fields.MaskRegister, OS, TRI);
871 OS << ", " << Fields.MaskRegisterSizeInBits;
872 break;
873 }
874 default:
875 // TODO: Print the other CFI Operations.
876 OS << "<unserializable cfi directive>";
877 break;
878 }
879}
880
882 const TargetRegisterInfo *TRI) const {
883 print(OS, LLT{}, TRI);
884}
885
887 const TargetRegisterInfo *TRI) const {
888 tryToGetTargetInfo(*this, TRI);
889 ModuleSlotTracker DummyMST(nullptr);
890 print(OS, DummyMST, TypeToPrint, std::nullopt, /*PrintDef=*/false,
891 /*IsStandalone=*/true,
892 /*ShouldPrintRegisterTies=*/true,
893 /*TiedOperandIdx=*/0, TRI);
894}
895
897 LLT TypeToPrint, std::optional<unsigned> OpIdx,
898 bool PrintDef, bool IsStandalone,
899 bool ShouldPrintRegisterTies,
900 unsigned TiedOperandIdx,
901 const TargetRegisterInfo *TRI) const {
902 printTargetFlags(OS, *this);
903 switch (getType()) {
905 Register Reg = getReg();
906 if (isImplicit())
907 OS << (isDef() ? "implicit-def " : "implicit ");
908 else if (PrintDef && isDef())
909 // Print the 'def' flag only when the operand is defined after '='.
910 OS << "def ";
911 if (isInternalRead())
912 OS << "internal ";
913 if (isDead())
914 OS << "dead ";
915 if (isKill())
916 OS << "killed ";
917 if (isUndef())
918 OS << "undef ";
919 if (isEarlyClobber())
920 OS << "early-clobber ";
921 if (getReg().isPhysical() && isRenamable())
922 OS << "renamable ";
923 // isDebug() is exactly true for register operands of a DBG_VALUE. So we
924 // simply infer it when parsing and do not need to print it.
925
926 const MachineRegisterInfo *MRI = nullptr;
927 if (Reg.isVirtual()) {
928 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
929 MRI = &MF->getRegInfo();
930 }
931 }
932
933 OS << printReg(Reg, TRI, 0, MRI);
934 // Print the sub register.
935 if (unsigned SubReg = getSubReg()) {
936 if (TRI)
937 OS << '.' << TRI->getSubRegIndexName(SubReg);
938 else
939 OS << ".subreg" << SubReg;
940 }
941 // Print the register class / bank.
942 if (Reg.isVirtual()) {
943 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
944 const MachineRegisterInfo &MRI = MF->getRegInfo();
945 if (IsStandalone || !PrintDef || MRI.def_empty(Reg)) {
946 OS << ':';
947 OS << printRegClassOrBank(Reg, MRI, TRI);
948 }
949 }
950 }
951 // Print ties.
952 if (ShouldPrintRegisterTies && isTied() && !isDef())
953 OS << "(tied-def " << TiedOperandIdx << ")";
954 // Print types.
955 if (TypeToPrint.isValid())
956 OS << '(' << TypeToPrint << ')';
957 break;
958 }
960 const MIRFormatter *Formatter = nullptr;
961 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
962 const auto *TII = MF->getSubtarget().getInstrInfo();
963 assert(TII && "expected instruction info");
964 Formatter = TII->getMIRFormatter();
965 }
966 if (Formatter)
967 Formatter->printImm(OS, *getParent(), OpIdx, getImm());
968 else
969 OS << getImm();
970 break;
971 }
973 getCImm()->printAsOperand(OS, /*PrintType=*/true, MST);
974 break;
976 getFPImm()->printAsOperand(OS, /*PrintType=*/true, MST);
977 break;
979 OS << printMBBReference(*getMBB());
980 break;
982 int FrameIndex = getIndex();
983 bool IsFixed = false;
984 const MachineFrameInfo *MFI = nullptr;
985 if (const MachineFunction *MF = getMFIfAvailable(*this))
986 MFI = &MF->getFrameInfo();
987 printFrameIndex(OS, FrameIndex, IsFixed, MFI);
988 break;
989 }
991 OS << "%const." << getIndex();
993 break;
995 OS << "target-index(";
996 const char *Name = "<unknown>";
997 if (const MachineFunction *MF = getMFIfAvailable(*this))
998 if (const auto *TargetIndexName = ::getTargetIndexName(*MF, getIndex()))
999 Name = TargetIndexName;
1000 OS << Name << ')';
1002 break;
1003 }
1006 break;
1008 if (auto *GV = getGlobal())
1009 GV->printAsOperand(OS, /*PrintType=*/false, MST);
1010 else // Invalid, but may appear in debugging scenarios.
1011 OS << "globaladdress(null)";
1012
1014 break;
1016 StringRef Name = getSymbolName();
1017 OS << '&';
1018 if (Name.empty()) {
1019 OS << "\"\"";
1020 } else {
1022 }
1024 break;
1025 }
1027 OS << "blockaddress(";
1028 getBlockAddress()->getFunction()->printAsOperand(OS, /*PrintType=*/false,
1029 MST);
1030 OS << ", ";
1031 printIRBlockReference(OS, *getBlockAddress()->getBasicBlock(), MST);
1032 OS << ')';
1034 break;
1035 }
1037 OS << "<regmask";
1038 if (TRI) {
1039 unsigned NumRegsInMask = 0;
1040 unsigned NumRegsEmitted = 0;
1041 for (unsigned i = 0; i < TRI->getNumRegs(); ++i) {
1042 unsigned MaskWord = i / 32;
1043 unsigned MaskBit = i % 32;
1044 if (getRegMask()[MaskWord] & (1 << MaskBit)) {
1045 if (PrintRegMaskNumRegs < 0 ||
1046 NumRegsEmitted <= static_cast<unsigned>(PrintRegMaskNumRegs)) {
1047 OS << " " << printReg(i, TRI);
1048 NumRegsEmitted++;
1049 }
1050 NumRegsInMask++;
1051 }
1052 }
1053 if (NumRegsEmitted != NumRegsInMask)
1054 OS << " and " << (NumRegsInMask - NumRegsEmitted) << " more...";
1055 } else {
1056 OS << " ...";
1057 }
1058 OS << ">";
1059 break;
1060 }
1062 const uint32_t *RegMask = getRegLiveOut();
1063 OS << "liveout(";
1064 if (!TRI) {
1065 OS << "<unknown>";
1066 } else {
1067 bool IsCommaNeeded = false;
1068 for (unsigned Reg = 0, E = TRI->getNumRegs(); Reg < E; ++Reg) {
1069 if (RegMask[Reg / 32] & (1U << (Reg % 32))) {
1070 if (IsCommaNeeded)
1071 OS << ", ";
1072 OS << printReg(Reg, TRI);
1073 IsCommaNeeded = true;
1074 }
1075 }
1076 }
1077 OS << ")";
1078 break;
1079 }
1081 getMetadata()->printAsOperand(OS, MST);
1082 break;
1084 printSymbol(OS, *getMCSymbol());
1085 break;
1087 OS << "dbg-instr-ref(" << getInstrRefInstrIndex() << ", "
1088 << getInstrRefOpIndex() << ')';
1089 break;
1090 }
1092 if (const MachineFunction *MF = getMFIfAvailable(*this))
1093 printCFI(OS, MF->getFrameInstructions()[getCFIIndex()], TRI);
1094 else
1095 OS << "<cfi directive>";
1096 break;
1097 }
1100 if (ID < Intrinsic::num_intrinsics)
1101 OS << "intrinsic(@" << Intrinsic::getBaseName(ID) << ')';
1102 else
1103 OS << "intrinsic(" << ID << ')';
1104 break;
1105 }
1107 auto Pred = static_cast<CmpInst::Predicate>(getPredicate());
1108 OS << (CmpInst::isIntPredicate(Pred) ? "int" : "float") << "pred(" << Pred
1109 << ')';
1110 break;
1111 }
1113 OS << "shufflemask(";
1115 StringRef Separator;
1116 for (int Elt : Mask) {
1117 if (Elt == -1)
1118 OS << Separator << "undef";
1119 else
1120 OS << Separator << Elt;
1121 Separator = ", ";
1122 }
1123
1124 OS << ')';
1125 break;
1126 }
1128 OS << "lanemask(";
1129 LaneBitmask LaneMask = getLaneMask();
1130 OS << "0x" << PrintLaneMask(LaneMask);
1131 OS << ')';
1132 break;
1133 }
1134 }
1135}
1136
1137#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1138LLVM_DUMP_METHOD void MachineOperand::dump() const { dbgs() << *this << '\n'; }
1139#endif
1140
1141//===----------------------------------------------------------------------===//
1142// MachineMemOperand Implementation
1143//===----------------------------------------------------------------------===//
1144
1145/// getAddrSpace - Return the LLVM IR address space number that this pointer
1146/// points into.
1148
1149/// isDereferenceable - Return true if V is always dereferenceable for
1150/// Offset + Size byte.
1152 const DataLayout &DL) const {
1153 if (!isa<const Value *>(V))
1154 return false;
1155
1156 const Value *BasePtr = cast<const Value *>(V);
1157 if (BasePtr == nullptr)
1158 return false;
1159
1161 BasePtr, APInt(DL.getPointerSizeInBits(), Offset + Size),
1163}
1164
1165/// getConstantPool - Return a MachinePointerInfo record that refers to the
1166/// constant pool.
1170
1171/// getFixedStack - Return a MachinePointerInfo record that refers to the
1172/// the specified FrameIndex.
1177
1181
1185
1190
1194
1196 LLT Type, Align A,
1197 const MMOMetadata &Metadata,
1198 SyncScope::ID SSID,
1199 AtomicOrdering Ordering,
1200 AtomicOrdering FailureOrdering)
1201 : PtrInfo(PtrInfo), MemoryType(Type), FlagVals(F), BaseAlign(A),
1202 AAInfo(Metadata.AAInfo), Ranges(Metadata.Ranges),
1203 MemCacheHint(Metadata.MemCacheHint) {
1204 assert((PtrInfo.V.isNull() || isa<const PseudoSourceValue *>(PtrInfo.V) ||
1205 isa<PointerType>(cast<const Value *>(PtrInfo.V)->getType())) &&
1206 "invalid pointer value");
1207 assert((isLoad() || isStore()) && "Not a load/store!");
1208
1209 AtomicInfo.SSID = static_cast<unsigned>(SSID);
1210 assert(getSyncScopeID() == SSID && "Value truncated");
1211 AtomicInfo.Ordering = static_cast<unsigned>(Ordering);
1212 assert(getSuccessOrdering() == Ordering && "Value truncated");
1213 AtomicInfo.FailureOrdering = static_cast<unsigned>(FailureOrdering);
1214 assert(getFailureOrdering() == FailureOrdering && "Value truncated");
1215}
1216
1218 LocationSize TS, Align BaseAlignment,
1219 const MMOMetadata &Metadata,
1220 SyncScope::ID SSID,
1221 AtomicOrdering Ordering,
1222 AtomicOrdering FailureOrdering)
1224 PtrInfo, F,
1225 !TS.isPrecise() ? LLT()
1226 : TS.isScalable()
1227 ? LLT::scalable_vector(1, 8 * TS.getValue().getKnownMinValue())
1228 : LLT::scalar(8 * TS.getValue().getKnownMinValue()),
1229 BaseAlignment, Metadata, SSID, Ordering, FailureOrdering) {}
1230
1232 // The Value and Offset may differ due to CSE. But the flags and size
1233 // should be the same.
1234 assert(MMO->getFlags() == getFlags() && "Flags mismatch!");
1235 assert((!MMO->getSize().hasValue() || !getSize().hasValue() ||
1236 MMO->getSize() == getSize()) &&
1237 "Size mismatch!");
1238 if (MMO->getBaseAlign() >= getBaseAlign()) {
1239 // Update the alignment value.
1240 BaseAlign = MMO->getBaseAlign();
1241 // Also update the base and offset, because the new alignment may
1242 // not be applicable with the old ones.
1243 PtrInfo = MMO->PtrInfo;
1244 }
1245}
1246
1247/// getAlign - Return the minimum known alignment in bytes of the
1248/// actual memory reference.
1252
1255 const LLVMContext &Context,
1256 const MachineFrameInfo *MFI,
1257 const TargetInstrInfo *TII) const {
1258 OS << '(';
1259 if (isVolatile())
1260 OS << "volatile ";
1261 if (isNonTemporal())
1262 OS << "non-temporal ";
1263 if (isDereferenceable())
1264 OS << "dereferenceable ";
1265 if (isInvariant())
1266 OS << "invariant ";
1267 if (TII) {
1270 << "\" ";
1273 << "\" ";
1276 << "\" ";
1279 << "\" ";
1282 << "\" ";
1285 << "\" ";
1286 } else {
1288 OS << "\"MOTargetFlag1\" ";
1290 OS << "\"MOTargetFlag2\" ";
1292 OS << "\"MOTargetFlag3\" ";
1294 OS << "\"MOTargetFlag4\" ";
1296 OS << "\"MOTargetFlag5\" ";
1298 OS << "\"MOTargetFlag6\" ";
1299 }
1300
1301 assert((isLoad() || isStore()) &&
1302 "machine memory operand must be a load or store (or both)");
1303 if (isLoad())
1304 OS << "load ";
1305 if (isStore())
1306 OS << "store ";
1307
1308 printSyncScope(OS, Context, getSyncScopeID(), SSNs);
1309
1311 OS << toIRString(getSuccessOrdering()) << ' ';
1313 OS << toIRString(getFailureOrdering()) << ' ';
1314
1315 if (getMemoryType().isValid())
1316 OS << '(' << getMemoryType() << ')';
1317 else
1318 OS << "unknown-size";
1319
1320 if (const Value *Val = getValue()) {
1321 OS << ((isLoad() && isStore()) ? " on " : isLoad() ? " from " : " into ");
1322 MIRFormatter::printIRValue(OS, *Val, MST);
1323 } else if (const PseudoSourceValue *PVal = getPseudoValue()) {
1324 OS << ((isLoad() && isStore()) ? " on " : isLoad() ? " from " : " into ");
1325 assert(PVal && "Expected a pseudo source value");
1326 switch (PVal->kind()) {
1328 OS << "stack";
1329 break;
1331 OS << "got";
1332 break;
1334 OS << "jump-table";
1335 break;
1337 OS << "constant-pool";
1338 break;
1340 int FrameIndex = cast<FixedStackPseudoSourceValue>(PVal)->getFrameIndex();
1341 bool IsFixed = true;
1342 printFrameIndex(OS, FrameIndex, IsFixed, MFI);
1343 break;
1344 }
1346 OS << "call-entry ";
1347 cast<GlobalValuePseudoSourceValue>(PVal)->getValue()->printAsOperand(
1348 OS, /*PrintType=*/false, MST);
1349 break;
1351 OS << "call-entry &";
1353 OS, cast<ExternalSymbolPseudoSourceValue>(PVal)->getSymbol());
1354 break;
1355 default: {
1356 // FIXME: This is not necessarily the correct MIR serialization format for
1357 // a custom pseudo source value, but at least it allows
1358 // MIR printing to work on a target with custom pseudo source
1359 // values.
1360 OS << "custom \"";
1361 if (TII) {
1362 const MIRFormatter *Formatter = TII->getMIRFormatter();
1363 Formatter->printCustomPseudoSourceValue(OS, MST, *PVal);
1364 } else {
1365 PVal->printCustom(OS);
1366 }
1367 OS << '\"';
1368 break;
1369 }
1370 }
1371 } else if (getOpaqueValue() == nullptr && getOffset() != 0) {
1372 OS << ((isLoad() && isStore()) ? " on "
1373 : isLoad() ? " from "
1374 : " into ")
1375 << "unknown-address";
1376 }
1378 if (!getSize().hasValue() ||
1379 (!getSize().isZero() &&
1380 getAlign() != getSize().getValue().getKnownMinValue()))
1381 OS << ", align " << getAlign().value();
1382 if (getAlign() != getBaseAlign())
1383 OS << ", basealign " << getBaseAlign().value();
1384 auto AAInfo = getAAInfo();
1385 if (AAInfo.TBAA) {
1386 OS << ", !tbaa ";
1387 AAInfo.TBAA->printAsOperand(OS, MST);
1388 }
1389 if (AAInfo.Scope) {
1390 OS << ", !alias.scope ";
1391 AAInfo.Scope->printAsOperand(OS, MST);
1392 }
1393 if (AAInfo.NoAlias) {
1394 OS << ", !noalias ";
1395 AAInfo.NoAlias->printAsOperand(OS, MST);
1396 }
1397 if (AAInfo.NoAliasAddrSpace) {
1398 OS << ", !noalias.addrspace ";
1399 AAInfo.NoAliasAddrSpace->printAsOperand(OS, MST);
1400 }
1401 if (getRanges()) {
1402 OS << ", !range ";
1403 getRanges()->printAsOperand(OS, MST);
1404 }
1405 if (getMemCacheHint()) {
1406 OS << ", !mem.cache_hint ";
1407 getMemCacheHint()->printAsOperand(OS, MST);
1408 }
1409 // FIXME: Implement addrspace printing/parsing in MIR.
1410 // For now, print this even though parsing it is not available in MIR.
1411 if (unsigned AS = getAddrSpace())
1412 OS << ", addrspace " << AS;
1413
1414 OS << ')';
1415}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:702
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const HexagonInstrInfo * TII
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:550
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
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)
Register Reg
Register const TargetRegisterInfo * TRI
MachineRegisterInfo & MRI
static bool isPhysical(const MachineOperand &MO)
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
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
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
LLVM Basic Block Representation.
Definition BasicBlock.h:62
const Function * getParent() const
Return the enclosing method, or null if none.
Definition BasicBlock.h:213
The address of a basic block.
Definition Constants.h:1088
Function * getFunction() const
Definition Constants.h:1126
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
bool isIntPredicate() const
Definition InstrTypes.h:846
ConstantFP - Floating Point Values [float, double].
Definition Constants.h:420
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
unsigned getAllocaAddrSpace() const
Definition DataLayout.h:255
constexpr bool isValid() const
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
bool hasValue() const
MCSymbol * getLabel() const
Definition MCDwarf.h:837
unsigned getRASignState() const
Definition MCDwarf.h:866
unsigned getAddressSpace() const
Definition MCDwarf.h:853
MCSymbol * getRASignSymbol() const
Definition MCDwarf.h:871
unsigned getRegister2() const
Definition MCDwarf.h:848
unsigned getRegister() const
Definition MCDwarf.h:839
OpType getOperation() const
Definition MCDwarf.h:836
int64_t getRASignOffset() const
Definition MCDwarf.h:876
StringRef getValues() const
Definition MCDwarf.h:886
ExtraFieldsTy & getExtraFields()
Definition MCDwarf.h:822
int64_t getOffset() const
Definition MCDwarf.h:858
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
MIRFormater - Interface to format MIR operand based on target.
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...
virtual void printCustomPseudoSourceValue(raw_ostream &OS, ModuleSlotTracker &MST, const PseudoSourceValue &PSV) const
Implement target specific printing of target custom pseudo source value.
static LLVM_ABI 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...
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.
unsigned getOperandNo(const_mop_iterator I) const
Returns the number of the operand iterator I points to.
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
LLVM_ABI 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.
LLVM_ABI 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
Flags
Flags values. These may be or'd together.
AtomicOrdering getSuccessOrdering() const
Return the atomic ordering requirements for this memory operation.
LLVM_ABI MachineMemOperand(MachinePointerInfo PtrInfo, Flags Flags, LocationSize TS, Align A, const MMOMetadata &Metadata=MMOMetadata(), SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
Construct a MachineMemOperand object with the specified PtrInfo, flags, size, base alignment,...
Flags getFlags() const
Return the raw flags of the source value,.
LLVM_ABI 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.
const MDNode * getMemCacheHint() const
Return the cache hint metadata for the memory reference.
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)
LLVM_ABI unsigned getOperandNo() const
Returns the index of this operand in the instruction that it belongs to.
const GlobalValue * getGlobal() const
LLVM_ABI void substVirtReg(Register Reg, unsigned SubIdx, const TargetRegisterInfo &)
substVirtReg - Substitute the current register with the virtual subregister Reg:SubReg.
LLVM_ABI 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
LLVM_ABI const char * getTargetIndexName() const
getTargetIndexName - If this MachineOperand is a TargetIndex that has a name, attempt to get the name...
static LLVM_ABI void printStackObjectReference(raw_ostream &OS, unsigned FrameIndex, bool IsFixed, StringRef Name)
Print a stack object reference.
static LLVM_ABI void printSubRegIdx(raw_ostream &OS, uint64_t Index, const TargetRegisterInfo *TRI)
Print a subreg index operand.
int64_t getImm() const
unsigned getInstrRefInstrIndex() const
static LLVM_ABI void printTargetFlags(raw_ostream &OS, const MachineOperand &Op)
Print operand target flags.
LLVM_ABI void ChangeToFPImmediate(const ConstantFP *FPImm, unsigned TargetFlags=0)
ChangeToFPImmediate - Replace this operand with a new FP immediate operand of the specified value.
LLVM_ABI void setIsRenamable(bool Val=true)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isRegMask() const
isRegMask - Tests if this is a MO_RegisterMask operand.
const MDNode * getMetadata() const
MachineBasicBlock * getMBB() const
ArrayRef< int > getShuffleMask() const
LLVM_ABI void ChangeToMCSymbol(MCSymbol *Sym, unsigned TargetFlags=0)
ChangeToMCSymbol - Replace this operand with a new MC symbol operand.
LLVM_ABI void ChangeToTargetIndex(unsigned Idx, int64_t Offset, unsigned TargetFlags=0)
Replace this operand with a target index.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
LLVM_ABI void dump() const
LLVM_ABI void ChangeToImmediate(int64_t ImmVal, unsigned TargetFlags=0)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value.
LLVM_ABI void ChangeToES(const char *SymName, unsigned TargetFlags=0)
ChangeToES - Replace this operand with a new external symbol operand.
LLVM_ABI void ChangeToGA(const GlobalValue *GV, int64_t Offset, unsigned TargetFlags=0)
ChangeToGA - Replace this operand with a new global address operand.
LLVM_ABI void print(raw_ostream &os, const TargetRegisterInfo *TRI=nullptr) const
Print the MachineOperand to os.
LaneBitmask getLaneMask() const
unsigned getCFIIndex() const
LLVM_ABI bool isRenamable() const
isRenamable - Returns true if this register may be renamed, i.e.
LLVM_ABI void ChangeToBA(const BlockAddress *BA, int64_t Offset, unsigned TargetFlags=0)
ChangeToBA - Replace this operand with a new block address operand.
static LLVM_ABI void printOperandOffset(raw_ostream &OS, int64_t Offset)
Print the offset with explicit +/- signs.
LLVM_ABI void ChangeToDbgInstrRef(unsigned InstrIdx, unsigned OpIdx, unsigned TargetFlags=0)
Replace this operand with an Instruction Reference.
LLVM_ABI 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.
LLVM_ABI void substPhysReg(MCRegister Reg, const TargetRegisterInfo &)
substPhysReg - Substitute the current register with the physical register Reg, taking any existing Su...
LLVM_ABI bool isEarlyClobberDefOrUse() const
Return true if this operand is an early-clobber def or a use tied to one.
static unsigned getRegMaskSize(unsigned NumRegs)
Returns number of elements needed for a regmask array.
void setOffset(int64_t Offset)
static LLVM_ABI 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)
LLVM_ABI bool isIdenticalTo(const MachineOperand &Other) const
Returns true if this operand is identical to the specified operand except for liveness related flags ...
LLVM_ABI void ChangeToCPI(unsigned Idx, int Offset, unsigned TargetFlags=0)
ChangeToCPI - Replace this operand with a new constant pool index operand.
friend class MachineRegisterInfo
const uint32_t * getRegMask() const
getRegMask - Returns a bit mask of registers preserved by this RegMask operand.
LLVM_ABI void setIsDef(bool Val=true)
Change a def to a use, or a use to a def.
const ConstantFP * getFPImm() const
static LLVM_ABI 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_LaneMask
Mask to represent active parts of registers.
@ 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.
Root of the metadata hierarchy.
Definition Metadata.h:65
LLVM_ABI void printAsOperand(raw_ostream &OS, const Module *M=nullptr) const
Print as operand.
Manage lifetime of a slot tracker for printing IR.
int getLocalSlot(const Value *V)
Return the slot number of the specified local value.
const Function * getCurrentFunction() const
void incorporateFunction(const Function &F)
Incorporate the given function.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
LLVM_ABI const PseudoSourceValue * getJumpTable()
Return a pseudo source value referencing a jump table.
LLVM_ABI const PseudoSourceValue * getFixedStack(int FI)
Return a pseudo source value referencing a fixed stack frame entry, e.g., a spill slot.
LLVM_ABI const PseudoSourceValue * getGOT()
Return a pseudo source value referencing the global offset table (or something the like).
LLVM_ABI const PseudoSourceValue * getStack()
Return a pseudo source value referencing the area below the stack frame of a function,...
LLVM_ABI 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:20
constexpr unsigned id() const
Definition Register.h:100
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
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
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI 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.
bool hasName() const
Definition Value.h:263
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:314
An opaque object representing a hash code.
Definition Hashing.h:77
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI StringRef getBaseName(ID id)
Return the LLVM name for an intrinsic, without encoded types for overloading, such as "llvm....
@ System
Synchronized with respect to all concurrently executing threads.
Definition LLVMContext.h:66
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
hash_code hash_value(const FixedPointSemantics &Val)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
Definition LaneBitmask.h:92
LLVM_ABI Printable printJumpTableEntryReference(unsigned Idx)
Prints a jump table entry reference.
LLVM_ABI void printEscapedString(StringRef Name, raw_ostream &Out)
Print each character of the specified string, escaping it if it is not printable or if it is an escap...
const char * toIRString(AtomicOrdering ao)
String used by LLVM IR to represent atomic ordering.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI Printable printRegClassOrBank(Register Reg, const MachineRegisterInfo &RegInfo, const TargetRegisterInfo *TRI)
Create Printable object to print register classes or register banks on a raw_ostream.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:102
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Other
Any other memory.
Definition ModRef.h:68
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
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:1788
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
Definition Alignment.h:206
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition Hashing.h:307
LLVM_ABI bool isDereferenceablePointer(const Value *V, Type *Ty, const SimplifyQuery &Q, bool IgnoreFree=false)
Equivalent to isDereferenceableAndAlignedPointer with an alignment of 1.
Definition Loads.cpp:266
stable_hash stable_hash_combine(ArrayRef< stable_hash > Buffer)
LLVM_ABI void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name)
Print out a name of an LLVM value without any prefixes.
LLVM_ABI 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.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:82
constexpr Type getAsInteger() const
Definition LaneBitmask.h:74
Held in ExtraFields when OpLLVMRegisterPair.
Definition MCDwarf.h:570
Held in ExtraFields when OpLLVMVectorOffset.
Definition MCDwarf.h:586
Held in ExtraFields when OpLLVMVectorRegisterMask.
Definition MCDwarf.h:594
Held in ExtraFields when OpLLVMVectorRegisters.
Definition MCDwarf.h:581
LLVM IR metadata carried by a MachineMemOperand.
This class contains a discriminated union of information about pointers in memory operands,...
static LLVM_ABI MachinePointerInfo getJumpTable(MachineFunction &MF)
Return a MachinePointerInfo record that refers to a jump table entry.
LLVM_ABI bool isDereferenceable(unsigned Size, LLVMContext &C, const DataLayout &DL) const
Return true if memory region [V, V+Offset+Size) is known to be dereferenceable.
LLVM_ABI unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
static LLVM_ABI 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 LLVM_ABI MachinePointerInfo getConstantPool(MachineFunction &MF)
Return a MachinePointerInfo record that refers to the constant pool.
static LLVM_ABI MachinePointerInfo getUnknownStack(MachineFunction &MF)
Stack memory without other information.
static LLVM_ABI MachinePointerInfo getGOT(MachineFunction &MF)
Return a MachinePointerInfo record that refers to a GOT entry.
MachinePointerInfo(const Value *v, int64_t offset=0, uint8_t ID=0)
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.