LLVM 23.0.0git
MachineOperand.cpp
Go to the documentation of this file.
1//===- lib/CodeGen/MachineOperand.cpp -------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file Methods common to all machine operands.
10//
11//===----------------------------------------------------------------------===//
12
16#include "llvm/Analysis/Loads.h"
24#include "llvm/Config/llvm-config.h"
25#include "llvm/IR/Constants.h"
29#include "llvm/MC/MCDwarf.h"
31#include <optional>
32
33using namespace llvm;
34
35static cl::opt<int>
36 PrintRegMaskNumRegs("print-regmask-num-regs",
37 cl::desc("Number of registers to limit to when "
38 "printing regmask operands in IR dumps. "
39 "unlimited = -1"),
40 cl::init(32), cl::Hidden);
41
43 if (const MachineInstr *MI = MO.getParent())
44 if (const MachineBasicBlock *MBB = MI->getParent())
45 if (const MachineFunction *MF = MBB->getParent())
46 return MF;
47 return nullptr;
48}
49
51 return const_cast<MachineFunction *>(
52 getMFIfAvailable(const_cast<const MachineOperand &>(MO)));
53}
54
56 assert(getParent() && "Operand does not belong to any instruction!");
57 return getParent()->getOperandNo(this);
58}
59
61 if (getReg() == Reg)
62 return; // No change.
63
64 // Clear the IsRenamable bit to keep it conservatively correct.
65 IsRenamable = false;
66
67 // Otherwise, we have to change the register. If this operand is embedded
68 // into a machine function, we need to update the old and new register's
69 // use/def lists.
70 if (MachineFunction *MF = getMFIfAvailable(*this)) {
71 MachineRegisterInfo &MRI = MF->getRegInfo();
73 SmallContents.RegNo = Reg.id();
74 MRI.addRegOperandToUseList(this);
75 return;
76 }
77
78 // Otherwise, just change the register, no problem. :)
79 SmallContents.RegNo = Reg.id();
80}
81
82void MachineOperand::substVirtReg(Register Reg, unsigned SubIdx,
83 const TargetRegisterInfo &TRI) {
84 assert(Reg.isVirtual());
85 if (SubIdx && getSubReg())
86 SubIdx = TRI.composeSubRegIndices(SubIdx, getSubReg());
87 setReg(Reg);
88 if (SubIdx)
89 setSubReg(SubIdx);
90}
91
93 assert(Reg.isPhysical());
94 if (getSubReg()) {
95 Reg = TRI.getSubReg(Reg, getSubReg());
96 // Note that getSubReg() may return 0 if the sub-register doesn't exist.
97 // That won't happen in legal code.
98 setSubReg(0);
99 if (isDef())
100 setIsUndef(false);
101 }
102 setReg(Reg);
103}
104
105/// Change a def to a use, or a use to a def.
107 assert(isReg() && "Wrong MachineOperand accessor");
108 assert((!Val || !isDebug()) && "Marking a debug operation as def");
109 if (IsDef == Val)
110 return;
111 assert(!IsDeadOrKill && "Changing def/use with dead/kill set not supported");
112 // MRI may keep uses and defs in different list positions.
113 if (MachineFunction *MF = getMFIfAvailable(*this)) {
114 MachineRegisterInfo &MRI = MF->getRegInfo();
116 IsDef = Val;
117 MRI.addRegOperandToUseList(this);
118 return;
119 }
120 IsDef = Val;
121}
122
124 assert(isReg() && "Wrong MachineOperand accessor");
126 "isRenamable should only be checked on physical registers");
127 if (!IsRenamable)
128 return false;
129
130 const MachineInstr *MI = getParent();
131 if (!MI)
132 return true;
133
134 if (isDef())
135 return !MI->hasExtraDefRegAllocReq(MachineInstr::IgnoreBundle);
136
137 assert(isUse() && "Reg is not def or use");
138 return !MI->hasExtraSrcRegAllocReq(MachineInstr::IgnoreBundle);
139}
140
142 assert(isReg() && "Wrong MachineOperand accessor");
144 "setIsRenamable should only be called on physical registers");
145 IsRenamable = Val;
146}
147
148// If this operand is currently a register operand, and if this is in a
149// function, deregister the operand from the register's use/def list.
150void MachineOperand::removeRegFromUses() {
151 if (!isReg() || !isOnRegUseList())
152 return;
153
154 if (MachineFunction *MF = getMFIfAvailable(*this))
155 MF->getRegInfo().removeRegOperandFromUseList(this);
156}
157
158/// ChangeToImmediate - Replace this operand with a new immediate operand of
159/// the specified value. If an operand is known to be an immediate already,
160/// the setImm method should be used.
161void MachineOperand::ChangeToImmediate(int64_t ImmVal, unsigned TargetFlags) {
162 assert((!isReg() || !isTied()) && "Cannot change a tied operand into an imm");
163
164 removeRegFromUses();
165
166 OpKind = MO_Immediate;
167 Contents.ImmVal = ImmVal;
168 setTargetFlags(TargetFlags);
169}
170
172 unsigned TargetFlags) {
173 assert((!isReg() || !isTied()) && "Cannot change a tied operand into an imm");
174
175 removeRegFromUses();
176
177 OpKind = MO_FPImmediate;
178 Contents.CFP = FPImm;
179 setTargetFlags(TargetFlags);
180}
181
182void MachineOperand::ChangeToES(const char *SymName,
183 unsigned TargetFlags) {
184 assert((!isReg() || !isTied()) &&
185 "Cannot change a tied operand into an external symbol");
186
187 removeRegFromUses();
188
189 OpKind = MO_ExternalSymbol;
190 Contents.OffsetedInfo.Val.SymbolName = SymName;
191 setOffset(0); // Offset is always 0.
192 setTargetFlags(TargetFlags);
193}
194
196 unsigned TargetFlags) {
197 assert((!isReg() || !isTied()) &&
198 "Cannot change a tied operand into a global address");
199
200 removeRegFromUses();
201
202 OpKind = MO_GlobalAddress;
203 Contents.OffsetedInfo.Val.GV = GV;
205 setTargetFlags(TargetFlags);
206}
207
209 unsigned TargetFlags) {
210 assert((!isReg() || !isTied()) &&
211 "Cannot change a tied operand into a block address");
212
213 removeRegFromUses();
214
215 OpKind = MO_BlockAddress;
216 Contents.OffsetedInfo.Val.BA = BA;
218 setTargetFlags(TargetFlags);
219}
220
221void MachineOperand::ChangeToCPI(unsigned Idx, int Offset,
222 unsigned TargetFlags) {
223 assert((!isReg() || !isTied()) &&
224 "Cannot change a tied operand into a constant pool index");
225
226 removeRegFromUses();
227
228 OpKind = MO_ConstantPoolIndex;
229 setIndex(Idx);
231 setTargetFlags(TargetFlags);
232}
233
234void MachineOperand::ChangeToMCSymbol(MCSymbol *Sym, unsigned TargetFlags) {
235 assert((!isReg() || !isTied()) &&
236 "Cannot change a tied operand into an MCSymbol");
237
238 removeRegFromUses();
239
240 OpKind = MO_MCSymbol;
241 Contents.Sym = Sym;
242 setTargetFlags(TargetFlags);
243}
244
245void MachineOperand::ChangeToFrameIndex(int Idx, unsigned TargetFlags) {
246 assert((!isReg() || !isTied()) &&
247 "Cannot change a tied operand into a FrameIndex");
248
249 removeRegFromUses();
250
251 OpKind = MO_FrameIndex;
252 setIndex(Idx);
253 setTargetFlags(TargetFlags);
254}
255
257 unsigned TargetFlags) {
258 assert((!isReg() || !isTied()) &&
259 "Cannot change a tied operand into a FrameIndex");
260
261 removeRegFromUses();
262
263 OpKind = MO_TargetIndex;
264 setIndex(Idx);
266 setTargetFlags(TargetFlags);
267}
268
269void MachineOperand::ChangeToDbgInstrRef(unsigned InstrIdx, unsigned OpIdx,
270 unsigned TargetFlags) {
271 assert((!isReg() || !isTied()) &&
272 "Cannot change a tied operand into a DbgInstrRef");
273
274 removeRegFromUses();
275
276 OpKind = MO_DbgInstrRef;
277 setInstrRefInstrIndex(InstrIdx);
279 setTargetFlags(TargetFlags);
280}
281
282/// ChangeToRegister - Replace this operand with a new register operand of
283/// the specified value. If an operand is known to be an register already,
284/// the setReg method should be used.
286 bool isKill, bool isDead, bool isUndef,
287 bool isDebug) {
288 MachineRegisterInfo *RegInfo = nullptr;
289 if (MachineFunction *MF = getMFIfAvailable(*this))
290 RegInfo = &MF->getRegInfo();
291 // If this operand is already a register operand, remove it from the
292 // register's use/def lists.
293 bool WasReg = isReg();
294 if (RegInfo && WasReg)
295 RegInfo->removeRegOperandFromUseList(this);
296
297 // Ensure debug instructions set debug flag on register uses.
298 const MachineInstr *MI = getParent();
299 if (!isDef && MI && MI->isDebugInstr())
300 isDebug = true;
301
302 // Change this to a register and set the reg#.
303 assert(!(isDead && !isDef) && "Dead flag on non-def");
304 assert(!(isKill && isDef) && "Kill flag on def");
305 OpKind = MO_Register;
306 SmallContents.RegNo = Reg.id();
307 SubReg_TargetFlags = 0;
308 IsDef = isDef;
309 IsImp = isImp;
310 IsDeadOrKill = isKill | isDead;
311 IsRenamable = false;
312 IsUndef = isUndef;
313 IsInternalRead = false;
314 IsEarlyClobber = false;
315 IsDebug = isDebug;
316 // Ensure isOnRegUseList() returns false.
317 Contents.Reg.Prev = nullptr;
318 // Preserve the tie when the operand was already a register.
319 if (!WasReg)
320 TiedTo = 0;
321
322 // If this operand is embedded in a function, add the operand to the
323 // register's use/def list.
324 if (RegInfo)
325 RegInfo->addRegOperandToUseList(this);
326}
327
328/// isIdenticalTo - Return true if this operand is identical to the specified
329/// operand. Note that this should stay in sync with the hash_value overload
330/// below.
331bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {
332 if (getType() != Other.getType() ||
333 getTargetFlags() != Other.getTargetFlags())
334 return false;
335
336 switch (getType()) {
338 return getReg() == Other.getReg() && isDef() == Other.isDef() &&
339 getSubReg() == Other.getSubReg();
341 return getImm() == Other.getImm();
343 return getCImm() == Other.getCImm();
345 return getFPImm() == Other.getFPImm();
347 return getMBB() == Other.getMBB();
349 return getIndex() == Other.getIndex();
352 return getIndex() == Other.getIndex() && getOffset() == Other.getOffset();
354 return getIndex() == Other.getIndex();
356 return getGlobal() == Other.getGlobal() && getOffset() == Other.getOffset();
358 return strcmp(getSymbolName(), Other.getSymbolName()) == 0 &&
359 getOffset() == Other.getOffset();
361 return getBlockAddress() == Other.getBlockAddress() &&
362 getOffset() == Other.getOffset();
365 // Shallow compare of the two RegMasks
366 const uint32_t *RegMask = isRegMask() ? getRegMask() : getRegLiveOut();
367 const uint32_t *OtherRegMask =
368 isRegMask() ? Other.getRegMask() : Other.getRegLiveOut();
369 if (RegMask == OtherRegMask)
370 return true;
371
372 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
373 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
374 unsigned RegMaskSize = MachineOperand::getRegMaskSize(TRI->getNumRegs());
375 // Deep compare of the two RegMasks
376 return std::equal(RegMask, RegMask + RegMaskSize, OtherRegMask);
377 }
378 // We don't know the size of the RegMask, so we can't deep compare the two
379 // reg masks.
380 return false;
381 }
383 return getMCSymbol() == Other.getMCSymbol();
385 return getInstrRefInstrIndex() == Other.getInstrRefInstrIndex() &&
386 getInstrRefOpIndex() == Other.getInstrRefOpIndex();
388 return getCFIIndex() == Other.getCFIIndex();
390 return getMetadata() == Other.getMetadata();
392 return getIntrinsicID() == Other.getIntrinsicID();
394 return getPredicate() == Other.getPredicate();
396 return getShuffleMask() == Other.getShuffleMask();
398 return getLaneMask() == Other.getLaneMask();
399 }
400 llvm_unreachable("Invalid machine operand type");
401}
402
403// Note: this must stay exactly in sync with isIdenticalTo above.
405 switch (MO.getType()) {
407 // Register operands don't have target flags.
408 return hash_combine(MO.getType(), MO.getReg().id(), MO.getSubReg(),
409 MO.isDef());
411 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getImm());
413 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getCImm());
415 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getFPImm());
417 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMBB());
419 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex());
422 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex(),
423 MO.getOffset());
425 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIndex());
427 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getOffset(),
430 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getGlobal(),
431 MO.getOffset());
433 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getBlockAddress(),
434 MO.getOffset());
437 if (const MachineFunction *MF = getMFIfAvailable(MO)) {
438 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
439 unsigned RegMaskSize = MachineOperand::getRegMaskSize(TRI->getNumRegs());
440 const uint32_t *RegMask =
441 MO.isRegMask() ? MO.getRegMask() : MO.getRegLiveOut();
442 std::vector<stable_hash> RegMaskHashes(RegMask, RegMask + RegMaskSize);
443 return hash_combine(MO.getType(), MO.getTargetFlags(),
444 stable_hash_combine(RegMaskHashes));
445 }
446
447 assert(0 && "MachineOperand not associated with any MachineFunction");
448 return hash_combine(MO.getType(), MO.getTargetFlags());
449 }
451 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMetadata());
453 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMCSymbol());
455 return hash_combine(MO.getType(), MO.getTargetFlags(),
458 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getCFIIndex());
460 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIntrinsicID());
462 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getPredicate());
464 return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getShuffleMask());
466 return hash_combine(MO.getType(), MO.getTargetFlags(),
468 }
469 llvm_unreachable("Invalid machine operand type");
470}
471
472// Try to crawl up to the machine function and get TRI from it.
473static void tryToGetTargetInfo(const MachineOperand &MO,
474 const TargetRegisterInfo *&TRI) {
475 if (const MachineFunction *MF = getMFIfAvailable(MO)) {
476 TRI = MF->getSubtarget().getRegisterInfo();
477 }
478}
479
480static const char *getTargetIndexName(const MachineFunction &MF, int Index) {
481 const auto *TII = MF.getSubtarget().getInstrInfo();
482 assert(TII && "expected instruction info");
483 auto Indices = TII->getSerializableTargetIndices();
484 auto Found = find_if(Indices, [&](const std::pair<int, const char *> &I) {
485 return I.first == Index;
486 });
487 if (Found != Indices.end())
488 return Found->second;
489 return nullptr;
490}
491
493 const MachineFunction *MF = getMFIfAvailable(*this);
494 return MF ? ::getTargetIndexName(*MF, this->getIndex()) : nullptr;
495}
496
497static const char *getTargetFlagName(const TargetInstrInfo *TII, unsigned TF) {
498 auto Flags = TII->getSerializableDirectMachineOperandTargetFlags();
499 for (const auto &I : Flags) {
500 if (I.first == TF) {
501 return I.second;
502 }
503 }
504 return nullptr;
505}
506
507static void printCFIRegister(unsigned DwarfReg, raw_ostream &OS,
508 const TargetRegisterInfo *TRI) {
509 if (!TRI) {
510 OS << "%dwarfreg." << DwarfReg;
511 return;
512 }
513
514 if (std::optional<MCRegister> Reg = TRI->getLLVMRegNum(DwarfReg, true))
515 OS << printReg(*Reg, TRI);
516 else
517 OS << "<badreg>";
518}
519
521 ModuleSlotTracker &MST) {
522 OS << "%ir-block.";
523 if (BB.hasName()) {
525 return;
526 }
527 std::optional<int> Slot;
528 if (const Function *F = BB.getParent()) {
529 if (F == MST.getCurrentFunction()) {
530 Slot = MST.getLocalSlot(&BB);
531 } else if (const Module *M = F->getParent()) {
532 ModuleSlotTracker CustomMST(M, /*ShouldInitializeAllMetadata=*/false);
533 CustomMST.incorporateFunction(*F);
534 Slot = CustomMST.getLocalSlot(&BB);
535 }
536 }
537 if (Slot)
539 else
540 OS << "<unknown>";
541}
542
543static void printSyncScope(raw_ostream &OS, const LLVMContext &Context,
544 SyncScope::ID SSID,
546 switch (SSID) {
548 break;
549 default:
550 if (SSNs.empty())
551 Context.getSyncScopeNames(SSNs);
552
553 OS << "syncscope(\"";
554 printEscapedString(SSNs[SSID], OS);
555 OS << "\") ";
556 break;
557 }
558}
559
560static const char *getTargetMMOFlagName(const TargetInstrInfo &TII,
561 unsigned TMMOFlag) {
562 auto Flags = TII.getSerializableMachineMemOperandTargetFlags();
563 for (const auto &I : Flags) {
564 if (I.first == TMMOFlag) {
565 return I.second;
566 }
567 }
568 return nullptr;
569}
570
571static void printFrameIndex(raw_ostream& OS, int FrameIndex, bool IsFixed,
572 const MachineFrameInfo *MFI) {
573 StringRef Name;
574 if (MFI) {
575 IsFixed = MFI->isFixedObjectIndex(FrameIndex);
576 if (const AllocaInst *Alloca = MFI->getObjectAllocation(FrameIndex))
577 if (Alloca->hasName())
578 Name = Alloca->getName();
579 if (IsFixed)
580 FrameIndex -= MFI->getObjectIndexBegin();
581 }
582 MachineOperand::printStackObjectReference(OS, FrameIndex, IsFixed, Name);
583}
584
586 const TargetRegisterInfo *TRI) {
587 OS << "%subreg.";
588 if (TRI && Index != 0 && Index < TRI->getNumSubRegIndices())
589 OS << TRI->getSubRegIndexName(Index);
590 else
591 OS << Index;
592}
593
595 const MachineOperand &Op) {
596 if (!Op.getTargetFlags())
597 return;
599 if (!MF)
600 return;
601
602 const auto *TII = MF->getSubtarget().getInstrInfo();
603 assert(TII && "expected instruction info");
604 auto Flags = TII->decomposeMachineOperandsTargetFlags(Op.getTargetFlags());
605 OS << "target-flags(";
606 const bool HasDirectFlags = Flags.first;
607 const bool HasBitmaskFlags = Flags.second;
608 if (!HasDirectFlags && !HasBitmaskFlags) {
609 OS << "<unknown>) ";
610 return;
611 }
612 if (HasDirectFlags) {
613 if (const auto *Name = getTargetFlagName(TII, Flags.first))
614 OS << Name;
615 else
616 OS << "<unknown target flag>";
617 }
618 if (!HasBitmaskFlags) {
619 OS << ") ";
620 return;
621 }
622 bool IsCommaNeeded = HasDirectFlags;
623 unsigned BitMask = Flags.second;
624 auto BitMasks = TII->getSerializableBitmaskMachineOperandTargetFlags();
625 for (const auto &Mask : BitMasks) {
626 // Check if the flag's bitmask has the bits of the current mask set.
627 if ((BitMask & Mask.first) == Mask.first) {
628 if (IsCommaNeeded)
629 OS << ", ";
630 IsCommaNeeded = true;
631 OS << Mask.second;
632 // Clear the bits which were serialized from the flag's bitmask.
633 BitMask &= ~(Mask.first);
634 }
635 }
636 if (BitMask) {
637 // When the resulting flag's bitmask isn't zero, we know that we didn't
638 // serialize all of the bit flags.
639 if (IsCommaNeeded)
640 OS << ", ";
641 OS << "<unknown bitmask target flag>";
642 }
643 OS << ") ";
644}
645
647 OS << "<mcsymbol " << Sym << ">";
648}
649
651 unsigned FrameIndex,
652 bool IsFixed, StringRef Name) {
653 if (IsFixed) {
654 OS << "%fixed-stack." << FrameIndex;
655 return;
656 }
657
658 OS << "%stack." << FrameIndex;
659 if (!Name.empty())
660 OS << '.' << Name;
661}
662
664 if (Offset == 0)
665 return;
666 if (Offset < 0) {
667 OS << " - " << -Offset;
668 return;
669 }
670 OS << " + " << Offset;
671}
672
674 if (Slot == -1)
675 OS << "<badref>";
676 else
677 OS << Slot;
678}
679
680static void printCFI(raw_ostream &OS, const MCCFIInstruction &CFI,
681 const TargetRegisterInfo *TRI) {
682 switch (CFI.getOperation()) {
684 OS << "same_value ";
685 if (MCSymbol *Label = CFI.getLabel())
686 MachineOperand::printSymbol(OS, *Label);
687 printCFIRegister(CFI.getRegister(), OS, TRI);
688 break;
690 OS << "remember_state ";
691 if (MCSymbol *Label = CFI.getLabel())
692 MachineOperand::printSymbol(OS, *Label);
693 break;
695 OS << "restore_state ";
696 if (MCSymbol *Label = CFI.getLabel())
697 MachineOperand::printSymbol(OS, *Label);
698 break;
700 OS << "offset ";
701 if (MCSymbol *Label = CFI.getLabel())
702 MachineOperand::printSymbol(OS, *Label);
703 printCFIRegister(CFI.getRegister(), OS, TRI);
704 OS << ", " << CFI.getOffset();
705 break;
707 OS << "def_cfa_register ";
708 if (MCSymbol *Label = CFI.getLabel())
709 MachineOperand::printSymbol(OS, *Label);
710 printCFIRegister(CFI.getRegister(), OS, TRI);
711 break;
713 OS << "def_cfa_offset ";
714 if (MCSymbol *Label = CFI.getLabel())
715 MachineOperand::printSymbol(OS, *Label);
716 OS << CFI.getOffset();
717 break;
719 OS << "def_cfa ";
720 if (MCSymbol *Label = CFI.getLabel())
721 MachineOperand::printSymbol(OS, *Label);
722 printCFIRegister(CFI.getRegister(), OS, TRI);
723 OS << ", " << CFI.getOffset();
724 break;
726 OS << "llvm_def_aspace_cfa ";
727 if (MCSymbol *Label = CFI.getLabel())
728 MachineOperand::printSymbol(OS, *Label);
729 printCFIRegister(CFI.getRegister(), OS, TRI);
730 OS << ", " << CFI.getOffset();
731 OS << ", " << CFI.getAddressSpace();
732 break;
734 OS << "rel_offset ";
735 if (MCSymbol *Label = CFI.getLabel())
736 MachineOperand::printSymbol(OS, *Label);
737 printCFIRegister(CFI.getRegister(), OS, TRI);
738 OS << ", " << CFI.getOffset();
739 break;
741 OS << "adjust_cfa_offset ";
742 if (MCSymbol *Label = CFI.getLabel())
743 MachineOperand::printSymbol(OS, *Label);
744 OS << CFI.getOffset();
745 break;
747 OS << "restore ";
748 if (MCSymbol *Label = CFI.getLabel())
749 MachineOperand::printSymbol(OS, *Label);
750 printCFIRegister(CFI.getRegister(), OS, TRI);
751 break;
753 OS << "escape ";
754 if (MCSymbol *Label = CFI.getLabel())
755 MachineOperand::printSymbol(OS, *Label);
756 if (!CFI.getValues().empty()) {
757 size_t e = CFI.getValues().size() - 1;
758 for (size_t i = 0; i < e; ++i)
759 OS << format("0x%02x", uint8_t(CFI.getValues()[i])) << ", ";
760 OS << format("0x%02x", uint8_t(CFI.getValues()[e]));
761 }
762 break;
763 }
765 OS << "undefined ";
766 if (MCSymbol *Label = CFI.getLabel())
767 MachineOperand::printSymbol(OS, *Label);
768 printCFIRegister(CFI.getRegister(), OS, TRI);
769 break;
771 OS << "register ";
772 if (MCSymbol *Label = CFI.getLabel())
773 MachineOperand::printSymbol(OS, *Label);
774 printCFIRegister(CFI.getRegister(), OS, TRI);
775 OS << ", ";
777 break;
779 OS << "window_save ";
780 if (MCSymbol *Label = CFI.getLabel())
781 MachineOperand::printSymbol(OS, *Label);
782 break;
784 OS << "negate_ra_sign_state ";
785 if (MCSymbol *Label = CFI.getLabel())
786 MachineOperand::printSymbol(OS, *Label);
787 break;
789 OS << "negate_ra_sign_state_with_pc ";
790 if (MCSymbol *Label = CFI.getLabel())
791 MachineOperand::printSymbol(OS, *Label);
792 break;
794 const auto &Fields =
796
797 OS << "llvm_register_pair ";
798 if (MCSymbol *Label = CFI.getLabel())
799 MachineOperand::printSymbol(OS, *Label);
800 printCFIRegister(Fields.Register, OS, TRI);
801 OS << ", ";
802 printCFIRegister(Fields.Reg1, OS, TRI);
803 OS << ", " << Fields.Reg1SizeInBits << ", ";
804 printCFIRegister(Fields.Reg2, OS, TRI);
805 OS << ", " << Fields.Reg2SizeInBits;
806 break;
807 }
809 const auto &Fields =
811
812 OS << "llvm_vector_registers ";
813 if (MCSymbol *Label = CFI.getLabel())
814 MachineOperand::printSymbol(OS, *Label);
815 printCFIRegister(Fields.Register, OS, TRI);
816 for (auto [Reg, Lane, Size] : Fields.VectorRegisters) {
817 OS << ", ";
819 OS << ", " << Lane << ", " << Size;
820 }
821 break;
822 }
824 const auto &Fields =
826
827 OS << "llvm_vector_offset ";
828 if (MCSymbol *Label = CFI.getLabel())
829 MachineOperand::printSymbol(OS, *Label);
830 printCFIRegister(Fields.Register, OS, TRI);
831 OS << ", " << Fields.RegisterSizeInBits << ", ";
832 printCFIRegister(Fields.MaskRegister, OS, TRI);
833 OS << ", " << Fields.MaskRegisterSizeInBits << ", " << Fields.Offset;
834 break;
835 }
837 const auto &Fields =
839
840 OS << "llvm_vector_register_mask ";
841 if (MCSymbol *Label = CFI.getLabel())
842 MachineOperand::printSymbol(OS, *Label);
843 printCFIRegister(Fields.Register, OS, TRI);
844 OS << ", ";
845 printCFIRegister(Fields.SpillRegister, OS, TRI);
846 OS << ", " << Fields.SpillRegisterLaneSizeInBits << ", ";
847 printCFIRegister(Fields.MaskRegister, OS, TRI);
848 OS << ", " << Fields.MaskRegisterSizeInBits;
849 break;
850 }
851 default:
852 // TODO: Print the other CFI Operations.
853 OS << "<unserializable cfi directive>";
854 break;
855 }
856}
857
859 const TargetRegisterInfo *TRI) const {
860 print(OS, LLT{}, TRI);
861}
862
864 const TargetRegisterInfo *TRI) const {
865 tryToGetTargetInfo(*this, TRI);
866 ModuleSlotTracker DummyMST(nullptr);
867 print(OS, DummyMST, TypeToPrint, std::nullopt, /*PrintDef=*/false,
868 /*IsStandalone=*/true,
869 /*ShouldPrintRegisterTies=*/true,
870 /*TiedOperandIdx=*/0, TRI);
871}
872
874 LLT TypeToPrint, std::optional<unsigned> OpIdx,
875 bool PrintDef, bool IsStandalone,
876 bool ShouldPrintRegisterTies,
877 unsigned TiedOperandIdx,
878 const TargetRegisterInfo *TRI) const {
879 printTargetFlags(OS, *this);
880 switch (getType()) {
882 Register Reg = getReg();
883 if (isImplicit())
884 OS << (isDef() ? "implicit-def " : "implicit ");
885 else if (PrintDef && isDef())
886 // Print the 'def' flag only when the operand is defined after '='.
887 OS << "def ";
888 if (isInternalRead())
889 OS << "internal ";
890 if (isDead())
891 OS << "dead ";
892 if (isKill())
893 OS << "killed ";
894 if (isUndef())
895 OS << "undef ";
896 if (isEarlyClobber())
897 OS << "early-clobber ";
898 if (getReg().isPhysical() && isRenamable())
899 OS << "renamable ";
900 // isDebug() is exactly true for register operands of a DBG_VALUE. So we
901 // simply infer it when parsing and do not need to print it.
902
903 const MachineRegisterInfo *MRI = nullptr;
904 if (Reg.isVirtual()) {
905 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
906 MRI = &MF->getRegInfo();
907 }
908 }
909
910 OS << printReg(Reg, TRI, 0, MRI);
911 // Print the sub register.
912 if (unsigned SubReg = getSubReg()) {
913 if (TRI)
914 OS << '.' << TRI->getSubRegIndexName(SubReg);
915 else
916 OS << ".subreg" << SubReg;
917 }
918 // Print the register class / bank.
919 if (Reg.isVirtual()) {
920 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
921 const MachineRegisterInfo &MRI = MF->getRegInfo();
922 if (IsStandalone || !PrintDef || MRI.def_empty(Reg)) {
923 OS << ':';
924 OS << printRegClassOrBank(Reg, MRI, TRI);
925 }
926 }
927 }
928 // Print ties.
929 if (ShouldPrintRegisterTies && isTied() && !isDef())
930 OS << "(tied-def " << TiedOperandIdx << ")";
931 // Print types.
932 if (TypeToPrint.isValid())
933 OS << '(' << TypeToPrint << ')';
934 break;
935 }
937 const MIRFormatter *Formatter = nullptr;
938 if (const MachineFunction *MF = getMFIfAvailable(*this)) {
939 const auto *TII = MF->getSubtarget().getInstrInfo();
940 assert(TII && "expected instruction info");
941 Formatter = TII->getMIRFormatter();
942 }
943 if (Formatter)
944 Formatter->printImm(OS, *getParent(), OpIdx, getImm());
945 else
946 OS << getImm();
947 break;
948 }
950 getCImm()->printAsOperand(OS, /*PrintType=*/true, MST);
951 break;
953 getFPImm()->printAsOperand(OS, /*PrintType=*/true, MST);
954 break;
956 OS << printMBBReference(*getMBB());
957 break;
959 int FrameIndex = getIndex();
960 bool IsFixed = false;
961 const MachineFrameInfo *MFI = nullptr;
962 if (const MachineFunction *MF = getMFIfAvailable(*this))
963 MFI = &MF->getFrameInfo();
964 printFrameIndex(OS, FrameIndex, IsFixed, MFI);
965 break;
966 }
968 OS << "%const." << getIndex();
970 break;
972 OS << "target-index(";
973 const char *Name = "<unknown>";
974 if (const MachineFunction *MF = getMFIfAvailable(*this))
975 if (const auto *TargetIndexName = ::getTargetIndexName(*MF, getIndex()))
976 Name = TargetIndexName;
977 OS << Name << ')';
979 break;
980 }
983 break;
985 if (auto *GV = getGlobal())
986 GV->printAsOperand(OS, /*PrintType=*/false, MST);
987 else // Invalid, but may appear in debugging scenarios.
988 OS << "globaladdress(null)";
989
991 break;
993 StringRef Name = getSymbolName();
994 OS << '&';
995 if (Name.empty()) {
996 OS << "\"\"";
997 } else {
999 }
1001 break;
1002 }
1004 OS << "blockaddress(";
1005 getBlockAddress()->getFunction()->printAsOperand(OS, /*PrintType=*/false,
1006 MST);
1007 OS << ", ";
1008 printIRBlockReference(OS, *getBlockAddress()->getBasicBlock(), MST);
1009 OS << ')';
1011 break;
1012 }
1014 OS << "<regmask";
1015 if (TRI) {
1016 unsigned NumRegsInMask = 0;
1017 unsigned NumRegsEmitted = 0;
1018 for (unsigned i = 0; i < TRI->getNumRegs(); ++i) {
1019 unsigned MaskWord = i / 32;
1020 unsigned MaskBit = i % 32;
1021 if (getRegMask()[MaskWord] & (1 << MaskBit)) {
1022 if (PrintRegMaskNumRegs < 0 ||
1023 NumRegsEmitted <= static_cast<unsigned>(PrintRegMaskNumRegs)) {
1024 OS << " " << printReg(i, TRI);
1025 NumRegsEmitted++;
1026 }
1027 NumRegsInMask++;
1028 }
1029 }
1030 if (NumRegsEmitted != NumRegsInMask)
1031 OS << " and " << (NumRegsInMask - NumRegsEmitted) << " more...";
1032 } else {
1033 OS << " ...";
1034 }
1035 OS << ">";
1036 break;
1037 }
1039 const uint32_t *RegMask = getRegLiveOut();
1040 OS << "liveout(";
1041 if (!TRI) {
1042 OS << "<unknown>";
1043 } else {
1044 bool IsCommaNeeded = false;
1045 for (unsigned Reg = 0, E = TRI->getNumRegs(); Reg < E; ++Reg) {
1046 if (RegMask[Reg / 32] & (1U << (Reg % 32))) {
1047 if (IsCommaNeeded)
1048 OS << ", ";
1049 OS << printReg(Reg, TRI);
1050 IsCommaNeeded = true;
1051 }
1052 }
1053 }
1054 OS << ")";
1055 break;
1056 }
1058 getMetadata()->printAsOperand(OS, MST);
1059 break;
1061 printSymbol(OS, *getMCSymbol());
1062 break;
1064 OS << "dbg-instr-ref(" << getInstrRefInstrIndex() << ", "
1065 << getInstrRefOpIndex() << ')';
1066 break;
1067 }
1069 if (const MachineFunction *MF = getMFIfAvailable(*this))
1070 printCFI(OS, MF->getFrameInstructions()[getCFIIndex()], TRI);
1071 else
1072 OS << "<cfi directive>";
1073 break;
1074 }
1077 if (ID < Intrinsic::num_intrinsics)
1078 OS << "intrinsic(@" << Intrinsic::getBaseName(ID) << ')';
1079 else
1080 OS << "intrinsic(" << ID << ')';
1081 break;
1082 }
1084 auto Pred = static_cast<CmpInst::Predicate>(getPredicate());
1085 OS << (CmpInst::isIntPredicate(Pred) ? "int" : "float") << "pred(" << Pred
1086 << ')';
1087 break;
1088 }
1090 OS << "shufflemask(";
1092 StringRef Separator;
1093 for (int Elt : Mask) {
1094 if (Elt == -1)
1095 OS << Separator << "undef";
1096 else
1097 OS << Separator << Elt;
1098 Separator = ", ";
1099 }
1100
1101 OS << ')';
1102 break;
1103 }
1105 OS << "lanemask(";
1106 LaneBitmask LaneMask = getLaneMask();
1107 OS << "0x" << PrintLaneMask(LaneMask);
1108 OS << ')';
1109 break;
1110 }
1111 }
1112}
1113
1114#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1115LLVM_DUMP_METHOD void MachineOperand::dump() const { dbgs() << *this << '\n'; }
1116#endif
1117
1118//===----------------------------------------------------------------------===//
1119// MachineMemOperand Implementation
1120//===----------------------------------------------------------------------===//
1121
1122/// getAddrSpace - Return the LLVM IR address space number that this pointer
1123/// points into.
1125
1126/// isDereferenceable - Return true if V is always dereferenceable for
1127/// Offset + Size byte.
1129 const DataLayout &DL) const {
1130 if (!isa<const Value *>(V))
1131 return false;
1132
1133 const Value *BasePtr = cast<const Value *>(V);
1134 if (BasePtr == nullptr)
1135 return false;
1136
1138 BasePtr, Align(1), APInt(DL.getPointerSizeInBits(), Offset + Size), DL,
1139 dyn_cast<Instruction>(BasePtr));
1140}
1141
1142/// getConstantPool - Return a MachinePointerInfo record that refers to the
1143/// constant pool.
1147
1148/// getFixedStack - Return a MachinePointerInfo record that refers to the
1149/// the specified FrameIndex.
1154
1158
1162
1167
1171
1173 LLT type, Align a, const AAMDNodes &AAInfo,
1174 const MDNode *Ranges, SyncScope::ID SSID,
1175 AtomicOrdering Ordering,
1176 AtomicOrdering FailureOrdering)
1177 : PtrInfo(ptrinfo), MemoryType(type), FlagVals(f), BaseAlign(a),
1178 AAInfo(AAInfo), Ranges(Ranges) {
1179 assert((PtrInfo.V.isNull() || isa<const PseudoSourceValue *>(PtrInfo.V) ||
1180 isa<PointerType>(cast<const Value *>(PtrInfo.V)->getType())) &&
1181 "invalid pointer value");
1182 assert((isLoad() || isStore()) && "Not a load/store!");
1183
1184 AtomicInfo.SSID = static_cast<unsigned>(SSID);
1185 assert(getSyncScopeID() == SSID && "Value truncated");
1186 AtomicInfo.Ordering = static_cast<unsigned>(Ordering);
1187 assert(getSuccessOrdering() == Ordering && "Value truncated");
1188 AtomicInfo.FailureOrdering = static_cast<unsigned>(FailureOrdering);
1189 assert(getFailureOrdering() == FailureOrdering && "Value truncated");
1190}
1191
1193 LocationSize TS, Align BaseAlignment,
1194 const AAMDNodes &AAInfo,
1195 const MDNode *Ranges, SyncScope::ID SSID,
1196 AtomicOrdering Ordering,
1197 AtomicOrdering FailureOrdering)
1199 ptrinfo, F,
1200 !TS.isPrecise() ? LLT()
1201 : TS.isScalable()
1202 ? LLT::scalable_vector(1, 8 * TS.getValue().getKnownMinValue())
1203 : LLT::scalar(8 * TS.getValue().getKnownMinValue()),
1204 BaseAlignment, AAInfo, Ranges, SSID, Ordering, FailureOrdering) {}
1205
1207 // The Value and Offset may differ due to CSE. But the flags and size
1208 // should be the same.
1209 assert(MMO->getFlags() == getFlags() && "Flags mismatch!");
1210 assert((!MMO->getSize().hasValue() || !getSize().hasValue() ||
1211 MMO->getSize() == getSize()) &&
1212 "Size mismatch!");
1213 if (MMO->getBaseAlign() >= getBaseAlign()) {
1214 // Update the alignment value.
1215 BaseAlign = MMO->getBaseAlign();
1216 // Also update the base and offset, because the new alignment may
1217 // not be applicable with the old ones.
1218 PtrInfo = MMO->PtrInfo;
1219 }
1220}
1221
1222/// getAlign - Return the minimum known alignment in bytes of the
1223/// actual memory reference.
1227
1230 const LLVMContext &Context,
1231 const MachineFrameInfo *MFI,
1232 const TargetInstrInfo *TII) const {
1233 OS << '(';
1234 if (isVolatile())
1235 OS << "volatile ";
1236 if (isNonTemporal())
1237 OS << "non-temporal ";
1238 if (isDereferenceable())
1239 OS << "dereferenceable ";
1240 if (isInvariant())
1241 OS << "invariant ";
1242 if (TII) {
1245 << "\" ";
1248 << "\" ";
1251 << "\" ";
1254 << "\" ";
1255 } else {
1257 OS << "\"MOTargetFlag1\" ";
1259 OS << "\"MOTargetFlag2\" ";
1261 OS << "\"MOTargetFlag3\" ";
1263 OS << "\"MOTargetFlag4\" ";
1264 }
1265
1266 assert((isLoad() || isStore()) &&
1267 "machine memory operand must be a load or store (or both)");
1268 if (isLoad())
1269 OS << "load ";
1270 if (isStore())
1271 OS << "store ";
1272
1273 printSyncScope(OS, Context, getSyncScopeID(), SSNs);
1274
1276 OS << toIRString(getSuccessOrdering()) << ' ';
1278 OS << toIRString(getFailureOrdering()) << ' ';
1279
1280 if (getMemoryType().isValid())
1281 OS << '(' << getMemoryType() << ')';
1282 else
1283 OS << "unknown-size";
1284
1285 if (const Value *Val = getValue()) {
1286 OS << ((isLoad() && isStore()) ? " on " : isLoad() ? " from " : " into ");
1287 MIRFormatter::printIRValue(OS, *Val, MST);
1288 } else if (const PseudoSourceValue *PVal = getPseudoValue()) {
1289 OS << ((isLoad() && isStore()) ? " on " : isLoad() ? " from " : " into ");
1290 assert(PVal && "Expected a pseudo source value");
1291 switch (PVal->kind()) {
1293 OS << "stack";
1294 break;
1296 OS << "got";
1297 break;
1299 OS << "jump-table";
1300 break;
1302 OS << "constant-pool";
1303 break;
1305 int FrameIndex = cast<FixedStackPseudoSourceValue>(PVal)->getFrameIndex();
1306 bool IsFixed = true;
1307 printFrameIndex(OS, FrameIndex, IsFixed, MFI);
1308 break;
1309 }
1311 OS << "call-entry ";
1312 cast<GlobalValuePseudoSourceValue>(PVal)->getValue()->printAsOperand(
1313 OS, /*PrintType=*/false, MST);
1314 break;
1316 OS << "call-entry &";
1318 OS, cast<ExternalSymbolPseudoSourceValue>(PVal)->getSymbol());
1319 break;
1320 default: {
1321 // FIXME: This is not necessarily the correct MIR serialization format for
1322 // a custom pseudo source value, but at least it allows
1323 // MIR printing to work on a target with custom pseudo source
1324 // values.
1325 OS << "custom \"";
1326 if (TII) {
1327 const MIRFormatter *Formatter = TII->getMIRFormatter();
1328 Formatter->printCustomPseudoSourceValue(OS, MST, *PVal);
1329 } else {
1330 PVal->printCustom(OS);
1331 }
1332 OS << '\"';
1333 break;
1334 }
1335 }
1336 } else if (getOpaqueValue() == nullptr && getOffset() != 0) {
1337 OS << ((isLoad() && isStore()) ? " on "
1338 : isLoad() ? " from "
1339 : " into ")
1340 << "unknown-address";
1341 }
1343 if (!getSize().hasValue() ||
1344 (!getSize().isZero() &&
1345 getAlign() != getSize().getValue().getKnownMinValue()))
1346 OS << ", align " << getAlign().value();
1347 if (getAlign() != getBaseAlign())
1348 OS << ", basealign " << getBaseAlign().value();
1349 auto AAInfo = getAAInfo();
1350 if (AAInfo.TBAA) {
1351 OS << ", !tbaa ";
1352 AAInfo.TBAA->printAsOperand(OS, MST);
1353 }
1354 if (AAInfo.Scope) {
1355 OS << ", !alias.scope ";
1356 AAInfo.Scope->printAsOperand(OS, MST);
1357 }
1358 if (AAInfo.NoAlias) {
1359 OS << ", !noalias ";
1360 AAInfo.NoAlias->printAsOperand(OS, MST);
1361 }
1362 if (AAInfo.NoAliasAddrSpace) {
1363 OS << ", !noalias.addrspace ";
1364 AAInfo.NoAliasAddrSpace->printAsOperand(OS, MST);
1365 }
1366 if (getRanges()) {
1367 OS << ", !range ";
1368 getRanges()->printAsOperand(OS, MST);
1369 }
1370 // FIXME: Implement addrspace printing/parsing in MIR.
1371 // For now, print this even though parsing it is not available in MIR.
1372 if (unsigned AS = getAddrSpace())
1373 OS << ", addrspace " << AS;
1374
1375 OS << ')';
1376}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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:661
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:539
#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
MachineInstr unsigned OpIdx
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:1071
Function * getFunction() const
Definition Constants.h:1107
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:676
bool isIntPredicate() const
Definition InstrTypes.h:783
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:252
constexpr bool isValid() const
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
bool hasValue() const
MCSymbol * getLabel() const
Definition MCDwarf.h:805
unsigned getAddressSpace() const
Definition MCDwarf.h:821
unsigned getRegister2() const
Definition MCDwarf.h:816
unsigned getRegister() const
Definition MCDwarf.h:807
OpType getOperation() const
Definition MCDwarf.h:804
StringRef getValues() const
Definition MCDwarf.h:839
ExtraFieldsTy & getExtraFields()
Definition MCDwarf.h:790
int64_t getOffset() const
Definition MCDwarf.h:826
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
Metadata node.
Definition Metadata.h:1080
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
LLVM_ABI 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,.
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.
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...
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.
bool def_empty(Register RegNo) const
def_empty - Return true if there are no instructions defining the specified register (it may be live-...
LLVM_ABI void removeRegOperandFromUseList(MachineOperand *MO)
Remove MO from its use-def list.
LLVM_ABI void addRegOperandToUseList(MachineOperand *MO)
Add MO to the linked list of operands for its register.
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:67
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
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:261
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:318
An opaque object representing a hash code.
Definition Hashing.h:78
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
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:58
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:557
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
LLVM_ABI 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:230
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:129
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:1771
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
Definition Alignment.h:201
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition Hashing.h:325
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.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition Metadata.h:763
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:77
constexpr Type getAsInteger() const
Definition LaneBitmask.h:74
Held in ExtraFields when OpLLVMRegisterPair.
Definition MCDwarf.h:566
Held in ExtraFields when OpLLVMVectorOffset.
Definition MCDwarf.h:582
Held in ExtraFields when OpLLVMVectorRegisterMask.
Definition MCDwarf.h:590
Held in ExtraFields when OpLLVMVectorRegisters.
Definition MCDwarf.h:577
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.