lamb-j created this revision. lamb-j added reviewers: kzhuravl, scott.linder, yaxunl. Herald added a subscriber: mgorny. Herald added a project: All. lamb-j requested review of this revision. Herald added subscribers: cfe-commits, MaskRay. Herald added a project: clang.
Lifting the core functionalities of the clang-offload-bundler into a user-facing library/API. This NFC patch (4/4) moves the API files from clang/tools/clang-offload-bundler into clang/lib/Driver and clang/include/clang/Driver. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D129305 Files: clang/include/clang/Driver/OffloadBundler.h clang/lib/Driver/CMakeLists.txt clang/lib/Driver/OffloadBundler.cpp clang/tools/clang-offload-bundler/CMakeLists.txt clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp clang/tools/clang-offload-bundler/OffloadBundler.cpp clang/tools/clang-offload-bundler/OffloadBundler.h
Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp =================================================================== --- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp @@ -7,15 +7,14 @@ //===----------------------------------------------------------------------===// /// /// \file -/// This file implements a clang-offload-bundler that bundles different -/// files that relate with the same source code but different targets into a -/// single one. Also the implements the opposite functionality, i.e. unbundle -/// files previous created by this tool. +/// This file implements a stand-alone clang-offload-bundler tool using the +/// OffloadBundler API. /// //===----------------------------------------------------------------------===// #include "clang/Basic/Cuda.h" #include "clang/Basic/Version.h" +#include "clang/Driver/OffloadBundler.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" @@ -52,7 +51,6 @@ #include <string> #include <system_error> #include <utility> -#include "OffloadBundler.h" using namespace llvm; using namespace llvm::object; Index: clang/tools/clang-offload-bundler/CMakeLists.txt =================================================================== --- clang/tools/clang-offload-bundler/CMakeLists.txt +++ clang/tools/clang-offload-bundler/CMakeLists.txt @@ -2,7 +2,6 @@ add_clang_tool(clang-offload-bundler ClangOffloadBundler.cpp - OffloadBundler.cpp DEPENDS intrinsics_gen @@ -10,6 +9,7 @@ set(CLANG_OFFLOAD_BUNDLER_LIB_DEPS clangBasic + clangDriver ) add_dependencies(clang clang-offload-bundler) Index: clang/lib/Driver/OffloadBundler.cpp =================================================================== --- clang/lib/Driver/OffloadBundler.cpp +++ clang/lib/Driver/OffloadBundler.cpp @@ -1,4 +1,4 @@ -//===-- clang-offload-bundler/ClangOffloadBundler.cpp ---------------------===// +//===- OffloadBundler.cpp - File Bundling and Unbundling ------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,15 +7,16 @@ //===----------------------------------------------------------------------===// /// /// \file -/// This file implements a clang-offload-bundler that bundles different -/// files that relate with the same source code but different targets into a -/// single one. Also the implements the opposite functionality, i.e. unbundle -/// files previous created by this tool. +/// This file implements an offload bundling API that bundles different files +/// that relate with the same source code but different targets into a single +/// one. Also the implements the opposite functionality, i.e. unbundle files +/// previous created by this API. /// //===----------------------------------------------------------------------===// #include "clang/Basic/Cuda.h" #include "clang/Basic/Version.h" +#include "clang/Driver/OffloadBundler.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" @@ -53,8 +54,6 @@ #include <system_error> #include <utility> -#include "OffloadBundler.h" - using namespace llvm; using namespace llvm::object; Index: clang/lib/Driver/CMakeLists.txt =================================================================== --- clang/lib/Driver/CMakeLists.txt +++ clang/lib/Driver/CMakeLists.txt @@ -20,6 +20,7 @@ DriverOptions.cpp Job.cpp Multilib.cpp + OffloadBundler.cpp OptionUtils.cpp Phases.cpp SanitizerArgs.cpp Index: clang/include/clang/Driver/OffloadBundler.h =================================================================== --- clang/include/clang/Driver/OffloadBundler.h +++ clang/include/clang/Driver/OffloadBundler.h @@ -1,4 +1,4 @@ -//===-- clang-offload-bundler/OffloadBundler.h ----------------------------===// +//=== -OffloadBundler.h - File Bundling and Unbundling ----------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,15 +7,20 @@ //===----------------------------------------------------------------------===// /// /// \file -/// This file defines a clang-offload-bundler library that bundles different -/// files that relate with the same source code but different targets into a -/// single one. Also the implements the opposite functionality, i.e. unbundle -/// files previous created by this tool. +/// This file defines an offload bundling API that bundles different files +/// that relate with the same source code but different targets into a single +/// one. Also the implements the opposite functionality, i.e. unbundle files +/// previous created by this API. /// //===----------------------------------------------------------------------===// -using namespace llvm; -using namespace llvm::object; +#ifndef LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H +#define LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H + +#include "llvm/ADT/Triple.h" +#include "llvm/Support/Error.h" +#include <string> +#include <vector> class Config { public: @@ -44,9 +49,9 @@ // TODO: Add error checking from ClangOffloadBundler.cpp OffloadBundler(Config *BC) : BundlerConfig(BC) {} - Error BundleFiles(); - Error UnbundleFiles(); - Error UnbundleArchive(); + llvm::Error BundleFiles(); + llvm::Error UnbundleFiles(); + llvm::Error UnbundleArchive(); }; /// Obtain the offload kind, real machine triple, and an optional GPUArch @@ -56,19 +61,22 @@ /// * Triple - Standard LLVM Triple /// * GPUArch (Optional) - Processor name, followed by set of ON/OFF features struct OffloadTargetInfo { - StringRef OffloadKind; + llvm::StringRef OffloadKind; llvm::Triple Triple; - StringRef GPUArch; + llvm::StringRef GPUArch; Config *BundlerConfig; - OffloadTargetInfo(const StringRef Target, Config *BC); + OffloadTargetInfo(const llvm::StringRef Target, Config *BC); bool hasHostKind() const; bool isOffloadKindValid() const; - bool isOffloadKindCompatible(const StringRef TargetOffloadKind) const; + bool isOffloadKindCompatible(const llvm::StringRef TargetOffloadKind) const; bool isTripleValid() const; bool operator==(const OffloadTargetInfo &Target) const; std::string str(); }; // List bundle IDs. Return true if an error was found. -Error ListBundleIDsInFile(StringRef InputFileName, Config *BundlerConfig); +llvm::Error ListBundleIDsInFile(llvm::StringRef InputFileName, + Config *BundlerConfig); + +#endif // LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits