Skip to content

Commit 8e84378

Browse files
andrurogerzsivan-shani
authored andcommitted
[llvm] annotate interfaces in llvm/Analysis for DLL export (llvm#136623)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/Analysis` 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 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_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 ## 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 9e73583 commit 8e84378

File tree

98 files changed

+2661
-2328
lines changed

Some content is hidden

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

98 files changed

+2661
-2328
lines changed

llvm/include/llvm/Analysis/AliasAnalysis.h

Lines changed: 91 additions & 73 deletions
Large diffs are not rendered by default.

llvm/include/llvm/Analysis/AliasAnalysisEvaluator.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define LLVM_ANALYSIS_ALIASANALYSISEVALUATOR_H
2626

2727
#include "llvm/IR/PassManager.h"
28+
#include "llvm/Support/Compiler.h"
2829

2930
namespace llvm {
3031
class AAResults;
@@ -47,10 +48,10 @@ class AAEvaluator : public PassInfoMixin<AAEvaluator> {
4748
ModRefCount(Arg.ModRefCount) {
4849
Arg.FunctionCount = 0;
4950
}
50-
~AAEvaluator();
51+
LLVM_ABI ~AAEvaluator();
5152

5253
/// Run the pass over the function.
53-
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
54+
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
5455

5556
private:
5657
void runInternal(Function &F, AAResults &AA);

llvm/include/llvm/Analysis/AliasSetTracker.h

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/Analysis/MemoryLocation.h"
2626
#include "llvm/IR/PassManager.h"
2727
#include "llvm/IR/ValueHandle.h"
28+
#include "llvm/Support/Compiler.h"
2829
#include <cassert>
2930
#include <vector>
3031

@@ -113,7 +114,8 @@ class AliasSet : public ilist_node<AliasSet> {
113114
bool isForwardingAliasSet() const { return Forward; }
114115

115116
/// Merge the specified alias set into this alias set.
116-
void mergeSetIn(AliasSet &AS, AliasSetTracker &AST, BatchAAResults &BatchAA);
117+
LLVM_ABI void mergeSetIn(AliasSet &AS, AliasSetTracker &AST,
118+
BatchAAResults &BatchAA);
117119

118120
// Alias Set iteration - Allow access to all of the memory locations which are
119121
// part of this alias set.
@@ -127,17 +129,17 @@ class AliasSet : public ilist_node<AliasSet> {
127129
/// The order matches that of the memory locations, but duplicate pointer
128130
/// values are omitted.
129131
using PointerVector = SmallVector<const Value *, 8>;
130-
PointerVector getPointers() const;
132+
LLVM_ABI PointerVector getPointers() const;
131133

132-
void print(raw_ostream &OS) const;
133-
void dump() const;
134+
LLVM_ABI void print(raw_ostream &OS) const;
135+
LLVM_ABI void dump() const;
134136

135137
private:
136138
// Can only be created by AliasSetTracker.
137139
AliasSet()
138140
: RefCount(0), AliasAny(false), Access(NoAccess), Alias(SetMustAlias) {}
139141

140-
void removeFromTracker(AliasSetTracker &AST);
142+
LLVM_ABI void removeFromTracker(AliasSetTracker &AST);
141143

142144
void addMemoryLocation(AliasSetTracker &AST, const MemoryLocation &MemLoc,
143145
bool KnownMustAlias = false);
@@ -146,11 +148,11 @@ class AliasSet : public ilist_node<AliasSet> {
146148
public:
147149
/// If the specified memory location "may" (or must) alias one of the members
148150
/// in the set return the appropriate AliasResult. Otherwise return NoAlias.
149-
AliasResult aliasesMemoryLocation(const MemoryLocation &MemLoc,
150-
BatchAAResults &AA) const;
151+
LLVM_ABI AliasResult aliasesMemoryLocation(const MemoryLocation &MemLoc,
152+
BatchAAResults &AA) const;
151153

152-
ModRefInfo aliasesUnknownInst(const Instruction *Inst,
153-
BatchAAResults &AA) const;
154+
LLVM_ABI ModRefInfo aliasesUnknownInst(const Instruction *Inst,
155+
BatchAAResults &AA) const;
154156
};
155157

156158
inline raw_ostream& operator<<(raw_ostream &OS, const AliasSet &AS) {
@@ -183,18 +185,20 @@ class AliasSetTracker {
183185
/// 3. If the instruction aliases multiple sets, merge the sets, and add
184186
/// the instruction to the result.
185187
///
186-
void add(const MemoryLocation &Loc);
187-
void add(LoadInst *LI);
188-
void add(StoreInst *SI);
189-
void add(VAArgInst *VAAI);
190-
void add(AnyMemSetInst *MSI);
191-
void add(AnyMemTransferInst *MTI);
192-
void add(Instruction *I); // Dispatch to one of the other add methods...
193-
void add(BasicBlock &BB); // Add all instructions in basic block
194-
void add(const AliasSetTracker &AST); // Add alias relations from another AST
195-
void addUnknown(Instruction *I);
196-
197-
void clear();
188+
LLVM_ABI void add(const MemoryLocation &Loc);
189+
LLVM_ABI void add(LoadInst *LI);
190+
LLVM_ABI void add(StoreInst *SI);
191+
LLVM_ABI void add(VAArgInst *VAAI);
192+
LLVM_ABI void add(AnyMemSetInst *MSI);
193+
LLVM_ABI void add(AnyMemTransferInst *MTI);
194+
LLVM_ABI void
195+
add(Instruction *I); // Dispatch to one of the other add methods...
196+
LLVM_ABI void add(BasicBlock &BB); // Add all instructions in basic block
197+
LLVM_ABI void
198+
add(const AliasSetTracker &AST); // Add alias relations from another AST
199+
LLVM_ABI void addUnknown(Instruction *I);
200+
201+
LLVM_ABI void clear();
198202

199203
/// Return the alias sets that are active.
200204
const ilist<AliasSet> &getAliasSets() const { return AliasSets; }
@@ -203,7 +207,7 @@ class AliasSetTracker {
203207
/// the memory location aliases two or more existing alias sets, will have
204208
/// the effect of merging those alias sets before the single resulting alias
205209
/// set is returned.
206-
AliasSet &getAliasSetFor(const MemoryLocation &MemLoc);
210+
LLVM_ABI AliasSet &getAliasSetFor(const MemoryLocation &MemLoc);
207211

208212
/// Return the underlying alias analysis object used by this tracker.
209213
BatchAAResults &getAliasAnalysis() const { return AA; }
@@ -217,8 +221,8 @@ class AliasSetTracker {
217221
iterator begin() { return AliasSets.begin(); }
218222
iterator end() { return AliasSets.end(); }
219223

220-
void print(raw_ostream &OS) const;
221-
void dump() const;
224+
LLVM_ABI void print(raw_ostream &OS) const;
225+
LLVM_ABI void dump() const;
222226

223227
private:
224228
friend class AliasSet;
@@ -270,8 +274,8 @@ class AliasSetsPrinterPass : public PassInfoMixin<AliasSetsPrinterPass> {
270274
raw_ostream &OS;
271275

272276
public:
273-
explicit AliasSetsPrinterPass(raw_ostream &OS);
274-
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
277+
LLVM_ABI explicit AliasSetsPrinterPass(raw_ostream &OS);
278+
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
275279
static bool isRequired() { return true; }
276280
};
277281

llvm/include/llvm/Analysis/AssumeBundleQueries.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "llvm/ADT/DenseMap.h"
1818
#include "llvm/IR/IntrinsicInst.h"
19+
#include "llvm/Support/Compiler.h"
1920

2021
namespace llvm {
2122
class AssumptionCache;
@@ -38,8 +39,9 @@ enum AssumeBundleArg {
3839
///
3940
/// Return true iff the queried attribute was found.
4041
/// If ArgVal is set. the argument will be stored to ArgVal.
41-
bool hasAttributeInAssume(AssumeInst &Assume, Value *IsOn, StringRef AttrName,
42-
uint64_t *ArgVal = nullptr);
42+
LLVM_ABI bool hasAttributeInAssume(AssumeInst &Assume, Value *IsOn,
43+
StringRef AttrName,
44+
uint64_t *ArgVal = nullptr);
4345
inline bool hasAttributeInAssume(AssumeInst &Assume, Value *IsOn,
4446
Attribute::AttrKind Kind,
4547
uint64_t *ArgVal = nullptr) {
@@ -86,7 +88,8 @@ using RetainedKnowledgeMap =
8688
/// many queries are going to be made on the same llvm.assume.
8789
/// String attributes are not inserted in the map.
8890
/// If the IR changes the map will be outdated.
89-
void fillMapFromAssume(AssumeInst &Assume, RetainedKnowledgeMap &Result);
91+
LLVM_ABI void fillMapFromAssume(AssumeInst &Assume,
92+
RetainedKnowledgeMap &Result);
9093

9194
/// Represent one information held inside an operand bundle of an llvm.assume.
9295
/// AttrKind is the property that holds.
@@ -120,8 +123,8 @@ struct RetainedKnowledge {
120123

121124
/// Retreive the information help by Assume on the operand at index Idx.
122125
/// Assume should be an llvm.assume and Idx should be in the operand bundle.
123-
RetainedKnowledge getKnowledgeFromOperandInAssume(AssumeInst &Assume,
124-
unsigned Idx);
126+
LLVM_ABI RetainedKnowledge getKnowledgeFromOperandInAssume(AssumeInst &Assume,
127+
unsigned Idx);
125128

126129
/// Retreive the information help by the Use U of an llvm.assume. the use should
127130
/// be in the operand bundle.
@@ -141,16 +144,16 @@ constexpr StringRef IgnoreBundleTag = "ignore";
141144
///
142145
/// the argument to the call of llvm.assume may still be useful even if the
143146
/// function returned true.
144-
bool isAssumeWithEmptyBundle(const AssumeInst &Assume);
147+
LLVM_ABI bool isAssumeWithEmptyBundle(const AssumeInst &Assume);
145148

146149
/// Return a valid Knowledge associated to the Use U if its Attribute kind is
147150
/// in AttrKinds.
148-
RetainedKnowledge getKnowledgeFromUse(const Use *U,
149-
ArrayRef<Attribute::AttrKind> AttrKinds);
151+
LLVM_ABI RetainedKnowledge
152+
getKnowledgeFromUse(const Use *U, ArrayRef<Attribute::AttrKind> AttrKinds);
150153

151154
/// Return a valid Knowledge associated to the Value V if its Attribute kind is
152155
/// in AttrKinds and it matches the Filter.
153-
RetainedKnowledge getKnowledgeForValue(
156+
LLVM_ABI RetainedKnowledge getKnowledgeForValue(
154157
const Value *V, ArrayRef<Attribute::AttrKind> AttrKinds,
155158
AssumptionCache &AC,
156159
function_ref<bool(RetainedKnowledge, Instruction *,
@@ -160,16 +163,15 @@ RetainedKnowledge getKnowledgeForValue(
160163
/// Return a valid Knowledge associated to the Value V if its Attribute kind is
161164
/// in AttrKinds and the knowledge is suitable to be used in the context of
162165
/// CtxI.
163-
RetainedKnowledge
164-
getKnowledgeValidInContext(const Value *V,
165-
ArrayRef<Attribute::AttrKind> AttrKinds,
166-
AssumptionCache &AC, const Instruction *CtxI,
167-
const DominatorTree *DT = nullptr);
166+
LLVM_ABI RetainedKnowledge getKnowledgeValidInContext(
167+
const Value *V, ArrayRef<Attribute::AttrKind> AttrKinds,
168+
AssumptionCache &AC, const Instruction *CtxI,
169+
const DominatorTree *DT = nullptr);
168170

169171
/// This extracts the Knowledge from an element of an operand bundle.
170172
/// This is mostly for use in the assume builder.
171-
RetainedKnowledge getKnowledgeFromBundle(AssumeInst &Assume,
172-
const CallBase::BundleOpInfo &BOI);
173+
LLVM_ABI RetainedKnowledge
174+
getKnowledgeFromBundle(AssumeInst &Assume, const CallBase::BundleOpInfo &BOI);
173175

174176
} // namespace llvm
175177

llvm/include/llvm/Analysis/AssumptionCache.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/IR/PassManager.h"
2323
#include "llvm/IR/ValueHandle.h"
2424
#include "llvm/Pass.h"
25+
#include "llvm/Support/Compiler.h"
2526
#include <memory>
2627

2728
namespace llvm {
@@ -66,7 +67,7 @@ class AssumptionCache {
6667
/// intrinsic.
6768
SmallVector<ResultElem, 4> AssumeHandles;
6869

69-
class AffectedValueCallbackVH final : public CallbackVH {
70+
class LLVM_ABI AffectedValueCallbackVH final : public CallbackVH {
7071
AssumptionCache *AC;
7172

7273
void deleted() override;
@@ -101,7 +102,7 @@ class AssumptionCache {
101102
bool Scanned = false;
102103

103104
/// Scan the function for assumptions and add them to the cache.
104-
void scanFunction();
105+
LLVM_ABI void scanFunction();
105106

106107
public:
107108
/// Construct an AssumptionCache from a function by scanning all of
@@ -120,15 +121,15 @@ class AssumptionCache {
120121
///
121122
/// The call passed in must be an instruction within this function and must
122123
/// not already be in the cache.
123-
void registerAssumption(AssumeInst *CI);
124+
LLVM_ABI void registerAssumption(AssumeInst *CI);
124125

125126
/// Remove an \@llvm.assume intrinsic from this function's cache if it has
126127
/// been added to the cache earlier.
127-
void unregisterAssumption(AssumeInst *CI);
128+
LLVM_ABI void unregisterAssumption(AssumeInst *CI);
128129

129130
/// Update the cache of values being affected by this assumption (i.e.
130131
/// the values about which this assumption provides information).
131-
void updateAffectedValues(AssumeInst *CI);
132+
LLVM_ABI void updateAffectedValues(AssumeInst *CI);
132133

133134
/// Clear the cache of \@llvm.assume intrinsics for a function.
134135
///
@@ -173,12 +174,12 @@ class AssumptionCache {
173174
class AssumptionAnalysis : public AnalysisInfoMixin<AssumptionAnalysis> {
174175
friend AnalysisInfoMixin<AssumptionAnalysis>;
175176

176-
static AnalysisKey Key;
177+
LLVM_ABI static AnalysisKey Key;
177178

178179
public:
179180
using Result = AssumptionCache;
180181

181-
AssumptionCache run(Function &F, FunctionAnalysisManager &);
182+
LLVM_ABI AssumptionCache run(Function &F, FunctionAnalysisManager &);
182183
};
183184

184185
/// Printer pass for the \c AssumptionAnalysis results.
@@ -188,7 +189,7 @@ class AssumptionPrinterPass : public PassInfoMixin<AssumptionPrinterPass> {
188189
public:
189190
explicit AssumptionPrinterPass(raw_ostream &OS) : OS(OS) {}
190191

191-
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
192+
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
192193

193194
static bool isRequired() { return true; }
194195
};
@@ -201,10 +202,10 @@ class AssumptionPrinterPass : public PassInfoMixin<AssumptionPrinterPass> {
201202
/// function is deleted. The nature of the AssumptionCache is that it is not
202203
/// invalidated by any changes to the function body and so this is sufficient
203204
/// to be conservatively correct.
204-
class AssumptionCacheTracker : public ImmutablePass {
205+
class LLVM_ABI AssumptionCacheTracker : public ImmutablePass {
205206
/// A callback value handle applied to function objects, which we use to
206207
/// delete our cache of intrinsics for a function when it is deleted.
207-
class FunctionCallbackVH final : public CallbackVH {
208+
class LLVM_ABI FunctionCallbackVH final : public CallbackVH {
208209
AssumptionCacheTracker *ACT;
209210

210211
void deleted() override;

llvm/include/llvm/Analysis/BasicAliasAnalysis.h

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/Analysis/AliasAnalysis.h"
1818
#include "llvm/IR/PassManager.h"
1919
#include "llvm/Pass.h"
20+
#include "llvm/Support/Compiler.h"
2021
#include <memory>
2122
#include <utility>
2223

@@ -65,17 +66,19 @@ class BasicAAResult : public AAResultBase {
6566
AC(Arg.AC), DT_(Arg.DT_) {}
6667

6768
/// Handle invalidation events in the new pass manager.
68-
bool invalidate(Function &Fn, const PreservedAnalyses &PA,
69-
FunctionAnalysisManager::Invalidator &Inv);
69+
LLVM_ABI bool invalidate(Function &Fn, const PreservedAnalyses &PA,
70+
FunctionAnalysisManager::Invalidator &Inv);
7071

71-
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
72-
AAQueryInfo &AAQI, const Instruction *CtxI);
72+
LLVM_ABI AliasResult alias(const MemoryLocation &LocA,
73+
const MemoryLocation &LocB, AAQueryInfo &AAQI,
74+
const Instruction *CtxI);
7375

74-
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
75-
AAQueryInfo &AAQI);
76+
LLVM_ABI ModRefInfo getModRefInfo(const CallBase *Call,
77+
const MemoryLocation &Loc,
78+
AAQueryInfo &AAQI);
7679

77-
ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
78-
AAQueryInfo &AAQI);
80+
LLVM_ABI ModRefInfo getModRefInfo(const CallBase *Call1,
81+
const CallBase *Call2, AAQueryInfo &AAQI);
7982

8083
/// Returns a bitmask that should be unconditionally applied to the ModRef
8184
/// info of a memory location. This allows us to eliminate Mod and/or Ref
@@ -84,18 +87,20 @@ class BasicAAResult : public AAResultBase {
8487
///
8588
/// If IgnoreLocals is true, then this method returns NoModRef for memory
8689
/// that points to a local alloca.
87-
ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI,
88-
bool IgnoreLocals = false);
90+
LLVM_ABI ModRefInfo getModRefInfoMask(const MemoryLocation &Loc,
91+
AAQueryInfo &AAQI,
92+
bool IgnoreLocals = false);
8993

9094
/// Get the location associated with a pointer argument of a callsite.
91-
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx);
95+
LLVM_ABI ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx);
9296

9397
/// Returns the behavior when calling the given call site.
94-
MemoryEffects getMemoryEffects(const CallBase *Call, AAQueryInfo &AAQI);
98+
LLVM_ABI MemoryEffects getMemoryEffects(const CallBase *Call,
99+
AAQueryInfo &AAQI);
95100

96101
/// Returns the behavior when calling the given function. For use when the
97102
/// call site is not known.
98-
MemoryEffects getMemoryEffects(const Function *Fn);
103+
LLVM_ABI MemoryEffects getMemoryEffects(const Function *Fn);
99104

100105
private:
101106
struct DecomposedGEP;
@@ -152,16 +157,16 @@ class BasicAAResult : public AAResultBase {
152157
class BasicAA : public AnalysisInfoMixin<BasicAA> {
153158
friend AnalysisInfoMixin<BasicAA>;
154159

155-
static AnalysisKey Key;
160+
LLVM_ABI static AnalysisKey Key;
156161

157162
public:
158163
using Result = BasicAAResult;
159164

160-
BasicAAResult run(Function &F, FunctionAnalysisManager &AM);
165+
LLVM_ABI BasicAAResult run(Function &F, FunctionAnalysisManager &AM);
161166
};
162167

163168
/// Legacy wrapper pass to provide the BasicAAResult object.
164-
class BasicAAWrapperPass : public FunctionPass {
169+
class LLVM_ABI BasicAAWrapperPass : public FunctionPass {
165170
std::unique_ptr<BasicAAResult> Result;
166171

167172
virtual void anchor();
@@ -178,7 +183,7 @@ class BasicAAWrapperPass : public FunctionPass {
178183
void getAnalysisUsage(AnalysisUsage &AU) const override;
179184
};
180185

181-
FunctionPass *createBasicAAWrapperPass();
186+
LLVM_ABI FunctionPass *createBasicAAWrapperPass();
182187

183188
} // end namespace llvm
184189

0 commit comments

Comments
 (0)