13#ifndef LLVM_CODEGEN_MACHINEOPERAND_H
14#define LLVM_CODEGEN_MACHINEOPERAND_H
29class MachineBasicBlock;
31class MachineRegisterInfo;
32class MCCFIInstruction;
34class ModuleSlotTracker;
35class TargetIntrinsicInfo;
36class TargetRegisterInfo;
84 unsigned SubReg_TargetFlags : 12;
110 unsigned IsDeadOrKill : 1;
113 unsigned IsRenamable : 1;
132 unsigned IsUndef : 1;
143 unsigned IsInternalRead : 1;
148 unsigned IsEarlyClobber : 1;
152 unsigned IsDebug : 1;
168 union ContentsUnion {
170 MachineBasicBlock *
MBB;
171 const ConstantFP *CFP;
172 const ConstantInt *CI;
180 ArrayRef<int> ShuffleMask;
184 MachineOperand *Prev;
185 MachineOperand *Next;
199 const GlobalValue *GV;
208 : OpKind(
K), SubReg_TargetFlags(0) {
210 static_assert(
alignof(MachineOperand) <=
alignof(int64_t),
211 "MachineOperand shouldn't be more than 8 byte aligned");
212 static_assert(
sizeof(Contents) <= 2 *
sizeof(
void *),
213 "Contents should be at most two pointers");
214 static_assert(
sizeof(MachineOperand) <=
217 "MachineOperand too big. Should be Kind, SmallContents, "
218 "ParentMI, and Contents");
227 return isReg() ? 0 : SubReg_TargetFlags;
230 assert(!
isReg() &&
"Register operands can't have target flags");
231 SubReg_TargetFlags =
F;
232 assert(SubReg_TargetFlags ==
F &&
"Target flags out of range");
235 assert(!
isReg() &&
"Register operands can't have target flags");
236 SubReg_TargetFlags |=
F;
237 assert((SubReg_TargetFlags &
F) &&
"Target flags out of range");
311 std::optional<unsigned> OpIdx,
bool PrintDef,
bool IsStandalone,
312 bool ShouldPrintRegisterTies,
unsigned TiedOperandIdx,
370 assert(
isReg() &&
"This is not a register operand!");
371 return Register(SmallContents.RegNo);
375 assert(
isReg() &&
"Wrong MachineOperand accessor");
376 return SubReg_TargetFlags;
380 assert(
isReg() &&
"Wrong MachineOperand accessor");
385 assert(
isReg() &&
"Wrong MachineOperand accessor");
390 assert(
isReg() &&
"Wrong MachineOperand accessor");
395 assert(
isReg() &&
"Wrong MachineOperand accessor");
396 return IsDeadOrKill & IsDef;
400 assert(
isReg() &&
"Wrong MachineOperand accessor");
401 return IsDeadOrKill & !IsDef;
405 assert(
isReg() &&
"Wrong MachineOperand accessor");
441 assert(
isReg() &&
"Wrong MachineOperand accessor");
442 return IsInternalRead;
446 assert(
isReg() &&
"Wrong MachineOperand accessor");
447 return IsEarlyClobber;
451 assert(
isReg() &&
"Wrong MachineOperand accessor");
456 assert(
isReg() &&
"Wrong MachineOperand accessor");
468 assert(
isReg() &&
"Wrong MachineOperand accessor");
492 SubReg_TargetFlags = subReg;
493 assert(SubReg_TargetFlags == subReg &&
"SubReg out of range");
520 assert(
isReg() && !IsDef &&
"Wrong MachineOperand mutator");
521 assert((!Val || !
isDebug()) &&
"Marking a debug operation as kill");
526 assert(
isReg() && IsDef &&
"Wrong MachineOperand mutator");
539 IsInternalRead = Val;
543 assert(
isReg() && IsDef &&
"Wrong MachineOperand mutator");
544 IsEarlyClobber = Val;
548 assert(
isReg() && !IsDef &&
"Wrong MachineOperand mutator");
557 assert(
isImm() &&
"Wrong MachineOperand accessor");
558 return Contents.ImmVal;
572 assert(
isMBB() &&
"Wrong MachineOperand accessor");
578 "Wrong MachineOperand accessor");
579 return Contents.OffsetedInfo.Val.Index;
584 return Contents.OffsetedInfo.Val.GV;
589 return Contents.OffsetedInfo.Val.BA;
599 return Contents.InstrRef.InstrIdx;
604 return Contents.InstrRef.OpIdx;
609 return Contents.CFIIndex;
614 return Contents.IntrinsicID;
619 return Contents.Pred;
624 return Contents.ShuffleMask;
632 "Wrong MachineOperand accessor");
633 return int64_t(
uint64_t(Contents.OffsetedInfo.OffsetHi) << 32) |
634 SmallContents.OffsetLo;
639 return Contents.OffsetedInfo.Val.SymbolName;
648 assert(PhysReg < (1u << 30) &&
"Not a physical register");
649 return !(RegMask[PhysReg / 32] & (1u << PhysReg % 32));
661 return Contents.RegMask;
666 return (NumRegs + 31) / 32;
672 return Contents.RegMask;
686 Contents.ImmVal = immVal;
702 "Wrong MachineOperand mutator");
704 Contents.OffsetedInfo.OffsetHi = int(
Offset >> 32);
709 "Wrong MachineOperand mutator");
710 Contents.OffsetedInfo.Val.Index =
Idx;
720 Contents.InstrRef.InstrIdx = InstrIdx;
724 Contents.InstrRef.OpIdx = OpIdx;
738 Contents.RegMask = RegMaskPtr;
743 Contents.IntrinsicID = IID;
748 Contents.Pred = Predicate;
779 void ChangeToES(
const char *SymName,
unsigned TargetFlags = 0);
783 unsigned TargetFlags = 0);
787 unsigned TargetFlags = 0);
797 unsigned TargetFlags = 0);
801 unsigned TargetFlags = 0);
833 Op.Contents.CFP = CFP;
856 Op.SmallContents.RegNo =
Reg;
857 Op.Contents.Reg.Prev =
nullptr;
858 Op.Contents.Reg.Next =
nullptr;
863 unsigned TargetFlags = 0) {
866 Op.setTargetFlags(TargetFlags);
875 unsigned TargetFlags = 0) {
879 Op.setTargetFlags(TargetFlags);
883 unsigned TargetFlags = 0) {
887 Op.setTargetFlags(TargetFlags);
893 Op.setTargetFlags(TargetFlags);
897 unsigned TargetFlags = 0) {
899 Op.Contents.OffsetedInfo.Val.GV = GV;
901 Op.setTargetFlags(TargetFlags);
905 unsigned TargetFlags = 0) {
907 Op.Contents.OffsetedInfo.Val.SymbolName = SymName;
909 Op.setTargetFlags(TargetFlags);
913 unsigned TargetFlags = 0) {
915 Op.Contents.OffsetedInfo.Val.BA = BA;
917 Op.setTargetFlags(TargetFlags);
933 assert(Mask &&
"Missing register mask");
935 Op.Contents.RegMask = Mask;
939 assert(Mask &&
"Missing live-out register mask");
941 Op.Contents.RegMask = Mask;
946 Op.Contents.MD = Meta;
951 unsigned TargetFlags = 0) {
953 Op.Contents.Sym =
Sym;
955 Op.setTargetFlags(TargetFlags);
961 Op.Contents.InstrRef.InstrIdx = InstrIdx;
962 Op.Contents.InstrRef.OpIdx = OpIdx;
968 Op.Contents.CFIIndex = CFIIndex;
974 Op.Contents.IntrinsicID =
ID;
980 Op.Contents.Pred = Pred;
986 Op.Contents.ShuffleMask = Mask;
996 void removeRegFromUses();
999 enum :
unsigned char {
1013 bool isOnRegUseList()
const {
1014 assert(
isReg() &&
"Can only add reg operand to use lists");
1015 return Contents.Reg.Prev !=
nullptr;
1022 MachineOperand::MO_Empty));
1026 MachineOperand::MO_Tombstone));
1033 MachineOperand::MO_Empty) ||
1035 MachineOperand::MO_Tombstone))
1036 return LHS.getType() ==
RHS.getType();
1037 return LHS.isIdenticalTo(
RHS);
1048hash_code
hash_value(
const MachineOperand &MO);
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines DenseMapInfo traits for DenseMap.
unsigned const TargetRegisterInfo * TRI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
The address of a basic block.
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
This class represents an Operation in the Expression.
Wrapper class representing physical registers. Should be passed by value.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
void setSubReg(unsigned subReg)
unsigned getSubReg() const
void setIsUse(bool Val=true)
static MachineOperand CreateMCSymbol(MCSymbol *Sym, unsigned TargetFlags=0)
unsigned getInstrRefOpIndex() const
void setInstrRefInstrIndex(unsigned InstrIdx)
unsigned getOperandNo() const
Returns the index of this operand in the instruction that it belongs to.
const GlobalValue * getGlobal() const
void setImplicit(bool Val=true)
void setIsInternalRead(bool Val=true)
void substVirtReg(Register Reg, unsigned SubIdx, const TargetRegisterInfo &)
substVirtReg - Substitute the current register with the virtual subregister Reg:SubReg.
void ChangeToFrameIndex(int Idx, unsigned TargetFlags=0)
Replace this operand with a frame index.
const uint32_t * getRegLiveOut() const
getRegLiveOut - Returns a bit mask of live-out registers.
void setInstrRefOpIndex(unsigned OpIdx)
static MachineOperand CreateES(const char *SymName, unsigned TargetFlags=0)
const ConstantInt * getCImm() const
const char * getTargetIndexName() const
getTargetIndexName - If this MachineOperand is a TargetIndex that has a name, attempt to get the name...
static void printStackObjectReference(raw_ostream &OS, unsigned FrameIndex, bool IsFixed, StringRef Name)
Print a stack object reference.
static void printSubRegIdx(raw_ostream &OS, uint64_t Index, const TargetRegisterInfo *TRI)
Print a subreg index operand.
static MachineOperand CreateFPImm(const ConstantFP *CFP)
void setImm(int64_t immVal)
bool isCImm() const
isCImm - Test if this is a MO_CImmediate operand.
void setRegMask(const uint32_t *RegMaskPtr)
Sets value of register mask operand referencing Mask.
unsigned getInstrRefInstrIndex() const
static void printTargetFlags(raw_ostream &OS, const MachineOperand &Op)
Print operand target flags.
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register.
static MachineOperand CreateCFIIndex(unsigned CFIIndex)
void setFPImm(const ConstantFP *CFP)
void ChangeToFPImmediate(const ConstantFP *FPImm, unsigned TargetFlags=0)
ChangeToFPImmediate - Replace this operand with a new FP immediate operand of the specified value.
bool isIntrinsicID() const
void setIsRenamable(bool Val=true)
static MachineOperand CreateRegMask(const uint32_t *Mask)
CreateRegMask - Creates a register mask operand referencing Mask.
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
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
friend hash_code hash_value(const MachineOperand &MO)
MachineOperand hash_value overload.
static MachineOperand CreateCImm(const ConstantInt *CI)
void setIsDead(bool Val=true)
ArrayRef< int > getShuffleMask() const
void ChangeToMCSymbol(MCSymbol *Sym, unsigned TargetFlags=0)
ChangeToMCSymbol - Replace this operand with a new MC symbol operand.
void ChangeToTargetIndex(unsigned Idx, int64_t Offset, unsigned TargetFlags=0)
Replace this operand with a target index.
void setReg(Register Reg)
Change the register this operand corresponds to.
void setMetadata(const MDNode *MD)
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isValidExcessOperand() const
Return true if this operand can validly be appended to an arbitrary operand list.
void ChangeToImmediate(int64_t ImmVal, unsigned TargetFlags=0)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value.
bool isMetadata() const
isMetadata - Tests if this is a MO_Metadata operand.
bool clobbersPhysReg(MCRegister PhysReg) const
clobbersPhysReg - Returns true if this RegMask operand clobbers PhysReg.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
void ChangeToES(const char *SymName, unsigned TargetFlags=0)
ChangeToES - Replace this operand with a new external symbol operand.
void clearParent()
clearParent - Reset the parent pointer.
bool isShuffleMask() const
void ChangeToGA(const GlobalValue *GV, int64_t Offset, unsigned TargetFlags=0)
ChangeToGA - Replace this operand with a new global address operand.
unsigned getCFIIndex() const
void setIsKill(bool Val=true)
bool isRenamable() const
isRenamable - Returns true if this register may be renamed, i.e.
void ChangeToBA(const BlockAddress *BA, int64_t Offset, unsigned TargetFlags=0)
ChangeToBA - Replace this operand with a new block address operand.
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
static MachineOperand CreateMetadata(const MDNode *Meta)
static void printOperandOffset(raw_ostream &OS, int64_t Offset)
Print the offset with explicit +/- signs.
void ChangeToDbgInstrRef(unsigned InstrIdx, unsigned OpIdx, unsigned TargetFlags=0)
Replace this operand with an Instruction Reference.
void ChangeToRegister(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isDebug=false)
ChangeToRegister - Replace this operand with a new register operand of the specified value.
const BlockAddress * getBlockAddress() const
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
void substPhysReg(MCRegister Reg, const TargetRegisterInfo &)
substPhysReg - Substitute the current register with the physical register Reg, taking any existing Su...
static MachineOperand CreatePredicate(unsigned Pred)
void setMBB(MachineBasicBlock *MBB)
bool isRegLiveOut() const
isRegLiveOut - Tests if this is a MO_RegisterLiveOut operand.
void setIsEarlyClobber(bool Val=true)
static unsigned getRegMaskSize(unsigned NumRegs)
Returns number of elements needed for a regmask array.
void setOffset(int64_t Offset)
void setCImm(const ConstantInt *CI)
static void printIRSlotNumber(raw_ostream &OS, int Slot)
Print an IRSlotNumber.
unsigned getTargetFlags() const
static MachineOperand CreateImm(int64_t Val)
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
void setPredicate(unsigned Predicate)
static MachineOperand CreateShuffleMask(ArrayRef< int > Mask)
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
static MachineOperand CreateJTI(unsigned Idx, unsigned TargetFlags=0)
const char * getSymbolName() const
static MachineOperand CreateDbgInstrRef(unsigned InstrIdx, unsigned OpIdx)
void setIsUndef(bool Val=true)
void setIsDebug(bool Val=true)
bool isEarlyClobber() const
bool isBlockAddress() const
isBlockAddress - Tests if this is a MO_BlockAddress operand.
Register getReg() const
getReg - Returns the register number.
bool isTargetIndex() const
isTargetIndex - Tests if this is a MO_TargetIndex operand.
static MachineOperand CreateRegLiveOut(const uint32_t *Mask)
static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset, unsigned TargetFlags=0)
void setIntrinsicID(Intrinsic::ID IID)
void addTargetFlag(unsigned F)
bool isDbgInstrRef() const
Intrinsic::ID getIntrinsicID() const
bool isInternalRead() const
static MachineOperand CreateBA(const BlockAddress *BA, int64_t Offset, unsigned TargetFlags=0)
void setTargetFlags(unsigned F)
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
bool isIdenticalTo(const MachineOperand &Other) const
Returns true if this operand is identical to the specified operand except for liveness related flags ...
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
const uint32_t * getRegMask() const
getRegMask - Returns a bit mask of registers preserved by this RegMask operand.
static MachineOperand CreateCPI(unsigned Idx, int Offset, unsigned TargetFlags=0)
void setIsDef(bool Val=true)
Change a def to a use, or a use to a def.
void print(raw_ostream &os, const TargetRegisterInfo *TRI=nullptr, const TargetIntrinsicInfo *IntrinsicInfo=nullptr) const
Print the MachineOperand to os.
const ConstantFP * getFPImm() const
static void printSymbol(raw_ostream &OS, MCSymbol &Sym)
Print a MCSymbol as an operand.
const MachineInstr * getParent() const
unsigned getPredicate() const
MCSymbol * getMCSymbol() const
@ MO_CFIIndex
MCCFIInstruction index.
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_MCSymbol
MCSymbol reference (for debug/eh info)
@ MO_Predicate
Generic predicate for ISel.
@ MO_GlobalAddress
Address of a global value.
@ MO_RegisterMask
Mask of preserved registers.
@ MO_ShuffleMask
Other IR Constant for ISel (shuffle masks)
@ MO_CImmediate
Immediate >64bit operand.
@ MO_BlockAddress
Address of a basic block.
@ MO_DbgInstrRef
Integer indices referring to an instruction+operand.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_FrameIndex
Abstract Stack Frame Index.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_IntrinsicID
Intrinsic ID for ISel.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
@ MO_TargetIndex
Target-dependent index+offset operand.
@ MO_Metadata
Metadata reference (for debug info)
@ MO_FPImmediate
Floating-point immediate operand.
@ MO_RegisterLiveOut
Mask of live-out registers.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
static MachineOperand CreateTargetIndex(unsigned Idx, int64_t Offset, unsigned TargetFlags=0)
static MachineOperand CreateMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0)
int64_t getOffset() const
Return the offset from the symbol in this operand.
static MachineOperand CreateIntrinsicID(Intrinsic::ID ID)
bool isFPImm() const
isFPImm - Tests if this is a MO_FPImmediate operand.
static MachineOperand CreateFI(int Idx)
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Manage lifetime of a slot tracker for printing IR.
Wrapper class representing virtual and physical registers.
StringRef - Represent a constant reference to a string, i.e.
TargetIntrinsicInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
An opaque object representing a hash code.
This class implements an extremely fast bulk output stream that can only output to a stream.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Reg
All possible values of the reg field in the ModR/M byte.
This is an optimization pass for GlobalISel generic memory operations.
hash_code hash_value(const FixedPointSemantics &Val)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
static unsigned getHashValue(const MachineOperand &MO)
static MachineOperand getTombstoneKey()
static MachineOperand getEmptyKey()
static bool isEqual(const MachineOperand &LHS, const MachineOperand &RHS)
An information struct used to provide DenseMap with the various necessary components for a given valu...