[llvm] f8e4116 - [SafeStack,NFC] Move ClColoring into SafeStack.cpp

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 14 23:15:00 PDT 2020


Author: Vitaly Buka
Date: 2020-06-14T23:05:41-07:00
New Revision: f8e411656e5b324284822d67e7230f18ad547fc4

URL: https://github.com/llvm/llvm-project/commit/f8e411656e5b324284822d67e7230f18ad547fc4
DIFF: https://github.com/llvm/llvm-project/commit/f8e411656e5b324284822d67e7230f18ad547fc4.diff

LOG: [SafeStack,NFC] Move ClColoring into SafeStack.cpp

This allows to reuse the code in other components.

Added: 
    

Modified: 
    llvm/lib/CodeGen/SafeStack.cpp
    llvm/lib/CodeGen/SafeStackColoring.cpp

Removed: 
    


################################################################################
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<bool>
     SafeStackUsePointerAddress("safestack-use-pointer-address",
                                   cl::init(false), cl::Hidden);
 
+// Disabled by default due to PR32143.
+static cl::opt<bool> 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<bool> 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<AllocaInst *> 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)


        


More information about the llvm-commits mailing list