21 #define DEBUG_TYPE "arm-isel"
27 #ifndef LLVM_BUILD_GLOBAL_ISEL
28 #error "You shouldn't build this"
33 #define GET_GLOBALISEL_PREDICATE_BITSET
34 #include "ARMGenGlobalISel.inc"
35 #undef GET_GLOBALISEL_PREDICATE_BITSET
56 bool insertComparison(CmpConstants Helper, InsertInfo I,
unsigned ResReg,
58 unsigned PrevRes)
const;
61 void putConstant(InsertInfo I,
unsigned DestReg,
unsigned Constant)
const;
68 unsigned ExpectedSize,
unsigned ExpectedRegBankID)
const;
72 unsigned ExpectedRegBankID)
const;
80 #define GET_GLOBALISEL_PREDICATES_DECL
81 #include "ARMGenGlobalISel.inc"
82 #undef GET_GLOBALISEL_PREDICATES_DECL
86 #define GET_GLOBALISEL_TEMPORARIES_DECL
87 #include "ARMGenGlobalISel.inc"
88 #undef GET_GLOBALISEL_TEMPORARIES_DECL
97 return new ARMInstructionSelector(TM, STI, RBI);
103 #define GET_GLOBALISEL_IMPL
104 #include "ARMGenGlobalISel.inc"
105 #undef GET_GLOBALISEL_IMPL
111 TRI(*STI.getRegisterInfo()), TM(TM), RBI(RBI), STI(STI),
113 #include
"ARMGenGlobalISel.inc"
116 #include
"ARMGenGlobalISel.inc"
125 if (TargetRegisterInfo::isPhysicalRegister(DstReg))
130 assert(RegBank &&
"Can't get reg bank for virtual register");
134 RegBank->
getID() == ARM::FPRRegBankID) &&
135 "Unsupported reg bank");
139 if (RegBank->
getID() == ARM::FPRRegBankID) {
141 RC = &ARM::SPRRegClass;
142 else if (DstSize == 64)
143 RC = &ARM::DPRRegClass;
172 "Unsupported operand for G_MERGE_VALUES");
177 "Unsupported operand for G_MERGE_VALUES");
182 "Unsupported operand for G_MERGE_VALUES");
203 "Unsupported operand for G_UNMERGE_VALUES");
208 "Unsupported operand for G_UNMERGE_VALUES");
213 "Unsupported operand for G_UNMERGE_VALUES");
226 using namespace TargetOpcode;
228 if (Size != 8 && Size != 16)
245 bool isStore = Opc == TargetOpcode::G_STORE;
247 if (RegBank == ARM::GPRRegBankID) {
251 return isStore ? ARM::STRBi12 : ARM::LDRBi12;
253 return isStore ? ARM::STRH : ARM::LDRH;
255 return isStore ? ARM::STRi12 : ARM::LDRi12;
261 if (RegBank == ARM::FPRRegBankID) {
264 return isStore ? ARM::VSTRS : ARM::VLDRS;
266 return isStore ? ARM::VSTRD : ARM::VLDRD;
278 static std::pair<ARMCC::CondCodes, ARMCC::CondCodes>
282 case CmpInst::FCMP_ONE:
285 case CmpInst::FCMP_UEQ:
288 case CmpInst::ICMP_EQ:
289 case CmpInst::FCMP_OEQ:
292 case CmpInst::ICMP_SGT:
293 case CmpInst::FCMP_OGT:
296 case CmpInst::ICMP_SGE:
297 case CmpInst::FCMP_OGE:
300 case CmpInst::ICMP_UGT:
301 case CmpInst::FCMP_UGT:
304 case CmpInst::FCMP_OLT:
307 case CmpInst::ICMP_ULE:
308 case CmpInst::FCMP_OLE:
311 case CmpInst::FCMP_ORD:
314 case CmpInst::FCMP_UNO:
317 case CmpInst::FCMP_UGE:
320 case CmpInst::ICMP_SLT:
321 case CmpInst::FCMP_ULT:
324 case CmpInst::ICMP_SLE:
325 case CmpInst::FCMP_ULE:
328 case CmpInst::FCMP_UNE:
329 case CmpInst::ICMP_NE:
332 case CmpInst::ICMP_UGE:
335 case CmpInst::ICMP_ULT:
346 CmpConstants(
unsigned CmpOpcode,
unsigned FlagsOpcode,
unsigned OpRegBank,
368 DbgLoc(MIB->getDebugLoc()) {}
375 void ARMInstructionSelector::putConstant(
InsertInfo I,
unsigned DestReg,
385 unsigned LHSReg,
unsigned RHSReg,
386 unsigned ExpectedSize,
387 unsigned ExpectedRegBankID)
const {
389 validReg(MRI, LHSReg, ExpectedSize, ExpectedRegBankID) &&
390 validReg(MRI, RHSReg, ExpectedSize, ExpectedRegBankID);
394 unsigned ExpectedSize,
395 unsigned ExpectedRegBankID)
const {
397 DEBUG(
dbgs() <<
"Unexpected size for register");
402 DEBUG(
dbgs() <<
"Unexpected register bank for register");
409 bool ARMInstructionSelector::selectCmp(CmpConstants Helper,
412 const InsertInfo
I(MIB);
415 if (!validReg(MRI, ResReg, 1, ARM::GPRRegBankID))
420 if (Cond == CmpInst::FCMP_TRUE || Cond == CmpInst::FCMP_FALSE) {
421 putConstant(I, ResReg, Cond == CmpInst::FCMP_TRUE ? 1 : 0);
428 if (!validOpRegPair(MRI, LHSReg, RHSReg, Helper.OperandSize,
429 Helper.OperandRegBankID))
434 putConstant(I, ZeroReg, 0);
438 if (!insertComparison(Helper, I, ResReg, ARMConds.first, LHSReg, RHSReg,
444 if (!insertComparison(Helper, I, IntermediateRes, ARMConds.first, LHSReg,
447 if (!insertComparison(Helper, I, ResReg, ARMConds.second, LHSReg, RHSReg,
456 bool ARMInstructionSelector::insertComparison(CmpConstants Helper, InsertInfo I,
459 unsigned LHSReg,
unsigned RHSReg,
460 unsigned PrevRes)
const {
463 BuildMI(I.MBB, I.InsertBefore, I.DbgLoc, TII.
get(Helper.ComparisonOpcode))
467 if (!constrainSelectedInstRegOperands(*CmpI, TII, TRI, RBI))
471 if (Helper.ReadFlagsOpcode != ARM::INSTRUCTION_LIST_END) {
472 auto ReadI =
BuildMI(I.MBB, I.InsertBefore, I.DbgLoc,
473 TII.
get(Helper.ReadFlagsOpcode))
475 if (!constrainSelectedInstRegOperands(*ReadI, TII, TRI, RBI))
480 auto Mov1I =
BuildMI(I.MBB, I.InsertBefore, I.DbgLoc, TII.
get(ARM::MOVCCi))
485 if (!constrainSelectedInstRegOperands(*Mov1I, TII, TRI, RBI))
499 assert(validReg(MRI, CondReg, 1, ARM::GPRRegBankID) &&
500 "Unsupported types for select operation");
501 auto CmpI =
BuildMI(MBB, InsertBefore, DbgLoc, TII.
get(ARM::CMPri))
505 if (!constrainSelectedInstRegOperands(*CmpI, TII, TRI, RBI))
513 assert(validOpRegPair(MRI, ResReg, TrueReg, 32, ARM::GPRRegBankID) &&
514 validOpRegPair(MRI, TrueReg, FalseReg, 32, ARM::GPRRegBankID) &&
515 "Unsupported types for select operation");
516 auto Mov1I =
BuildMI(MBB, InsertBefore, DbgLoc, TII.
get(ARM::MOVCCr))
521 if (!constrainSelectedInstRegOperands(*Mov1I, TII, TRI, RBI))
528 bool ARMInstructionSelector::select(
MachineInstr &I)
const {
534 auto &MRI = MF.getRegInfo();
549 using namespace TargetOpcode;
558 DEBUG(
dbgs() <<
"Unsupported destination size for extension");
585 if (!constrainSelectedInstRegOperands(*SubI, TII, TRI, RBI))
600 DEBUG(
dbgs() <<
"Unsupported source size for extension");
612 const auto &SrcRegBank = *RBI.
getRegBank(SrcReg, MRI, TRI);
613 const auto &DstRegBank = *RBI.
getRegBank(DstReg, MRI, TRI);
615 if (SrcRegBank.getID() != DstRegBank.getID()) {
616 DEBUG(
dbgs() <<
"G_TRUNC/G_ANYEXT operands on different register banks\n");
620 if (SrcRegBank.getID() != ARM::GPRRegBankID) {
621 DEBUG(
dbgs() <<
"G_TRUNC/G_ANYEXT on non-GPR not supported yet\n");
629 return selectSelect(MIB, MRI);
631 CmpConstants Helper(ARM::CMPrr, ARM::INSTRUCTION_LIST_END,
632 ARM::GPRRegBankID, 32);
633 return selectCmp(Helper, MIB, MRI);
636 assert(TII.getSubtarget().hasVFP2() &&
"Can't select fcmp without VFP");
641 if (Size == 64 && TII.getSubtarget().isFPOnlySP()) {
642 DEBUG(
dbgs() <<
"Subtarget only supports single precision");
645 if (Size != 32 && Size != 64) {
646 DEBUG(
dbgs() <<
"Unsupported size for G_FCMP operand");
650 CmpConstants Helper(Size == 32 ? ARM::VCMPS : ARM::VCMPD,
ARM::FMSTAT,
651 ARM::FPRRegBankID, Size);
652 return selectCmp(Helper, MIB, MRI);
667 if (!validReg(MRI, Reg, 32, ARM::GPRRegBankID))
675 if (Val.getCImm()->getBitWidth() > 32)
689 if (MemOp.getOrdering() != AtomicOrdering::NotAtomic) {
690 DEBUG(
dbgs() <<
"Atomic load/store not supported yet\n");
700 assert((ValSize != 64 || TII.getSubtarget().hasVFP2()) &&
701 "Don't know how to load/store 64-bit value without VFP");
704 if (NewOpc == G_LOAD || NewOpc == G_STORE)
709 if (NewOpc == ARM::LDRH || NewOpc == ARM::STRH)
715 case G_MERGE_VALUES: {
720 case G_UNMERGE_VALUES: {
727 DEBUG(
dbgs() <<
"Unsupported condition register for G_BRCOND");
736 if (!constrainSelectedInstRegOperands(*Test, TII, TRI, RBI))
743 if (!constrainSelectedInstRegOperands(*
Branch, TII, TRI, RBI))
752 return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
InsertInfo(MachineInstrBuilder &MIB)
LLT getType(unsigned VReg) const
Get the low-level type of VReg or LLT{} if VReg is not a generic (target independent) virtual registe...
static bool selectMergeValues(MachineInstrBuilder &MIB, const ARMBaseInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
const MachineInstrBuilder & add(const MachineOperand &MO) const
#define GET_GLOBALISEL_PREDICATES_INIT
InstructionSelector * createARMInstructionSelector(const ARMBaseTargetMachine &TM, const ARMSubtarget &STI, const ARMRegisterBankInfo &RBI)
const unsigned ReadFlagsOpcode
Holds all the information related to register banks.
const HexagonInstrInfo * TII
CmpConstants(unsigned CmpOpcode, unsigned FlagsOpcode, unsigned OpRegBank, unsigned OpSize)
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
StringRef getName(unsigned Opcode) const
Returns the name for the instructions with the given opcode.
Reg
All possible values of the reg field in the ModR/M byte.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
static std::array< MachineOperand, 2 > predOps(ARMCC::CondCodes Pred, unsigned PredReg=0)
Get the operands corresponding to the given Pred value.
This class provides the information for the target register banks.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
static std::pair< ARMCC::CondCodes, ARMCC::CondCodes > getComparePreds(CmpInst::Predicate Pred)
void ChangeToImmediate(int64_t ImmVal)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value...
const MachineBasicBlock * getParent() const
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
This file declares the targeting of the RegisterBankInfo class for ARM.
This is an important base class in LLVM.
const MachineOperand & getOperand(unsigned i) const
unsigned getID() const
Get the identifier of this register bank.
static unsigned selectLoadStoreOpCode(unsigned Opc, unsigned RegBank, unsigned Size)
Select the opcode for simple loads and stores.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
static bool selectUnmergeValues(MachineInstrBuilder &MIB, const ARMBaseInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
self_iterator getIterator()
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
unsigned getPredicate() const
This class implements the register bank concept.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel...
const unsigned OperandRegBankID
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
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.
static MachineOperand condCodeOp(unsigned CCReg=0)
Get the operand corresponding to the conditional code result.
void setReg(unsigned Reg)
Change the register this operand corresponds to.
static const TargetRegisterClass * constrainGenericRegister(unsigned Reg, const TargetRegisterClass &RC, MachineRegisterInfo &MRI)
Constrain the (possibly generic) virtual register Reg to RC.
#define GET_GLOBALISEL_TEMPORARIES_INIT
const unsigned ComparisonOpcode
const unsigned OperandSize
Instructions::iterator instr_iterator
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MachineInstrBuilder & addUse(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
static const Function * getParent(const Value *V)
const MachineBasicBlock::instr_iterator InsertBefore
const ARMSubtarget & getSubtarget() const
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
static unsigned selectSimpleExtOpc(unsigned Opc, unsigned Size)
Select the opcode for simple extensions (that translate to a single SXT/UXT instruction).
static bool selectCopy(MachineInstr &I, const TargetInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.