diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp index 626e318de85631..7886bf341303d7 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 fd4f31723700c6..7d2485b6ee928c 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 a0c2feb02d10c8..c22469c481f4c5 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 1e658ed9e3a1ba..a2a735a7301312 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 << " .. "