|
23 | 23 | #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" |
24 | 24 | #include "mlir/Transforms/LocationSnapshot.h" |
25 | 25 |
|
| 26 | +#include "ir.h" |
26 | 27 | #include "triton/Conversion/TritonGPUToLLVM/Utility.h" |
27 | 28 | #include "triton/Dialect/Triton/IR/Dialect.h" |
28 | 29 | #include "triton/Dialect/Triton/IR/Types.h" |
@@ -56,90 +57,6 @@ llvm::raw_ostream &mlir_dumps_or_dbgs() { |
56 | 57 | } |
57 | 58 | } |
58 | 59 |
|
59 | | -// A custom op builder that keeps track of the last location |
60 | | -class TritonOpBuilder { |
61 | | -public: |
62 | | - TritonOpBuilder(MLIRContext *context) { |
63 | | - builder = std::make_unique<OpBuilder>(context); |
64 | | - lastLoc = std::make_unique<Location>(builder->getUnknownLoc()); |
65 | | - } |
66 | | - |
67 | | - OpBuilder &getBuilder() { return *builder; } |
68 | | - MLIRContext *getContext() { return builder->getContext(); } |
69 | | - |
70 | | - bool isLineInfoEnabled() { return lineInfoEnabled; } |
71 | | - |
72 | | - void setLastLoc(Location loc) { |
73 | | - if (lineInfoEnabled) |
74 | | - lastLoc = std::make_unique<Location>(loc); |
75 | | - } |
76 | | - |
77 | | - void setLastLoc(const std::string &fileName, int line, int column) { |
78 | | - auto context = builder->getContext(); |
79 | | - setLastLoc(FileLineColLoc::get(context, fileName, line, column)); |
80 | | - } |
81 | | - |
82 | | - Location getLastLoc() { |
83 | | - assert(lastLoc); |
84 | | - return *lastLoc; |
85 | | - } |
86 | | - |
87 | | - void setInsertionPointToStart(Block &block) { |
88 | | - if (!block.empty()) |
89 | | - setLastLoc(block.begin()->getLoc()); |
90 | | - else |
91 | | - setLastLoc(builder->getUnknownLoc()); |
92 | | - builder->setInsertionPointToStart(&block); |
93 | | - } |
94 | | - |
95 | | - void setInsertionPointToEnd(Block &block) { |
96 | | - if (!block.empty()) |
97 | | - setLastLoc(block.back().getLoc()); |
98 | | - else |
99 | | - setLastLoc(builder->getUnknownLoc()); |
100 | | - builder->setInsertionPointToEnd(&block); |
101 | | - } |
102 | | - |
103 | | - void setInsertionPointAfter(Operation &op) { |
104 | | - setLastLoc(op.getLoc()); |
105 | | - builder->setInsertionPointAfter(&op); |
106 | | - } |
107 | | - |
108 | | - void restoreInsertionPoint(OpBuilder::InsertPoint pt) { |
109 | | - if (pt.isSet() && pt.getPoint() != pt.getBlock()->end()) |
110 | | - setLastLoc(pt.getPoint()->getLoc()); |
111 | | - else |
112 | | - setLastLoc(builder->getUnknownLoc()); |
113 | | - builder->restoreInsertionPoint(pt); |
114 | | - } |
115 | | - |
116 | | - template <typename OpTy, typename... Args> OpTy create(Args &&...args) { |
117 | | - auto loc = getLastLoc(); |
118 | | - return builder->create<OpTy>(loc, std::forward<Args>(args)...); |
119 | | - } |
120 | | - |
121 | | - // Overload to create or fold a single result operation. |
122 | | - template <typename OpTy, typename... Args> |
123 | | - std::enable_if_t<OpTy::template hasTrait<OpTrait::OneResult>(), Value> |
124 | | - createOrFold(Args &&...args) { |
125 | | - auto loc = getLastLoc(); |
126 | | - return builder->createOrFold<OpTy>(loc, std::forward<Args>(args)...); |
127 | | - } |
128 | | - |
129 | | - // Overload to create or fold a zero result operation. |
130 | | - template <typename OpTy, typename... Args> |
131 | | - std::enable_if_t<OpTy::template hasTrait<OpTrait::ZeroResults>(), OpTy> |
132 | | - createOrFold(Args &&...args) { |
133 | | - auto loc = getLastLoc(); |
134 | | - return builder->createOrFold<OpTy>(loc, std::forward<Args>(args)...); |
135 | | - } |
136 | | - |
137 | | -private: |
138 | | - std::unique_ptr<OpBuilder> builder; |
139 | | - std::unique_ptr<Location> lastLoc; |
140 | | - bool lineInfoEnabled = !triton::tools::getBoolEnv("TRITON_DISABLE_LINE_INFO"); |
141 | | -}; |
142 | | - |
143 | 60 | // Run the pass manager under a source manager diagnostic handler, which |
144 | 61 | // enables emitted MLIR diagnostics to directly reference Python source |
145 | 62 | // code. This diagnostic handler supports filtering diagnostic info by |
|
0 commit comments