Skip to content

Commit 49a9ae4

Browse files
authored
Cherry-pick collection of spir-v and hipstdpar related patches. (llvm#2603)
Patches authored by Alex Voicu
1 parent df93f70 commit 49a9ae4

File tree

24 files changed

+449
-385
lines changed

24 files changed

+449
-385
lines changed

clang/docs/HIPSupport.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ Predefined Macros
498498
* - ``__HIPSTDPAR__``
499499
- Defined when Clang is compiling code in algorithm offload mode, enabled
500500
with the ``--hipstdpar`` compiler option.
501-
* - ``__HIPSTDPAR_INTERPOSE_ALLOC__``
501+
* - ``__HIPSTDPAR_INTERPOSE_ALLOC__`` / ``__HIPSTDPAR_INTERPOSE_ALLOC_V1__``
502502
- Defined only when compiling in algorithm offload mode, when the user
503503
enables interposition mode with the ``--hipstdpar-interpose-alloc``
504504
compiler option, indicating that all dynamic memory allocation /

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,10 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
10991099
if (CodeGenOpts.LinkBitcodePostopt)
11001100
MPM.addPass(LinkInModulesPass(BC));
11011101

1102+
if (LangOpts.HIPStdPar && !LangOpts.CUDAIsDevice &&
1103+
LangOpts.HIPStdParInterposeAlloc)
1104+
MPM.addPass(HipStdParAllocationInterpositionPass());
1105+
11021106
// Add a verifier pass if requested. We don't have to do this if the action
11031107
// requires code generation because there will already be a verifier pass in
11041108
// the code-generation pipeline.
@@ -1162,10 +1166,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
11621166
return;
11631167
}
11641168

1165-
if (LangOpts.HIPStdPar && !LangOpts.CUDAIsDevice &&
1166-
LangOpts.HIPStdParInterposeAlloc)
1167-
MPM.addPass(HipStdParAllocationInterpositionPass());
1168-
11691169
// Now that we have all of the passes ready, run them.
11701170
{
11711171
PrettyStackTraceString CrashInfo("Optimizer");

clang/lib/Driver/Driver.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3726,9 +3726,12 @@ class OffloadingActionBuilder final {
37263726
// compiler phases, including backend and assemble phases.
37273727
ActionList AL;
37283728
Action *BackendAction = nullptr;
3729-
if (ToolChains.front()->getTriple().isSPIRV()) {
3729+
if (ToolChains.front()->getTriple().isSPIRV() ||
3730+
(ToolChains.front()->getTriple().isAMDGCN() &&
3731+
GpuArchList[I] == StringRef("amdgcnspirv"))) {
37303732
// Emit LLVM bitcode for SPIR-V targets. SPIR-V device tool chain
3731-
// (HIPSPVToolChain) runs post-link LLVM IR passes.
3733+
// (HIPSPVToolChain or HIPAMDToolChain) runs post-link LLVM IR
3734+
// passes.
37323735
types::ID Output = Args.hasArg(options::OPT_S)
37333736
? types::TY_LLVM_IR
37343737
: types::TY_LLVM_BC;

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,11 @@ void HIPAMDToolChain::addClangTargetOptions(
254254
CC1Args.append({"-fcuda-is-device", "-fno-threadsafe-statics"});
255255

256256
if (!DriverArgs.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
257-
false))
257+
false)) {
258258
CC1Args.append({"-mllvm", "-amdgpu-internalize-symbols"});
259-
if (DriverArgs.hasArgNoClaim(options::OPT_hipstdpar))
260-
CC1Args.append({"-mllvm", "-amdgpu-enable-hipstdpar"});
259+
if (DriverArgs.hasArgNoClaim(options::OPT_hipstdpar))
260+
CC1Args.append({"-mllvm", "-amdgpu-enable-hipstdpar"});
261+
}
261262

262263
StringRef MaxThreadsPerBlock =
263264
DriverArgs.getLastArgValue(options::OPT_gpu_max_threads_per_block_EQ);

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,10 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
614614
Builder.defineMacro("__HIP_MEMORY_SCOPE_SYSTEM", "5");
615615
if (LangOpts.HIPStdPar) {
616616
Builder.defineMacro("__HIPSTDPAR__");
617-
if (LangOpts.HIPStdParInterposeAlloc)
617+
if (LangOpts.HIPStdParInterposeAlloc) {
618618
Builder.defineMacro("__HIPSTDPAR_INTERPOSE_ALLOC__");
619+
Builder.defineMacro("__HIPSTDPAR_INTERPOSE_ALLOC_V1__");
620+
}
619621
}
620622
if (LangOpts.CUDAIsDevice) {
621623
Builder.defineMacro("__HIP_DEVICE_COMPILE__");
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Check that if we are compiling with fgpu-rdc amdgpu-enable-hipstdpar is not
2+
// passed to CC1, to avoid eager, per TU, removal of potentially accessible
3+
// functions.
4+
5+
// RUN: %clang -### --hipstdpar --offload-arch=gfx906 -nogpulib -nogpuinc %s \
6+
// RUN: --hipstdpar-path=%S/../Driver/Inputs/hipstdpar \
7+
// RUN: --hipstdpar-thrust-path=%S/../Driver/Inputs/hipstdpar/thrust \
8+
// RUN: --hipstdpar-prim-path=%S/../Driver/Inputs/hipstdpar/rocprim 2>&1 \
9+
// RUN: | FileCheck %s -check-prefix=NORDC
10+
// NORDC: {{.*}}"-mllvm" "-amdgpu-enable-hipstdpar"
11+
12+
// RUN: %clang -### --hipstdpar --offload-arch=gfx906 -nogpulib -nogpuinc %s \
13+
// RUN: -fgpu-rdc --hipstdpar-path=%S/../Driver/Inputs/hipstdpar \
14+
// RUN: --hipstdpar-thrust-path=%S/../Driver/Inputs/hipstdpar/thrust \
15+
// RUN: --hipstdpar-prim-path=%S/../Driver/Inputs/hipstdpar/rocprim 2>&1 \
16+
// RUN: | FileCheck %s -check-prefix=RDC
17+
// RDC-NOT: {{.*}}"-mllvm" "-amdgpu-enable-hipstdpar"

clang/test/Driver/hip-toolchain-no-rdc.hip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@
187187
// Check mixed AMDGCNSPIRV and concrete GPU arch.
188188
//
189189

190-
// AMDGCNSPIRV: "-cc1" "-triple" "spirv64-amd-amdhsa" {{.*}}"-emit-obj" {{.*}} "-o" "[[AMDGCNSPV_OBJ:.*o]]"
191-
// AMDGCNSPIRV: {{".*llvm-link.*"}} "-o" "[[AMDGCNSPV_TMP:.*out]]" "[[AMDGCNSPV_OBJ]]"
190+
// AMDGCNSPIRV: "-cc1" "-triple" "spirv64-amd-amdhsa" {{.*}}"-emit-llvm-bc" {{.*}} "-o" "[[AMDGCNSPV_BC:.*bc]]"
191+
// AMDGCNSPIRV: {{".*llvm-link.*"}} "-o" "[[AMDGCNSPV_TMP:.*out]]" "[[AMDGCNSPV_BC]]"
192192
// AMDGCNSPIRV: {{".*llvm-spirv.*"}} "--spirv-max-version=1.6" "--spirv-ext=+all" {{.*}} "[[AMDGCNSPV_TMP]]" {{.*}}"-o" "[[AMDGCNSPV_CO:.*out]]"
193193
// AMDGCNSPIRV: "-cc1" "-triple" "amdgcn-amd-amdhsa" {{.*}}"-emit-obj" {{.*}}"-target-cpu" "gfx900"{{.*}} "-o" "[[GFX900_OBJ:.*o]]"
194194
// AMDGCNSPIRV: {{".*lld.*"}} {{.*}}"-plugin-opt=mcpu=gfx900" {{.*}} "-o" "[[GFX900_CO:.*out]]" {{.*}}"[[GFX900_OBJ]]"

0 commit comments

Comments
 (0)