Skip to content

Commit 8f8ed23

Browse files
authored
[llvm] annotate interfaces in llvm/SandboxIR for DLL export (#142863)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/SandboxIR` 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 #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: - Remove explicit `GlobalWithNodeAPI::LLVMGVToGV::operator()` template function instantiations that were previously added for the dylib build. Instead, directly annotate the `LLVMGVToGV::operator()` method with `LLVM_ABI`. This is done so the DLL build works with both MSVC and clang-cl. - Explicitly `#include "llvm/SandboxIR/Value.h"` in `Tracker.h` so that the symbol is available for exported templates in this file. These templates get fully instantiated on DLL export, so they require the full definition of `Value`. - Add extern template instantiation declarations for `GlobalWithNodeAPI` template types in `Constants.h` and annotate them with `LLVM_TEMPLATE_ABI`. - Add `LLVM_EXPORT_TEMPLATE` to `GlobalWithNodeAPI` template instantiations in `Constants.cpp`. ## 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 5188bea commit 8f8ed23

File tree

14 files changed

+565
-551
lines changed

14 files changed

+565
-551
lines changed

llvm/include/llvm/SandboxIR/BasicBlock.h

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

1212
#include "llvm/IR/BasicBlock.h"
1313
#include "llvm/SandboxIR/Value.h"
14+
#include "llvm/Support/Compiler.h"
1415

1516
namespace llvm::sandboxir {
1617

@@ -32,20 +33,20 @@ class BBIterator {
3233
llvm::BasicBlock *BB;
3334
llvm::BasicBlock::iterator It;
3435
Context *Ctx;
35-
pointer getInstr(llvm::BasicBlock::iterator It) const;
36+
LLVM_ABI pointer getInstr(llvm::BasicBlock::iterator It) const;
3637

3738
public:
3839
BBIterator() : BB(nullptr), Ctx(nullptr) {}
3940
BBIterator(llvm::BasicBlock *BB, llvm::BasicBlock::iterator It, Context *Ctx)
4041
: BB(BB), It(It), Ctx(Ctx) {}
4142
reference operator*() const { return *getInstr(It); }
42-
BBIterator &operator++();
43+
LLVM_ABI BBIterator &operator++();
4344
BBIterator operator++(int) {
4445
auto Copy = *this;
4546
++*this;
4647
return Copy;
4748
}
48-
BBIterator &operator--();
49+
LLVM_ABI BBIterator &operator--();
4950
BBIterator operator--(int) {
5051
auto Copy = *this;
5152
--*this;
@@ -60,14 +61,14 @@ class BBIterator {
6061
/// the instruction is not found in the IR-to-SandboxIR tables.
6162
pointer get() const { return getInstr(It); }
6263
/// \Returns the parent BB.
63-
BasicBlock *getNodeParent() const;
64+
LLVM_ABI BasicBlock *getNodeParent() const;
6465
};
6566

6667
/// Contains a list of sandboxir::Instruction's.
6768
class BasicBlock : public Value {
6869
/// Builds a graph that contains all values in \p BB in their original form
6970
/// i.e., no vectorization is taking place here.
70-
void buildBasicBlockFromLLVMIR(llvm::BasicBlock *LLVMBB);
71+
LLVM_ABI void buildBasicBlockFromLLVMIR(llvm::BasicBlock *LLVMBB);
7172
friend class Context; // For `buildBasicBlockFromIR`
7273
friend class Instruction; // For LLVM Val.
7374

@@ -82,9 +83,9 @@ class BasicBlock : public Value {
8283
static bool classof(const Value *From) {
8384
return From->getSubclassID() == Value::ClassID::Block;
8485
}
85-
Function *getParent() const;
86+
LLVM_ABI Function *getParent() const;
8687
using iterator = BBIterator;
87-
iterator begin() const;
88+
LLVM_ABI iterator begin() const;
8889
iterator end() const {
8990
auto *BB = cast<llvm::BasicBlock>(Val);
9091
return iterator(BB, BB->end(), &Ctx);
@@ -96,10 +97,10 @@ class BasicBlock : public Value {
9697
return std::make_reverse_iterator(begin());
9798
}
9899
Context &getContext() const { return Ctx; }
99-
Instruction *getTerminator() const;
100+
LLVM_ABI Instruction *getTerminator() const;
100101
bool empty() const { return begin() == end(); }
101-
Instruction &front() const;
102-
Instruction &back() const;
102+
LLVM_ABI Instruction &front() const;
103+
LLVM_ABI Instruction &back() const;
103104

104105
#ifndef NDEBUG
105106
void verify() const final;

0 commit comments

Comments
 (0)