29 #define GEN_CHECK_COMPRESS_INSTR 30 #include "RISCVGenCompressInstEmitter.inc" 32 #define GET_INSTRINFO_CTOR_DTOR 33 #include "RISCVGenInstrInfo.inc" 92 if (RISCV::GPRRegClass.
contains(DstReg, SrcReg)) {
93 BuildMI(MBB, MBBI, DL,
get(RISCV::ADDI), DstReg)
101 if (RISCV::FPR32RegClass.
contains(DstReg, SrcReg))
102 Opc = RISCV::FSGNJ_S;
103 else if (RISCV::FPR64RegClass.
contains(DstReg, SrcReg))
104 Opc = RISCV::FSGNJ_D;
108 BuildMI(MBB, MBBI, DL,
get(Opc), DstReg)
115 unsigned SrcReg,
bool IsKill,
int FI,
120 DL = I->getDebugLoc();
124 if (RISCV::GPRRegClass.hasSubClassEq(RC))
126 RISCV::SW : RISCV::SD;
127 else if (RISCV::FPR32RegClass.hasSubClassEq(RC))
129 else if (RISCV::FPR64RegClass.hasSubClassEq(RC))
134 BuildMI(MBB, I, DL,
get(Opcode))
142 unsigned DstReg,
int FI,
147 DL = I->getDebugLoc();
151 if (RISCV::GPRRegClass.hasSubClassEq(RC))
154 else if (RISCV::FPR32RegClass.hasSubClassEq(RC))
156 else if (RISCV::FPR64RegClass.hasSubClassEq(RC))
185 if (++Num == Seq.size())
188 if (Inst.Opc == RISCV::LUI) {
189 BuildMI(MBB, MBBI, DL,
get(RISCV::LUI), Result)
193 BuildMI(MBB, MBBI, DL,
get(Inst.Opc), Result)
210 "Unknown conditional branch");
240 bool AllowModify)
const {
246 if (I == MBB.
end() || !isUnpredicatedTerminator(*I))
252 int NumTerminators = 0;
253 for (
auto J = I.
getReverse(); J != MBB.
rend() && isUnpredicatedTerminator(*J);
256 if (J->getDesc().isUnconditionalBranch() ||
257 J->getDesc().isIndirectBranch()) {
264 if (AllowModify && FirstUncondOrIndirectBr != MBB.
end()) {
265 while (std::next(FirstUncondOrIndirectBr) != MBB.
end()) {
266 std::next(FirstUncondOrIndirectBr)->eraseFromParent();
269 I = FirstUncondOrIndirectBr;
273 if (I->getDesc().isIndirectBranch())
277 if (NumTerminators > 2)
281 if (NumTerminators == 1 && I->getDesc().isUnconditionalBranch()) {
282 TBB = I->getOperand(0).getMBB();
287 if (NumTerminators == 1 && I->getDesc().isConditionalBranch()) {
293 if (NumTerminators == 2 && std::prev(I)->
getDesc().isConditionalBranch() &&
294 I->getDesc().isUnconditionalBranch()) {
296 FBB = I->getOperand(0).getMBB();
305 int *BytesRemoved)
const {
312 if (!I->getDesc().isUnconditionalBranch() &&
313 !I->getDesc().isConditionalBranch())
319 I->eraseFromParent();
323 if (I == MBB.
begin())
326 if (!I->getDesc().isConditionalBranch())
332 I->eraseFromParent();
345 assert(TBB &&
"InsertBranch must not be told to insert a fallthrough");
347 "RISCV branch conditions have two components!");
358 unsigned Opc = Cond[0].getImm();
380 assert(RS &&
"RegScavenger required for long branching");
382 "new block should be inserted for expanding unconditional branch");
389 if (
TM.isPositionIndependent())
394 "Branch offsets outside of the signed 32-bit range not supported");
404 BuildMI(MBB, II, DL,
get(RISCV::PseudoBRIND))
419 assert((Cond.
size() == 3) &&
"Invalid branch condition!");
433 int64_t BrOffset)
const {
446 return isIntN(13, BrOffset);
448 case RISCV::PseudoBR:
449 return isIntN(21, BrOffset);
459 const auto MF = MI.
getMF();
464 if (isCompressibleInst(MI, &ST, MRI, STI))
467 return get(Opcode).getSize();
470 case TargetOpcode::IMPLICIT_DEF:
472 case TargetOpcode::DBG_VALUE:
474 case RISCV::PseudoCALLReg:
475 case RISCV::PseudoCALL:
476 case RISCV::PseudoTAIL:
477 case RISCV::PseudoLLA:
478 case RISCV::PseudoLA:
479 case RISCV::PseudoLA_TLS_IE:
480 case RISCV::PseudoLA_TLS_GD:
511 unsigned OpType = OI.value().OperandType;
516 int64_t Imm = MO.
getImm();
528 Ok = isUInt<12>(Imm);
534 Ok = isShiftedInt<12, 1>(Imm);
537 Ok = isUInt<20>(Imm);
540 Ok = isShiftedInt<20, 1>(Imm);
543 if (
STI.getTargetTriple().isArch64Bit())
550 ErrInfo =
"Invalid immediate";
601 int64_t OffsetA = 0, OffsetB = 0;
602 unsigned int WidthA = 0, WidthB = 0;
606 int LowOffset = std::min(OffsetA, OffsetB);
607 int HighOffset =
std::max(OffsetA, OffsetB);
608 int LowWidth = (LowOffset == OffsetA) ? WidthA : WidthB;
609 if (LowOffset + LowWidth <= HighOffset)
616 std::pair<unsigned, unsigned>
619 return std::make_pair(TF & Mask, TF & ~Mask);
624 using namespace RISCVII;
625 static const std::pair<unsigned, const char *> TargetFlags[] = {
658 unsigned &Flags)
const {
669 std::vector<outliner::Candidate> &RepeatedSequenceLocs)
const {
681 RepeatedSequenceLocs.erase(
std::remove_if(RepeatedSequenceLocs.begin(),
682 RepeatedSequenceLocs.end(),
684 RepeatedSequenceLocs.end());
687 if (RepeatedSequenceLocs.size() < 2)
690 unsigned SequenceSize = 0;
692 auto I = RepeatedSequenceLocs[0].front();
693 auto E = std::next(RepeatedSequenceLocs[0].back());
698 unsigned CallOverhead = 8;
699 for (
auto &
C : RepeatedSequenceLocs)
703 unsigned FrameOverhead = 4;
704 if (RepeatedSequenceLocs[0].getMF()->getSubtarget()
705 .getFeatureBits()[RISCV::FeatureStdExtC])
714 unsigned Flags)
const {
749 for (
const auto &MO : MI.
operands())
750 if (MO.isMBB() || MO.isBlockAddress() || MO.isCPI())
771 for (;
I !=
E; ++
I) {
772 if (
I->isCFIInstruction()) {
773 I->removeFromParent();
void movImm(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, Register DstReg, uint64_t Val, MachineInstr::MIFlag Flag=MachineInstr::NoFlags) const
const MachineInstrBuilder & add(const MachineOperand &MO) const
Wrapper class representing physical registers. Should be passed by value.
MachineBasicBlock * getMBB() const
const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
virtual MachineBasicBlock::iterator insertOutlinedCall(Module &M, MachineBasicBlock &MBB, MachineBasicBlock::iterator &It, MachineFunction &MF, const outliner::Candidate &C) const override
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
bool isCFIInstruction() const
void push_back(const T &Elt)
bool getMemOperandWithOffsetWidth(const MachineInstr &LdSt, const MachineOperand *&BaseOp, int64_t &Offset, unsigned &Width, const TargetRegisterInfo *TRI) const
Describe properties that are true of each instruction in the target description file.
const RISCVRegisterInfo * getRegisterInfo() const override
bool mayLoadOrStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read or modify memory.
virtual bool isMBBSafeToOutlineFrom(MachineBasicBlock &MBB, unsigned &Flags) const override
unsigned const TargetRegisterInfo * TRI
bool isMetaInstruction() const
Return true if this instruction doesn't produce any output in the form of executable instructions...
iterator_range< mop_iterator > operands()
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
An individual sequence of instructions to be replaced with a call to an outlined function.
void clearVirtRegs()
clearVirtRegs - Remove all virtual registers (after physreg assignment).
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &dl, int *BytesAdded=nullptr) const override
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
return AArch64::GPR64RegClass contains(Reg)
bool isBranch() const
Returns true if this is a conditional, unconditional, or indirect branch.
virtual void buildOutlinedFrame(MachineBasicBlock &MBB, MachineFunction &MF, const outliner::OutlinedFunction &OF) const override
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned SrcReg, bool IsKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
unsigned isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const char * getSymbolName() const
INLINEASM - Represents an inline asm block.
void setRegUsed(Register Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Tell the scavenger a register is used.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
bool available(MCPhysReg Reg) const
Returns true if no part of physical register Reg is live.
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
reverse_iterator getReverse() const
Get a reverse iterator to the same node.
iterator getLastNonDebugInstr()
Returns an iterator to the last non-debug instruction in the basic block, or end().
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
unsigned getKillRegState(bool B)
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
bool isAsCheapAsAMove(const MachineInstr &MI) const override
outliner::OutlinedFunction getOutliningCandidateInfo(std::vector< outliner::Candidate > &RepeatedSequenceLocs) const override
Flag
These should be considered private to the implementation of the MCInstrDesc class.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
bool isReturn(QueryType Type=AnyInBundle) const
bool isIdenticalTo(const MachineOperand &Other) const
Returns true if this operand is identical to the specified operand except for liveness related flags ...
bool verifyInstruction(const MachineInstr &MI, StringRef &ErrInfo) const override
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
bool hasLinkOnceODRLinkage() const
This file declares the machine register scavenger class.
unsigned const MachineRegisterInfo * MRI
InstrType
Represents how an instruction should be mapped by the outliner.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
This instruction implements an extending load to FP stack slots.
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
bool isConditionalBranch() const
Return true if this is a branch which may fall through to the next instruction or may transfer contro...
The information necessary to create an outlined function for some class of candidate.
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, MCRegister DstReg, MCRegister SrcReg, bool KillSrc) const override
Interface to description of machine instruction set.
bool hasOneMemOperand() const
Return true if this instruction has exactly one MachineMemOperand.
MCInstrDesc const & getDesc(MCInstrInfo const &MCII, MCInst const &MCI)
self_iterator getIterator()
RISCVInstrInfo(RISCVSubtarget &STI)
virtual outliner::InstrType getOutliningType(MachineBasicBlock::iterator &MBBI, unsigned Flags) const override
On a symbol operand, this represents the hi part.
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
const MachineInstrBuilder & addFrameIndex(int Idx) const
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
unsigned isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
constexpr bool isInt< 32 >(int64_t x)
Align max(MaybeAlign Lhs, Align Rhs)
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
static unsigned getOppositeBranchOpcode(int Opc)
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
MachineOperand class - Representation of each machine instruction operand.
bool hasSection() const
Check if this global has a custom object file section.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool modifiesRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr modifies (fully define or partially define) the specified register...
bool hasOrderedMemoryRef() const
Return true if this instruction may have an ordered or volatile memory reference, or if the informati...
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
void enterBasicBlockEnd(MachineBasicBlock &MBB)
Start tracking liveness from the end of basic block MBB.
unsigned pred_size() const
const Function & getFunction() const
Return the LLVM function that this machine code represents.
const RISCVSubtarget & STI
Target - Wrapper for Target specific information.
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
On a symbol operand, this represents the lo part.
Register scavengeRegisterBackwards(const TargetRegisterClass &RC, MachineBasicBlock::iterator To, bool RestoreAfter, int SPAdj, bool AllowSpill=true)
Make a register of the specific register class available from the current position backwards to the p...
MO_TPREL_HI/LO - Represents the hi and low part of the offset from.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
unsigned insertIndirectBranch(MachineBasicBlock &MBB, MachineBasicBlock &NewDestBB, const DebugLoc &DL, int64_t BrOffset, RegScavenger *RS=nullptr) const override
MachineBasicBlock * getBranchDestBlock(const MachineInstr &MI) const override
void generateInstSeq(int64_t Val, bool IsRV64, InstSeq &Res)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
bool areMemAccessesTriviallyDisjoint(const MachineInstr &MIa, const MachineInstr &MIb) const override
static MachineOperand CreateImm(int64_t Val)
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
Generic base class for all target subtargets.
iterator_range< const_opInfo_iterator > operands() const
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
A set of register units used to track register liveness.
bool isBranchOffsetInRange(unsigned BranchOpc, int64_t BrOffset) const override
bool isReg() const
isReg - Tests if this is a MO_Register operand.
static void parseCondBranch(MachineInstr &LastInst, MachineBasicBlock *&Target, SmallVectorImpl< MachineOperand > &Cond)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
INLINEASM_BR - Terminator version of inline asm. Used by asm-goto.
const RISCVInstrInfo * getInstrInfo() const override
MachineOutlinerConstructionID
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore...
StringRef - Represent a constant reference to a string, i.e.
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
Register getReg() const
getReg - Returns the register number.
bool hasImplicitDefOfPhysReg(unsigned Reg, const MCRegisterInfo *MRI=nullptr) const
Return true if this instruction implicitly defines the specified physical register.
const MachineOperand & getOperand(unsigned i) const
On a symbol operand "FOO", this indicates that the reference is actually to "FOO@plt".
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
static bool is64Bit(const char *name)
The operation is expected to be selectable directly by the target, and no transformation is necessary...
virtual bool isFunctionSafeToOutlineFrom(MachineFunction &MF, bool OutlineFromLinkOnceODRs) const override
bool isAsCheapAsAMove(QueryType Type=AllInBundle) const
Returns true if this instruction has the same cost (or less) than a move instruction.
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned DstReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
Wrapper class representing virtual and physical registers.
bool empty() const
empty - Check if the array is empty.
detail::enumerator< R > enumerate(R &&TheRange)
Given an input range, returns a new range whose values are are pair (A,B) such that A is the 0-based ...