29 #define DEBUG_TYPE "wasm-reg-coloring" 38 return "WebAssembly Register Coloring";
58 "Minimize number of registers used",
false,
false)
61 return new WebAssemblyRegColoring();
75 bool WebAssemblyRegColoring::runOnMachineFunction(
MachineFunction &MF) {
77 dbgs() <<
"********** Register Coloring **********\n" 78 <<
"********** Function: " << MF.
getName() <<
'\n';
91 &getAnalysis<MachineBlockFrequencyInfo>();
97 SortedIntervals.
reserve(NumVRegs);
100 for (
unsigned I = 0;
I < NumVRegs; ++
I) {
102 if (MFI.isVRegStackified(VReg))
133 SortedIntervals.
size());
135 bool Changed =
false;
136 for (
size_t I = 0,
E = SortedIntervals.
size();
I <
E; ++
I) {
138 unsigned Old = LI->
reg;
144 for (
unsigned C : UsedColors.set_bits()) {
148 if (!OtherLI->empty() && OtherLI->overlaps(*LI))
155 unsigned New = SortedIntervals[
Color]->reg;
157 Changed |= Old != New;
158 UsedColors.set(Color);
159 Assignments[
Color].push_back(LI);
167 for (
size_t I = 0, E = SortedIntervals.
size();
I <
E; ++
I) {
168 unsigned Old = SortedIntervals[
I]->reg;
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static unsigned virtReg2Index(unsigned Reg)
Convert a virtual register number to a 0-based index.
static float getSpillWeight(bool isDef, bool isUse, const MachineBlockFrequencyInfo *MBFI, const MachineInstr &MI)
Calculate the spill weight to assign to a single instruction.
This class represents lattice values for constants.
void push_back(const T &Elt)
char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
LiveInterval - This class represents the liveness of a register, or stack slot.
iterator_range< reg_nodbg_iterator > reg_nodbg_operands(unsigned Reg) const
static float computeWeight(const MachineRegisterInfo *MRI, const MachineBlockFrequencyInfo *MBFI, unsigned VReg)
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
INITIALIZE_PASS(WebAssemblyRegColoring, DEBUG_TYPE, "Minimize number of registers used", false, false) FunctionPass *llvm
void reserve(size_type N)
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
AnalysisUsage & addRequired()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
FunctionPass * createWebAssemblyRegColoring()
AnalysisUsage & addPreservedID(const void *ID)
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
unsigned const MachineRegisterInfo * MRI
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Represent the analysis usage information of a pass.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
FunctionPass class - This class is used to implement most global optimizations.
LiveInterval & getInterval(Register Reg)
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
void sort(IteratorTy Start, IteratorTy End)
Color
A "color", which is either even or odd.
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
void setPreservesCFG()
This function should be called by the pass, iff they do not:
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.
This struct contains the mappings from the slot numbers to unnamed metadata nodes, global values and types.
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.
bool isLiveIn(unsigned Reg) const
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool exposesReturnsTwice() const
exposesReturnsTwice - Returns true if the function calls setjmp or any other similar functions with a...
This file declares WebAssembly-specific per-machine-function information.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.