13#ifndef LLVM_CODEGEN_MACHINEOPERAND_H
14#define LLVM_CODEGEN_MACHINEOPERAND_H
86 unsigned SubReg_TargetFlags : 12;
112 unsigned IsDeadOrKill : 1;
115 unsigned IsRenamable : 1;
134 unsigned IsUndef : 1;
145 unsigned IsInternalRead : 1;
150 unsigned IsEarlyClobber : 1;
154 unsigned IsDebug : 1;
170 union ContentsUnion {
172 MachineBasicBlock *
MBB;
173 const ConstantFP *CFP;
174 const ConstantInt *CI;
182 ArrayRef<int> ShuffleMask;
183 LaneBitmask LaneMask;
187 MachineOperand *Prev;
188 MachineOperand *
Next;
201 const char *SymbolName;
202 const GlobalValue *GV;
211 : OpKind(
K), SubReg_TargetFlags(0) {
213 static_assert(
alignof(MachineOperand) <=
alignof(int64_t),
214 "MachineOperand shouldn't be more than 8 byte aligned");
215 static_assert(
sizeof(Contents) <= 2 *
sizeof(
void *),
216 "Contents should be at most two pointers");
217 static_assert(
sizeof(MachineOperand) <=
220 "MachineOperand too big. Should be Kind, SmallContents, "
221 "ParentMI, and Contents");
230 return isReg() ? 0 : SubReg_TargetFlags;
233 assert(!
isReg() &&
"Register operands can't have target flags");
234 SubReg_TargetFlags =
F;
235 assert(SubReg_TargetFlags ==
F &&
"Target flags out of range");
238 assert(!
isReg() &&
"Register operands can't have target flags");
239 SubReg_TargetFlags |=
F;
240 assert((SubReg_TargetFlags &
F) &&
"Target flags out of range");
314 std::optional<unsigned>
OpIdx,
bool PrintDef,
315 bool IsStandalone,
bool ShouldPrintRegisterTies,
316 unsigned TiedOperandIdx,
373 assert(
isReg() &&
"This is not a register operand!");
374 return Register(SmallContents.RegNo);
378 assert(
isReg() &&
"Wrong MachineOperand accessor");
379 return SubReg_TargetFlags;
383 assert(
isReg() &&
"Wrong MachineOperand accessor");
388 assert(
isReg() &&
"Wrong MachineOperand accessor");
393 assert(
isReg() &&
"Wrong MachineOperand accessor");
398 assert(
isReg() &&
"Wrong MachineOperand accessor");
399 return IsDeadOrKill & IsDef;
403 assert(
isReg() &&
"Wrong MachineOperand accessor");
404 return IsDeadOrKill & !IsDef;
408 assert(
isReg() &&
"Wrong MachineOperand accessor");
444 assert(
isReg() &&
"Wrong MachineOperand accessor");
445 return IsInternalRead;
449 assert(
isReg() &&
"Wrong MachineOperand accessor");
450 return IsEarlyClobber;
454 assert(
isReg() &&
"Wrong MachineOperand accessor");
459 assert(
isReg() &&
"Wrong MachineOperand accessor");
471 assert(
isReg() &&
"Wrong MachineOperand accessor");
495 SubReg_TargetFlags = subReg;
496 assert(SubReg_TargetFlags == subReg &&
"SubReg out of range");
524 assert(
isReg() && !IsDef &&
"Wrong MachineOperand mutator");
525 assert((!Val || !
isDebug()) &&
"Marking a debug operation as kill");
530 assert(
isReg() && IsDef &&
"Wrong MachineOperand mutator");
543 IsInternalRead = Val;
547 assert(
isReg() && IsDef &&
"Wrong MachineOperand mutator");
548 IsEarlyClobber = Val;
552 assert(
isReg() && !IsDef &&
"Wrong MachineOperand mutator");
561 assert(
isImm() &&
"Wrong MachineOperand accessor");
562 return Contents.ImmVal;
576 assert(
isMBB() &&
"Wrong MachineOperand accessor");
582 "Wrong MachineOperand accessor");
583 return Contents.OffsetedInfo.Val.Index;
588 return Contents.OffsetedInfo.Val.GV;
593 return Contents.OffsetedInfo.Val.BA;
603 return Contents.InstrRef.InstrIdx;
608 return Contents.InstrRef.OpIdx;
613 return Contents.CFIIndex;
618 return Contents.IntrinsicID;
623 return Contents.Pred;
628 return Contents.ShuffleMask;
633 return Contents.LaneMask;
641 "Wrong MachineOperand accessor");
642 return int64_t(
uint64_t(Contents.OffsetedInfo.OffsetHi) << 32) |
643 SmallContents.OffsetLo;
648 return Contents.OffsetedInfo.Val.SymbolName;
658 "Not a physical register");
659 return !(RegMask[PhysReg.
id() / 32] & (1u << PhysReg.
id() % 32));
671 return Contents.RegMask;
676 return (NumRegs + 31) / 32;
682 return Contents.RegMask;
696 Contents.ImmVal = immVal;
712 "Wrong MachineOperand mutator");
714 Contents.OffsetedInfo.OffsetHi = int(
Offset >> 32);
719 "Wrong MachineOperand mutator");
720 Contents.OffsetedInfo.Val.Index = Idx;
730 Contents.InstrRef.InstrIdx = InstrIdx;
734 Contents.InstrRef.OpIdx =
OpIdx;
748 Contents.RegMask = RegMaskPtr;
753 Contents.IntrinsicID = IID;
787 unsigned TargetFlags = 0);
794 unsigned TargetFlags = 0);
798 unsigned TargetFlags = 0);
811 unsigned TargetFlags = 0);
815 unsigned TargetFlags = 0);
847 Op.Contents.CFP = CFP;
870 Op.SmallContents.RegNo =
Reg.id();
871 Op.Contents.Reg.Prev =
nullptr;
872 Op.Contents.Reg.Next =
nullptr;
877 unsigned TargetFlags = 0) {
880 Op.setTargetFlags(TargetFlags);
889 unsigned TargetFlags = 0) {
893 Op.setTargetFlags(TargetFlags);
897 unsigned TargetFlags = 0) {
901 Op.setTargetFlags(TargetFlags);
904 static MachineOperand
CreateJTI(
unsigned Idx,
unsigned TargetFlags = 0) {
907 Op.setTargetFlags(TargetFlags);
911 unsigned TargetFlags = 0) {
913 Op.Contents.OffsetedInfo.Val.GV = GV;
915 Op.setTargetFlags(TargetFlags);
918 static MachineOperand
CreateES(
const char *SymName,
919 unsigned TargetFlags = 0) {
921 Op.Contents.OffsetedInfo.Val.SymbolName = SymName;
923 Op.setTargetFlags(TargetFlags);
927 unsigned TargetFlags = 0) {
929 Op.Contents.OffsetedInfo.Val.BA = BA;
931 Op.setTargetFlags(TargetFlags);
947 assert(Mask &&
"Missing register mask");
949 Op.Contents.RegMask = Mask;
953 assert(Mask &&
"Missing live-out register mask");
955 Op.Contents.RegMask = Mask;
960 Op.Contents.MD = Meta;
965 unsigned TargetFlags = 0) {
967 Op.Contents.Sym = Sym;
969 Op.setTargetFlags(TargetFlags);
975 Op.Contents.InstrRef.InstrIdx = InstrIdx;
976 Op.Contents.InstrRef.OpIdx =
OpIdx;
982 Op.Contents.CFIIndex = CFIIndex;
988 Op.Contents.IntrinsicID =
ID;
994 Op.Contents.Pred = Pred;
1000 Op.Contents.ShuffleMask = Mask;
1006 Op.Contents.LaneMask = LaneMask;
1016 void removeRegFromUses();
1019 enum :
unsigned char {
1033 bool isOnRegUseList()
const {
1034 assert(
isReg() &&
"Can only add reg operand to use lists");
1035 return Contents.Reg.Prev !=
nullptr;
1042 MachineOperand::MO_Empty));
1046 MachineOperand::MO_Tombstone));
1053 MachineOperand::MO_Empty) ||
1055 MachineOperand::MO_Tombstone))
1056 return LHS.getType() ==
RHS.getType();
1057 return LHS.isIdenticalTo(
RHS);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines DenseMapInfo traits for DenseMap.
A common definition of LaneBitmask for use in TableGen and CodeGen.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
MachineInstr unsigned OpIdx
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 is an important base class in LLVM.
Wrapper class representing physical registers. Should be passed by value.
constexpr bool isValid() const
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
constexpr unsigned id() const
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)
LLVM_ABI 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)
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)
static MachineOperand CreateES(const char *SymName, unsigned TargetFlags=0)
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.
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 LLVM_ABI 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)
LLVM_ABI 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
LLVM_ABI 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.
static MachineOperand CreateCImm(const ConstantInt *CI)
void setIsDead(bool Val=true)
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.
void setMetadata(const MDNode *MD)
LLVM_ABI void dump() const
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.
LLVM_ABI 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.
LLVM_ABI 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
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
void setIsKill(bool Val=true)
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.
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
static MachineOperand CreateMetadata(const MDNode *Meta)
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 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 LLVM_ABI 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)
static MachineOperand CreateLaneMask(LaneBitmask LaneMask)
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
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
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.
friend class MachineInstr
static MachineOperand CreateCPI(unsigned Idx, int Offset, unsigned TargetFlags=0)
LLVM_ABI friend hash_code hash_value(const MachineOperand &MO)
MachineOperand hash_value overload.
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.
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_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.
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.
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
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.
FunctionAddr VTableAddr Next
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...