26#define GET_INSTRINFO_CTOR_DTOR
27#include "LanaiGenInstrInfo.inc"
37 Register SourceRegister,
bool KillSource,
38 bool RenamableDest,
bool RenamableSrc)
const {
39 if (!Lanai::GPRRegClass.
contains(DestinationRegister, SourceRegister)) {
50 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,
76 if (Position !=
MBB.end()) {
77 DL = Position->getDebugLoc();
80 if (!Lanai::GPRRegClass.hasSubClassEq(RegisterClass)) {
105 int64_t OffsetA = 0, OffsetB = 0;
111 int LowOffset = std::min(OffsetA, OffsetB);
112 int HighOffset = std::max(OffsetA, OffsetB);
113 LocationSize LowWidth = (LowOffset == OffsetA) ? WidthA : WidthB;
115 LowOffset + (
int)LowWidth.
getValue() <= HighOffset)
165std::pair<unsigned, unsigned>
167 return std::make_pair(TF, 0u);
173 static const std::pair<unsigned, const char *> TargetFlags[] = {
174 {MO_ABS_HI,
"lanai-hi"},
175 {MO_ABS_LO,
"lanai-lo"},
176 {MO_NO_FLAG,
"lanai-nf"}};
181 Register &SrcReg2, int64_t &CmpMask,
182 int64_t &CmpValue)
const {
183 switch (
MI.getOpcode()) {
186 case Lanai::SFSUB_F_RI_LO:
187 case Lanai::SFSUB_F_RI_HI:
188 SrcReg =
MI.getOperand(0).getReg();
191 CmpValue =
MI.getOperand(1).getImm();
193 case Lanai::SFSUB_F_RR:
194 SrcReg =
MI.getOperand(0).getReg();
195 SrcReg2 =
MI.getOperand(1).getReg();
209 unsigned SrcReg2, int64_t ImmValue,
211 if (CmpI->
getOpcode() == Lanai::SFSUB_F_RR &&
219 if (((CmpI->
getOpcode() == Lanai::SFSUB_F_RI_LO &&
221 (CmpI->
getOpcode() == Lanai::SFSUB_F_RI_HI &&
231 case Lanai::ADD_I_HI:
232 return Lanai::ADD_F_I_HI;
233 case Lanai::ADD_I_LO:
234 return Lanai::ADD_F_I_LO;
236 return Lanai::ADD_F_R;
237 case Lanai::ADDC_I_HI:
238 return Lanai::ADDC_F_I_HI;
239 case Lanai::ADDC_I_LO:
240 return Lanai::ADDC_F_I_LO;
242 return Lanai::ADDC_F_R;
243 case Lanai::AND_I_HI:
244 return Lanai::AND_F_I_HI;
245 case Lanai::AND_I_LO:
246 return Lanai::AND_F_I_LO;
248 return Lanai::AND_F_R;
250 return Lanai::OR_F_I_HI;
252 return Lanai::OR_F_I_LO;
254 return Lanai::OR_F_R;
256 return Lanai::SL_F_I;
258 return Lanai::SRL_F_R;
260 return Lanai::SA_F_I;
262 return Lanai::SRA_F_R;
263 case Lanai::SUB_I_HI:
264 return Lanai::SUB_F_I_HI;
265 case Lanai::SUB_I_LO:
266 return Lanai::SUB_F_I_LO;
268 return Lanai::SUB_F_R;
269 case Lanai::SUBB_I_HI:
270 return Lanai::SUBB_F_I_HI;
271 case Lanai::SUBB_I_LO:
272 return Lanai::SUBB_F_I_LO;
274 return Lanai::SUBB_F_R;
275 case Lanai::XOR_I_HI:
276 return Lanai::XOR_F_I_HI;
277 case Lanai::XOR_I_LO:
278 return Lanai::XOR_F_I_LO;
280 return Lanai::XOR_F_R;
288 int64_t , int64_t CmpValue,
311 else if (
MI->getParent() != CmpInstr.
getParent() || CmpValue != 0) {
315 if (CmpInstr.
getOpcode() == Lanai::SFSUB_F_RI_LO)
324 for (--
I;
I != E; --
I) {
327 if (Instr.modifiesRegister(Lanai::SR,
TRI) ||
328 Instr.readsRegister(Lanai::SR,
TRI))
359 while (!isSafe && ++
I != E) {
361 for (
unsigned IO = 0, EO = Instr.getNumOperands(); !isSafe && IO != EO;
386 if (SrcReg2 != 0 &&
Sub->getOperand(1).getReg() == SrcReg2 &&
387 Sub->getOperand(2).getReg() == SrcReg) {
389 std::make_pair(&((*I).getOperand(IO - 1)), NewCC));
426 if (Succ->isLiveIn(Lanai::SR))
432 MI->addRegisterDefined(Lanai::SR);
442 unsigned &TrueOp,
unsigned &FalseOp,
443 bool &Optimizable)
const {
444 assert(
MI.getOpcode() == Lanai::SELECT &&
"unknown select instruction");
452 Cond.push_back(
MI.getOperand(3));
461 if (!
Reg.isVirtual())
463 if (!
MRI.hasOneNonDBGUse(
Reg))
469 if (!
MI->isPredicable())
475 if (MO.isFI() || MO.isCPI() || MO.isJTI())
482 if (MO.getReg().isPhysical())
484 if (MO.isDef() && !MO.isDead())
487 bool DontMoveAcrossStores =
true;
488 if (!
MI->isSafeToMove(DontMoveAcrossStores))
497 assert(
MI.getOpcode() == Lanai::SELECT &&
"unknown select instruction");
500 bool Invert = !
DefMI;
510 if (!
MRI.constrainRegClass(DestReg, PreviousClass))
520 i != e && !DefDesc.
operands()[i].isPredicate(); ++i)
523 unsigned CondCode =
MI.getOperand(3).getImm();
545 if (
DefMI->getParent() !=
MI.getParent())
549 DefMI->eraseFromParent();
567 bool AllowModify)
const {
601 FalseBlock =
nullptr;
618 if (Opcode != Lanai::BRCC)
623 if (Condition.
empty()) {
628 FalseBlock = TrueBlock;
648 "Lanai branch conditions should have one component.");
664 int *BytesAdded)
const {
666 assert(TrueBlock &&
"insertBranch must not be told to insert a fallthrough");
667 assert(!BytesAdded &&
"code size not handled");
670 if (Condition.
empty()) {
671 assert(!FalseBlock &&
"Unconditional branch with multiple successors!");
678 "Lanai branch conditions should have one component.");
679 unsigned ConditionalCode = Condition[0].getImm();
692 int *BytesRemoved)
const {
693 assert(!BytesRemoved &&
"code size not handled");
717 int &FrameIndex)
const {
718 if (
MI.getOpcode() == Lanai::LDW_RI)
719 if (
MI.getOperand(1).isFI() &&
MI.getOperand(2).isImm() &&
720 MI.getOperand(2).getImm() == 0) {
721 FrameIndex =
MI.getOperand(1).getIndex();
722 return MI.getOperand(0).getReg();
728 int &FrameIndex)
const {
729 if (
MI.getOpcode() == Lanai::LDW_RI) {
746 int &FrameIndex)
const {
747 if (
MI.getOpcode() == Lanai::SW_RI)
748 if (
MI.getOperand(0).isFI() &&
MI.getOperand(1).isImm() &&
749 MI.getOperand(1).getImm() == 0) {
750 FrameIndex =
MI.getOperand(0).getIndex();
751 return MI.getOperand(2).getReg();
791 if (!BaseOp->
isReg())
814 OffsetIsScalable =
false;
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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")
DXIL Forward Handle Accesses
static LPCC::CondCode getOppositeCondition(LPCC::CondCode CC)
static unsigned flagSettingOpcodeVariant(unsigned OldOpcode)
static MachineInstr * canFoldIntoSelect(Register Reg, const MachineRegisterInfo &MRI)
Register const TargetRegisterInfo * TRI
Promote Memory to Register
const SmallVectorImpl< MachineOperand > & Cond
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.
LLVM_ABI 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 loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator Position, Register DestinationRegister, int FrameIndex, const TargetRegisterClass *RegisterClass, const TargetRegisterInfo *RegisterInfo, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) 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
bool expandPostRAPseudo(MachineInstr &MI) const override
LanaiInstrInfo(const LanaiSubtarget &STI)
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
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator Position, Register SourceRegister, bool IsKill, int FrameIndex, const TargetRegisterClass *RegisterClass, const TargetRegisterInfo *RegisterInfo, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Condition) const override
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator Position, const DebugLoc &DL, Register DestinationRegister, Register SourceRegister, bool KillSource, bool RenamableDest=false, bool RenamableSrc=false) const override
static LocationSize precise(uint64_t Value)
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
MachineInstrBundleIterator< MachineInstr > iterator
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.
LLVM_ABI bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore,...
LLVM_ABI void tieOperands(unsigned DefIdx, unsigned UseIdx)
Add a tie between the register operands at DefIdx and UseIdx.
LLVM_ABI bool hasOrderedMemoryRef() const
Return true if this instruction may have an ordered or volatile memory reference, or if the informati...
LLVM_ABI void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI 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.
LLVM_ABI 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.
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
FunctionAddr VTableAddr Count
@ Sub
Subtraction of integers.
unsigned getKillRegState(bool B)
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.