Skip to content

Commit 7e4bdb4

Browse files
authored
[llvm] annotate interfaces in llvm/CGData and llvm/CodeGen for DLL export (#140823)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/CGData` and `llvm/CodeGen` 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 `LLVM_ABI` to a subset of private class methods and fields that require export - Add `LLVM_TEMPLATE_ABI` and `LLVM_EXPORT_TEMPLATE` to exported instantiated templates defined via X-macro - Add `LLVM_ABI_FRIEND` to friend member functions declared with `LLVM_ABI` - Explicitly make classes non-copyable where needed to due IDS adding LLVM_ABI at the class level - 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_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 b14799e commit 7e4bdb4

File tree

101 files changed

+3162
-2780
lines changed

Some content is hidden

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

101 files changed

+3162
-2780
lines changed

llvm/include/llvm/CGData/CodeGenData.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/IR/Module.h"
2424
#include "llvm/Object/ObjectFile.h"
2525
#include "llvm/Support/Caching.h"
26+
#include "llvm/Support/Compiler.h"
2627
#include "llvm/Support/ErrorHandling.h"
2728
#include "llvm/TargetParser/Triple.h"
2829
#include <mutex>
@@ -34,9 +35,9 @@ enum CGDataSectKind {
3435
#include "llvm/CGData/CodeGenData.inc"
3536
};
3637

37-
std::string getCodeGenDataSectionName(CGDataSectKind CGSK,
38-
Triple::ObjectFormatType OF,
39-
bool AddSegmentInfo = true);
38+
LLVM_ABI std::string getCodeGenDataSectionName(CGDataSectKind CGSK,
39+
Triple::ObjectFormatType OF,
40+
bool AddSegmentInfo = true);
4041

4142
enum class CGDataKind {
4243
Unknown = 0x0,
@@ -47,7 +48,7 @@ enum class CGDataKind {
4748
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/StableFunctionMergingMap)
4849
};
4950

50-
const std::error_category &cgdata_category();
51+
LLVM_ABI const std::error_category &cgdata_category();
5152

5253
enum class cgdata_error {
5354
success = 0,
@@ -63,7 +64,7 @@ inline std::error_code make_error_code(cgdata_error E) {
6364
return std::error_code(static_cast<int>(E), cgdata_category());
6465
}
6566

66-
class CGDataError : public ErrorInfo<CGDataError> {
67+
class LLVM_ABI CGDataError : public ErrorInfo<CGDataError> {
6768
public:
6869
CGDataError(cgdata_error Err, const Twine &ErrStr = Twine())
6970
: Err(Err), Msg(ErrStr.str()) {
@@ -130,7 +131,7 @@ class CodeGenData {
130131
public:
131132
~CodeGenData() = default;
132133

133-
static CodeGenData &getInstance();
134+
LLVM_ABI static CodeGenData &getInstance();
134135

135136
/// Returns true if we have a valid outlined hash tree.
136137
bool hasOutlinedHashTree() {
@@ -245,27 +246,27 @@ struct StreamCacheData {
245246
/// \p Task represents the partition number in the parallel code generation
246247
/// process. \p AddStream is the callback used to add the serialized module to
247248
/// the stream.
248-
void saveModuleForTwoRounds(const Module &TheModule, unsigned Task,
249-
AddStreamFn AddStream);
249+
LLVM_ABI void saveModuleForTwoRounds(const Module &TheModule, unsigned Task,
250+
AddStreamFn AddStream);
250251

251252
/// Load the optimized bitcode module for the second codegen round.
252253
/// \p OrigModule is the original bitcode module.
253254
/// \p Task identifies the partition number in the parallel code generation
254255
/// process. \p Context provides the environment settings for module operations.
255256
/// \p IRFiles contains optimized bitcode module files needed for loading.
256257
/// \return A unique_ptr to the loaded Module, or nullptr if loading fails.
257-
std::unique_ptr<Module> loadModuleForTwoRounds(BitcodeModule &OrigModule,
258-
unsigned Task,
259-
LLVMContext &Context,
260-
ArrayRef<StringRef> IRFiles);
258+
LLVM_ABI std::unique_ptr<Module>
259+
loadModuleForTwoRounds(BitcodeModule &OrigModule, unsigned Task,
260+
LLVMContext &Context, ArrayRef<StringRef> IRFiles);
261261

262262
/// Merge the codegen data from the scratch objects \p ObjectFiles from the
263263
/// first codegen round.
264264
/// \return the combined hash of the merged codegen data.
265-
Expected<stable_hash> mergeCodeGenData(ArrayRef<StringRef> ObjectFiles);
265+
LLVM_ABI Expected<stable_hash>
266+
mergeCodeGenData(ArrayRef<StringRef> ObjectFiles);
266267

267-
void warn(Error E, StringRef Whence = "");
268-
void warn(Twine Message, StringRef Whence = "", StringRef Hint = "");
268+
LLVM_ABI void warn(Error E, StringRef Whence = "");
269+
LLVM_ABI void warn(Twine Message, StringRef Whence = "", StringRef Hint = "");
269270

270271
} // end namespace cgdata
271272

@@ -297,7 +298,7 @@ struct Header {
297298
// the new field is read correctly.
298299

299300
// Reads a header struct from the buffer.
300-
static Expected<Header> readFromBuffer(const unsigned char *Curr);
301+
LLVM_ABI static Expected<Header> readFromBuffer(const unsigned char *Curr);
301302
};
302303

303304
} // end namespace IndexedCGData

llvm/include/llvm/CGData/CodeGenDataReader.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/CGData/CodeGenData.h"
1717
#include "llvm/CGData/OutlinedHashTreeRecord.h"
1818
#include "llvm/CGData/StableFunctionMapRecord.h"
19+
#include "llvm/Support/Compiler.h"
1920
#include "llvm/Support/LineIterator.h"
2021
#include "llvm/Support/VirtualFileSystem.h"
2122

@@ -49,20 +50,20 @@ class CodeGenDataReader {
4950

5051
/// Factory method to create an appropriately typed reader for the given
5152
/// codegen data file path and file system.
52-
static Expected<std::unique_ptr<CodeGenDataReader>>
53+
LLVM_ABI static Expected<std::unique_ptr<CodeGenDataReader>>
5354
create(const Twine &Path, vfs::FileSystem &FS);
5455

5556
/// Factory method to create an appropriately typed reader for the given
5657
/// memory buffer.
57-
static Expected<std::unique_ptr<CodeGenDataReader>>
58+
LLVM_ABI static Expected<std::unique_ptr<CodeGenDataReader>>
5859
create(std::unique_ptr<MemoryBuffer> Buffer);
5960

6061
/// Extract the cgdata embedded in sections from the given object file and
6162
/// merge them into the GlobalOutlineRecord. This is a static helper that
6263
/// is used by `llvm-cgdata --merge` or ThinLTO's two-codegen rounds.
6364
/// Optionally, \p CombinedHash can be used to compuate the combined hash of
6465
/// the merged data.
65-
static Error
66+
LLVM_ABI static Error
6667
mergeFromObjectFile(const object::ObjectFile *Obj,
6768
OutlinedHashTreeRecord &GlobalOutlineRecord,
6869
StableFunctionMapRecord &GlobalFunctionMapRecord,
@@ -98,7 +99,7 @@ class CodeGenDataReader {
9899
Error success() { return error(cgdata_error::success); }
99100
};
100101

101-
class IndexedCodeGenDataReader : public CodeGenDataReader {
102+
class LLVM_ABI IndexedCodeGenDataReader : public CodeGenDataReader {
102103
/// The codegen data file contents.
103104
std::unique_ptr<MemoryBuffer> DataBuffer;
104105
/// The header
@@ -139,7 +140,7 @@ class IndexedCodeGenDataReader : public CodeGenDataReader {
139140
/// codegen data is recorded. `#` is used to indicate a comment.
140141
/// The subsequent data is a YAML format per each codegen data in order.
141142
/// Currently, it only has a function outlined hash tree.
142-
class TextCodeGenDataReader : public CodeGenDataReader {
143+
class LLVM_ABI TextCodeGenDataReader : public CodeGenDataReader {
143144
/// The codegen data file contents.
144145
std::unique_ptr<MemoryBuffer> DataBuffer;
145146
/// Iterator over the profile data.

llvm/include/llvm/CGData/CodeGenDataWriter.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/CGData/CodeGenData.h"
1717
#include "llvm/CGData/OutlinedHashTreeRecord.h"
1818
#include "llvm/CGData/StableFunctionMapRecord.h"
19+
#include "llvm/Support/Compiler.h"
1920
#include "llvm/Support/EndianStream.h"
2021
#include "llvm/Support/Error.h"
2122

@@ -45,7 +46,7 @@ class CGDataOStream {
4546
// \c patch can only be called when all data is written and flushed.
4647
// For raw_string_ostream, the patch is done on the target string
4748
// directly and it won't be reflected in the stream's internal buffer.
48-
void patch(ArrayRef<CGDataPatchItem> P);
49+
LLVM_ABI void patch(ArrayRef<CGDataPatchItem> P);
4950

5051
// If \c OS is an instance of \c raw_fd_ostream, this field will be
5152
// true. Otherwise, \c OS will be an raw_string_ostream.
@@ -69,16 +70,16 @@ class CodeGenDataWriter {
6970
~CodeGenDataWriter() = default;
7071

7172
/// Add the outlined hash tree record. The input hash tree is released.
72-
void addRecord(OutlinedHashTreeRecord &Record);
73+
LLVM_ABI void addRecord(OutlinedHashTreeRecord &Record);
7374

7475
/// Add the stable function map record. The input function map is released.
75-
void addRecord(StableFunctionMapRecord &Record);
76+
LLVM_ABI void addRecord(StableFunctionMapRecord &Record);
7677

7778
/// Write the codegen data to \c OS
78-
Error write(raw_fd_ostream &OS);
79+
LLVM_ABI Error write(raw_fd_ostream &OS);
7980

8081
/// Write the codegen data in text format to \c OS
81-
Error writeText(raw_fd_ostream &OS);
82+
LLVM_ABI Error writeText(raw_fd_ostream &OS);
8283

8384
/// Return the attributes of the current CGData.
8485
CGDataKind getCGDataKind() const { return DataKind; }

llvm/include/llvm/CGData/OutlinedHashTree.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/DenseMap.h"
1919
#include "llvm/ADT/StableHashing.h"
2020
#include "llvm/ObjectYAML/YAML.h"
21+
#include "llvm/Support/Compiler.h"
2122
#include "llvm/Support/raw_ostream.h"
2223

2324
#include <unordered_map>
@@ -54,9 +55,9 @@ class OutlinedHashTree {
5455
/// the source and the stable_hash of the sink for an edge. These generic
5556
/// callbacks can be used to traverse a OutlinedHashTree for the purpose of
5657
/// print debugging or serializing it.
57-
void walkGraph(NodeCallbackFn CallbackNode,
58-
EdgeCallbackFn CallbackEdge = nullptr,
59-
bool SortedWalk = false) const;
58+
LLVM_ABI void walkGraph(NodeCallbackFn CallbackNode,
59+
EdgeCallbackFn CallbackEdge = nullptr,
60+
bool SortedWalk = false) const;
6061

6162
/// Release all hash nodes except the root hash node.
6263
void clear() {
@@ -71,24 +72,24 @@ class OutlinedHashTree {
7172
/// \p GetTerminalCountOnly is true, it only counts the terminal nodes
7273
/// (meaning it returns the the number of hash sequences in the
7374
/// OutlinedHashTree).
74-
size_t size(bool GetTerminalCountOnly = false) const;
75+
LLVM_ABI size_t size(bool GetTerminalCountOnly = false) const;
7576

7677
/// \returns the depth of a OutlinedHashTree by traversing it.
77-
size_t depth() const;
78+
LLVM_ABI size_t depth() const;
7879

7980
/// \returns the root hash node of a OutlinedHashTree.
8081
const HashNode *getRoot() const { return &Root; }
8182
HashNode *getRoot() { return &Root; }
8283

8384
/// Inserts a \p Sequence into the this tree. The last node in the sequence
8485
/// will increase Terminals.
85-
void insert(const HashSequencePair &SequencePair);
86+
LLVM_ABI void insert(const HashSequencePair &SequencePair);
8687

8788
/// Merge a \p OtherTree into this Tree.
88-
void merge(const OutlinedHashTree *OtherTree);
89+
LLVM_ABI void merge(const OutlinedHashTree *OtherTree);
8990

9091
/// \returns the matching count if \p Sequence exists in the OutlinedHashTree.
91-
std::optional<unsigned> find(const HashSequence &Sequence) const;
92+
LLVM_ABI std::optional<unsigned> find(const HashSequence &Sequence) const;
9293

9394
private:
9495
HashNode Root;

llvm/include/llvm/CGData/OutlinedHashTreeRecord.h

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

1919
#include "llvm/CGData/OutlinedHashTree.h"
20+
#include "llvm/Support/Compiler.h"
2021

2122
namespace llvm {
2223

@@ -40,13 +41,13 @@ struct OutlinedHashTreeRecord {
4041
: HashTree(std::move(HashTree)) {};
4142

4243
/// Serialize the outlined hash tree to a raw_ostream.
43-
void serialize(raw_ostream &OS) const;
44+
LLVM_ABI void serialize(raw_ostream &OS) const;
4445
/// Deserialize the outlined hash tree from a raw_ostream.
45-
void deserialize(const unsigned char *&Ptr);
46+
LLVM_ABI void deserialize(const unsigned char *&Ptr);
4647
/// Serialize the outlined hash tree to a YAML stream.
47-
void serializeYAML(yaml::Output &YOS) const;
48+
LLVM_ABI void serializeYAML(yaml::Output &YOS) const;
4849
/// Deserialize the outlined hash tree from a YAML stream.
49-
void deserializeYAML(yaml::Input &YIS);
50+
LLVM_ABI void deserializeYAML(yaml::Input &YIS);
5051

5152
/// Merge the other outlined hash tree into this one.
5253
void merge(const OutlinedHashTreeRecord &Other) {

llvm/include/llvm/CGData/StableFunctionMap.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/DenseMap.h"
2020
#include "llvm/ADT/StringMap.h"
2121
#include "llvm/IR/StructuralHash.h"
22+
#include "llvm/Support/Compiler.h"
2223

2324
namespace llvm {
2425

@@ -82,18 +83,18 @@ struct StableFunctionMap {
8283

8384
/// Get an existing ID associated with the given name or create a new ID if it
8485
/// doesn't exist.
85-
unsigned getIdOrCreateForName(StringRef Name);
86+
LLVM_ABI unsigned getIdOrCreateForName(StringRef Name);
8687

8788
/// Get the name associated with a given ID
88-
std::optional<std::string> getNameForId(unsigned Id) const;
89+
LLVM_ABI std::optional<std::string> getNameForId(unsigned Id) const;
8990

9091
/// Insert a `StableFunction` object into the function map. This method
9192
/// handles the uniquing of string names and create a `StableFunctionEntry`
9293
/// for insertion.
93-
void insert(const StableFunction &Func);
94+
LLVM_ABI void insert(const StableFunction &Func);
9495

9596
/// Merge a \p OtherMap into this function map.
96-
void merge(const StableFunctionMap &OtherMap);
97+
LLVM_ABI void merge(const StableFunctionMap &OtherMap);
9798

9899
/// \returns true if there is no stable function entry.
99100
bool empty() const { return size() == 0; }
@@ -107,10 +108,10 @@ struct StableFunctionMap {
107108

108109
/// \returns the size of StableFunctionMap.
109110
/// \p Type is the type of size to return.
110-
size_t size(SizeType Type = UniqueHashCount) const;
111+
LLVM_ABI size_t size(SizeType Type = UniqueHashCount) const;
111112

112113
/// Finalize the stable function map by trimming content.
113-
void finalize(bool SkipTrim = false);
114+
LLVM_ABI void finalize(bool SkipTrim = false);
114115

115116
private:
116117
/// Insert a `StableFunctionEntry` into the function map directly. This

llvm/include/llvm/CGData/StableFunctionMapRecord.h

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

1919
#include "llvm/CGData/StableFunctionMap.h"
2020
#include "llvm/ObjectYAML/YAML.h"
21+
#include "llvm/Support/Compiler.h"
2122
#include "llvm/Support/raw_ostream.h"
2223

2324
namespace llvm {
@@ -34,19 +35,20 @@ struct StableFunctionMapRecord {
3435

3536
/// A static helper function to serialize the stable function map without
3637
/// owning the stable function map.
37-
static void serialize(raw_ostream &OS, const StableFunctionMap *FunctionMap);
38+
LLVM_ABI static void serialize(raw_ostream &OS,
39+
const StableFunctionMap *FunctionMap);
3840

3941
/// Serialize the stable function map to a raw_ostream.
40-
void serialize(raw_ostream &OS) const;
42+
LLVM_ABI void serialize(raw_ostream &OS) const;
4143

4244
/// Deserialize the stable function map from a raw_ostream.
43-
void deserialize(const unsigned char *&Ptr);
45+
LLVM_ABI void deserialize(const unsigned char *&Ptr);
4446

4547
/// Serialize the stable function map to a YAML stream.
46-
void serializeYAML(yaml::Output &YOS) const;
48+
LLVM_ABI void serializeYAML(yaml::Output &YOS) const;
4749

4850
/// Deserialize the stable function map from a YAML stream.
49-
void deserializeYAML(yaml::Input &YIS);
51+
LLVM_ABI void deserializeYAML(yaml::Input &YIS);
5052

5153
/// Finalize the stable function map by trimming content.
5254
void finalize(bool SkipTrim = false) { FunctionMap->finalize(SkipTrim); }

0 commit comments

Comments
 (0)