|
| 1 | +//===- OffloadBundler.h - File Bundling and Unbundling ----------*- C++ -*-===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | +/// |
| 9 | +/// \file |
| 10 | +/// This file defines an offload bundling API that bundles different files |
| 11 | +/// that relate with the same source code but different targets into a single |
| 12 | +/// one. Also the implements the opposite functionality, i.e. unbundle files |
| 13 | +/// previous created by this API. |
| 14 | +/// |
| 15 | +//===----------------------------------------------------------------------===// |
| 16 | + |
| 17 | +#ifndef LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H |
| 18 | +#define LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H |
| 19 | + |
| 20 | +#include "llvm/ADT/Triple.h" |
| 21 | +#include "llvm/Support/Error.h" |
| 22 | +#include <string> |
| 23 | +#include <vector> |
| 24 | + |
| 25 | +namespace clang { |
| 26 | + |
| 27 | +class OffloadBundlerConfig { |
| 28 | +public: |
| 29 | + bool AllowNoHost = false; |
| 30 | + bool AllowMissingBundles = false; |
| 31 | + bool CheckInputArchive = false; |
| 32 | + bool PrintExternalCommands = false; |
| 33 | + bool HipOpenmpCompatible = false; |
| 34 | + |
| 35 | + unsigned BundleAlignment = 1; |
| 36 | + unsigned HostInputIndex = ~0u; |
| 37 | + |
| 38 | + std::string FilesType; |
| 39 | + std::string ObjcopyPath; |
| 40 | + |
| 41 | + // TODO: Convert these to llvm::SmallVector |
| 42 | + std::vector<std::string> TargetNames; |
| 43 | + std::vector<std::string> InputFileNames; |
| 44 | + std::vector<std::string> OutputFileNames; |
| 45 | +}; |
| 46 | + |
| 47 | +class OffloadBundler { |
| 48 | +public: |
| 49 | + const OffloadBundlerConfig &BundlerConfig; |
| 50 | + |
| 51 | + // TODO: Add error checking from ClangOffloadBundler.cpp |
| 52 | + OffloadBundler(const OffloadBundlerConfig &BC) : BundlerConfig(BC) {} |
| 53 | + |
| 54 | + // List bundle IDs. Return true if an error was found. |
| 55 | + static llvm::Error |
| 56 | + ListBundleIDsInFile(llvm::StringRef InputFileName, |
| 57 | + const OffloadBundlerConfig &BundlerConfig); |
| 58 | + |
| 59 | + llvm::Error BundleFiles(); |
| 60 | + llvm::Error UnbundleFiles(); |
| 61 | + llvm::Error UnbundleArchive(); |
| 62 | +}; |
| 63 | + |
| 64 | +/// Obtain the offload kind, real machine triple, and an optional GPUArch |
| 65 | +/// out of the target information specified by the user. |
| 66 | +/// Bundle Entry ID (or, Offload Target String) has following components: |
| 67 | +/// * Offload Kind - Host, OpenMP, or HIP |
| 68 | +/// * Triple - Standard LLVM Triple |
| 69 | +/// * GPUArch (Optional) - Processor name, like gfx906 or sm_30 |
| 70 | +struct OffloadTargetInfo { |
| 71 | + llvm::StringRef OffloadKind; |
| 72 | + llvm::Triple Triple; |
| 73 | + llvm::StringRef GPUArch; |
| 74 | + |
| 75 | + const OffloadBundlerConfig &BundlerConfig; |
| 76 | + |
| 77 | + OffloadTargetInfo(const llvm::StringRef Target, |
| 78 | + const OffloadBundlerConfig &BC); |
| 79 | + bool hasHostKind() const; |
| 80 | + bool isOffloadKindValid() const; |
| 81 | + bool isOffloadKindCompatible(const llvm::StringRef TargetOffloadKind) const; |
| 82 | + bool isTripleValid() const; |
| 83 | + bool operator==(const OffloadTargetInfo &Target) const; |
| 84 | + std::string str(); |
| 85 | +}; |
| 86 | + |
| 87 | +} // namespace clang |
| 88 | + |
| 89 | +#endif // LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H |
0 commit comments