#include "clang/Driver/OffloadBundler.h"
#include "clang/Basic/Cuda.h"
#include "clang/Basic/TargetID.h"
#include "clang/Basic/Version.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/ArchiveWriter.h"
#include "llvm/Object/Binary.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/EndianStream.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/TargetParser/Triple.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <forward_list>
#include <llvm/Support/Process.h>
#include <memory>
#include <set>
#include <string>
#include <system_error>
#include <utility>
usingnamespacellvm;
usingnamespacellvm::object;
usingnamespaceclang;
static llvm::TimerGroup
ClangOffloadBundlerTimerGroup("Clang Offload Bundler Timer Group",
"Timer group for clang offload bundler");
#define OFFLOAD_BUNDLER_MAGIC_STR …
OffloadTargetInfo::OffloadTargetInfo(const StringRef Target,
const OffloadBundlerConfig &BC)
: … { … }
bool OffloadTargetInfo::hasHostKind() const { … }
bool OffloadTargetInfo::isOffloadKindValid() const { … }
bool OffloadTargetInfo::isOffloadKindCompatible(
const StringRef TargetOffloadKind) const { … }
bool OffloadTargetInfo::isTripleValid() const { … }
bool OffloadTargetInfo::operator==(const OffloadTargetInfo &Target) const { … }
std::string OffloadTargetInfo::str() const { … }
static StringRef getDeviceFileExtension(StringRef Device,
StringRef BundleFileName) { … }
static std::string getDeviceLibraryFileName(StringRef BundleFileName,
StringRef Device) { … }
namespace {
class FileHandler { … };
static uint64_t Read8byteIntegerFromBuffer(StringRef Buffer, size_t pos) { … }
static void Write8byteIntegerToBuffer(raw_ostream &OS, uint64_t Val) { … }
class BinaryFileHandler final : public FileHandler { … };
class TempFileHandlerRAII { … };
class ObjectFileHandler final : public FileHandler { … };
class TextFileHandler final : public FileHandler { … };
}
static std::unique_ptr<FileHandler>
CreateObjectFileHandler(MemoryBuffer &FirstInput,
const OffloadBundlerConfig &BundlerConfig) { … }
static Expected<std::unique_ptr<FileHandler>>
CreateFileHandler(MemoryBuffer &FirstInput,
const OffloadBundlerConfig &BundlerConfig) { … }
OffloadBundlerConfig::OffloadBundlerConfig() { … }
static std::string formatWithCommas(unsigned long long Value) { … }
llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
CompressedOffloadBundle::compress(llvm::compression::Params P,
const llvm::MemoryBuffer &Input,
bool Verbose) { … }
llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
CompressedOffloadBundle::decompress(const llvm::MemoryBuffer &Input,
bool Verbose) { … }
Error OffloadBundler::ListBundleIDsInFile(
StringRef InputFileName, const OffloadBundlerConfig &BundlerConfig) { … }
bool isCodeObjectCompatible(const OffloadTargetInfo &CodeObjectInfo,
const OffloadTargetInfo &TargetInfo) { … }
Error OffloadBundler::BundleFiles() { … }
Error OffloadBundler::UnbundleFiles() { … }
static Archive::Kind getDefaultArchiveKindForHost() { … }
static bool
getCompatibleOffloadTargets(OffloadTargetInfo &CodeObjectInfo,
SmallVectorImpl<StringRef> &CompatibleTargets,
const OffloadBundlerConfig &BundlerConfig) { … }
static Error
CheckHeterogeneousArchive(StringRef ArchiveName,
const OffloadBundlerConfig &BundlerConfig) { … }
Error OffloadBundler::UnbundleArchive() { … }