[llvm] f9bb101 - Revert "[NFC, StackSafety] Change type of internal container"

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 2 20:03:23 PDT 2020


Author: Mehdi Amini
Date: 2020-06-03T03:02:28Z
New Revision: f9bb101d394d62027ba33e132691540f1e63cea8

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

LOG: Revert "[NFC, StackSafety] Change type of internal container"

This reverts commit f62813e7eae148a6175de28bfa384524a9f2bf94.
GCC 5.3 build is broken.

Added: 
    

Modified: 
    llvm/lib/Analysis/StackSafetyAnalysis.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/StackSafetyAnalysis.cpp b/llvm/lib/Analysis/StackSafetyAnalysis.cpp
index dafa06922906..60ed0ed161f0 100644
--- a/llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ b/llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -140,7 +140,7 @@ ConstantRange getStaticAllocaSizeRange(const AllocaInst &AI) {
 }
 
 struct FunctionInfo {
-  std::map<const AllocaInst *, UseInfo> Allocas;
+  SmallVector<UseInfo, 4> Allocas;
   SmallVector<UseInfo, 4> Params;
   // TODO: describe return value as depending on one or more of its arguments.
 
@@ -165,11 +165,13 @@ struct FunctionInfo {
 
     O << "    allocas uses:\n";
     if (F) {
+      size_t Pos = 0;
       for (auto &I : instructions(F)) {
         if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
-          auto &AS = Allocas.find(AI)->second;
+          auto &AS = Allocas[Pos];
           O << "      " << AI->getName() << "["
             << getStaticAllocaSizeRange(*AI).getUpper() << "]: " << AS << "\n";
+          ++Pos;
         }
       }
     } else {
@@ -389,7 +391,8 @@ FunctionInfo StackSafetyLocalAnalysis::run() {
 
   for (auto &I : instructions(F)) {
     if (auto *AI = dyn_cast<AllocaInst>(&I)) {
-      UseInfo &AS = Info.Allocas.emplace(AI, PointerSize).first->second;
+      Info.Allocas.emplace_back(PointerSize);
+      UseInfo &AS = Info.Allocas.back();
       analyzeAllUses(AI, AS);
     }
   }
@@ -599,18 +602,19 @@ GVToSSI createGlobalStackSafetyInfo(
 
   for (auto &F : SSDFA.run()) {
     auto FI = F.second;
+    size_t Pos = 0;
     auto &SrcF = Functions[F.first];
-    for (auto &KV : FI.Allocas) {
-      auto &A = KV.second;
+    for (auto &A : FI.Allocas) {
       resolveAllCalls(A);
       for (auto &C : A.Calls) {
         A.updateRange(
             SSDFA.getArgumentAccessRange(C.Callee, C.ParamNo, C.Offset));
       }
       // FIXME: This is needed only to preserve calls in print() results.
-      A.Calls = SrcF.Allocas.find(KV.first)->second.Calls;
+      A.Calls = SrcF.Allocas[Pos].Calls;
+      ++Pos;
     }
-    size_t Pos = 0;
+    Pos = 0;
     for (auto &P : FI.Params) {
       P.Calls = SrcF.Params[Pos].Calls;
       ++Pos;
@@ -658,11 +662,20 @@ const StackSafetyGlobalInfo::InfoTy &StackSafetyGlobalInfo::getInfo() const {
     }
     Info.reset(
         new InfoTy{createGlobalStackSafetyInfo(std::move(Functions)), {}});
-    for (auto &FnKV : Info->Info) {
-      for (auto &KV : FnKV.second.Allocas) {
-        const AllocaInst *AI = KV.first;
-        if (getStaticAllocaSizeRange(*AI).contains(KV.second.Range))
-          Info->SafeAllocas.insert(AI);
+    for (auto &KV : Info->Info) {
+      if (!KV.first->isDeclaration()) {
+        size_t Pos = 0;
+        // FIXME: Convert FunctionInfo::Allocas into map<AllocaInst*, UseInfo>
+        // and do not rely on alloca index.
+        for (auto &I : instructions(*cast<Function>(KV.first))) {
+          if (const auto &AI = dyn_cast<AllocaInst>(&I)) {
+            if (getStaticAllocaSizeRange(*AI).contains(
+                    KV.second.Allocas[Pos].Range)) {
+              Info->SafeAllocas.insert(AI);
+            }
+            ++Pos;
+          }
+        }
       }
     }
     if (StackSafetyPrint)


        


More information about the llvm-commits mailing list