[llvm] 41f2a57 - [Attributor][NFC] Use a BumpPtrAllocator to allocate `AbstractAttribute`s

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 1 18:54:35 PDT 2020


Author: Johannes Doerfert
Date: 2020-04-01T20:53:28-05:00
New Revision: 41f2a57d0bc1c54cefc3145102632fc5e767d953

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

LOG: [Attributor][NFC] Use a BumpPtrAllocator to allocate `AbstractAttribute`s

We create a lot of AbstractAttributes and they live as long as
the Attributor does. It seems reasonable to allocate them via a
BumpPtrAllocator owned by the Attributor.

Reviewed By: baziotis

Differential Revision: https://reviews.llvm.org/D76589

Added: 
    

Modified: 
    llvm/include/llvm/Transforms/IPO/Attributor.h
    llvm/lib/Transforms/IPO/Attributor.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 2113197c067d..e5c50bdfbd5c 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -112,6 +112,7 @@
 #include "llvm/IR/ConstantRange.h"
 #include "llvm/IR/KnowledgeRetention.h"
 #include "llvm/IR/PassManager.h"
+#include "llvm/Support/Allocator.h"
 #include "llvm/Transforms/Utils/CallGraphUpdater.h"
 
 namespace llvm {
@@ -700,11 +701,7 @@ struct Attributor {
       : Functions(Functions), InfoCache(InfoCache), CGUpdater(CGUpdater),
         DepRecomputeInterval(DepRecomputeInterval), Whitelist(Whitelist) {}
 
-  ~Attributor() {
-    DeleteContainerPointers(AllAbstractAttributes);
-    for (auto &It : ArgumentReplacementMap)
-      DeleteContainerPointers(It.second);
-  }
+  ~Attributor();
 
   /// Run the analyses until a fixpoint is reached or enforced (timeout).
   ///
@@ -1070,6 +1067,9 @@ struct Attributor {
   /// Return the data layout associated with the anchor scope.
   const DataLayout &getDataLayout() const { return InfoCache.DL; }
 
+  /// The allocator used to allocate memory, e.g. for `AbstractAttribute`s.
+  BumpPtrAllocator Allocator;
+
 private:
   /// Check \p Pred on all call sites of \p Fn.
   ///

diff  --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 8877a5f74dd5..1e5591fd8d18 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -7309,6 +7309,16 @@ struct AAValueConstantRangeCallSiteArgument : AAValueConstantRangeFloating {
 ///                               Attributor
 /// ----------------------------------------------------------------------------
 
+Attributor::~Attributor() {
+  // The abstract attributes are allocated via the BumpPtrAllocator Allocator,
+  // thus we cannot delete them. We can, and want to, destruct them though.
+  for (AbstractAttribute *AA : AllAbstractAttributes)
+    AA->~AbstractAttribute();
+
+  for (auto &It : ArgumentReplacementMap)
+    DeleteContainerPointers(It.second);
+}
+
 bool Attributor::isAssumedDead(const AbstractAttribute &AA,
                                const AAIsDead *FnLivenessAA,
                                bool CheckBBLivenessOnly, DepClassTy DepClass) {
@@ -8891,7 +8901,7 @@ const char AAValueConstantRange::ID = 0;
 
 #define SWITCH_PK_CREATE(CLASS, IRP, PK, SUFFIX)                               \
   case IRPosition::PK:                                                         \
-    AA = new CLASS##SUFFIX(IRP);                                               \
+    AA = new (A.Allocator) CLASS##SUFFIX(IRP);                                 \
     break;
 
 #define CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(CLASS)                 \


        


More information about the llvm-commits mailing list