Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FuncSpec] Adjust the names of specializations and promoted stack val… #66685

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

labrinea
Copy link
Collaborator

…ues.

Currently the naming scheme is a bit funky; the specializations are named after the original function followed by an arbitrary decimal number. This makes it hard to debug inlined specializations of recursive functions. With this patch I am adding ".funcspec." in between of the original name and the suffix, which is now a single increment counter.

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 18, 2023

@llvm/pr-subscribers-clang-codegen
@llvm/pr-subscribers-mlir
@llvm/pr-subscribers-clang
@llvm/pr-subscribers-mlir-core
@llvm/pr-subscribers-lldb
@llvm/pr-subscribers-llvm-analysis
@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-function-specialization

Changes

…ues.

Currently the naming scheme is a bit funky; the specializations are named after the original function followed by an arbitrary decimal number. This makes it hard to debug inlined specializations of recursive functions. With this patch I am adding ".funcspec." in between of the original name and the suffix, which is now a single increment counter.


Patch is 51.12 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/66685.diff

41 Files Affected:

  • (modified) llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h (+1)
  • (modified) llvm/lib/Transforms/IPO/FunctionSpecialization.cpp (+4-3)
  • (modified) llvm/test/Transforms/FunctionSpecialization/bug55000-read-uninitialized-value.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/compiler-crash-58759.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/compiler-crash-60191.ll (+3-3)
  • (modified) llvm/test/Transforms/FunctionSpecialization/compiler-crash-promote-alloca.ll (+1-1)
  • (modified) llvm/test/Transforms/FunctionSpecialization/constant-struct.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-always-inline.ll (+1-1)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression3.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression4.ll (+1-1)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression5.ll (+1-1)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-integers.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize2.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize3.ll (+1-1)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-nodup.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-nodup2.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-noexec.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-nonconst-glob.ll (+5-5)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive2.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive3.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive4.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization.ll (+6-6)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization2.ll (+8-8)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization3.ll (+5-5)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization4.ll (+4-4)
  • (modified) llvm/test/Transforms/FunctionSpecialization/function-specialization5.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/get-possible-constants.ll (+8-8)
  • (modified) llvm/test/Transforms/FunctionSpecialization/global-rank.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/global-var-constants.ll (+3-3)
  • (modified) llvm/test/Transforms/FunctionSpecialization/identical-specializations.ll (+9-9)
  • (modified) llvm/test/Transforms/FunctionSpecialization/literal-const.ll (+12-12)
  • (modified) llvm/test/Transforms/FunctionSpecialization/no-spec-unused-arg.ll (+1-1)
  • (modified) llvm/test/Transforms/FunctionSpecialization/noinline.ll (+2-2)
  • (modified) llvm/test/Transforms/FunctionSpecialization/non-argument-tracked.ll (+12-12)
  • (modified) llvm/test/Transforms/FunctionSpecialization/promoteContantStackValues.ll (+20-20)
  • (modified) llvm/test/Transforms/FunctionSpecialization/remove-dead-recursive-function.ll (+4-4)
  • (modified) llvm/test/Transforms/FunctionSpecialization/specialization-order.ll (+6-6)
  • (modified) llvm/test/Transforms/FunctionSpecialization/specialize-multiple-arguments.ll (+9-9)
  • (modified) llvm/test/Transforms/FunctionSpecialization/track-return.ll (+12-12)
diff --git a/llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h b/llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h
index cb8fa380a3aa3f6..e17b3bb244b70b2 100644
--- a/llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h
+++ b/llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h
@@ -252,6 +252,7 @@ class FunctionSpecializer {
   SmallPtrSet<Function *, 32> FullySpecialized;
   DenseMap<Function *, CodeMetrics> FunctionMetrics;
   DenseMap<Function *, unsigned> FunctionGrowth;
+  unsigned NGlobals;
 
 public:
   FunctionSpecializer(
diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index 2c1f5f66da74bda..ec950754efdcee5 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -487,7 +487,7 @@ void FunctionSpecializer::promoteConstantStackValues(Function *F) {
 
       Value *GV = new GlobalVariable(M, ConstVal->getType(), true,
                                      GlobalValue::InternalLinkage, ConstVal,
-                                     "funcspec.arg");
+                                     "funcspec.arg." + Twine(++NGlobals));
       if (ArgOpType != ConstVal->getType())
         GV = ConstantExpr::getBitCast(cast<Constant>(GV), ArgOpType);
 
@@ -719,9 +719,10 @@ void FunctionSpecializer::removeDeadFunctions() {
 
 /// Clone the function \p F and remove the ssa_copy intrinsics added by
 /// the SCCPSolver in the cloned version.
-static Function *cloneCandidateFunction(Function *F) {
+static Function *cloneCandidateFunction(Function *F, unsigned NSpecs) {
   ValueToValueMapTy Mappings;
   Function *Clone = CloneFunction(F, Mappings);
+  Clone->setName(F->getName() + ".funcspec." + Twine(NSpecs));
   removeSSACopy(*Clone);
   return Clone;
 }
@@ -879,7 +880,7 @@ bool FunctionSpecializer::isCandidateFunction(Function *F) {
 
 Function *FunctionSpecializer::createSpecialization(Function *F,
                                                     const SpecSig &S) {
-  Function *Clone = cloneCandidateFunction(F);
+  Function *Clone = cloneCandidateFunction(F, Specializations.size() + 1);
 
   // The original function does not neccessarily have internal linkage, but the
   // clone must.
diff --git a/llvm/test/Transforms/FunctionSpecialization/bug55000-read-uninitialized-value.ll b/llvm/test/Transforms/FunctionSpecialization/bug55000-read-uninitialized-value.ll
index 0cd15384454343f..27a6711822c070c 100644
--- a/llvm/test/Transforms/FunctionSpecialization/bug55000-read-uninitialized-value.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/bug55000-read-uninitialized-value.ll
@@ -4,8 +4,8 @@ declare hidden i1 @compare(ptr) align 2
 declare hidden { i8, ptr } @getType(ptr) align 2
 
 ; CHECK-LABEL: @foo
-; CHECK-LABEL: @foo.1
-; CHECK-LABEL: @foo.2
+; CHECK-LABEL: @foo.funcspec.1
+; CHECK-LABEL: @foo.funcspec.2
 
 define internal void @foo(ptr %TLI, ptr %DL, ptr %Ty, ptr %ValueVTs, ptr %Offsets, i64 %StartingOffset) {
 entry:
diff --git a/llvm/test/Transforms/FunctionSpecialization/compiler-crash-58759.ll b/llvm/test/Transforms/FunctionSpecialization/compiler-crash-58759.ll
index 5cbfaade98d3c65..80f0ebce2d994dc 100644
--- a/llvm/test/Transforms/FunctionSpecialization/compiler-crash-58759.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/compiler-crash-58759.ll
@@ -23,5 +23,5 @@ declare i32 @p0(i32 noundef)
 declare i32 @p1(i32 noundef)
 
 ;; Tests that `f` has been fully specialize and it didn't cause compiler crash.
-;; CHECK-DAG: f.1
-;; CHECK-DAG: f.2
+;; CHECK-DAG: f.funcspec.1
+;; CHECK-DAG: f.funcspec.2
diff --git a/llvm/test/Transforms/FunctionSpecialization/compiler-crash-60191.ll b/llvm/test/Transforms/FunctionSpecialization/compiler-crash-60191.ll
index 35364c4b0ad2bea..9f9487a95d3766c 100644
--- a/llvm/test/Transforms/FunctionSpecialization/compiler-crash-60191.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/compiler-crash-60191.ll
@@ -60,7 +60,7 @@ define i32 @f2(i32 %offset) {
 }
 
 ; Tests that `func` has been specialized and it didn't cause compiler crash.
-; CHECK-DAG: func.1
-; CHECK-DAG: func.2
-; CHECK-DAG: func.3
+; CHECK-DAG: func.funcspec.1
+; CHECK-DAG: func.funcspec.2
+; CHECK-DAG: func.funcspec.3
 
diff --git a/llvm/test/Transforms/FunctionSpecialization/compiler-crash-promote-alloca.ll b/llvm/test/Transforms/FunctionSpecialization/compiler-crash-promote-alloca.ll
index fff454db303c95e..f9fb414d28a3281 100644
--- a/llvm/test/Transforms/FunctionSpecialization/compiler-crash-promote-alloca.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/compiler-crash-promote-alloca.ll
@@ -2,7 +2,7 @@
 
 ; Tests that `bar` has been specialized and that the compiler did not crash
 ; while attempting to promote the alloca in `entry`.
-; CHECK: bar.1
+; CHECK: bar.funcspec.1
 
 @block = internal constant [8 x i8] zeroinitializer, align 1
 
diff --git a/llvm/test/Transforms/FunctionSpecialization/constant-struct.ll b/llvm/test/Transforms/FunctionSpecialization/constant-struct.ll
index 6c3bfaef49b0ad5..c07e970af56eca9 100644
--- a/llvm/test/Transforms/FunctionSpecialization/constant-struct.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/constant-struct.ll
@@ -8,7 +8,7 @@ define i32 @foo(i32 %y0, i32 %y1) {
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[Y:%.*]] = insertvalue { i32, i32 } undef, i32 [[Y0:%.*]], 0
 ; CHECK-NEXT:    [[YY:%.*]] = insertvalue { i32, i32 } [[Y]], i32 [[Y1:%.*]], 1
-; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @add.1({ i32, i32 } { i32 2, i32 3 }, { i32, i32 } [[YY]])
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @add.funcspec.1({ i32, i32 } { i32 2, i32 3 }, { i32, i32 } [[YY]])
 ; CHECK-NEXT:    ret i32 [[CALL]]
 ;
 entry:
@@ -23,7 +23,7 @@ define i32 @bar(i32 %x0, i32 %x1) {
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[X:%.*]] = insertvalue { i32, i32 } undef, i32 [[X0:%.*]], 0
 ; CHECK-NEXT:    [[XX:%.*]] = insertvalue { i32, i32 } [[X]], i32 [[X1:%.*]], 1
-; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @add.2({ i32, i32 } [[XX]], { i32, i32 } { i32 3, i32 2 })
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @add.funcspec.2({ i32, i32 } [[XX]], { i32, i32 } { i32 3, i32 2 })
 ; CHECK-NEXT:    ret i32 [[CALL]]
 ;
 entry:
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-always-inline.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-always-inline.ll
index b5a0084ed52e63c..3c9f327fec47a97 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-always-inline.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-always-inline.ll
@@ -1,6 +1,6 @@
 ; RUN: opt -passes="ipsccp<func-spec>" -force-specialization -S < %s | FileCheck %s
 
-; CHECK-NOT: foo.{{[0-9]+}}
+; CHECK-NOT: foo.funcspec.{{[0-9]+}}
 
 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
 
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression.ll
index 57db1cf71a9b9ed..2e8ea190eb64ceb 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression.ll
@@ -30,10 +30,10 @@ define internal i64 @zoo(i1 %flag) {
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    br i1 [[FLAG:%.*]], label [[PLUS:%.*]], label [[MINUS:%.*]]
 ; CHECK:       plus:
-; CHECK-NEXT:    [[TMP0:%.*]] = call i64 @func2.2(ptr getelementptr inbounds ([[STRUCT:%.*]], ptr @Global, i64 0, i32 3))
+; CHECK-NEXT:    [[TMP0:%.*]] = call i64 @func2.funcspec.2(ptr getelementptr inbounds ([[STRUCT:%.*]], ptr @Global, i64 0, i32 3))
 ; CHECK-NEXT:    br label [[MERGE:%.*]]
 ; CHECK:       minus:
-; CHECK-NEXT:    [[TMP1:%.*]] = call i64 @func2.1(ptr getelementptr inbounds ([[STRUCT]], ptr @Global, i64 0, i32 4))
+; CHECK-NEXT:    [[TMP1:%.*]] = call i64 @func2.funcspec.1(ptr getelementptr inbounds ([[STRUCT]], ptr @Global, i64 0, i32 4))
 ; CHECK-NEXT:    br label [[MERGE]]
 ; CHECK:       merge:
 ; CHECK-NEXT:    [[TMP2:%.*]] = phi i64 [ ptrtoint (ptr getelementptr inbounds ([[STRUCT]], ptr @Global, i64 0, i32 3) to i64), [[PLUS]] ], [ ptrtoint (ptr getelementptr inbounds ([[STRUCT]], ptr @Global, i64 0, i32 4) to i64), [[MINUS]] ]
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression3.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression3.ll
index b1b7f1fd820d63f..78e9efd9e503bd2 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression3.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression3.ll
@@ -4,8 +4,8 @@
 define i32 @main() {
 ; CHECK-LABEL: @main(
 ; CHECK-NEXT:  bb:
-; CHECK-NEXT:    tail call void @wombat.1(ptr undef, i64 undef, i64 undef, ptr @quux)
-; CHECK-NEXT:    tail call void @wombat.2(ptr undef, i64 undef, i64 undef, ptr @eggs)
+; CHECK-NEXT:    tail call void @wombat.funcspec.1(ptr undef, i64 undef, i64 undef, ptr @quux)
+; CHECK-NEXT:    tail call void @wombat.funcspec.2(ptr undef, i64 undef, i64 undef, ptr @eggs)
 ; CHECK-NEXT:    ret i32 undef
 ;
 bb:
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression4.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression4.ll
index 9cac9ca95f8bce0..2899412b62ca4a1 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression4.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression4.ll
@@ -2,7 +2,7 @@
 
 ; Check that we don't crash and specialise on a function call with byval attribute.
 
-; CHECK-NOT: wombat.{{[0-9]+}}
+; CHECK-NOT: wombat.funcspec.{{[0-9]+}}
 
 declare ptr @quux()
 declare ptr @eggs()
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression5.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression5.ll
index c53673cf84b636f..774341a3a623809 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression5.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression5.ll
@@ -3,7 +3,7 @@
 
 ; Check that we don't crash and specialise on a scalar global variable with byval attribute.
 
-; CHECK-NOT: wombat.{{[0-9]+}}
+; CHECK-NOT: wombat.funcspec.{{[0-9]+}}
 
 %struct.pluto = type { %struct.spam }
 %struct.quux = type { i16 }
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-integers.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-integers.ll
index 976a326a4a886c1..f649eb0f402f776 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-integers.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-integers.ll
@@ -1,8 +1,8 @@
 ; RUN: opt -passes="ipsccp<func-spec>" -funcspec-for-literal-constant=true -force-specialization -S < %s | FileCheck %s
 
 ; Check that the literal constant parameter could be specialized.
-; CHECK: @foo.1(
-; CHECK: @foo.2(
+; CHECK: @foo.funcspec.1(
+; CHECK: @foo.funcspec.2(
 
 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
 
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize.ll
index 6cc35403cc4e15a..5500a047d3bf23c 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize.ll
@@ -1,7 +1,7 @@
 ; RUN: opt -passes="ipsccp<func-spec>" -S < %s | FileCheck %s
 
-; CHECK-NOT: @compute.1
-; CHECK-NOT: @compute.2
+; CHECK-NOT: @compute.funcspec.1
+; CHECK-NOT: @compute.funcspec.2
 
 define i64 @main(i64 %x, i1 %flag) {
 entry:
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize2.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize2.ll
index 2d0e04d01dc3740..8d5590c36e0cdcb 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize2.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize2.ll
@@ -3,8 +3,8 @@
 ; Checks for callsites that have been annotated with MinSize. No specialisation
 ; expected here:
 ;
-; CHECK-NOT: @compute.1
-; CHECK-NOT: @compute.2
+; CHECK-NOT: @compute.funcspec.1
+; CHECK-NOT: @compute.funcspec.2
 
 define i64 @main(i64 %x, i1 %flag) {
 entry:
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize3.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize3.ll
index 525721f03cfb251..3c4ad6207ea5853 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize3.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize3.ll
@@ -4,7 +4,7 @@
 ; specialisation for the call that does not have the attribute:
 ;
 ; CHECK: plus:
-; CHECK:   %tmp0 = call i64 @compute.1(i64 %x, ptr @plus)
+; CHECK:   %tmp0 = call i64 @compute.funcspec.1(i64 %x, ptr @plus)
 ; CHECK:   br label %merge
 ; CHECK: minus:
 ; CHECK:   %tmp1 = call i64 @compute(i64 %x, ptr @minus) #0
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-nodup.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-nodup.ll
index d9dcb44dcdb525e..1a4c79dfd747e66 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-nodup.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-nodup.ll
@@ -3,8 +3,8 @@
 ; Function @foo has function attribute 'noduplicate', so check that we don't
 ; specialize it:
 
-; CHECK-NOT: @foo.1(
-; CHECK-NOT: @foo.2(
+; CHECK-NOT: @foo.funcspec.1(
+; CHECK-NOT: @foo.funcspec.2(
 
 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
 
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-nodup2.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-nodup2.ll
index c950dfa31e4b2c4..7e24efa3e3257bc 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-nodup2.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-nodup2.ll
@@ -5,8 +5,8 @@
 ; Please note that the use of the hardwareloop intrinsic is arbitrary; it's
 ; just an easy to use intrinsic that has NoDuplicate.
 
-; CHECK-NOT: @foo.1(
-; CHECK-NOT: @foo.2(
+; CHECK-NOT: @foo.funcspec.1(
+; CHECK-NOT: @foo.funcspec.2(
 
 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
 
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-noexec.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-noexec.ll
index d1e2a77dfc19c91..7fe57e808e34e9f 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-noexec.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-noexec.ll
@@ -2,8 +2,8 @@
 
 ; The if.then block is not executed, so check that we don't specialise here.
 
-; CHECK-NOT: @foo.1(
-; CHECK-NOT: @foo.2(
+; CHECK-NOT: @foo.funcspec.1(
+; CHECK-NOT: @foo.funcspec.2(
 
 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
 
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-nonconst-glob.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-nonconst-glob.ll
index 54eed8d1346fede..5fe6bf5efce4191 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-nonconst-glob.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-nonconst-glob.ll
@@ -7,8 +7,8 @@
 ; Global B is not constant. We do not specialise on addresses unless we
 ; enable that:
 
-; ON-ADDRESS: call i32 @foo.1(i32 %x, ptr @A)
-; ON-ADDRESS: call i32 @foo.2(i32 %y, ptr @B)
+; ON-ADDRESS: call i32 @foo.funcspec.1(i32 %x, ptr @A)
+; ON-ADDRESS: call i32 @foo.funcspec.2(i32 %y, ptr @B)
 
 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
 
@@ -21,7 +21,7 @@ define dso_local i32 @bar(i32 %x, i32 %y) {
 ; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp ne i32 [[X:%.*]], 0
 ; CHECK-NEXT:    br i1 [[TOBOOL]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
 ; CHECK:       if.then:
-; CHECK-NEXT:    [[CALL:%.*]] = call i32 @foo.1(i32 [[X]], ptr @A)
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @foo.funcspec.1(i32 [[X]], ptr @A)
 ; CHECK-NEXT:    br label [[RETURN:%.*]]
 ; CHECK:       if.else:
 ; CHECK-NEXT:    [[CALL1:%.*]] = call i32 @foo(i32 [[Y:%.*]], ptr @B)
@@ -60,11 +60,11 @@ entry:
   ret i32 %add
 }
 
-; CHECK-LABEL: define internal i32 @foo.1(i32 %x, ptr %b) {
+; CHECK-LABEL: define internal i32 @foo.funcspec.1(i32 %x, ptr %b) {
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    %0 = load i32, ptr @A, align 4
 ; CHECK-NEXT:    %add = add nsw i32 %x, %0
 ; CHECK-NEXT:    ret i32 %add
 ; CHECK-NEXT:  }
 
-; CHECK-NOT: define internal i32 @foo.2(
+; CHECK-NOT: define internal i32 @foo.funcspec.2(
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive2.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive2.ll
index 9c7d3b22c917d89..7423ae5dc73fa9e 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive2.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive2.ll
@@ -2,8 +2,8 @@
 
 ; Volatile store preventing recursive specialisation:
 ;
-; CHECK:     @recursiveFunc.1
-; CHECK-NOT: @recursiveFunc.2
+; CHECK:     @recursiveFunc.funcspec.1
+; CHECK-NOT: @recursiveFunc.funcspec.2
 
 @Global = internal constant i32 1, align 4
 
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive3.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive3.ll
index 633138721e5540a..5a564998fd0410e 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive3.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive3.ll
@@ -2,8 +2,8 @@
 
 ; Duplicate store preventing recursive specialisation:
 ;
-; CHECK:     @recursiveFunc.1
-; CHECK-NOT: @recursiveFunc.2
+; CHECK:     @recursiveFunc.funcspec.1
+; CHECK-NOT: @recursiveFunc.funcspec.2
 
 @Global = internal constant i32 1, align 4
 
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive4.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive4.ll
index 6dca04c17bf4dca..e47e2eaf3df3716 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive4.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive4.ll
@@ -2,8 +2,8 @@
 
 ; Alloca is not an integer type:
 ;
-; CHECK:     @recursiveFunc.1
-; CHECK-NOT: @recursiveFunc.2
+; CHECK:     @recursiveFunc.funcspec.1
+; CHECK-NOT: @recursiveFunc.funcspec.2
 
 @Global = internal constant i32 1, align 4
 
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization.ll
index b5d16f6dab1c05c..306ac3d96ab2d21 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization.ll
@@ -7,10 +7,10 @@ define i64 @main(i64 %x, i1 %flag) {
 ; CHECK:      entry:
 ; CHECK-NEXT:   br i1 %flag, label %plus, label %minus
 ; CHECK:      plus:
-; CHECK-NEXT:   [[TMP0:%.+]] = call i64 @compute.1(i64 %x, ptr @plus)
+; CHECK-NEXT:   [[TMP0:%.+]] = call i64 @compute.funcspec.1(i64 %x, ptr @plus)
 ; CHECK-NEXT:   br label %merge
 ; CHECK:      minus:
-; CHECK-NEXT:   [[TMP1:%.+]] = call i64 @compute.2(i64 %x, ptr @minus)
+; CHECK-NEXT:   [[TMP1:%.+]] = call i64 @compute.funcspec.2(i64 %x, ptr @minus)
 ; CHECK-NEXT:   br label %merge
 ; CHECK:      merge:
 ; CHECK-NEXT:   [[TMP2:%.+]] = phi i64 [ [[TMP0]], %plus ], [ [[TMP1]], %minus ]
@@ -18,7 +18,7 @@ define i64 @main(i64 %x, i1 %flag) {
 ; CHECK-NEXT: }
 ;
 ; NOFSPEC-LABEL: @main(i64 %x, i1 %flag) {
-; NOFSPEC-NOT: call i64 @compute.{{[0-...
[truncated]

Copy link
Member

@ChuanqiXu9 ChuanqiXu9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I prefer specialized than funcspec.

LGTM with initializing the member variable.

llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h Outdated Show resolved Hide resolved
…ues.

Currently the naming scheme is a bit funky; the specializations are named
after the original function followed by an arbitrary decimal number. This
makes it hard to debug inlined specializations of recursive functions.
With this patch I am adding ".specialized." in between of the original
name and the suffix, which is now a single increment counter.
@llvmbot llvmbot added lldb llvm:analysis clang Clang issues not falling into any other category clang:codegen mlir:core MLIR Core Infrastructure mlir labels Sep 19, 2023
@labrinea labrinea removed clang Clang issues not falling into any other category lldb clang:codegen mlir:core MLIR Core Infrastructure mlir llvm:analysis labels Sep 19, 2023
@labrinea labrinea merged commit e15d72a into llvm:main Sep 19, 2023
7 of 9 checks passed
@labrinea labrinea deleted the funcspec branch September 19, 2023 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants