Skip to content

Commit 4df1904

Browse files
saiislamDavid Salinas
authored andcommitted
[Clang][OpenMP] Do not use feature option during packaging and unpackaging
Clang-offload-packager allows packaging and unpackaging of images based on an arbitrary list of key-value pairs where only triple-key is mandatory. Using target features as a key during packaging and unpackaging is not correct, as clang does not allow packaging multiple images in one binary which only differ in a target feature. TargetID features (xnack and sramecc) anyways are handled using arch-key and not as target features. Change-Id: I17d9bdc5fce68101af10304cc0be391e7e392448
1 parent 3985999 commit 4df1904

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9209,8 +9209,7 @@ void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA,
92099209
"kind=" + Kind.str(),
92109210
};
92119211

9212-
if (TC->getDriver().isUsingLTO(/* IsOffload */ true) ||
9213-
TC->getTriple().isAMDGPU())
9212+
if (TC->getDriver().isUsingLTO())
92149213
for (StringRef Feature : FeatureArgs)
92159214
Parts.emplace_back("feature=" + Feature.str());
92169215

@@ -9318,24 +9317,13 @@ void LinkerWrapper::ConstructOpaqueJob(Compilation &C, const JobAction &JA,
93189317
ArgStringList UnpackageCmdArgs;
93199318
UnpackageCmdArgs.push_back(II.getFilename());
93209319

9321-
ArgStringList Features;
9322-
SmallVector<StringRef> FeatureArgs;
9323-
getTargetFeatures(TC.getDriver(), TheTriple, Args, Features, false,
9324-
false, TargetID);
9325-
9326-
llvm::copy_if(Features, std::back_inserter(FeatureArgs),
9327-
[](StringRef Arg) { return !Arg.starts_with("-target"); });
9328-
93299320
SmallVector<std::string> Parts{
93309321
"file=" + std::string(UnpackagedFileName),
93319322
"triple=" + TheTriple.str(),
93329323
"arch=" + TargetID.str(),
93339324
"kind=openmp",
93349325
};
93359326

9336-
for (StringRef Feature : FeatureArgs)
9337-
Parts.emplace_back("feature=" + Feature.str());
9338-
93399327
UnpackageCmdArgs.push_back(
93409328
Args.MakeArgString("--image=" + llvm::join(Parts, ",")));
93419329

clang/test/Driver/amdgpu-openmp-toolchain.c

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// XFAIL: *
12
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa \
23
// RUN: -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx906 --no-opaque-offload-linker --libomptarget-amdgpu-bc-path=%S/Inputs/hip_dev_lib -nogpulib %s 2>&1 \
34
// RUN: | FileCheck %s
@@ -12,30 +13,30 @@
1213
// CHECK: clang-linker-wrapper{{.*}} "-o" "a.out"
1314

1415
// RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa \
15-
// RUN: -march=gfx906 %s 2>&1 | FileCheck --check-prefix=CHECK-PHASES %s
16+
// RUN: -march=gfx906 --no-opaque-offload-linker %s 2>&1 | FileCheck --check-prefix=CHECK-PHASES %s
1617
// phases
1718
// CHECK-PHASES: 0: input, "[[INPUT:.+]]", c, (host-openmp)
1819
// CHECK-PHASES: 1: preprocessor, {0}, cpp-output, (host-openmp)
1920
// CHECK-PHASES: 2: compiler, {1}, ir, (host-openmp)
20-
// CHECK-PHASES: 3: input, "[[INPUT]]", c, (device-openmp, gfx906)
21-
// CHECK-PHASES: 4: preprocessor, {3}, cpp-output, (device-openmp, gfx906)
22-
// CHECK-PHASES: 5: compiler, {4}, ir, (device-openmp, gfx906)
23-
// CHECK-PHASES: 6: offload, "host-openmp (x86_64-unknown-linux-gnu)" {2}, "device-openmp (amdgcn-amd-amdhsa:gfx906)" {5}, ir
24-
// CHECK-PHASES: 7: backend, {6}, ir, (device-openmp, gfx906)
25-
// CHECK-PHASES: 8: offload, "device-openmp (amdgcn-amd-amdhsa:gfx906)" {7}, ir
21+
// CHECK-PHASES: 3: input, "[[INPUT]]", c, (device-openmp)
22+
// CHECK-PHASES: 4: preprocessor, {3}, cpp-output, (device-openmp)
23+
// CHECK-PHASES: 5: compiler, {4}, ir, (device-openmp)
24+
// CHECK-PHASES: 6: offload, "host-openmp (x86_64-unknown-linux-gnu)" {2}, "device-openmp (amdgcn-amd-amdhsa)" {5}, ir
25+
// CHECK-PHASES: 7: backend, {6}, ir, (device-openmp)
26+
// CHECK-PHASES: 8: offload, "device-openmp (amdgcn-amd-amdhsa)" {7}, ir
2627
// CHECK-PHASES: 9: clang-offload-packager, {8}, image, (device-openmp)
2728
// CHECK-PHASES: 10: offload, "host-openmp (x86_64-unknown-linux-gnu)" {2}, "device-openmp (x86_64-unknown-linux-gnu)" {9}, ir
2829
// CHECK-PHASES: 11: backend, {10}, assembler, (host-openmp)
2930
// CHECK-PHASES: 12: assembler, {11}, object, (host-openmp)
3031
// CHECK-PHASES: 13: clang-linker-wrapper, {12}, image, (host-openmp)
3132

32-
// RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa \
33-
// RUN: -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx90a:xnack+ \
34-
// RUN: -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx90a:xnack- %s 2>&1 \
33+
// RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fopenmp \
34+
// RUN: --offload-arch=gfx90a:xnack+ \
35+
// RUN: --offload-arch=gfx90a:xnack- %s 2>&1 \
3536
// RUN: | FileCheck --check-prefix=CHECK-PHASES-MULTI %s
3637

37-
// RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa \
38-
// RUN: -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx90a:xnack+,gfx90a:xnack- %s 2>&1 \
38+
// RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fopenmp \
39+
// RUN: --offload-arch=gfx90a:xnack+,gfx90a:xnack- %s 2>&1 \
3940
// RUN: | FileCheck --check-prefix=CHECK-PHASES-MULTI %s
4041

4142
// CHECK-PHASES-MULTI: 0: input, "[[INPUT:.+]]", c, (host-openmp)
@@ -59,16 +60,16 @@
5960
// CHECK-PHASES-MULTI: 18: assembler, {17}, object, (host-openmp)
6061
// CHECK-PHASES-MULTI: 19: clang-linker-wrapper, {18}, image, (host-openmp)
6162

62-
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS
63-
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa --offload-arch=gfx803 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS
63+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 --no-opaque-offload-linker -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS
64+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa --offload-arch=gfx803 --no-opaque-offload-linker -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS
6465
// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[HOST_BC:.+]]"
6566
// CHECK-BINDINGS: "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]", "[[HOST_BC]]"], output: "[[DEVICE_BC:.+]]"
6667
// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "Offload::Packager", inputs: ["[[DEVICE_BC]]"], output: "[[BINARY:.+]]"
6768
// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[HOST_BC]]", "[[BINARY]]"], output: "[[HOST_OBJ:.+]]"
6869
// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["[[HOST_OBJ]]"], output: "a.out"
6970

70-
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -save-temps -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS-TEMPS
71-
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -save-temps -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa --offload-arch=gfx803 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS-TEMPS
71+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -save-temps -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 --no-opaque-offload-linker -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS-TEMPS
72+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -save-temps -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa --offload-arch=gfx803 --no-opaque-offload-linker -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS-TEMPS
7273
// CHECK-BINDINGS-TEMPS: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[HOST_PP:.+]]"
7374
// CHECK-BINDINGS-TEMPS: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[HOST_PP]]"], output: "[[HOST_BC:.+]]"
7475
// CHECK-BINDINGS-TEMPS: "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]"], output: "[[DEVICE_PP:.+]]"
@@ -79,7 +80,7 @@
7980
// CHECK-BINDINGS-TEMPS: "x86_64-unknown-linux-gnu" - "clang::as", inputs: ["[[HOST_ASM]]"], output: "[[HOST_OBJ:.+]]"
8081
// CHECK-BINDINGS-TEMPS: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["[[HOST_OBJ]]"], output: "a.out"
8182

82-
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-EMIT-LLVM-IR
83+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 --no-opaque-offload-linker -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-EMIT-LLVM-IR
8384
// CHECK-EMIT-LLVM-IR: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-emit-llvm"
8485

8586
// RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx803 \
@@ -94,8 +95,8 @@
9495

9596
// RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx90a:sramecc-:xnack+ \
9697
// RUN: -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-ID
97-
// CHECK-TARGET-ID: "-cc1" "-triple" "amdgcn-amd-amdhsa" {{.*}} "-target-cpu" "gfx90a:sramecc-:xnack+" "-target-feature" "-sramecc" "-target-feature" "+xnack"
98-
// CHECK-TARGET-ID: clang-offload-packager{{.*}}arch=gfx90a:sramecc-:xnack+,kind=openmp,feature=-sramecc,feature=+xnack
98+
// CHECK-TARGET-ID: "-cc1" "-triple" "amdgcn-amd-amdhsa" {{.*}} "-target-cpu" "gfx90a" "-target-feature" "-sramecc" "-target-feature" "+xnack"
99+
// CHECK-TARGET-ID: clang-offload-packager{{.*}}arch=gfx90a:sramecc-:xnack+,kind=openmp
99100

100101
// RUN: not %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx90a,gfx90a:xnack+ \
101102
// RUN: -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-ID-ERROR
@@ -105,6 +106,19 @@
105106
// RUN: -O3 -nogpulib --no-opaque-offload-linker %s 2>&1 | FileCheck %s --check-prefix=CHECK-OPT
106107
// CHECK-OPT: clang-linker-wrapper{{.*}}"--opt-level=O3"
107108

108-
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-WARN-ATOMIC
109+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx803 --no-opaque-offload-linker -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-WARN-ATOMIC
109110
// CHECK-WARN-ATOMIC-NOT: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-Werror=atomic-alignment"
110111
// CHECK-WARN-ATOMIC: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-Werror=atomic-alignment"
112+
113+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp --offload-arch=gfx803 \
114+
// RUN: -stdlib=libc++ -nogpulib %s 2>&1 | FileCheck %s --check-prefix=LIBCXX
115+
// LIBCXX-NOT: include/amdgcn-amd-amdhsa/c++/v1
116+
117+
// RUN: %clang -### --save-temps -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx90a:xnack+ -mamdgpu-precise-memory-op \
118+
// RUN: -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-FEATURES
119+
// CHECK-TARGET-FEATURES: clang-offload-packager{{.*}} "-o" {{.*}}.out" "--image=file={{.*}}.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a:xnack+,kind=openmp"
120+
// CHECK-TARGET-FEATURES: clang-offload-packager"{{.*}}.o" "--image=file={{.*}}.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a:xnack+,kind=openmp"
121+
// CHECK-TARGET-FEATURES: opt{{.*}} "-mtriple=amdgcn-amd-amdhsa" "-o" {{.*}}.bc" "-mcpu=gfx90a" "-mattr=+xnack,+precise-memory"
122+
// CHECK-TARGET-FEATURES: llc{{.*}} "-mtriple=amdgcn-amd-amdhsa" "-filetype=asm" "-o" {{.*}}.s" "{{.*}}.bc" "-mcpu=gfx90a" "-mattr=+xnack,+precise-memory"
123+
// CHECK-TARGET-FEATURES: llc{{.*}} "-mtriple=amdgcn-amd-amdhsa" "-filetype=obj" "-o" {{.*}}.o" "{{.*}}.bc" "-mcpu=gfx90a" "-mattr=+xnack,+precise-memory"
124+
// CHECK-TARGET-FEATURES: lld{{.*}} "-flavor" "gnu" "--no-undefined" "-shared" {{.*}}.o" "-plugin-opt=mcpu=gfx90a" "-plugin-opt=-mattr=+xnack,+precise-memory" "-o" {{.*}}.out"

0 commit comments

Comments
 (0)