File indexing completed on 2026-05-10 08:36:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
0018 #define LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
0019
0020 #include "llvm/Support/Compression.h"
0021 #include "llvm/Support/Error.h"
0022 #include "llvm/TargetParser/Triple.h"
0023 #include <llvm/Support/MemoryBuffer.h>
0024 #include <string>
0025 #include <vector>
0026
0027 namespace clang {
0028
0029 class OffloadBundlerConfig {
0030 public:
0031 OffloadBundlerConfig();
0032
0033 bool AllowNoHost = false;
0034 bool AllowMissingBundles = false;
0035 bool CheckInputArchive = false;
0036 bool PrintExternalCommands = false;
0037 bool HipOpenmpCompatible = false;
0038 bool Compress = false;
0039 bool Verbose = false;
0040 llvm::compression::Format CompressionFormat;
0041 int CompressionLevel;
0042 uint16_t CompressedBundleVersion;
0043
0044 unsigned BundleAlignment = 1;
0045 unsigned HostInputIndex = ~0u;
0046
0047 std::string FilesType;
0048 std::string ObjcopyPath;
0049
0050
0051 std::vector<std::string> TargetNames;
0052 std::vector<std::string> InputFileNames;
0053 std::vector<std::string> OutputFileNames;
0054 };
0055
0056 class OffloadBundler {
0057 public:
0058 const OffloadBundlerConfig &BundlerConfig;
0059
0060
0061 OffloadBundler(const OffloadBundlerConfig &BC) : BundlerConfig(BC) {}
0062
0063
0064 static llvm::Error
0065 ListBundleIDsInFile(llvm::StringRef InputFileName,
0066 const OffloadBundlerConfig &BundlerConfig);
0067
0068 llvm::Error BundleFiles();
0069 llvm::Error UnbundleFiles();
0070 llvm::Error UnbundleArchive();
0071 };
0072
0073
0074
0075
0076
0077
0078
0079 struct OffloadTargetInfo {
0080 llvm::StringRef OffloadKind;
0081 llvm::Triple Triple;
0082 llvm::StringRef TargetID;
0083
0084 const OffloadBundlerConfig &BundlerConfig;
0085
0086 OffloadTargetInfo(const llvm::StringRef Target,
0087 const OffloadBundlerConfig &BC);
0088 bool hasHostKind() const;
0089 bool isOffloadKindValid() const;
0090 bool isOffloadKindCompatible(const llvm::StringRef TargetOffloadKind) const;
0091 bool isTripleValid() const;
0092 bool operator==(const OffloadTargetInfo &Target) const;
0093 std::string str() const;
0094 };
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 class CompressedOffloadBundle {
0109 private:
0110 static inline const size_t MagicSize = 4;
0111 static inline const size_t VersionFieldSize = sizeof(uint16_t);
0112 static inline const size_t MethodFieldSize = sizeof(uint16_t);
0113
0114 static inline const size_t FileSizeFieldSizeV2 = sizeof(uint32_t);
0115 static inline const size_t UncompressedSizeFieldSizeV2 = sizeof(uint32_t);
0116
0117 static inline const size_t FileSizeFieldSizeV3 = sizeof(uint64_t);
0118 static inline const size_t UncompressedSizeFieldSizeV3 = sizeof(uint64_t);
0119 static inline const size_t HashFieldSize = sizeof(uint64_t);
0120
0121
0122 static inline const size_t V1HeaderSize =
0123 MagicSize + VersionFieldSize + MethodFieldSize +
0124 UncompressedSizeFieldSizeV2 + HashFieldSize;
0125
0126
0127 static inline const size_t V2HeaderSize =
0128 MagicSize + VersionFieldSize + FileSizeFieldSizeV2 + MethodFieldSize +
0129 UncompressedSizeFieldSizeV2 + HashFieldSize;
0130
0131
0132 static inline const size_t V3HeaderSize =
0133 MagicSize + VersionFieldSize + FileSizeFieldSizeV3 + MethodFieldSize +
0134 UncompressedSizeFieldSizeV3 + HashFieldSize;
0135
0136 static inline const llvm::StringRef MagicNumber = "CCOB";
0137
0138 public:
0139 static inline const uint16_t DefaultVersion = 2;
0140
0141
0142 static size_t getHeaderSize(uint16_t Version) {
0143 switch (Version) {
0144 case 1:
0145 return V1HeaderSize;
0146 case 2:
0147 return V2HeaderSize;
0148 case 3:
0149 return V3HeaderSize;
0150 default:
0151 llvm_unreachable("Unsupported version");
0152 }
0153 }
0154
0155 static llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
0156 compress(llvm::compression::Params P, const llvm::MemoryBuffer &Input,
0157 uint16_t Version, bool Verbose = false);
0158 static llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
0159 decompress(const llvm::MemoryBuffer &Input, bool Verbose = false);
0160 };
0161 }
0162
0163 #endif