Skip to content

Commit ad0fba2

Browse files
authored
[llvm] annotate remaining CodeGen and CodeGenTypes library interfaces for DLL export (#145361)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the remaining LLVM CodeGen and CodeGenTypes library interfaces that were missed in, or modified since, previous patches. The 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). ## Overview 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: - Explicitly instantiate `CallLowering::setArgFlags` template method instances in `CodeGen/GlobalISel/CallLowering.h` and annotate them with `LLVM_ABI`. These methods are already explicitly instantiated in `lib/CodeGen/GlobalISel/CallLowering.cpp` but were not `extern` declared in the header. - Annotate several explicit template instantiations with `LLVM_EXPORT_TEMPLATE`. - Include `llvm/CodeGen/Passes.h` from `llvm/lib/CodeGen/GlobalMergeFunctions.cpp` to pick up the declaration of `llvm::createGlobalMergeFuncPass` with the `LLVM_ABI` annotation (instead of adding `LLVM_ABI` to the function definition in this file) ## 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 f8b906e commit ad0fba2

File tree

10 files changed

+80
-51
lines changed

10 files changed

+80
-51
lines changed

llvm/include/llvm/CodeGen/GlobalISel/CallLowering.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,15 @@ class LLVM_ABI CallLowering {
609609
virtual bool isTypeIsValidForThisReturn(EVT Ty) const { return false; }
610610
};
611611

612+
extern template LLVM_ABI void
613+
CallLowering::setArgFlags<Function>(CallLowering::ArgInfo &Arg, unsigned OpIdx,
614+
const DataLayout &DL,
615+
const Function &FuncInfo) const;
616+
617+
extern template LLVM_ABI void
618+
CallLowering::setArgFlags<CallBase>(CallLowering::ArgInfo &Arg, unsigned OpIdx,
619+
const DataLayout &DL,
620+
const CallBase &FuncInfo) const;
612621
} // end namespace llvm
613622

614623
#endif // LLVM_CODEGEN_GLOBALISEL_CALLLOWERING_H

llvm/include/llvm/CodeGenTypes/LowLevelType.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "llvm/ADT/DenseMapInfo.h"
3030
#include "llvm/CodeGenTypes/MachineValueType.h"
31+
#include "llvm/Support/Compiler.h"
3132
#include "llvm/Support/Debug.h"
3233
#include <cassert>
3334

@@ -140,7 +141,7 @@ class LLT {
140141
explicit constexpr LLT()
141142
: IsScalar(false), IsPointer(false), IsVector(false), RawData(0) {}
142143

143-
explicit LLT(MVT VT);
144+
LLVM_ABI explicit LLT(MVT VT);
144145

145146
constexpr bool isValid() const { return IsScalar || RawData != 0; }
146147
constexpr bool isScalar() const { return IsScalar; }
@@ -282,7 +283,7 @@ class LLT {
282283
return scalar(getScalarSizeInBits());
283284
}
284285

285-
void print(raw_ostream &OS) const;
286+
LLVM_ABI void print(raw_ostream &OS) const;
286287

287288
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
288289
LLVM_DUMP_METHOD void dump() const;

llvm/include/llvm/CodeGenTypes/MachineValueType.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define LLVM_CODEGEN_MACHINEVALUETYPE_H
1818

1919
#include "llvm/ADT/Sequence.h"
20+
#include "llvm/Support/Compiler.h"
2021
#include "llvm/Support/ErrorHandling.h"
2122
#include "llvm/Support/MathExtras.h"
2223
#include "llvm/Support/TypeSize.h"
@@ -65,10 +66,10 @@ namespace llvm {
6566
bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
6667

6768
/// Support for debugging, callable in GDB: VT.dump()
68-
void dump() const;
69+
LLVM_ABI void dump() const;
6970

7071
/// Implement operator<<.
71-
void print(raw_ostream &OS) const;
72+
LLVM_ABI void print(raw_ostream &OS) const;
7273

7374
/// Return true if this is a valid simple valuetype.
7475
bool isValid() const {
@@ -509,11 +510,11 @@ namespace llvm {
509510
/// otherwise they are invalid.
510511
/// NB: This includes pointer types, which require a DataLayout to convert
511512
/// to a concrete value type.
512-
static MVT getVT(Type *Ty, bool HandleUnknown = false);
513+
LLVM_ABI static MVT getVT(Type *Ty, bool HandleUnknown = false);
513514

514515
/// Returns an APFloat semantics tag appropriate for the value type. If this
515516
/// is a vector type, the element semantics are returned.
516-
const fltSemantics &getFltSemantics() const;
517+
LLVM_ABI const fltSemantics &getFltSemantics() const;
517518

518519
public:
519520
/// SimpleValueType Iteration

llvm/lib/CodeGen/GlobalMergeFunctions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/Analysis/ModuleSummaryAnalysis.h"
1616
#include "llvm/CGData/CodeGenData.h"
1717
#include "llvm/CGData/CodeGenDataWriter.h"
18+
#include "llvm/CodeGen/Passes.h"
1819
#include "llvm/IR/IRBuilder.h"
1920
#include "llvm/IR/StructuralHash.h"
2021
#include "llvm/InitializePasses.h"

llvm/lib/CodeGen/MachineDomTreeUpdater.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@
1414
#include "llvm/CodeGen/MachineDomTreeUpdater.h"
1515
#include "llvm/Analysis/GenericDomTreeUpdaterImpl.h"
1616
#include "llvm/CodeGen/MachinePostDominators.h"
17+
#include "llvm/Support/Compiler.h"
1718

1819
namespace llvm {
1920

20-
template class GenericDomTreeUpdater<
21+
template class LLVM_EXPORT_TEMPLATE GenericDomTreeUpdater<
2122
MachineDomTreeUpdater, MachineDominatorTree, MachinePostDominatorTree>;
2223

23-
template void
24+
template LLVM_EXPORT_TEMPLATE void
2425
GenericDomTreeUpdater<MachineDomTreeUpdater, MachineDominatorTree,
2526
MachinePostDominatorTree>::recalculate(MachineFunction
2627
&MF);
2728

28-
template void GenericDomTreeUpdater<
29+
template LLVM_EXPORT_TEMPLATE void GenericDomTreeUpdater<
2930
MachineDomTreeUpdater, MachineDominatorTree,
3031
MachinePostDominatorTree>::applyUpdatesImpl</*IsForward=*/true>();
31-
template void GenericDomTreeUpdater<
32+
template LLVM_EXPORT_TEMPLATE void GenericDomTreeUpdater<
3233
MachineDomTreeUpdater, MachineDominatorTree,
3334
MachinePostDominatorTree>::applyUpdatesImpl</*IsForward=*/false>();
3435

llvm/lib/CodeGen/MachineDominators.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/Pass.h"
1818
#include "llvm/PassRegistry.h"
1919
#include "llvm/Support/CommandLine.h"
20+
#include "llvm/Support/Compiler.h"
2021
#include "llvm/Support/GenericDomTreeConstruction.h"
2122

2223
using namespace llvm;
@@ -35,24 +36,29 @@ static cl::opt<bool, true> VerifyMachineDomInfoX(
3536
cl::desc("Verify machine dominator info (time consuming)"));
3637

3738
namespace llvm {
38-
template class DomTreeNodeBase<MachineBasicBlock>;
39-
template class DominatorTreeBase<MachineBasicBlock, false>; // DomTreeBase
39+
template class LLVM_EXPORT_TEMPLATE DomTreeNodeBase<MachineBasicBlock>;
40+
template class LLVM_EXPORT_TEMPLATE
41+
DominatorTreeBase<MachineBasicBlock, false>; // DomTreeBase
4042

4143
namespace DomTreeBuilder {
42-
template void Calculate<MBBDomTree>(MBBDomTree &DT);
43-
template void CalculateWithUpdates<MBBDomTree>(MBBDomTree &DT, MBBUpdates U);
44+
template LLVM_EXPORT_TEMPLATE void Calculate<MBBDomTree>(MBBDomTree &DT);
45+
template LLVM_EXPORT_TEMPLATE void
46+
CalculateWithUpdates<MBBDomTree>(MBBDomTree &DT, MBBUpdates U);
4447

45-
template void InsertEdge<MBBDomTree>(MBBDomTree &DT, MachineBasicBlock *From,
46-
MachineBasicBlock *To);
48+
template LLVM_EXPORT_TEMPLATE void
49+
InsertEdge<MBBDomTree>(MBBDomTree &DT, MachineBasicBlock *From,
50+
MachineBasicBlock *To);
4751

48-
template void DeleteEdge<MBBDomTree>(MBBDomTree &DT, MachineBasicBlock *From,
49-
MachineBasicBlock *To);
52+
template LLVM_EXPORT_TEMPLATE void
53+
DeleteEdge<MBBDomTree>(MBBDomTree &DT, MachineBasicBlock *From,
54+
MachineBasicBlock *To);
5055

51-
template void ApplyUpdates<MBBDomTree>(MBBDomTree &DT, MBBDomTreeGraphDiff &,
52-
MBBDomTreeGraphDiff *);
56+
template LLVM_EXPORT_TEMPLATE void
57+
ApplyUpdates<MBBDomTree>(MBBDomTree &DT, MBBDomTreeGraphDiff &,
58+
MBBDomTreeGraphDiff *);
5359

54-
template bool Verify<MBBDomTree>(const MBBDomTree &DT,
55-
MBBDomTree::VerificationLevel VL);
60+
template LLVM_EXPORT_TEMPLATE bool
61+
Verify<MBBDomTree>(const MBBDomTree &DT, MBBDomTree::VerificationLevel VL);
5662
} // namespace DomTreeBuilder
5763
}
5864

llvm/lib/CodeGen/MachineLoopInfo.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@
2222
#include "llvm/InitializePasses.h"
2323
#include "llvm/Pass.h"
2424
#include "llvm/PassRegistry.h"
25+
#include "llvm/Support/Compiler.h"
2526
#include "llvm/Support/GenericLoopInfoImpl.h"
2627

2728
using namespace llvm;
2829

2930
// Explicitly instantiate methods in LoopInfoImpl.h for MI-level Loops.
30-
template class llvm::LoopBase<MachineBasicBlock, MachineLoop>;
31-
template class llvm::LoopInfoBase<MachineBasicBlock, MachineLoop>;
31+
template class LLVM_EXPORT_TEMPLATE
32+
llvm::LoopBase<MachineBasicBlock, MachineLoop>;
33+
template class LLVM_EXPORT_TEMPLATE
34+
llvm::LoopInfoBase<MachineBasicBlock, MachineLoop>;
3235

3336
AnalysisKey MachineLoopAnalysis::Key;
3437

llvm/lib/CodeGen/MachinePassManager.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@
1717
#include "llvm/IR/Function.h"
1818
#include "llvm/IR/Module.h"
1919
#include "llvm/IR/PassManagerImpl.h"
20+
#include "llvm/Support/Compiler.h"
2021

2122
using namespace llvm;
2223

2324
AnalysisKey FunctionAnalysisManagerMachineFunctionProxy::Key;
2425

2526
namespace llvm {
26-
template class AnalysisManager<MachineFunction>;
27+
template class LLVM_EXPORT_TEMPLATE AnalysisManager<MachineFunction>;
2728
template class PassManager<MachineFunction>;
28-
template class InnerAnalysisManagerProxy<MachineFunctionAnalysisManager,
29-
Module>;
30-
template class InnerAnalysisManagerProxy<MachineFunctionAnalysisManager,
31-
Function>;
32-
template class OuterAnalysisManagerProxy<ModuleAnalysisManager,
33-
MachineFunction>;
29+
template class LLVM_EXPORT_TEMPLATE
30+
InnerAnalysisManagerProxy<MachineFunctionAnalysisManager, Module>;
31+
template class LLVM_EXPORT_TEMPLATE
32+
InnerAnalysisManagerProxy<MachineFunctionAnalysisManager, Function>;
33+
template class LLVM_EXPORT_TEMPLATE
34+
OuterAnalysisManagerProxy<ModuleAnalysisManager, MachineFunction>;
3435
} // namespace llvm
3536

3637
bool FunctionAnalysisManagerMachineFunctionProxy::Result::invalidate(

llvm/lib/CodeGen/MachinePostDominators.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,25 @@
1818
using namespace llvm;
1919

2020
namespace llvm {
21-
template class DominatorTreeBase<MachineBasicBlock, true>; // PostDomTreeBase
21+
template class LLVM_EXPORT_TEMPLATE
22+
DominatorTreeBase<MachineBasicBlock, true>; // PostDomTreeBase
2223

2324
namespace DomTreeBuilder {
2425

25-
template void Calculate<MBBPostDomTree>(MBBPostDomTree &DT);
26-
template void InsertEdge<MBBPostDomTree>(MBBPostDomTree &DT,
27-
MachineBasicBlock *From,
28-
MachineBasicBlock *To);
29-
template void DeleteEdge<MBBPostDomTree>(MBBPostDomTree &DT,
30-
MachineBasicBlock *From,
31-
MachineBasicBlock *To);
32-
template void ApplyUpdates<MBBPostDomTree>(MBBPostDomTree &DT,
33-
MBBPostDomTreeGraphDiff &,
34-
MBBPostDomTreeGraphDiff *);
35-
template bool Verify<MBBPostDomTree>(const MBBPostDomTree &DT,
36-
MBBPostDomTree::VerificationLevel VL);
26+
template LLVM_EXPORT_TEMPLATE void
27+
Calculate<MBBPostDomTree>(MBBPostDomTree &DT);
28+
template LLVM_EXPORT_TEMPLATE void
29+
InsertEdge<MBBPostDomTree>(MBBPostDomTree &DT, MachineBasicBlock *From,
30+
MachineBasicBlock *To);
31+
template LLVM_EXPORT_TEMPLATE void
32+
DeleteEdge<MBBPostDomTree>(MBBPostDomTree &DT, MachineBasicBlock *From,
33+
MachineBasicBlock *To);
34+
template LLVM_EXPORT_TEMPLATE void
35+
ApplyUpdates<MBBPostDomTree>(MBBPostDomTree &DT, MBBPostDomTreeGraphDiff &,
36+
MBBPostDomTreeGraphDiff *);
37+
template LLVM_EXPORT_TEMPLATE bool
38+
Verify<MBBPostDomTree>(const MBBPostDomTree &DT,
39+
MBBPostDomTree::VerificationLevel VL);
3740

3841
} // namespace DomTreeBuilder
3942
extern bool VerifyMachineDomInfo;

llvm/lib/CodeGen/RegAllocScore.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323
#include "llvm/Support/CommandLine.h"
2424

2525
using namespace llvm;
26-
cl::opt<double> CopyWeight("regalloc-copy-weight", cl::init(0.2), cl::Hidden);
27-
cl::opt<double> LoadWeight("regalloc-load-weight", cl::init(4.0), cl::Hidden);
28-
cl::opt<double> StoreWeight("regalloc-store-weight", cl::init(1.0), cl::Hidden);
29-
cl::opt<double> CheapRematWeight("regalloc-cheap-remat-weight", cl::init(0.2),
30-
cl::Hidden);
31-
cl::opt<double> ExpensiveRematWeight("regalloc-expensive-remat-weight",
32-
cl::init(1.0), cl::Hidden);
26+
LLVM_ABI cl::opt<double> CopyWeight("regalloc-copy-weight", cl::init(0.2),
27+
cl::Hidden);
28+
LLVM_ABI cl::opt<double> LoadWeight("regalloc-load-weight", cl::init(4.0),
29+
cl::Hidden);
30+
LLVM_ABI cl::opt<double> StoreWeight("regalloc-store-weight", cl::init(1.0),
31+
cl::Hidden);
32+
LLVM_ABI cl::opt<double> CheapRematWeight("regalloc-cheap-remat-weight",
33+
cl::init(0.2), cl::Hidden);
34+
LLVM_ABI cl::opt<double> ExpensiveRematWeight("regalloc-expensive-remat-weight",
35+
cl::init(1.0), cl::Hidden);
3336
#define DEBUG_TYPE "regalloc-score"
3437

3538
RegAllocScore &RegAllocScore::operator+=(const RegAllocScore &Other) {

0 commit comments

Comments
 (0)