26 #include "llvm/Config/config.h" 33 #define DEBUG_TYPE "instruction-select" 37 #ifdef LLVM_GISEL_COV_PREFIX 40 cl::desc(
"Record GlobalISel rule coverage files of this " 41 "prefix if instrumentation was generated"));
48 "Select target instructions out of generic instructions",
73 GISelKnownBits &KB = getAnalysis<GISelKnownBitsAnalysis>().
get(MF);
78 assert(ISel &&
"Cannot work without InstructionSelector");
79 ISel->setupMF(MF, KB, CoverageInfo);
95 "instruction is not legal", *
MI);
100 const size_t NumBlocks = MF.
size();
109 bool ReachedBegin =
false;
110 for (
auto MII = std::prev(MBB->end()), Begin = MBB->begin();
114 const auto AfterIt = std::next(MII);
135 if (!ISel->select(MI)) {
144 auto InsertedBegin = ReachedBegin ? MBB->begin() : std::next(MII);
146 for (
auto &InsertedMI :
make_range(InsertedBegin, AfterIt))
147 dbgs() <<
" " << InsertedMI;
158 bool ReachedBegin =
false;
159 for (
auto MII = std::prev(MBB.end()), Begin = MBB.begin(); !ReachedBegin;) {
168 if (MI.
getOpcode() != TargetOpcode::COPY)
176 if (SrcRC == DstRC) {
203 "VReg has no regclass after selection", *MI);
210 MF, TPC, MORE,
"gisel-select",
211 "VReg's low-level type and register class have different sizes", *MI);
216 if (MF.size() != NumBlocks) {
218 MF.getFunction().getSubprogram(),
220 R <<
"inserting blocks is not supported yet";
225 auto &TLI = *MF.getSubtarget().getTargetLowering();
226 TLI.finalizeLowering(MF);
231 for (
const auto &MBB : MF) {
232 if (MFI.
hasCalls() && MF.hasInlineAsm())
235 for (
const auto &
MI : MBB) {
236 if ((
MI.isCall() && !
MI.isReturn()) ||
MI.isStackAligningInlineAsm())
238 if (
MI.isInlineAsm())
239 MF.setHasInlineAsm(
true);
245 dbgs() <<
"Rules covered by selecting function: " << MF.getName() <<
":";
246 for (
auto RuleID : CoverageInfo.
covered())
247 dbgs() <<
" id" << RuleID;
250 CoverageInfo.
emit(CoveragePrefix,
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
void clearVirtRegTypes()
Remove all types associated to virtual registers (after instruction selection and constraining of all...
This class represents lattice values for constants.
void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
const MachineFunctionProperties & getProperties() const
Get the function properties.
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
unsigned const TargetRegisterInfo * TRI
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
bool emit(StringRef FilePrefix, StringRef BackendName) const
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Target-Independent Code Generator Pass Configuration Options.
INITIALIZE_PASS_BEGIN(InstructionSelect, DEBUG_TYPE, "Select target instructions out of generic instructions", false, false) INITIALIZE_PASS_END(InstructionSelect
void eraseFromParentAndMarkDBGValuesForRemoval()
Unlink 'this' from the containing basic block and delete it.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
To use KnownBitsInfo analysis in a pass, KnownBitsInfo &Info = getAnalysis<GISelKnownBitsInfoAnalysis...
initializer< Ty > init(const Ty &Val)
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Represent the analysis usage information of a pass.
use_instr_iterator use_instr_begin(unsigned RegNo) const
virtual InstructionSelector * getInstructionSelector() const
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
bool def_empty(unsigned RegNo) const
def_empty - Return true if there are no instructions defining the specified register (it may be live-...
iterator_range< po_iterator< T > > post_order(const T &G)
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
static const std::string CoveragePrefix
cl::opt< bool > DisableGISelLegalityCheck
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
const MachineInstr * machineFunctionIsIllegal(const MachineFunction &MF)
Checks that MIR is fully legal, returns an illegal instruction if it's not, nullptr otherwise...
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
This pass is responsible for selecting generic machine instructions to target-specific instructions...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool use_empty(unsigned RegNo) const
use_empty - Return true if there are no instructions using the specified register.
def_instr_iterator def_instr_begin(unsigned RegNo) const
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Provides the logic to select generic machine instructions.
bool isTriviallyDead(const MachineInstr &MI, const MachineRegisterInfo &MRI)
Check whether an instruction MI is dead: it only defines dead virtual registers, and doesn't have oth...
Representation of each machine instruction.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
iterator_range< const_covered_iterator > covered() const
const TargetRegisterClass * getRegClassOrNull(unsigned Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool hasProperty(Property P) const
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
inst_range instructions(Function *F)
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.
const MachineOperand & getOperand(unsigned i) const
void reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC, MachineOptimizationRemarkEmitter &MORE, MachineOptimizationRemarkMissed &R)
Report an ISel error as a missed optimization remark to the LLVMContext's diagnostic stream...
Wrapper class representing virtual and physical registers.
This file describes how to lower LLVM code to machine code.
bool hasCalls() const
Return true if the current function has any function calls.