-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[llvm] annotate interfaces in llvm/LTO for DLL export #142499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-lto Author: Andrew Rogers (andrurogerz) ChangesPurposeThis patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the BackgroundThis effort is tracked in #109483. Additional context is provided in this discourse, and documentation for The bulk of these changes were generated automatically using the Interface Definition Scanner (IDS) tool, followed formatting with The following manual adjustments were also applied after running IDS on Linux:
ValidationLocal builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations:
Patch is 47.86 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/142499.diff 13 Files Affected:
diff --git a/llvm/include/llvm/InterfaceStub/ELFObjHandler.h b/llvm/include/llvm/InterfaceStub/ELFObjHandler.h
index c15838c4ae0af..0de0b32804801 100644
--- a/llvm/include/llvm/InterfaceStub/ELFObjHandler.h
+++ b/llvm/include/llvm/InterfaceStub/ELFObjHandler.h
@@ -14,6 +14,7 @@
#define LLVM_INTERFACESTUB_ELFOBJHANDLER_H
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBufferRef.h"
#include <memory>
@@ -24,7 +25,7 @@ namespace ifs {
struct IFSStub;
/// Attempt to read a binary ELF file from a MemoryBuffer.
-Expected<std::unique_ptr<IFSStub>> readELFFile(MemoryBufferRef Buf);
+LLVM_ABI Expected<std::unique_ptr<IFSStub>> readELFFile(MemoryBufferRef Buf);
/// Attempt to write a binary ELF stub.
/// This function determines appropriate ELFType using the passed ELFTarget and
@@ -34,8 +35,8 @@ Expected<std::unique_ptr<IFSStub>> readELFFile(MemoryBufferRef Buf);
/// @param Stub Source ELFStub to generate a binary ELF stub from.
/// @param WriteIfChanged Whether or not to preserve timestamp if
/// the output stays the same.
-Error writeBinaryStub(StringRef FilePath, const IFSStub &Stub,
- bool WriteIfChanged = false);
+LLVM_ABI Error writeBinaryStub(StringRef FilePath, const IFSStub &Stub,
+ bool WriteIfChanged = false);
} // end namespace ifs
} // end namespace llvm
diff --git a/llvm/include/llvm/InterfaceStub/IFSHandler.h b/llvm/include/llvm/InterfaceStub/IFSHandler.h
index 09687bfb9e44f..d0f6eb52c576a 100644
--- a/llvm/include/llvm/InterfaceStub/IFSHandler.h
+++ b/llvm/include/llvm/InterfaceStub/IFSHandler.h
@@ -16,6 +16,7 @@
#define LLVM_INTERFACESTUB_IFSHANDLER_H
#include "IFSStub.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/VersionTuple.h"
#include <memory>
@@ -36,29 +37,30 @@ struct IFSStub;
const VersionTuple IFSVersionCurrent(3, 0);
/// Attempts to read an IFS interface file from a StringRef buffer.
-Expected<std::unique_ptr<IFSStub>> readIFSFromBuffer(StringRef Buf);
+LLVM_ABI Expected<std::unique_ptr<IFSStub>> readIFSFromBuffer(StringRef Buf);
/// Attempts to write an IFS interface file to a raw_ostream.
-Error writeIFSToOutputStream(raw_ostream &OS, const IFSStub &Stub);
+LLVM_ABI Error writeIFSToOutputStream(raw_ostream &OS, const IFSStub &Stub);
/// Override the target platform inforation in the text stub.
-Error overrideIFSTarget(IFSStub &Stub, std::optional<IFSArch> OverrideArch,
- std::optional<IFSEndiannessType> OverrideEndianness,
- std::optional<IFSBitWidthType> OverrideBitWidth,
- std::optional<std::string> OverrideTriple);
+LLVM_ABI Error
+overrideIFSTarget(IFSStub &Stub, std::optional<IFSArch> OverrideArch,
+ std::optional<IFSEndiannessType> OverrideEndianness,
+ std::optional<IFSBitWidthType> OverrideBitWidth,
+ std::optional<std::string> OverrideTriple);
/// Validate the target platform inforation in the text stub.
-Error validateIFSTarget(IFSStub &Stub, bool ParseTriple);
+LLVM_ABI Error validateIFSTarget(IFSStub &Stub, bool ParseTriple);
/// Strips target platform information from the text stub.
-void stripIFSTarget(IFSStub &Stub, bool StripTriple, bool StripArch,
- bool StripEndianness, bool StripBitWidth);
+LLVM_ABI void stripIFSTarget(IFSStub &Stub, bool StripTriple, bool StripArch,
+ bool StripEndianness, bool StripBitWidth);
-Error filterIFSSyms(IFSStub &Stub, bool StripUndefined,
- const std::vector<std::string> &Exclude = {});
+LLVM_ABI Error filterIFSSyms(IFSStub &Stub, bool StripUndefined,
+ const std::vector<std::string> &Exclude = {});
/// Parse llvm triple string into a IFSTarget struct.
-IFSTarget parseTriple(StringRef TripleStr);
+LLVM_ABI IFSTarget parseTriple(StringRef TripleStr);
} // end namespace ifs
} // end namespace llvm
diff --git a/llvm/include/llvm/InterfaceStub/IFSStub.h b/llvm/include/llvm/InterfaceStub/IFSStub.h
index 09f96f72950cf..ddde889d46890 100644
--- a/llvm/include/llvm/InterfaceStub/IFSStub.h
+++ b/llvm/include/llvm/InterfaceStub/IFSStub.h
@@ -14,6 +14,7 @@
#ifndef LLVM_INTERFACESTUB_IFSSTUB_H
#define LLVM_INTERFACESTUB_IFSSTUB_H
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/VersionTuple.h"
#include <optional>
#include <vector>
@@ -69,7 +70,7 @@ struct IFSTarget {
std::optional<IFSEndiannessType> Endianness;
std::optional<IFSBitWidthType> BitWidth;
- bool empty();
+ LLVM_ABI bool empty();
};
inline bool operator==(const IFSTarget &Lhs, const IFSTarget &Rhs) {
@@ -95,8 +96,8 @@ struct IFSStub {
std::vector<IFSSymbol> Symbols;
IFSStub() = default;
- IFSStub(const IFSStub &Stub);
- IFSStub(IFSStub &&Stub);
+ LLVM_ABI IFSStub(const IFSStub &Stub);
+ LLVM_ABI IFSStub(IFSStub &&Stub);
virtual ~IFSStub() = default;
};
@@ -107,42 +108,42 @@ struct IFSStub {
// structure can be used for 2 different yaml schema.
struct IFSStubTriple : IFSStub {
IFSStubTriple() = default;
- IFSStubTriple(const IFSStub &Stub);
- IFSStubTriple(const IFSStubTriple &Stub);
- IFSStubTriple(IFSStubTriple &&Stub);
+ LLVM_ABI IFSStubTriple(const IFSStub &Stub);
+ LLVM_ABI IFSStubTriple(const IFSStubTriple &Stub);
+ LLVM_ABI IFSStubTriple(IFSStubTriple &&Stub);
};
/// This function convert bit width type from IFS enum to ELF format
/// Currently, ELFCLASS32 and ELFCLASS64 are supported.
///
/// @param BitWidth IFS bit width type.
-uint8_t convertIFSBitWidthToELF(IFSBitWidthType BitWidth);
+LLVM_ABI uint8_t convertIFSBitWidthToELF(IFSBitWidthType BitWidth);
/// This function convert endianness type from IFS enum to ELF format
/// Currently, ELFDATA2LSB and ELFDATA2MSB are supported.
///
/// @param Endianness IFS endianness type.
-uint8_t convertIFSEndiannessToELF(IFSEndiannessType Endianness);
+LLVM_ABI uint8_t convertIFSEndiannessToELF(IFSEndiannessType Endianness);
/// This function convert symbol type from IFS enum to ELF format
/// Currently, STT_NOTYPE, STT_OBJECT, STT_FUNC, and STT_TLS are supported.
///
/// @param SymbolType IFS symbol type.
-uint8_t convertIFSSymbolTypeToELF(IFSSymbolType SymbolType);
+LLVM_ABI uint8_t convertIFSSymbolTypeToELF(IFSSymbolType SymbolType);
/// This function extracts ELF bit width from e_ident[EI_CLASS] of an ELF file
/// Currently, ELFCLASS32 and ELFCLASS64 are supported.
/// Other endianness types are mapped to IFSBitWidthType::Unknown.
///
/// @param BitWidth e_ident[EI_CLASS] value to extract bit width from.
-IFSBitWidthType convertELFBitWidthToIFS(uint8_t BitWidth);
+LLVM_ABI IFSBitWidthType convertELFBitWidthToIFS(uint8_t BitWidth);
/// This function extracts ELF endianness from e_ident[EI_DATA] of an ELF file
/// Currently, ELFDATA2LSB and ELFDATA2MSB are supported.
/// Other endianness types are mapped to IFSEndiannessType::Unknown.
///
/// @param Endianness e_ident[EI_DATA] value to extract endianness type from.
-IFSEndiannessType convertELFEndiannessToIFS(uint8_t Endianness);
+LLVM_ABI IFSEndiannessType convertELFEndiannessToIFS(uint8_t Endianness);
/// This function extracts symbol type from a symbol's st_info member and
/// maps it to an IFSSymbolType enum.
@@ -150,7 +151,7 @@ IFSEndiannessType convertELFEndiannessToIFS(uint8_t Endianness);
/// Other symbol types are mapped to IFSSymbolType::Unknown.
///
/// @param SymbolType Binary symbol st_info to extract symbol type from.
-IFSSymbolType convertELFSymbolTypeToIFS(uint8_t SymbolType);
+LLVM_ABI IFSSymbolType convertELFSymbolTypeToIFS(uint8_t SymbolType);
} // namespace ifs
} // end namespace llvm
diff --git a/llvm/include/llvm/LTO/Config.h b/llvm/include/llvm/LTO/Config.h
index a49cce9f30e20..50e143c518213 100644
--- a/llvm/include/llvm/LTO/Config.h
+++ b/llvm/include/llvm/LTO/Config.h
@@ -22,6 +22,7 @@
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/CodeGen.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Target/TargetOptions.h"
#include <functional>
@@ -277,9 +278,9 @@ struct Config {
///
/// SaveTempsArgs can be specified to select which temps to save.
/// If SaveTempsArgs is not provided, all temps are saved.
- Error addSaveTemps(std::string OutputFileName,
- bool UseInputModulePath = false,
- const DenseSet<StringRef> &SaveTempsArgs = {});
+ LLVM_ABI Error addSaveTemps(std::string OutputFileName,
+ bool UseInputModulePath = false,
+ const DenseSet<StringRef> &SaveTempsArgs = {});
};
struct LTOLLVMDiagnosticHandler : public DiagnosticHandler {
diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h
index ea045dcc5d7cf..d8e632b5a49d5 100644
--- a/llvm/include/llvm/LTO/LTO.h
+++ b/llvm/include/llvm/LTO/LTO.h
@@ -15,6 +15,7 @@
#ifndef LLVM_LTO_LTO_H
#define LLVM_LTO_LTO_H
+#include "llvm/Support/Compiler.h"
#include <memory>
#include "llvm/ADT/DenseMap.h"
@@ -47,7 +48,7 @@ class ToolOutputFile;
///
/// This is done for correctness (if value exported, ensure we always
/// emit a copy), and compile-time optimization (allow drop of duplicates).
-void thinLTOResolvePrevailingInIndex(
+LLVM_ABI void thinLTOResolvePrevailingInIndex(
const lto::Config &C, ModuleSummaryIndex &Index,
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
isPrevailing,
@@ -58,7 +59,7 @@ void thinLTOResolvePrevailingInIndex(
/// Update the linkages in the given \p Index to mark exported values
/// as external and non-exported values as internal. The ThinLTO backends
/// must apply the changes to the Module via thinLTOInternalizeModule.
-void thinLTOInternalizeAndPromoteInIndex(
+LLVM_ABI void thinLTOInternalizeAndPromoteInIndex(
ModuleSummaryIndex &Index,
function_ref<bool(StringRef, ValueInfo)> isExported,
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
@@ -66,7 +67,7 @@ void thinLTOInternalizeAndPromoteInIndex(
/// Computes a unique hash for the Module considering the current list of
/// export/import and other global analysis results.
-std::string computeLTOCacheKey(
+LLVM_ABI std::string computeLTOCacheKey(
const lto::Config &Conf, const ModuleSummaryIndex &Index,
StringRef ModuleID, const FunctionImporter::ImportMapTy &ImportList,
const FunctionImporter::ExportSetTy &ExportList,
@@ -76,36 +77,38 @@ std::string computeLTOCacheKey(
const DenseSet<GlobalValue::GUID> &CfiFunctionDecls = {});
/// Recomputes the LTO cache key for a given key with an extra identifier.
-std::string recomputeLTOCacheKey(const std::string &Key, StringRef ExtraID);
+LLVM_ABI std::string recomputeLTOCacheKey(const std::string &Key,
+ StringRef ExtraID);
namespace lto {
-StringLiteral getThinLTODefaultCPU(const Triple &TheTriple);
+LLVM_ABI StringLiteral getThinLTODefaultCPU(const Triple &TheTriple);
/// Given the original \p Path to an output file, replace any path
/// prefix matching \p OldPrefix with \p NewPrefix. Also, create the
/// resulting directory if it does not yet exist.
-std::string getThinLTOOutputFile(StringRef Path, StringRef OldPrefix,
- StringRef NewPrefix);
+LLVM_ABI std::string getThinLTOOutputFile(StringRef Path, StringRef OldPrefix,
+ StringRef NewPrefix);
/// Setup optimization remarks.
-Expected<std::unique_ptr<ToolOutputFile>> setupLLVMOptimizationRemarks(
+LLVM_ABI Expected<std::unique_ptr<ToolOutputFile>> setupLLVMOptimizationRemarks(
LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses,
StringRef RemarksFormat, bool RemarksWithHotness,
std::optional<uint64_t> RemarksHotnessThreshold = 0, int Count = -1);
/// Setups the output file for saving statistics.
-Expected<std::unique_ptr<ToolOutputFile>>
+LLVM_ABI Expected<std::unique_ptr<ToolOutputFile>>
setupStatsFile(StringRef StatsFilename);
/// Produces a container ordering for optimal multi-threaded processing. Returns
/// ordered indices to elements in the input array.
-std::vector<int> generateModulesOrdering(ArrayRef<BitcodeModule *> R);
+LLVM_ABI std::vector<int> generateModulesOrdering(ArrayRef<BitcodeModule *> R);
/// Updates MemProf attributes (and metadata) based on whether the index
/// has recorded that we are linking with allocation libraries containing
/// the necessary APIs for downstream transformations.
-void updateMemProfAttributes(Module &Mod, const ModuleSummaryIndex &Index);
+LLVM_ABI void updateMemProfAttributes(Module &Mod,
+ const ModuleSummaryIndex &Index);
class LTO;
struct SymbolResolution;
@@ -133,10 +136,11 @@ class InputFile {
std::vector<std::pair<StringRef, Comdat::SelectionKind>> ComdatTable;
public:
- ~InputFile();
+ LLVM_ABI ~InputFile();
/// Create an InputFile.
- static Expected<std::unique_ptr<InputFile>> create(MemoryBufferRef Object);
+ LLVM_ABI static Expected<std::unique_ptr<InputFile>>
+ create(MemoryBufferRef Object);
/// The purpose of this struct is to only expose the symbol information that
/// an LTO client should need in order to do symbol resolution.
@@ -174,7 +178,7 @@ class InputFile {
ArrayRef<StringRef> getDependentLibraries() const { return DependentLibraries; }
/// Returns the path to the InputFile.
- StringRef getName() const;
+ LLVM_ABI StringRef getName() const;
/// Returns the input file's target triple.
StringRef getTargetTriple() const { return TargetTriple; }
@@ -188,7 +192,7 @@ class InputFile {
}
// Returns the only BitcodeModule from InputFile.
- BitcodeModule &getSingleBitcodeModule();
+ LLVM_ABI BitcodeModule &getSingleBitcodeModule();
private:
ArrayRef<Symbol> module_symbols(unsigned I) const {
@@ -243,16 +247,17 @@ class ThinBackendProc {
virtual bool isSensitiveToInputOrder() { return false; }
// Write sharded indices and (optionally) imports to disk
- Error emitFiles(const FunctionImporter::ImportMapTy &ImportList,
- StringRef ModulePath, const std::string &NewModulePath) const;
+ LLVM_ABI Error emitFiles(const FunctionImporter::ImportMapTy &ImportList,
+ StringRef ModulePath,
+ const std::string &NewModulePath) const;
// Write sharded indices to SummaryPath, (optionally) imports to disk, and
// (optionally) record imports in ImportsFiles.
- Error emitFiles(const FunctionImporter::ImportMapTy &ImportList,
- StringRef ModulePath, const std::string &NewModulePath,
- StringRef SummaryPath,
- std::optional<std::reference_wrapper<ImportsFilesContainer>>
- ImportsFiles) const;
+ LLVM_ABI Error emitFiles(
+ const FunctionImporter::ImportMapTy &ImportList, StringRef ModulePath,
+ const std::string &NewModulePath, StringRef SummaryPath,
+ std::optional<std::reference_wrapper<ImportsFilesContainer>> ImportsFiles)
+ const;
};
/// This callable defines the behavior of a ThinLTO backend after the thin-link
@@ -300,10 +305,9 @@ struct ThinBackend {
/// to the same path as the input module, with suffix ".thinlto.bc"
/// ShouldEmitImportsFiles is true it also writes a list of imported files to a
/// similar path with ".imports" appended instead.
-ThinBackend createInProcessThinBackend(ThreadPoolStrategy Parallelism,
- IndexWriteCallback OnWrite = nullptr,
- bool ShouldEmitIndexFiles = false,
- bool ShouldEmitImportsFiles = false);
+LLVM_ABI ThinBackend createInProcessThinBackend(
+ ThreadPoolStrategy Parallelism, IndexWriteCallback OnWrite = nullptr,
+ bool ShouldEmitIndexFiles = false, bool ShouldEmitImportsFiles = false);
/// This ThinBackend generates the index shards and then runs the individual
/// backend jobs via an external process. It takes the same parameters as the
@@ -322,7 +326,7 @@ ThinBackend createInProcessThinBackend(ThreadPoolStrategy Parallelism,
/// backend compilations.
/// SaveTemps is a debugging tool that prevents temporary files created by this
/// backend from being cleaned up.
-ThinBackend createOutOfProcessThinBackend(
+LLVM_ABI ThinBackend createOutOfProcessThinBackend(
ThreadPoolStrategy Parallelism, IndexWriteCallback OnWrite,
bool ShouldEmitIndexFiles, bool ShouldEmitImportsFiles,
StringRef LinkerOutputFile, StringRef Distributor,
@@ -344,13 +348,11 @@ ThinBackend createOutOfProcessThinBackend(
/// the objects with NativeObjectPrefix instead of NewPrefix. OnWrite is
/// callback which receives module identifier and notifies LTO user that index
/// file for the module (and optionally imports file) was created.
-ThinBackend createWriteIndexesThinBackend(ThreadPoolStrategy Parallelism,
- std::string OldPrefix,
- std::string NewPrefix,
- std::string NativeObjectPrefix,
- bool ShouldEmitImportsFiles,
- raw_fd_ostream *LinkedObjectsFile,
- IndexWriteCallback OnWrite);
+LLVM_ABI ThinBackend createWriteIndexesThinBackend(
+ ThreadPoolStrategy Parallelism, std::string OldPrefix,
+ std::string NewPrefix, std::string NativeObjectPrefix,
+ bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile,
+ IndexWriteCallback OnWrite);
/// This class implements a resolution-based interface to LLVM's LTO
/// functionality. It supports regular LTO, parallel LTO code generation and
@@ -389,20 +391,21 @@ class LTO {
/// this constructor.
/// FIXME: We do currently require the DiagHandler field to be set in Conf.
/// Until that is fixed, a Config argument is required.
- LTO(Config Conf, ThinBackend Backend = {},
- unsigned ParallelCodeGenParallelismLevel = 1,
- LTOKind LTOMode = LTOK_Default);
- ~LTO();
+ LLVM_ABI LTO(Config Conf, ThinBackend Backend = {},
+ unsigned ParallelCodeGenParallelismLevel = 1,
+ LTOKind LTOMode = LTOK_Default);
+ LLVM_ABI ~LTO();
/// Add an input file to the LTO link, using the provided symbol resolutions.
/// The symbol resolutions must appear in the enumeration order given by
/// InputFile::symbols().
- Error add(std::unique_ptr<InputFile> Obj, ArrayRef<SymbolResolution> Res);
+ LLVM_ABI Error add(std::unique_ptr<InputFile> Obj,
+ ArrayRef<SymbolResolution> Res);
/// Returns an upper bound on the number of tasks that the client may expect.
/// This may only be called after all IR object files have been added. For a
/// full description of tasks see LTOBackend.h.
- unsigned getMaxTasks() const;
+ LLVM_ABI unsigned getMaxTasks() const;
/// Runs the LTO pipeline. This function calls the supplied AddStream
/// function to add native object files to the link.
@@ -412,18 +415,19 @@ class LTO {
///
/// The client will receive at most one callback (via either AddStream or
/// Cache) for each task identifier.
- Error run(AddStreamFn AddStream, FileCache Cache = {});
+ LLVM_ABI Error run(AddStreamFn AddStream, FileCache Cache = {});
/// Static method that returns a list of libcall symbols that can be generated
/// by LTO but might not be visible from bitcode symbol table.
- static SmallVector<const char *> getRuntimeLibcallSymbols(const Triple &TT);
+ LLVM_ABI static SmallVector<const char *>
+ getRuntimeLibcallSymbols(const Triple &TT);
private:
Config Conf;
struct RegularLTOState {
- RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
- const Config &Conf);
+ LLVM_ABI RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
+ const Config &Conf);
struct CommonResolution {
uint64_t Size = 0;
Align Alignment;
@@ -452,7 +456,7 @@ class LTO {
using ModuleMapType = MapVector<StringRef, BitcodeModule>;
struct ThinLTOState {
- ThinLTOState(ThinBack...
[truncated]
|
@compnerd, @vgvassilev here is another small one for review, thanks! |
Purpose
This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the
llvm/LTO
library. These annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build.Background
This effort is tracked in #109483. Additional context is provided in this discourse, and documentation for
LLVM_ABI
and related annotations is found in the LLVM repo here.The bulk of these changes were generated automatically using the Interface Definition Scanner (IDS) tool, followed formatting with
git clang-format
.The following manual adjustments were also applied after running IDS on Linux:
LLVM_ABI
to a small number of symbols that require export but are not declared in headersValidation
Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: