30 #define DEBUG_TYPE "wasm-reg-coloring"
39 return "WebAssembly Register Coloring";
59 return new WebAssemblyRegColoring();
73 bool WebAssemblyRegColoring::runOnMachineFunction(
MachineFunction &MF) {
75 dbgs() <<
"********** Register Coloring **********\n"
76 <<
"********** Function: " << MF.
getName() <<
'\n';
89 &getAnalysis<MachineBlockFrequencyInfo>();
95 SortedIntervals.
reserve(NumVRegs);
97 DEBUG(
dbgs() <<
"Interesting register intervals:\n");
98 for (
unsigned i = 0;
i < NumVRegs; ++
i) {
100 if (MFI.isVRegStackified(VReg))
118 std::sort(SortedIntervals.
begin(), SortedIntervals.
end(),
122 if (LHS->
weight != RHS->weight)
123 return LHS->
weight > RHS->weight;
124 if (LHS->
empty() || RHS->empty())
125 return !LHS->
empty() && RHS->empty();
129 DEBUG(
dbgs() <<
"Coloring register intervals:\n");
132 SortedIntervals.
size());
134 bool Changed =
false;
135 for (
size_t i = 0, e = SortedIntervals.
size();
i < e; ++
i) {
137 unsigned Old = LI->
reg;
143 for (
int C(UsedColors.find_first());
C != -1;
144 C = UsedColors.find_next(
C)) {
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);
168 for (
size_t i = 0, e = SortedIntervals.
size();
i < e; ++
i) {
169 unsigned Old = SortedIntervals[
i]->reg;
void push_back(const T &Elt)
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 unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
LiveInterval - This class represents the liveness of a register, or stack slot.
static float computeWeight(const MachineRegisterInfo *MRI, const MachineBlockFrequencyInfo *MBFI, unsigned VReg)
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
void reserve(size_type N)
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
AnalysisUsage & addRequired()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
bool isLiveIn(unsigned Reg) const
AnalysisUsage & addPreservedID(const void *ID)
unsigned const MachineRegisterInfo * MRI
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
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.
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)
static float getSpillWeight(bool isDef, bool isUse, const MachineBlockFrequencyInfo *MBFI, const MachineInstr &Instr)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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.
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
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...
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
This file declares WebAssembly-specific per-machine-function information.
FunctionPass * createWebAssemblyRegColoring()
iterator_range< reg_nodbg_iterator > reg_nodbg_operands(unsigned Reg) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
bool use_empty(unsigned RegNo) const
use_empty - Return true if there are no instructions using the specified register.