[PATCH] D104373: [FuncSpec] Option for specializing const globals and function pointers.

Sjoerd Meijer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 16 05:55:17 PDT 2021


SjoerdMeijer created this revision.
SjoerdMeijer added reviewers: ChuanqiXu, fhahn.
Herald added subscribers: ormris, hiraditya.
SjoerdMeijer requested review of this revision.
Herald added a project: LLVM.

In anticipation of D104365 <https://reviews.llvm.org/D104365> that adds support for constant integers, this adds and option to enable specialisation for constant globals and function pointers. This more fine grain control may also be useful for testing.


https://reviews.llvm.org/D104373

Files:
  llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
  llvm/test/Transforms/FunctionSpecialization/function-specialization3.ll


Index: llvm/test/Transforms/FunctionSpecialization/function-specialization3.ll
===================================================================
--- llvm/test/Transforms/FunctionSpecialization/function-specialization3.ll
+++ llvm/test/Transforms/FunctionSpecialization/function-specialization3.ll
@@ -1,6 +1,8 @@
 ; RUN: opt -function-specialization -func-specialization-avg-iters-cost=3 -S < %s | \
 ; RUN:   FileCheck %s --check-prefixes=COMMON,DISABLED
-; RUN: opt -function-specialization -force-function-specialization -S < %s | \
+; RUN: opt -function-specialization -force-function-specialization -function-specialization-const-globals=0 -S < %s | \
+; RUN:   FileCheck %s --check-prefixes=COMMON,DISABLED
+; RUN: opt -function-specialization -force-function-specialization -function-specialization-const-globals=1 -S < %s | \
 ; RUN:   FileCheck %s --check-prefixes=COMMON,FORCE
 ; RUN: opt -function-specialization -func-specialization-avg-iters-cost=3 -force-function-specialization -S < %s | \
 ; RUN:   FileCheck %s --check-prefixes=COMMON,FORCE
Index: llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -64,6 +64,11 @@
                           cl::desc("Average loop iteration count cost"),
                           cl::init(10));
 
+static cl::opt<bool> SpecializeConstGlobals(
+    "function-specialization-const-globals", cl::init(true), cl::Hidden,
+    cl::desc("Enable function specialization for constant globals and function "
+             "pointers"));
+
 // Helper to check if \p LV is either overdefined or a constant int.
 static bool isOverdefined(const ValueLatticeElement &LV) {
   return !LV.isUnknownOrUndef() && !LV.isConstant();
@@ -485,8 +490,9 @@
         continue;
       }
 
-      // Add the constant to the set.
-      if (auto *C = dyn_cast<Constant>(CS.getArgOperand(A->getArgNo())))
+      // Add the constant global or function pointer to the set.
+      auto *C = dyn_cast<Constant>(CS.getArgOperand(A->getArgNo()));
+      if (C && SpecializeConstGlobals)
         Constants.push_back(C);
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104373.352409.patch
Type: text/x-patch
Size: 2230 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210616/a98c0b89/attachment-0001.bin>


More information about the llvm-commits mailing list