diff --git a/clang/tools/clang-offload-bundler/OffloadBundler.h b/clang/include/clang/Driver/OffloadBundler.h rename from clang/tools/clang-offload-bundler/OffloadBundler.h rename to clang/include/clang/Driver/OffloadBundler.h --- a/clang/tools/clang-offload-bundler/OffloadBundler.h +++ b/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 +#include 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 diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -20,6 +20,7 @@ DriverOptions.cpp Job.cpp Multilib.cpp + OffloadBundler.cpp OptionUtils.cpp Phases.cpp SanitizerArgs.cpp diff --git a/clang/tools/clang-offload-bundler/OffloadBundler.cpp b/clang/lib/Driver/OffloadBundler.cpp rename from clang/tools/clang-offload-bundler/OffloadBundler.cpp rename to clang/lib/Driver/OffloadBundler.cpp --- a/clang/tools/clang-offload-bundler/OffloadBundler.cpp +++ b/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 #include -#include "OffloadBundler.h" - using namespace llvm; using namespace llvm::object; diff --git a/clang/tools/clang-offload-bundler/CMakeLists.txt b/clang/tools/clang-offload-bundler/CMakeLists.txt --- a/clang/tools/clang-offload-bundler/CMakeLists.txt +++ b/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) diff --git a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp --- a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ b/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 #include #include -#include "OffloadBundler.h" using namespace llvm; using namespace llvm::object;