30 #define DEBUG_TYPE "wasm-reg-coloring" 39 return "WebAssembly Register Coloring";
59 "Minimize number of registers used",
false,
false)
62 return new WebAssemblyRegColoring();
76 bool WebAssemblyRegColoring::runOnMachineFunction(
MachineFunction &MF) {
78 dbgs() <<
"********** Register Coloring **********\n" 79 <<
"********** Function: " << MF.
getName() <<
'\n';
92 &getAnalysis<MachineBlockFrequencyInfo>();
98 SortedIntervals.
reserve(NumVRegs);
101 for (
unsigned i = 0; i < NumVRegs; ++i) {
103 if (MFI.isVRegStackified(VReg))
134 SortedIntervals.
size());
136 bool Changed =
false;
137 for (
size_t i = 0, e = SortedIntervals.
size(); i < e; ++i) {
139 unsigned Old = LI->
reg;
145 for (
unsigned C : UsedColors.set_bits()) {
149 if (!OtherLI->empty() && OtherLI->overlaps(*LI))
156 unsigned New = SortedIntervals[
Color]->reg;
158 Changed |= Old != New;
159 UsedColors.set(Color);
160 Assignments[
Color].push_back(LI);
169 for (
size_t i = 0, e = SortedIntervals.
size(); i < e; ++i) {
170 unsigned Old = SortedIntervals[i]->reg;
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
static float getSpillWeight(bool isDef, bool isUse, const MachineBlockFrequencyInfo *MBFI, const MachineInstr &MI)
Calculate the spill weight to assign to a single instruction.
static unsigned virtReg2Index(unsigned Reg)
Convert a virtual register number to a 0-based index.
This class represents lattice values for constants.
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
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...
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...
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.
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.
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:
LiveInterval & getInterval(unsigned Reg)
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.