Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Unified Diff: src/IceOperand.h

Issue 1312433004: Weight variables by their number of uses for register allocation. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Tidy up lose ends. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceLiveness.cpp ('k') | src/IceOperand.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceOperand.h
diff --git a/src/IceOperand.h b/src/IceOperand.h
index bcb38d03d395191d04ebc24a675e957d3df39bba..a2593ea654e3678d4bf00d23936b21a2c51873fc 100644
--- a/src/IceOperand.h
+++ b/src/IceOperand.h
@@ -332,8 +332,6 @@ public:
void addWeight(const RegWeight &Other) { addWeight(Other.Weight); }
void setWeight(uint32_t Val) { Weight = Val; }
uint32_t getWeight() const { return Weight; }
- bool isInf() const { return Weight == Inf; }
- bool isZero() const { return Weight == Zero; }
private:
uint32_t Weight = 0;
@@ -346,9 +344,7 @@ bool operator==(const RegWeight &A, const RegWeight &B);
/// LiveRange is a set of instruction number intervals representing
/// a variable's live range. Generally there is one interval per basic
/// block where the variable is live, but adjacent intervals get
-/// coalesced into a single interval. LiveRange also includes a
-/// weight, in case e.g. we want a live range to have higher weight
-/// inside a loop.
+/// coalesced into a single interval.
class LiveRange {
public:
LiveRange() = default;
@@ -364,7 +360,6 @@ public:
void reset() {
Range.clear();
- Weight.setWeight(0);
untrim();
}
void addSegment(InstNumberT Start, InstNumberT End);
@@ -384,9 +379,6 @@ public:
void untrim() { TrimmedBegin = Range.begin(); }
void trim(InstNumberT Lower);
- RegWeight getWeight() const { return Weight; }
- void setWeight(const RegWeight &NewWeight) { Weight = NewWeight; }
- void addWeight(uint32_t Delta) { Weight.addWeight(Delta); }
void dump(Ostream &Str) const;
private:
@@ -395,7 +387,6 @@ private:
typedef std::vector<RangeElementType, CfgLocalAllocator<RangeElementType>>
RangeType;
RangeType Range;
- RegWeight Weight = RegWeight(0);
/// TrimmedBegin is an optimization for the overlaps() computation.
/// Since the linear-scan algorithm always calls it as overlaps(Cur)
/// and Cur advances monotonically according to live range start, we
@@ -417,6 +408,12 @@ class Variable : public Operand {
Variable(const Variable &) = delete;
Variable &operator=(const Variable &) = delete;
+ enum RegRequirement {
+ ShouldHaveRegister,
+ MustHaveRegister,
+ MustNotHaveRegister,
+ };
+
public:
static Variable *create(Cfg *Func, Type Ty, SizeT Index) {
return new (Func->allocate<Variable>()) Variable(kVariable, Ty, Index);
@@ -454,25 +451,29 @@ public:
int32_t getRegNumTmp() const { return RegNumTmp; }
void setRegNumTmp(int32_t NewRegNum) { RegNumTmp = NewRegNum; }
- RegWeight getWeight() const { return Weight; }
- void setWeight(uint32_t NewWeight) { Weight = RegWeight(NewWeight); }
- void setWeightInfinite() { setWeight(RegWeight::Inf); }
+ RegWeight getWeight() const {
+ return RegWeight(mustHaveReg() ? RegWeight::Inf : mustNotHaveReg()
+ ? RegWeight::Zero
+ : Weight);
+ }
+ void resetUses() { Weight = 0; }
+ void addUse(uint32_t Weight) { Weight += Weight; }
jvoung (off chromium) 2015/08/26 22:35:16 I'm a bit worried about the variable shadowing her
ascull 2015/08/26 22:53:49 Done.
+
+ void setMustHaveReg() { RegRequirement = MustHaveRegister; }
+ bool mustHaveReg() const { return RegRequirement == MustHaveRegister; }
+ void setMustNotHaveReg() { RegRequirement = MustNotHaveRegister; }
+ bool mustNotHaveReg() const { return RegRequirement == MustNotHaveRegister; }
LiveRange &getLiveRange() { return Live; }
const LiveRange &getLiveRange() const { return Live; }
void setLiveRange(const LiveRange &Range) { Live = Range; }
- void resetLiveRange() { Live.reset(); }
- void addLiveRange(InstNumberT Start, InstNumberT End, uint32_t WeightDelta) {
+ void resetLiveRange() {
+ Live.reset();
+ resetUses();
+ }
+ void addLiveRange(InstNumberT Start, InstNumberT End) {
assert(!getIgnoreLiveness());
- assert(WeightDelta != RegWeight::Inf);
Live.addSegment(Start, End);
- if (Weight.isInf())
- Live.setWeight(RegWeight(RegWeight::Inf));
- else
- Live.addWeight(WeightDelta * Weight.getWeight());
- }
- void setLiveRangeInfiniteWeight() {
- Live.setWeight(RegWeight(RegWeight::Inf));
}
void trimLiveRange(InstNumberT Start) { Live.trim(Start); }
void untrimLiveRange() { Live.untrim(); }
@@ -540,7 +541,11 @@ protected:
int32_t RegNum = NoRegister;
/// RegNumTmp is the tentative assignment during register allocation.
int32_t RegNumTmp = NoRegister;
- RegWeight Weight = RegWeight(1); // Register allocation priority
+ /// \name Register allocation priority
+ /// @{
+ uint32_t Weight = 0; /// Calculated by use count and loop nest depth.
+ RegRequirement RegRequirement = ShouldHaveRegister;
+ /// @}
LiveRange Live;
// LoVar and HiVar are needed for lowering from 64 to 32 bits. When
// lowering from I64 to I32 on a 32-bit architecture, we split the
« no previous file with comments | « src/IceLiveness.cpp ('k') | src/IceOperand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698