[PATCH] D86129: [Attributor] Fucntion seed allow list

Kuter Dinel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 00:44:42 PDT 2020


kuter created this revision.
Herald added subscribers: llvm-commits, okura, uenoku, hiraditya.
Herald added a reviewer: uenoku.
Herald added a reviewer: homerdin.
Herald added a project: LLVM.
kuter requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added a reviewer: baziotis.
Herald added a subscriber: bbn.

This patch adds a command line option to seed only selected functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86129

Files:
  llvm/lib/Transforms/IPO/Attributor.cpp
  llvm/test/Transforms/Attributor/allow_list.ll


Index: llvm/test/Transforms/Attributor/allow_list.ll
===================================================================
--- llvm/test/Transforms/Attributor/allow_list.ll
+++ llvm/test/Transforms/Attributor/allow_list.ll
@@ -2,6 +2,8 @@
 ; RUN: opt -S -passes=attributor --attributor-seed-allow-list asd < %s | FileCheck %s --check-prefixes=CHECK_DISABLED
 ; RUN: opt -S -passes=attributor --attributor-seed-allow-list AAValueSimplify < %s | FileCheck %s --check-prefixes=CHECK_ENABLED
 
+; RUN: opt -S -passes=attributor --attributor-function-seed-allow-list @range_test < %s | FileCheck %s --check-prefixes=CHECK_ENABLED_FUNCTION
+
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 
 ; Function Attrs: nounwind uwtable
@@ -12,6 +14,13 @@
 ; CHECK_DISABLED-NEXT:    [[TMP1:%.*]] = icmp sgt i32 [[A]], 100
 ; CHECK_DISABLED-NEXT:    [[TMP2:%.*]] = zext i1 [[TMP1]] to i32
 ; CHECK_DISABLED-NEXT:    ret i32 [[TMP2]]
+;
+; CHECK_ENABLED_FUNCTION: Function Attrs: noinline nounwind uwtable
+; CHECK_ENABLED_FUNCTION-LABEL: define {{[^@]+}}@range_test
+; CHECK_ENABLED_FUNCTION-SAME: (i32 [[A:%.*]])
+; CHECK_ENABLED_FUNCTION-NEXT:    [[TMP1:%.*]] = icmp sgt i32 [[A]], 100
+; CHECK_ENABLED_FUNCTION-NEXT:    [[TMP2:%.*]] = zext i1 [[TMP1]] to i32
+; CHECK_ENABLED_FUNCTION-NEXT:    ret i32 [[TMP2]]
 ;
   %1 = icmp sgt i32 %a, 100
   %2 = zext i1 %1 to i32
@@ -28,6 +37,11 @@
 ; CHECK_ENABLED: Function Attrs: noinline nounwind uwtable
 ; CHECK_ENABLED-LABEL: define {{[^@]+}}@range_use()
 ; CHECK_ENABLED-NEXT:    ret i32 1
+;
+; CHECK_ENABLED_FUNCTION: Function Attrs: noinline nounwind uwtable
+; CHECK_ENABLED_FUNCTION-LABEL: define {{[^@]+}}@range_use()
+; CHECK_ENABLED_FUNCTION-NEXT:    [[TMP1:%.*]] = call i32 @range_test(i32 123)
+; CHECK_ENABLED_FUNCTION-NEXT:    ret i32 [[TMP1]]
 ;
   %1 = call i32 @range_test(i32 123)
   ret i32 %1
Index: llvm/lib/Transforms/IPO/Attributor.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Attributor.cpp
+++ llvm/lib/Transforms/IPO/Attributor.cpp
@@ -99,10 +99,16 @@
 
 static cl::list<std::string>
     SeedAllowList("attributor-seed-allow-list", cl::Hidden,
-                  cl::desc("Comma seperated list of attrbute names that are "
+                  cl::desc("Comma seperated list of attribute names that are "
                            "allowed to be seeded."),
                   cl::ZeroOrMore, cl::CommaSeparated);
 
+static cl::list<std::string> FunctionSeedAllowList(
+    "attributor-function-seed-allow-list", cl::Hidden,
+    cl::desc("Comma seperated list of function names that are "
+             "allowed to be seeded."),
+    cl::ZeroOrMore, cl::CommaSeparated);
+
 static cl::opt<bool>
     DumpDepGraph("attributor-dump-dep-graph", cl::Hidden,
                  cl::desc("Dump the dependency graph to dot files."),
@@ -1568,9 +1574,16 @@
 }
 
 bool Attributor::shouldSeedAttribute(AbstractAttribute &AA) {
-  if (SeedAllowList.size() == 0)
-    return true;
-  return std::count(SeedAllowList.begin(), SeedAllowList.end(), AA.getName());
+  bool result = true;
+  if (SeedAllowList.size() != 0)
+    result =
+        std::count(SeedAllowList.begin(), SeedAllowList.end(), AA.getName());
+  Function *Fn = AA.getAnchorScope();
+  if (FunctionSeedAllowList.size() != 0 && Fn)
+    result = result && std::count(FunctionSeedAllowList.begin(),
+                                  FunctionSeedAllowList.end(), Fn->getName());
+
+  return result;
 }
 
 ChangeStatus Attributor::rewriteFunctionSignatures(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86129.286210.patch
Type: text/x-patch
Size: 3534 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200818/b0d9edf8/attachment.bin>


More information about the llvm-commits mailing list