13#ifndef LLVM_CODEGEN_MACHINEOPERAND_H
14#define LLVM_CODEGEN_MACHINEOPERAND_H
29class MachineBasicBlock;
31class MachineRegisterInfo;
32class MCCFIInstruction;
34class ModuleSlotTracker;
35class TargetRegisterInfo;
83 unsigned SubReg_TargetFlags : 12;
109 unsigned IsDeadOrKill : 1;
112 unsigned IsRenamable : 1;
131 unsigned IsUndef : 1;
142 unsigned IsInternalRead : 1;
147 unsigned IsEarlyClobber : 1;
151 unsigned IsDebug : 1;
167 union ContentsUnion {
169 MachineBasicBlock *
MBB;
170 const ConstantFP *CFP;
171 const ConstantInt *CI;
179 ArrayRef<int> ShuffleMask;
183 MachineOperand *Prev;
184 MachineOperand *Next;
198 const GlobalValue *GV;
207 : OpKind(
K), SubReg_TargetFlags(0) {
209 static_assert(
alignof(MachineOperand) <=
alignof(int64_t),
210 "MachineOperand shouldn't be more than 8 byte aligned");
211 static_assert(
sizeof(Contents) <= 2 *
sizeof(
void *),
212 "Contents should be at most two pointers");
213 static_assert(
sizeof(MachineOperand) <=
216 "MachineOperand too big. Should be Kind, SmallContents, "
217 "ParentMI, and Contents");
226 return isReg() ? 0 : SubReg_TargetFlags;
229 assert(!
isReg() &&
"Register operands can't have target flags");
230 SubReg_TargetFlags =
F;
231 assert(SubReg_TargetFlags ==
F &&
"Target flags out of range");
234 assert(!
isReg() &&
"Register operands can't have target flags");
235 SubReg_TargetFlags |=
F;
236 assert((SubReg_TargetFlags &
F) &&
"Target flags out of range");
309 std::optional<unsigned> OpIdx,
bool PrintDef,
bool IsStandalone,
310 bool ShouldPrintRegisterTies,
unsigned TiedOperandIdx,
366 assert(
isReg() &&
"This is not a register operand!");
367 return Register(SmallContents.RegNo);
371 assert(
isReg() &&
"Wrong MachineOperand accessor");
372 return SubReg_TargetFlags;
376 assert(
isReg() &&
"Wrong MachineOperand accessor");
381 assert(
isReg() &&
"Wrong MachineOperand accessor");
386 assert(
isReg() &&
"Wrong MachineOperand accessor");
391 assert(
isReg() &&
"Wrong MachineOperand accessor");
392 return IsDeadOrKill & IsDef;
396 assert(
isReg() &&
"Wrong MachineOperand accessor");
397 return IsDeadOrKill & !IsDef;
401 assert(
isReg() &&
"Wrong MachineOperand accessor");
437 assert(
isReg() &&
"Wrong MachineOperand accessor");
438 return IsInternalRead;
442 assert(
isReg() &&
"Wrong MachineOperand accessor");
443 return IsEarlyClobber;
447 assert(
isReg() &&
"Wrong MachineOperand accessor");
452 assert(
isReg() &&
"Wrong MachineOperand accessor");
464 assert(
isReg() &&
"Wrong MachineOperand accessor");
488 SubReg_TargetFlags = subReg;
489 assert(SubReg_TargetFlags == subReg &&
"SubReg out of range");
516 assert(
isReg() && !IsDef &&
"Wrong MachineOperand mutator");
517 assert((!Val || !
isDebug()) &&
"Marking a debug operation as kill");
522 assert(
isReg() && IsDef &&
"Wrong MachineOperand mutator");
535 IsInternalRead = Val;
539 assert(
isReg() && IsDef &&
"Wrong MachineOperand mutator");
540 IsEarlyClobber = Val;
544 assert(
isReg() && !IsDef &&
"Wrong MachineOperand mutator");
553 assert(
isImm() &&
"Wrong MachineOperand accessor");
554 return Contents.ImmVal;
568 assert(
isMBB() &&
"Wrong MachineOperand accessor");
574 "Wrong MachineOperand accessor");
575 return Contents.OffsetedInfo.Val.Index;
580 return Contents.OffsetedInfo.Val.GV;
585 return Contents.OffsetedInfo.Val.BA;
595 return Contents.InstrRef.InstrIdx;
600 return Contents.InstrRef.OpIdx;
605 return Contents.CFIIndex;
610 return Contents.IntrinsicID;
615 return Contents.Pred;
620 return Contents.ShuffleMask;
628 "Wrong MachineOperand accessor");
629 return int64_t(
uint64_t(Contents.OffsetedInfo.OffsetHi) << 32) |
630 SmallContents.OffsetLo;
635 return Contents.OffsetedInfo.Val.SymbolName;
645 "Not a physical register");
646 return !(RegMask[PhysReg.
id() / 32] & (1u << PhysReg.
id() % 32));
658 return Contents.RegMask;
663 return (NumRegs + 31) / 32;
669 return Contents.RegMask;
683 Contents.ImmVal = immVal;
699 "Wrong MachineOperand mutator");
701 Contents.OffsetedInfo.OffsetHi = int(
Offset >> 32);
706 "Wrong MachineOperand mutator");
707 Contents.OffsetedInfo.Val.Index =
Idx;
717 Contents.InstrRef.InstrIdx = InstrIdx;
721 Contents.InstrRef.OpIdx = OpIdx;
735 Contents.RegMask = RegMaskPtr;
740 Contents.IntrinsicID = IID;
776 void ChangeToES(
const char *SymName,
unsigned TargetFlags = 0);
780 unsigned TargetFlags = 0);
784 unsigned TargetFlags = 0);
794 unsigned TargetFlags = 0);
798 unsigned TargetFlags = 0);
830 Op.Contents.CFP = CFP;
853 Op.SmallContents.RegNo =
Reg.id();
854 Op.Contents.Reg.Prev =
nullptr;
855 Op.Contents.Reg.Next =
nullptr;
860 unsigned TargetFlags = 0) {
863 Op.setTargetFlags(TargetFlags);
872 unsigned TargetFlags = 0) {
876 Op.setTargetFlags(TargetFlags);
880 unsigned TargetFlags = 0) {
884 Op.setTargetFlags(TargetFlags);
890 Op.setTargetFlags(TargetFlags);
894 unsigned TargetFlags = 0) {
896 Op.Contents.OffsetedInfo.Val.GV = GV;
898 Op.setTargetFlags(TargetFlags);
902 unsigned TargetFlags = 0) {
904 Op.Contents.OffsetedInfo.Val.SymbolName = SymName;
906 Op.setTargetFlags(TargetFlags);
910 unsigned TargetFlags = 0) {
912 Op.Contents.OffsetedInfo.Val.BA = BA;
914 Op.setTargetFlags(TargetFlags);
930 assert(Mask &&
"Missing register mask");
932 Op.Contents.RegMask = Mask;
936 assert(Mask &&
"Missing live-out register mask");
938 Op.Contents.RegMask = Mask;
943 Op.Contents.MD = Meta;
948 unsigned TargetFlags = 0) {
950 Op.Contents.Sym =
Sym;
952 Op.setTargetFlags(TargetFlags);
958 Op.Contents.InstrRef.InstrIdx = InstrIdx;
959 Op.Contents.InstrRef.OpIdx = OpIdx;
965 Op.Contents.CFIIndex = CFIIndex;
971 Op.Contents.IntrinsicID =
ID;
977 Op.Contents.Pred = Pred;
983 Op.Contents.ShuffleMask = Mask;
993 void removeRegFromUses();
996 enum :
unsigned char {
1010 bool isOnRegUseList()
const {
1011 assert(
isReg() &&
"Can only add reg operand to use lists");
1012 return Contents.Reg.Prev !=
nullptr;
1019 MachineOperand::MO_Empty));
1023 MachineOperand::MO_Tombstone));
1030 MachineOperand::MO_Empty) ||
1032 MachineOperand::MO_Tombstone))
1033 return LHS.getType() ==
RHS.getType();
1034 return LHS.isIdenticalTo(
RHS);
1045hash_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.
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)
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.
void print(raw_ostream &os, const TargetRegisterInfo *TRI=nullptr) const
Print the MachineOperand to os.
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.
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.
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...