Skip to content

Commit b2584e0

Browse files
authored
[llvm] annotate interfaces in llvm/Transforms for DLL export (llvm#143413)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/Transforms` 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: - Removed a redundant `operator<<` from Attributor.h. IDS only auto-annotates the 1st declaration, and the 2nd declaration being un-annotated resulted in an "inconsistent linkage" error on Windows when building LLVM as a DLL. - `#include` the `VirtualFileSystem.h` in PGOInstrumentation.h and remove the local declaration of the `vfs::FileSystem` class. This is required because exporting the `PGOInstrumentationUse` constructor requires the class be fully defined because it is used by an argument. - 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. ## 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 3cb104e commit b2584e0

File tree

110 files changed

+2094
-1753
lines changed

Some content is hidden

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

110 files changed

+2094
-1753
lines changed

llvm/include/llvm/Transforms/Coroutines/ABI.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define LLVM_TRANSFORMS_COROUTINES_ABI_H
1717

1818
#include "llvm/Analysis/TargetTransformInfo.h"
19+
#include "llvm/Support/Compiler.h"
1920
#include "llvm/Transforms/Coroutines/CoroShape.h"
2021
#include "llvm/Transforms/Coroutines/MaterializationUtils.h"
2122
#include "llvm/Transforms/Coroutines/SuspendCrossingInfo.h"
@@ -37,7 +38,7 @@ namespace coro {
3738
// index of an ABI generator for the custom ABI object in a SmallVector passed
3839
// to CoroSplitPass ctor.
3940

40-
class BaseABI {
41+
class LLVM_ABI BaseABI {
4142
public:
4243
BaseABI(Function &F, coro::Shape &S,
4344
std::function<bool(Instruction &)> IsMaterializable)
@@ -63,7 +64,7 @@ class BaseABI {
6364
std::function<bool(Instruction &I)> IsMaterializable;
6465
};
6566

66-
class SwitchABI : public BaseABI {
67+
class LLVM_ABI SwitchABI : public BaseABI {
6768
public:
6869
SwitchABI(Function &F, coro::Shape &S,
6970
std::function<bool(Instruction &)> IsMaterializable)
@@ -76,7 +77,7 @@ class SwitchABI : public BaseABI {
7677
TargetTransformInfo &TTI) override;
7778
};
7879

79-
class AsyncABI : public BaseABI {
80+
class LLVM_ABI AsyncABI : public BaseABI {
8081
public:
8182
AsyncABI(Function &F, coro::Shape &S,
8283
std::function<bool(Instruction &)> IsMaterializable)
@@ -89,7 +90,7 @@ class AsyncABI : public BaseABI {
8990
TargetTransformInfo &TTI) override;
9091
};
9192

92-
class AnyRetconABI : public BaseABI {
93+
class LLVM_ABI AnyRetconABI : public BaseABI {
9394
public:
9495
AnyRetconABI(Function &F, coro::Shape &S,
9596
std::function<bool(Instruction &)> IsMaterializable)

llvm/include/llvm/Transforms/Coroutines/CoroInstr.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "llvm/IR/GlobalVariable.h"
2929
#include "llvm/IR/IntrinsicInst.h"
30+
#include "llvm/Support/Compiler.h"
3031
#include "llvm/Support/raw_ostream.h"
3132

3233
namespace llvm {
@@ -237,7 +238,7 @@ class AnyCoroIdRetconInst : public AnyCoroIdInst {
237238
enum { SizeArg, AlignArg, StorageArg, PrototypeArg, AllocArg, DeallocArg };
238239

239240
public:
240-
void checkWellFormed() const;
241+
LLVM_ABI void checkWellFormed() const;
241242

242243
uint64_t getStorageSize() const {
243244
return cast<ConstantInt>(getArgOperand(SizeArg))->getZExtValue();
@@ -306,7 +307,7 @@ class CoroIdAsyncInst : public AnyCoroIdInst {
306307
enum { SizeArg, AlignArg, StorageArg, AsyncFuncPtrArg };
307308

308309
public:
309-
void checkWellFormed() const;
310+
LLVM_ABI void checkWellFormed() const;
310311

311312
/// The initial async function context size. The fields of which are reserved
312313
/// for use by the frontend. The frame will be allocated as a tail of this
@@ -568,7 +569,7 @@ class CoroSuspendAsyncInst : public AnyCoroSuspendInst {
568569
MustTailCallFuncArg
569570
};
570571

571-
void checkWellFormed() const;
572+
LLVM_ABI void checkWellFormed() const;
572573

573574
unsigned getStorageArgumentIndex() const {
574575
auto *Arg = cast<ConstantInt>(getArgOperand(StorageArgNoArg));
@@ -722,7 +723,7 @@ class CoroAsyncEndInst : public AnyCoroEndInst {
722723
enum { FrameArg, UnwindArg, MustTailCallFuncArg };
723724

724725
public:
725-
void checkWellFormed() const;
726+
LLVM_ABI void checkWellFormed() const;
726727

727728
Function *getMustTailCallFunction() const {
728729
if (arg_size() < 3)

llvm/include/llvm/Transforms/Coroutines/CoroShape.h

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

1515
#include "llvm/IR/IRBuilder.h"
1616
#include "llvm/IR/PassManager.h"
17+
#include "llvm/Support/Compiler.h"
1718
#include "llvm/Transforms/Coroutines/CoroInstr.h"
1819

1920
namespace llvm {
@@ -78,18 +79,20 @@ struct Shape {
7879
}
7980

8081
// Scan the function and collect the above intrinsics for later processing
81-
void analyze(Function &F, SmallVectorImpl<CoroFrameInst *> &CoroFrames,
82-
SmallVectorImpl<CoroSaveInst *> &UnusedCoroSaves,
83-
CoroPromiseInst *&CoroPromise);
82+
LLVM_ABI void analyze(Function &F,
83+
SmallVectorImpl<CoroFrameInst *> &CoroFrames,
84+
SmallVectorImpl<CoroSaveInst *> &UnusedCoroSaves,
85+
CoroPromiseInst *&CoroPromise);
8486
// If for some reason, we were not able to find coro.begin, bailout.
85-
void invalidateCoroutine(Function &F,
86-
SmallVectorImpl<CoroFrameInst *> &CoroFrames);
87+
LLVM_ABI void
88+
invalidateCoroutine(Function &F,
89+
SmallVectorImpl<CoroFrameInst *> &CoroFrames);
8790
// Perform ABI related initial transformation
88-
void initABI();
91+
LLVM_ABI void initABI();
8992
// Remove orphaned and unnecessary intrinsics
90-
void cleanCoroutine(SmallVectorImpl<CoroFrameInst *> &CoroFrames,
91-
SmallVectorImpl<CoroSaveInst *> &UnusedCoroSaves,
92-
CoroPromiseInst *CoroPromise);
93+
LLVM_ABI void cleanCoroutine(SmallVectorImpl<CoroFrameInst *> &CoroFrames,
94+
SmallVectorImpl<CoroSaveInst *> &UnusedCoroSaves,
95+
CoroPromiseInst *CoroPromise);
9396

9497
// Field indexes for special fields in the switch lowering.
9598
struct SwitchFieldIndex {
@@ -256,12 +259,14 @@ struct Shape {
256259
/// Allocate memory according to the rules of the active lowering.
257260
///
258261
/// \param CG - if non-null, will be updated for the new call
259-
Value *emitAlloc(IRBuilder<> &Builder, Value *Size, CallGraph *CG) const;
262+
LLVM_ABI Value *emitAlloc(IRBuilder<> &Builder, Value *Size,
263+
CallGraph *CG) const;
260264

261265
/// Deallocate memory according to the rules of the active lowering.
262266
///
263267
/// \param CG - if non-null, will be updated for the new call
264-
void emitDealloc(IRBuilder<> &Builder, Value *Ptr, CallGraph *CG) const;
268+
LLVM_ABI void emitDealloc(IRBuilder<> &Builder, Value *Ptr,
269+
CallGraph *CG) const;
265270

266271
Shape() = default;
267272
explicit Shape(Function &F) {

llvm/include/llvm/Transforms/Coroutines/CoroSplit.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/Analysis/CGSCCPassManager.h"
1919
#include "llvm/Analysis/LazyCallGraph.h"
2020
#include "llvm/IR/PassManager.h"
21+
#include "llvm/Support/Compiler.h"
2122
#include "llvm/Transforms/Coroutines/ABI.h"
2223

2324
namespace llvm {
@@ -31,20 +32,23 @@ struct CoroSplitPass : PassInfoMixin<CoroSplitPass> {
3132
using BaseABITy =
3233
std::function<std::unique_ptr<coro::BaseABI>(Function &, coro::Shape &)>;
3334

34-
CoroSplitPass(bool OptimizeFrame = false);
35+
LLVM_ABI CoroSplitPass(bool OptimizeFrame = false);
3536

36-
CoroSplitPass(SmallVector<BaseABITy> GenCustomABIs,
37-
bool OptimizeFrame = false);
37+
LLVM_ABI CoroSplitPass(SmallVector<BaseABITy> GenCustomABIs,
38+
bool OptimizeFrame = false);
3839

40+
LLVM_ABI
3941
CoroSplitPass(std::function<bool(Instruction &)> MaterializableCallback,
4042
bool OptimizeFrame = false);
4143

44+
LLVM_ABI
4245
CoroSplitPass(std::function<bool(Instruction &)> MaterializableCallback,
4346
SmallVector<BaseABITy> GenCustomABIs,
4447
bool OptimizeFrame = false);
4548

46-
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM,
47-
LazyCallGraph &CG, CGSCCUpdateResult &UR);
49+
LLVM_ABI PreservedAnalyses run(LazyCallGraph::SCC &C,
50+
CGSCCAnalysisManager &AM, LazyCallGraph &CG,
51+
CGSCCUpdateResult &UR);
4852

4953
static bool isRequired() { return true; }
5054

llvm/include/llvm/Transforms/Coroutines/MaterializationUtils.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "llvm/Support/Compiler.h"
910
#include "llvm/Transforms/Coroutines/SuspendCrossingInfo.h"
1011

1112
#ifndef LLVM_TRANSFORMS_COROUTINES_MATERIALIZATIONUTILS_H
@@ -16,11 +17,12 @@ namespace llvm {
1617
namespace coro {
1718

1819
// True if I is trivially rematerialzable, e.g. InsertElementInst
19-
bool isTriviallyMaterializable(Instruction &I);
20+
LLVM_ABI bool isTriviallyMaterializable(Instruction &I);
2021

2122
// Performs rematerialization, invoked from buildCoroutineFrame.
22-
void doRematerializations(Function &F, SuspendCrossingInfo &Checker,
23-
std::function<bool(Instruction &)> IsMaterializable);
23+
LLVM_ABI void
24+
doRematerializations(Function &F, SuspendCrossingInfo &Checker,
25+
std::function<bool(Instruction &)> IsMaterializable);
2426

2527
} // namespace coro
2628

llvm/include/llvm/Transforms/Coroutines/SuspendCrossingInfo.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/IR/BasicBlock.h"
2222
#include "llvm/IR/Function.h"
2323
#include "llvm/IR/Instruction.h"
24+
#include "llvm/Support/Compiler.h"
2425
#include "llvm/Transforms/Coroutines/CoroInstr.h"
2526

2627
namespace llvm {
@@ -102,19 +103,21 @@ class SuspendCrossingInfo {
102103
ModuleSlotTracker &MST) const;
103104
#endif
104105

106+
LLVM_ABI
105107
SuspendCrossingInfo(Function &F,
106108
const SmallVectorImpl<AnyCoroSuspendInst *> &CoroSuspends,
107109
const SmallVectorImpl<AnyCoroEndInst *> &CoroEnds);
108110

109111
/// Returns true if there is a path from \p From to \p To crossing a suspend
110112
/// point without crossing \p From a 2nd time.
111-
bool hasPathCrossingSuspendPoint(BasicBlock *From, BasicBlock *To) const;
113+
LLVM_ABI bool hasPathCrossingSuspendPoint(BasicBlock *From,
114+
BasicBlock *To) const;
112115

113116
/// Returns true if there is a path from \p From to \p To crossing a suspend
114117
/// point without crossing \p From a 2nd time. If \p From is the same as \p To
115118
/// this will also check if there is a looping path crossing a suspend point.
116-
bool hasPathOrLoopCrossingSuspendPoint(BasicBlock *From,
117-
BasicBlock *To) const;
119+
LLVM_ABI bool hasPathOrLoopCrossingSuspendPoint(BasicBlock *From,
120+
BasicBlock *To) const;
118121

119122
bool isDefinitionAcrossSuspend(BasicBlock *DefBB, User *U) const {
120123
auto *I = cast<Instruction>(U);

llvm/include/llvm/Transforms/HipStdPar/HipStdPar.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define LLVM_TRANSFORMS_HIPSTDPAR_HIPSTDPAR_H
2020

2121
#include "llvm/IR/PassManager.h"
22+
#include "llvm/Support/Compiler.h"
2223

2324
namespace llvm {
2425

@@ -27,15 +28,15 @@ class Module;
2728
class HipStdParAcceleratorCodeSelectionPass
2829
: public PassInfoMixin<HipStdParAcceleratorCodeSelectionPass> {
2930
public:
30-
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
31+
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
3132

3233
static bool isRequired() { return true; }
3334
};
3435

3536
class HipStdParAllocationInterpositionPass
3637
: public PassInfoMixin<HipStdParAllocationInterpositionPass> {
3738
public:
38-
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
39+
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
3940

4041
static bool isRequired() { return true; }
4142
};

llvm/include/llvm/Transforms/IPO.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@ class raw_ostream;
2424
/// createDeadArgEliminationPass - This pass removes arguments from functions
2525
/// which are not used by the body of the function.
2626
///
27-
ModulePass *createDeadArgEliminationPass();
27+
LLVM_ABI ModulePass *createDeadArgEliminationPass();
2828

2929
/// DeadArgHacking pass - Same as DAE, but delete arguments of external
3030
/// functions as well. This is definitely not safe, and should only be used by
3131
/// bugpoint.
32-
ModulePass *createDeadArgHackingPass();
32+
LLVM_ABI ModulePass *createDeadArgHackingPass();
3333

3434
//===----------------------------------------------------------------------===//
3535
//
3636
/// createLoopExtractorPass - This pass extracts all natural loops from the
3737
/// program into a function if it can.
3838
///
39-
Pass *createLoopExtractorPass();
39+
LLVM_ABI Pass *createLoopExtractorPass();
4040

4141
/// createSingleLoopExtractorPass - This pass extracts one natural loop from the
4242
/// program into a function if it can. This is used by bugpoint.
4343
///
44-
Pass *createSingleLoopExtractorPass();
44+
LLVM_ABI Pass *createSingleLoopExtractorPass();
4545

4646
//===----------------------------------------------------------------------===//
4747
/// createBarrierNoopPass - This pass is purely a module pass barrier in a pass
4848
/// manager.
49-
ModulePass *createBarrierNoopPass();
49+
LLVM_ABI ModulePass *createBarrierNoopPass();
5050

5151
/// What to do with the summary when running passes that operate on it.
5252
enum class PassSummaryAction {

llvm/include/llvm/Transforms/IPO/AlwaysInliner.h

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

1717
#include "llvm/IR/PassManager.h"
18+
#include "llvm/Support/Compiler.h"
1819

1920
namespace llvm {
2021

@@ -36,14 +37,13 @@ class AlwaysInlinerPass : public PassInfoMixin<AlwaysInlinerPass> {
3637
AlwaysInlinerPass(bool InsertLifetime = true)
3738
: InsertLifetime(InsertLifetime) {}
3839

39-
PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
40+
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
4041
static bool isRequired() { return true; }
4142
};
4243

4344
/// Create a legacy pass manager instance of a pass to inline and remove
4445
/// functions marked as "always_inline".
45-
Pass *createAlwaysInlinerLegacyPass(bool InsertLifetime = true);
46-
46+
LLVM_ABI Pass *createAlwaysInlinerLegacyPass(bool InsertLifetime = true);
4747
}
4848

4949
#endif // LLVM_TRANSFORMS_IPO_ALWAYSINLINER_H

0 commit comments

Comments
 (0)