13#ifndef LLVM_CODEGEN_MACHINEOPERAND_H
14#define LLVM_CODEGEN_MACHINEOPERAND_H
30class MachineBasicBlock;
32class MachineRegisterInfo;
33class MCCFIInstruction;
35class ModuleSlotTracker;
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,
312 bool IsStandalone,
bool ShouldPrintRegisterTies,
313 unsigned TiedOperandIdx,
369 assert(
isReg() &&
"This is not a register operand!");
370 return Register(SmallContents.RegNo);
374 assert(
isReg() &&
"Wrong MachineOperand accessor");
375 return SubReg_TargetFlags;
379 assert(
isReg() &&
"Wrong MachineOperand accessor");
384 assert(
isReg() &&
"Wrong MachineOperand accessor");
389 assert(
isReg() &&
"Wrong MachineOperand accessor");
394 assert(
isReg() &&
"Wrong MachineOperand accessor");
395 return IsDeadOrKill & IsDef;
399 assert(
isReg() &&
"Wrong MachineOperand accessor");
400 return IsDeadOrKill & !IsDef;
404 assert(
isReg() &&
"Wrong MachineOperand accessor");
440 assert(
isReg() &&
"Wrong MachineOperand accessor");
441 return IsInternalRead;
445 assert(
isReg() &&
"Wrong MachineOperand accessor");
446 return IsEarlyClobber;
450 assert(
isReg() &&
"Wrong MachineOperand accessor");
455 assert(
isReg() &&
"Wrong MachineOperand accessor");
467 assert(
isReg() &&
"Wrong MachineOperand accessor");
491 SubReg_TargetFlags = subReg;
492 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;
649 "Not a physical register");
650 return !(RegMask[PhysReg.
id() / 32] & (1u << PhysReg.
id() % 32));
662 return Contents.RegMask;
667 return (NumRegs + 31) / 32;
673 return Contents.RegMask;
687 Contents.ImmVal = immVal;
703 "Wrong MachineOperand mutator");
705 Contents.OffsetedInfo.OffsetHi = int(
Offset >> 32);
710 "Wrong MachineOperand mutator");
711 Contents.OffsetedInfo.Val.Index =
Idx;
721 Contents.InstrRef.InstrIdx = InstrIdx;
725 Contents.InstrRef.OpIdx =
OpIdx;
739 Contents.RegMask = RegMaskPtr;
744 Contents.IntrinsicID = IID;
778 unsigned TargetFlags = 0);
785 unsigned TargetFlags = 0);
789 unsigned TargetFlags = 0);
799 unsigned TargetFlags = 0);
803 unsigned TargetFlags = 0);
835 Op.Contents.CFP = CFP;
858 Op.SmallContents.RegNo =
Reg.id();
859 Op.Contents.Reg.Prev =
nullptr;
860 Op.Contents.Reg.Next =
nullptr;
865 unsigned TargetFlags = 0) {
868 Op.setTargetFlags(TargetFlags);
877 unsigned TargetFlags = 0) {
881 Op.setTargetFlags(TargetFlags);
885 unsigned TargetFlags = 0) {
889 Op.setTargetFlags(TargetFlags);
895 Op.setTargetFlags(TargetFlags);
899 unsigned TargetFlags = 0) {
901 Op.Contents.OffsetedInfo.Val.GV = GV;
903 Op.setTargetFlags(TargetFlags);
907 unsigned TargetFlags = 0) {
909 Op.Contents.OffsetedInfo.Val.SymbolName = SymName;
911 Op.setTargetFlags(TargetFlags);
915 unsigned TargetFlags = 0) {
917 Op.Contents.OffsetedInfo.Val.BA = BA;
919 Op.setTargetFlags(TargetFlags);
935 assert(Mask &&
"Missing register mask");
937 Op.Contents.RegMask = Mask;
941 assert(Mask &&
"Missing live-out register mask");
943 Op.Contents.RegMask = Mask;
948 Op.Contents.MD = Meta;
953 unsigned TargetFlags = 0) {
955 Op.Contents.Sym =
Sym;
957 Op.setTargetFlags(TargetFlags);
963 Op.Contents.InstrRef.InstrIdx = InstrIdx;
964 Op.Contents.InstrRef.OpIdx =
OpIdx;
970 Op.Contents.CFIIndex = CFIIndex;
976 Op.Contents.IntrinsicID =
ID;
982 Op.Contents.Pred = Pred;
988 Op.Contents.ShuffleMask = Mask;
998 void removeRegFromUses();
1001 enum :
unsigned char {
1015 bool isOnRegUseList()
const {
1016 assert(
isReg() &&
"Can only add reg operand to use lists");
1017 return Contents.Reg.Prev !=
nullptr;
1024 MachineOperand::MO_Empty));
1028 MachineOperand::MO_Tombstone));
1035 MachineOperand::MO_Empty) ||
1037 MachineOperand::MO_Tombstone))
1038 return LHS.getType() ==
RHS.getType();
1039 return LHS.isIdenticalTo(
RHS);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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.
Register const TargetRegisterInfo * TRI
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 class represents an Operation in the Expression.
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.
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)
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 ...
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)
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_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.
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...