clang  20.0.0git
Classes | Macros | Functions
OffloadBundler.cpp File Reference

This file implements an offload bundling API that bundles different files that relate with the same source code but different targets into a single one. More...

#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/Bitcode/BitcodeWriter.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IRReader/IRReader.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/TargetSelect.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/SourceMgr.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 <unordered_set>
#include <utility>

Go to the source code of this file.

Classes

class  ArchiveFileHandler
 Archive file handler. Only unbundling is supported so far. More...
 

Macros

#define OFFLOAD_BUNDLER_MAGIC_STR   "__CLANG_OFFLOAD_BUNDLE__"
 Magic string that marks the existence of offloading data. More...
 
#define SYMBOLS_SECTION_NAME   ".tgtsym"
 Section name which holds target symbol names. More...
 
#define DEBUG_TYPE   "clang-offload-bundler"
 

Functions

static llvm::TimerGroup ClangOffloadBundlerTimerGroup ("Clang Offload Bundler Timer Group", "Timer group for clang offload bundler")
 
static Triple getTargetTriple (StringRef Target, const OffloadBundlerConfig &BC)
 
static StringRef getDeviceFileExtension (StringRef Device, StringRef BundleFileName)
 
static std::string getDeviceLibraryFileName (StringRef BundleFileName, StringRef Device)
 
static std::unique_ptr< FileHandler > CreateObjectFileHandler (MemoryBuffer &FirstInput, const OffloadBundlerConfig &BundlerConfig)
 Return an appropriate object file handler. More...
 
static bool FilesTypeIsArchiveToList (const std::string &FilesType)
 
static bool FilesTypeIsArchive (const std::string &FilesType)
 
static Expected< std::unique_ptr< FileHandler > > CreateFileHandler (MemoryBuffer &FirstInput, const OffloadBundlerConfig &BundlerConfig)
 Return an appropriate handler given the input files and options. More...
 
static std::string formatWithCommas (unsigned long long Value)
 
bool isCodeObjectCompatible (const OffloadTargetInfo &CodeObjectInfo, const OffloadTargetInfo &TargetInfo)
 Checks if a code object CodeObjectInfo is compatible with a given target TargetInfo. More...
 
static Archive::Kind getDefaultArchiveKindForHost ()
 
static bool getCompatibleOffloadTargets (OffloadTargetInfo &CodeObjectInfo, SmallVectorImpl< StringRef > &CompatibleTargets, const OffloadBundlerConfig &BundlerConfig)
 Computes a list of targets among all given targets which are compatible with this code object. More...
 
static Error CheckHeterogeneousArchive (StringRef ArchiveName, const OffloadBundlerConfig &BundlerConfig)
 

Detailed Description

This file implements an offload bundling API that bundles different files that relate with the same source code but different targets into a single one.

Also the implements the opposite functionality, i.e. unbundle files previous created by this API.

Definition in file OffloadBundler.cpp.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "clang-offload-bundler"

Definition at line 84 of file OffloadBundler.cpp.

◆ OFFLOAD_BUNDLER_MAGIC_STR

#define OFFLOAD_BUNDLER_MAGIC_STR   "__CLANG_OFFLOAD_BUNDLE__"

Magic string that marks the existence of offloading data.

Definition at line 79 of file OffloadBundler.cpp.

◆ SYMBOLS_SECTION_NAME

#define SYMBOLS_SECTION_NAME   ".tgtsym"

Section name which holds target symbol names.

Definition at line 82 of file OffloadBundler.cpp.

Function Documentation

◆ CheckHeterogeneousArchive()

static Error CheckHeterogeneousArchive ( StringRef  ArchiveName,
const OffloadBundlerConfig BundlerConfig 
)
static

Iterate over all bundled code object files in the input archive.

Definition at line 2158 of file OffloadBundler.cpp.

References clang::serialized_diags::create(), CreateFileHandler(), and clang::getConflictTargetIDCombination().

Referenced by clang::OffloadBundler::UnbundleArchive().

◆ ClangOffloadBundlerTimerGroup()

static llvm::TimerGroup ClangOffloadBundlerTimerGroup ( "Clang Offload Bundler Timer Group"  ,
"Timer group for clang offload bundler"   
)
static

◆ CreateFileHandler()

static Expected<std::unique_ptr<FileHandler> > CreateFileHandler ( MemoryBuffer &  FirstInput,
const OffloadBundlerConfig BundlerConfig 
)
static

◆ CreateObjectFileHandler()

static std::unique_ptr<FileHandler> CreateObjectFileHandler ( MemoryBuffer &  FirstInput,
const OffloadBundlerConfig BundlerConfig 
)
static

Return an appropriate object file handler.

We use the specific object handler if we know how to deal with that format, otherwise we use a default binary file handler.

Definition at line 1399 of file OffloadBundler.cpp.

Referenced by CreateFileHandler().

◆ FilesTypeIsArchive()

static bool FilesTypeIsArchive ( const std::string &  FilesType)
static

◆ FilesTypeIsArchiveToList()

static bool FilesTypeIsArchiveToList ( const std::string &  FilesType)
static

◆ formatWithCommas()

static std::string formatWithCommas ( unsigned long long  Value)
static

Definition at line 1505 of file OffloadBundler.cpp.

◆ getCompatibleOffloadTargets()

static bool getCompatibleOffloadTargets ( OffloadTargetInfo CodeObjectInfo,
SmallVectorImpl< StringRef > &  CompatibleTargets,
const OffloadBundlerConfig BundlerConfig 
)
static

Computes a list of targets among all given targets which are compatible with this code object.

Parameters
[in]CodeObjectInfoCode Object
[out]CompatibleTargetsList of all compatible targets among all given targets
Returns
false, if no compatible target is found.

Definition at line 2137 of file OffloadBundler.cpp.

References isCodeObjectCompatible(), and clang::OffloadBundlerConfig::TargetNames.

Referenced by clang::OffloadBundler::UnbundleArchive().

◆ getDefaultArchiveKindForHost()

static Archive::Kind getDefaultArchiveKindForHost ( )
static

Definition at line 2125 of file OffloadBundler.cpp.

Referenced by clang::OffloadBundler::UnbundleArchive().

◆ getDeviceFileExtension()

static StringRef getDeviceFileExtension ( StringRef  Device,
StringRef  BundleFileName 
)
static

Definition at line 155 of file OffloadBundler.cpp.

References clang::Device.

Referenced by getDeviceLibraryFileName().

◆ getDeviceLibraryFileName()

static std::string getDeviceLibraryFileName ( StringRef  BundleFileName,
StringRef  Device 
)
static

Definition at line 164 of file OffloadBundler.cpp.

References clang::Device, and getDeviceFileExtension().

Referenced by clang::OffloadBundler::UnbundleArchive().

◆ getTargetTriple()

static Triple getTargetTriple ( StringRef  Target,
const OffloadBundlerConfig BC 
)
static

Definition at line 149 of file OffloadBundler.cpp.

◆ isCodeObjectCompatible()

bool isCodeObjectCompatible ( const OffloadTargetInfo CodeObjectInfo,
const OffloadTargetInfo TargetInfo 
)