29#define DEBUG_TYPE "wasm-reg-coloring"
38 return "WebAssembly Register Coloring";
56char WebAssemblyRegColoring::ID = 0;
58 "Minimize number of registers used",
false,
false)
61 return new WebAssemblyRegColoring();
77 dbgs() <<
"********** Register Coloring **********\n"
78 <<
"********** Function: " << MF.
getName() <<
'\n';
91 &getAnalysis<MachineBlockFrequencyInfo>();
95 unsigned NumVRegs =
MRI->getNumVirtRegs();
97 SortedIntervals.
reserve(NumVRegs);
100 for (
unsigned I = 0;
I < NumVRegs; ++
I) {
105 if (
MRI->use_empty(VReg))
121 if (
MRI->isLiveIn(
LHS->reg()) !=
MRI->isLiveIn(
RHS->reg()))
122 return MRI->isLiveIn(
LHS->reg());
124 return LHS->weight() >
RHS->weight();
126 return !
LHS->empty() &&
RHS->empty();
133 SortedIntervals.
size());
135 bool Changed =
false;
136 for (
size_t I = 0,
E = SortedIntervals.
size();
I <
E; ++
I) {
143 if (!
MRI->isLiveIn(Old))
144 for (
unsigned C : UsedColors.set_bits()) {
145 if (
MRI->getRegClass(SortedIntervals[
C]->reg()) != RC)
148 if (!OtherLI->empty() && OtherLI->overlaps(*LI))
157 Changed |= Old !=
New;
158 UsedColors.set(Color);
159 Assignments[Color].push_back(LI);
170 for (
size_t I = 0,
E = SortedIntervals.
size();
I <
E; ++
I) {
171 Register Old = SortedIntervals[
I]->reg();
174 MRI->replaceRegWith(Old, New);
unsigned const MachineRegisterInfo * MRI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file declares WebAssembly-specific per-machine-function information.
static float computeWeight(const MachineRegisterInfo *MRI, const MachineBlockFrequencyInfo *MBFI, unsigned VReg)
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
Represent the analysis usage information of a pass.
AnalysisUsage & addPreservedID(const void *ID)
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
FunctionPass class - This class is used to implement most global optimizations.
LiveInterval - This class represents the liveness of a register, or stack slot.
void setWeight(float Value)
LiveInterval & getInterval(Register Reg)
static float getSpillWeight(bool isDef, bool isUse, const MachineBlockFrequencyInfo *MBFI, const MachineInstr &MI)
Calculate the spill weight to assign to a single instruction.
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
bool exposesReturnsTwice() const
exposesReturnsTwice - Returns true if the function calls setjmp or any other similar functions with a...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
static unsigned virtReg2Index(Register Reg)
Convert a virtual register number to a 0-based index.
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
void setFrameBaseVreg(unsigned Reg)
bool isVRegStackified(unsigned VReg) const
unsigned getFrameBaseVreg() const
bool isFrameBaseVirtual() const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
void sort(IteratorTy Start, IteratorTy End)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionPass * createWebAssemblyRegColoring()
This struct contains the mappings from the slot numbers to unnamed metadata nodes,...