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;
137 unsigned IsUndef : 1;
148 unsigned IsInternalRead : 1;
153 unsigned IsEarlyClobber : 1;
157 unsigned IsDebug : 1;
173 union ContentsUnion {
175 MachineBasicBlock *
MBB;
176 const ConstantFP *CFP;
177 const ConstantInt *CI;
185 ArrayRef<int> ShuffleMask;
186 LaneBitmask LaneMask;
190 MachineOperand *Prev;
191 MachineOperand *
Next;
204 const char *SymbolName;
205 const GlobalValue *GV;
214 : OpKind(
K), SubReg_TargetFlags(0) {
216 static_assert(
alignof(MachineOperand) <=
alignof(int64_t),
217 "MachineOperand shouldn't be more than 8 byte aligned");
218 static_assert(
sizeof(Contents) <= 2 *
sizeof(
void *),
219 "Contents should be at most two pointers");
220 static_assert(
sizeof(MachineOperand) <=
223 "MachineOperand too big. Should be Kind, SmallContents, "
224 "ParentMI, and Contents");
233 return isReg() ? 0 : SubReg_TargetFlags;
236 assert(!
isReg() &&
"Register operands can't have target flags");
237 SubReg_TargetFlags =
F;
238 assert(SubReg_TargetFlags ==
F &&
"Target flags out of range");
241 assert(!
isReg() &&
"Register operands can't have target flags");
242 SubReg_TargetFlags |=
F;
243 assert((SubReg_TargetFlags &
F) &&
"Target flags out of range");
317 std::optional<unsigned> OpIdx,
bool PrintDef,
318 bool IsStandalone,
bool ShouldPrintRegisterTies,
319 unsigned TiedOperandIdx,
376 assert(
isReg() &&
"This is not a register operand!");
377 return Register(SmallContents.RegNo);
381 assert(
isReg() &&
"Wrong MachineOperand accessor");
382 return SubReg_TargetFlags;
386 assert(
isReg() &&
"Wrong MachineOperand accessor");
391 assert(
isReg() &&
"Wrong MachineOperand accessor");
396 assert(
isReg() &&
"Wrong MachineOperand accessor");
401 assert(
isReg() &&
"Wrong MachineOperand accessor");
402 return IsDeadOrKill & IsDef;
406 assert(
isReg() &&
"Wrong MachineOperand accessor");
407 return IsDeadOrKill && !IsDef;
411 assert(
isReg() &&
"Wrong MachineOperand accessor");
447 assert(
isReg() &&
"Wrong MachineOperand accessor");
448 return IsInternalRead;
452 assert(
isReg() &&
"Wrong MachineOperand accessor");
453 return IsEarlyClobber;
457 assert(
isReg() &&
"Wrong MachineOperand accessor");
462 assert(
isReg() &&
"Wrong MachineOperand accessor");
474 assert(
isReg() &&
"Wrong MachineOperand accessor");
498 SubReg_TargetFlags = subReg;
499 assert(SubReg_TargetFlags == subReg &&
"SubReg out of range");
527 assert(
isReg() && !IsDef &&
"Wrong MachineOperand mutator");
528 assert((!Val || !
isDebug()) &&
"Marking a debug operation as kill");
533 assert(
isReg() && IsDef &&
"Wrong MachineOperand mutator");
546 IsInternalRead = Val;
550 assert(
isReg() && IsDef &&
"Wrong MachineOperand mutator");
551 IsEarlyClobber = Val;
555 assert(
isReg() && !IsDef &&
"Wrong MachineOperand mutator");
564 assert(
isImm() &&
"Wrong MachineOperand accessor");
565 return Contents.ImmVal;
579 assert(
isMBB() &&
"Wrong MachineOperand accessor");
585 "Wrong MachineOperand accessor");
586 return Contents.OffsetedInfo.Val.Index;
591 return Contents.OffsetedInfo.Val.GV;
596 return Contents.OffsetedInfo.Val.BA;
606 return Contents.InstrRef.InstrIdx;
611 return Contents.InstrRef.OpIdx;
616 return Contents.CFIIndex;
621 return Contents.IntrinsicID;
626 return Contents.Pred;
631 return Contents.ShuffleMask;
636 return Contents.LaneMask;
644 "Wrong MachineOperand accessor");
645 return int64_t(
uint64_t(Contents.OffsetedInfo.OffsetHi) << 32) |
646 SmallContents.OffsetLo;
651 return Contents.OffsetedInfo.Val.SymbolName;
661 "Not a physical register");
662 return !(RegMask[PhysReg.
id() / 32] & (1u << PhysReg.
id() % 32));
674 return Contents.RegMask;
679 return (NumRegs + 31) / 32;
685 return Contents.RegMask;
699 Contents.ImmVal = immVal;
715 "Wrong MachineOperand mutator");
717 Contents.OffsetedInfo.OffsetHi = int(
Offset >> 32);
722 "Wrong MachineOperand mutator");
723 Contents.OffsetedInfo.Val.Index = Idx;
733 Contents.InstrRef.InstrIdx = InstrIdx;
737 Contents.InstrRef.OpIdx = OpIdx;
751 Contents.RegMask = RegMaskPtr;
756 Contents.IntrinsicID = IID;
790 unsigned TargetFlags = 0);
797 unsigned TargetFlags = 0);
801 unsigned TargetFlags = 0);
814 unsigned TargetFlags = 0);
818 unsigned TargetFlags = 0);
850 Op.Contents.CFP = CFP;
858 unsigned SubReg = 0,
bool isDebug =
false,
873 Op.SmallContents.RegNo =
Reg.id();
874 Op.Contents.Reg.Prev =
nullptr;
875 Op.Contents.Reg.Next =
nullptr;
876 Op.setSubReg(SubReg);
880 unsigned TargetFlags = 0) {
883 Op.setTargetFlags(TargetFlags);
892 unsigned TargetFlags = 0) {
896 Op.setTargetFlags(TargetFlags);
900 unsigned TargetFlags = 0) {
904 Op.setTargetFlags(TargetFlags);
907 static MachineOperand
CreateJTI(
unsigned Idx,
unsigned TargetFlags = 0) {
910 Op.setTargetFlags(TargetFlags);
914 unsigned TargetFlags = 0) {
916 Op.Contents.OffsetedInfo.Val.GV = GV;
918 Op.setTargetFlags(TargetFlags);
921 static MachineOperand
CreateES(
const char *SymName,
922 unsigned TargetFlags = 0) {
924 Op.Contents.OffsetedInfo.Val.SymbolName = SymName;
926 Op.setTargetFlags(TargetFlags);
930 unsigned TargetFlags = 0) {
932 Op.Contents.OffsetedInfo.Val.BA = BA;
934 Op.setTargetFlags(TargetFlags);
950 assert(Mask &&
"Missing register mask");
952 Op.Contents.RegMask = Mask;
956 assert(Mask &&
"Missing live-out register mask");
958 Op.Contents.RegMask = Mask;
963 Op.Contents.MD = Meta;
968 unsigned TargetFlags = 0) {
970 Op.Contents.Sym = Sym;
972 Op.setTargetFlags(TargetFlags);
978 Op.Contents.InstrRef.InstrIdx = InstrIdx;
979 Op.Contents.InstrRef.OpIdx = OpIdx;
985 Op.Contents.CFIIndex = CFIIndex;
991 Op.Contents.IntrinsicID = ID;
997 Op.Contents.Pred = Pred;
1003 Op.Contents.ShuffleMask = Mask;
1009 Op.Contents.LaneMask = LaneMask;
1019 void removeRegFromUses();
1022 enum :
unsigned char {
1035 bool isOnRegUseList()
const {
1036 assert(
isReg() &&
"Can only add reg operand to use lists");
1037 return Contents.Reg.Prev !=
nullptr;
1047 MachineOperand::MO_Empty))
1048 return LHS.getType() ==
RHS.getType();
1049 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
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.
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.
This is an optimization pass for GlobalISel generic memory operations.
hash_code hash_value(const FixedPointSemantics &Val)
constexpr 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)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
static unsigned getHashValue(const MachineOperand &MO)
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...