Index: cfe/trunk/lib/Driver/ToolChains/HIP.cpp =================================================================== --- cfe/trunk/lib/Driver/ToolChains/HIP.cpp +++ cfe/trunk/lib/Driver/ToolChains/HIP.cpp @@ -31,7 +31,7 @@ namespace { -static void addBCLib(Compilation &C, const ArgList &Args, +static void addBCLib(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs, ArgStringList LibraryPaths, StringRef BCName) { StringRef FullName; @@ -40,11 +40,12 @@ llvm::sys::path::append(Path, BCName); FullName = Path; if (llvm::sys::fs::exists(FullName)) { + CmdArgs.push_back("-mlink-builtin-bitcode"); CmdArgs.push_back(Args.MakeArgString(FullName)); return; } } - C.getDriver().Diag(diag::err_drv_no_such_file) << BCName; + D.Diag(diag::err_drv_no_such_file) << BCName; } } // namespace @@ -58,44 +59,6 @@ for (const auto &II : Inputs) CmdArgs.push_back(II.getFilename()); - ArgStringList LibraryPaths; - - // Find in --hip-device-lib-path and HIP_LIBRARY_PATH. - for (auto Path : Args.getAllArgValues(options::OPT_hip_device_lib_path_EQ)) - LibraryPaths.push_back(Args.MakeArgString(Path)); - - addDirectoryList(Args, LibraryPaths, "-L", "HIP_DEVICE_LIB_PATH"); - - llvm::SmallVector BCLibs; - - // Add bitcode library in --hip-device-lib. - for (auto Lib : Args.getAllArgValues(options::OPT_hip_device_lib_EQ)) { - BCLibs.push_back(Args.MakeArgString(Lib)); - } - - // If --hip-device-lib is not set, add the default bitcode libraries. - if (BCLibs.empty()) { - // Get the bc lib file name for ISA version. For example, - // gfx803 => oclc_isa_version_803.amdgcn.bc. - std::string ISAVerBC = - "oclc_isa_version_" + SubArchName.drop_front(3).str() + ".amdgcn.bc"; - - llvm::StringRef FlushDenormalControlBC; - if (Args.hasArg(options::OPT_fcuda_flush_denormals_to_zero)) - FlushDenormalControlBC = "oclc_daz_opt_on.amdgcn.bc"; - else - FlushDenormalControlBC = "oclc_daz_opt_off.amdgcn.bc"; - - BCLibs.append({"hip.amdgcn.bc", "opencl.amdgcn.bc", - "ocml.amdgcn.bc", "ockl.amdgcn.bc", - "oclc_finite_only_off.amdgcn.bc", - FlushDenormalControlBC, - "oclc_correctly_rounded_sqrt_on.amdgcn.bc", - "oclc_unsafe_math_off.amdgcn.bc", ISAVerBC}); - } - for (auto Lib : BCLibs) - addBCLib(C, Args, CmdArgs, LibraryPaths, Lib); - // Add an intermediate output file. CmdArgs.push_back("-o"); std::string TmpName = @@ -324,6 +287,44 @@ CC1Args.append({"-fvisibility", "hidden"}); CC1Args.push_back("-fapply-global-visibility-to-externs"); } + ArgStringList LibraryPaths; + + // Find in --hip-device-lib-path and HIP_LIBRARY_PATH. + for (auto Path : + DriverArgs.getAllArgValues(options::OPT_hip_device_lib_path_EQ)) + LibraryPaths.push_back(DriverArgs.MakeArgString(Path)); + + addDirectoryList(DriverArgs, LibraryPaths, "-L", "HIP_DEVICE_LIB_PATH"); + + llvm::SmallVector BCLibs; + + // Add bitcode library in --hip-device-lib. + for (auto Lib : DriverArgs.getAllArgValues(options::OPT_hip_device_lib_EQ)) { + BCLibs.push_back(DriverArgs.MakeArgString(Lib)); + } + + // If --hip-device-lib is not set, add the default bitcode libraries. + if (BCLibs.empty()) { + // Get the bc lib file name for ISA version. For example, + // gfx803 => oclc_isa_version_803.amdgcn.bc. + std::string ISAVerBC = + "oclc_isa_version_" + GpuArch.drop_front(3).str() + ".amdgcn.bc"; + + llvm::StringRef FlushDenormalControlBC; + if (DriverArgs.hasArg(options::OPT_fcuda_flush_denormals_to_zero)) + FlushDenormalControlBC = "oclc_daz_opt_on.amdgcn.bc"; + else + FlushDenormalControlBC = "oclc_daz_opt_off.amdgcn.bc"; + + BCLibs.append({"hip.amdgcn.bc", "opencl.amdgcn.bc", "ocml.amdgcn.bc", + "ockl.amdgcn.bc", "oclc_finite_only_off.amdgcn.bc", + FlushDenormalControlBC, + "oclc_correctly_rounded_sqrt_on.amdgcn.bc", + "oclc_unsafe_math_off.amdgcn.bc", ISAVerBC}); + } + for (auto Lib : BCLibs) + addBCLib(getDriver(), DriverArgs, CC1Args, LibraryPaths, Lib); + } llvm::opt::DerivedArgList * Index: cfe/trunk/test/Driver/hip-device-libs.hip =================================================================== --- cfe/trunk/test/Driver/hip-device-libs.hip +++ cfe/trunk/test/Driver/hip-device-libs.hip @@ -20,10 +20,11 @@ // RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD -// COM: [[LLVM_LINK:"*.llvm-link"]] -// COM-SAME: "{{.*}}hip.amdgcn.bc" "{{.*}}opencl.amdgcn.bc" -// COM-SAME: "{{.*}}ocml.amdgcn.bc" "{{.*}}ockl.amdgcn.bc" -// FLUSHD-SAME: {{.*}} "{{.*}}oclc_daz_opt_on.amdgcn.bc" -// NOFLUSHD-SAME: {{.*}} "{{.*}}oclc_daz_opt_off.amdgcn.bc" -// COM-SAME: {{.*}} "-o" "{{.*}}-gfx900-linked-{{.*bc}}" +// COM: {{"[^"]*clang[^"]*"}} +// COM-SAME: "-mlink-builtin-bitcode" "{{.*}}hip.amdgcn.bc" +// COM-SAME: "-mlink-builtin-bitcode" "{{.*}}opencl.amdgcn.bc" +// COM-SAME: "-mlink-builtin-bitcode" "{{.*}}ocml.amdgcn.bc" +// COM-SAME: "-mlink-builtin-bitcode" "{{.*}}ockl.amdgcn.bc" +// FLUSHD-SAME: "-mlink-builtin-bitcode" "{{.*}}oclc_daz_opt_on.amdgcn.bc" +// NOFLUSHD-SAME: "-mlink-builtin-bitcode" "{{.*}}oclc_daz_opt_off.amdgcn.bc" Index: cfe/trunk/test/Driver/hip-toolchain-no-rdc.hip =================================================================== --- cfe/trunk/test/Driver/hip-toolchain-no-rdc.hip +++ cfe/trunk/test/Driver/hip-toolchain-no-rdc.hip @@ -22,11 +22,11 @@ // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" {{.*}} "-target-cpu" "gfx803" // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden" // CHECK-SAME: "-fapply-global-visibility-to-externs" +// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: {{.*}} "-o" [[A_BC_803:".*bc"]] "-x" "hip" // CHECK-SAME: {{.*}} [[A_SRC:".*a.cu"]] // CHECK: [[LLVM_LINK:"*.llvm-link"]] [[A_BC_803]] -// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: "-o" [[LINKED_BC_DEV_A_803:".*-gfx803-linked-.*bc"]] // CHECK: [[OPT:".*opt"]] [[LINKED_BC_DEV_A_803]] "-mtriple=amdgcn-amd-amdhsa" @@ -50,11 +50,11 @@ // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" {{.*}} "-target-cpu" "gfx900" // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden" // CHECK-SAME: "-fapply-global-visibility-to-externs" +// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: {{.*}} "-o" [[A_BC_900:".*bc"]] "-x" "hip" // CHECK-SAME: {{.*}} [[A_SRC]] // CHECK: [[LLVM_LINK:"*.llvm-link"]] [[A_BC_900]] -// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: "-o" [[LINKED_BC_DEV_A_900:".*-gfx900-linked-.*bc"]] // CHECK: [[OPT:".*opt"]] [[LINKED_BC_DEV_A_900]] "-mtriple=amdgcn-amd-amdhsa" @@ -94,11 +94,11 @@ // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" {{.*}} "-target-cpu" "gfx803" // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden" // CHECK-SAME: "-fapply-global-visibility-to-externs" +// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: {{.*}} "-o" [[B_BC_803:".*bc"]] "-x" "hip" // CHECK-SAME: {{.*}} [[B_SRC:".*b.hip"]] // CHECK: [[LLVM_LINK:"*.llvm-link"]] [[B_BC_803]] -// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: "-o" [[LINKED_BC_DEV_B_803:".*-gfx803-linked-.*bc"]] // CHECK: [[OPT:".*opt"]] [[LINKED_BC_DEV_B_803]] "-mtriple=amdgcn-amd-amdhsa" @@ -122,11 +122,11 @@ // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" {{.*}} "-target-cpu" "gfx900" // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden" // CHECK-SAME: "-fapply-global-visibility-to-externs" +// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: {{.*}} "-o" [[B_BC_900:".*bc"]] "-x" "hip" // CHECK-SAME: {{.*}} [[B_SRC]] // CHECK: [[LLVM_LINK:"*.llvm-link"]] [[B_BC_900]] -// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: "-o" [[LINKED_BC_DEV_B_900:".*-gfx900-linked-.*bc"]] // CHECK: [[OPT:".*opt"]] [[LINKED_BC_DEV_B_900]] "-mtriple=amdgcn-amd-amdhsa" Index: cfe/trunk/test/Driver/hip-toolchain-rdc.hip =================================================================== --- cfe/trunk/test/Driver/hip-toolchain-rdc.hip +++ cfe/trunk/test/Driver/hip-toolchain-rdc.hip @@ -18,6 +18,7 @@ // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" {{.*}} "-target-cpu" "gfx803" // CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fvisibility" "hidden" // CHECK-SAME: "-fapply-global-visibility-to-externs" +// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: {{.*}} "-o" [[A_BC:".*bc"]] "-x" "hip" // CHECK-SAME: {{.*}} [[A_SRC:".*a.cu"]] @@ -27,11 +28,11 @@ // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" {{.*}} "-target-cpu" "gfx803" // CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fvisibility" "hidden" // CHECK-SAME: "-fapply-global-visibility-to-externs" +// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: {{.*}} "-o" [[B_BC:".*bc"]] "-x" "hip" // CHECK-SAME: {{.*}} [[B_SRC:".*b.hip"]] // CHECK: [[LLVM_LINK:"*.llvm-link"]] [[A_BC]] [[B_BC]] -// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: "-o" [[LINKED_BC_DEV1:".*-gfx803-linked-.*bc"]] // CHECK: [[OPT:".*opt"]] [[LINKED_BC_DEV1]] "-mtriple=amdgcn-amd-amdhsa" @@ -49,18 +50,21 @@ // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" // CHECK-SAME: "-emit-llvm-bc" // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" {{.*}} "-target-cpu" "gfx900" -// CHECK-SAME: "-fcuda-is-device" {{.*}} "-o" [[A_BC:".*bc"]] "-x" "hip" +// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" +// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" +// CHECK-SAME: {{.*}} "-o" [[A_BC:".*bc"]] "-x" "hip" // CHECK-SAME: {{.*}} [[A_SRC]] // CHECK: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa" // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" // CHECK-SAME: "-emit-llvm-bc" // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" {{.*}} "-target-cpu" "gfx900" -// CHECK-SAME: "-fcuda-is-device" {{.*}} "-o" [[B_BC:".*bc"]] "-x" "hip" +// CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" +// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" +// CHECK-SAME: {{.*}} "-o" [[B_BC:".*bc"]] "-x" "hip" // CHECK-SAME: {{.*}} [[B_SRC]] // CHECK: [[LLVM_LINK]] [[A_BC]] [[B_BC]] -// CHECK-SAME: "{{.*}}lib1.bc" "{{.*}}lib2.bc" // CHECK-SAME: "-o" [[LINKED_BC_DEV2:".*-gfx900-linked-.*bc"]] // CHECK: [[OPT]] [[LINKED_BC_DEV2]] "-mtriple=amdgcn-amd-amdhsa"