Skip to content

Commit 34bb642

Browse files
authored
[llvm] annotate interfaces in AsmParser, BinaryFormat, Bitcode, and Bitstream libraries for DLL export (#141794)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/AsmParser`, `llvm/BinaryFormat`, `llvm/Bitcode` and `llvm/Bitstream libraries. 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](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307), and documentation for `LLVM_ABI` and related annotations is found in the LLVM repo [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst). The bulk of these changes were generated automatically using the [Interface Definition Scanner (IDS)](https://github.com/compnerd/ids) tool, followed formatting with `git clang-format`. The following manual adjustments were also applied after running IDS on Linux: - Add `LLVM_ABI_FRIEND` to friend member functions declared with `LLVM_ABI` - Add `LLVM_ABI` symbols that require export but are not declared in headers ## Validation Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang
1 parent 405c31f commit 34bb642

File tree

21 files changed

+276
-245
lines changed

21 files changed

+276
-245
lines changed

llvm/include/llvm/AsmParser/Parser.h

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "llvm/ADT/STLFunctionalExtras.h"
1717
#include "llvm/ADT/StringRef.h"
18+
#include "llvm/Support/Compiler.h"
1819
#include <memory>
1920
#include <optional>
2021

@@ -44,9 +45,9 @@ typedef llvm::function_ref<std::optional<std::string>(StringRef, StringRef)>
4445
/// \param Context Context in which to allocate globals info.
4546
/// \param Slots The optional slot mapping that will be initialized during
4647
/// parsing.
47-
std::unique_ptr<Module> parseAssemblyFile(StringRef Filename, SMDiagnostic &Err,
48-
LLVMContext &Context,
49-
SlotMapping *Slots = nullptr);
48+
LLVM_ABI std::unique_ptr<Module>
49+
parseAssemblyFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
50+
SlotMapping *Slots = nullptr);
5051

5152
/// The function is a secondary interface to the LLVM Assembly Parser. It parses
5253
/// an ASCII string that (presumably) contains LLVM Assembly code. It returns a
@@ -59,10 +60,9 @@ std::unique_ptr<Module> parseAssemblyFile(StringRef Filename, SMDiagnostic &Err,
5960
/// \param Context Context in which to allocate globals info.
6061
/// \param Slots The optional slot mapping that will be initialized during
6162
/// parsing.
62-
std::unique_ptr<Module> parseAssemblyString(StringRef AsmString,
63-
SMDiagnostic &Err,
64-
LLVMContext &Context,
65-
SlotMapping *Slots = nullptr);
63+
LLVM_ABI std::unique_ptr<Module>
64+
parseAssemblyString(StringRef AsmString, SMDiagnostic &Err,
65+
LLVMContext &Context, SlotMapping *Slots = nullptr);
6666

6767
/// Holds the Module and ModuleSummaryIndex returned by the interfaces
6868
/// that parse both.
@@ -84,15 +84,15 @@ struct ParsedModuleAndIndex {
8484
/// \param Slots The optional slot mapping that will be initialized during
8585
/// parsing.
8686
/// \param DataLayoutCallback Override datalayout in the llvm assembly.
87-
ParsedModuleAndIndex parseAssemblyFileWithIndex(
87+
LLVM_ABI ParsedModuleAndIndex parseAssemblyFileWithIndex(
8888
StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
8989
SlotMapping *Slots = nullptr,
9090
DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) {
9191
return std::nullopt;
9292
});
9393

9494
/// Only for use in llvm-as for testing; this does not produce a valid module.
95-
ParsedModuleAndIndex parseAssemblyFileWithIndexNoUpgradeDebugInfo(
95+
LLVM_ABI ParsedModuleAndIndex parseAssemblyFileWithIndexNoUpgradeDebugInfo(
9696
StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
9797
SlotMapping *Slots, DataLayoutCallbackTy DataLayoutCallback);
9898

@@ -104,7 +104,7 @@ ParsedModuleAndIndex parseAssemblyFileWithIndexNoUpgradeDebugInfo(
104104
/// Parse LLVM Assembly Index from a file
105105
/// \param Filename The name of the file to parse
106106
/// \param Err Error result info.
107-
std::unique_ptr<ModuleSummaryIndex>
107+
LLVM_ABI std::unique_ptr<ModuleSummaryIndex>
108108
parseSummaryIndexAssemblyFile(StringRef Filename, SMDiagnostic &Err);
109109

110110
/// The function is a secondary interface to the LLVM Assembly Parser. It parses
@@ -115,7 +115,7 @@ parseSummaryIndexAssemblyFile(StringRef Filename, SMDiagnostic &Err);
115115
/// Parse LLVM Assembly from a string
116116
/// \param AsmString The string containing assembly
117117
/// \param Err Error result info.
118-
std::unique_ptr<ModuleSummaryIndex>
118+
LLVM_ABI std::unique_ptr<ModuleSummaryIndex>
119119
parseSummaryIndexAssemblyString(StringRef AsmString, SMDiagnostic &Err);
120120

121121
/// parseAssemblyFile and parseAssemblyString are wrappers around this function.
@@ -125,7 +125,7 @@ parseSummaryIndexAssemblyString(StringRef AsmString, SMDiagnostic &Err);
125125
/// \param Slots The optional slot mapping that will be initialized during
126126
/// parsing.
127127
/// \param DataLayoutCallback Override datalayout in the llvm assembly.
128-
std::unique_ptr<Module> parseAssembly(
128+
LLVM_ABI std::unique_ptr<Module> parseAssembly(
129129
MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context,
130130
SlotMapping *Slots = nullptr,
131131
DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) {
@@ -140,18 +140,17 @@ std::unique_ptr<Module> parseAssembly(
140140
/// parsing.
141141
///
142142
/// parseAssemblyFileWithIndex is a wrapper around this function.
143-
ParsedModuleAndIndex parseAssemblyWithIndex(MemoryBufferRef F,
144-
SMDiagnostic &Err,
145-
LLVMContext &Context,
146-
SlotMapping *Slots = nullptr);
143+
LLVM_ABI ParsedModuleAndIndex
144+
parseAssemblyWithIndex(MemoryBufferRef F, SMDiagnostic &Err,
145+
LLVMContext &Context, SlotMapping *Slots = nullptr);
147146

148147
/// Parse LLVM Assembly for summary index from a MemoryBuffer.
149148
///
150149
/// \param F The MemoryBuffer containing assembly with summary
151150
/// \param Err Error result info.
152151
///
153152
/// parseSummaryIndexAssemblyFile is a wrapper around this function.
154-
std::unique_ptr<ModuleSummaryIndex>
153+
LLVM_ABI std::unique_ptr<ModuleSummaryIndex>
155154
parseSummaryIndexAssembly(MemoryBufferRef F, SMDiagnostic &Err);
156155

157156
/// This function is the low-level interface to the LLVM Assembly Parser.
@@ -167,7 +166,7 @@ parseSummaryIndexAssembly(MemoryBufferRef F, SMDiagnostic &Err);
167166
/// parsing.
168167
/// \return true on error.
169168
/// \param DataLayoutCallback Override datalayout in the llvm assembly.
170-
bool parseAssemblyInto(
169+
LLVM_ABI bool parseAssemblyInto(
171170
MemoryBufferRef F, Module *M, ModuleSummaryIndex *Index, SMDiagnostic &Err,
172171
SlotMapping *Slots = nullptr,
173172
DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) {
@@ -182,16 +181,17 @@ bool parseAssemblyInto(
182181
/// \param Slots The optional slot mapping that will restore the parsing state
183182
/// of the module.
184183
/// \return null on error.
185-
Constant *parseConstantValue(StringRef Asm, SMDiagnostic &Err, const Module &M,
186-
const SlotMapping *Slots = nullptr);
184+
LLVM_ABI Constant *parseConstantValue(StringRef Asm, SMDiagnostic &Err,
185+
const Module &M,
186+
const SlotMapping *Slots = nullptr);
187187

188188
/// Parse a type in the given string.
189189
///
190190
/// \param Slots The optional slot mapping that will restore the parsing state
191191
/// of the module.
192192
/// \return null on error.
193-
Type *parseType(StringRef Asm, SMDiagnostic &Err, const Module &M,
194-
const SlotMapping *Slots = nullptr);
193+
LLVM_ABI Type *parseType(StringRef Asm, SMDiagnostic &Err, const Module &M,
194+
const SlotMapping *Slots = nullptr);
195195

196196
/// Parse a string \p Asm that starts with a type.
197197
/// \p Read[out] gives the number of characters that have been read to parse
@@ -200,13 +200,14 @@ Type *parseType(StringRef Asm, SMDiagnostic &Err, const Module &M,
200200
/// \param Slots The optional slot mapping that will restore the parsing state
201201
/// of the module.
202202
/// \return null on error.
203-
Type *parseTypeAtBeginning(StringRef Asm, unsigned &Read, SMDiagnostic &Err,
204-
const Module &M, const SlotMapping *Slots = nullptr);
205-
206-
DIExpression *parseDIExpressionBodyAtBeginning(StringRef Asm, unsigned &Read,
207-
SMDiagnostic &Err,
208-
const Module &M,
209-
const SlotMapping *Slots);
203+
LLVM_ABI Type *parseTypeAtBeginning(StringRef Asm, unsigned &Read,
204+
SMDiagnostic &Err, const Module &M,
205+
const SlotMapping *Slots = nullptr);
206+
207+
LLVM_ABI DIExpression *
208+
parseDIExpressionBodyAtBeginning(StringRef Asm, unsigned &Read,
209+
SMDiagnostic &Err, const Module &M,
210+
const SlotMapping *Slots);
210211

211212
} // End llvm namespace
212213

llvm/include/llvm/BinaryFormat/AMDGPUMetadataVerifier.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/STLFunctionalExtras.h"
2020
#include "llvm/ADT/StringRef.h"
2121
#include "llvm/BinaryFormat/MsgPackReader.h"
22+
#include "llvm/Support/Compiler.h"
2223

2324
#include <cstddef>
2425
#include <optional>
@@ -69,7 +70,7 @@ class MetadataVerifier {
6970
/// Verify given HSA metadata.
7071
///
7172
/// \returns True when successful, false when metadata is invalid.
72-
bool verify(msgpack::DocNode &HSAMetadataRoot);
73+
LLVM_ABI bool verify(msgpack::DocNode &HSAMetadataRoot);
7374
};
7475

7576
} // end namespace V3

llvm/include/llvm/BinaryFormat/COFF.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#ifndef LLVM_BINARYFORMAT_COFF_H
2323
#define LLVM_BINARYFORMAT_COFF_H
2424

25+
#include "llvm/Support/Compiler.h"
2526
#include "llvm/Support/DataTypes.h"
2627
#include <cassert>
2728

@@ -851,7 +852,7 @@ inline bool isReservedSectionNumber(int32_t SectionNumber) {
851852

852853
/// Encode section name based on string table offset.
853854
/// The size of Out must be at least COFF::NameSize.
854-
bool encodeSectionName(char *Out, uint64_t Offset);
855+
LLVM_ABI bool encodeSectionName(char *Out, uint64_t Offset);
855856

856857
} // End namespace COFF.
857858
} // End namespace llvm.

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_BINARYFORMAT_DXCONTAINER_H
1515

1616
#include "llvm/ADT/StringRef.h"
17+
#include "llvm/Support/Compiler.h"
1718
#include "llvm/Support/Error.h"
1819
#include "llvm/Support/SwapByteOrder.h"
1920
#include "llvm/TargetParser/Triple.h"
@@ -59,7 +60,7 @@ struct ShaderHash {
5960
uint32_t Flags; // dxbc::HashFlags
6061
uint8_t Digest[16];
6162

62-
bool isPopulated();
63+
LLVM_ABI bool isPopulated();
6364

6465
void swapBytes() { sys::swapByteOrder(Flags); }
6566
};
@@ -173,7 +174,7 @@ enum class RootParameterType : uint32_t {
173174
#include "DXContainerConstants.def"
174175
};
175176

176-
ArrayRef<EnumEntry<RootParameterType>> getRootParameterTypes();
177+
LLVM_ABI ArrayRef<EnumEntry<RootParameterType>> getRootParameterTypes();
177178

178179
#define DESCRIPTOR_RANGE(Val, Enum) Enum = Val,
179180
enum class DescriptorRangeType : uint32_t {
@@ -197,7 +198,7 @@ enum class ShaderVisibility : uint32_t {
197198
#include "DXContainerConstants.def"
198199
};
199200

200-
ArrayRef<EnumEntry<ShaderVisibility>> getShaderVisibility();
201+
LLVM_ABI ArrayRef<EnumEntry<ShaderVisibility>> getShaderVisibility();
201202

202203
#define SHADER_VISIBILITY(Val, Enum) \
203204
case Val: \
@@ -229,7 +230,7 @@ enum class SamplersBorderColor : uint32_t {
229230
#include "DXContainerConstants.def"
230231
};
231232

232-
PartType parsePartType(StringRef S);
233+
LLVM_ABI PartType parsePartType(StringRef S);
233234

234235
struct VertexPSVInfo {
235236
uint8_t OutputPositionPresent;
@@ -360,35 +361,35 @@ enum class SemanticKind : uint8_t {
360361
#include "DXContainerConstants.def"
361362
};
362363

363-
ArrayRef<EnumEntry<SemanticKind>> getSemanticKinds();
364+
LLVM_ABI ArrayRef<EnumEntry<SemanticKind>> getSemanticKinds();
364365

365366
#define COMPONENT_TYPE(Val, Enum) Enum = Val,
366367
enum class ComponentType : uint8_t {
367368
#include "DXContainerConstants.def"
368369
};
369370

370-
ArrayRef<EnumEntry<ComponentType>> getComponentTypes();
371+
LLVM_ABI ArrayRef<EnumEntry<ComponentType>> getComponentTypes();
371372

372373
#define INTERPOLATION_MODE(Val, Enum) Enum = Val,
373374
enum class InterpolationMode : uint8_t {
374375
#include "DXContainerConstants.def"
375376
};
376377

377-
ArrayRef<EnumEntry<InterpolationMode>> getInterpolationModes();
378+
LLVM_ABI ArrayRef<EnumEntry<InterpolationMode>> getInterpolationModes();
378379

379380
#define RESOURCE_TYPE(Val, Enum) Enum = Val,
380381
enum class ResourceType : uint32_t {
381382
#include "DXContainerConstants.def"
382383
};
383384

384-
ArrayRef<EnumEntry<ResourceType>> getResourceTypes();
385+
LLVM_ABI ArrayRef<EnumEntry<ResourceType>> getResourceTypes();
385386

386387
#define RESOURCE_KIND(Val, Enum) Enum = Val,
387388
enum class ResourceKind : uint32_t {
388389
#include "DXContainerConstants.def"
389390
};
390391

391-
ArrayRef<EnumEntry<ResourceKind>> getResourceKinds();
392+
LLVM_ABI ArrayRef<EnumEntry<ResourceKind>> getResourceKinds();
392393

393394
#define RESOURCE_FLAG(Index, Enum) bool Enum = false;
394395
struct ResourceFlags {
@@ -555,21 +556,21 @@ enum class SigMinPrecision : uint32_t {
555556
#include "DXContainerConstants.def"
556557
};
557558

558-
ArrayRef<EnumEntry<SigMinPrecision>> getSigMinPrecisions();
559+
LLVM_ABI ArrayRef<EnumEntry<SigMinPrecision>> getSigMinPrecisions();
559560

560561
#define D3D_SYSTEM_VALUE(Val, Enum) Enum = Val,
561562
enum class D3DSystemValue : uint32_t {
562563
#include "DXContainerConstants.def"
563564
};
564565

565-
ArrayRef<EnumEntry<D3DSystemValue>> getD3DSystemValues();
566+
LLVM_ABI ArrayRef<EnumEntry<D3DSystemValue>> getD3DSystemValues();
566567

567568
#define COMPONENT_TYPE(Val, Enum) Enum = Val,
568569
enum class SigComponentType : uint32_t {
569570
#include "DXContainerConstants.def"
570571
};
571572

572-
ArrayRef<EnumEntry<SigComponentType>> getSigComponentTypes();
573+
LLVM_ABI ArrayRef<EnumEntry<SigComponentType>> getSigComponentTypes();
573574

574575
struct ProgramSignatureHeader {
575576
uint32_t ParamCount;

0 commit comments

Comments
 (0)