[llvm] ca2dcbd - [SafeStack,NFC] Make StackColoring read-only

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


Author: Vitaly Buka
Date: 2020-06-14T23:05:43-07:00
New Revision: ca2dcbd030eadbf0aa9b660efe864ff08af6e18b

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

LOG: [SafeStack,NFC] Make StackColoring read-only

Move core which removes markers out of StackColoring.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp
index 7886bf341303..63c4e94b4935 100644
--- a/llvm/lib/CodeGen/SafeStack.cpp
+++ b/llvm/lib/CodeGen/SafeStack.cpp
@@ -501,7 +501,14 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
   static const StackColoring::LiveRange NoColoringRange(1, true);
   if (ClColoring)
     SSC.run();
-  SSC.removeAllMarkers();
+
+  for (auto *I : SSC.getMarkers()) {
+    auto *Op = dyn_cast<Instruction>(I->getOperand(1));
+    const_cast<IntrinsicInst *>(I)->eraseFromParent();
+    // Remove the operand bitcast, too, if it has no more uses left.
+    if (Op && Op->use_empty())
+      Op->eraseFromParent();
+  }
 
   // Unsafe stack always grows down.
   StackLayout SSL(StackAlignment);

diff  --git a/llvm/lib/CodeGen/SafeStackColoring.cpp b/llvm/lib/CodeGen/SafeStackColoring.cpp
index 7009b7cf68b0..ad6d9bde3dea 100644
--- a/llvm/lib/CodeGen/SafeStackColoring.cpp
+++ b/llvm/lib/CodeGen/SafeStackColoring.cpp
@@ -42,14 +42,12 @@ static bool readMarker(const Instruction *I, bool *IsStart) {
   return true;
 }
 
-void StackColoring::removeAllMarkers() {
-  for (auto *I : Markers) {
-    auto *Op = dyn_cast<Instruction>(I->getOperand(1));
-    const_cast<IntrinsicInst *>(I)->eraseFromParent();
-    // Remove the operand bitcast, too, if it has no more uses left.
-    if (Op && Op->use_empty())
-      Op->eraseFromParent();
-  }
+std::vector<const IntrinsicInst *> StackColoring::getMarkers() const {
+  std::vector<const IntrinsicInst *> Markers;
+  for (auto &M : InstructionNumbering)
+    if (M.getFirst()->isLifetimeStartOrEnd())
+      Markers.push_back(M.getFirst());
+  return Markers;
 }
 
 void StackColoring::collectMarkers() {
@@ -78,7 +76,6 @@ void StackColoring::collectMarkers() {
         if (IsStart)
           InterestingAllocas.set(AllocaNo);
         BBMarkerSet[UI->getParent()][UI] = {AllocaNo, IsStart};
-        Markers.push_back(UI);
       }
     }
   }

diff  --git a/llvm/lib/CodeGen/SafeStackColoring.h b/llvm/lib/CodeGen/SafeStackColoring.h
index b58e9e47c07a..b71b374182c0 100644
--- a/llvm/lib/CodeGen/SafeStackColoring.h
+++ b/llvm/lib/CodeGen/SafeStackColoring.h
@@ -102,7 +102,6 @@ class StackColoring {
   /// The set of allocas that have at least one lifetime.start. All other
   /// allocas get LiveRange that corresponds to the entire function.
   BitVector InterestingAllocas;
-  SmallVector<const IntrinsicInst *, 8> Markers;
 
   struct Marker {
     unsigned AllocaNo;
@@ -125,7 +124,7 @@ class StackColoring {
   StackColoring(const Function &F, ArrayRef<const AllocaInst *> Allocas);
 
   void run();
-  void removeAllMarkers();
+  std::vector<const IntrinsicInst *> getMarkers() const;
 
   /// Returns a set of "interesting" instructions where the given alloca is
   /// live. Not all instructions in a function are interesting: we pick a set


        


More information about the llvm-commits mailing list