Skip to content

Commit 91777c9

Browse files
andrurogerzfschlimb
authored andcommitted
[llvm] annotate interfaces in llvm/Target for DLL export (llvm#143615)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/Target` 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). A sub-set 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 bulk of this change is manual additions of `LLVM_ABI` to `LLVMInitializeX` functions defined in .cpp files under llvm/lib/Target. Adding `LLVM_ABI` to the function implementation is required here because they do not `#include "llvm/Support/TargetSelect.h"`, which contains the declarations for this functions and was already updated with `LLVM_ABI` in a previous patch. I considered patching these files with `#include "llvm/Support/TargetSelect.h"` instead, but since TargetSelect.h is a large file with a bunch of preprocessor x-macro stuff in it I was concerned it would unnecessarily impact compile times. In addition, a number of unit tests under llvm/unittests/Target required additional dependencies to make them build correctly against the LLVM DLL on Windows using MSVC. ## 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 9314ba2 commit 91777c9

File tree

121 files changed

+322
-123
lines changed

Some content is hidden

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

121 files changed

+322
-123
lines changed

llvm/include/llvm/Target/CGPassBuilderOption.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define LLVM_TARGET_CGPASSBUILDEROPTION_H
1616

1717
#include "llvm/Support/CommandLine.h"
18+
#include "llvm/Support/Compiler.h"
1819
#include "llvm/Target/TargetOptions.h"
1920
#include <optional>
2021

@@ -82,7 +83,7 @@ struct CGPassBuilderOption {
8283
std::optional<bool> DebugifyCheckAndStripAll;
8384
};
8485

85-
CGPassBuilderOption getCGPassBuilderOption();
86+
LLVM_ABI CGPassBuilderOption getCGPassBuilderOption();
8687

8788
} // namespace llvm
8889

llvm/include/llvm/Target/TargetLoweringObjectFile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "llvm/MC/MCObjectFileInfo.h"
1818
#include "llvm/MC/MCRegister.h"
19+
#include "llvm/Support/Compiler.h"
1920
#include <cstdint>
2021

2122
namespace llvm {
@@ -43,7 +44,7 @@ class StringRef;
4344
class TargetMachine;
4445
class DSOLocalEquivalent;
4546

46-
class TargetLoweringObjectFile : public MCObjectFileInfo {
47+
class LLVM_ABI TargetLoweringObjectFile : public MCObjectFileInfo {
4748
/// Name-mangler for global names.
4849
Mangler *Mang = nullptr;
4950

llvm/include/llvm/Target/TargetMachine.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/Support/Allocator.h"
2020
#include "llvm/Support/CodeGen.h"
2121
#include "llvm/Support/CommandLine.h"
22+
#include "llvm/Support/Compiler.h"
2223
#include "llvm/Support/Error.h"
2324
#include "llvm/Support/PGOOptions.h"
2425
#include "llvm/Target/CGPassBuilderOption.h"
@@ -28,7 +29,7 @@
2829
#include <string>
2930
#include <utility>
3031

31-
extern llvm::cl::opt<bool> NoKernelInfoEndLTO;
32+
extern LLVM_ABI llvm::cl::opt<bool> NoKernelInfoEndLTO;
3233

3334
namespace llvm {
3435

@@ -78,7 +79,7 @@ struct MachineFunctionInfo;
7879
/// machine. All target-specific information should be accessible through this
7980
/// interface.
8081
///
81-
class TargetMachine {
82+
class LLVM_ABI TargetMachine {
8283
protected: // Can only create subclasses.
8384
TargetMachine(const Target &T, StringRef DataLayoutString,
8485
const Triple &TargetTriple, StringRef CPU, StringRef FS,

llvm/include/llvm/Target/TargetOptions.h

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

1717
#include "llvm/ADT/FloatingPointMode.h"
1818
#include "llvm/MC/MCTargetOptions.h"
19+
#include "llvm/Support/Compiler.h"
1920

2021
#include <memory>
2122

@@ -158,12 +159,12 @@ class TargetOptions {
158159

159160
/// DisableFramePointerElim - This returns true if frame pointer elimination
160161
/// optimization should be disabled for the given machine function.
161-
bool DisableFramePointerElim(const MachineFunction &MF) const;
162+
LLVM_ABI bool DisableFramePointerElim(const MachineFunction &MF) const;
162163

163164
/// FramePointerIsReserved - This returns true if the frame pointer must
164165
/// always either point to a new frame record or be un-modified in the given
165166
/// function.
166-
bool FramePointerIsReserved(const MachineFunction &MF) const;
167+
LLVM_ABI bool FramePointerIsReserved(const MachineFunction &MF) const;
167168

168169
/// If greater than 0, override the default value of
169170
/// MCAsmInfo::BinutilsVersion.
@@ -219,7 +220,7 @@ class TargetOptions {
219220
/// truncations). If this is enabled (set to true), the code generator must
220221
/// assume that the rounding mode may dynamically change.
221222
unsigned HonorSignDependentRoundingFPMathOption : 1;
222-
bool HonorSignDependentRoundingFPMath() const;
223+
LLVM_ABI bool HonorSignDependentRoundingFPMath() const;
223224

224225
/// NoZerosInBSS - By default some codegens place zero-initialized data to
225226
/// .bss section. This flag disables such behaviour (necessary, e.g. for
@@ -346,7 +347,7 @@ class TargetOptions {
346347
unsigned EnableDebugEntryValues : 1;
347348
/// NOTE: There are targets that still do not support the debug entry values
348349
/// production.
349-
bool ShouldEmitDebugEntryValues() const;
350+
LLVM_ABI bool ShouldEmitDebugEntryValues() const;
350351

351352
// When set to true, use experimental new debug variable location tracking,
352353
// which seeks to follow the values of variables rather than their location,
@@ -450,7 +451,7 @@ class TargetOptions {
450451

451452
DenormalMode getRawFP32DenormalMode() const { return FP32DenormalMode; }
452453

453-
DenormalMode getDenormalMode(const fltSemantics &FPType) const;
454+
LLVM_ABI DenormalMode getDenormalMode(const fltSemantics &FPType) const;
454455

455456
/// What exception model to use
456457
ExceptionHandling ExceptionModel = ExceptionHandling::None;

llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "llvm/MC/TargetRegistry.h"
5959
#include "llvm/Support/Casting.h"
6060
#include "llvm/Support/CommandLine.h"
61+
#include "llvm/Support/Compiler.h"
6162
#include "llvm/Support/ErrorHandling.h"
6263
#include "llvm/Support/raw_ostream.h"
6364
#include "llvm/Target/TargetMachine.h"
@@ -3534,7 +3535,8 @@ INITIALIZE_PASS(AArch64AsmPrinter, "aarch64-asm-printer",
35343535
"AArch64 Assembly Printer", false, false)
35353536

35363537
// Force static initialization.
3537-
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64AsmPrinter() {
3538+
extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
3539+
LLVMInitializeAArch64AsmPrinter() {
35383540
RegisterAsmPrinter<AArch64AsmPrinter> X(getTheAArch64leTarget());
35393541
RegisterAsmPrinter<AArch64AsmPrinter> Y(getTheAArch64beTarget());
35403542
RegisterAsmPrinter<AArch64AsmPrinter> Z(getTheARM64Target());

llvm/lib/Target/AArch64/AArch64TargetMachine.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "llvm/Passes/PassBuilder.h"
4545
#include "llvm/Support/CodeGen.h"
4646
#include "llvm/Support/CommandLine.h"
47+
#include "llvm/Support/Compiler.h"
4748
#include "llvm/Target/TargetLoweringObjectFile.h"
4849
#include "llvm/Target/TargetOptions.h"
4950
#include "llvm/TargetParser/Triple.h"
@@ -223,7 +224,8 @@ static cl::opt<bool>
223224
cl::desc("Enable Machine Pipeliner for AArch64"),
224225
cl::init(false), cl::Hidden);
225226

226-
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64Target() {
227+
extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
228+
LLVMInitializeAArch64Target() {
227229
// Register the target.
228230
RegisterTargetMachine<AArch64leTargetMachine> X(getTheAArch64leTarget());
229231
RegisterTargetMachine<AArch64beTargetMachine> Y(getTheAArch64beTarget());

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8322,7 +8322,8 @@ bool AArch64AsmParser::classifySymbolRef(const MCExpr *Expr,
83228322
}
83238323

83248324
/// Force static initialization.
8325-
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64AsmParser() {
8325+
extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
8326+
LLVMInitializeAArch64AsmParser() {
83268327
RegisterMCAsmParser<AArch64AsmParser> X(getTheAArch64leTarget());
83278328
RegisterMCAsmParser<AArch64AsmParser> Y(getTheAArch64beTarget());
83288329
RegisterMCAsmParser<AArch64AsmParser> Z(getTheARM64Target());

llvm/lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ createAArch64ExternalSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo,
310310
SymbolLookUp, DisInfo);
311311
}
312312

313-
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64Disassembler() {
313+
extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
314+
LLVMInitializeAArch64Disassembler() {
314315
TargetRegistry::RegisterMCDisassembler(getTheAArch64leTarget(),
315316
createAArch64Disassembler);
316317
TargetRegistry::RegisterMCDisassembler(getTheAArch64beTarget(),

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/MC/MCStreamer.h"
2828
#include "llvm/MC/MCSubtargetInfo.h"
2929
#include "llvm/MC/TargetRegistry.h"
30+
#include "llvm/Support/Compiler.h"
3031
#include "llvm/Support/Endian.h"
3132
#include "llvm/Support/ErrorHandling.h"
3233
#include "llvm/TargetParser/AArch64TargetParser.h"
@@ -503,7 +504,8 @@ static MCInstrAnalysis *createAArch64InstrAnalysis(const MCInstrInfo *Info) {
503504
}
504505

505506
// Force static initialization.
506-
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64TargetMC() {
507+
extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
508+
LLVMInitializeAArch64TargetMC() {
507509
for (Target *T : {&getTheAArch64leTarget(), &getTheAArch64beTarget(),
508510
&getTheAArch64_32Target(), &getTheARM64Target(),
509511
&getTheARM64_32Target()}) {

llvm/lib/Target/AArch64/TargetInfo/AArch64TargetInfo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "TargetInfo/AArch64TargetInfo.h"
1010
#include "llvm/MC/TargetRegistry.h"
11+
#include "llvm/Support/Compiler.h"
1112

1213
using namespace llvm;
1314
Target &llvm::getTheAArch64leTarget() {
@@ -31,7 +32,8 @@ Target &llvm::getTheARM64_32Target() {
3132
return TheARM64_32Target;
3233
}
3334

34-
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64TargetInfo() {
35+
extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
36+
LLVMInitializeAArch64TargetInfo() {
3537
// Now register the "arm64" name for use with "-march". We don't want it to
3638
// take possession of the Triple::aarch64 tags though.
3739
TargetRegistry::RegisterTarget(getTheARM64Target(), "arm64",

0 commit comments

Comments
 (0)