34 #define DEBUG_TYPE "legalizer" 40 cl::desc(
"Should enable CSE in Legalizer"),
45 "Legalize the Machine IR a function's Machine IR",
false,
72 case TargetOpcode::G_TRUNC:
73 case TargetOpcode::G_ZEXT:
74 case TargetOpcode::G_ANYEXT:
75 case TargetOpcode::G_SEXT:
76 case TargetOpcode::G_MERGE_VALUES:
77 case TargetOpcode::G_UNMERGE_VALUES:
78 case TargetOpcode::G_CONCAT_VECTORS:
79 case TargetOpcode::G_BUILD_VECTOR:
93 : InstList(Insts), ArtifactList(Arts) {}
136 getAnalysis<GISelCSEAnalysisWrapperPass>().getCSEWrapper();
139 const size_t NumBlocks = MF.
size();
149 for (
auto *MBB : RPOT) {
163 std::unique_ptr<MachineIRBuilder> MIRBuilder;
169 MIRBuilder = make_unique<CSEMIRBuilder>();
170 std::unique_ptr<CSEConfig> Config = make_unique<CSEConfig>();
171 CSEInfo = &Wrapper.get(std::move(Config));
172 MIRBuilder->setCSEInfo(CSEInfo);
174 MIRBuilder = make_unique<MachineIRBuilder>();
176 LegalizerWorkListManager WorkListObserver(InstList, ArtifactList);
180 if (EnableCSE && CSEInfo)
189 auto RemoveDeadInstFromLists = [&WrapperObserver](
MachineInstr *DeadMI) {
192 bool Changed =
false;
194 while (!InstList.
empty()) {
204 auto Res = Helper.legalizeInstrStep(MI);
208 Helper.MIRBuilder.stopObservingChanges();
210 "unable to legalize instruction", MI);
215 while (!ArtifactList.
empty()) {
220 RemoveDeadInstFromLists(&MI);
225 if (ArtCombiner.tryCombineInstruction(MI, DeadInstructions)) {
226 for (
auto *DeadMI : DeadInstructions) {
228 RemoveDeadInstFromLists(DeadMI);
229 DeadMI->eraseFromParentAndMarkDBGValuesForRemoval();
240 }
while (!InstList.
empty());
244 if (MF.
size() != NumBlocks) {
248 R <<
"inserting blocks is not supported yet";
A simple RAII based CSEInfo installer.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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.
The actual analysis pass wrapper.
INITIALIZE_PASS_BEGIN(Legalizer, DEBUG_TYPE, "Legalize the Machine IR a function's Machine IR", false, false) INITIALIZE_PASS_END(Legalizer
void remove(const MachineInstr *I)
Remove I from the worklist if it exists.
CodeGenOpt::Level getOptLevel() const
void erasingInstr(MachineInstr &MI) override
An instruction is about to be erased.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
amdgpu aa AMDGPU Address space based Alias Analysis Wrapper
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Target-Independent Code Generator Pass Configuration Options.
void eraseFromParentAndMarkDBGValuesForRemoval()
Unlink 'this' from the containing basic block and delete it.
COFF::MachineTypes Machine
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
initializer< Ty > init(const Ty &Val)
Abstract class that contains various methods for clients to notify about changes. ...
unsigned const MachineRegisterInfo * MRI
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
DISubprogram * getSubprogram() const
Get the attached subprogram.
This file implements a version of MachineIRBuilder which CSEs insts within a MachineBasicBlock.
Represent the analysis usage information of a pass.
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
Simple wrapper that does the following.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
MachineInstr * pop_back_val()
void insert(MachineInstr *I)
Add the specified instruction to the worklist if it isn't already in it.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
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...
static cl::opt< bool > EnableCSEInLegalizer("enable-cse-in-legalizer", cl::desc("Should enable CSE in Legalizer"), cl::Optional, cl::init(false))
Representation of each machine instruction.
Instruction has been legalized and the MachineFunction changed.
void addObserver(GISelChangeObserver *O)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static bool isArtifact(const MachineInstr &MI)
void initializeLegalizerPass(PassRegistry &)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool hasProperty(Property P) const
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel...
print Print MemDeps of function
Simple wrapper observer that takes several observers, and calls each one for each event...
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...