[llvm] 2f5e535 - [SafeStack,NFC] Cleanup LiveRange interface
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 14 23:15:07 PDT 2020
Author: Vitaly Buka
Date: 2020-06-14T23:05:42-07:00
New Revision: 2f5e535a8478d51e72e693f055a6abd21cceb6b8
URL: https://github.com/llvm/llvm-project/commit/2f5e535a8478d51e72e693f055a6abd21cceb6b8
DIFF: https://github.com/llvm/llvm-project/commit/2f5e535a8478d51e72e693f055a6abd21cceb6b8.diff
LOG: [SafeStack,NFC] Cleanup LiveRange interface
Added:
Modified:
llvm/lib/CodeGen/SafeStack.cpp
llvm/lib/CodeGen/SafeStackColoring.cpp
llvm/lib/CodeGen/SafeStackColoring.h
llvm/lib/CodeGen/SafeStackLayout.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp
index 626e318de856..7886bf341303 100644
--- a/llvm/lib/CodeGen/SafeStack.cpp
+++ b/llvm/lib/CodeGen/SafeStack.cpp
@@ -498,7 +498,7 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
DIBuilder DIB(*F.getParent());
StackColoring SSC(F, StaticAllocas);
- static const StackColoring::LiveRange NoColoringRange = {BitVector{1, true}};
+ static const StackColoring::LiveRange NoColoringRange(1, true);
if (ClColoring)
SSC.run();
SSC.removeAllMarkers();
diff --git a/llvm/lib/CodeGen/SafeStackColoring.cpp b/llvm/lib/CodeGen/SafeStackColoring.cpp
index fd4f31723700..7d2485b6ee92 100644
--- a/llvm/lib/CodeGen/SafeStackColoring.cpp
+++ b/llvm/lib/CodeGen/SafeStackColoring.cpp
@@ -275,14 +275,12 @@ StackColoring::StackColoring(const Function &F,
for (unsigned I = 0; I < NumAllocas; ++I)
AllocaNumbering[Allocas[I]] = I;
- LiveRanges.resize(NumAllocas);
collectMarkers();
}
void StackColoring::run() {
- for (auto &R : LiveRanges)
- R.SetMaximum(NumInst);
+ LiveRanges.resize(NumAllocas, LiveRange(NumInst));
for (unsigned I = 0; I < NumAllocas; ++I)
if (!InterestingAllocas.test(I))
LiveRanges[I] = getFullLiveRange();
diff --git a/llvm/lib/CodeGen/SafeStackColoring.h b/llvm/lib/CodeGen/SafeStackColoring.h
index a0c2feb02d10..c22469c481f4 100644
--- a/llvm/lib/CodeGen/SafeStackColoring.h
+++ b/llvm/lib/CodeGen/SafeStackColoring.h
@@ -59,17 +59,20 @@ class StackColoring {
public:
/// This class represents a set of interesting instructions where an alloca is
/// live.
- struct LiveRange {
- BitVector bv;
+ class LiveRange {
+ BitVector Bits;
+ friend raw_ostream &operator<<(raw_ostream &OS,
+ const StackColoring::LiveRange &R);
- void SetMaximum(int size) { bv.resize(size); }
- void AddRange(unsigned start, unsigned end) { bv.set(start, end); }
+ public:
+ LiveRange(unsigned Size, bool Set = false) : Bits(Size, Set) {}
+ void AddRange(unsigned Start, unsigned End) { Bits.set(Start, End); }
bool Overlaps(const LiveRange &Other) const {
- return bv.anyCommon(Other.bv);
+ return Bits.anyCommon(Other.Bits);
}
- void Join(const LiveRange &Other) { bv |= Other.bv; }
+ void Join(const LiveRange &Other) { Bits |= Other.Bits; }
};
private:
@@ -133,10 +136,7 @@ class StackColoring {
/// entire function.
LiveRange getFullLiveRange() const {
assert(NumInst >= 0);
- LiveRange R;
- R.SetMaximum(NumInst);
- R.AddRange(0, NumInst);
- return R;
+ return LiveRange(NumInst, true);
}
};
@@ -156,9 +156,9 @@ static inline raw_ostream &operator<<(raw_ostream &OS, const BitVector &V) {
return OS;
}
-static inline raw_ostream &operator<<(raw_ostream &OS,
- const StackColoring::LiveRange &R) {
- return OS << R.bv;
+inline raw_ostream &operator<<(raw_ostream &OS,
+ const StackColoring::LiveRange &R) {
+ return OS << R.Bits;
}
} // end namespace safestack
diff --git a/llvm/lib/CodeGen/SafeStackLayout.cpp b/llvm/lib/CodeGen/SafeStackLayout.cpp
index 1e658ed9e3a1..a2a735a73013 100644
--- a/llvm/lib/CodeGen/SafeStackLayout.cpp
+++ b/llvm/lib/CodeGen/SafeStackLayout.cpp
@@ -95,7 +95,7 @@ void StackLayout::layoutObject(StackObject &Obj) {
if (Start > LastRegionEnd) {
LLVM_DEBUG(dbgs() << " Creating gap region: " << LastRegionEnd << " .. "
<< Start << "\n");
- Regions.emplace_back(LastRegionEnd, Start, StackColoring::LiveRange());
+ Regions.emplace_back(LastRegionEnd, Start, StackColoring::LiveRange(0));
LastRegionEnd = Start;
}
LLVM_DEBUG(dbgs() << " Creating new region: " << LastRegionEnd << " .. "
More information about the llvm-commits
mailing list