21 #include "llvm/IR/IntrinsicsMips.h" 23 #define DEBUG_TYPE "mips-isel" 29 #define GET_GLOBALISEL_PREDICATE_BITSET 30 #include "MipsGenGlobalISel.inc" 31 #undef GET_GLOBALISEL_PREDICATE_BITSET 59 #define GET_GLOBALISEL_PREDICATES_DECL 60 #include "MipsGenGlobalISel.inc" 61 #undef GET_GLOBALISEL_PREDICATES_DECL 63 #define GET_GLOBALISEL_TEMPORARIES_DECL 64 #include "MipsGenGlobalISel.inc" 65 #undef GET_GLOBALISEL_TEMPORARIES_DECL 70 #define GET_GLOBALISEL_IMPL 71 #include "MipsGenGlobalISel.inc" 72 #undef GET_GLOBALISEL_IMPL 74 MipsInstructionSelector::MipsInstructionSelector(
78 TRI(*STI.getRegisterInfo()), RBI(RBI),
81 #include
"MipsGenGlobalISel.inc" 84 #include
"MipsGenGlobalISel.inc" 89 bool MipsInstructionSelector::isRegInGprb(
Register Reg,
91 return RBI.getRegBank(Reg, MRI,
TRI)->getID() == Mips::GPRBRegBankID;
94 bool MipsInstructionSelector::isRegInFprb(
Register Reg,
96 return RBI.getRegBank(Reg, MRI,
TRI)->getID() == Mips::FPRBRegBankID;
102 if (Register::isPhysicalRegister(DstReg))
106 if (!RBI.constrainGenericRegister(DstReg, *RC, MRI)) {
119 if (isRegInGprb(Reg, MRI)) {
121 "Register class not available for LLT, register bank combination");
122 return &Mips::GPR32RegClass;
125 if (isRegInFprb(Reg, MRI)) {
127 assert((TySize == 32 || TySize == 64) &&
128 "Register class not available for LLT, register bank combination");
130 return &Mips::FGR32RegClass;
131 return STI.isFP64bit() ? &Mips::FGR64RegClass : &Mips::AFGR64RegClass;
138 bool MipsInstructionSelector::materialize32BitImm(
Register DestReg,
APInt Imm,
176 MipsInstructionSelector::selectLoadStoreOpCode(
MachineInstr &I,
183 const bool isStore = Opc == TargetOpcode::G_STORE;
185 if (isRegInGprb(ValueReg, MRI)) {
187 (Ty.
isPointer() && TySize == 32 && MemSizeInBytes == 4)) &&
188 "Unsupported register bank, LLT, MemSizeInBytes combination");
191 switch (MemSizeInBytes) {
203 switch (MemSizeInBytes) {
207 return Opc == TargetOpcode::G_SEXTLOAD ? Mips::LH : Mips::LHu;
209 return Opc == TargetOpcode::G_SEXTLOAD ? Mips::LB : Mips::LBu;
215 if (isRegInFprb(ValueReg, MRI)) {
217 assert(((TySize == 32 && MemSizeInBytes == 4) ||
218 (TySize == 64 && MemSizeInBytes == 8)) &&
219 "Unsupported register bank, LLT, MemSizeInBytes combination");
221 if (MemSizeInBytes == 4)
222 return isStore ? Mips::SWC1 : Mips::LWC1;
225 return isStore ? Mips::SDC164 : Mips::LDC164;
226 return isStore ? Mips::SDC1 : Mips::LDC1;
230 assert(STI.hasMSA() &&
"Vector instructions require target with MSA.");
231 assert((TySize == 128 && MemSizeInBytes == 16) &&
232 "Unsupported register bank, LLT, MemSizeInBytes combination");
235 return isStore ? Mips::ST_B : Mips::LD_B;
237 return isStore ? Mips::ST_H : Mips::LD_H;
239 return isStore ? Mips::ST_W : Mips::LD_W;
241 return isStore ? Mips::ST_D : Mips::LD_D;
283 using namespace TargetOpcode;
291 .addDef(PseudoMULTuReg)
299 .addUse(PseudoMULTuReg);
318 case G_FRAME_INDEX: {
336 "Non-power-of-two jump-table entry size not supported.");
395 if (Register::isPhysicalRegister(DestReg))
396 DefRC =
TRI.getRegClass(DestReg);
398 DefRC = getRegClassForTypeOnBank(DestReg, MRI);
401 return RBI.constrainGenericRegister(DestReg, *DefRC, MRI);
407 const unsigned NewOpc = selectLoadStoreOpCode(I, MRI);
412 int64_t SignedOffset = 0;
435 .addImm(SignedOffset)
449 TII.get(IsSigned ? Mips::PseudoSDIV : Mips::PseudoUDIV))
457 TII.get(IsDiv ? Mips::PseudoMFLO : Mips::PseudoMFHI))
475 case G_IMPLICIT_DEF: {
481 MRI.
setRegClass(Dst, getRegClassForTypeOnBank(Dst, MRI));
501 if (!materialize32BitImm(GPRReg, APImm, B))
513 if (!materialize32BitImm(GPRRegHigh, APImm.
getHiBits(32).
trunc(32),
B))
530 unsigned FABSOpcode =
531 Size == 32 ? Mips::FABS_S
532 : STI.isFP64bit() ? Mips::FABS_D64 : Mips::FABS_D32;
542 assert((ToSize == 32) &&
"Unsupported integer size for G_FPTOSI");
543 assert((FromSize == 32 || FromSize == 64) &&
544 "Unsupported floating point size for G_FPTOSI");
548 Opcode = Mips::TRUNC_W_S;
550 Opcode = STI.isFP64bit() ? Mips::TRUNC_W_D64 : Mips::TRUNC_W_D32;
560 .addUse(ResultInFPR);
567 case G_GLOBAL_VALUE: {
574 .addGlobalAddress(GVal);
585 MachineMemOperand::MOLoad, 4, 4));
633 MachineMemOperand::MOLoad, 4, 4));
647 : Opcode(Opcode),
Def(Def), LHS(LHS), RHS(RHS){};
650 if (Opcode == Mips::SLTiu || Opcode == Mips::XORi)
665 case CmpInst::ICMP_EQ:
667 Instructions.
emplace_back(Mips::SLTiu, ICMPReg, Temp, 1);
669 case CmpInst::ICMP_NE:
671 Instructions.
emplace_back(Mips::SLTu, ICMPReg, Mips::ZERO, Temp);
673 case CmpInst::ICMP_UGT:
674 Instructions.
emplace_back(Mips::SLTu, ICMPReg, RHS, LHS);
676 case CmpInst::ICMP_UGE:
678 Instructions.
emplace_back(Mips::XORi, ICMPReg, Temp, 1);
680 case CmpInst::ICMP_ULT:
681 Instructions.
emplace_back(Mips::SLTu, ICMPReg, LHS, RHS);
683 case CmpInst::ICMP_ULE:
685 Instructions.
emplace_back(Mips::XORi, ICMPReg, Temp, 1);
687 case CmpInst::ICMP_SGT:
688 Instructions.
emplace_back(Mips::SLT, ICMPReg, RHS, LHS);
690 case CmpInst::ICMP_SGE:
692 Instructions.
emplace_back(Mips::XORi, ICMPReg, Temp, 1);
694 case CmpInst::ICMP_SLT:
695 Instructions.
emplace_back(Mips::SLT, ICMPReg, LHS, RHS);
697 case CmpInst::ICMP_SLE:
699 Instructions.
emplace_back(Mips::XORi, ICMPReg, Temp, 1);
706 for (
const struct Instr &
Instruction : Instructions) {
708 Instruction.Opcode, {Instruction.Def}, {Instruction.LHS});
723 unsigned MipsFCMPCondCode;
724 bool isLogicallyNegated;
727 case CmpInst::FCMP_UNO:
728 case CmpInst::FCMP_ORD:
730 isLogicallyNegated = Cond != CmpInst::FCMP_UNO;
732 case CmpInst::FCMP_OEQ:
733 case CmpInst::FCMP_UNE:
735 isLogicallyNegated = Cond != CmpInst::FCMP_OEQ;
737 case CmpInst::FCMP_UEQ:
738 case CmpInst::FCMP_ONE:
740 isLogicallyNegated = Cond != CmpInst::FCMP_UEQ;
742 case CmpInst::FCMP_OLT:
743 case CmpInst::FCMP_UGE:
745 isLogicallyNegated = Cond != CmpInst::FCMP_OLT;
747 case CmpInst::FCMP_ULT:
748 case CmpInst::FCMP_OGE:
750 isLogicallyNegated = Cond != CmpInst::FCMP_ULT;
752 case CmpInst::FCMP_OLE:
753 case CmpInst::FCMP_UGT:
755 isLogicallyNegated = Cond != CmpInst::FCMP_OLE;
757 case CmpInst::FCMP_ULE:
758 case CmpInst::FCMP_OGT:
760 isLogicallyNegated = Cond != CmpInst::FCMP_ULE;
770 unsigned MoveOpcode = isLogicallyNegated ? Mips::MOVT_I : Mips::MOVF_I;
779 unsigned FCMPOpcode =
780 Size == 32 ? Mips::FCMP_S32
781 : STI.isFP64bit() ? Mips::FCMP_D64 : Mips::FCMP_D32;
785 .addImm(MipsFCMPCondCode);
839 return new MipsInstructionSelector(TM, Subtarget, RBI);
unsigned getTargetFlags() const
const MachineInstrBuilder & add(const MachineOperand &MO) const
reference emplace_back(ArgTypes &&... Args)
bool hasLocalLinkage() const
This class represents lattice values for constants.
void setTargetFlags(unsigned F)
#define GET_GLOBALISEL_TEMPORARIES_INIT
int getVarArgsFrameIndex() const
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 DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
const MachineInstrBuilder & addJumpTableIndex(unsigned Idx, unsigned TargetFlags=0) const
static uint64_t selectImpl(uint64_t CandidateMask, uint64_t &NextInSequenceMask)
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
void setIsDead(bool Val=true)
unsigned getBitWidth() const
Return the number of bits in the APInt.
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
const HexagonInstrInfo * TII
const ConstantFP * getFPImm() const
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
static StringRef getName(Value *V)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, unsigned base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
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.
MO_GOT - This flag indicates that a symbol operand represents the address of the GOT entry for the sy...
static bool isStore(int Opcode)
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
This file declares the targeting of the RegisterBankInfo class for Mips.
const APInt & getValue() const
Return the constant as an APInt value reference.
void setReg(Register Reg)
Change the register this operand corresponds to.
void addMemOperand(MachineFunction &MF, MachineMemOperand *MO)
Add a MachineMemOperand to the machine instruction.
bool hasImm(uint64_t TSFlags)
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
InstructionSelector * createMipsInstructionSelector(const MipsTargetMachine &, MipsSubtarget &, MipsRegisterBankInfo &)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
MachineRegisterInfo * getMRI()
Getter for MRI.
MO_GOT_CALL - Represents the offset into the global offset table at which the address of a call site ...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
Register getGlobalBaseRegForGlobalISel()
const GlobalValue * getGlobal() const
Helper class to build MachineInstr.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineInstrBuilder & addFrameIndex(int Idx) const
This class contains a discriminated union of information about pointers in memory operands...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const APFloat & getValueAPF() const
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
static uint64_t add(uint64_t LeftOp, uint64_t RightOp)
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...
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
Promote Memory to Register
This class provides the information for the target register banks.
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...
This file declares the MachineIRBuilder class.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Class for arbitrary precision integers.
unsigned getEntrySize(const DataLayout &TD) const
getEntrySize - Return the size of each entry in the jump table.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Provides the logic to select generic machine instructions.
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool isPositionIndependent() const
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value...
MipsFunctionInfo - This class is derived from MachineFunction private Mips target-specific informatio...
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
#define GET_GLOBALISEL_PREDICATES_INIT
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel...
void setRegClass(unsigned Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
APInt bitcastToAPInt() const
Register getReg() const
getReg - Returns the register number.
static bool selectCopy(MachineInstr &I, const TargetInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
const MachineOperand & getOperand(unsigned i) const
const ConstantInt * getCImm() const
bool constrainAllUses(const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
bool isNullValue() const
Determine if all bits are clear.
Wrapper class representing virtual and physical registers.
unsigned getPredicate() const