Skip to content

Commit 391eb01

Browse files
andrurogerzsallto
authored andcommitted
[llvm] annotate interfaces in llvm/IR for DLL export (llvm#141650)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/IR`, `llvm/IRPrinter`, and `llvm/IRReader` 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"` to files where it was not auto-added by IDS due to no pre-existing block of include statements. - Add `LLVM_ABI_FRIEND` to friend member functions declared with `LLVM_ABI` - Add `LLVM_TEMPLATE_ABI` and `LLVM_EXPORT_TEMPLATE` to exported instantiated templates - Add `LLVM_ABI` to a subset of private class methods and fields that require export - Add `LLVM_ABI` to a small number of symbols that require export but are not declared in headers - Reorder `LLVM_ABI` with `[[deprecated]]` and `[[nodiscard]]` attributes. ## 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 1a88152 commit 391eb01

File tree

105 files changed

+3510
-3139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+3510
-3139
lines changed

llvm/include/llvm/IR/AbstractCallSite.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/IR/Function.h"
1919
#include "llvm/IR/InstrTypes.h"
2020
#include "llvm/IR/Value.h"
21+
#include "llvm/Support/Compiler.h"
2122
#include <cassert>
2223

2324
namespace llvm {
@@ -95,15 +96,16 @@ class AbstractCallSite {
9596
/// If the use is not a callee use of a call or invoke instruction, the
9697
/// callback metadata is used to determine the argument <-> parameter mapping
9798
/// as well as the callee of the abstract call site.
98-
AbstractCallSite(const Use *U);
99+
LLVM_ABI AbstractCallSite(const Use *U);
99100

100101
/// Add operand uses of \p CB that represent callback uses into
101102
/// \p CallbackUses.
102103
///
103104
/// All uses added to \p CallbackUses can be used to create abstract call
104105
/// sites for which AbstractCallSite::isCallbackCall() will return true.
105-
static void getCallbackUses(const CallBase &CB,
106-
SmallVectorImpl<const Use *> &CallbackUses);
106+
LLVM_ABI static void
107+
getCallbackUses(const CallBase &CB,
108+
SmallVectorImpl<const Use *> &CallbackUses);
107109

108110
/// Conversion operator to conveniently check for a valid/initialized ACS.
109111
explicit operator bool() const { return CB != nullptr; }

llvm/include/llvm/IR/Analysis.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define LLVM_IR_ANALYSIS_H
1414

1515
#include "llvm/ADT/SmallPtrSet.h"
16+
#include "llvm/Support/Compiler.h"
1617

1718
namespace llvm {
1819

@@ -56,8 +57,8 @@ template <typename IRUnitT> class AllAnalysesOn {
5657

5758
template <typename IRUnitT> AnalysisSetKey AllAnalysesOn<IRUnitT>::SetKey;
5859

59-
extern template class AllAnalysesOn<Module>;
60-
extern template class AllAnalysesOn<Function>;
60+
extern template class LLVM_TEMPLATE_ABI AllAnalysesOn<Module>;
61+
extern template class LLVM_TEMPLATE_ABI AllAnalysesOn<Function>;
6162

6263
/// Represents analyses that only rely on functions' control flow.
6364
///
@@ -74,7 +75,7 @@ class CFGAnalyses {
7475
static AnalysisSetKey *ID() { return &SetKey; }
7576

7677
private:
77-
static AnalysisSetKey SetKey;
78+
LLVM_ABI static AnalysisSetKey SetKey;
7879
};
7980

8081
/// A set of analyses that are preserved following a run of a transformation
@@ -310,7 +311,7 @@ class PreservedAnalyses {
310311

311312
private:
312313
/// A special key used to indicate all analyses.
313-
static AnalysisSetKey AllAnalysesKey;
314+
LLVM_ABI static AnalysisSetKey AllAnalysesKey;
314315

315316
/// The IDs of analyses and analysis sets that are preserved.
316317
SmallPtrSet<void *, 2> PreservedIDs;

llvm/include/llvm/IR/Argument.h

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/ADT/Twine.h"
1717
#include "llvm/IR/Attributes.h"
1818
#include "llvm/IR/Value.h"
19+
#include "llvm/Support/Compiler.h"
1920
#include <optional>
2021

2122
namespace llvm {
@@ -37,8 +38,8 @@ class Argument final : public Value {
3738

3839
public:
3940
/// Argument constructor.
40-
explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr,
41-
unsigned ArgNo = 0);
41+
LLVM_ABI explicit Argument(Type *Ty, const Twine &Name = "",
42+
Function *F = nullptr, unsigned ArgNo = 0);
4243

4344
inline const Function *getParent() const { return Parent; }
4445
inline Function *getParent() { return Parent; }
@@ -56,133 +57,133 @@ class Argument final : public Value {
5657
/// addrspace(0).
5758
/// If AllowUndefOrPoison is true, respect the semantics of nonnull attribute
5859
/// and return true even if the argument can be undef or poison.
59-
bool hasNonNullAttr(bool AllowUndefOrPoison = true) const;
60+
LLVM_ABI bool hasNonNullAttr(bool AllowUndefOrPoison = true) const;
6061

6162
/// If this argument has the dereferenceable attribute, return the number of
6263
/// bytes known to be dereferenceable. Otherwise, zero is returned.
63-
uint64_t getDereferenceableBytes() const;
64+
LLVM_ABI uint64_t getDereferenceableBytes() const;
6465

6566
/// If this argument has the dereferenceable_or_null attribute, return the
6667
/// number of bytes known to be dereferenceable. Otherwise, zero is returned.
67-
uint64_t getDereferenceableOrNullBytes() const;
68+
LLVM_ABI uint64_t getDereferenceableOrNullBytes() const;
6869

6970
/// If this argument has nofpclass attribute, return the mask representing
7071
/// disallowed floating-point values. Otherwise, fcNone is returned.
71-
FPClassTest getNoFPClass() const;
72+
LLVM_ABI FPClassTest getNoFPClass() const;
7273

7374
/// If this argument has a range attribute, return the value range of the
7475
/// argument. Otherwise, std::nullopt is returned.
75-
std::optional<ConstantRange> getRange() const;
76+
LLVM_ABI std::optional<ConstantRange> getRange() const;
7677

7778
/// Return true if this argument has the byval attribute.
78-
bool hasByValAttr() const;
79+
LLVM_ABI bool hasByValAttr() const;
7980

8081
/// Return true if this argument has the byref attribute.
81-
bool hasByRefAttr() const;
82+
LLVM_ABI bool hasByRefAttr() const;
8283

8384
/// Return true if this argument has the swiftself attribute.
84-
bool hasSwiftSelfAttr() const;
85+
LLVM_ABI bool hasSwiftSelfAttr() const;
8586

8687
/// Return true if this argument has the swifterror attribute.
87-
bool hasSwiftErrorAttr() const;
88+
LLVM_ABI bool hasSwiftErrorAttr() const;
8889

8990
/// Return true if this argument has the byval, inalloca, or preallocated
9091
/// attribute. These attributes represent arguments being passed by value,
9192
/// with an associated copy between the caller and callee
92-
bool hasPassPointeeByValueCopyAttr() const;
93+
LLVM_ABI bool hasPassPointeeByValueCopyAttr() const;
9394

9495
/// If this argument satisfies has hasPassPointeeByValueAttr, return the
9596
/// in-memory ABI size copied to the stack for the call. Otherwise, return 0.
96-
uint64_t getPassPointeeByValueCopySize(const DataLayout &DL) const;
97+
LLVM_ABI uint64_t getPassPointeeByValueCopySize(const DataLayout &DL) const;
9798

9899
/// Return true if this argument has the byval, sret, inalloca, preallocated,
99100
/// or byref attribute. These attributes represent arguments being passed by
100101
/// value (which may or may not involve a stack copy)
101-
bool hasPointeeInMemoryValueAttr() const;
102+
LLVM_ABI bool hasPointeeInMemoryValueAttr() const;
102103

103104
/// If hasPointeeInMemoryValueAttr returns true, the in-memory ABI type is
104105
/// returned. Otherwise, nullptr.
105-
Type *getPointeeInMemoryValueType() const;
106+
LLVM_ABI Type *getPointeeInMemoryValueType() const;
106107

107108
/// If this is a byval or inalloca argument, return its alignment.
108109
/// FIXME: Remove this function once transition to Align is over.
109110
/// Use getParamAlign() instead.
110-
LLVM_DEPRECATED("Use getParamAlign() instead", "getParamAlign")
111-
uint64_t getParamAlignment() const;
111+
LLVM_ABI LLVM_DEPRECATED("Use getParamAlign() instead",
112+
"getParamAlign") uint64_t getParamAlignment() const;
112113

113114
/// If this is a byval or inalloca argument, return its alignment.
114-
MaybeAlign getParamAlign() const;
115+
LLVM_ABI MaybeAlign getParamAlign() const;
115116

116-
MaybeAlign getParamStackAlign() const;
117+
LLVM_ABI MaybeAlign getParamStackAlign() const;
117118

118119
/// If this is a byval argument, return its type.
119-
Type *getParamByValType() const;
120+
LLVM_ABI Type *getParamByValType() const;
120121

121122
/// If this is an sret argument, return its type.
122-
Type *getParamStructRetType() const;
123+
LLVM_ABI Type *getParamStructRetType() const;
123124

124125
/// If this is a byref argument, return its type.
125-
Type *getParamByRefType() const;
126+
LLVM_ABI Type *getParamByRefType() const;
126127

127128
/// If this is an inalloca argument, return its type.
128-
Type *getParamInAllocaType() const;
129+
LLVM_ABI Type *getParamInAllocaType() const;
129130

130131
/// Return true if this argument has the nest attribute.
131-
bool hasNestAttr() const;
132+
LLVM_ABI bool hasNestAttr() const;
132133

133134
/// Return true if this argument has the noalias attribute.
134-
bool hasNoAliasAttr() const;
135+
LLVM_ABI bool hasNoAliasAttr() const;
135136

136137
/// Return true if this argument has the nocapture attribute.
137-
bool hasNoCaptureAttr() const;
138+
LLVM_ABI bool hasNoCaptureAttr() const;
138139

139140
/// Return true if this argument has the nofree attribute.
140-
bool hasNoFreeAttr() const;
141+
LLVM_ABI bool hasNoFreeAttr() const;
141142

142143
/// Return true if this argument has the sret attribute.
143-
bool hasStructRetAttr() const;
144+
LLVM_ABI bool hasStructRetAttr() const;
144145

145146
/// Return true if this argument has the inreg attribute.
146-
bool hasInRegAttr() const;
147+
LLVM_ABI bool hasInRegAttr() const;
147148

148149
/// Return true if this argument has the returned attribute.
149-
bool hasReturnedAttr() const;
150+
LLVM_ABI bool hasReturnedAttr() const;
150151

151152
/// Return true if this argument has the readonly or readnone attribute.
152-
bool onlyReadsMemory() const;
153+
LLVM_ABI bool onlyReadsMemory() const;
153154

154155
/// Return true if this argument has the inalloca attribute.
155-
bool hasInAllocaAttr() const;
156+
LLVM_ABI bool hasInAllocaAttr() const;
156157

157158
/// Return true if this argument has the preallocated attribute.
158-
bool hasPreallocatedAttr() const;
159+
LLVM_ABI bool hasPreallocatedAttr() const;
159160

160161
/// Return true if this argument has the zext attribute.
161-
bool hasZExtAttr() const;
162+
LLVM_ABI bool hasZExtAttr() const;
162163

163164
/// Return true if this argument has the sext attribute.
164-
bool hasSExtAttr() const;
165+
LLVM_ABI bool hasSExtAttr() const;
165166

166167
/// Add attributes to an argument.
167-
void addAttrs(AttrBuilder &B);
168+
LLVM_ABI void addAttrs(AttrBuilder &B);
168169

169-
void addAttr(Attribute::AttrKind Kind);
170+
LLVM_ABI void addAttr(Attribute::AttrKind Kind);
170171

171-
void addAttr(Attribute Attr);
172+
LLVM_ABI void addAttr(Attribute Attr);
172173

173174
/// Remove attributes from an argument.
174-
void removeAttr(Attribute::AttrKind Kind);
175+
LLVM_ABI void removeAttr(Attribute::AttrKind Kind);
175176

176-
void removeAttrs(const AttributeMask &AM);
177+
LLVM_ABI void removeAttrs(const AttributeMask &AM);
177178

178179
/// Check if an argument has a given attribute.
179-
bool hasAttribute(Attribute::AttrKind Kind) const;
180+
LLVM_ABI bool hasAttribute(Attribute::AttrKind Kind) const;
180181

181-
bool hasAttribute(StringRef Kind) const;
182+
LLVM_ABI bool hasAttribute(StringRef Kind) const;
182183

183-
Attribute getAttribute(Attribute::AttrKind Kind) const;
184+
LLVM_ABI Attribute getAttribute(Attribute::AttrKind Kind) const;
184185

185-
AttributeSet getAttributes() const;
186+
LLVM_ABI AttributeSet getAttributes() const;
186187

187188
/// Method for support type inquiry through isa, cast, and dyn_cast.
188189
static bool classof(const Value *V) {

llvm/include/llvm/IR/AssemblyAnnotationWriter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#ifndef LLVM_IR_ASSEMBLYANNOTATIONWRITER_H
1717
#define LLVM_IR_ASSEMBLYANNOTATIONWRITER_H
1818

19+
#include "llvm/Support/Compiler.h"
20+
1921
namespace llvm {
2022

2123
class Function;
@@ -24,7 +26,7 @@ class Instruction;
2426
class Value;
2527
class formatted_raw_ostream;
2628

27-
class AssemblyAnnotationWriter {
29+
class LLVM_ABI AssemblyAnnotationWriter {
2830
public:
2931
virtual ~AssemblyAnnotationWriter();
3032

llvm/include/llvm/IR/Assumptions.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/DenseSet.h"
1919
#include "llvm/ADT/StringRef.h"
2020
#include "llvm/ADT/StringSet.h"
21+
#include "llvm/Support/Compiler.h"
2122

2223
namespace llvm {
2324

@@ -29,7 +30,7 @@ constexpr StringRef AssumptionAttrKey = "llvm.assume";
2930

3031
/// A set of known assumption strings that are accepted without warning and
3132
/// which can be recommended as typo correction.
32-
extern StringSet<> KnownAssumptionStrings;
33+
LLVM_ABI extern StringSet<> KnownAssumptionStrings;
3334

3435
/// Helper that allows to insert a new assumption string in the known assumption
3536
/// set by creating a (static) object.
@@ -49,25 +50,27 @@ struct KnownAssumptionString {
4950
};
5051

5152
/// Return true if \p F has the assumption \p AssumptionStr attached.
52-
bool hasAssumption(const Function &F,
53-
const KnownAssumptionString &AssumptionStr);
53+
LLVM_ABI bool hasAssumption(const Function &F,
54+
const KnownAssumptionString &AssumptionStr);
5455

5556
/// Return true if \p CB or the callee has the assumption \p AssumptionStr
5657
/// attached.
57-
bool hasAssumption(const CallBase &CB,
58-
const KnownAssumptionString &AssumptionStr);
58+
LLVM_ABI bool hasAssumption(const CallBase &CB,
59+
const KnownAssumptionString &AssumptionStr);
5960

6061
/// Return the set of all assumptions for the function \p F.
61-
DenseSet<StringRef> getAssumptions(const Function &F);
62+
LLVM_ABI DenseSet<StringRef> getAssumptions(const Function &F);
6263

6364
/// Return the set of all assumptions for the call \p CB.
64-
DenseSet<StringRef> getAssumptions(const CallBase &CB);
65+
LLVM_ABI DenseSet<StringRef> getAssumptions(const CallBase &CB);
6566

6667
/// Appends the set of assumptions \p Assumptions to \F.
67-
bool addAssumptions(Function &F, const DenseSet<StringRef> &Assumptions);
68+
LLVM_ABI bool addAssumptions(Function &F,
69+
const DenseSet<StringRef> &Assumptions);
6870

6971
/// Appends the set of assumptions \p Assumptions to \CB.
70-
bool addAssumptions(CallBase &CB, const DenseSet<StringRef> &Assumptions);
72+
LLVM_ABI bool addAssumptions(CallBase &CB,
73+
const DenseSet<StringRef> &Assumptions);
7174

7275
} // namespace llvm
7376

0 commit comments

Comments
 (0)