Author: Yaxun (Sam) Liu Date: 2020-10-04T21:41:43-04:00 New Revision: 9756a402f297d0030689aaade3651785b7496649
URL: https://github.com/llvm/llvm-project/commit/9756a402f297d0030689aaade3651785b7496649 DIFF: https://github.com/llvm/llvm-project/commit/9756a402f297d0030689aaade3651785b7496649.diff LOG: Recommit "[HIP] Add option --gpu-instrument-lib=" recommit 64f7790e7d2309b5d38949921a256acf8068e659 after fixing hip-device-libs.hip. Added: clang/test/Driver/Inputs/hip_multiple_inputs/instrument.bc Modified: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/HIP.cpp clang/test/Driver/hip-device-libs.hip Removed: ################################################################################ diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 672a833c9d4d..18a123476253 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -672,6 +672,9 @@ defm gpu_allow_device_init : OptInFFlag<"gpu-allow-device-init", def gpu_max_threads_per_block_EQ : Joined<["--"], "gpu-max-threads-per-block=">, Flags<[CC1Option]>, HelpText<"Default max threads per block for kernel launch bounds for HIP">; +def gpu_instrument_lib_EQ : Joined<["--"], "gpu-instrument-lib=">, + HelpText<"Instrument device library for HIP, which is a LLVM bitcode containing " + "__cyg_profile_func_enter and __cyg_profile_func_exit">; def libomptarget_nvptx_path_EQ : Joined<["--"], "libomptarget-nvptx-path=">, Group<i_Group>, HelpText<"Path to libomptarget-nvptx libraries">; def dD : Flag<["-"], "dD">, Group<d_Group>, Flags<[CC1Option]>, diff --git a/clang/lib/Driver/ToolChains/HIP.cpp b/clang/lib/Driver/ToolChains/HIP.cpp index 07d72c073b4b..f1044f316fc8 100644 --- a/clang/lib/Driver/ToolChains/HIP.cpp +++ b/clang/lib/Driver/ToolChains/HIP.cpp @@ -330,6 +330,17 @@ void HIPToolChain::addClangTargetOptions( RocmInstallation.addCommonBitcodeLibCC1Args( DriverArgs, CC1Args, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt, FastRelaxedMath, CorrectSqrt); + + // Add instrument lib. + auto InstLib = + DriverArgs.getLastArgValue(options::OPT_gpu_instrument_lib_EQ); + if (InstLib.empty()) + return; + if (llvm::sys::fs::exists(InstLib)) { + CC1Args.push_back("-mlink-builtin-bitcode"); + CC1Args.push_back(DriverArgs.MakeArgString(InstLib)); + } else + getDriver().Diag(diag::err_drv_no_such_file) << InstLib; } } diff --git a/clang/test/Driver/Inputs/hip_multiple_inputs/instrument.bc b/clang/test/Driver/Inputs/hip_multiple_inputs/instrument.bc new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/clang/test/Driver/hip-device-libs.hip b/clang/test/Driver/hip-device-libs.hip index 3dd798476e2b..c3e89d1a4fed 100644 --- a/clang/test/Driver/hip-device-libs.hip +++ b/clang/test/Driver/hip-device-libs.hip @@ -92,7 +92,7 @@ // Test --hip-device-lib-path flag // RUN: %clang -### -target x86_64-linux-gnu \ -// RUN: --cuda-gpu-arch=gfx803 \ +// RUN: --cuda-gpu-arch=gfx803 -nogpuinc \ // RUN: --hip-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode \ // RUN: %S/Inputs/hip_multiple_inputs/b.hip \ // RUN: 2>&1 | FileCheck %s --check-prefixes=ALL,FLUSHD @@ -101,10 +101,19 @@ // Test environment variable HIP_DEVICE_LIB_PATH // RUN: env HIP_DEVICE_LIB_PATH=%S/Inputs/rocm/amdgcn/bitcode \ // RUN: %clang -### -target x86_64-linux-gnu \ -// RUN: --cuda-gpu-arch=gfx900 \ +// RUN: --cuda-gpu-arch=gfx900 -nogpuinc \ // RUN: %S/Inputs/hip_multiple_inputs/b.hip \ // RUN: 2>&1 | FileCheck %s --check-prefixes=ALL +// Test --gpu-instrument-lib +// RUN: %clang -### -target x86_64-linux-gnu \ +// RUN: --cuda-gpu-arch=gfx900 \ +// RUN: --rocm-path=%S/Inputs/rocm \ +// RUN: --gpu-instrument-lib=%S/Inputs/hip_multiple_inputs/instrument.bc \ +// RUN: %S/Inputs/hip_multiple_inputs/b.hip \ +// RUN: 2>&1 | FileCheck %s --check-prefixes=ALL,INST + +// ALL-NOT: error: // ALL: {{"[^"]*clang[^"]*"}} // ALL-SAME: "-mlink-builtin-bitcode" "{{.*}}hip.bc" // ALL-SAME: "-mlink-builtin-bitcode" "{{.*}}ocml.bc" @@ -118,3 +127,4 @@ // ALL-SAME: "-mlink-builtin-bitcode" "{{.*}}oclc_correctly_rounded_sqrt_on.bc" // ALL-SAME: "-mlink-builtin-bitcode" "{{.*}}oclc_wavefrontsize64_on.bc" // ALL-SAME: "-mlink-builtin-bitcode" "{{.*}}oclc_isa_version_{{[0-9]+}}.bc" +// INST-SAME: "-mlink-builtin-bitcode" "{{.*}}instrument.bc" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits