23 #define DEBUG_TYPE "arm-isel" 29 #define GET_GLOBALISEL_PREDICATE_BITSET 30 #include "ARMGenGlobalISel.inc" 31 #undef GET_GLOBALISEL_PREDICATE_BITSET 53 bool insertComparison(CmpConstants Helper, InsertInfo I,
unsigned ResReg,
55 unsigned PrevRes)
const;
58 void putConstant(InsertInfo I,
unsigned DestReg,
unsigned Constant)
const;
67 unsigned ExpectedSize,
unsigned ExpectedRegBankID)
const;
71 unsigned ExpectedRegBankID)
const;
79 #define GET_GLOBALISEL_PREDICATES_DECL 80 #include "ARMGenGlobalISel.inc" 81 #undef GET_GLOBALISEL_PREDICATES_DECL 85 #define GET_GLOBALISEL_TEMPORARIES_DECL 86 #include "ARMGenGlobalISel.inc" 87 #undef GET_GLOBALISEL_TEMPORARIES_DECL 96 return new ARMInstructionSelector(TM, STI, RBI);
102 #define GET_GLOBALISEL_IMPL 103 #include "ARMGenGlobalISel.inc" 104 #undef GET_GLOBALISEL_IMPL 110 TRI(*STI.getRegisterInfo()), TM(TM), RBI(RBI), STI(STI),
112 #include
"ARMGenGlobalISel.inc" 115 #include
"ARMGenGlobalISel.inc" 125 assert(RegBank &&
"Can't get reg bank for virtual register");
129 RegBank->
getID() == ARM::FPRRegBankID) &&
130 "Unsupported reg bank");
132 if (RegBank->
getID() == ARM::FPRRegBankID) {
134 return &ARM::SPRRegClass;
136 return &ARM::DPRRegClass;
137 else if (Size == 128)
138 return &ARM::QPRRegClass;
143 return &ARM::GPRRegClass;
150 if (TargetRegisterInfo::isPhysicalRegister(DstReg))
179 "Unsupported operand for G_MERGE_VALUES");
184 "Unsupported operand for G_MERGE_VALUES");
189 "Unsupported operand for G_MERGE_VALUES");
210 "Unsupported operand for G_UNMERGE_VALUES");
215 "Unsupported operand for G_UNMERGE_VALUES");
220 "Unsupported operand for G_UNMERGE_VALUES");
233 using namespace TargetOpcode;
235 if (Size != 8 && Size != 16)
252 bool isStore = Opc == TargetOpcode::G_STORE;
254 if (RegBank == ARM::GPRRegBankID) {
258 return isStore ? ARM::STRBi12 : ARM::LDRBi12;
260 return isStore ? ARM::STRH : ARM::LDRH;
262 return isStore ? ARM::STRi12 : ARM::LDRi12;
268 if (RegBank == ARM::FPRRegBankID) {
271 return isStore ? ARM::VSTRS : ARM::VLDRS;
273 return isStore ? ARM::VSTRD : ARM::VLDRD;
285 static std::pair<ARMCC::CondCodes, ARMCC::CondCodes>
289 case CmpInst::FCMP_ONE:
292 case CmpInst::FCMP_UEQ:
295 case CmpInst::ICMP_EQ:
296 case CmpInst::FCMP_OEQ:
299 case CmpInst::ICMP_SGT:
300 case CmpInst::FCMP_OGT:
303 case CmpInst::ICMP_SGE:
304 case CmpInst::FCMP_OGE:
307 case CmpInst::ICMP_UGT:
308 case CmpInst::FCMP_UGT:
311 case CmpInst::FCMP_OLT:
314 case CmpInst::ICMP_ULE:
315 case CmpInst::FCMP_OLE:
318 case CmpInst::FCMP_ORD:
321 case CmpInst::FCMP_UNO:
324 case CmpInst::FCMP_UGE:
327 case CmpInst::ICMP_SLT:
328 case CmpInst::FCMP_ULT:
331 case CmpInst::ICMP_SLE:
332 case CmpInst::FCMP_ULE:
335 case CmpInst::FCMP_UNE:
336 case CmpInst::ICMP_NE:
339 case CmpInst::ICMP_UGE:
342 case CmpInst::ICMP_ULT:
348 assert(Preds.first != ARMCC::AL &&
"No comparisons needed?");
353 CmpConstants(
unsigned CmpOpcode,
unsigned FlagsOpcode,
unsigned OpRegBank,
355 : ComparisonOpcode(CmpOpcode), ReadFlagsOpcode(FlagsOpcode),
356 OperandRegBankID(OpRegBank), OperandSize(OpSize) {}
374 : MBB(*MIB->
getParent()), InsertBefore(
std::next(MIB->getIterator())),
375 DbgLoc(MIB->getDebugLoc()) {}
382 void ARMInstructionSelector::putConstant(
InsertInfo I,
unsigned DestReg,
392 unsigned LHSReg,
unsigned RHSReg,
393 unsigned ExpectedSize,
394 unsigned ExpectedRegBankID)
const {
396 validReg(MRI, LHSReg, ExpectedSize, ExpectedRegBankID) &&
397 validReg(MRI, RHSReg, ExpectedSize, ExpectedRegBankID);
401 unsigned ExpectedSize,
402 unsigned ExpectedRegBankID)
const {
416 bool ARMInstructionSelector::selectCmp(
CmpConstants Helper,
422 if (!validReg(MRI, ResReg, 1, ARM::GPRRegBankID))
427 if (Cond == CmpInst::FCMP_TRUE || Cond == CmpInst::FCMP_FALSE) {
428 putConstant(I, ResReg, Cond == CmpInst::FCMP_TRUE ? 1 : 0);
435 if (!validOpRegPair(MRI, LHSReg, RHSReg, Helper.
OperandSize,
441 putConstant(I, ZeroReg, 0);
445 if (!insertComparison(Helper, I, ResReg, ARMConds.first, LHSReg, RHSReg,
451 if (!insertComparison(Helper, I, IntermediateRes, ARMConds.first, LHSReg,
454 if (!insertComparison(Helper, I, ResReg, ARMConds.second, LHSReg, RHSReg,
466 unsigned LHSReg,
unsigned RHSReg,
467 unsigned PrevRes)
const {
500 if ((STI.isROPI() || STI.isRWPI()) && !STI.isTargetELF()) {
506 if (GV->isThreadLocal()) {
514 bool UseMovt = STI.useMovt(MF);
516 unsigned Size =
TM.getPointerSize(0);
517 unsigned Alignment = 4;
519 auto addOpsForConstantPoolLoad = [&MF, Alignment,
522 assert(MIB->getOpcode() == ARM::LDRi12 &&
"Unsupported instruction");
523 auto ConstPool = MF.getConstantPool();
528 ? ConstPool->getConstantPoolIndex(
529 ARMConstantPoolConstant::Create(GV,
ARMCP::SBREL), Alignment)
530 : ConstPool->getConstantPoolIndex(GV, Alignment);
531 MIB.addConstantPoolIndex(CPIndex, 0, 0)
533 MF.getMachineMemOperand(MachinePointerInfo::getConstantPool(MF),
534 MachineMemOperand::MOLoad, Size, Alignment))
539 if (
TM.isPositionIndependent()) {
540 bool Indirect = STI.isGVIndirectSymbol(GV);
544 UseMovt && !STI.isTargetELF()
545 ? (Indirect ? ARM::MOV_ga_pcrel_ldr : ARM::MOV_ga_pcrel)
546 : (Indirect ? ARM::LDRLIT_ga_pcrel_ldr : ARM::LDRLIT_ga_pcrel);
547 MIB->setDesc(
TII.get(Opc));
550 if (STI.isTargetDarwin())
552 if (STI.isGVInGOT(GV))
554 MIB->getOperand(1).setTargetFlags(TargetFlags);
557 MIB.addMemOperand(MF.getMachineMemOperand(
558 MachinePointerInfo::getGOT(MF), MachineMemOperand::MOLoad,
559 TM.getProgramPointerSize(), Alignment));
564 bool isReadOnly = STI.getTargetLowering()->isReadOnly(GV);
565 if (STI.isROPI() && isReadOnly) {
566 unsigned Opc = UseMovt ? ARM::MOV_ga_pcrel : ARM::LDRLIT_ga_pcrel;
567 MIB->setDesc(
TII.get(Opc));
570 if (STI.isRWPI() && !isReadOnly) {
574 OffsetMIB =
BuildMI(MBB, *MIB, MIB->getDebugLoc(),
581 addOpsForConstantPoolLoad(OffsetMIB, GV,
true);
587 MIB->setDesc(
TII.get(ARM::ADDrr));
588 MIB->RemoveOperand(1);
597 if (STI.isTargetELF()) {
599 MIB->setDesc(
TII.get(ARM::MOVi32imm));
602 MIB->setDesc(
TII.get(ARM::LDRi12));
603 MIB->RemoveOperand(1);
604 addOpsForConstantPoolLoad(MIB, GV,
false);
606 }
else if (STI.isTargetMachO()) {
608 MIB->setDesc(
TII.get(ARM::MOVi32imm));
610 MIB->setDesc(
TII.get(ARM::LDRLIT_ga_abs));
627 assert(validReg(MRI, CondReg, 1, ARM::GPRRegBankID) &&
628 "Unsupported types for select operation");
629 auto CmpI =
BuildMI(MBB, InsertBefore, DbgLoc,
TII.get(ARM::CMPri))
641 assert(validOpRegPair(MRI, ResReg, TrueReg, 32, ARM::GPRRegBankID) &&
642 validOpRegPair(MRI, TrueReg, FalseReg, 32, ARM::GPRRegBankID) &&
643 "Unsupported types for select operation");
644 auto Mov1I =
BuildMI(MBB, InsertBefore, DbgLoc,
TII.get(ARM::MOVCCr))
656 bool ARMInstructionSelector::selectShift(
unsigned ShiftOpc,
671 auto &MRI = MF.getRegInfo();
680 using namespace TargetOpcode;
682 if (selectImpl(I, CoverageInfo))
688 switch (I.getOpcode()) {
693 LLT DstTy = MRI.
getType(I.getOperand(0).getReg());
696 LLVM_DEBUG(
dbgs() <<
"Unsupported destination size for extension");
700 LLT SrcTy = MRI.
getType(I.getOperand(1).getReg());
705 I.setDesc(
TII.get(ARM::ANDri));
709 unsigned SExtResult = I.getOperand(0).getReg();
713 I.getOperand(0).setReg(AndResult);
715 auto InsertBefore = std::next(I.getIterator());
717 BuildMI(MBB, InsertBefore, I.getDebugLoc(),
TII.get(ARM::RSBri))
731 if (NewOpc == I.getOpcode())
733 I.setDesc(
TII.get(NewOpc));
747 auto SrcReg = I.getOperand(1).getReg();
748 auto DstReg = I.getOperand(0).getReg();
750 const auto &SrcRegBank = *RBI.
getRegBank(SrcReg, MRI, TRI);
751 const auto &DstRegBank = *RBI.
getRegBank(DstReg, MRI, TRI);
753 if (SrcRegBank.getID() == ARM::FPRRegBankID) {
757 assert(I.getOpcode() == G_TRUNC &&
"Unsupported operand for G_ANYEXT");
758 assert(DstRegBank.getID() == ARM::GPRRegBankID &&
759 "Unsupported combination of register banks");
764 auto InsertBefore = std::next(I.getIterator());
778 if (SrcRegBank.getID() != DstRegBank.getID()) {
780 dbgs() <<
"G_TRUNC/G_ANYEXT operands on different register banks\n");
784 if (SrcRegBank.getID() != ARM::GPRRegBankID) {
785 LLVM_DEBUG(
dbgs() <<
"G_TRUNC/G_ANYEXT on non-GPR not supported yet\n");
789 I.setDesc(
TII.get(COPY));
793 if (!MRI.
getType(I.getOperand(0).getReg()).isPointer()) {
799 auto &Val = I.getOperand(1);
801 if (!Val.getCImm()->isZero()) {
805 Val.ChangeToImmediate(0);
807 assert(Val.isImm() &&
"Unexpected operand for G_CONSTANT");
808 if (Val.getImm() != 0) {
814 I.setDesc(
TII.get(ARM::MOVi));
820 auto SrcReg = I.getOperand(1).getReg();
821 auto DstReg = I.getOperand(0).getReg();
823 const auto &SrcRegBank = *RBI.
getRegBank(SrcReg, MRI, TRI);
824 const auto &DstRegBank = *RBI.
getRegBank(DstReg, MRI, TRI);
826 if (SrcRegBank.getID() != DstRegBank.getID()) {
829 <<
"G_INTTOPTR/G_PTRTOINT operands on different register banks\n");
833 if (SrcRegBank.getID() != ARM::GPRRegBankID) {
835 dbgs() <<
"G_INTTOPTR/G_PTRTOINT on non-GPR not supported yet\n");
839 I.setDesc(
TII.get(COPY));
843 return selectSelect(MIB, MRI);
845 CmpConstants Helper(ARM::CMPrr, ARM::INSTRUCTION_LIST_END,
846 ARM::GPRRegBankID, 32);
847 return selectCmp(Helper, MIB, MRI);
850 assert(STI.hasVFP2() &&
"Can't select fcmp without VFP");
852 unsigned OpReg = I.getOperand(2).getReg();
855 if (Size == 64 && STI.isFPOnlySP()) {
859 if (Size != 32 && Size != 64) {
865 ARM::FPRRegBankID, Size);
866 return selectCmp(Helper, MIB, MRI);
876 I.setDesc(
TII.get(ARM::ADDrr));
882 I.setDesc(
TII.get(ARM::ADDri));
886 return selectGlobal(MIB, MRI);
889 const auto &MemOp = **I.memoperands_begin();
890 if (MemOp.getOrdering() != AtomicOrdering::NotAtomic) {
895 unsigned Reg = I.getOperand(0).getReg();
901 assert((ValSize != 64 || STI.hasVFP2()) &&
902 "Don't know how to load/store 64-bit value without VFP");
905 if (NewOpc == G_LOAD || NewOpc == G_STORE)
908 I.setDesc(
TII.get(NewOpc));
910 if (NewOpc == ARM::LDRH || NewOpc == ARM::STRH)
916 case G_MERGE_VALUES: {
921 case G_UNMERGE_VALUES: {
927 if (!validReg(MRI, I.getOperand(0).getReg(), 1, ARM::GPRRegBankID)) {
928 LLVM_DEBUG(
dbgs() <<
"Unsupported condition register for G_BRCOND");
933 auto Test =
BuildMI(*I.getParent(),
I, I.getDebugLoc(),
TII.get(ARM::TSTri))
934 .addReg(I.getOperand(0).getReg())
942 .
add(I.getOperand(1))
950 I.setDesc(
TII.get(PHI));
952 unsigned DstReg = I.getOperand(0).getReg();
const MachineInstrBuilder & add(const MachineOperand &MO) const
InsertInfo(MachineInstrBuilder &MIB)
static bool selectMergeValues(MachineInstrBuilder &MIB, const ARMBaseInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
Compute iterated dominance frontiers using a linear time algorithm.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
unsigned getReg() const
getReg - Returns the register number.
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
#define GET_GLOBALISEL_PREDICATES_INIT
unsigned const TargetRegisterInfo * TRI
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned char TargetFlags=0) const
InstructionSelector * createARMInstructionSelector(const ARMBaseTargetMachine &TM, const ARMSubtarget &STI, const ARMRegisterBankInfo &RBI)
const unsigned ReadFlagsOpcode
Holds all the information related to register banks.
MO_SBREL - On a symbol operand, this represents a static base relative relocation.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
const HexagonInstrInfo * TII
CmpConstants(unsigned CmpOpcode, unsigned FlagsOpcode, unsigned OpRegBank, unsigned OpSize)
const MachineInstrBuilder & addUse(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
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.
static std::array< MachineOperand, 2 > predOps(ARMCC::CondCodes Pred, unsigned PredReg=0)
Get the operands corresponding to the given Pred 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)
This class provides the information for the target register banks.
const ARMSubtarget & getSubtarget() const
static std::pair< ARMCC::CondCodes, ARMCC::CondCodes > getComparePreds(CmpInst::Predicate Pred)
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 GlobalValue * getGlobal() const
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...
StringRef getName(unsigned Opcode) const
Returns the name for the instructions with the given opcode.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static bool selectCopy(MachineInstr &I, const TargetInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
Iterator for intrusive lists based on ilist_node.
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 getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
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 class implements the register bank concept.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const unsigned OperandRegBankID
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Section Relative (Windows TLS)
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.
static MachineOperand condCodeOp(unsigned CCReg=0)
Get the operand corresponding to the conditional code result.
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
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
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...
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static const Function * getParent(const Value *V)
MO_NONLAZY - This is an independent flag, on a symbol operand "FOO" it represents a symbol which...
const MachineBasicBlock::instr_iterator InsertBefore
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
const MachineInstrBuilder & addDef(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
static unsigned selectSimpleExtOpc(unsigned Opc, unsigned Size)
Select the opcode for simple extensions (that translate to a single SXT/UXT instruction).
const MachineOperand & getOperand(unsigned i) const
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
unsigned getID() const
Get the identifier of this register bank.
unsigned getPredicate() const