clang 23.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/SmallVector.h"
21#include "llvm/Support/Compression.h"
22#include "llvm/Support/Error.h"
23#include "llvm/TargetParser/Triple.h"
24#include <llvm/Support/MemoryBuffer.h>
25#include <string>
26
27namespace clang {
28
54
56public:
58
59 // TODO: Add error checking from ClangOffloadBundler.cpp
61
62 // List bundle IDs. Return true if an error was found.
63 static llvm::Error
64 ListBundleIDsInFile(llvm::StringRef InputFileName,
66
67 llvm::Error BundleFiles();
68 llvm::Error UnbundleFiles();
69 llvm::Error UnbundleArchive();
70};
71
72/// Obtain the offload kind, real machine triple, and an optional TargetID
73/// out of the target information specified by the user.
74/// Bundle Entry ID (or, Offload Target String) has following components:
75/// * Offload Kind - Host, OpenMP, or HIP
76/// * Triple - Standard LLVM Triple
77/// * TargetID (Optional) - target ID, like gfx906:xnack+ or sm_30
79 llvm::StringRef OffloadKind;
80 llvm::Triple Triple;
81 llvm::StringRef TargetID;
82
84
85 OffloadTargetInfo(const llvm::StringRef Target,
86 const OffloadBundlerConfig &BC);
87 bool hasHostKind() const;
88 bool isOffloadKindValid() const;
89 bool isOffloadKindCompatible(const llvm::StringRef TargetOffloadKind) const;
90 bool isTripleValid() const;
91 bool operator==(const OffloadTargetInfo &Target) const;
92 std::string str() const;
93};
94
95// CompressedOffloadBundle represents the format for the compressed offload
96// bundles.
97//
98// The format is as follows:
99// - Magic Number (4 bytes) - A constant "CCOB".
100// - Version (2 bytes)
101// - Compression Method (2 bytes) - Uses the values from
102// llvm::compression::Format.
103// - Total file size (4 bytes in V2, 8 bytes in V3).
104// - Uncompressed Size (4 bytes in V1/V2, 8 bytes in V3).
105// - Truncated MD5 Hash (8 bytes).
106// - Compressed Data (variable length).
108private:
109 static inline const llvm::StringRef MagicNumber = "CCOB";
110
111public:
113 unsigned Version;
114 llvm::compression::Format CompressionFormat;
115 std::optional<size_t> FileSize;
117 uint64_t Hash;
118
119 static llvm::Expected<CompressedBundleHeader> tryParse(llvm::StringRef);
120 };
121
122 static inline const uint16_t DefaultVersion = 3;
123
125 compress(llvm::compression::Params P, const llvm::MemoryBuffer &Input,
126 uint16_t Version, bool Verbose = false);
128 decompress(const llvm::MemoryBuffer &Input, bool Verbose = false);
129};
130
131/// Check whether the bundle id is in the following format:
132/// <kind>-<triple>[-<target id>[:target features]]
133/// <triple> := <arch>-<vendor>-<os>-<env>
134bool checkOffloadBundleID(const llvm::StringRef Str);
135} // namespace clang
136
137#endif // LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
static llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > decompress(const llvm::MemoryBuffer &Input, bool Verbose=false)
static const uint16_t DefaultVersion
static llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > compress(llvm::compression::Params P, const llvm::MemoryBuffer &Input, uint16_t Version, bool Verbose=false)
llvm::SmallVector< std::string, 4 > TargetNames
llvm::compression::Format CompressionFormat
llvm::SmallVector< std::string, 4 > OutputFileNames
llvm::SmallVector< std::string, 4 > InputFileNames
llvm::Error BundleFiles()
Bundle the files. Return true if an error was found.
OffloadBundler(const OffloadBundlerConfig &BC)
llvm::Error UnbundleArchive()
UnbundleArchive takes an archive file (".a") as input containing bundled code object files,...
static llvm::Error ListBundleIDsInFile(llvm::StringRef InputFileName, const OffloadBundlerConfig &BundlerConfig)
const OffloadBundlerConfig & BundlerConfig
The JSON file list parser is used to communicate input to InstallAPI.
bool checkOffloadBundleID(const llvm::StringRef Str)
Check whether the bundle id is in the following format: <kind>-<triple>[-<target id>[:target features...
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 uint16_t
static llvm::Expected< CompressedBundleHeader > tryParse(llvm::StringRef)
bool operator==(const OffloadTargetInfo &Target) const
bool isOffloadKindCompatible(const llvm::StringRef TargetOffloadKind) const
OffloadTargetInfo(const llvm::StringRef Target, const OffloadBundlerConfig &BC)
llvm::StringRef OffloadKind
std::string str() const
const OffloadBundlerConfig & BundlerConfig