diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp index 001df8b25f16..626e318de856 100644 --- a/llvm/lib/CodeGen/SafeStack.cpp +++ b/llvm/lib/CodeGen/SafeStack.cpp @@ -18,6 +18,7 @@ #include "SafeStackLayout.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/BitVector.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" @@ -95,6 +96,10 @@ static cl::opt SafeStackUsePointerAddress("safestack-use-pointer-address", cl::init(false), cl::Hidden); +// Disabled by default due to PR32143. +static cl::opt ClColoring("safe-stack-coloring", + cl::desc("enable safe stack coloring"), + cl::Hidden, cl::init(false)); namespace { @@ -493,7 +498,9 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack( DIBuilder DIB(*F.getParent()); StackColoring SSC(F, StaticAllocas); - SSC.run(); + static const StackColoring::LiveRange NoColoringRange = {BitVector{1, true}}; + if (ClColoring) + SSC.run(); SSC.removeAllMarkers(); // Unsafe stack always grows down. @@ -528,7 +535,8 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack( unsigned Align = std::max((unsigned)DL.getPrefTypeAlignment(Ty), AI->getAlignment()); - SSL.addObject(AI, Size, Align, SSC.getLiveRange(AI)); + SSL.addObject(AI, Size, Align, + ClColoring ? SSC.getLiveRange(AI) : NoColoringRange); } SSL.computeLayout(); diff --git a/llvm/lib/CodeGen/SafeStackColoring.cpp b/llvm/lib/CodeGen/SafeStackColoring.cpp index 564df8a8ce46..75aad268a018 100644 --- a/llvm/lib/CodeGen/SafeStackColoring.cpp +++ b/llvm/lib/CodeGen/SafeStackColoring.cpp @@ -26,11 +26,6 @@ using namespace llvm::safestack; #define DEBUG_TYPE "safestackcoloring" -// Disabled by default due to PR32143. -static cl::opt ClColoring("safe-stack-coloring", - cl::desc("enable safe stack coloring"), - cl::Hidden, cl::init(false)); - const StackColoring::LiveRange &StackColoring::getLiveRange(AllocaInst *AI) { const auto IT = AllocaNumbering.find(AI); assert(IT != AllocaNumbering.end()); @@ -285,14 +280,6 @@ StackColoring::StackColoring(Function &F, ArrayRef Allocas) } void StackColoring::run() { - if (!ClColoring) { - for (auto &R : LiveRanges) { - R.SetMaximum(1); - R.AddRange(0, 1); - } - return; - } - for (auto &R : LiveRanges) R.SetMaximum(NumInst); for (unsigned I = 0; I < NumAllocas; ++I)