Skip to content

Commit 150d466

Browse files
authored
[llvm] annotate interfaces in FileCheck, FrontEnd, and FuzzMutate libraries for DLL export (llvm#141864)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/FileCheck`, `llvm/FrontEnd`, and `llvm/FuzzMutate 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 llvm#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 #include "llvm/Support/Compiler.h" where it was not auto-added by IDS due to no pre-existing block of include statements. ## 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 be6fc00 commit 150d466

File tree

14 files changed

+525
-466
lines changed

14 files changed

+525
-466
lines changed

llvm/include/llvm/FileCheck/FileCheck.h

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

1616
#include "llvm/ADT/StringRef.h"
17+
#include "llvm/Support/Compiler.h"
1718
#include "llvm/Support/Regex.h"
1819
#include "llvm/Support/SMLoc.h"
1920
#include <bitset>
@@ -91,7 +92,7 @@ class FileCheckType {
9192
operator FileCheckKind() const { return Kind; }
9293

9394
int getCount() const { return Count; }
94-
FileCheckType &setCount(int C);
95+
LLVM_ABI FileCheckType &setCount(int C);
9596

9697
bool isLiteralMatch() const {
9798
return Modifiers[FileCheckKindModifier::ModifierLiteral];
@@ -102,10 +103,10 @@ class FileCheckType {
102103
}
103104

104105
// \returns a description of \p Prefix.
105-
std::string getDescription(StringRef Prefix) const;
106+
LLVM_ABI std::string getDescription(StringRef Prefix) const;
106107

107108
// \returns a description of \p Modifiers.
108-
std::string getModifiersDescription() const;
109+
LLVM_ABI std::string getModifiersDescription() const;
109110
};
110111
} // namespace Check
111112

@@ -167,9 +168,10 @@ struct FileCheckDiag {
167168
/// A note to replace the one normally indicated by MatchTy, or the empty
168169
/// string if none.
169170
std::string Note;
170-
FileCheckDiag(const SourceMgr &SM, const Check::FileCheckType &CheckTy,
171-
SMLoc CheckLoc, MatchType MatchTy, SMRange InputRange,
172-
StringRef Note = "");
171+
LLVM_ABI FileCheckDiag(const SourceMgr &SM,
172+
const Check::FileCheckType &CheckTy, SMLoc CheckLoc,
173+
MatchType MatchTy, SMRange InputRange,
174+
StringRef Note = "");
173175
};
174176

175177
class FileCheckPatternContext;
@@ -183,33 +185,33 @@ class FileCheck {
183185
std::vector<FileCheckString> CheckStrings;
184186

185187
public:
186-
explicit FileCheck(FileCheckRequest Req);
187-
~FileCheck();
188+
LLVM_ABI explicit FileCheck(FileCheckRequest Req);
189+
LLVM_ABI ~FileCheck();
188190

189191
/// Reads the check file from \p Buffer and records the expected strings it
190192
/// contains. Errors are reported against \p SM.
191193
///
192194
/// If \p ImpPatBufferIDRange, then the range (inclusive start, exclusive end)
193195
/// of IDs for source buffers added to \p SM for implicit patterns are
194196
/// recorded in it. The range is empty if there are none.
195-
bool
197+
LLVM_ABI bool
196198
readCheckFile(SourceMgr &SM, StringRef Buffer,
197199
std::pair<unsigned, unsigned> *ImpPatBufferIDRange = nullptr);
198200

199-
bool ValidateCheckPrefixes();
201+
LLVM_ABI bool ValidateCheckPrefixes();
200202

201203
/// Canonicalizes whitespaces in the file. Line endings are replaced with
202204
/// UNIX-style '\n'.
203-
StringRef CanonicalizeFile(MemoryBuffer &MB,
204-
SmallVectorImpl<char> &OutputBuffer);
205+
LLVM_ABI StringRef CanonicalizeFile(MemoryBuffer &MB,
206+
SmallVectorImpl<char> &OutputBuffer);
205207

206208
/// Checks the input to FileCheck provided in the \p Buffer against the
207209
/// expected strings read from the check file and record diagnostics emitted
208210
/// in \p Diags. Errors are recorded against \p SM.
209211
///
210212
/// \returns false if the input fails to satisfy the checks.
211-
bool checkInput(SourceMgr &SM, StringRef Buffer,
212-
std::vector<FileCheckDiag> *Diags = nullptr);
213+
LLVM_ABI bool checkInput(SourceMgr &SM, StringRef Buffer,
214+
std::vector<FileCheckDiag> *Diags = nullptr);
213215
};
214216

215217
} // namespace llvm

llvm/include/llvm/Frontend/Atomic/Atomic.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "llvm/IR/IRBuilder.h"
1313
#include "llvm/IR/Module.h"
14+
#include "llvm/Support/Compiler.h"
1415

1516
namespace llvm {
1617
class AtomicInfo {
@@ -55,13 +56,13 @@ class AtomicInfo {
5556

5657
LLVMContext &getLLVMContext() const { return Builder->getContext(); }
5758

58-
bool shouldCastToInt(Type *ValTy, bool CmpXchg);
59+
LLVM_ABI bool shouldCastToInt(Type *ValTy, bool CmpXchg);
5960

60-
Value *EmitAtomicLoadOp(AtomicOrdering AO, bool IsVolatile,
61-
bool CmpXchg = false);
61+
LLVM_ABI Value *EmitAtomicLoadOp(AtomicOrdering AO, bool IsVolatile,
62+
bool CmpXchg = false);
6263

63-
CallInst *EmitAtomicLibcall(StringRef fnName, Type *ResultType,
64-
ArrayRef<Value *> Args);
64+
LLVM_ABI CallInst *EmitAtomicLibcall(StringRef fnName, Type *ResultType,
65+
ArrayRef<Value *> Args);
6566

6667
Value *getAtomicSizeValue() const {
6768
LLVMContext &ctx = getLLVMContext();
@@ -73,7 +74,7 @@ class AtomicInfo {
7374
AtomicSizeInBits / BitsPerByte);
7475
}
7576

76-
std::pair<Value *, Value *>
77+
LLVM_ABI std::pair<Value *, Value *>
7778
EmitAtomicCompareExchangeLibcall(Value *ExpectedVal, Value *DesiredVal,
7879
AtomicOrdering Success,
7980
AtomicOrdering Failure);
@@ -86,19 +87,20 @@ class AtomicInfo {
8687
return castToAtomicIntPointer(getAtomicPointer());
8788
}
8889

89-
std::pair<Value *, Value *>
90+
LLVM_ABI std::pair<Value *, Value *>
9091
EmitAtomicCompareExchangeOp(Value *ExpectedVal, Value *DesiredVal,
9192
AtomicOrdering Success, AtomicOrdering Failure,
9293
bool IsVolatile = false, bool IsWeak = false);
9394

94-
std::pair<Value *, Value *>
95+
LLVM_ABI std::pair<Value *, Value *>
9596
EmitAtomicCompareExchange(Value *ExpectedVal, Value *DesiredVal,
9697
AtomicOrdering Success, AtomicOrdering Failure,
9798
bool IsVolatile, bool IsWeak);
9899

99-
std::pair<LoadInst *, AllocaInst *> EmitAtomicLoadLibcall(AtomicOrdering AO);
100+
LLVM_ABI std::pair<LoadInst *, AllocaInst *>
101+
EmitAtomicLoadLibcall(AtomicOrdering AO);
100102

101-
void EmitAtomicStoreLibcall(AtomicOrdering AO, Value *Source);
103+
LLVM_ABI void EmitAtomicStoreLibcall(AtomicOrdering AO, Value *Source);
102104
};
103105
} // end namespace llvm
104106

llvm/include/llvm/Frontend/Driver/CodeGenOptions.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#ifndef LLVM_FRONTEND_DRIVER_CODEGENOPTIONS_H
1414
#define LLVM_FRONTEND_DRIVER_CODEGENOPTIONS_H
1515

16+
#include "llvm/Support/Compiler.h"
17+
1618
namespace llvm {
1719
class Triple;
1820
class TargetLibraryInfoImpl;
@@ -46,8 +48,8 @@ enum class VectorLibrary {
4648
AMDLIBM // AMD vector math library.
4749
};
4850

49-
TargetLibraryInfoImpl *createTLII(const llvm::Triple &TargetTriple,
50-
VectorLibrary Veclib);
51+
LLVM_ABI TargetLibraryInfoImpl *createTLII(const llvm::Triple &TargetTriple,
52+
VectorLibrary Veclib);
5153

5254
} // end namespace llvm::driver
5355

llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H
1616

1717
#include "llvm/ADT/ArrayRef.h"
18+
#include "llvm/Support/Compiler.h"
1819
#include "llvm/Support/DXILABI.h"
1920
#include "llvm/Support/raw_ostream.h"
2021
#include <variant>
@@ -150,7 +151,7 @@ struct DescriptorTable {
150151
uint32_t NumClauses = 0;
151152
};
152153

153-
raw_ostream &operator<<(raw_ostream &OS, const DescriptorTable &Table);
154+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const DescriptorTable &Table);
154155

155156
static const uint32_t NumDescriptorsUnbounded = 0xffffffff;
156157
static const uint32_t DescriptorTableOffsetAppend = 0xffffffff;
@@ -180,7 +181,8 @@ struct DescriptorTableClause {
180181
}
181182
};
182183

183-
raw_ostream &operator<<(raw_ostream &OS, const DescriptorTableClause &Clause);
184+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
185+
const DescriptorTableClause &Clause);
184186

185187
struct StaticSampler {
186188
Register Reg;
@@ -217,7 +219,7 @@ using RootElement =
217219
std::variant<RootFlags, RootConstants, RootDescriptor, DescriptorTable,
218220
DescriptorTableClause, StaticSampler>;
219221

220-
void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements);
222+
LLVM_ABI void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements);
221223

222224
class MetadataBuilder {
223225
public:
@@ -228,7 +230,7 @@ class MetadataBuilder {
228230
///
229231
/// Accumulates the root signature and returns the Metadata node that is just
230232
/// a list of all the elements
231-
MDNode *BuildRootSignature();
233+
LLVM_ABI MDNode *BuildRootSignature();
232234

233235
private:
234236
/// Define the various builders for the different metadata types

llvm/include/llvm/Frontend/Offloading/OffloadWrapper.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "llvm/ADT/ArrayRef.h"
1313
#include "llvm/IR/Module.h"
14+
#include "llvm/Support/Compiler.h"
1415

1516
namespace llvm {
1617
namespace offloading {
@@ -22,11 +23,10 @@ using EntryArrayTy = std::pair<GlobalVariable *, GlobalVariable *>;
2223
/// \param Suffix An optional suffix appended to the emitted symbols.
2324
/// \param Relocatable Indicate if we need to change the offloading section to
2425
/// create a relocatable object.
25-
llvm::Error wrapOpenMPBinaries(llvm::Module &M,
26-
llvm::ArrayRef<llvm::ArrayRef<char>> Images,
27-
EntryArrayTy EntryArray,
28-
llvm::StringRef Suffix = "",
29-
bool Relocatable = false);
26+
LLVM_ABI llvm::Error
27+
wrapOpenMPBinaries(llvm::Module &M, llvm::ArrayRef<llvm::ArrayRef<char>> Images,
28+
EntryArrayTy EntryArray, llvm::StringRef Suffix = "",
29+
bool Relocatable = false);
3030

3131
/// Wraps the input fatbinary image into the module \p M as global symbols and
3232
/// registers the images with the CUDA runtime.
@@ -35,9 +35,11 @@ llvm::Error wrapOpenMPBinaries(llvm::Module &M,
3535
/// \param Suffix An optional suffix appended to the emitted symbols.
3636
/// \param EmitSurfacesAndTextures Whether to emit surface and textures
3737
/// registration code. It defaults to false.
38-
llvm::Error wrapCudaBinary(llvm::Module &M, llvm::ArrayRef<char> Images,
39-
EntryArrayTy EntryArray, llvm::StringRef Suffix = "",
40-
bool EmitSurfacesAndTextures = true);
38+
LLVM_ABI llvm::Error wrapCudaBinary(llvm::Module &M,
39+
llvm::ArrayRef<char> Images,
40+
EntryArrayTy EntryArray,
41+
llvm::StringRef Suffix = "",
42+
bool EmitSurfacesAndTextures = true);
4143

4244
/// Wraps the input bundled image into the module \p M as global symbols and
4345
/// registers the images with the HIP runtime.
@@ -46,9 +48,10 @@ llvm::Error wrapCudaBinary(llvm::Module &M, llvm::ArrayRef<char> Images,
4648
/// \param Suffix An optional suffix appended to the emitted symbols.
4749
/// \param EmitSurfacesAndTextures Whether to emit surface and textures
4850
/// registration code. It defaults to false.
49-
llvm::Error wrapHIPBinary(llvm::Module &M, llvm::ArrayRef<char> Images,
50-
EntryArrayTy EntryArray, llvm::StringRef Suffix = "",
51-
bool EmitSurfacesAndTextures = true);
51+
LLVM_ABI llvm::Error wrapHIPBinary(llvm::Module &M, llvm::ArrayRef<char> Images,
52+
EntryArrayTy EntryArray,
53+
llvm::StringRef Suffix = "",
54+
bool EmitSurfacesAndTextures = true);
5255
} // namespace offloading
5356
} // namespace llvm
5457

llvm/include/llvm/Frontend/Offloading/Utility.h

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_FRONTEND_OFFLOADING_UTILITY_H
1010
#define LLVM_FRONTEND_OFFLOADING_UTILITY_H
1111

12+
#include "llvm/Support/Compiler.h"
1213
#include <cstdint>
1314
#include <memory>
1415

@@ -67,7 +68,7 @@ enum OffloadEntryKindFlag : uint32_t {
6768

6869
/// Returns the type of the offloading entry we use to store kernels and
6970
/// globals that will be registered with the offloading runtime.
70-
StructType *getEntryTy(Module &M);
71+
LLVM_ABI StructType *getEntryTy(Module &M);
7172

7273
/// Create an offloading section struct used to register this global at
7374
/// runtime.
@@ -81,22 +82,23 @@ StructType *getEntryTy(Module &M);
8182
/// \param Data Extra data storage associated with the entry.
8283
/// \param SectionName The section this entry will be placed at.
8384
/// \param AuxAddr An extra pointer if needed.
84-
void emitOffloadingEntry(Module &M, object::OffloadKind Kind, Constant *Addr,
85-
StringRef Name, uint64_t Size, uint32_t Flags,
86-
uint64_t Data, Constant *AuxAddr = nullptr,
87-
StringRef SectionName = "llvm_offload_entries");
85+
LLVM_ABI void
86+
emitOffloadingEntry(Module &M, object::OffloadKind Kind, Constant *Addr,
87+
StringRef Name, uint64_t Size, uint32_t Flags,
88+
uint64_t Data, Constant *AuxAddr = nullptr,
89+
StringRef SectionName = "llvm_offload_entries");
8890

8991
/// Create a constant struct initializer used to register this global at
9092
/// runtime.
9193
/// \return the constant struct and the global variable holding the symbol name.
92-
std::pair<Constant *, GlobalVariable *>
94+
LLVM_ABI std::pair<Constant *, GlobalVariable *>
9395
getOffloadingEntryInitializer(Module &M, object::OffloadKind Kind,
9496
Constant *Addr, StringRef Name, uint64_t Size,
9597
uint32_t Flags, uint64_t Data, Constant *AuxAddr);
9698

9799
/// Creates a pair of globals used to iterate the array of offloading entries by
98100
/// accessing the section variables provided by the linker.
99-
std::pair<GlobalVariable *, GlobalVariable *>
101+
LLVM_ABI std::pair<GlobalVariable *, GlobalVariable *>
100102
getOffloadEntryArray(Module &M, StringRef SectionName = "llvm_offload_entries");
101103

102104
namespace amdgpu {
@@ -109,8 +111,8 @@ namespace amdgpu {
109111
/// and is compatible with either '+' or '-'. The HSA runtime returns this
110112
/// information using the target-id, while we use the ELF header to determine
111113
/// these features.
112-
bool isImageCompatibleWithEnv(StringRef ImageArch, uint32_t ImageFlags,
113-
StringRef EnvTargetID);
114+
LLVM_ABI bool isImageCompatibleWithEnv(StringRef ImageArch, uint32_t ImageFlags,
115+
StringRef EnvTargetID);
114116

115117
/// Struct for holding metadata related to AMDGPU kernels, for more information
116118
/// about the metadata and its meaning see:
@@ -149,15 +151,16 @@ struct AMDGPUKernelMetaData {
149151

150152
/// Reads AMDGPU specific metadata from the ELF file and propagates the
151153
/// KernelInfoMap.
152-
Error getAMDGPUMetaDataFromImage(MemoryBufferRef MemBuffer,
153-
StringMap<AMDGPUKernelMetaData> &KernelInfoMap,
154-
uint16_t &ELFABIVersion);
154+
LLVM_ABI Error getAMDGPUMetaDataFromImage(
155+
MemoryBufferRef MemBuffer, StringMap<AMDGPUKernelMetaData> &KernelInfoMap,
156+
uint16_t &ELFABIVersion);
155157
} // namespace amdgpu
156158

157159
namespace intel {
158160
/// Containerizes an offloading binary into the ELF binary format expected by
159161
/// the Intel runtime offload plugin.
160-
Error containerizeOpenMPSPIRVImage(std::unique_ptr<MemoryBuffer> &Binary);
162+
LLVM_ABI Error
163+
containerizeOpenMPSPIRVImage(std::unique_ptr<MemoryBuffer> &Binary);
161164
} // namespace intel
162165
} // namespace offloading
163166
} // namespace llvm

llvm/include/llvm/Frontend/OpenMP/OMP.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,24 @@
1414
#define LLVM_FRONTEND_OPENMP_OMP_H
1515

1616
#include "llvm/Frontend/OpenMP/OMP.h.inc"
17+
#include "llvm/Support/Compiler.h"
1718

1819
#include "llvm/ADT/ArrayRef.h"
1920
#include "llvm/ADT/SmallVector.h"
2021
#include "llvm/ADT/StringRef.h"
2122

2223
namespace llvm::omp {
23-
ArrayRef<Directive> getLeafConstructs(Directive D);
24-
ArrayRef<Directive> getLeafConstructsOrSelf(Directive D);
24+
LLVM_ABI ArrayRef<Directive> getLeafConstructs(Directive D);
25+
LLVM_ABI ArrayRef<Directive> getLeafConstructsOrSelf(Directive D);
2526

26-
ArrayRef<Directive>
27+
LLVM_ABI ArrayRef<Directive>
2728
getLeafOrCompositeConstructs(Directive D, SmallVectorImpl<Directive> &Output);
2829

29-
Directive getCompoundConstruct(ArrayRef<Directive> Parts);
30+
LLVM_ABI Directive getCompoundConstruct(ArrayRef<Directive> Parts);
3031

31-
bool isLeafConstruct(Directive D);
32-
bool isCompositeConstruct(Directive D);
33-
bool isCombinedConstruct(Directive D);
32+
LLVM_ABI bool isLeafConstruct(Directive D);
33+
LLVM_ABI bool isCompositeConstruct(Directive D);
34+
LLVM_ABI bool isCombinedConstruct(Directive D);
3435

3536
/// Can clause C have an iterator-modifier.
3637
static constexpr inline bool canHaveIterator(Clause C) {
@@ -48,14 +49,15 @@ static constexpr inline bool canHaveIterator(Clause C) {
4849
}
4950

5051
static constexpr unsigned FallbackVersion = 52;
51-
ArrayRef<unsigned> getOpenMPVersions();
52+
LLVM_ABI ArrayRef<unsigned> getOpenMPVersions();
5253

5354
/// Create a nicer version of a function name for humans to look at.
54-
std::string prettifyFunctionName(StringRef FunctionName);
55+
LLVM_ABI std::string prettifyFunctionName(StringRef FunctionName);
5556

5657
/// Deconstruct an OpenMP kernel name into the parent function name and the line
5758
/// number.
58-
std::string deconstructOpenMPKernelName(StringRef KernelName, unsigned &LineNo);
59+
LLVM_ABI std::string deconstructOpenMPKernelName(StringRef KernelName,
60+
unsigned &LineNo);
5961

6062
} // namespace llvm::omp
6163

0 commit comments

Comments
 (0)