26 #define DEBUG_TYPE "globalisel-utils" 53 if (ConstrainedReg != Reg) {
58 TII.
get(TargetOpcode::COPY), ConstrainedReg)
63 TII.
get(TargetOpcode::COPY),
Reg)
64 .addReg(ConstrainedReg);
67 return ConstrainedReg;
93 "Register class constraint is required unless either the " 94 "instruction is target independent or the operand is a use");
116 "A selected instruction is expected");
129 assert(MO.
isReg() &&
"Unsupported non-reg operand");
162 bool SawStore =
false;
168 if (!MO.isReg() || !MO.isDef())
186 R << (
" (in function: " + MF.
getName() +
")").str();
211 assert((!ValAndVReg || ValAndVReg->
VReg == VReg) &&
212 "Value found while looking through instrs");
215 return ValAndVReg->
Value;
220 bool HandleFConstant) {
223 auto IsConstantOpcode = [HandleFConstant](
unsigned Opcode) {
224 return Opcode == TargetOpcode::G_CONSTANT ||
225 (HandleFConstant && Opcode == TargetOpcode::G_FCONSTANT);
227 auto GetImmediateValue = [HandleFConstant,
231 (!HandleFConstant || !CstVal.
isFPImm()))
239 "Value bitwidth doesn't match definition type");
247 case TargetOpcode::G_TRUNC:
248 case TargetOpcode::G_SEXT:
249 case TargetOpcode::G_ZEXT:
255 case TargetOpcode::COPY:
260 case TargetOpcode::G_INTTOPTR:
267 if (!MI || !IsConstantOpcode(MI->
getOpcode()))
273 APInt &Val = *MaybeVal;
274 while (!SeenOpcodes.
empty()) {
275 std::pair<unsigned, unsigned> OpcodeAndSize = SeenOpcodes.
pop_back_val();
276 switch (OpcodeAndSize.first) {
277 case TargetOpcode::G_TRUNC:
278 Val = Val.
trunc(OpcodeAndSize.second);
280 case TargetOpcode::G_SEXT:
281 Val = Val.
sext(OpcodeAndSize.second);
283 case TargetOpcode::G_ZEXT:
284 Val = Val.
zext(OpcodeAndSize.second);
298 if (TargetOpcode::G_FCONSTANT != MI->
getOpcode())
307 if (!DstTy.isValid())
311 auto SrcTy = MRI.
getType(SrcReg);
312 if (!SrcTy.isValid() || SrcTy != DstTy)
343 if (MaybeOp1Cst && MaybeOp2Cst) {
350 case TargetOpcode::G_ADD:
352 case TargetOpcode::G_AND:
354 case TargetOpcode::G_ASHR:
356 case TargetOpcode::G_LSHR:
358 case TargetOpcode::G_MUL:
360 case TargetOpcode::G_OR:
362 case TargetOpcode::G_SHL:
364 case TargetOpcode::G_SUB:
366 case TargetOpcode::G_XOR:
368 case TargetOpcode::G_UDIV:
369 if (!C2.getBoolValue())
372 case TargetOpcode::G_SDIV:
373 if (!C2.getBoolValue())
376 case TargetOpcode::G_UREM:
377 if (!C2.getBoolValue())
380 case TargetOpcode::G_SREM:
381 if (!C2.getBoolValue())
402 case TargetOpcode::G_FPEXT:
403 case TargetOpcode::G_FPTRUNC:
404 case TargetOpcode::G_FCANONICALIZE:
424 case TargetOpcode::G_SEXT_INREG:
425 return C1.
trunc(Imm).
sext(C1.getBitWidth());
Simple struct used to hold a constant integer value and a virtual register.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
APInt sext(unsigned width) const
Sign extend to a new width.
bool use_nodbg_empty(unsigned RegNo) const
use_nodbg_empty - Return true if there are no non-Debug instructions using the specified register...
unsigned constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const TargetRegisterClass &RegClass, const MachineOperand &RegMO, unsigned OpIdx)
Constrain the Register operand OpIdx, so that it is now constrained to the TargetRegisterClass passed...
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
unsigned getSizeInBits(Register Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
const MachineFunctionProperties & getProperties() const
Get the function properties.
const ConstantFP * getConstantFPVRegVal(unsigned VReg, const MachineRegisterInfo &MRI)
void push_back(const T &Elt)
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Describe properties that are true of each instruction in the target description file.
APInt zext(unsigned width) const
Zero extend to a new width.
APInt udiv(const APInt &RHS) const
Unsigned division operation.
MI-specific kinds of diagnostic Arguments.
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
APInt trunc(unsigned width) const
Truncate to new width.
unsigned const TargetRegisterInfo * TRI
iterator_range< mop_iterator > operands()
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
MachineInstr * getDefIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, folding away any trivial copies.
unsigned getBitWidth() const
Return the number of bits in the APInt.
Holds all the information related to register banks.
const HexagonInstrInfo * TII
const ConstantFP * getFPImm() const
virtual const TargetRegisterClass * getRegClass(const MCInstrDesc &MCID, unsigned OpNum, const TargetRegisterInfo *TRI, const MachineFunction &MF) const
Given a machine instruction descriptor, returns the register class constraint for OpNum...
Optional< APInt > ConstantFoldBinOp(unsigned Opcode, const unsigned Op1, const unsigned Op2, const MachineRegisterInfo &MRI)
unsigned constrainRegToClass(MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, unsigned Reg, const TargetRegisterClass &RegClass)
Try to constrain Reg to the specified register class.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Target-Independent Code Generator Pass Configuration Options.
APFloat getAPFloatFromSize(double Val, unsigned Size)
Returns an APFloat from Val converted to the appropriate size.
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
int64_t getSExtValue() const
Get sign extended value.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
const APInt & getValue() const
Return the constant as an APInt value reference.
bool isFPImm() const
isFPImm - Tests if this is a MO_FPImmediate operand.
void setReg(Register Reg)
Change the register this operand corresponds to.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
TargetInstrInfo - Interface to description of machine instruction set.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned const MachineRegisterInfo * MRI
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
ConstantFP - Floating Point Values [float, double].
bool isCImm() const
isCImm - Test if this is a MO_CImmediate operand.
Represent the analysis usage information of a pass.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
bool isTargetSpecificOpcode(unsigned Opcode)
Check whether the given Opcode is a target-specific opcode.
Optional< ValueAndVReg > getConstantVRegValWithLookThrough(unsigned VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true, bool HandleFConstants=true)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_F/CONSTANT (LookThro...
void getLocation(StringRef &RelativePath, unsigned &Line, unsigned &Column) const
Return location information for this diagnostic in three parts: the relative source file path...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MachineInstr * getOpcodeDef(unsigned Opcode, Register Reg, const MachineRegisterInfo &MRI)
See if Reg is defined by an single def instruction that is Opcode.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
const APFloat & getValueAPF() const
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specific constraint if it is set.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
bool isGlobalISelAbortEnabled() const
Check whether or not GlobalISel should abort on error.
static const fltSemantics & IEEEhalf() LLVM_READNONE
std::string getMsg() const
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
MachineInstrBuilder MachineInstrBuilder & DefMI
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
LLVM_NODISCARD T pop_back_val()
bool constrainSelectedInstRegOperands(MachineInstr &I, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
Mutate the newly-selected instruction I to constrain its (possibly generic) virtual register operands...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Class for arbitrary precision integers.
Optional< int64_t > getConstantVRegVal(unsigned VReg, const MachineRegisterInfo &MRI)
If VReg is defined by a G_CONSTANT fits in int64_t returns it.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineFunctionProperties & set(Property P)
bool isTriviallyDead(const MachineInstr &MI, const MachineRegisterInfo &MRI)
Check whether an instruction MI is dead: it only defines dead virtual registers, and doesn't have oth...
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
LLVM_NODISCARD bool empty() const
Optional< APInt > ConstantFoldExtOp(unsigned Opcode, const unsigned Op1, uint64_t Imm, const MachineRegisterInfo &MRI)
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
APInt srem(const APInt &RHS) const
Function for signed remainder operation.
bool isAllocatable() const
Return true if this register class may be used to create virtual registers.
bool isKnownNeverNaN(const Value *V, const TargetLibraryInfo *TLI, unsigned Depth=0)
Return true if the floating-point scalar value is not a NaN or if the floating-point vector value has...
bool isRegTiedToUseOperand(unsigned DefOpIdx, unsigned *UseOpIdx=nullptr) const
Given the index of a register def operand, check if the register def is tied to a source operand...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isSafeToMove(AAResults *AA, bool &SawStore) const
Return true if it is safe to move this instruction.
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel...
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
virtual const TargetRegisterClass * getConstrainedRegClassForOperand(const MachineOperand &MO, const MachineRegisterInfo &MRI) const
unsigned getOpcode() const
Return the opcode number for this descriptor.
StringRef - Represent a constant reference to a string, i.e.
APInt bitcastToAPInt() const
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
const ConstantInt * getCImm() const
static const TargetRegisterClass * constrainGenericRegister(Register Reg, const TargetRegisterClass &RC, MachineRegisterInfo &MRI)
Constrain the (possibly generic) virtual register Reg to RC.
void reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC, MachineOptimizationRemarkEmitter &MORE, MachineOptimizationRemarkMissed &R)
Report an ISel error as a missed optimization remark to the LLVMContext's diagnostic stream...
bool getFlag(MIFlag Flag) const
Return whether an MI flag is set.
Wrapper class representing virtual and physical registers.
void tieOperands(unsigned DefIdx, unsigned UseIdx)
Add a tie between the register operands at DefIdx and UseIdx.