diff --git a/llvm/include/llvm/Analysis/StackLifetime.h b/llvm/include/llvm/Analysis/StackLifetime.h --- a/llvm/include/llvm/Analysis/StackLifetime.h +++ b/llvm/include/llvm/Analysis/StackLifetime.h @@ -1,4 +1,4 @@ -//===- SafeStackColoring.h - SafeStack frame coloring ----------*- C++ -*--===// +//===- StackLifetime.h - Alloca Lifetime Analysis --------------*- C++ -*--===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIB_CODEGEN_SAFESTACKCOLORING_H -#define LLVM_LIB_CODEGEN_SAFESTACKCOLORING_H +#ifndef LLVM_ANALYSIS_STACKLIFETIME_H +#define LLVM_ANALYSIS_STACKLIFETIME_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/BitVector.h" @@ -25,8 +25,6 @@ class Function; class Instruction; -namespace safestack { - /// Compute live ranges of allocas. /// Live ranges are represented as sets of "interesting" instructions, which are /// defined as instructions that may start or end an alloca's lifetime. These @@ -35,7 +33,7 @@ /// * first instruction of any basic block /// Interesting instructions are numbered in the depth-first walk of the CFG, /// and in the program order inside each basic block. -class StackColoring { +class StackLifetime { /// A class representing liveness information for a single basic block. /// Each bit in the BitVector represents the liveness property /// for a different stack slot. @@ -62,7 +60,7 @@ class LiveRange { BitVector Bits; friend raw_ostream &operator<<(raw_ostream &OS, - const StackColoring::LiveRange &R); + const StackLifetime::LiveRange &R); public: LiveRange(unsigned Size, bool Set = false) : Bits(Size, Set) {} @@ -121,7 +119,7 @@ void calculateLiveIntervals(); public: - StackColoring(const Function &F, ArrayRef Allocas); + StackLifetime(const Function &F, ArrayRef Allocas); void run(); std::vector getMarkers() const; @@ -156,12 +154,10 @@ } inline raw_ostream &operator<<(raw_ostream &OS, - const StackColoring::LiveRange &R) { + const StackLifetime::LiveRange &R) { return OS << R.Bits; } -} // end namespace safestack - } // end namespace llvm -#endif // LLVM_LIB_CODEGEN_SAFESTACKCOLORING_H +#endif // LLVM_ANALYSIS_STACKLIFETIME_H diff --git a/llvm/lib/Analysis/StackLifetime.cpp b/llvm/lib/Analysis/StackLifetime.cpp --- a/llvm/lib/Analysis/StackLifetime.cpp +++ b/llvm/lib/Analysis/StackLifetime.cpp @@ -1,4 +1,4 @@ -//===- SafeStackColoring.cpp - SafeStack frame coloring -------------------===// +//===- StackLifetime.cpp - Alloca Lifetime Analysis -----------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -22,12 +22,11 @@ #include using namespace llvm; -using namespace llvm::safestack; -#define DEBUG_TYPE "safestackcoloring" +#define DEBUG_TYPE "stack-lifetime" -const StackColoring::LiveRange & -StackColoring::getLiveRange(const AllocaInst *AI) const { +const StackLifetime::LiveRange & +StackLifetime::getLiveRange(const AllocaInst *AI) const { const auto IT = AllocaNumbering.find(AI); assert(IT != AllocaNumbering.end()); return LiveRanges[IT->second]; @@ -42,7 +41,7 @@ return true; } -std::vector StackColoring::getMarkers() const { +std::vector StackLifetime::getMarkers() const { std::vector Markers; for (auto &M : InstructionNumbering) if (M.getFirst()->isLifetimeStartOrEnd()) @@ -50,7 +49,7 @@ return Markers; } -void StackColoring::collectMarkers() { +void StackLifetime::collectMarkers() { InterestingAllocas.resize(NumAllocas); DenseMap> BBMarkerSet; @@ -143,7 +142,7 @@ NumInst = InstNo; } -void StackColoring::calculateLocalLiveness() { +void StackLifetime::calculateLocalLiveness() { bool Changed = true; while (Changed) { Changed = false; @@ -187,7 +186,7 @@ } // while changed. } -void StackColoring::calculateLiveIntervals() { +void StackLifetime::calculateLiveIntervals() { for (auto IT : BlockLiveness) { const BasicBlock *BB = IT.getFirst(); BlockLifetimeInfo &BlockInfo = IT.getSecond(); @@ -237,13 +236,13 @@ } #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) -LLVM_DUMP_METHOD void StackColoring::dumpAllocas() const { +LLVM_DUMP_METHOD void StackLifetime::dumpAllocas() const { dbgs() << "Allocas:\n"; for (unsigned AllocaNo = 0; AllocaNo < NumAllocas; ++AllocaNo) dbgs() << " " << AllocaNo << ": " << *Allocas[AllocaNo] << "\n"; } -LLVM_DUMP_METHOD void StackColoring::dumpBlockLiveness() const { +LLVM_DUMP_METHOD void StackLifetime::dumpBlockLiveness() const { dbgs() << "Block liveness:\n"; for (auto IT : BlockLiveness) { const BasicBlock *BB = IT.getFirst(); @@ -256,14 +255,14 @@ } } -LLVM_DUMP_METHOD void StackColoring::dumpLiveRanges() const { +LLVM_DUMP_METHOD void StackLifetime::dumpLiveRanges() const { dbgs() << "Alloca liveness:\n"; for (unsigned AllocaNo = 0; AllocaNo < NumAllocas; ++AllocaNo) dbgs() << " " << AllocaNo << ": " << LiveRanges[AllocaNo] << "\n"; } #endif -StackColoring::StackColoring(const Function &F, +StackLifetime::StackLifetime(const Function &F, ArrayRef Allocas) : F(F), Allocas(Allocas), NumAllocas(Allocas.size()) { LLVM_DEBUG(dumpAllocas()); @@ -274,7 +273,7 @@ collectMarkers(); } -void StackColoring::run() { +void StackLifetime::run() { LiveRanges.resize(NumAllocas, LiveRange(NumInst)); for (unsigned I = 0; I < NumAllocas; ++I) if (!InterestingAllocas.test(I)) diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp --- a/llvm/lib/CodeGen/SafeStack.cpp +++ b/llvm/lib/CodeGen/SafeStack.cpp @@ -497,8 +497,8 @@ DIBuilder DIB(*F.getParent()); - StackColoring SSC(F, StaticAllocas); - static const StackColoring::LiveRange NoColoringRange(1, true); + StackLifetime SSC(F, StaticAllocas); + static const StackLifetime::LiveRange NoColoringRange(1, true); if (ClColoring) SSC.run(); diff --git a/llvm/lib/CodeGen/SafeStackLayout.h b/llvm/lib/CodeGen/SafeStackLayout.h --- a/llvm/lib/CodeGen/SafeStackLayout.h +++ b/llvm/lib/CodeGen/SafeStackLayout.h @@ -27,10 +27,10 @@ struct StackRegion { unsigned Start; unsigned End; - StackColoring::LiveRange Range; + StackLifetime::LiveRange Range; StackRegion(unsigned Start, unsigned End, - const StackColoring::LiveRange &Range) + const StackLifetime::LiveRange &Range) : Start(Start), End(End), Range(Range) {} }; @@ -40,7 +40,7 @@ struct StackObject { const Value *Handle; unsigned Size, Alignment; - StackColoring::LiveRange Range; + StackLifetime::LiveRange Range; }; SmallVector StackObjects; @@ -56,7 +56,7 @@ /// Add an object to the stack frame. Value pointer is opaque and used as a /// handle to retrieve the object's offset in the frame later. void addObject(const Value *V, unsigned Size, unsigned Alignment, - const StackColoring::LiveRange &Range); + const StackLifetime::LiveRange &Range); /// Run the layout computation for all previously added objects. void computeLayout(); diff --git a/llvm/lib/CodeGen/SafeStackLayout.cpp b/llvm/lib/CodeGen/SafeStackLayout.cpp --- a/llvm/lib/CodeGen/SafeStackLayout.cpp +++ b/llvm/lib/CodeGen/SafeStackLayout.cpp @@ -39,7 +39,7 @@ } void StackLayout::addObject(const Value *V, unsigned Size, unsigned Alignment, - const StackColoring::LiveRange &Range) { + const StackLifetime::LiveRange &Range) { StackObjects.push_back({V, Size, Alignment, Range}); ObjectAlignments[V] = Alignment; MaxAlignment = std::max(MaxAlignment, Alignment); @@ -96,7 +96,7 @@ if (Start > LastRegionEnd) { LLVM_DEBUG(dbgs() << " Creating gap region: " << LastRegionEnd << " .. " << Start << "\n"); - Regions.emplace_back(LastRegionEnd, Start, StackColoring::LiveRange(0)); + Regions.emplace_back(LastRegionEnd, Start, StackLifetime::LiveRange(0)); LastRegionEnd = Start; } LLVM_DEBUG(dbgs() << " Creating new region: " << LastRegionEnd << " .. "