Skip to content

Commit d94846a

Browse files
authored
[llvm] annotate interfaces in llvm/MC and llvm/MCA for DLL export (#142655)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/MC` and `llvm/MCA` 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 #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. - Explicitly make classes non-copyable where needed to due IDS adding LLVM_ABI at the class level ## 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 ecbe2e8 commit d94846a

Some content is hidden

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

56 files changed

+600
-488
lines changed

llvm/include/llvm/MC/MCAsmBackend.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "llvm/ADT/ArrayRef.h"
1313
#include "llvm/MC/MCDirectives.h"
1414
#include "llvm/MC/MCFixup.h"
15+
#include "llvm/Support/Compiler.h"
1516
#include "llvm/Support/Endian.h"
1617
#include <cstdint>
1718

@@ -39,7 +40,7 @@ class StringRef;
3940
class raw_ostream;
4041

4142
/// Generic interface to target specific assembler backends.
42-
class MCAsmBackend {
43+
class LLVM_ABI MCAsmBackend {
4344
protected: // Can only create subclasses.
4445
MCAsmBackend(llvm::endianness Endian) : Endian(Endian) {}
4546

llvm/include/llvm/MC/MCAsmInfo.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/StringRef.h"
2121
#include "llvm/MC/MCDirectives.h"
2222
#include "llvm/MC/MCTargetOptions.h"
23+
#include "llvm/Support/Compiler.h"
2324
#include <vector>
2425

2526
namespace llvm {
@@ -55,7 +56,7 @@ enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };
5556

5657
/// This class is intended to be used as a base class for asm
5758
/// properties and features specific to the target.
58-
class MCAsmInfo {
59+
class LLVM_ABI MCAsmInfo {
5960
public:
6061
/// Assembly character literal syntax types.
6162
enum AsmCharLiteralSyntax {
@@ -427,6 +428,10 @@ class MCAsmInfo {
427428
explicit MCAsmInfo();
428429
virtual ~MCAsmInfo();
429430

431+
// Explicitly non-copyable.
432+
MCAsmInfo(MCAsmInfo const &) = delete;
433+
MCAsmInfo &operator=(MCAsmInfo const &) = delete;
434+
430435
/// Get the code pointer size in bytes.
431436
unsigned getCodePointerSize() const { return CodePointerSize; }
432437

llvm/include/llvm/MC/MCAsmMacro.h

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

1212
#include "llvm/ADT/APInt.h"
1313
#include "llvm/ADT/StringRef.h"
14+
#include "llvm/Support/Compiler.h"
1415
#include "llvm/Support/Debug.h"
1516
#include "llvm/Support/SMLoc.h"
1617
#include <vector>
@@ -74,9 +75,9 @@ class AsmToken {
7475
bool is(TokenKind K) const { return Kind == K; }
7576
bool isNot(TokenKind K) const { return Kind != K; }
7677

77-
SMLoc getLoc() const;
78-
SMLoc getEndLoc() const;
79-
SMRange getLocRange() const;
78+
LLVM_ABI SMLoc getLoc() const;
79+
LLVM_ABI SMLoc getEndLoc() const;
80+
LLVM_ABI SMRange getLocRange() const;
8081

8182
/// Get the contents of a string token (without quotes).
8283
StringRef getStringContents() const {
@@ -115,7 +116,7 @@ class AsmToken {
115116
return IntVal;
116117
}
117118

118-
void dump(raw_ostream &OS) const;
119+
LLVM_ABI void dump(raw_ostream &OS) const;
119120
};
120121

121122
struct MCAsmMacroParameter {

llvm/include/llvm/MC/MCAssembler.h

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/ADT/iterator_range.h"
1818
#include "llvm/MC/MCDwarf.h"
1919
#include "llvm/MC/MCSymbol.h"
20+
#include "llvm/Support/Compiler.h"
2021
#include "llvm/Support/SMLoc.h"
2122
#include <algorithm>
2223
#include <cassert>
@@ -135,46 +136,48 @@ class MCAssembler {
135136
// concrete and require clients to pass in a target like object. The other
136137
// option is to make this abstract, and have targets provide concrete
137138
// implementations as we do with AsmParser.
138-
MCAssembler(MCContext &Context, std::unique_ptr<MCAsmBackend> Backend,
139-
std::unique_ptr<MCCodeEmitter> Emitter,
140-
std::unique_ptr<MCObjectWriter> Writer);
139+
LLVM_ABI MCAssembler(MCContext &Context,
140+
std::unique_ptr<MCAsmBackend> Backend,
141+
std::unique_ptr<MCCodeEmitter> Emitter,
142+
std::unique_ptr<MCObjectWriter> Writer);
141143
MCAssembler(const MCAssembler &) = delete;
142144
MCAssembler &operator=(const MCAssembler &) = delete;
143145

144146
/// Compute the effective fragment size.
145-
uint64_t computeFragmentSize(const MCFragment &F) const;
147+
LLVM_ABI uint64_t computeFragmentSize(const MCFragment &F) const;
146148

147-
void layoutBundle(MCFragment *Prev, MCFragment *F) const;
149+
LLVM_ABI void layoutBundle(MCFragment *Prev, MCFragment *F) const;
148150

149151
// Get the offset of the given fragment inside its containing section.
150152
uint64_t getFragmentOffset(const MCFragment &F) const { return F.Offset; }
151153

152-
uint64_t getSectionAddressSize(const MCSection &Sec) const;
153-
uint64_t getSectionFileSize(const MCSection &Sec) const;
154+
LLVM_ABI uint64_t getSectionAddressSize(const MCSection &Sec) const;
155+
LLVM_ABI uint64_t getSectionFileSize(const MCSection &Sec) const;
154156

155157
// Get the offset of the given symbol, as computed in the current
156158
// layout.
157159
// \return True on success.
158-
bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const;
160+
LLVM_ABI bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const;
159161

160162
// Variant that reports a fatal error if the offset is not computable.
161-
uint64_t getSymbolOffset(const MCSymbol &S) const;
163+
LLVM_ABI uint64_t getSymbolOffset(const MCSymbol &S) const;
162164

163165
// If this symbol is equivalent to A + Constant, return A.
164-
const MCSymbol *getBaseSymbol(const MCSymbol &Symbol) const;
166+
LLVM_ABI const MCSymbol *getBaseSymbol(const MCSymbol &Symbol) const;
165167

166168
/// Emit the section contents to \p OS.
167-
void writeSectionData(raw_ostream &OS, const MCSection *Section) const;
169+
LLVM_ABI void writeSectionData(raw_ostream &OS,
170+
const MCSection *Section) const;
168171

169172
/// Check whether a given symbol has been flagged with .thumb_func.
170-
bool isThumbFunc(const MCSymbol *Func) const;
173+
LLVM_ABI bool isThumbFunc(const MCSymbol *Func) const;
171174

172175
/// Flag a function symbol as the target of a .thumb_func directive.
173176
void setIsThumbFunc(const MCSymbol *Func) { ThumbFuncs.insert(Func); }
174177

175178
/// Reuse an assembler instance
176179
///
177-
void reset();
180+
LLVM_ABI void reset();
178181

179182
MCContext &getContext() const { return Context; }
180183

@@ -193,10 +196,10 @@ class MCAssembler {
193196
/// Finish - Do final processing and write the object to the output stream.
194197
/// \p Writer is used for custom object writer (as the MCJIT does),
195198
/// if not specified it is automatically created from backend.
196-
void Finish();
199+
LLVM_ABI void Finish();
197200

198201
// Layout all section and prepare them for emission.
199-
void layout();
202+
LLVM_ABI void layout();
200203

201204
bool hasLayout() const { return HasLayout; }
202205
bool hasFinalLayout() const { return HasFinalLayout; }
@@ -223,21 +226,22 @@ class MCAssembler {
223226
return make_pointee_range(Symbols);
224227
}
225228

226-
bool registerSection(MCSection &Section);
227-
bool registerSymbol(const MCSymbol &Symbol);
229+
LLVM_ABI bool registerSection(MCSection &Section);
230+
LLVM_ABI bool registerSymbol(const MCSymbol &Symbol);
228231

229232
/// Write the necessary bundle padding to \p OS.
230233
/// Expects a fragment \p F containing instructions and its size \p FSize.
231-
void writeFragmentPadding(raw_ostream &OS, const MCEncodedFragment &F,
232-
uint64_t FSize) const;
234+
LLVM_ABI void writeFragmentPadding(raw_ostream &OS,
235+
const MCEncodedFragment &F,
236+
uint64_t FSize) const;
233237

234-
void reportError(SMLoc L, const Twine &Msg) const;
238+
LLVM_ABI void reportError(SMLoc L, const Twine &Msg) const;
235239
// Record pending errors during layout iteration, as they may go away once the
236240
// layout is finalized.
237-
void recordError(SMLoc L, const Twine &Msg) const;
238-
void flushPendingErrors() const;
241+
LLVM_ABI void recordError(SMLoc L, const Twine &Msg) const;
242+
LLVM_ABI void flushPendingErrors() const;
239243

240-
void dump() const;
244+
LLVM_ABI void dump() const;
241245
};
242246

243247
} // end namespace llvm

llvm/include/llvm/MC/MCCodeEmitter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef LLVM_MC_MCCODEEMITTER_H
1010
#define LLVM_MC_MCCODEEMITTER_H
1111

12+
#include "llvm/Support/Compiler.h"
13+
1214
namespace llvm {
1315

1416
class MCFixup;
@@ -18,7 +20,7 @@ class raw_ostream;
1820
template<typename T> class SmallVectorImpl;
1921

2022
/// MCCodeEmitter - Generic instruction encoding interface.
21-
class MCCodeEmitter {
23+
class LLVM_ABI MCCodeEmitter {
2224
protected: // Can only create subclasses.
2325
MCCodeEmitter();
2426

0 commit comments

Comments
 (0)