aboutsummaryrefslogtreecommitdiff
path: root/clang/include
diff options
context:
space:
mode:
authorJacob Lambert <jacob.lambert@amd.com>2022-07-14 17:00:26 -0700
committerJacob Lambert <jacob.lambert@amd.com>2022-07-26 10:05:22 -0700
commit8348c4095600ec2c0beee293267832799d2ebee3 (patch)
treead14a88d146709771f2eafaa5cc46742be2c24cc /clang/include
parent1ea7b9c6ee6420dd6e87489534f44b92e1b6f220 (diff)
downloadllvm-8348c4095600ec2c0beee293267832799d2ebee3.zip
llvm-8348c4095600ec2c0beee293267832799d2ebee3.tar.gz
llvm-8348c4095600ec2c0beee293267832799d2ebee3.tar.bz2
[clang-offload-bundler] Library-ize ClangOffloadBundler
Lifting the core functionalities of the clang-offload-bundler into a user-facing library/API. This will allow online and JIT compilers to bundle and unbundle files without spawning a new process. This patch lifts the classes and functions used to implement the clang-offload-bundler into a separate OffloadBundler.cpp, and defines three top-level API functions in OfflaodBundler.h. BundleFiles() UnbundleFiles() UnbundleArchives() This patch also introduces a Config class that locally stores the previously global cl::opt options and arrays to allow users to call the APIs in a multi-threaded context, and introduces an OffloadBundler class to encapsulate the top-level API functions. We also lift the BundlerExecutable variable, which is specific to the clang-offload-bundler tool, from the API, and replace its use with an ObjcopyPath variable. This variable must be set in order to internally call llvm-objcopy. Finally, we move the API files from clang/tools/clang-offload-bundler into clang/lib/Driver and clang/include/clang/Driver. Differential Revision: https://reviews.llvm.org/D129873
Diffstat (limited to 'clang/include')
-rw-r--r--clang/include/clang/Driver/OffloadBundler.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/clang/include/clang/Driver/OffloadBundler.h b/clang/include/clang/Driver/OffloadBundler.h
new file mode 100644
index 0000000..ea0631b
--- /dev/null
+++ b/clang/include/clang/Driver/OffloadBundler.h
@@ -0,0 +1,89 @@
+//===- 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.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// 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.
+///
+//===----------------------------------------------------------------------===//
+
+#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>
+
+namespace clang {
+
+class OffloadBundlerConfig {
+public:
+ bool AllowNoHost = false;
+ bool AllowMissingBundles = false;
+ bool CheckInputArchive = false;
+ bool PrintExternalCommands = false;
+ bool HipOpenmpCompatible = false;
+
+ unsigned BundleAlignment = 1;
+ unsigned HostInputIndex = ~0u;
+
+ std::string FilesType;
+ std::string ObjcopyPath;
+
+ // TODO: Convert these to llvm::SmallVector
+ std::vector<std::string> TargetNames;
+ std::vector<std::string> InputFileNames;
+ std::vector<std::string> OutputFileNames;
+};
+
+class OffloadBundler {
+public:
+ const OffloadBundlerConfig &BundlerConfig;
+
+ // TODO: Add error checking from ClangOffloadBundler.cpp
+ OffloadBundler(const OffloadBundlerConfig &BC) : BundlerConfig(BC) {}
+
+ // List bundle IDs. Return true if an error was found.
+ static llvm::Error
+ ListBundleIDsInFile(llvm::StringRef InputFileName,
+ const OffloadBundlerConfig &BundlerConfig);
+
+ llvm::Error BundleFiles();
+ llvm::Error UnbundleFiles();
+ llvm::Error UnbundleArchive();
+};
+
+/// Obtain the offload kind, real machine triple, and an optional GPUArch
+/// out of the target information specified by the user.
+/// Bundle Entry ID (or, Offload Target String) has following components:
+/// * Offload Kind - Host, OpenMP, or HIP
+/// * Triple - Standard LLVM Triple
+/// * GPUArch (Optional) - Processor name, like gfx906 or sm_30
+struct OffloadTargetInfo {
+ llvm::StringRef OffloadKind;
+ llvm::Triple Triple;
+ llvm::StringRef GPUArch;
+
+ const OffloadBundlerConfig &BundlerConfig;
+
+ OffloadTargetInfo(const llvm::StringRef Target,
+ const OffloadBundlerConfig &BC);
+ bool hasHostKind() const;
+ bool isOffloadKindValid() const;
+ bool isOffloadKindCompatible(const llvm::StringRef TargetOffloadKind) const;
+ bool isTripleValid() const;
+ bool operator==(const OffloadTargetInfo &Target) const;
+ std::string str();
+};
+
+} // namespace clang
+
+#endif // LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H