[PATCH] D80847: [NFC, StackSafety] Change type of internal container

Vitaly Buka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 29 15:20:22 PDT 2020


vitalybuka created this revision.
vitalybuka added a reviewer: eugenis.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Depends on D80771 <https://reviews.llvm.org/D80771>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80847

Files:
  llvm/lib/Analysis/StackSafetyAnalysis.cpp


Index: llvm/lib/Analysis/StackSafetyAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -10,6 +10,7 @@
 
 #include "llvm/Analysis/StackSafetyAnalysis.h"
 #include "llvm/ADT/APInt.h"
+#include "llvm/ADT/AllocatorList.h"
 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
 #include "llvm/IR/ConstantRange.h"
 #include "llvm/IR/DerivedTypes.h"
@@ -140,7 +141,7 @@
 }
 
 struct FunctionInfo {
-  SmallVector<UseInfo, 4> Allocas;
+  std::map<const AllocaInst *, UseInfo> Allocas;
   SmallVector<UseInfo, 4> Params;
   // TODO: describe return value as depending on one or more of its arguments.
 
@@ -165,13 +166,11 @@
 
     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[Pos];
+          auto &AS = Allocas.find(AI)->second;
           O << "      " << AI->getName() << "["
             << getStaticAllocaSizeRange(*AI).getUpper() << "]: " << AS << "\n";
-          ++Pos;
         }
       }
     } else {
@@ -391,8 +390,7 @@
 
   for (auto &I : instructions(F)) {
     if (auto *AI = dyn_cast<AllocaInst>(&I)) {
-      Info.Allocas.emplace_back(PointerSize);
-      UseInfo &AS = Info.Allocas.back();
+      UseInfo &AS = Info.Allocas.emplace(AI, PointerSize).first->second;
       analyzeAllUses(AI, AS);
     }
   }
@@ -602,19 +600,18 @@
 
   for (auto &F : SSDFA.run()) {
     auto FI = F.second;
-    size_t Pos = 0;
     auto &SrcF = Functions[F.first];
-    for (auto &A : FI.Allocas) {
+    for (auto &KV : FI.Allocas) {
+      auto &A = KV.second;
       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[Pos].Calls;
-      ++Pos;
+      A.Calls = SrcF.Allocas.find(KV.first)->second.Calls;
     }
-    Pos = 0;
+    size_t Pos = 0;
     for (auto &P : FI.Params) {
       P.Calls = SrcF.Params[Pos].Calls;
       ++Pos;
@@ -662,20 +659,11 @@
     }
     Info.reset(
         new InfoTy{createGlobalStackSafetyInfo(std::move(Functions)), {}});
-    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;
-          }
-        }
+    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);
       }
     }
     if (StackSafetyPrint)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80847.267385.patch
Type: text/x-patch
Size: 3195 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200529/0d3b44ce/attachment.bin>


More information about the llvm-commits mailing list