LLVM 22.0.0git
RegAllocBasic.h
Go to the documentation of this file.
1//===-- RegAllocBasic.h - Basic Register Allocator Header -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file declares the RABasic class, which provides a minimal
11/// implementation of the basic register allocator.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_REGALLOCBASIC_H
16#define LLVM_CODEGEN_REGALLOCBASIC_H
17
18#include "RegAllocBase.h"
22#include <queue>
23
24namespace llvm {
25
27 bool operator()(const LiveInterval *A, const LiveInterval *B) const {
28 return A->weight() < B->weight();
29 }
30};
31
32/// RABasic provides a minimal implementation of the basic register allocation
33/// algorithm. It prioritizes live virtual registers by spill weight and spills
34/// whenever a register is unavailable. This is not practical in production but
35/// provides a useful baseline both for measuring other allocators and comparing
36/// the speed of the basic algorithm against other styles of allocators.
38 public RegAllocBase,
40 // context
41 MachineFunction *MF = nullptr;
42
43 // state
44 std::unique_ptr<Spiller> SpillerInstance;
45 std::priority_queue<const LiveInterval *, std::vector<const LiveInterval *>,
47 Queue;
48
49 // Scratch space. Allocated here to avoid repeated malloc calls in
50 // selectOrSplit().
51 BitVector UsableRegs;
52
53 bool LRE_CanEraseVirtReg(Register) override;
54 void LRE_WillShrinkVirtReg(Register) override;
55
56public:
57 RABasic(const RegAllocFilterFunc F = nullptr);
58
59 /// Return the pass name.
60 StringRef getPassName() const override { return "Basic Register Allocator"; }
61
62 /// RABasic analysis usage.
63 void getAnalysisUsage(AnalysisUsage &AU) const override;
64
65 void releaseMemory() override;
66
67 Spiller &spiller() override { return *SpillerInstance; }
68
69 void enqueueImpl(const LiveInterval *LI) override { Queue.push(LI); }
70
71 const LiveInterval *dequeue() override {
72 if (Queue.empty())
73 return nullptr;
74 const LiveInterval *LI = Queue.top();
75 Queue.pop();
76 return LI;
77 }
78
79 MCRegister selectOrSplit(const LiveInterval &VirtReg,
80 SmallVectorImpl<Register> &SplitVRegs) override;
81
82 /// Perform register allocation.
83 bool runOnMachineFunction(MachineFunction &mf) override;
84
87 MachineFunctionProperties::Property::NoPHIs);
88 }
89
92 MachineFunctionProperties::Property::IsSSA);
93 }
94
95 // Helper for spilling all live virtual registers currently unified under preg
96 // that interfere with the most recently queried lvr. Return true if spilling
97 // was successful, and append any new spilled/split intervals to splitLVRs.
98 bool spillInterferences(const LiveInterval &VirtReg, MCRegister PhysReg,
99 SmallVectorImpl<Register> &SplitVRegs);
100
101 static char ID;
102};
103} // namespace llvm
104#endif
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_LIBRARY_VISIBILITY
Definition: Compiler.h:137
#define F(x, y, z)
Definition: MD5.cpp:55
Represent the analysis usage information of a pass.
LiveInterval - This class represents the liveness of a register, or stack slot.
Definition: LiveInterval.h:690
Callback methods for LiveRangeEdit owners.
Definition: LiveRangeEdit.h:45
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Properties which a MachineFunction may have at a given point in time.
MachineFunctionProperties & set(Property P)
RABasic provides a minimal implementation of the basic register allocation algorithm.
Definition: RegAllocBasic.h:39
const LiveInterval * dequeue() override
dequeue - Return the next unassigned register, or NULL.
Definition: RegAllocBasic.h:71
Spiller & spiller() override
Definition: RegAllocBasic.h:67
void enqueueImpl(const LiveInterval *LI) override
enqueue - Add VirtReg to the priority queue of unassigned registers.
Definition: RegAllocBasic.h:69
MachineFunctionProperties getClearedProperties() const override
Definition: RegAllocBasic.h:90
static char ID
MachineFunctionProperties getRequiredProperties() const override
Definition: RegAllocBasic.h:85
StringRef getPassName() const override
Return the pass name.
Definition: RegAllocBasic.h:60
RegAllocBase provides the register allocation driver and interface that can be extended to add intere...
Definition: RegAllocBase.h:63
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
Spiller interface.
Definition: Spiller.h:33
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::function< bool(const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI, const Register Reg)> RegAllocFilterFunc
Filter function for register classes during regalloc.
bool operator()(const LiveInterval *A, const LiveInterval *B) const
Definition: RegAllocBasic.h:27