r338916 - [OpenMP] Encode offload target triples into comdat key for offload initialization code
Author: sdmitriev Date: Fri Aug 3 13:19:28 2018 New Revision: 338916 URL: http://llvm.org/viewvc/llvm-project?rev=338916&view=rev Log: [OpenMP] Encode offload target triples into comdat key for offload initialization code Encoding offload target triples onto comdat group key for offload initialization code guarantees that it will be executed once per each unique combination of offload targets. Differential Revision: https://reviews.llvm.org/D50218 Added: cfe/trunk/test/OpenMP/openmp_offload_registration.cpp (with props) Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=338916&r1=338915&r2=338916&view=diff == --- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original) +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Fri Aug 3 13:19:28 2018 @@ -3818,7 +3818,19 @@ CGOpenMPRuntime::createOffloadingBinaryD CGF.disableDebugInfo(); const auto &FI = CGM.getTypes().arrangeNullaryFunction(); llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI); -std::string Descriptor = getName({"omp_offloading", "descriptor_reg"}); + +// Encode offload target triples into the registration function name. It +// will serve as a comdat key for the registration/unregistration code for +// this particular combination of offloading targets. +SmallVector RegFnNameParts(Devices.size() + 2U); +RegFnNameParts[0] = "omp_offloading"; +RegFnNameParts[1] = "descriptor_reg"; +llvm::transform(Devices, std::next(RegFnNameParts.begin(), 2), +[](const llvm::Triple &T) -> const std::string& { + return T.getTriple(); +}); +llvm::sort(std::next(RegFnNameParts.begin(), 2), RegFnNameParts.end()); +std::string Descriptor = getName(RegFnNameParts); RegFn = CGM.CreateGlobalInitOrDestructFunction(FTy, Descriptor, FI); CGF.StartFunction(GlobalDecl(), C.VoidTy, RegFn, FI, FunctionArgList()); CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__tgt_register_lib), Desc); Added: cfe/trunk/test/OpenMP/openmp_offload_registration.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/openmp_offload_registration.cpp?rev=338916&view=auto == --- cfe/trunk/test/OpenMP/openmp_offload_registration.cpp (added) +++ cfe/trunk/test/OpenMP/openmp_offload_registration.cpp Fri Aug 3 13:19:28 2018 @@ -0,0 +1,49 @@ +// Test for offload registration code for two targets +// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-unknown-linux-gnu -fopenmp-targets=x86_64-pc-linux-gnu,powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s +// expected-no-diagnostics + +void foo() { +#pragma omp target + {} +} + +// CHECK-DAG: [[ENTTY:%.+]] = type { i8*, i8*, i[[SZ:32|64]], i32, i32 } +// CHECK-DAG: [[DEVTY:%.+]] = type { i8*, i8*, [[ENTTY]]*, [[ENTTY]]* } +// CHECK-DAG: [[DSCTY:%.+]] = type { i32, [[DEVTY]]*, [[ENTTY]]*, [[ENTTY]]* } + +// Comdat key for the offload registration code. Should have sorted offload +// target triples encoded into the name. +// CHECK-DAG: $[[REGFN:\.omp_offloading\..+\.powerpc64le-ibm-linux-gnu\.x86_64-pc-linux-gnu+]] = comdat any + +// Check if offloading descriptor is created. +// CHECK: [[ENTBEGIN:@.+]] = external constant [[ENTTY]] +// CHECK: [[ENTEND:@.+]] = external constant [[ENTTY]] +// CHECK: [[DEV1BEGIN:@.+]] = extern_weak constant i8 +// CHECK: [[DEV1END:@.+]] = extern_weak constant i8 +// CHECK: [[DEV2BEGIN:@.+]] = extern_weak constant i8 +// CHECK: [[DEV2END:@.+]] = extern_weak constant i8 +// CHECK: [[IMAGES:@.+]] = internal unnamed_addr constant [2 x [[DEVTY]]] [{{.+}} { i8* [[DEV1BEGIN]], i8* [[DEV1END]], [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }, {{.+}} { i8* [[DEV2BEGIN]], i8* [[DEV2END]], [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }], comdat($[[REGFN]]) +// CHECK: [[DESC:@.+]] = internal constant [[DSCTY]] { i32 2, [[DEVTY]]* getelementptr inbounds ([2 x [[DEVTY]]], [2 x [[DEVTY]]]* [[IMAGES]], i32 0, i32 0), [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }, comdat($[[REGFN]]) + +// Check target registration is registered as a Ctor. +// CHECK: appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @[[REGFN]], i8* bitcast (void ()* @[[REGFN]] to i8*) }] + +// Check presence of foo() and the outlined target region +// CHECK: define void [[FOO:@.+]]() +// CHECK: define internal void [[OUTLINEDTARGET:@.+]]() + +// Check registration and unregistration code. + +// CHECK: define internal void @[[UNREGFN:.+]](i8*) +// CHECK-SAME: comdat($[[REGFN]]) { +// CHECK: call i32 @__tgt_unregister_lib([[DSCTY]]* [[DESC]]) +// CHECK: ret void +// CHECK: declare i32 @__tgt_unregister_lib([[DSCTY]]*) + +// CHECK: define linkonce h
r371633 - [Clang][Bundler] Fix for a potential memory leak [NFC]
Author: sdmitriev Date: Wed Sep 11 09:03:21 2019 New Revision: 371633 URL: http://llvm.org/viewvc/llvm-project?rev=371633&view=rev Log: [Clang][Bundler] Fix for a potential memory leak [NFC] Bundler leaks memory if it is called with -type=o but given input isn't an object file (though it has to have a known binary type like IR, archive, etc...). Memory leak is happening when binary object returned by the createBinary(...) call cannot be casted to an ObjectFile type. In this case returned BinaryOrErr object releases ownership of the binary, but no one is taking it (see line 626). Differential Revision: https://reviews.llvm.org/D67416 Modified: cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp Modified: cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp?rev=371633&r1=371632&r2=371633&view=diff == --- cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp (original) +++ cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp Wed Sep 11 09:03:21 2019 @@ -611,24 +611,15 @@ static FileHandler *CreateObjectFileHand // Check if the input file format is one that we know how to deal with. Expected> BinaryOrErr = createBinary(FirstInput); - // Failed to open the input as a known binary. Use the default binary handler. - if (!BinaryOrErr) { -// We don't really care about the error (we just consume it), if we could -// not get a valid device binary object we use the default binary handler. -consumeError(BinaryOrErr.takeError()); + // We only support regular object files. If failed to open the input as a + // known binary or this is not an object file use the default binary handler. + if (errorToBool(BinaryOrErr.takeError()) || !isa(*BinaryOrErr)) return new BinaryFileHandler(); - } - // We only support regular object files. If this is not an object file, - // default to the binary handler. The handler will be owned by the client of - // this function. - std::unique_ptr Obj( - dyn_cast(BinaryOrErr.get().release())); - - if (!Obj) -return new BinaryFileHandler(); - - return new ObjectFileHandler(std::move(Obj)); + // Otherwise create an object file handler. The handler will be owned by the + // client of this function. + return new ObjectFileHandler( + std::unique_ptr(cast(BinaryOrErr->release(; } /// Return an appropriate handler given the input files and options. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r371637 - [Clang][Bundler] Replace std::vector by SmallVector [NFC]
Author: sdmitriev Date: Wed Sep 11 09:28:47 2019 New Revision: 371637 URL: http://llvm.org/viewvc/llvm-project?rev=371637&view=rev Log: [Clang][Bundler] Replace std::vector by SmallVector [NFC] Differential Revision: https://reviews.llvm.org/D67413 Modified: cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp Modified: cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp?rev=371637&r1=371636&r2=371637&view=diff == --- cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp (original) +++ cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp Wed Sep 11 09:28:47 2019 @@ -17,6 +17,7 @@ #include "clang/Basic/Version.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" @@ -41,7 +42,6 @@ #include #include #include -#include using namespace llvm; using namespace llvm::object; @@ -658,10 +658,8 @@ static bool BundleFiles() { } // Open input files. - std::vector> InputBuffers( - InputFileNames.size()); - - unsigned Idx = 0; + SmallVector, 8u> InputBuffers; + InputBuffers.reserve(InputFileNames.size()); for (auto &I : InputFileNames) { ErrorOr> CodeOrErr = MemoryBuffer::getFileOrSTDIN(I); @@ -669,7 +667,7 @@ static bool BundleFiles() { errs() << "error: Can't open file " << I << ": " << EC.message() << "\n"; return true; } -InputBuffers[Idx++] = std::move(CodeOrErr.get()); +InputBuffers.emplace_back(std::move(CodeOrErr.get())); } // Get the file handler. We use the host buffer as reference. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r373523 - [Clang][Driver][NFC] Corrected DeviceActionBuilder methods' comments.
Author: sdmitriev Date: Wed Oct 2 13:44:45 2019 New Revision: 373523 URL: http://llvm.org/viewvc/llvm-project?rev=373523&view=rev Log: [Clang][Driver][NFC] Corrected DeviceActionBuilder methods' comments. Differential Revision: https://reviews.llvm.org/D68355 Modified: cfe/trunk/lib/Driver/Driver.cpp Modified: cfe/trunk/lib/Driver/Driver.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=373523&r1=373522&r2=373523&view=diff == --- cfe/trunk/lib/Driver/Driver.cpp (original) +++ cfe/trunk/lib/Driver/Driver.cpp Wed Oct 2 13:44:45 2019 @@ -2281,12 +2281,10 @@ class OffloadingActionBuilder final { return ABRT_Inactive; } -/// Append top level actions generated by the builder. Return true if errors -/// were found. +/// Append top level actions generated by the builder. virtual void appendTopLevelActions(ActionList &AL) {} -/// Append linker actions generated by the builder. Return true if errors -/// were found. +/// Append linker actions generated by the builder. virtual void appendLinkDependences(OffloadAction::DeviceDependences &DA) {} /// Initialize the builder. Return true if any initialization errors are ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r374219 - [Clang][OpenMP Offload] Add new tool for wrapping offload device binaries
Author: sdmitriev Date: Wed Oct 9 13:42:58 2019 New Revision: 374219 URL: http://llvm.org/viewvc/llvm-project?rev=374219&view=rev Log: [Clang][OpenMP Offload] Add new tool for wrapping offload device binaries This patch removes the remaining part of the OpenMP offload linker scripts which was used for inserting device binaries into the output linked binary. Device binaries are now inserted into the host binary with a help of the wrapper bit-code file which contains device binaries as data. Wrapper bit-code file is dynamically created by the clang driver with a help of new tool clang-offload-wrapper which takes device binaries as input and produces bit-code file with required contents. Wrapper bit-code is then compiled to an object and resulting object is appended to the host linking by the clang driver. This is the second part of the patch for eliminating OpenMP linker script (please see https://reviews.llvm.org/D64943). Differential Revision: https://reviews.llvm.org/D68166 Added: cfe/trunk/test/Driver/clang-offload-wrapper.c (with props) cfe/trunk/tools/clang-offload-wrapper/ cfe/trunk/tools/clang-offload-wrapper/CMakeLists.txt (with props) cfe/trunk/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp (with props) Modified: cfe/trunk/include/clang/Driver/Action.h cfe/trunk/include/clang/Driver/Options.td cfe/trunk/include/clang/Driver/ToolChain.h cfe/trunk/lib/Driver/Action.cpp cfe/trunk/lib/Driver/Driver.cpp cfe/trunk/lib/Driver/ToolChain.cpp cfe/trunk/lib/Driver/ToolChains/Clang.cpp cfe/trunk/lib/Driver/ToolChains/Clang.h cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp cfe/trunk/lib/Driver/ToolChains/CommonArgs.h cfe/trunk/lib/Driver/ToolChains/Cuda.cpp cfe/trunk/lib/Driver/ToolChains/Gnu.cpp cfe/trunk/test/Driver/openmp-offload-gpu.c cfe/trunk/test/Driver/openmp-offload.c cfe/trunk/tools/CMakeLists.txt Modified: cfe/trunk/include/clang/Driver/Action.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Action.h?rev=374219&r1=374218&r2=374219&view=diff == --- cfe/trunk/include/clang/Driver/Action.h (original) +++ cfe/trunk/include/clang/Driver/Action.h Wed Oct 9 13:42:58 2019 @@ -72,9 +72,10 @@ public: VerifyPCHJobClass, OffloadBundlingJobClass, OffloadUnbundlingJobClass, +OffloadWrapperJobClass, JobClassFirst = PreprocessJobClass, -JobClassLast = OffloadUnbundlingJobClass +JobClassLast = OffloadWrapperJobClass }; // The offloading kind determines if this action is binded to a particular @@ -625,6 +626,17 @@ public: } }; +class OffloadWrapperJobAction : public JobAction { + void anchor() override; + +public: + OffloadWrapperJobAction(ActionList &Inputs, types::ID Type); + + static bool classof(const Action *A) { +return A->getKind() == OffloadWrapperJobClass; + } +}; + } // namespace driver } // namespace clang Modified: cfe/trunk/include/clang/Driver/Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=374219&r1=374218&r2=374219&view=diff == --- cfe/trunk/include/clang/Driver/Options.td (original) +++ cfe/trunk/include/clang/Driver/Options.td Wed Oct 9 13:42:58 2019 @@ -1604,8 +1604,6 @@ def fnoopenmp_use_tls : Flag<["-"], "fno Flags<[CC1Option, NoArgumentUnused, HelpHidden]>; def fopenmp_targets_EQ : CommaJoined<["-"], "fopenmp-targets=">, Flags<[DriverOption, CC1Option]>, HelpText<"Specify comma-separated list of triples OpenMP offloading targets to be supported">; -def fopenmp_dump_offload_linker_script : Flag<["-"], "fopenmp-dump-offload-linker-script">, - Group, Flags<[NoArgumentUnused, HelpHidden]>; def fopenmp_relocatable_target : Flag<["-"], "fopenmp-relocatable-target">, Group, Flags<[CC1Option, NoArgumentUnused, HelpHidden]>; def fnoopenmp_relocatable_target : Flag<["-"], "fnoopenmp-relocatable-target">, Modified: cfe/trunk/include/clang/Driver/ToolChain.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=374219&r1=374218&r2=374219&view=diff == --- cfe/trunk/include/clang/Driver/ToolChain.h (original) +++ cfe/trunk/include/clang/Driver/ToolChain.h Wed Oct 9 13:42:58 2019 @@ -138,6 +138,7 @@ private: mutable std::unique_ptr Link; mutable std::unique_ptr IfsMerge; mutable std::unique_ptr OffloadBundler; + mutable std::unique_ptr OffloadWrapper; Tool *getClang() const; Tool *getAssemble() const; @@ -145,6 +146,7 @@ private: Tool *getIfsMerge() const; Tool *getClangAs() const; Tool *getOffloadBundler() const; + Tool *getOffloadWrapper() const; mutable std::unique_ptr SanitizerArguments; mutable std::unique_ptr XRayArguments; Modified: cfe/trunk/lib/Driver/Ac
r375177 - [clang-offload-wrapper][NFC] Use captured name of the entry type in LIT test
Author: sdmitriev Date: Thu Oct 17 14:55:39 2019 New Revision: 375177 URL: http://llvm.org/viewvc/llvm-project?rev=375177&view=rev Log: [clang-offload-wrapper][NFC] Use captured name of the entry type in LIT test Differential Revision: https://reviews.llvm.org/D69140 Modified: cfe/trunk/test/Driver/clang-offload-wrapper.c Modified: cfe/trunk/test/Driver/clang-offload-wrapper.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang-offload-wrapper.c?rev=375177&r1=375176&r2=375177&view=diff == --- cfe/trunk/test/Driver/clang-offload-wrapper.c (original) +++ cfe/trunk/test/Driver/clang-offload-wrapper.c Thu Oct 17 14:55:39 2019 @@ -31,7 +31,7 @@ // CHECK-IR: [[ENTBEGIN:@.+]] = external hidden constant [[ENTTY]] // CHECK-IR: [[ENTEND:@.+]] = external hidden constant [[ENTTY]] -// CHECK-IR: [[DUMMY:@.+]] = hidden constant [0 x %__tgt_offload_entry] zeroinitializer, section "omp_offloading_entries" +// CHECK-IR: [[DUMMY:@.+]] = hidden constant [0 x [[ENTTY]]] zeroinitializer, section "omp_offloading_entries" // CHECK-IR: [[BIN:@.+]] = internal unnamed_addr constant [[BINTY:\[[0-9]+ x i8\]]] c"Content of device file{{.+}}" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] dd50104 - [Clang][Bundler] Error reporting improvements
Author: Sergey Dmitriev Date: 2019-10-25T16:29:57-07:00 New Revision: dd501045cdea1c80b6788f0266d2a79f8b412eea URL: https://github.com/llvm/llvm-project/commit/dd501045cdea1c80b6788f0266d2a79f8b412eea DIFF: https://github.com/llvm/llvm-project/commit/dd501045cdea1c80b6788f0266d2a79f8b412eea.diff LOG: [Clang][Bundler] Error reporting improvements - Changed FileHandler read/write methods to return llvm::Error - Using unified way of reporting errors - Removed trailing '.' from the error messages Differential Revision: https://reviews.llvm.org/D67031 Added: Modified: clang/test/Driver/clang-offload-bundler.c clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp Removed: diff --git a/clang/test/Driver/clang-offload-bundler.c b/clang/test/Driver/clang-offload-bundler.c index be17b092ef34..35c327c56b3b 100644 --- a/clang/test/Driver/clang-offload-bundler.c +++ b/clang/test/Driver/clang-offload-bundler.c @@ -52,27 +52,27 @@ // Check errors. // // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR1 -// CK-ERR1: error: only one input file supported in unbundling mode. -// CK-ERR1: error: number of output files and targets should match in unbundling mode. +// CK-ERR1: error: only one input file supported in unbundling mode +// CK-ERR1: error: number of output files and targets should match in unbundling mode // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR2 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR2 -// CK-ERR2: error: number of input files and targets should match in bundling mode. +// CK-ERR2: error: number of input files and targets should match in bundling mode // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.i,%t.tgt1,%t.tgt2 -inputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR3 -// CK-ERR3: error: only one output file supported in bundling mode. -// CK-ERR3: error: number of input files and targets should match in bundling mode. +// CK-ERR3: error: only one output file supported in bundling mode +// CK-ERR3: error: number of input files and targets should match in bundling mode // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu -outputs=%t.i,%t.tgt1,%t.tgt2 -inputs=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR4 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.i,%t.tgt1 -inputs=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR4 -// CK-ERR4: error: number of output files and targets should match in unbundling mode. +// CK-ERR4: error: number of output files and targets should match in unbundling mode -// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2.notexist -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR5 -// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.i,%t.tgt1,%t.tgt2 -inputs=%t.bundle.i.notexist -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR5 -// CK-ERR5: error: Can't open file {{.+}}.notexist: {{N|n}}o such file or directory +// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2.notexist -outputs=%t.bundle.i 2>&1 | FileCheck %s -DFILE=%t.tgt2.notexist --check-prefix CK-ERR5 +// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.i,%t.tgt1,%t.tgt2 -inputs=%t.bundle.i.notexist -unbundle 2>&1 | FileCheck %s -DFILE=%t.bundle.i.notexist --check-prefix CK-ERR5 +// CK-ERR5: error: '[[FILE]]': {{N|n}}o such file or directory -// RUN: not clang-offload-bundler -type=invalid -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR6 -// CK-ERR6: error: invalid file type specified. +// RUN: not clang-offload-bundler -type=invalid -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-li
[clang] 93b29d3 - Revert "[Clang][Bundler] Error reporting improvements"
Author: Sergey Dmitriev Date: 2019-10-25T17:57:55-07:00 New Revision: 93b29d3882baf7df42e4e9bc26b977b00373ef56 URL: https://github.com/llvm/llvm-project/commit/93b29d3882baf7df42e4e9bc26b977b00373ef56 DIFF: https://github.com/llvm/llvm-project/commit/93b29d3882baf7df42e4e9bc26b977b00373ef56.diff LOG: Revert "[Clang][Bundler] Error reporting improvements" This reverts commit dd501045cdea1c80b6788f0266d2a79f8b412eea. Added: Modified: clang/test/Driver/clang-offload-bundler.c clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp Removed: diff --git a/clang/test/Driver/clang-offload-bundler.c b/clang/test/Driver/clang-offload-bundler.c index 35c327c56b3b..be17b092ef34 100644 --- a/clang/test/Driver/clang-offload-bundler.c +++ b/clang/test/Driver/clang-offload-bundler.c @@ -52,27 +52,27 @@ // Check errors. // // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR1 -// CK-ERR1: error: only one input file supported in unbundling mode -// CK-ERR1: error: number of output files and targets should match in unbundling mode +// CK-ERR1: error: only one input file supported in unbundling mode. +// CK-ERR1: error: number of output files and targets should match in unbundling mode. // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR2 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR2 -// CK-ERR2: error: number of input files and targets should match in bundling mode +// CK-ERR2: error: number of input files and targets should match in bundling mode. // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.i,%t.tgt1,%t.tgt2 -inputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR3 -// CK-ERR3: error: only one output file supported in bundling mode -// CK-ERR3: error: number of input files and targets should match in bundling mode +// CK-ERR3: error: only one output file supported in bundling mode. +// CK-ERR3: error: number of input files and targets should match in bundling mode. // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu -outputs=%t.i,%t.tgt1,%t.tgt2 -inputs=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR4 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.i,%t.tgt1 -inputs=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR4 -// CK-ERR4: error: number of output files and targets should match in unbundling mode +// CK-ERR4: error: number of output files and targets should match in unbundling mode. -// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2.notexist -outputs=%t.bundle.i 2>&1 | FileCheck %s -DFILE=%t.tgt2.notexist --check-prefix CK-ERR5 -// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.i,%t.tgt1,%t.tgt2 -inputs=%t.bundle.i.notexist -unbundle 2>&1 | FileCheck %s -DFILE=%t.bundle.i.notexist --check-prefix CK-ERR5 -// CK-ERR5: error: '[[FILE]]': {{N|n}}o such file or directory +// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2.notexist -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR5 +// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.i,%t.tgt1,%t.tgt2 -inputs=%t.bundle.i.notexist -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR5 +// CK-ERR5: error: Can't open file {{.+}}.notexist: {{N|n}}o such file or directory -// RUN: not clang-offload-bundler -type=invalid -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s -DTYPE=invalid --check-prefix CK-ERR6 -// CK-ERR6: error: '[[TYPE]]': invalid file type specified +// RUN: not clang-offload-bundler -type=invalid -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s --
[clang] edb1a1d - Reland "[Clang][Bundler] Error reporting improvements"
Author: Sergey Dmitriev Date: 2019-10-25T19:00:06-07:00 New Revision: edb1a1de1b79c190ed7b76cf889a295c72e73729 URL: https://github.com/llvm/llvm-project/commit/edb1a1de1b79c190ed7b76cf889a295c72e73729 DIFF: https://github.com/llvm/llvm-project/commit/edb1a1de1b79c190ed7b76cf889a295c72e73729.diff LOG: Reland "[Clang][Bundler] Error reporting improvements" - Changed FileHandler read/write methods to return llvm::Error - Using unified way of reporting errors - Removed trailing '.' from the error messages Differential Revision: https://reviews.llvm.org/D67031 Added: Modified: clang/test/Driver/clang-offload-bundler.c clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp Removed: diff --git a/clang/test/Driver/clang-offload-bundler.c b/clang/test/Driver/clang-offload-bundler.c index be17b092ef34..35c327c56b3b 100644 --- a/clang/test/Driver/clang-offload-bundler.c +++ b/clang/test/Driver/clang-offload-bundler.c @@ -52,27 +52,27 @@ // Check errors. // // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR1 -// CK-ERR1: error: only one input file supported in unbundling mode. -// CK-ERR1: error: number of output files and targets should match in unbundling mode. +// CK-ERR1: error: only one input file supported in unbundling mode +// CK-ERR1: error: number of output files and targets should match in unbundling mode // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR2 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR2 -// CK-ERR2: error: number of input files and targets should match in bundling mode. +// CK-ERR2: error: number of input files and targets should match in bundling mode // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.i,%t.tgt1,%t.tgt2 -inputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR3 -// CK-ERR3: error: only one output file supported in bundling mode. -// CK-ERR3: error: number of input files and targets should match in bundling mode. +// CK-ERR3: error: only one output file supported in bundling mode +// CK-ERR3: error: number of input files and targets should match in bundling mode // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu -outputs=%t.i,%t.tgt1,%t.tgt2 -inputs=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR4 // RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.i,%t.tgt1 -inputs=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR4 -// CK-ERR4: error: number of output files and targets should match in unbundling mode. +// CK-ERR4: error: number of output files and targets should match in unbundling mode -// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2.notexist -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR5 -// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.i,%t.tgt1,%t.tgt2 -inputs=%t.bundle.i.notexist -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR5 -// CK-ERR5: error: Can't open file {{.+}}.notexist: {{N|n}}o such file or directory +// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2.notexist -outputs=%t.bundle.i 2>&1 | FileCheck %s -DFILE=%t.tgt2.notexist --check-prefix CK-ERR5 +// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.i,%t.tgt1,%t.tgt2 -inputs=%t.bundle.i.notexist -unbundle 2>&1 | FileCheck %s -DFILE=%t.bundle.i.notexist --check-prefix CK-ERR5 +// CK-ERR5: error: '[[FILE]]': {{N|n}}o such file or directory -// RUN: not clang-offload-bundler -type=invalid -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR6 -// CK-ERR6: error: invalid file type specified. +// RUN: not clang-offload-bundler -type=invalid -targets=host-%itanium_abi_triple,openmp-powerpc64
r369955 - [Clang][Bundler] Use llvm-objcopy for creating fat object files
Author: sdmitriev Date: Mon Aug 26 12:48:43 2019 New Revision: 369955 URL: http://llvm.org/viewvc/llvm-project?rev=369955&view=rev Log: [Clang][Bundler] Use llvm-objcopy for creating fat object files clang-offload-bundler currently uses partial linking for creating fat object files, but such technique cannot be used on Windows due to the absence of partial linking support in the linker. This patch changes implementation to use llvm-objcopy for merging device and host objects instead of doing partial linking. This is one step forward towards enabling OpenMP offload on Windows. Differential Revision: https://reviews.llvm.org/D66485 Modified: cfe/trunk/test/CMakeLists.txt cfe/trunk/test/Driver/clang-offload-bundler.c cfe/trunk/tools/clang-offload-bundler/CMakeLists.txt cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp Modified: cfe/trunk/test/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=369955&r1=369954&r2=369955&view=diff == --- cfe/trunk/test/CMakeLists.txt (original) +++ cfe/trunk/test/CMakeLists.txt Mon Aug 26 12:48:43 2019 @@ -111,6 +111,7 @@ if( NOT CLANG_BUILT_STANDALONE ) llvm-lto2 llvm-modextract llvm-nm +llvm-objcopy llvm-objdump llvm-profdata llvm-readelf Modified: cfe/trunk/test/Driver/clang-offload-bundler.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang-offload-bundler.c?rev=369955&r1=369954&r2=369955&view=diff == --- cfe/trunk/test/Driver/clang-offload-bundler.c (original) +++ cfe/trunk/test/Driver/clang-offload-bundler.c Mon Aug 26 12:48:43 2019 @@ -229,12 +229,9 @@ // tests. // -// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.o,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.o -### -dump-temporary-files 2>&1 \ -// RUN: | FileCheck %s --check-prefix CK-OBJ-CMD -// CK-OBJ-CMD: private constant [{{[0-9]+}} x i8] c"{{.+}}", section "__CLANG_OFFLOAD_BUNDLE__host-[[HOST:.+]]" -// CK-OBJ-CMD: private constant [{{[0-9]+}} x i8] c"Content of device file 1{{.+}}", section "__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu" -// CK-OBJ-CMD: private constant [{{[0-9]+}} x i8] c"Content of device file 2{{.+}}", section "__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu" -// CK-OBJ-CMD: clang{{(.exe)?}}" "-r" "-target" "[[HOST]]" "-o" "{{.+}}.o" "{{.+}}.o" "{{.+}}.bc" "-nostdlib" +// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.o,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.o -### 2>&1 \ +// RUN: | FileCheck %s -DHOST=%itanium_abi_triple -DINOBJ1=%t.o -DINOBJ2=%t.tgt1 -DINOBJ3=%t.tgt2 -DOUTOBJ=%t.bundle3.o --check-prefix CK-OBJ-CMD +// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=[[INOBJ1]]" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=[[INOBJ2]]" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=[[INOBJ3]]" "[[INOBJ1]]" "[[OUTOBJ]]" // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.o,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.o // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.o,%t.res.tgt1,%t.res.tgt2 -inputs=%t.bundle3.o -unbundle Modified: cfe/trunk/tools/clang-offload-bundler/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-offload-bundler/CMakeLists.txt?rev=369955&r1=369954&r2=369955&view=diff == --- cfe/trunk/tools/clang-offload-bundler/CMakeLists.txt (original) +++ cfe/trunk/tools/clang-offload-bundler/CMakeLists.txt Mon Aug 26 12:48:43 2019 @@ -1,4 +1,4 @@ -set(LLVM_LINK_COMPONENTS BitWriter Core Object Support) +set(LLVM_LINK_COMPONENTS Object Support) if(NOT CLANG_BUILT_STANDALONE) set(tablegen_deps intrinsics_gen) Modified: cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp?rev=369955&r1=369954&r2=369955&view=diff == --- cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp (original) +++ cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp Mon Aug 26 12:48:43 2019 @@ -21,12 +21,6 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Triple.h" -#include "llvm/Bitcode/BitcodeWriter.h" -#include "llvm/IR/Constant.h" -#include "llvm/IR/Constants.h" -#include "llvm/IR/GlobalVariable.h" -#in
r370115 - [Clang][Bundler] Fix for a hang when unbundling fat binary
Author: sdmitriev Date: Tue Aug 27 14:47:52 2019 New Revision: 370115 URL: http://llvm.org/viewvc/llvm-project?rev=370115&view=rev Log: [Clang][Bundler] Fix for a hang when unbundling fat binary clang-offload-bundler tool may hang under certain conditions when it extracts a subset of all available device bundles from the fat binary that is handled by the BinaryFileHandler. This patch fixes this problem. Differential Revision: https://reviews.llvm.org/D66598 Modified: cfe/trunk/test/Driver/clang-offload-bundler.c cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp Modified: cfe/trunk/test/Driver/clang-offload-bundler.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang-offload-bundler.c?rev=370115&r1=370114&r2=370115&view=diff == --- cfe/trunk/test/Driver/clang-offload-bundler.c (original) +++ cfe/trunk/test/Driver/clang-offload-bundler.c Tue Aug 27 14:47:52 2019 @@ -221,6 +221,11 @@ // RUN: diff %t.empty %t.res.tgt1 // RUN: diff %t.empty %t.res.tgt2 +// Check that we do not have to unbundle all available bundles from the fat binary. +// RUN: clang-offload-bundler -type=ast -targets=host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -outputs=%t.res.ast,%t.res.tgt2 -inputs=%t.bundle3.unordered.ast -unbundle +// RUN: diff %t.ast %t.res.ast +// RUN: diff %t.tgt2 %t.res.tgt2 + // // Check object bundle/unbundle. The content should be bundled into an ELF // section (we are using a PowerPC little-endian host which uses ELF). We Modified: cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp?rev=370115&r1=370114&r2=370115&view=diff == --- cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp (original) +++ cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp Tue Aug 27 14:47:52 2019 @@ -215,6 +215,7 @@ class BinaryFileHandler final : public F /// Iterator for the bundle information that is being read. StringMap::iterator CurBundleInfo; + StringMap::iterator NextBundleInfo; public: BinaryFileHandler() : FileHandler() {} @@ -284,19 +285,19 @@ public: BundlesInfo[Triple] = BundleInfo(Size, Offset); } // Set the iterator to where we will start to read. -CurBundleInfo = BundlesInfo.begin(); +CurBundleInfo = BundlesInfo.end(); +NextBundleInfo = BundlesInfo.begin(); } StringRef ReadBundleStart(MemoryBuffer &Input) final { -if (CurBundleInfo == BundlesInfo.end()) +if (NextBundleInfo == BundlesInfo.end()) return StringRef(); - +CurBundleInfo = NextBundleInfo++; return CurBundleInfo->first(); } void ReadBundleEnd(MemoryBuffer &Input) final { assert(CurBundleInfo != BundlesInfo.end() && "Invalid reader info!"); -++CurBundleInfo; } void ReadBundle(raw_fd_ostream &OS, MemoryBuffer &Input) final { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r370143 - [Clang][Bundler] Do not require host triple for extracting device bundles
Author: sdmitriev Date: Tue Aug 27 18:26:13 2019 New Revision: 370143 URL: http://llvm.org/viewvc/llvm-project?rev=370143&view=rev Log: [Clang][Bundler] Do not require host triple for extracting device bundles Bundler currently requires host triple to be provided no matter if you are performing bundling or unbundling, but for unbundling operation such requirement is too restrictive. You may for example want to examine device part of the object for a particular offload target, but you have to extract host part as well even though you do not need it. Host triple isn't really needed for unbundling, so this patch removes that requirement. Differential Revision: https://reviews.llvm.org/D66601 Modified: cfe/trunk/test/Driver/clang-offload-bundler.c cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp Modified: cfe/trunk/test/Driver/clang-offload-bundler.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang-offload-bundler.c?rev=370143&r1=370142&r2=370143&view=diff == --- cfe/trunk/test/Driver/clang-offload-bundler.c (original) +++ cfe/trunk/test/Driver/clang-offload-bundler.c Tue Aug 27 18:26:13 2019 @@ -156,14 +156,20 @@ // RUN: diff %t.i %t.res.i // RUN: diff %t.tgt1 %t.res.tgt1 // RUN: diff %t.tgt2 %t.res.tgt2 +// RUN: clang-offload-bundler -type=i -targets=openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.tgt1 -inputs=%t.bundle3.i -unbundle +// RUN: diff %t.tgt1 %t.res.tgt1 // RUN: clang-offload-bundler -type=ii -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.ii,%t.res.tgt1,%t.res.tgt2 -inputs=%t.bundle3.ii -unbundle // RUN: diff %t.ii %t.res.ii // RUN: diff %t.tgt1 %t.res.tgt1 // RUN: diff %t.tgt2 %t.res.tgt2 +// RUN: clang-offload-bundler -type=ii -targets=openmp-x86_64-pc-linux-gnu -outputs=%t.res.tgt2 -inputs=%t.bundle3.ii -unbundle +// RUN: diff %t.tgt2 %t.res.tgt2 // RUN: clang-offload-bundler -type=ll -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.ll,%t.res.tgt1,%t.res.tgt2 -inputs=%t.bundle3.ll -unbundle // RUN: diff %t.ll %t.res.ll // RUN: diff %t.tgt1 %t.res.tgt1 // RUN: diff %t.tgt2 %t.res.tgt2 +// RUN: clang-offload-bundler -type=ll -targets=openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.tgt1 -inputs=%t.bundle3.ll -unbundle +// RUN: diff %t.tgt1 %t.res.tgt1 // RUN: clang-offload-bundler -type=s -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.s,%t.res.tgt1,%t.res.tgt2 -inputs=%t.bundle3.s -unbundle // RUN: diff %t.s %t.res.s // RUN: diff %t.tgt1 %t.res.tgt1 @@ -172,6 +178,8 @@ // RUN: diff %t.s %t.res.s // RUN: diff %t.tgt1 %t.res.tgt1 // RUN: diff %t.tgt2 %t.res.tgt2 +// RUN: clang-offload-bundler -type=s -targets=openmp-x86_64-pc-linux-gnu -outputs=%t.res.tgt2 -inputs=%t.bundle3.s -unbundle +// RUN: diff %t.tgt2 %t.res.tgt2 // Check if we can unbundle a file with no magic strings. // RUN: clang-offload-bundler -type=s -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.s,%t.res.tgt1,%t.res.tgt2 -inputs=%t.s -unbundle @@ -183,6 +191,10 @@ // RUN: diff %t.empty %t.res.tgt1 // RUN: diff %t.empty %t.res.tgt2 +// Check that bindler prints an error if given host bundle does not exist in the fat binary. +// RUN: not clang-offload-bundler -type=s -targets=host-x86_64-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.s,%t.res.tgt1 -inputs=%t.bundle3.s -unbundle 2>&1 | FileCheck %s --check-prefix CK-NO-HOST-BUNDLE +// CK-NO-HOST-BUNDLE: error: Can't find bundle for the host target + // // Check binary bundle/unbundle. The content that we have before bundling must be the same we have after unbundling. // @@ -194,10 +206,14 @@ // RUN: diff %t.bc %t.res.bc // RUN: diff %t.tgt1 %t.res.tgt1 // RUN: diff %t.tgt2 %t.res.tgt2 +// RUN: clang-offload-bundler -type=bc -targets=openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.tgt1 -inputs=%t.bundle3.bc -unbundle +// RUN: diff %t.tgt1 %t.res.tgt1 // RUN: clang-offload-bundler -type=gch -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.gch,%t.res.tgt1,%t.res.tgt2 -inputs=%t.bundle3.gch -unbundle // RUN: diff %t.ast %t.res.gch // RUN: diff %t.tgt1 %t.res.tgt1 // RUN: diff %t.tgt2 %t.res.tgt2 +// RUN: clang-offload-bundler -type=gch -targets=openmp-x86_64-pc-linux-gnu -outputs=%t.res.tgt2 -inputs=%t.bundle3.gch -unbundle +// RUN: diff %t.tgt2 %t.res.tgt2 // RUN: clang-offload-bundler -type=ast -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.ast,%t.res.tgt1,%t.res.tgt2 -inputs=%t.bundle3.ast -unbundle // RUN: diff %t.ast %t.res.ast // RUN: diff %t.tgt1 %t.res.tgt1 @@ -210,6 +226,8 @@ // RUN: diff %t.ast %t.res.ast
[clang] 1b0ca81 - [clang-offload-bundler] use std::forward_list for storing temp file names [NFC]
Author: Sergey Dmitriev Date: 2020-11-24T08:07:31-08:00 New Revision: 1b0ca81a6c358d2d52d4f84b7f42e620ead1ed26 URL: https://github.com/llvm/llvm-project/commit/1b0ca81a6c358d2d52d4f84b7f42e620ead1ed26 DIFF: https://github.com/llvm/llvm-project/commit/1b0ca81a6c358d2d52d4f84b7f42e620ead1ed26.diff LOG: [clang-offload-bundler] use std::forward_list for storing temp file names [NFC] Use a different container that preserves existing elements on modification for storing temporary file names. Current container can make StringRefs returned earlier invalid on reallocation. Reviewed By: ABataev Differential Revision: https://reviews.llvm.org/D92010 Added: Modified: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp Removed: diff --git a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp index 44c46a89a859..a1b2fecb4a80 100644 --- a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -394,7 +395,7 @@ class TempFileHandlerRAII { if (std::error_code EC = sys::fs::createTemporaryFile("clang-offload-bundler", "tmp", File)) return createFileError(File, EC); -Files.push_back(File); +Files.push_front(File); if (Contents) { std::error_code EC; @@ -403,11 +404,11 @@ class TempFileHandlerRAII { return createFileError(File, EC); OS.write(Contents->data(), Contents->size()); } -return Files.back(); +return Files.front(); } private: - SmallVector, 4u> Files; + std::forward_list> Files; }; } // end anonymous namespace ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 8998a8a - [clang-offload-bundler] Add sections and set section flags using one llvm-objcopy invocation
Author: Sergey Dmitriev Date: 2021-05-18T08:44:41-07:00 New Revision: 8998a8aa97f81c758403615ec897ce79c1ccdcad URL: https://github.com/llvm/llvm-project/commit/8998a8aa97f81c758403615ec897ce79c1ccdcad DIFF: https://github.com/llvm/llvm-project/commit/8998a8aa97f81c758403615ec897ce79c1ccdcad.diff LOG: [clang-offload-bundler] Add sections and set section flags using one llvm-objcopy invocation llvm-objcopy has been changed to support adding a section and updating section flags in one run (D90438), so we can now change clang-offload-bundler to run llvm-objcopy tool only once when creating fat object. Reviewed By: ABataev Differential Revision: https://reviews.llvm.org/D102670 Added: Modified: clang/test/Driver/clang-offload-bundler.c clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp Removed: diff --git a/clang/test/Driver/clang-offload-bundler.c b/clang/test/Driver/clang-offload-bundler.c index 32fe6dad1f3f3..f77a240e79b51 100644 --- a/clang/test/Driver/clang-offload-bundler.c +++ b/clang/test/Driver/clang-offload-bundler.c @@ -274,8 +274,7 @@ // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.o,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.o -### 2>&1 \ // RUN: | FileCheck %s -DHOST=%itanium_abi_triple -DINOBJ1=%t.o -DINOBJ2=%t.tgt1 -DINOBJ3=%t.tgt2 -DOUTOBJ=%t.bundle3.o --check-prefix CK-OBJ-CMD -// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]={{.*}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=[[INOBJ2]]" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=[[INOBJ3]]" "[[INOBJ1]]" "[[TEMPOBJ:.*]]" -// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=readonly,exclude" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=readonly,exclude" "[[TEMPOBJ]]" "[[OUTOBJ]]" +// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]={{.*}}" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=[[INOBJ2]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=[[INOBJ3]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=readonly,exclude" "[[INOBJ1]]" "[[OUTOBJ]]" // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.o,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.o // RUN: clang-offload-bundler -type=o -inputs=%t.bundle3.o -list | FileCheck -check-prefix=CKLST %s diff --git a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp index 0b56d19e616c1..74b7a4539aff5 100644 --- a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp @@ -578,11 +578,7 @@ class ObjectFileHandler final : public FileHandler { // We will use llvm-objcopy to add target objects sections to the output // fat object. These sections should have 'exclude' flag set which tells // link editor to remove them from linker inputs when linking executable or -// shared library. llvm-objcopy currently does not support adding new -// section and changing flags for the added section in one invocation, and -// because of that we have to run it two times. First run adds sections and -// the second changes flags. -// TODO: change it to one run once llvm-objcopy starts supporting that. +// shared library. // Find llvm-objcopy in order to create the bundle binary. ErrorOr Objcopy = sys::findProgramByName( @@ -600,14 +596,8 @@ class ObjectFileHandler final : public FileHandler { // Temporary files that need to be removed. TempFileHandlerRAII TempFiles; -// Create an intermediate temporary file to save object after the first -// llvm-objcopy run. -Expected IntermediateObjOrErr = TempFiles.Create(None); -if (!IntermediateObjOrErr) - return IntermediateObjOrErr.takeError(); -StringRef IntermediateObj = *IntermediateObjOrErr; - -// Compose llvm-objcopy command line for add target objects' sections. +// Compose llvm-objcopy command line for add target objects' sections with +// appropriate flags. BumpPtrAllocator Alloc; StringSaver SS{Alloc}; SmallVector ObjcopyArgs{"llvm-objcopy"}; @@ -627,20 +617,11 @@ class ObjectFileHandler final : public FileHandler { ObjcopyArgs.push_back(SS.save(Twine("--add-section
[clang] f8444a8 - [clang-offload-bundler] Delimit input/output file names by '--' for llvm-objcopy
Author: Sergey Dmitriev Date: 2021-05-19T20:25:05-07:00 New Revision: f8444a8e94227401f816d948ec09ae1b2761d575 URL: https://github.com/llvm/llvm-project/commit/f8444a8e94227401f816d948ec09ae1b2761d575 DIFF: https://github.com/llvm/llvm-project/commit/f8444a8e94227401f816d948ec09ae1b2761d575.diff LOG: [clang-offload-bundler] Delimit input/output file names by '--' for llvm-objcopy That fixes a problem of using bundler with file names starting with dash. Reviewed By: ABataev Differential Revision: https://reviews.llvm.org/D102752 Added: Modified: clang/test/Driver/clang-offload-bundler.c clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp Removed: diff --git a/clang/test/Driver/clang-offload-bundler.c b/clang/test/Driver/clang-offload-bundler.c index f77a240e79b51..221aaeb6316d8 100644 --- a/clang/test/Driver/clang-offload-bundler.c +++ b/clang/test/Driver/clang-offload-bundler.c @@ -274,7 +274,7 @@ // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.o,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.o -### 2>&1 \ // RUN: | FileCheck %s -DHOST=%itanium_abi_triple -DINOBJ1=%t.o -DINOBJ2=%t.tgt1 -DINOBJ3=%t.tgt2 -DOUTOBJ=%t.bundle3.o --check-prefix CK-OBJ-CMD -// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]={{.*}}" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=[[INOBJ2]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=[[INOBJ3]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=readonly,exclude" "[[INOBJ1]]" "[[OUTOBJ]]" +// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]={{.*}}" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=[[INOBJ2]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=[[INOBJ3]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=readonly,exclude" "--" "[[INOBJ1]]" "[[OUTOBJ]]" // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.o,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.o // RUN: clang-offload-bundler -type=o -inputs=%t.bundle3.o -list | FileCheck -check-prefix=CKLST %s diff --git a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp index 74b7a4539aff5..afa7c292a53f1 100644 --- a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp @@ -621,6 +621,7 @@ class ObjectFileHandler final : public FileHandler { OFFLOAD_BUNDLER_MAGIC_STR + TargetNames[I] + "=readonly,exclude")); } +ObjcopyArgs.push_back("--"); ObjcopyArgs.push_back(InputFileNames[HostInputIndex]); ObjcopyArgs.push_back(OutputFileNames.front()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 4b55329 - [clang-offload-bundler] Reuse original file extension for device archive member
Author: Sergey Dmitriev Date: 2021-11-30T20:38:59-08:00 New Revision: 4b553297ef3ee4dc2119d5429adf3072e90fac38 URL: https://github.com/llvm/llvm-project/commit/4b553297ef3ee4dc2119d5429adf3072e90fac38 DIFF: https://github.com/llvm/llvm-project/commit/4b553297ef3ee4dc2119d5429adf3072e90fac38.diff LOG: [clang-offload-bundler] Reuse original file extension for device archive member This patch changes clang-offload-bundler to use the original file extension for the device archive member when unbundling archives instead of printing a warning and defaulting to ".o". Differential Revision: https://reviews.llvm.org/D114776 Added: clang/test/Driver/fat-archive-unbundle-ext.c Modified: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp Removed: diff --git a/clang/test/Driver/fat-archive-unbundle-ext.c b/clang/test/Driver/fat-archive-unbundle-ext.c new file mode 100644 index 0..90e0803daff67 --- /dev/null +++ b/clang/test/Driver/fat-archive-unbundle-ext.c @@ -0,0 +1,21 @@ +// REQUIRES: x86-registered-target +// UNSUPPORTED: windows, darwin, aix + +// Generate dummy fat object +// RUN: %clang -O0 -target %itanium_abi_triple %s -c -o %t.host.o +// RUN: echo 'Content of device file' > %t.tgt.o +// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-%itanium_abi_triple -inputs=%t.host.o,%t.tgt.o -outputs=%t.fat.obj + +// Then create a static archive with that object +// RUN: rm -f %t.fat.a +// RUN: llvm-ar cr %t.fat.a %t.fat.obj + +// Unbundle device part from the archive. Check that bundler does not print warnings. +// RUN: clang-offload-bundler -unbundle -type=a -targets=openmp-%itanium_abi_triple -inputs=%t.fat.a -outputs=%t.tgt.a 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-WARNING %s +// CHECK-WARNING-NOT: warning + +// Check that device archive member inherited file extension from the original file. +// RUN: llvm-ar t %t.tgt.a | FileCheck --check-prefix=CHECK-ARCHIVE %s +// CHECK-ARCHIVE: {{\.obj$}} + +void foo(void) {} diff --git a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp index 0dbb75f67b289..f9ccbd36dc407 100644 --- a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp @@ -180,21 +180,19 @@ struct OffloadTargetInfo { } }; -static StringRef getDeviceFileExtension(StringRef Device) { +static StringRef getDeviceFileExtension(StringRef Device, +StringRef BundleFileName) { if (Device.contains("gfx")) return ".bc"; if (Device.contains("sm_")) return ".cubin"; - - WithColor::warning() << "Could not determine extension for archive" - "members, using \".o\"\n"; - return ".o"; + return sys::path::extension(BundleFileName); } static std::string getDeviceLibraryFileName(StringRef BundleFileName, StringRef Device) { StringRef LibName = sys::path::stem(BundleFileName); - StringRef Extension = getDeviceFileExtension(Device); + StringRef Extension = getDeviceFileExtension(Device, BundleFileName); std::string Result; Result += LibName; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6e82d0d - [Clang][Bundler] Add 'exclude' flag to target objects sections
Author: Sergey Dmitriev Date: 2020-01-29T09:00:45-08:00 New Revision: 6e82d0dfd8dfaebc3985e73740a020b273a2dd31 URL: https://github.com/llvm/llvm-project/commit/6e82d0dfd8dfaebc3985e73740a020b273a2dd31 DIFF: https://github.com/llvm/llvm-project/commit/6e82d0dfd8dfaebc3985e73740a020b273a2dd31.diff LOG: [Clang][Bundler] Add 'exclude' flag to target objects sections Summary: This flag tells link editor to exclude section from linker inputs when linking executable or shared library. Reviewers: ABataev, alexshap, jdoerfert Reviewed By: ABataev Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73408 Added: Modified: clang/test/Driver/clang-offload-bundler.c clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp Removed: diff --git a/clang/test/Driver/clang-offload-bundler.c b/clang/test/Driver/clang-offload-bundler.c index 35c327c56b3b..99d638cb889b 100644 --- a/clang/test/Driver/clang-offload-bundler.c +++ b/clang/test/Driver/clang-offload-bundler.c @@ -253,7 +253,8 @@ // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.o,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.o -### 2>&1 \ // RUN: | FileCheck %s -DHOST=%itanium_abi_triple -DINOBJ1=%t.o -DINOBJ2=%t.tgt1 -DINOBJ3=%t.tgt2 -DOUTOBJ=%t.bundle3.o --check-prefix CK-OBJ-CMD -// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=[[INOBJ1]]" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=[[INOBJ2]]" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=[[INOBJ3]]" "[[INOBJ1]]" "[[OUTOBJ]]" +// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=[[INOBJ1]]" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=[[INOBJ2]]" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=[[INOBJ3]]" "[[INOBJ1]]" "[[TEMPOBJ:.*]]" +// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=readonly,exclude" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=readonly,exclude" "[[TEMPOBJ]]" "[[OUTOBJ]]" // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.o,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.o // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.o,%t.res.tgt1,%t.res.tgt2 -inputs=%t.bundle3.o -unbundle diff --git a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp index a75d2a630cf4..c215cff303e7 100644 --- a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp @@ -30,6 +30,7 @@ #include "llvm/Support/Error.h" #include "llvm/Support/ErrorOr.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/FileUtilities.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/Program.h" @@ -463,6 +464,15 @@ class ObjectFileHandler final : public FileHandler { if (NumberOfProcessedInputs != NumberOfInputs) return Error::success(); +// We will use llvm-objcopy to add target objects sections to the output +// fat object. These sections should have 'exclude' flag set which tells +// link editor to remove them from linker inputs when linking executable or +// shared library. llvm-objcopy currently does not support adding new +// section and changing flags for the added section in one invocation, and +// because of that we have to run it two times. First run adds sections and +// the second changes flags. +// TODO: change it to one run once llvm-objcopy starts supporting that. + // Find llvm-objcopy in order to create the bundle binary. ErrorOr Objcopy = sys::findProgramByName( "llvm-objcopy", sys::path::parent_path(BundlerExecutable)); @@ -476,7 +486,15 @@ class ObjectFileHandler final : public FileHandler { // to pass down to llvm-objcopy. OS.close(); -// Compose command line for the objcopy tool. +// Create an intermediate temporary file to save object after the first +// llvm-objcopy run. +SmallString<128u> IntermediateObj; +if (std::error_code EC = sys::fs::createTemporaryFile( +"clang-offload-bundler", "tmp", IntermediateObj)) + return createFileError(IntermediateObj, EC); +FileRemover IntermediateObjRemover(IntermediateObj); + +// Compose llvm-objcopy command line for add target objects' sections. BumpPtrAllocator Alloc; StringSav
[clang] c53cb2b - [Clang][Bundler] Reduce fat object size
Author: Sergey Dmitriev Date: 2020-01-30T08:21:39-08:00 New Revision: c53cb2bdc78ee3d3eec8c30821480b390b0eb145 URL: https://github.com/llvm/llvm-project/commit/c53cb2bdc78ee3d3eec8c30821480b390b0eb145 DIFF: https://github.com/llvm/llvm-project/commit/c53cb2bdc78ee3d3eec8c30821480b390b0eb145.diff LOG: [Clang][Bundler] Reduce fat object size Summary: Fat object size has significantly increased after D65819 which changed bundler tool to add host object as a normal bundle to the fat output which almost doubled its size. That patch was fixing the following issues 1. Problems associated with the partial linking - global constructors were not called for partially linking objects which clearly resulted in incorrect behavior. 2. Eliminating "junk" target object sections from the linked binary on the host side. The first problem is no longer relevant because we do not use partial linking for creating fat objects anymore. Target objects sections are now inserted into the resulting fat object with a help of llvm-objcopy tool. The second issue, "junk" sections in the linked host binary, has been fixed in D73408 by adding "exclude" flag to the fat object's sections which contain target objects. This flag tells linker to drop section from the inputs when linking executable or shared library, therefore these sections will not be propagated in the linked binary. Since both problems have been solved, we can revert D65819 changes to reduce fat object size and this patch essentially is doing that. Reviewers: ABataev, alexshap, jdoerfert Reviewed By: ABataev Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73642 Added: Modified: clang/test/Driver/clang-offload-bundler.c clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp Removed: diff --git a/clang/test/Driver/clang-offload-bundler.c b/clang/test/Driver/clang-offload-bundler.c index 99d638cb889b..a0724b3c60e8 100644 --- a/clang/test/Driver/clang-offload-bundler.c +++ b/clang/test/Driver/clang-offload-bundler.c @@ -253,16 +253,16 @@ // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.o,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.o -### 2>&1 \ // RUN: | FileCheck %s -DHOST=%itanium_abi_triple -DINOBJ1=%t.o -DINOBJ2=%t.tgt1 -DINOBJ3=%t.tgt2 -DOUTOBJ=%t.bundle3.o --check-prefix CK-OBJ-CMD -// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=[[INOBJ1]]" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=[[INOBJ2]]" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=[[INOBJ3]]" "[[INOBJ1]]" "[[TEMPOBJ:.*]]" +// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]={{.*}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=[[INOBJ2]]" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=[[INOBJ3]]" "[[INOBJ1]]" "[[TEMPOBJ:.*]]" // CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=readonly,exclude" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=readonly,exclude" "[[TEMPOBJ]]" "[[OUTOBJ]]" // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.o,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.o // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.o,%t.res.tgt1,%t.res.tgt2 -inputs=%t.bundle3.o -unbundle -// RUN: diff %t.o %t.res.o +// RUN: diff %t.bundle3.o %t.res.o // RUN: diff %t.tgt1 %t.res.tgt1 // RUN: diff %t.tgt2 %t.res.tgt2 // RUN: clang-offload-bundler -type=o -targets=openmp-powerpc64le-ibm-linux-gnu,host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -outputs=%t.res.tgt1,%t.res.o,%t.res.tgt2 -inputs=%t.bundle3.o -unbundle -// RUN: diff %t.o %t.res.o +// RUN: diff %t.bundle3.o %t.res.o // RUN: diff %t.tgt1 %t.res.tgt1 // RUN: diff %t.tgt2 %t.res.tgt2 // RUN: clang-offload-bundler -type=o -targets=openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.tgt1 -inputs=%t.bundle3.o -unbundle diff --git a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp index c215cff303e7..2a99a71501ab 100644 --- a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp @@ -30,7 +30,6 @@ #include "llvm/Support/Error.h" #include "llvm/Support/ErrorOr.h" #include "llvm/Support/FileSystem.h" -#include "llvm/Support/FileUtilities.h" #include "llvm/Support/MemoryBuffer.h" #include "l
[clang] 36bfdb7 - [Clang][Driver] Disable llvm passes for the first host OpenMP offload compilation
Author: Sergey Dmitriev Date: 2020-01-30T10:16:41-08:00 New Revision: 36bfdb7096cfe1925448e408ec72f1a6bdc4cd2c URL: https://github.com/llvm/llvm-project/commit/36bfdb7096cfe1925448e408ec72f1a6bdc4cd2c DIFF: https://github.com/llvm/llvm-project/commit/36bfdb7096cfe1925448e408ec72f1a6bdc4cd2c.diff LOG: [Clang][Driver] Disable llvm passes for the first host OpenMP offload compilation Summary: With OpenMP offloading host compilation is done in two phases to capture host IR that is passed to all device compilations as input. But it turns out that we currently run entire LLVM optimization pipeline on host IR on both compilations which may have unpredictable effects on the resulting code. This patch fixes this problem by disabling LLVM passes on the first compilation, so the host IR that is passed to device compilations will be captured right after front end. Reviewers: ABataev, jdoerfert, hfinkel Reviewed By: ABataev Subscribers: guansong, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73721 Added: Modified: clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/openmp-offload.c Removed: diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 44f8f2676cbb..fdd0610f464c 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5788,7 +5788,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // FIXME: -fembed-bitcode -save-temps will save optimized bitcode instead of // pristine IR generated by the frontend. Ideally, a new compile action should // be added so both IR can be captured. - if (C.getDriver().isSaveTempsEnabled() && + if ((C.getDriver().isSaveTempsEnabled() || + JA.isHostOffloading(Action::OFK_OpenMP)) && !(C.getDriver().embedBitcodeInObject() && !C.getDriver().isUsingLTO()) && isa(JA)) CmdArgs.push_back("-disable-llvm-passes"); diff --git a/clang/test/Driver/openmp-offload.c b/clang/test/Driver/openmp-offload.c index 30669bb86ed1..a93ef24d7e0a 100644 --- a/clang/test/Driver/openmp-offload.c +++ b/clang/test/Driver/openmp-offload.c @@ -259,7 +259,7 @@ // // Generate host BC file and host object. // -// CHK-COMMANDS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-unknown-linux" {{.*}}"-emit-llvm-bc" +// CHK-COMMANDS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-unknown-linux" {{.*}}"-emit-llvm-bc" {{.*}}"-disable-llvm-passes" // CHK-COMMANDS-SAME: "-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu" // CHK-COMMANDS-SAME: "-o" " // CHK-COMMANDS-SAME: [[HOSTBC:[^\\/]+\.bc]]" "-x" "c" " @@ -269,7 +269,7 @@ // CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-unknown-linux" {{.*}}"-E" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-COMMANDS-ST-SAME: [[HOSTPP:[^\\/]+\.i]]" "-x" "c" " // CHK-COMMANDS-ST-SAME: [[INPUT:[^\\/]+\.c]]" -// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-unknown-linux" {{.*}}"-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu" {{.*}}"-o" " +// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-unknown-linux" {{.*}}"-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-disable-llvm-passes" {{.*}}"-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu" {{.*}}"-o" " // CHK-COMMANDS-ST-SAME: [[HOSTBC:[^\\/]+\.bc]]" "-x" "cpp-output" "{{.*}}[[HOSTPP]]" // CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-unknown-linux" {{.*}}"-S" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-COMMANDS-ST-SAME: [[HOSTASM:[^\\/]+\.s]]" "-x" "ir" "{{.*}}[[HOSTBC]]" @@ -427,14 +427,14 @@ // RUN: | FileCheck -check-prefix=CHK-BUJOBS-ST %s // Create host BC. -// CHK-BUJOBS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-unknown-linux" {{.*}}"-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu" {{.*}}"-o" " +// CHK-BUJOBS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-unknown-linux" {{.*}}"-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-disable-llvm-passes" {{.*}}"-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu" {{.*}}"-o" " // CHK-BUJOBS-SAME: [[HOSTBC:[^\\/]+\.bc]]" "-x" "c" " // CHK-BUJOBS-SAME: [[INPUT:[^\\/]+\.c]]" // CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-unknown-linux" {{.*}}"-E" {{.*}}"-fopenmp" {{.*}}"-o" " // CHK-BUJOBS-ST-SAME: [[HOSTPP:[^\\/]+\.i]]" "-x" "c" " // CHK-BUJOBS-ST-SAME: [[INPUT:[^\\/]+\.c]]" -// CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-unknown-linux" {{.*}}"-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu" {{.*}}"-o" " +// CHK-BUJOBS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-unknown-linux" {{.*}}"-emit-llvm-bc" {{.*}}"-fopenmp" {{.*}}"-disable-llvm-passes" {{.*}}"-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu" {{.*}}"-o"
[clang] 5be2ca2 - [Clang][Bundler][NFC] Replace SmallString<...> with StringRef
Author: Sergey Dmitriev Date: 2020-01-30T12:50:04-08:00 New Revision: 5be2ca29217ad977f2479bfc530127c7fb418963 URL: https://github.com/llvm/llvm-project/commit/5be2ca29217ad977f2479bfc530127c7fb418963 DIFF: https://github.com/llvm/llvm-project/commit/5be2ca29217ad977f2479bfc530127c7fb418963.diff LOG: [Clang][Bundler][NFC] Replace SmallString<...> with StringRef Reviewers: ABataev Reviewed By: ABataev Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73738 Added: Modified: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp Removed: diff --git a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp index 2a99a71501ab..3f9925d1e099 100644 --- a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp @@ -530,10 +530,10 @@ class ObjectFileHandler final : public FileHandler { // Create an intermediate temporary file to save object after the first // llvm-objcopy run. -Expected> IntermediateObjOrErr = TempFiles.Create(None); +Expected IntermediateObjOrErr = TempFiles.Create(None); if (!IntermediateObjOrErr) return IntermediateObjOrErr.takeError(); -const SmallString<128u> &IntermediateObj = *IntermediateObjOrErr; +StringRef IntermediateObj = *IntermediateObjOrErr; // Compose llvm-objcopy command line for add target objects' sections. BumpPtrAllocator Alloc; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits