27#define GET_INSTRINFO_CTOR_DTOR
28#include "LanaiGenInstrInfo.inc"
39 bool KillSource)
const {
40 if (!Lanai::GPRRegClass.
contains(DestinationRegister, SourceRegister)) {
51 Register SourceRegister,
bool IsKill,
int FrameIndex,
55 if (Position !=
MBB.
end()) {
56 DL = Position->getDebugLoc();
59 if (!Lanai::GPRRegClass.hasSubClassEq(RegisterClass)) {
71 Register DestinationRegister,
int FrameIndex,
75 if (Position !=
MBB.
end()) {
76 DL = Position->getDebugLoc();
79 if (!Lanai::GPRRegClass.hasSubClassEq(RegisterClass)) {
104 int64_t OffsetA = 0, OffsetB = 0;
109 int LowOffset = std::min(OffsetA, OffsetB);
110 int HighOffset = std::max(OffsetA, OffsetB);
111 LocationSize LowWidth = (LowOffset == OffsetA) ? WidthA : WidthB;
113 LowOffset + (int)LowWidth.
getValue() <= HighOffset)
163std::pair<unsigned, unsigned>
165 return std::make_pair(TF, 0u);
170 using namespace LanaiII;
171 static const std::pair<unsigned, const char *> TargetFlags[] = {
172 {MO_ABS_HI,
"lanai-hi"},
173 {MO_ABS_LO,
"lanai-lo"},
174 {MO_NO_FLAG,
"lanai-nf"}};
179 Register &SrcReg2, int64_t &CmpMask,
180 int64_t &CmpValue)
const {
181 switch (
MI.getOpcode()) {
184 case Lanai::SFSUB_F_RI_LO:
185 case Lanai::SFSUB_F_RI_HI:
186 SrcReg =
MI.getOperand(0).getReg();
189 CmpValue =
MI.getOperand(1).getImm();
191 case Lanai::SFSUB_F_RR:
192 SrcReg =
MI.getOperand(0).getReg();
193 SrcReg2 =
MI.getOperand(1).getReg();
207 unsigned SrcReg2, int64_t ImmValue,
209 if (CmpI->
getOpcode() == Lanai::SFSUB_F_RR &&
217 if (((CmpI->
getOpcode() == Lanai::SFSUB_F_RI_LO &&
219 (CmpI->
getOpcode() == Lanai::SFSUB_F_RI_HI &&
229 case Lanai::ADD_I_HI:
230 return Lanai::ADD_F_I_HI;
231 case Lanai::ADD_I_LO:
232 return Lanai::ADD_F_I_LO;
234 return Lanai::ADD_F_R;
235 case Lanai::ADDC_I_HI:
236 return Lanai::ADDC_F_I_HI;
237 case Lanai::ADDC_I_LO:
238 return Lanai::ADDC_F_I_LO;
240 return Lanai::ADDC_F_R;
241 case Lanai::AND_I_HI:
242 return Lanai::AND_F_I_HI;
243 case Lanai::AND_I_LO:
244 return Lanai::AND_F_I_LO;
246 return Lanai::AND_F_R;
248 return Lanai::OR_F_I_HI;
250 return Lanai::OR_F_I_LO;
252 return Lanai::OR_F_R;
254 return Lanai::SL_F_I;
256 return Lanai::SRL_F_R;
258 return Lanai::SA_F_I;
260 return Lanai::SRA_F_R;
261 case Lanai::SUB_I_HI:
262 return Lanai::SUB_F_I_HI;
263 case Lanai::SUB_I_LO:
264 return Lanai::SUB_F_I_LO;
266 return Lanai::SUB_F_R;
267 case Lanai::SUBB_I_HI:
268 return Lanai::SUBB_F_I_HI;
269 case Lanai::SUBB_I_LO:
270 return Lanai::SUBB_F_I_LO;
272 return Lanai::SUBB_F_R;
273 case Lanai::XOR_I_HI:
274 return Lanai::XOR_F_I_HI;
275 case Lanai::XOR_I_LO:
276 return Lanai::XOR_F_I_LO;
278 return Lanai::XOR_F_R;
286 int64_t , int64_t CmpValue,
309 else if (
MI->getParent() != CmpInstr.
getParent() || CmpValue != 0) {
313 if (CmpInstr.
getOpcode() == Lanai::SFSUB_F_RI_LO)
322 for (--
I;
I != E; --
I) {
325 if (Instr.modifiesRegister(Lanai::SR,
TRI) ||
326 Instr.readsRegister(Lanai::SR,
TRI))
357 while (!isSafe && ++
I != E) {
359 for (
unsigned IO = 0, EO = Instr.getNumOperands(); !isSafe && IO != EO;
387 std::make_pair(&((*I).getOperand(IO - 1)), NewCC));
424 if (Succ->isLiveIn(Lanai::SR))
430 MI->addRegisterDefined(Lanai::SR);
440 unsigned &TrueOp,
unsigned &FalseOp,
441 bool &Optimizable)
const {
442 assert(
MI.getOpcode() == Lanai::SELECT &&
"unknown select instruction");
450 Cond.push_back(
MI.getOperand(3));
459 if (!Reg.isVirtual())
461 if (!
MRI.hasOneNonDBGUse(Reg))
467 if (!
MI->isPredicable())
473 if (MO.isFI() || MO.isCPI() || MO.isJTI())
480 if (MO.getReg().isPhysical())
482 if (MO.isDef() && !MO.isDead())
485 bool DontMoveAcrossStores =
true;
486 if (!
MI->isSafeToMove(DontMoveAcrossStores))
495 assert(
MI.getOpcode() == Lanai::SELECT &&
"unknown select instruction");
498 bool Invert = !
DefMI;
508 if (!
MRI.constrainRegClass(DestReg, PreviousClass))
518 i != e && !DefDesc.
operands()[i].isPredicate(); ++i)
521 unsigned CondCode =
MI.getOperand(3).getImm();
565 bool AllowModify)
const {
599 FalseBlock =
nullptr;
616 if (Opcode != Lanai::BRCC)
621 if (Condition.
empty()) {
626 FalseBlock = TrueBlock;
646 "Lanai branch conditions should have one component.");
662 int *BytesAdded)
const {
664 assert(TrueBlock &&
"insertBranch must not be told to insert a fallthrough");
665 assert(!BytesAdded &&
"code size not handled");
668 if (Condition.
empty()) {
669 assert(!FalseBlock &&
"Unconditional branch with multiple successors!");
676 "Lanai branch conditions should have one component.");
677 unsigned ConditionalCode = Condition[0].getImm();
690 int *BytesRemoved)
const {
691 assert(!BytesRemoved &&
"code size not handled");
715 int &FrameIndex)
const {
716 if (
MI.getOpcode() == Lanai::LDW_RI)
717 if (
MI.getOperand(1).isFI() &&
MI.getOperand(2).isImm() &&
718 MI.getOperand(2).getImm() == 0) {
719 FrameIndex =
MI.getOperand(1).getIndex();
720 return MI.getOperand(0).getReg();
726 int &FrameIndex)
const {
727 if (
MI.getOpcode() == Lanai::LDW_RI) {
733 if (hasLoadFromStackSlot(
MI, Accesses)){
735 cast<FixedStackPseudoSourceValue>(Accesses.
front()->getPseudoValue())
744 int &FrameIndex)
const {
745 if (
MI.getOpcode() == Lanai::SW_RI)
746 if (
MI.getOperand(0).isFI() &&
MI.getOperand(1).isImm() &&
747 MI.getOperand(1).getImm() == 0) {
748 FrameIndex =
MI.getOperand(0).getIndex();
749 return MI.getOperand(2).getReg();
789 if (!BaseOp->
isReg())
812 OffsetIsScalable =
false;
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder MachineInstrBuilder & DefMI
static bool isRedundantFlagInstr(const MachineInstr *CmpI, Register SrcReg, Register SrcReg2, int64_t ImmValue, const MachineInstr *OI, bool &IsThumb1)
isRedundantFlagInstr - check whether the first instruction, whose only purpose is to update flags,...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static LPCC::CondCode getOppositeCondition(LPCC::CondCode CC)
static unsigned flagSettingOpcodeVariant(unsigned OldOpcode)
static MachineInstr * canFoldIntoSelect(Register Reg, const MachineRegisterInfo &MRI)
unsigned const TargetRegisterInfo * TRI
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
bool areMemAccessesTriviallyDisjoint(const MachineInstr &MIa, const MachineInstr &MIb) const override
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TrueBlock, MachineBasicBlock *FalseBlock, ArrayRef< MachineOperand > Condition, const DebugLoc &DL, int *BytesAdded=nullptr) const override
Register isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
bool analyzeSelect(const MachineInstr &MI, SmallVectorImpl< MachineOperand > &Cond, unsigned &TrueOp, unsigned &FalseOp, bool &Optimizable) const override
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator Position, const DebugLoc &DL, MCRegister DestinationRegister, MCRegister SourceRegister, bool KillSource) const override
Register isLoadFromStackSlotPostFE(const MachineInstr &MI, int &FrameIndex) const override
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TrueBlock, MachineBasicBlock *&FalseBlock, SmallVectorImpl< MachineOperand > &Condition, bool AllowModify) const override
virtual const LanaiRegisterInfo & getRegisterInfo() const
MachineInstr * optimizeSelect(MachineInstr &MI, SmallPtrSetImpl< MachineInstr * > &SeenMIs, bool PreferFalse) const override
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator Position, Register DestinationRegister, int FrameIndex, const TargetRegisterClass *RegisterClass, const TargetRegisterInfo *RegisterInfo, Register VReg) const override
bool expandPostRAPseudo(MachineInstr &MI) const override
bool getMemOperandWithOffsetWidth(const MachineInstr &LdSt, const MachineOperand *&BaseOp, int64_t &Offset, LocationSize &Width, const TargetRegisterInfo *TRI) const
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
bool optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg, Register SrcReg2, int64_t CmpMask, int64_t CmpValue, const MachineRegisterInfo *MRI) const override
bool analyzeCompare(const MachineInstr &MI, Register &SrcReg, Register &SrcReg2, int64_t &CmpMask, int64_t &CmpValue) const override
Register isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
bool getMemOperandsWithOffsetWidth(const MachineInstr &LdSt, SmallVectorImpl< const MachineOperand * > &BaseOps, int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width, const TargetRegisterInfo *TRI) const override
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Condition) const override
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator Position, Register SourceRegister, bool IsKill, int FrameIndex, const TargetRegisterClass *RegisterClass, const TargetRegisterInfo *RegisterInfo, Register VReg) const override
TypeSize getValue() const
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
ArrayRef< MCOperandInfo > operands() const
Wrapper class representing physical registers. Should be passed by value.
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
iterator_range< succ_iterator > successors()
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & copyImplicitOps(const MachineInstr &OtherMI) const
Copy all the implicit operands from OtherMI onto this one.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool mayLoadOrStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read or modify memory.
const MachineBasicBlock * getParent() const
unsigned getNumOperands() const
Retuns the total number of operands.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore,...
void tieOperands(unsigned DefIdx, unsigned UseIdx)
Add a tie between the register operands at DefIdx and UseIdx.
bool hasOrderedMemoryRef() const
Return true if this instruction may have an ordered or volatile memory reference, or if the informati...
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const MachineOperand & getOperand(unsigned i) const
void clearKillInfo()
Clears kill flags on all operands.
MachineOperand class - Representation of each machine instruction operand.
void setImplicit(bool Val=true)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isRegMask() const
isRegMask - Tests if this is a MO_RegisterMask operand.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
static MachineOperand CreateImm(int64_t Val)
Register getReg() const
getReg - Returns the register number.
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.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Wrapper class representing virtual and physical registers.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
bool erase(PtrType Ptr)
Remove pointer from the set.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Value * getOperand(unsigned i) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
unsigned getKillRegState(bool B)