28 #define DEBUG_TYPE "legalizer"
34 "Legalize the Machine IR a function's Machine IR",
false,
56 if (MI.
getOpcode() != TargetOpcode::G_UNMERGE_VALUES)
62 if (MergeI.
getOpcode() != TargetOpcode::G_MERGE_VALUES)
67 if (NumMergeRegs < NumDefs) {
68 if (NumDefs % NumMergeRegs != 0)
79 const unsigned NewNumDefs = NumDefs / NumMergeRegs;
80 for (
unsigned Idx = 0; Idx < NumMergeRegs; ++Idx) {
82 for (
unsigned j = 0, DefIdx = Idx * NewNumDefs; j < NewNumDefs;
89 }
else if (NumMergeRegs > NumDefs) {
90 if (NumMergeRegs % NumDefs != 0)
101 const unsigned NumRegs = NumMergeRegs / NumDefs;
102 for (
unsigned DefIdx = 0; DefIdx < NumDefs; ++DefIdx) {
104 for (
unsigned j = 0, Idx = NumRegs * DefIdx + 1; j < NumRegs; ++j, ++Idx)
117 for (
unsigned Idx = 0; Idx < NumDefs; ++Idx)
144 bool Changed =
false;
146 for (
auto &MBB : MF) {
147 for (
auto MI = MBB.begin();
MI != MBB.end();
MI = NextMI) {
150 NextMI = std::next(
MI);
156 unsigned NumNewInsns = 0;
169 bool Changed =
false;
180 "unable to legalize instruction",
190 DEBUG(
dbgs() <<
".. .. Emitted " << NumNewInsns <<
" insns\n");
191 for (
auto I = WorkList.
end() - NumNewInsns,
E = WorkList.
end();
197 }
while (Idx < WorkList.
size());
205 for (
auto &MBB : MF) {
206 for (
auto MI = MBB.begin();
MI != MBB.end();
MI = NextMI) {
209 NextMI = std::next(
MI);
void push_back(const T &Elt)
MachineIRBuilder MIRBuilder
Expose MIRBuilder so clients can set their own RecordInsertInstruction functions. ...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLT getType(unsigned VReg) const
Get the low-level type of VReg or LLT{} if VReg is not a generic (target independent) virtual registe...
bool hasProperty(Property P) const
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Legalize the Machine IR a function s Machine false
const MachineFunctionProperties & getProperties() const
Get the function properties.
Target-Independent Code Generator Pass Configuration Options.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
INITIALIZE_PASS_BEGIN(Legalizer, DEBUG_TYPE,"Legalize the Machine IR a function's Machine IR", false, false) INITIALIZE_PASS_END(Legalizer
void recordInsertions(std::function< void(MachineInstr *)> InsertedInstr)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
TargetInstrInfo - Interface to description of machine instruction set.
unsigned const MachineRegisterInfo * MRI
LegalizeResult legalizeInstrStep(MachineInstr &MI)
Replace MI by a sequence of legal instructions that can implement the same operation.
const MachineOperand & getOperand(unsigned i) const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Helper class to build MachineInstr.
Represent the analysis usage information of a pass.
void setInstr(MachineInstr &MI)
Set the insertion point to before MI.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Some kind of error has occurred and we could not legalize this instruction.
Legalize the Machine IR a function s Machine IR
void stopRecordingInsertions()
bool combineMerges(MachineInstr &MI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, MachineIRBuilder &MIRBuilder)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel...
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.
Representation of each machine instruction.
Instruction has been legalized and the MachineFunction changed.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
def_instr_iterator def_instr_begin(unsigned RegNo) const
void initializeLegalizerPass(PassRegistry &)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
MachineInstrBuilder buildUnmerge(ArrayRef< unsigned > Res, unsigned Op)
Build and insert Res0<def>, ...
unsigned getReg() const
getReg - Returns the register number.
print Print MemDeps of function
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineInstrBuilder buildMerge(unsigned Res, ArrayRef< unsigned > Ops)
Build and insert Res<def> = G_MERGE_VALUES Op0, ...
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...
bool use_empty(unsigned RegNo) const
use_empty - Return true if there are no instructions using the specified register.