clang  16.0.0git
OffloadBundler.h
Go to the documentation of this file.
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 
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 
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 
48 public:
50 
51  // TODO: Add error checking from ClangOffloadBundler.cpp
53 
54  // List bundle IDs. Return true if an error was found.
55  static llvm::Error
56  ListBundleIDsInFile(llvm::StringRef InputFileName,
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 /// * TargetID (Optional) - target ID, like gfx906:xnack+ or sm_30
71  llvm::StringRef OffloadKind;
72  llvm::Triple Triple;
73  llvm::StringRef TargetID;
74 
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() const;
85 };
86 
87 } // namespace clang
88 
89 #endif // LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
clang::OffloadBundlerConfig::AllowNoHost
bool AllowNoHost
Definition: OffloadBundler.h:29
clang::OffloadBundlerConfig::HostInputIndex
unsigned HostInputIndex
Definition: OffloadBundler.h:36
clang::OffloadBundler::BundlerConfig
const OffloadBundlerConfig & BundlerConfig
Definition: OffloadBundler.h:49
clang::OffloadBundler::UnbundleArchive
llvm::Error UnbundleArchive()
UnbundleArchive takes an archive file (".a") as input containing bundled code object files,...
Definition: OffloadBundler.cpp:1119
clang::OffloadBundlerConfig::InputFileNames
std::vector< std::string > InputFileNames
Definition: OffloadBundler.h:43
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::OffloadTargetInfo::OffloadKind
llvm::StringRef OffloadKind
Definition: OffloadBundler.h:71
clang::OffloadTargetInfo::isOffloadKindValid
bool isOffloadKindValid() const
Definition: OffloadBundler.cpp:89
clang::OffloadBundlerConfig::OutputFileNames
std::vector< std::string > OutputFileNames
Definition: OffloadBundler.h:44
clang::OffloadBundler::UnbundleFiles
llvm::Error UnbundleFiles()
Definition: OffloadBundler.cpp:958
clang::OffloadTargetInfo::TargetID
llvm::StringRef TargetID
Definition: OffloadBundler.h:73
clang::OffloadBundler::BundleFiles
llvm::Error BundleFiles()
Bundle the files. Return true if an error was found.
Definition: OffloadBundler.cpp:905
clang::OffloadBundlerConfig::HipOpenmpCompatible
bool HipOpenmpCompatible
Definition: OffloadBundler.h:33
clang::OffloadBundler
Definition: OffloadBundler.h:47
clang::OffloadTargetInfo::BundlerConfig
const OffloadBundlerConfig & BundlerConfig
Definition: OffloadBundler.h:75
clang::OffloadBundlerConfig::CheckInputArchive
bool CheckInputArchive
Definition: OffloadBundler.h:31
clang::OffloadBundlerConfig::AllowMissingBundles
bool AllowMissingBundles
Definition: OffloadBundler.h:30
clang::OffloadTargetInfo::OffloadTargetInfo
OffloadTargetInfo(const llvm::StringRef Target, const OffloadBundlerConfig &BC)
Definition: OffloadBundler.cpp:64
clang::OffloadBundlerConfig
Definition: OffloadBundler.h:27
clang::OffloadTargetInfo::operator==
bool operator==(const OffloadTargetInfo &Target) const
Definition: OffloadBundler.cpp:113
clang::OffloadTargetInfo::str
std::string str() const
Definition: OffloadBundler.cpp:118
clang::OffloadTargetInfo
Obtain the offload kind, real machine triple, and an optional GPUArch out of the target information s...
Definition: OffloadBundler.h:70
clang::OffloadBundlerConfig::TargetNames
std::vector< std::string > TargetNames
Definition: OffloadBundler.h:42
clang::OffloadBundlerConfig::ObjcopyPath
std::string ObjcopyPath
Definition: OffloadBundler.h:39
clang::OffloadBundlerConfig::FilesType
std::string FilesType
Definition: OffloadBundler.h:38
clang::OffloadTargetInfo::isTripleValid
bool isTripleValid() const
Definition: OffloadBundler.cpp:109
clang::OffloadTargetInfo::Triple
llvm::Triple Triple
Definition: OffloadBundler.h:72
clang
Definition: CalledOnceCheck.h:17
clang::OffloadTargetInfo::hasHostKind
bool hasHostKind() const
Definition: OffloadBundler.cpp:85
clang::OffloadBundler::OffloadBundler
OffloadBundler(const OffloadBundlerConfig &BC)
Definition: OffloadBundler.h:52
clang::OffloadBundlerConfig::BundleAlignment
unsigned BundleAlignment
Definition: OffloadBundler.h:35
clang::OffloadBundler::ListBundleIDsInFile
static llvm::Error ListBundleIDsInFile(llvm::StringRef InputFileName, const OffloadBundlerConfig &BundlerConfig)
Definition: OffloadBundler.cpp:883
clang::OffloadTargetInfo::isOffloadKindCompatible
bool isOffloadKindCompatible(const llvm::StringRef TargetOffloadKind) const
Definition: OffloadBundler.cpp:94
clang::OffloadBundlerConfig::PrintExternalCommands
bool PrintExternalCommands
Definition: OffloadBundler.h:32