|
13 | 13 | #include "mlir/Dialect/LLVMIR/LLVMDialect.h" |
14 | 14 | #include "mlir/Linker/LLVMLinkerMixin.h" |
15 | 15 | #include "mlir/Linker/LinkerInterface.h" |
16 | | - |
| 16 | +#include "mlir/Dialect/LLVMIR/LLVMLinkerInterface.h" |
17 | 17 | using namespace mlir; |
18 | 18 | using namespace mlir::link; |
19 | 19 |
|
20 | 20 | //===----------------------------------------------------------------------===// |
21 | 21 | // LLVMSymbolLinkerInterface |
22 | 22 | //===----------------------------------------------------------------------===// |
23 | 23 |
|
24 | | -class LLVMSymbolLinkerInterface |
25 | | - : public SymbolAttrLLVMLinkerInterface<LLVMSymbolLinkerInterface> { |
26 | | -public: |
27 | | - LLVMSymbolLinkerInterface(Dialect *dialect) |
28 | | - : SymbolAttrLLVMLinkerInterface(dialect) {} |
29 | 24 |
|
30 | | - bool canBeLinked(Operation *op) const override { |
31 | | - return isa<LLVM::GlobalOp>(op) || isa<LLVM::LLVMFuncOp>(op); |
32 | | - } |
| 25 | + |
| 26 | + |
| 27 | +mlir::LLVM::LLVMSymbolLinkerInterface::LLVMSymbolLinkerInterface(Dialect *dialect) |
| 28 | + : SymbolAttrLLVMLinkerInterface(dialect) {} |
| 29 | + |
| 30 | +bool mlir::LLVM::LLVMSymbolLinkerInterface::canBeLinked(Operation *op) const { |
| 31 | + return isa<LLVM::GlobalOp>(op) || isa<LLVM::LLVMFuncOp>(op); |
| 32 | +} |
33 | 33 |
|
34 | 34 | //===--------------------------------------------------------------------===// |
35 | 35 | // LLVMLinkerMixin required methods from derived linker interface |
36 | 36 | //===--------------------------------------------------------------------===// |
37 | 37 |
|
38 | | - static Linkage getLinkage(Operation *op) { |
39 | | - if (auto gv = dyn_cast<LLVM::GlobalOp>(op)) |
40 | | - return gv.getLinkage(); |
41 | | - if (auto fn = dyn_cast<LLVM::LLVMFuncOp>(op)) |
42 | | - return fn.getLinkage(); |
43 | | - llvm_unreachable("unexpected operation"); |
44 | | - } |
| 38 | +Linkage mlir::LLVM::LLVMSymbolLinkerInterface::getLinkage(Operation *op) { |
| 39 | + if (auto gv = dyn_cast<LLVM::GlobalOp>(op)) |
| 40 | + return gv.getLinkage(); |
| 41 | + if (auto fn = dyn_cast<LLVM::LLVMFuncOp>(op)) |
| 42 | + return fn.getLinkage(); |
| 43 | + llvm_unreachable("unexpected operation"); |
| 44 | +} |
45 | 45 |
|
46 | | - static Visibility getVisibility(Operation *op) { |
47 | | - if (auto gv = dyn_cast<LLVM::GlobalOp>(op)) |
48 | | - return gv.getVisibility_(); |
49 | | - if (auto fn = dyn_cast<LLVM::LLVMFuncOp>(op)) |
50 | | - return fn.getVisibility_(); |
51 | | - llvm_unreachable("unexpected operation"); |
52 | | - } |
| 46 | +Visibility mlir::LLVM::LLVMSymbolLinkerInterface::getVisibility(Operation *op) { |
| 47 | + if (auto gv = dyn_cast<LLVM::GlobalOp>(op)) |
| 48 | + return gv.getVisibility_(); |
| 49 | + if (auto fn = dyn_cast<LLVM::LLVMFuncOp>(op)) |
| 50 | + return fn.getVisibility_(); |
| 51 | + llvm_unreachable("unexpected operation"); |
| 52 | +} |
53 | 53 |
|
54 | | - static void setVisibility(Operation *op, Visibility visibility) { |
55 | | - if (auto gv = dyn_cast<LLVM::GlobalOp>(op)) |
56 | | - return gv.setVisibility_(visibility); |
57 | | - if (auto fn = dyn_cast<LLVM::LLVMFuncOp>(op)) |
58 | | - return fn.setVisibility_(visibility); |
59 | | - llvm_unreachable("unexpected operation"); |
60 | | - } |
| 54 | +void mlir::LLVM::LLVMSymbolLinkerInterface::setVisibility(Operation *op, Visibility visibility) { |
| 55 | + if (auto gv = dyn_cast<LLVM::GlobalOp>(op)) |
| 56 | + return gv.setVisibility_(visibility); |
| 57 | + if (auto fn = dyn_cast<LLVM::LLVMFuncOp>(op)) |
| 58 | + return fn.setVisibility_(visibility); |
| 59 | + llvm_unreachable("unexpected operation"); |
| 60 | +} |
61 | 61 |
|
62 | | - // Return true if the primary definition of this global value is outside of |
63 | | - // the current translation unit. |
64 | | - static bool isDeclaration(Operation *op) { |
65 | | - if (auto gv = dyn_cast<LLVM::GlobalOp>(op)) |
66 | | - return gv.getInitializerRegion().empty() && !gv.getValue(); |
67 | | - if (auto fn = dyn_cast<LLVM::LLVMFuncOp>(op)) |
68 | | - return fn.getBody().empty(); |
69 | | - llvm_unreachable("unexpected operation"); |
70 | | - } |
| 62 | +// Return true if the primary definition of this global value is outside of |
| 63 | +// the current translation unit. |
| 64 | +bool mlir::LLVM::LLVMSymbolLinkerInterface::isDeclaration(Operation *op) { |
| 65 | + if (auto gv = dyn_cast<LLVM::GlobalOp>(op)) |
| 66 | + return gv.getInitializerRegion().empty() && !gv.getValue(); |
| 67 | + if (auto fn = dyn_cast<LLVM::LLVMFuncOp>(op)) |
| 68 | + return fn.getBody().empty(); |
| 69 | + llvm_unreachable("unexpected operation"); |
| 70 | +} |
71 | 71 |
|
72 | | - static unsigned getBitWidth(Operation *op) { |
73 | | - if (auto gv = dyn_cast<LLVM::GlobalOp>(op)) |
74 | | - return gv.getType().getIntOrFloatBitWidth(); |
75 | | - llvm_unreachable("unexpected operation"); |
76 | | - } |
| 72 | +unsigned mlir::LLVM::LLVMSymbolLinkerInterface::getBitWidth(Operation *op) { |
| 73 | + if (auto gv = dyn_cast<LLVM::GlobalOp>(op)) |
| 74 | + return gv.getType().getIntOrFloatBitWidth(); |
| 75 | + llvm_unreachable("unexpected operation"); |
| 76 | +} |
77 | 77 |
|
78 | | - static UnnamedAddr getUnnamedAddr(Operation *op) { |
79 | | - if (auto gv = dyn_cast<LLVM::GlobalOp>(op)) { |
80 | | - auto addr = gv.getUnnamedAddr(); |
81 | | - return addr ? *addr : UnnamedAddr::Global; |
82 | | - } |
83 | | - if (auto fn = dyn_cast<LLVM::LLVMFuncOp>(op)) { |
84 | | - auto addr = fn.getUnnamedAddr(); |
85 | | - return addr ? *addr : UnnamedAddr::Global; |
86 | | - } |
87 | | - llvm_unreachable("unexpected operation"); |
| 78 | +UnnamedAddr mlir::LLVM::LLVMSymbolLinkerInterface::getUnnamedAddr(Operation *op) { |
| 79 | + if (auto gv = dyn_cast<LLVM::GlobalOp>(op)) { |
| 80 | + auto addr = gv.getUnnamedAddr(); |
| 81 | + return addr ? *addr : UnnamedAddr::Global; |
88 | 82 | } |
89 | | - |
90 | | - static void setUnnamedAddr(Operation *op, UnnamedAddr val) { |
91 | | - if (auto gv = dyn_cast<LLVM::GlobalOp>(op)) |
92 | | - return gv.setUnnamedAddr(val); |
93 | | - if (auto fn = dyn_cast<LLVM::LLVMFuncOp>(op)) |
94 | | - return fn.setUnnamedAddr(val); |
95 | | - llvm_unreachable("unexpected operation"); |
| 83 | + if (auto fn = dyn_cast<LLVM::LLVMFuncOp>(op)) { |
| 84 | + auto addr = fn.getUnnamedAddr(); |
| 85 | + return addr ? *addr : UnnamedAddr::Global; |
96 | 86 | } |
97 | | -}; |
| 87 | + llvm_unreachable("unexpected operation"); |
| 88 | +} |
| 89 | + |
| 90 | +void mlir::LLVM::LLVMSymbolLinkerInterface::setUnnamedAddr(Operation *op, UnnamedAddr val) { |
| 91 | + if (auto gv = dyn_cast<LLVM::GlobalOp>(op)) |
| 92 | + return gv.setUnnamedAddr(val); |
| 93 | + if (auto fn = dyn_cast<LLVM::LLVMFuncOp>(op)) |
| 94 | + return fn.setUnnamedAddr(val); |
| 95 | + llvm_unreachable("unexpected operation"); |
| 96 | +} |
| 97 | + |
98 | 98 |
|
99 | 99 | //===----------------------------------------------------------------------===// |
100 | 100 | // registerLinkerInterface |
|
0 commit comments