25#define GET_INSTRINFO_CTOR_DTOR
26#include "LanaiGenInstrInfo.inc"
37 bool RenamableDest,
bool RenamableSrc)
const {
38 if (!Lanai::GPRRegClass.
contains(DestinationRegister, SourceRegister)) {
49 Register SourceRegister,
bool IsKill,
int FrameIndex,
53 if (Position !=
MBB.
end()) {
54 DL = Position->getDebugLoc();
57 if (!Lanai::GPRRegClass.hasSubClassEq(RegisterClass)) {
69 Register DestinationRegister,
int FrameIndex,
73 if (Position !=
MBB.
end()) {
74 DL = Position->getDebugLoc();
77 if (!Lanai::GPRRegClass.hasSubClassEq(RegisterClass)) {
102 int64_t OffsetA = 0, OffsetB = 0;
107 int LowOffset = std::min(OffsetA, OffsetB);
108 int HighOffset = std::max(OffsetA, OffsetB);
109 LocationSize LowWidth = (LowOffset == OffsetA) ? WidthA : WidthB;
111 LowOffset + (int)LowWidth.
getValue() <= HighOffset)
161std::pair<unsigned, unsigned>
163 return std::make_pair(TF, 0u);
168 using namespace LanaiII;
169 static const std::pair<unsigned, const char *> TargetFlags[] = {
170 {MO_ABS_HI,
"lanai-hi"},
171 {MO_ABS_LO,
"lanai-lo"},
172 {MO_NO_FLAG,
"lanai-nf"}};
177 Register &SrcReg2, int64_t &CmpMask,
178 int64_t &CmpValue)
const {
179 switch (
MI.getOpcode()) {
182 case Lanai::SFSUB_F_RI_LO:
183 case Lanai::SFSUB_F_RI_HI:
184 SrcReg =
MI.getOperand(0).getReg();
187 CmpValue =
MI.getOperand(1).getImm();
189 case Lanai::SFSUB_F_RR:
190 SrcReg =
MI.getOperand(0).getReg();
191 SrcReg2 =
MI.getOperand(1).getReg();
205 unsigned SrcReg2, int64_t ImmValue,
207 if (CmpI->
getOpcode() == Lanai::SFSUB_F_RR &&
215 if (((CmpI->
getOpcode() == Lanai::SFSUB_F_RI_LO &&
217 (CmpI->
getOpcode() == Lanai::SFSUB_F_RI_HI &&
227 case Lanai::ADD_I_HI:
228 return Lanai::ADD_F_I_HI;
229 case Lanai::ADD_I_LO:
230 return Lanai::ADD_F_I_LO;
232 return Lanai::ADD_F_R;
233 case Lanai::ADDC_I_HI:
234 return Lanai::ADDC_F_I_HI;
235 case Lanai::ADDC_I_LO:
236 return Lanai::ADDC_F_I_LO;
238 return Lanai::ADDC_F_R;
239 case Lanai::AND_I_HI:
240 return Lanai::AND_F_I_HI;
241 case Lanai::AND_I_LO:
242 return Lanai::AND_F_I_LO;
244 return Lanai::AND_F_R;
246 return Lanai::OR_F_I_HI;
248 return Lanai::OR_F_I_LO;
250 return Lanai::OR_F_R;
252 return Lanai::SL_F_I;
254 return Lanai::SRL_F_R;
256 return Lanai::SA_F_I;
258 return Lanai::SRA_F_R;
259 case Lanai::SUB_I_HI:
260 return Lanai::SUB_F_I_HI;
261 case Lanai::SUB_I_LO:
262 return Lanai::SUB_F_I_LO;
264 return Lanai::SUB_F_R;
265 case Lanai::SUBB_I_HI:
266 return Lanai::SUBB_F_I_HI;
267 case Lanai::SUBB_I_LO:
268 return Lanai::SUBB_F_I_LO;
270 return Lanai::SUBB_F_R;
271 case Lanai::XOR_I_HI:
272 return Lanai::XOR_F_I_HI;
273 case Lanai::XOR_I_LO:
274 return Lanai::XOR_F_I_LO;
276 return Lanai::XOR_F_R;
284 int64_t , int64_t CmpValue,
307 else if (
MI->getParent() != CmpInstr.
getParent() || CmpValue != 0) {
311 if (CmpInstr.
getOpcode() == Lanai::SFSUB_F_RI_LO)
320 for (--
I;
I != E; --
I) {
323 if (Instr.modifiesRegister(Lanai::SR,
TRI) ||
324 Instr.readsRegister(Lanai::SR,
TRI))
355 while (!isSafe && ++
I != E) {
357 for (
unsigned IO = 0, EO = Instr.getNumOperands(); !isSafe && IO != EO;
385 std::make_pair(&((*I).getOperand(IO - 1)), NewCC));
422 if (Succ->isLiveIn(Lanai::SR))
428 MI->addRegisterDefined(Lanai::SR);
438 unsigned &TrueOp,
unsigned &FalseOp,
439 bool &Optimizable)
const {
440 assert(
MI.getOpcode() == Lanai::SELECT &&
"unknown select instruction");
448 Cond.push_back(
MI.getOperand(3));
457 if (!Reg.isVirtual())
459 if (!
MRI.hasOneNonDBGUse(Reg))
465 if (!
MI->isPredicable())
471 if (MO.isFI() || MO.isCPI() || MO.isJTI())
478 if (MO.getReg().isPhysical())
480 if (MO.isDef() && !MO.isDead())
483 bool DontMoveAcrossStores =
true;
484 if (!
MI->isSafeToMove(DontMoveAcrossStores))
493 assert(
MI.getOpcode() == Lanai::SELECT &&
"unknown select instruction");
496 bool Invert = !
DefMI;
506 if (!
MRI.constrainRegClass(DestReg, PreviousClass))
516 i != e && !DefDesc.
operands()[i].isPredicate(); ++i)
519 unsigned CondCode =
MI.getOperand(3).getImm();
563 bool AllowModify)
const {
597 FalseBlock =
nullptr;
614 if (Opcode != Lanai::BRCC)
619 if (Condition.
empty()) {
624 FalseBlock = TrueBlock;
644 "Lanai branch conditions should have one component.");
660 int *BytesAdded)
const {
662 assert(TrueBlock &&
"insertBranch must not be told to insert a fallthrough");
663 assert(!BytesAdded &&
"code size not handled");
666 if (Condition.
empty()) {
667 assert(!FalseBlock &&
"Unconditional branch with multiple successors!");
674 "Lanai branch conditions should have one component.");
675 unsigned ConditionalCode = Condition[0].getImm();
688 int *BytesRemoved)
const {
689 assert(!BytesRemoved &&
"code size not handled");
713 int &FrameIndex)
const {
714 if (
MI.getOpcode() == Lanai::LDW_RI)
715 if (
MI.getOperand(1).isFI() &&
MI.getOperand(2).isImm() &&
716 MI.getOperand(2).getImm() == 0) {
717 FrameIndex =
MI.getOperand(1).getIndex();
718 return MI.getOperand(0).getReg();
724 int &FrameIndex)
const {
725 if (
MI.getOpcode() == Lanai::LDW_RI) {
731 if (hasLoadFromStackSlot(
MI, Accesses)){
733 cast<FixedStackPseudoSourceValue>(Accesses.
front()->getPseudoValue())
742 int &FrameIndex)
const {
743 if (
MI.getOpcode() == Lanai::SW_RI)
744 if (
MI.getOperand(0).isFI() &&
MI.getOperand(1).isImm() &&
745 MI.getOperand(1).getImm() == 0) {
746 FrameIndex =
MI.getOperand(0).getIndex();
747 return MI.getOperand(2).getReg();
787 if (!BaseOp->
isReg())
810 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())
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file defines the SmallVector class.
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
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
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator Position, const DebugLoc &DL, MCRegister DestinationRegister, MCRegister SourceRegister, bool KillSource, bool RenamableDest=false, bool RenamableSrc=false) 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)