diff --git a/0017-Add-BiSheng-Autotuner-support-for-LLVM-compiler-testcases.patch b/0017-Add-BiSheng-Autotuner-support-for-LLVM-compiler-testcases.patch new file mode 100644 index 0000000000000000000000000000000000000000..d902a45350c3e171c929042bbe47ae0f8d81704e --- /dev/null +++ b/0017-Add-BiSheng-Autotuner-support-for-LLVM-compiler-testcases.patch @@ -0,0 +1,936 @@ +diff --git a/clang/test/Autotuning/BaselineConfig/Inputs/autotune_datadir/baseline-config.yaml b/clang/test/Autotuning/BaselineConfig/Inputs/autotune_datadir/baseline-config.yaml +new file mode 100644 +index 000000000000..a5e669c17a71 +--- /dev/null ++++ b/clang/test/Autotuning/BaselineConfig/Inputs/autotune_datadir/baseline-config.yaml +@@ -0,0 +1,9 @@ ++!AutoTuning {Args: [{UnrollCount: 0}], CodeRegionHash: 12835463591102937421, ++ CodeRegionType: loop, Function: test, Invocation: 0, Name: for.body, ++ Pass: loop-unroll} ++--- !AutoTuning {Args: [{VectorizationInterleave: 2}], ++ CodeRegionHash: 12835463591102937421, CodeRegionType: loop, Function: test, ++ Invocation: 0, Name: for.body, Pass: loop-vectorize} ++--- !AutoTuning {Args: [{UnrollCount: 0}], CodeRegionHash: 8430337282115614432, ++ CodeRegionType: loop, Function: test, Invocation: 1, Name: vector.body, ++ Pass: loop-unroll} +diff --git a/clang/test/Autotuning/BaselineConfig/Inputs/autotune_datadir/random-config.yaml b/clang/test/Autotuning/BaselineConfig/Inputs/autotune_datadir/random-config.yaml +new file mode 100644 +index 000000000000..b0c338d26a7c +--- /dev/null ++++ b/clang/test/Autotuning/BaselineConfig/Inputs/autotune_datadir/random-config.yaml +@@ -0,0 +1,9 @@ ++!AutoTuning {Args: [{UnrollCount: 0}], CodeRegionHash: 12835463591102937421, ++ CodeRegionType: loop, Function: test, Invocation: 0, Name: for.body, ++ Pass: loop-unroll} ++--- !AutoTuning {Args: [{VectorizationInterleave: 2}], ++ CodeRegionHash: 12835463591102937421, CodeRegionType: loop, Function: test, ++ Invocation: 0, Name: for.body, Pass: loop-vectorize} ++--- !AutoTuning {Args: [{UnrollCount: 2}], CodeRegionHash: 8430337282115614432, ++ CodeRegionType: loop, Function: test, Invocation: 1, Name: vector.body, ++ Pass: loop-unroll} +diff --git a/clang/test/Autotuning/BaselineConfig/apply-baseline-config.c b/clang/test/Autotuning/BaselineConfig/apply-baseline-config.c +new file mode 100644 +index 000000000000..b110d6756b26 +--- /dev/null ++++ b/clang/test/Autotuning/BaselineConfig/apply-baseline-config.c +@@ -0,0 +1,32 @@ ++// Check that the baseline IR is the same as the IR from the first iteration of ++// the autotuning process with --use-baseline-config enabled. ++// REQUIRES: ! host-x86_64 ++ ++// RUN: rm -f %t.baseline %t.firstIt_baseline %t.firstIt_random ++// RUN: %clang -O3 %s -c -o %t.baseline ++// RUN: strip %t.baseline ++// RUN: %clang -O3 %s -c -o %t.firstIt_baseline -mllvm \ ++// RUN: -auto-tuning-input=%S/Inputs/autotune_datadir/baseline-config.yaml \ ++// RUN: -mllvm -auto-tuning-omit-metadata ++// RUN: strip %t.firstIt_baseline ++// RUN: cmp %t.firstIt_baseline %t.baseline ++ ++// RUN: %clang -O3 %s -c -o %t.firstIt_random -mllvm \ ++// RUN: -auto-tuning-input=%S/Inputs/autotune_datadir/random-config.yaml \ ++// RUN: -mllvm -auto-tuning-omit-metadata ++// RUN: strip %t.firstIt_random ++// RUN: not cmp %t.firstIt_random %t.baseline ++ ++#include ++#include ++ ++void test() { ++ int cs = 128370 * 1024 / sizeof(double); ++ double *flush = (double *)calloc(cs, sizeof(double)); ++ int i; ++ double tmp = 0.0; ++ for (i = 0; i < cs; i++) ++ tmp += flush[i]; ++ assert(tmp <= 10.0); ++ free(flush); ++} +diff --git a/clang/test/Autotuning/Driver/Inputs/config.yaml b/clang/test/Autotuning/Driver/Inputs/config.yaml +new file mode 100644 +index 000000000000..6420c52c1a8a +--- /dev/null ++++ b/clang/test/Autotuning/Driver/Inputs/config.yaml +@@ -0,0 +1,3 @@ ++!AutoTuning {Args: [{UnrollCount: 2}], CodeRegionType: loop, DebugLoc: { ++ Column: 5, File: clang/test/Autotuning/LoopDump/multiple_loops.c, Line: 21}, ++ Function: sum1d, Name: for.body, Pass: loop-unroll} +diff --git a/clang/test/Autotuning/Driver/Inputs/template.yaml b/clang/test/Autotuning/Driver/Inputs/template.yaml +new file mode 100644 +index 000000000000..a98a7c758d5e +--- /dev/null ++++ b/clang/test/Autotuning/Driver/Inputs/template.yaml +@@ -0,0 +1,9 @@ ++--- !AutoTuning ++Pass: pass-name ++Name: opp-name ++Function: func ++CodeRegionType: [type] ++CodeRegionHash: 4250615281180658289 ++Args: ++ - DummyOption: true ++... +diff --git a/clang/test/Autotuning/Driver/autotune-generate-pipeline.c b/clang/test/Autotuning/Driver/autotune-generate-pipeline.c +new file mode 100644 +index 000000000000..66276f11eb57 +--- /dev/null ++++ b/clang/test/Autotuning/Driver/autotune-generate-pipeline.c +@@ -0,0 +1,146 @@ ++// Verify if -fautotune-generate can be invoked properly ++ ++// RUN: %clang -fautotune-generate -O1 --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | FileCheck \ ++// RUN: %s --check-prefix=GENERATE-DEFAULT ++ ++// RUN: AUTOTUNE_DATADIR=/tmp/test_autotune_datadir/ %clang -fautotune-generate -O1 --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | FileCheck \ ++// RUN: %s --check-prefix=GENERATE-ENV-VAR ++ ++// RUN: %clang -fautotune-generate -O1 -flto -fuse-ld=lld --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | FileCheck \ ++// RUN: %s --check-prefix=GENERATE-LTO-DEFAULT ++ ++// RUN: AUTOTUNE_DATADIR=/tmp/test_autotune_datadir/ %clang -fautotune-generate -O1 -flto -fuse-ld=lld --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | FileCheck \ ++// RUN: %s --check-prefix=GENERATE-LTO-ENV-VAR ++ ++// RUN: %clang -fautotune-generate -O0 --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | FileCheck \ ++// RUN: %s --check-prefix=ERROR-O0 ++ ++// RUN: %clang -fautotune-generate -O1 -flto --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | FileCheck \ ++// RUN: %s --check-prefix=ERROR-LTO-WITHOUT-LLD ++ ++// RUN: export AUTOTUNE_MODE=-fautotune-generate ++// RUN: %clang -O1 --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=GENERATE-DEFAULT ++ ++// RUN: %clang -fautotune-generate -O1 -c -flto %s -### \ ++// RUN: --sysroot %S/Inputs/basic_cross_linux_tree 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=LTO-COMPILE-ONLY ++ ++// RUN: %clang -fautotune-generate -O1 -c -flto %s -v -o %t.tmp.o 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=LTO-COMPILE-ONLY ++ ++// RUN: not %clang -fautotune-generate -O1 -flto -v %t.tmp.o 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=ERROR-LTO-WITHOUT-LLD ++ ++// RUN: %clang -fautotune-generate -O1 -flto -v %t.tmp.o -fuse-ld=lld 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=LTO-LINK-ONLY ++ ++// RUN: export AUTOTUNE_MODE=-fautotune-generate ++// RUN: AUTOTUNE_DATADIR=/tmp/test_autotune_datadir/ %clang -O1 --sysroot \ ++// RUN: %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=GENERATE-ENV-VAR ++ ++// RUN: export AUTOTUNE_MODE=-fautotune-generate ++// RUN: %clang -O1 -flto -fuse-ld=lld --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=GENERATE-LTO-DEFAULT ++ ++// RUN: export AUTOTUNE_MODE=-fautotune-generate ++// RUN: AUTOTUNE_DATADIR=/tmp/test_autotune_datadir/ %clang -O1 -flto -fuse-ld=lld \ ++// RUN: --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=GENERATE-LTO-ENV-VAR ++ ++// RUN: export AUTOTUNE_MODE=-fautotune-generate ++// RUN: %clang -O0 --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=ERROR-O0 ++ ++// RUN: export AUTOTUNE_MODE=-fautotune-generate ++// RUN: %clang -O1 -flto --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=ERROR-LTO-WITHOUT-LLD ++ ++// RUN: %clang -fautotune-generate -c -O1 -flto=thin -fuse-ld=lld --sysroot \ ++// RUN: %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=GENERATE-THIN-SUCCESS1 ++ ++// RUN: %clang -fautotune-generate=LLVMParam -O1 -flto=thin -fuse-ld=lld \ ++// RUN: --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=GENERATE-THIN-SUCCESS2 ++ ++// RUN: %clang -fautotune-generate -O1 -flto=thin -fuse-ld=lld --sysroot \ ++// RUN: %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefixes=GENERATE-THIN-FAIL1 ++ ++// RUN: %clang -fautotune-generate=Loop -O1 -flto=thin -fuse-ld=lld --sysroot \ ++// RUN: %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefixes=GENERATE-THIN-FAIL2 ++ ++int main() { return 0; } ++ ++// GENERATE-DEFAULT: {{clang.* "-cc1"}} ++// GENERATE-DEFAULT-SAME: -debug-info-kind=line-tables-only ++// GENERATE-DEFAULT-SAME: -auto-tuning-opp=autotune_datadir/opp ++// GENERATE-DEFAULT-SAME: -auto-tuning-type-filter=CallSite,Function,Loop ++// GENERATE-DEFAULT: ld ++// GENERATE-DEFAULT-NOT: -auto-tuning-opp=autotune_datadir/opp ++// GENERATE-DEFAULT-NOT: -auto-tuning-type-filter=CallSite,Function,Loop ++ ++// GENERATE-ENV-VAR: {{clang.* "-cc1"}} ++// GENERATE-ENV-VAR-SAME: -auto-tuning-opp=/tmp/test_autotune_datadir/opp ++// GENERATE-ENV-VAR-SAME: -auto-tuning-type-filter=CallSite,Function,Loop ++ ++// GENERATE-LTO-DEFAULT: {{clang.* "-cc1"}} ++// GENERATE-LTO-DEFAULT-SAME: -debug-info-kind=line-tables-only ++// GENERATE-LTO-DEFAULT: -auto-tuning-opp=autotune_datadir/opp ++// GENERATE-LTO-DEFAULT: -auto-tuning-type-filter=CallSite,Function,Loop ++// GENERATE-LTO-DEFAULT: ld.lld ++// GENERATE-LTO-DEFAULT-SAME: -auto-tuning-opp=autotune_datadir/opp ++// GENERATE-LTO-DEFAULT-SAME: -auto-tuning-type-filter=CallSite,Function,Loop ++ ++// GENERATE-LTO-ENV-VAR: {{clang.* "-cc1"}} ++// GENERATE-LTO-ENV-VAR: -auto-tuning-opp=/tmp/test_autotune_datadir/opp ++// GENERATE-LTO-ENV-VAR: -auto-tuning-type-filter=CallSite,Function,Loop ++// GENERATE-LTO-ENV-VAR: ld.lld ++// GENERATE-LTO-ENV-VAR-SAME: -auto-tuning-opp=/tmp/test_autotune_datadir/opp ++// GENERATE-LTO-ENV-VAR-SAME: -auto-tuning-type-filter=CallSite,Function,Loop ++ ++// ERROR-O0: error: -fautotune/-fautotune-generate should not be enabled at -O0 ++ ++// ERROR-LTO-WITHOUT-LLD: error: LTO requires -fuse-ld=lld ++ ++// GENERATE-THIN-SUCCESS1-NOT: error ++// GENERATE-THIN-SUCCESS1: {{clang.* "-cc1"}} ++// GENERATE-THIN-SUCCESS1-SAME: -auto-tuning-type-filter=CallSite,Function,Loop ++// GENERATE-THIN-SUCCESS1-NOT: "{{.*}}ld.lld" ++ ++// GENERATE-THIN-SUCCESS2-NOT: error: ++// GENERATE-THIN-SUCCESS2: {{clang.* "-cc1"}} ++// GENERATE-THIN-SUCCESS2-SAME: -auto-tuning-type-filter=LLVMParam ++// GENERATE-THIN-SUCCESS2: "{{.*}}ld.lld" ++// GENERATE-THIN-SUCCESS2-SAME: -auto-tuning-type-filter=LLVMParam ++ ++// GENERATE-THIN-FAIL1: error: AutoTuner: no valid code region type specified ++// GENERATE-THIN-FAIL1-SAME: for ThinLTO mode ++// GENERATE-THIN-FAIL1: {{clang.* "-cc1"}} ++// GENERATE-THIN-FAIL1-SAME: -auto-tuning-type-filter=CallSite,Function,Loop ++// GENERATE-THIN-FAIL1: "{{.*}}ld.lld" ++// GENERATE-THIN-FAIL1-SAME: -auto-tuning-type-filter=CallSite,Function,Loop ++ ++// GENERATE-THIN-FAIL2: error: fine-grained autotuning not supported in ThinLTO ++// GENERATE-THIN-FAIL2-SAME: mode ++// GENERATE-THIN-FAIL2-NEXT: error: unsupported argument 'Loop' to option ++// GENERATE-THIN-FAIL2-SAME: 'fautotune-generate=' ++// GENERATE-THIN-FAIL2: {{clang.* "-cc1"}} ++// GENERATE-THIN-FAIL2-SAME: -auto-tuning-type-filter=Loop ++// GENERATE-THIN-FAIL2: "{{.*}}ld.lld" ++// GENERATE-THIN-FAIL2-SAME: -auto-tuning-type-filter= ++ ++// LTO-COMPILE-ONLY: {{clang.*-cc1}} ++// LTO-COMPILE-ONLY-SAME: -debug-info-kind=line-tables-only ++// LTO-COMPILE-ONLY-SAME: -auto-tuning-opp=autotune_datadir/opp ++// LTO-COMPILE-ONLY-SAME: -auto-tuning-type-filter=CallSite,Function,Loop ++// LTO-COMPILE-ONLY-NOT: ld.lld ++// LTO-COMPILE-ONLY-NOT: error: LTO requires -fuse-ld=lld ++ ++// LTO-LINK-ONLY-NOT: {{clang.*-cc1}} ++// LTO-LINK-ONLY: ld.lld ++// LTO-LINK-ONLY-SAME: -auto-tuning-opp=autotune_datadir/opp ++// LTO-LINK-ONLY-SAME: -auto-tuning-type-filter=CallSite,Function,Loop +diff --git a/clang/test/Autotuning/Driver/autotune-pipeline-thin-lto.c b/clang/test/Autotuning/Driver/autotune-pipeline-thin-lto.c +new file mode 100644 +index 000000000000..2ecc40e6f8d9 +--- /dev/null ++++ b/clang/test/Autotuning/Driver/autotune-pipeline-thin-lto.c +@@ -0,0 +1,42 @@ ++// REQUIRES: asserts ++ ++// RUN: rm -rf %t.data_dir ++// RUN: export AUTOTUNE_DATADIR=%t.data_dir ++// RUN: mkdir $AUTOTUNE_DATADIR ++ ++// RUN: sed 's#\[type\]#loop#g' %S/Inputs/template.yaml > \ ++// RUN: %t.data_dir/config.yaml ++// RUN: %clang -O3 %s -flto=thin -fautotune -mllvm -debug-only=autotuning \ ++// RUN: -fuse-ld=lld -Wl,-mllvm,-debug-only=autotuning 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=AUTOTUNE-CR-LOOP ++ ++// RUN: sed 's#\[type\]#llvm-param#g' %S/Inputs/template.yaml > \ ++// RUN: %t.data_dir/config.yaml ++// RUN: %clang -O3 %s -flto=thin -fautotune -mllvm -debug-only=autotuning \ ++// RUN: -fuse-ld=lld -Wl,-mllvm,-debug-only=autotuning 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=AUTOTUNE-CR-PARAM ++ ++#include ++#include ++ ++int main() { ++ int cs = 128370 * 1024 / sizeof(double); ++ double *flush = (double *)calloc(cs, sizeof(double)); ++ int i; ++ double tmp = 0.0; ++ for (i = 0; i < cs; i++) ++ tmp += flush[i]; ++ assert(tmp <= 10.0); ++ free(flush); ++ return tmp; ++} ++ ++// AUTOTUNE-CR-LOOP-NOT: AutoTuner does not support tuning of {{.*}} thinLTO ++// AUTOTUNE-CP-LOOP-NEXT: AutoTuningEngine is initialized. ++// AUTOTUNE-CR-LOOP: AutoTuner does not support tuning of {{.*}} thinLTO ++// AUTOTUNE-CP-LOOP-NEXT: AutoTuningEngine is initialized. ++ ++// AUTOTUNE-CR-PARAM-NOT: AutoTuner does not support tuning of {{.*}} thinLTO ++// AUTOTUNE-CP-PARAM-NEXT: AutoTuningEngine is initialized. ++// AUTOTUNE-CR-PARAM-NOT: AutoTuner does not support tuning of {{.*}} thinLTO ++// AUTOTUNE-CP-PARAM-NEXT: AutoTuningEngine is initialized. +diff --git a/clang/test/Autotuning/Driver/autotune-pipeline.c b/clang/test/Autotuning/Driver/autotune-pipeline.c +new file mode 100644 +index 000000000000..2247c9cf5bd3 +--- /dev/null ++++ b/clang/test/Autotuning/Driver/autotune-pipeline.c +@@ -0,0 +1,131 @@ ++// Verify if -fautotune can be invoked properly ++ ++// RUN: %clang -fautotune -O1 --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | FileCheck \ ++// RUN: %s --check-prefix=AUTOTUNE-DEFAULT ++ ++// RUN: %clang -fautotune=0 -O1 --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | FileCheck \ ++// RUN: %s --check-prefix=AUTOTUNE-DEFAULT-ID0 ++ ++// RUN: AUTOTUNE_DATADIR=/tmp/test_autotune_datadir/ %clang -fautotune=1 -O1 --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | FileCheck \ ++// RUN: %s --check-prefix=AUTOTUNE-ENV-VAR-ID1 ++ ++// RUN: %clang -fautotune -O1 -flto -fuse-ld=lld --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | FileCheck \ ++// RUN: %s --check-prefix=AUTOTUNE-LTO-DEFAULT ++ ++// RUN: AUTOTUNE_DATADIR=/tmp/test_autotune_datadir/ %clang -fautotune -O1 -flto -fuse-ld=lld --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | FileCheck \ ++// RUN: %s --check-prefix=AUTOTUNE-LTO-ENV-VAR ++ ++// RUN: %clang -fautotune -O0 --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | FileCheck \ ++// RUN: %s --check-prefix=ERROR-O0 ++ ++// RUN: %clang -fautotune -O1 -flto --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | FileCheck \ ++// RUN: %s --check-prefix=ERROR-LTO-WITHOUT-LLD ++ ++// RUN: %clang -fautotune=test -O1 --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | FileCheck \ ++// RUN: %s --check-prefix=ERROR-NON-INTEGER-ID ++// RUN: %clang -fautotune -O1 -c -flto %s -### \ ++// RUN: --sysroot %S/Inputs/basic_cross_linux_tree 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=LTO-COMPILE-ONLY ++ ++// RUN: mkdir -p %T.tmp/Output ++// RUN: cp %S/Inputs/config.yaml %T.tmp/Output ++// RUN: env AUTOTUNE_DATADIR=%T.tmp/Output \ ++// RUN: %clang -fautotune -O1 -c -flto %s -v -o %t.tmp.o 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=LTO-COMPILE-ONLY ++ ++// RUN: env AUTOTUNE_DATADIR=%T.tmp/Output \ ++// RUN: not %clang -fautotune -O1 -flto -v %t.tmp.o 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=ERROR-LTO-WITHOUT-LLD ++ ++// RUN: env AUTOTUNE_DATADIR=%T.tmp/Output \ ++// RUN: %clang -fautotune -O1 -flto -v %t.tmp.o -fuse-ld=lld 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=LTO-LINK-ONLY ++ ++// RUN: export AUTOTUNE_MODE=-fautotune ++// RUN: %clang -O1 --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=AUTOTUNE-DEFAULT ++ ++// RUN: export AUTOTUNE_MODE=-fautotune=0 ++// RUN: %clang -O1 --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=AUTOTUNE-DEFAULT-ID0 ++ ++// RUN: export AUTOTUNE_MODE=-fautotune=1 ++// RUN: AUTOTUNE_DATADIR=/tmp/test_autotune_datadir/ %clang -O1 --sysroot \ ++// RUN: %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=AUTOTUNE-ENV-VAR-ID1 ++ ++// RUN: export AUTOTUNE_MODE=-fautotune ++// RUN: %clang -O1 -flto -fuse-ld=lld --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=AUTOTUNE-LTO-DEFAULT ++ ++// RUN: export AUTOTUNE_MODE=-fautotune ++// RUN: AUTOTUNE_DATADIR=/tmp/test_autotune_datadir/ %clang -O1 -flto -fuse-ld=lld \ ++// RUN: --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=AUTOTUNE-LTO-ENV-VAR ++ ++// RUN: export AUTOTUNE_MODE=-fautotune ++// RUN: %clang -O0 --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=ERROR-O0 ++ ++// RUN: export AUTOTUNE_MODE=-fautotune ++// RUN: %clang -O1 -flto --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=ERROR-LTO-WITHOUT-LLD ++ ++// RUN: export AUTOTUNE_MODE=-fautotune=test ++// RUN: %clang -O1 --sysroot %S/Inputs/basic_cross_linux_tree -### %s 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=ERROR-NON-INTEGER-ID ++ ++// RUN: env AUTOTUNE_MODE=-fautotune \ ++// RUN: %clang -O1 --sysroot %S/Inputs/basic_cross_linux_tree -### %s \ ++// RUN: -flto=thin -fuse-ld=lld 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=AUTOTUNE-THIN-DEFAULT ++ ++int main() { return 0; } ++ ++// AUTOTUNE-DEFAULT: {{clang.* "-cc1"}} ++// AUTOTUNE-DEFAULT-SAME: -debug-info-kind=line-tables-only ++// AUTOTUNE-DEFAULT-SAME: -auto-tuning-input=autotune_datadir/config.yaml ++// AUTOTUNE-DEFAULT: ld ++// AUTOTUNE-DEFAULT-NOT: -auto-tuning-opp=autotune_datadir/opp ++// AUTOTUNE-DEFAULT-NOT: -auto-tuning-type-filter=CallSite,Function,Loop ++ ++// AUTOTUNE-ENV-VAR: {{clang.* "-cc1"}} ++// AUTOTUNE-ENV-VAR-SAME: -auto-tuning-input=/tmp/test_autotune_datadir/config.yaml ++ ++// AUTOTUNE-DEFAULT-ID0: {{clang.* "-cc1"}} ++// AUTOTUNE-DEFAULT-ID0-SAME: -auto-tuning-input=autotune_datadir/config-0.yaml ++ ++// AUTOTUNE-ENV-VAR-ID1: {{clang.* "-cc1"}} ++// AUTOTUNE-ENV-VAR-ID1-SAME: -auto-tuning-input=/tmp/test_autotune_datadir/config-1.yaml ++ ++// AUTOTUNE-LTO-DEFAULT: {{clang.* "-cc1"}} ++// AUTOTUNE-LTO-DEFAULT-SAME: -debug-info-kind=line-tables-only ++// AUTOTUNE-LTO-DEFAULT-SAME: -auto-tuning-input=autotune_datadir/config.yaml ++// AUTOTUNE-LTO-DEFAULT: ld.lld ++// AUTOTUNE-LTO-DEFAULT-SAME: -auto-tuning-input=autotune_datadir/config.yaml ++ ++// AUTOTUNE-LTO-ENV-VAR: {{clang.* "-cc1"}} ++// AUTOTUNE-LTO-ENV-VAR-SAME: -auto-tuning-input=/tmp/test_autotune_datadir/config.yaml ++// AUTOTUNE-LTO-ENV-VAR: ld.lld ++// AUTOTUNE-LTO-ENV-VAR-SAME: -auto-tuning-input=/tmp/test_autotune_datadir/config.yaml ++ ++// ERROR-O0: error: -fautotune/-fautotune-generate should not be enabled at -O0 ++// ERROR-LTO-WITHOUT-LLD: error: LTO requires -fuse-ld=lld ++// ERROR-NON-INTEGER-ID: error: invalid integral value 'test' in '-fautotune=test' ++ ++// AUTOTUNE-THIN-DEFAULT: {{clang.* "-cc1"}} ++// AUTOTUNE-THIN-DEFAULT-SAME: -debug-info-kind=line-tables-only ++// AUTOTUNE-THIN-DEFAULT-SAME: -auto-tuning-input=autotune_datadir/config.yaml ++// AUTOTUNE-THIN-DEFAULT: "{{.*}}ld.lld" ++// AUTOTUNE-THIN-DEFAULT-SAME: -auto-tuning-input=autotune_datadir/config.yaml ++// AUTOTUNE-THIN-DEFAULT-SAME: -autotuning-thin-lto=true ++ ++// LTO-COMPILE-ONLY: {{clang.*-cc1}} ++// LTO-COMPILE-ONLY-SAME: -debug-info-kind=line-tables-only ++// LTO-COMPILE-ONLY-SAME: -auto-tuning-input={{.*}}/config.yaml ++// LTO-COMPILE-ONLY-NOT: ld.lld ++// LTO-COMPILE-ONLY-NOT: error: LTO requires -fuse-ld=lld ++ ++// LTO-LINK-ONLY-NOT: {{clang.*-cc1}} ++// LTO-LINK-ONLY: ld.lld ++// LTO-LINK-ONLY-SAME: -auto-tuning-input={{.*}}/config.yaml +diff --git a/clang/test/Autotuning/GenerateOpp/generate.cpp b/clang/test/Autotuning/GenerateOpp/generate.cpp +new file mode 100644 +index 000000000000..e6f5a3e986f4 +--- /dev/null ++++ b/clang/test/Autotuning/GenerateOpp/generate.cpp +@@ -0,0 +1,25 @@ ++// RUN: rm -rf %t.other ++// RUN: export AUTOTUNE_DATADIR=%t.other ++ ++// Test coarse-grain code region generation process and 'Name' field have ++// complete path. ++// RUN: %clang %s -S -O3 -fautotune-generate=Other -o - ++// RUN: grep "Name: \+'%S/generate.cpp'" %t.other/opp/generate.cpp.yaml ++// RUN: not grep "Name: \+generate.cpp" %t.other/opp/generate.cpp.yaml ++ ++// Use environment variable 'AUTOTUNE_PROJECT_DIR' to truncate the complete ++// prefix and only use filename as 'Name' field for code region. ++// RUN: rm -rf %t.other ++// RUN: export AUTOTUNE_PROJECT_DIR=%S/ ++// RUN: %clang %s -S -O3 -fautotune-generate=Other -o - ++// RUN: not grep "Name: \+'%S/generate.cpp'" %t.other/opp/generate.cpp.yaml ++// RUN: grep "Name: \+generate.cpp" %t.other/opp/generate.cpp.yaml ++ ++// A simple cpp file. ++int main() { ++ int i = 8; ++ for (; i < 20;) { ++ int a = i - 5; ++ i = i + 2; ++ } ++} +diff --git a/clang/test/Autotuning/IncrementalCompilation/Inputs/template.yaml b/clang/test/Autotuning/IncrementalCompilation/Inputs/template.yaml +new file mode 100644 +index 000000000000..a7d390be63e7 +--- /dev/null ++++ b/clang/test/Autotuning/IncrementalCompilation/Inputs/template.yaml +@@ -0,0 +1,9 @@ ++--- !AutoTuning ++Pass: [dummy-pass] ++CodeRegionType: [dummy-type] ++Name: foo ++DebugLoc: { File: [dummy-file], Line: 0, Column: 0 } ++Function: foo ++CodeRegionHash: 0 ++Invocation: 0 ++... +diff --git a/clang/test/Autotuning/IncrementalCompilation/Inputs/test1.c b/clang/test/Autotuning/IncrementalCompilation/Inputs/test1.c +new file mode 100644 +index 000000000000..4aae331b262e +--- /dev/null ++++ b/clang/test/Autotuning/IncrementalCompilation/Inputs/test1.c +@@ -0,0 +1,3 @@ ++// No AutoTuning opportunity. ++ ++void test() { return; } +\ No newline at end of file +diff --git a/clang/test/Autotuning/IncrementalCompilation/Inputs/test2.c b/clang/test/Autotuning/IncrementalCompilation/Inputs/test2.c +new file mode 100644 +index 000000000000..a32fefaf5c1b +--- /dev/null ++++ b/clang/test/Autotuning/IncrementalCompilation/Inputs/test2.c +@@ -0,0 +1,17 @@ ++// Inlining opportunity. ++ ++int mul(int a) { return a * a; } ++ ++int add(int a) { return a + a; } ++ ++int inc(int a) { return ++a; } ++ ++int func(int a) { ++ int x = add(a); ++ int y = mul(a); ++ int z = x + y; ++ ++ z += inc(a); ++ ++ return z; ++} +diff --git a/clang/test/Autotuning/IncrementalCompilation/Inputs/test3.c b/clang/test/Autotuning/IncrementalCompilation/Inputs/test3.c +new file mode 100644 +index 000000000000..f0257e49c33f +--- /dev/null ++++ b/clang/test/Autotuning/IncrementalCompilation/Inputs/test3.c +@@ -0,0 +1,6 @@ ++// Loop unrolling opportunity. ++ ++void func3(int *a, int size) { ++ for (int i = 0; i < size; i++) ++ a[i]++; ++} +\ No newline at end of file +diff --git a/clang/test/Autotuning/IncrementalCompilation/inc-compile-generate-input.cpp b/clang/test/Autotuning/IncrementalCompilation/inc-compile-generate-input.cpp +new file mode 100644 +index 000000000000..54be8d2c5e63 +--- /dev/null ++++ b/clang/test/Autotuning/IncrementalCompilation/inc-compile-generate-input.cpp +@@ -0,0 +1,44 @@ ++// REQUIRES: asserts ++ ++// RUN: %clang -O3 -c -fautotune-generate=LLVMParam %S/Inputs/test1.c \ ++// RUN: -mllvm -auto-tuning-compile-mode=CoarseGrain \ ++// RUN: -mllvm -debug-only=autotuning-compile 2>&1 | \ ++// RUN: FileCheck %s -check-prefix=COARSEGRAIN ++// RUN: rm -rf %S/Inputs/test1.ll ++ ++// RUN: %clang -O3 -c -fautotune-generate %S/Inputs/test1.c \ ++// RUN: -mllvm -auto-tuning-compile-mode=FineGrain \ ++// RUN: -mllvm -debug-only=autotuning-compile 2>&1 | \ ++// RUN: FileCheck %s -check-prefix=FINEGRAIN-NO-OPP ++// RUN: rm -rf %S/Inputs/test1.ll ++ ++// RUN: %clang -O3 -c -fautotune-generate %S/Inputs/test2.c \ ++// RUN: -mllvm -auto-tuning-compile-mode=FineGrain \ ++// RUN: -mllvm -debug-only=autotuning-compile 2>&1 | \ ++// RUN: FileCheck %s -check-prefix=FINEGRAIN-INLINE ++// RUN: rm -rf %S/Inputs/test2.ll ++ ++// RUN: %clang -O3 -c -fautotune-generate %S/Inputs/test3.c \ ++// RUN: -mllvm -auto-tuning-compile-mode=FineGrain \ ++// RUN: -mllvm -debug-only=autotuning-compile 2>&1 | \ ++// RUN: FileCheck %s -check-prefix=FINEGRAIN-UNROLL ++// RUN: rm -rf %S/Inputs/test3.ll ++ ++// COARSEGRAIN: AutoTuningCompile: IR files writing before Pass: start. ++ ++// FINEGRAIN-NO-OPP: AutoTuningCompile: IR files writing before Pass: start. ++// FINEGRAIN-NO-OPP-NEXT: AutoTuningCompile: IR files writing before ++// FINEGRAIN-NO-OPP-SAME: Pass: inline. ++// FINEGRAIN-NO-OPP: AutoTuningCompile: IR files writing before ++// FINEGRAIN-NO-OPP-SAME: Pass: loop-vectorize. ++// FINEGRAIN-NO-OPP-NEXT: AutoTuningCompile: IR files writing before Pass: end. ++ ++// FINEGRAIN-INLINE: AutoTuningCompile: IR files writing before Pass: start. ++// FINEGRAIN-INLINE-NEXT: AutoTuningCompile: IR files writing before ++// FINEGRAIN-INLINE-SAME: Pass: inline. ++ ++// FINEGRAIN-UNROLL: AutoTuningCompile: IR files writing before Pass: start. ++// FINEGRAIN-UNROLL-NEXT: AutoTuningCompile: IR files writing before ++// FINEGRAIN-UNROLL-SAME: Pass: inline. ++// FINEGRAIN-UNROLL-NEXT: AutoTuningCompile: IR files writing before ++// FINEGRAIN-UNROLL-SAME: Pass: loop-unroll. +diff --git a/clang/test/Autotuning/LTO/Inputs/datadir/corse_grain_config.yaml b/clang/test/Autotuning/LTO/Inputs/datadir/corse_grain_config.yaml +new file mode 100644 +index 000000000000..0a8e9ee2cce1 +--- /dev/null ++++ b/clang/test/Autotuning/LTO/Inputs/datadir/corse_grain_config.yaml +@@ -0,0 +1 @@ ++!AutoTuning {Args: [{-unroll-count: 8}], CodeRegionHash: 0, CodeRegionType: llvm-param, Function: none, Invocation: 0, Name: [module], Pass: none} +diff --git a/clang/test/Autotuning/LTO/Inputs/datadir/fine_grain_a.out.yaml b/clang/test/Autotuning/LTO/Inputs/datadir/fine_grain_a.out.yaml +new file mode 100644 +index 000000000000..d0f8a86abba5 +--- /dev/null ++++ b/clang/test/Autotuning/LTO/Inputs/datadir/fine_grain_a.out.yaml +@@ -0,0 +1,4 @@ ++!AutoTuning {Args: [{ForceInline: 1}], CodeRegionHash: 795632090418537900, CodeRegionType: callsite, DebugLoc: {Column: 3, File: clang/test/Autotuning/LTO/Inputs/src/test.c, Line: 15}, Function: main, Invocation: 0, Name: input_data-, Pass: inline} ++--- !AutoTuning {Args: [{UnrollCount: 4}], CodeRegionHash: 13976873016266268884, CodeRegionType: loop, DebugLoc: {Column: 3, File: clang/test/Autotuning/LTO/Inputs/src/test.c, Line: 7}, Function: main, Invocation: 1, Name: label %39, Pass: loop-unroll} ++--- !AutoTuning {Args: [{UnrollCount: 1}], CodeRegionHash: 6932431056461711356, CodeRegionType: loop, DebugLoc: {Column: 3, File: clang/test/Autotuning/LTO/Inputs/src/test.c, Line: 7}, Function: main, Invocation: 1, Name: label %25, Pass: loop-unroll} ++--- !AutoTuning {Args: [{UnrollCount: 1}], CodeRegionHash: 14763110312986404579, CodeRegionType: loop, DebugLoc: {Column: 3, File: clang/test/Autotuning/LTO/Inputs/src/input.c, Line: 5}, Function: main, Invocation: 1, Name: label %12, Pass: loop-unroll} +diff --git a/clang/test/Autotuning/LTO/Inputs/datadir/fine_grain_output.yaml b/clang/test/Autotuning/LTO/Inputs/datadir/fine_grain_output.yaml +new file mode 100644 +index 000000000000..937ed95ad5fa +--- /dev/null ++++ b/clang/test/Autotuning/LTO/Inputs/datadir/fine_grain_output.yaml +@@ -0,0 +1 @@ ++!AutoTuning {Args: [{UnrollCount: 8}], CodeRegionHash: 1116845059539910783, CodeRegionType: loop, DebugLoc: {Column: 3, File: clang/test/Autotuning/LTO/Inputs/src/output.c, Line: 5}, Function: output_data, Invocation: 1, Name: for.body, Pass: loop-unroll} +diff --git a/clang/test/Autotuning/LTO/Inputs/src/input.c b/clang/test/Autotuning/LTO/Inputs/src/input.c +new file mode 100644 +index 000000000000..2511e80d3930 +--- /dev/null ++++ b/clang/test/Autotuning/LTO/Inputs/src/input.c +@@ -0,0 +1,7 @@ ++#include ++ ++void input_data(int Arr[], int NI) { ++ printf("Input data...\n"); ++ for (int I = 0; I < NI; ++I) ++ scanf("%d", &Arr[I]); ++} +diff --git a/clang/test/Autotuning/LTO/Inputs/src/input.h b/clang/test/Autotuning/LTO/Inputs/src/input.h +new file mode 100644 +index 000000000000..eed043181f2e +--- /dev/null ++++ b/clang/test/Autotuning/LTO/Inputs/src/input.h +@@ -0,0 +1 @@ ++void input_data(int Arr[], int NI); +diff --git a/clang/test/Autotuning/LTO/Inputs/src/output.c b/clang/test/Autotuning/LTO/Inputs/src/output.c +new file mode 100644 +index 000000000000..d8ff68f8dd01 +--- /dev/null ++++ b/clang/test/Autotuning/LTO/Inputs/src/output.c +@@ -0,0 +1,8 @@ ++#include ++ ++void output_data(int *Arr, int NI) { ++ printf("Printing data...\n"); ++ for (int I = 0; I < NI; ++I) ++ printf("%d\t", Arr[I]); ++ printf("\nPrinting done...\n"); ++} +diff --git a/clang/test/Autotuning/LTO/Inputs/src/output.h b/clang/test/Autotuning/LTO/Inputs/src/output.h +new file mode 100644 +index 000000000000..1c5aa0b119f4 +--- /dev/null ++++ b/clang/test/Autotuning/LTO/Inputs/src/output.h +@@ -0,0 +1 @@ ++void output_data(int *Arr, int NI); +diff --git a/clang/test/Autotuning/LTO/Inputs/src/test.c b/clang/test/Autotuning/LTO/Inputs/src/test.c +new file mode 100644 +index 000000000000..5d22f358505f +--- /dev/null ++++ b/clang/test/Autotuning/LTO/Inputs/src/test.c +@@ -0,0 +1,19 @@ ++#include "input.h" ++#include "output.h" ++#include ++#include ++ ++void inc_data(int Arr[], int Size) { ++ for (int I = 0; I < Size; ++I) ++ Arr[I] = Arr[I] + 1; ++} ++ ++int main(int argc, char **argv) { ++ int NI = atoi(argv[1]); ++ int Arr[NI]; ++ ++ input_data(Arr, NI); ++ inc_data(Arr, NI); ++ output_data(Arr, NI); ++ return 0; ++} +diff --git a/clang/test/Autotuning/LTO/apply_config_coarse_grain.cpp b/clang/test/Autotuning/LTO/apply_config_coarse_grain.cpp +new file mode 100644 +index 000000000000..353f875c001a +--- /dev/null ++++ b/clang/test/Autotuning/LTO/apply_config_coarse_grain.cpp +@@ -0,0 +1,41 @@ ++// REQUIRES: asserts ++ ++// RUN: rm -rf %t.data_dir ++// RUN: export AUTOTUNE_DATADIR=%t.data_dir ++// RUN: mkdir $AUTOTUNE_DATADIR ++ ++// RUN: sed 's#\[module\]#%S/Inputs/src/input.c#g' \ ++// RUN: %S/Inputs/datadir/corse_grain_config.yaml > %t.data_dir/config.yaml ++ ++// RUN: %clang -O3 -c -flto=full -fuse-ld=lld -fautotune %S/Inputs/src/output.c \ ++// RUN: -o %t.output.o -mllvm -debug-only=loop-unroll -mllvm -unroll-count=0 \ ++// RUN: 2>&1 | FileCheck %s --check-prefix=COARSEGRAIN1 ++ ++// RUN: %clang -O3 -c -flto=full -fuse-ld=lld -fautotune %S/Inputs/src/input.c \ ++// RUN: -o %t.input.o -mllvm -debug-only=loop-unroll 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=COARSEGRAIN2 ++ ++// RUN: %clang -O3 -c -flto=full -fuse-ld=lld -fautotune %S/Inputs/src/test.c \ ++// RUN: -o %t.test.o -mllvm -debug-only=loop-unroll -mllvm -unroll-count=0 \ ++// RUN: 2>&1 | FileCheck %s --check-prefix=COARSEGRAIN1 ++ ++// RUN: sed 's#\[module\]#a.out#g' %S/Inputs/datadir/corse_grain_config.yaml \ ++// RUN: > %t.data_dir/config.yaml ++ ++// RUN: env AUTOTUNE_PROJECT_DIR=$(echo -n %T | sed 's\Output\\') \ ++// RUN: %clang -O3 -fautotune %t.output.o %t.input.o %t.test.o \ ++// RUN: -flto=full -fuse-ld=lld -Wl,-mllvm,-debug-only=loop-unroll 2>&1 |\ ++// RUN: FileCheck %s --check-prefix=COARSEGRAIN3 ++ ++// COARSEGRAIN1-NOT: UNROLLING loop ++ ++// COARSEGRAIN2: Loop Unroll: F[input_data] Loop [[NAME:%for.body]] ++// COARSEGRAIN2: UNROLLING loop [[NAME]] ++ ++// COARSEGRAIN3: Loop Unroll: F{{\[}}[[FUNCNAME:main]]{{\]}} Loop % ++// COARSEGRAIN3: UNROLLING loop % ++// COARSEGRAIN3: Loop Unroll: F{{\[}}[[FUNCNAME]]{{\]}} Loop % ++// COARSEGRAIN3: UNROLLING loop % ++// COARSEGRAIN3: Loop Unroll: F{{\[}}[[FUNCNAME]]{{\]}} Loop % ++// COARSEGRAIN3: UNROLLING loop % ++// COARSEGRAIN3-NOT: UNROLLING loop +diff --git a/clang/test/Autotuning/LTO/apply_config_fine_grain.cpp b/clang/test/Autotuning/LTO/apply_config_fine_grain.cpp +new file mode 100644 +index 000000000000..7f0894cefeac +--- /dev/null ++++ b/clang/test/Autotuning/LTO/apply_config_fine_grain.cpp +@@ -0,0 +1,58 @@ ++// REQUIRES: asserts ++ ++// RUN: rm -rf %t.data_dir ++// RUN: export AUTOTUNE_DATADIR=%t.data_dir ++// RUN: mkdir $AUTOTUNE_DATADIR ++// RUN: cp %S/Inputs/datadir/fine_grain_output.yaml %t.data_dir/config.yaml ++ ++// RUN: %clang -O3 -flto=full -fuse-ld=lld -fautotune %S/Inputs/src/output.c \ ++// RUN: -c -mllvm -debug-only=loop-unroll -mllvm -debug-only=autotuning \ ++// RUN: -mllvm -auto-tuning-code-region-matching-hash=false -o %t.output.o \ ++// RUN: 2>&1 -mllvm -print-before-all | \ ++// RUN: FileCheck %s --check-prefix=FINEGRAIN1 ++ ++// RUN: %clang -O3 -flto=full -fuse-ld=lld -fautotune %S/Inputs/src/input.c \ ++// RUN: -c -mllvm -debug-only=loop-unroll -mllvm -debug-only=autotuning \ ++// RUN: -mllvm -auto-tuning-code-region-matching-hash=false -o %t.input.o \ ++// RUN: 2>&1 | FileCheck %s --check-prefix=FINEGRAIN2 ++ ++// RUN: %clang -O3 -flto=full -fuse-ld=lld -fautotune %S/Inputs/src/test.c \ ++// RUN: -c -mllvm -debug-only=loop-unroll -mllvm -debug-only=autotuning \ ++// RUN: -mllvm -auto-tuning-code-region-matching-hash=false -o %t.test.o \ ++// RUN: 2>&1 | FileCheck %s --check-prefix=FINEGRAIN2 ++ ++// RUN: cp %S/Inputs/datadir/fine_grain_a.out.yaml %t.data_dir/config.yaml ++// RUN: %clang -O3 -flto=full -fuse-ld=lld -fautotune %t.output.o %t.input.o \ ++// RUN: %t.test.o -Wl,-mllvm,-auto-tuning-code-region-matching-hash=false \ ++// RUN: -Wl,-mllvm,-debug-only=inline -Wl,-mllvm,-debug-only=loop-unroll \ ++// RUN: -Wl,-mllvm,-debug-only=autotuning 2>&1 | \ ++// RUN: FileCheck %s --check-prefix=FINEGRAIN3 ++ ++// FINEGRAIN1: IR Dump Before LoopUnrollPass on [[FUNCNAME1:output_data]] ++// FINEGRAIN1: Loop Unroll: F{{\[}}[[FUNCNAME1]]{{\]}} Loop %[[NAME:for.body]] ++// FINEGRAIN1: UnrollCount is set for the CodeRegion ++// FINEGRAIN1-NEXT: Name: [[NAME]] ++// FINEGRAIN1-NEXT: FuncName: [[FUNCNAME1]] ++// FINEGRAIN1: UNROLLING loop %[[NAME]] ++ ++// FINEGRAIN2-NOT: UnrollCount is set for the CodeRegion ++ ++// FINEGRAIN3: ForceInline is set for the CodeRegion ++// FINEGRAIN3-NEXT: Name: [[CALLEE:input_data]] ++// FINEGRAIN3: Inlining (cost=always): Force inlined by auto-tuning ++// FINEGRAIN3-SAME: @[[CALLEE]] ++// FINEGRAIN3: Loop Unroll: F{{\[}}[[FUNCNAME2:main]]{{\]}} Loop % ++// FINEGRAIN3: UnrollCount is set for the CodeRegion ++// FINEGRAIN3-NEXT: Name: label % ++// FINEGRAIN3-NEXT: FuncName: [[FUNCNAME2]] ++// FINEGRAIN3: UNROLLING loop % ++// FINEGRAIN3: Loop Unroll: F{{\[}}[[FUNCNAME2]]{{\]}} Loop % ++// FINEGRAIN3: UnrollCount is set for the CodeRegion ++// FINEGRAIN3-NEXT: Name: label % ++// FINEGRAIN3-NEXT: FuncName: [[FUNCNAME2]] ++// FINEGRAIN3: UNROLLING loop % ++// FINEGRAIN3: Loop Unroll: F{{\[}}[[FUNCNAME2]]{{\]}} Loop % ++// FINEGRAIN3: UnrollCount is set for the CodeRegion ++// FINEGRAIN3-NEXT: Name: label % ++// FINEGRAIN3-NEXT: FuncName: [[FUNCNAME2]] ++// FINEGRAIN3: UNROLLING loop % +diff --git a/clang/test/Autotuning/LTO/generate_opportunity.cpp b/clang/test/Autotuning/LTO/generate_opportunity.cpp +new file mode 100644 +index 000000000000..efcc4dc7c2f2 +--- /dev/null ++++ b/clang/test/Autotuning/LTO/generate_opportunity.cpp +@@ -0,0 +1,56 @@ ++// RUN: rm -rf %t.data_dir ++// RUN: export AUTOTUNE_DATADIR=%t.data_dir ++ ++// RUN: %clang -O3 -c -flto=full -fuse-ld=lld -fautotune-generate -o %t.output.o \ ++// RUN: %S/Inputs/src/output.c ++// RUN: FileCheck %s --input-file %t.data_dir/opp/output.c.yaml \ ++// RUN: -check-prefix=FINEGRAIN ++ ++// RUN: %clang -O3 -c -flto=full -fuse-ld=lld -fautotune-generate -o %t.input.o \ ++// RUN: %S/Inputs/src/input.c ++// RUN: FileCheck %s --input-file %t.data_dir/opp/input.c.yaml \ ++// RUN: -check-prefix=FINEGRAIN ++ ++// RUN: %clang -O3 -c -flto=full -fuse-ld=lld -fautotune-generate -o %t.test.o \ ++// RUN: %S/Inputs/src/test.c ++// RUN: FileCheck %s --input-file %t.data_dir/opp/test.c.yaml \ ++// RUN: -check-prefix=FINEGRAIN ++ ++// RUN: %clang -O3 -flto=full -fuse-ld=lld -fautotune-generate %t.output.o \ ++// RUN: %t.test.o %t.input.o ++// RUN: FileCheck %s --input-file %t.data_dir/opp/a.out.yaml \ ++// RUN: -check-prefix=FINEGRAIN-LTO ++ ++// RUN: rm -rf %t.data_dir ++// RUN: export AUTOTUNE_DATADIR=%t.data_dir ++ ++// RUN: %clang -O3 -c -flto=full -fuse-ld=lld -fautotune-generate=LLVMParam \ ++// RUN: %S/Inputs/src/output.c -o %t.output.o ++// RUN: FileCheck %s --input-file %t.data_dir/opp/output.c.yaml \ ++// RUN: -check-prefix=COARSEGRAIN ++ ++// RUN: %clang -O3 -c -flto=full -fuse-ld=lld -fautotune-generate=LLVMParam \ ++// RUN: %S/Inputs/src/input.c -o %t.input.o ++// RUN: FileCheck %s --input-file %t.data_dir/opp/input.c.yaml \ ++// RUN: -check-prefix=COARSEGRAIN ++ ++// RUN: %clang -O3 -c -flto=full -fuse-ld=lld -fautotune-generate=LLVMParam \ ++// RUN: %S/Inputs/src/test.c -o %t.test.o ++// RUN: FileCheck %s --input-file %t.data_dir/opp/test.c.yaml \ ++// RUN: -check-prefix=COARSEGRAIN ++ ++// RUN: %clang -O3 -flto=full -fuse-ld=lld -fautotune-generate=LLVMParam \ ++// RUN: %t.test.o %t.input.o %t.output.o ++// RUN: FileCheck %s --input-file %t.data_dir/opp/a.out.yaml \ ++// RUN: -check-prefix=COARSEGRAIN ++ ++// FINEGRAIN: --- !AutoTuning ++// FINEGRAIN: CodeRegionType: {{callsite|loop}} ++ ++// FINEGRAIN-LTO: --- !AutoTuning ++// FINEGRAIN-LTO: CodeRegionType: callsite ++// FINEGRAIN-LTO: --- !AutoTuning ++// FINEGRAIN-LTO: CodeRegionType: loop ++ ++// COARSEGRAIN: --- !AutoTuning ++// COARSEGRAIN: CodeRegionType: llvm-param +diff --git a/clang/test/Autotuning/PhaseOrdering/Inputs/template.yaml b/clang/test/Autotuning/PhaseOrdering/Inputs/template.yaml +new file mode 100644 +index 000000000000..065d3cb85b72 +--- /dev/null ++++ b/clang/test/Autotuning/PhaseOrdering/Inputs/template.yaml +@@ -0,0 +1,8 @@ ++--- !AutoTuning ++Pass: all ++Name: [filename] ++Function: none ++CodeRegionType: other ++Args: ++ - OptPass: [pass] ++... +diff --git a/clang/test/Autotuning/PhaseOrdering/pass-order.cpp b/clang/test/Autotuning/PhaseOrdering/pass-order.cpp +new file mode 100644 +index 000000000000..ce42527909f6 +--- /dev/null ++++ b/clang/test/Autotuning/PhaseOrdering/pass-order.cpp +@@ -0,0 +1,48 @@ ++// Disable auto-tuning ++// RUN: %clang %s -S -mllvm -debug-pass=Arguments 2>&1 >/dev/null | \ ++// RUN: FileCheck %s -check-prefix=DISABLE ++ ++// One Pass ++// RUN: rm %t.onepass-debug-pass.yaml -rf ++// RUN: sed 's#\[filename\]#%s#g; s#\[pass\]#\[loop-extract\]#g' \ ++// RUN: %S/Inputs/template.yaml > %t.onepass-debug-pass.yaml ++// RUN: %clang %s -S -mllvm -auto-tuning-input=%t.onepass-debug-pass.yaml \ ++// RUN: -mllvm -print-after-all 2>&1 >/dev/null | \ ++// RUN: FileCheck %s -check-prefix=ONEPASS ++ ++// Two passes (A->B): ++// RUN: rm %t.twopass-ab-debug-pass.yaml -rf ++// RUN: sed 's#\[filename\]#%s#g; s#\[pass\]#\[loop-extract,strip\]#g' \ ++// RUN: %S/Inputs/template.yaml > %t.twopass-ab-debug-pass.yaml ++// RUN: %clang %s -S -mllvm -auto-tuning-input=%t.twopass-ab-debug-pass.yaml \ ++// RUN: -mllvm -print-after-all 2>&1 >/dev/null | \ ++// RUN: FileCheck %s -check-prefix=TWOPASS_AB ++ ++// Two passes (B->A): ++// RUN: rm %t.twopass-ba-debug-pass.yaml -rf ++// RUN: sed 's#\[filename\]#%s#g; s#\[pass\]#\[strip,loop-extract\]#g' \ ++// RUN: %S/Inputs/template.yaml > %t.twopass-ba-debug-pass.yaml ++// RUN: %clang %s -S -mllvm -auto-tuning-input=%t.twopass-ba-debug-pass.yaml \ ++// RUN: -mllvm -print-after-all 2>&1 >/dev/null | \ ++// RUN: FileCheck %s -check-prefix=TWOPASS_BA ++// UNSUPPORTED: windows ++ ++// a simple cpp file ++int main() { ++ int i = 8; ++ for (; i < 20;) { ++ int a = i - 5; ++ i = i + 2; ++ } ++} ++ ++// DISABLE: Pass Arguments: ++// DISABLE-NOT: -loop-extract ++ ++// ONEPASS: *** IR Dump After LoopExtractorPass ++ ++// TWOPASS_AB: *** IR Dump After LoopExtractorPass ++// TWOPASS_AB: *** IR Dump After StripSymbolsPass ++ ++// TWOPASS_BA: *** IR Dump After StripSymbolsPass ++// TWOPASS_BA: *** IR Dump After LoopExtractorPass +diff --git a/clang/test/Autotuning/lit.local.cfg b/clang/test/Autotuning/lit.local.cfg +new file mode 100644 +index 000000000000..13b4927257ab +--- /dev/null ++++ b/clang/test/Autotuning/lit.local.cfg +@@ -0,0 +1,2 @@ ++if not config.enable_enable_autotuner: ++ config.unsupported = True +diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt +index b88694deb818..ba3349b2edf8 100644 +--- a/clang/test/CMakeLists.txt ++++ b/clang/test/CMakeLists.txt +@@ -11,6 +11,7 @@ llvm_canonicalize_cmake_booleans( + CLANG_SPAWN_CC1 + ENABLE_BACKTRACES + LLVM_ENABLE_CLASSIC_FLANG ++ LLVM_ENABLE_AUTOTUNER + LLVM_ENABLE_ZLIB + LLVM_ENABLE_ZSTD + LLVM_ENABLE_PER_TARGET_RUNTIME_DIR +diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in +index c2532e846fe7..89b7cafdc1d8 100644 +--- a/clang/test/lit.site.cfg.py.in ++++ b/clang/test/lit.site.cfg.py.in +@@ -43,6 +43,7 @@ config.ppc_linux_default_ieeelongdouble = @PPC_LINUX_DEFAULT_IEEELONGDOUBLE@ + config.have_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@ + config.use_classic_flang = @LLVM_ENABLE_CLASSIC_FLANG@ + config.build_for_openeuler = @BUILD_FOR_OPENEULER@ ++config.enable_enable_autotuner = @LLVM_ENABLE_AUTOTUNER@ + + import lit.llvm + lit.llvm.initialize(lit_config, config) +-- +2.33.0 \ No newline at end of file diff --git a/clang.spec b/clang.spec index 90bfdbb1438c8bbe86ece79e30f25d94e4e6ee0d..8dc002b7742a99bd6a3ab49e68d5cc7bcc90a55d 100644 --- a/clang.spec +++ b/clang.spec @@ -1,7 +1,7 @@ %bcond_without sys_llvm %bcond_without check %bcond_with classic_flang -%bcond_without toolchain_clang +%bcond_with toolchain_clang %bcond_without bisheng_autotuner %if %{with toolchain_clang} @@ -43,7 +43,7 @@ Name: %{pkg_name} Version: %{clang_version} -Release: 19 +Release: 20 Summary: A C language family front-end for LLVM License: NCSA @@ -68,6 +68,7 @@ Patch13: 0013-Ignored-option-Wa-generate-missing-build-notes.patch Patch14: 0014-Update-llvm-lit-config-to-support-build_for_openeule.patch Patch15: 0015-Backport-Defer-the-instantiation-of-explicit-specifier-until-.patch Patch16: 0016-Add-BiSheng-Autotuner-support-for-LLVM-compiler.patch +Patch17: 0017-Add-BiSheng-Autotuner-support-for-LLVM-compiler-testcases.patch # Patches for clang-tools-extra # See https://reviews.llvm.org/D120301 @@ -118,6 +119,9 @@ BuildRequires: perl(Sys::Hostname) %if %{with toolchain_clang} BuildRequires: clang %endif +%if %{with bisheng_autotuner} +BuildRequires: lld +%endif Requires: %{name}-libs%{?_isa} = %{version}-%{release} @@ -412,6 +416,10 @@ LD_LIBRARY_PATH=%{buildroot}/%{install_libdir} %{__ninja} check-all -C ./_build %{install_bindir}/git-clang-format %changelog +* Wed Jul 17 2024 liyunfei - 17.0.6-20 +- Add testcases for BiSheng Autotuner. +- Disable toolchain_clang build for BiSheng Autotuner support temporary. + * Tue Jul 16 2024 liyunfei - 17.0.6-19 - Add BiSheng Autotuner support.