MLIR: lib/CAPI/Transforms/Rewrite.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

10

19

20 using namespace mlir;

21

22

23

24

25

28 }

29

30

31

32

33

35 unwrap(rewriter)->clearInsertionPoint();

36 }

37

39 MlirOperation op) {

40 unwrap(rewriter)->setInsertionPoint(unwrap(op));

41 }

42

44 MlirOperation op) {

45 unwrap(rewriter)->setInsertionPointAfter(unwrap(op));

46 }

47

49 MlirValue value) {

50 unwrap(rewriter)->setInsertionPointAfterValue(unwrap(value));

51 }

52

54 MlirBlock block) {

55 unwrap(rewriter)->setInsertionPointToStart(unwrap(block));

56 }

57

59 MlirBlock block) {

60 unwrap(rewriter)->setInsertionPointToEnd(unwrap(block));

61 }

62

64 return wrap(unwrap(rewriter)->getInsertionBlock());

65 }

66

68 return wrap(unwrap(rewriter)->getBlock());

69 }

70

71

72

73

74

76 MlirBlock insertBefore,

77 intptr_t nArgTypes,

78 MlirType const *argTypes,

79 MlirLocation const *locations) {

85 unwrappedLocs));

86 }

87

89 MlirOperation op) {

91 }

92

93

94

96 MlirOperation op) {

98 }

99

101 MlirOperation op) {

103 }

104

106 MlirRegion region, MlirBlock before) {

107

108 unwrap(rewriter)->cloneRegionBefore(*unwrap(region), unwrap(before));

109 }

110

111

112

113

114

116 MlirRegion region, MlirBlock before) {

117 unwrap(rewriter)->inlineRegionBefore(*unwrap(region), unwrap(before));

118 }

119

121 MlirOperation op, intptr_t nValues,

122 MlirValue const *values) {

125 unwrap(rewriter)->replaceOp(unwrap(op), unwrappedVals);

126 }

127

129 MlirOperation op,

130 MlirOperation newOp) {

132 }

133

136 }

137

140 }

141

143 MlirBlock source, MlirOperation op,

144 intptr_t nArgValues,

145 MlirValue const *argValues) {

148

150 unwrappedVals);

151 }

152

154 MlirBlock dest, intptr_t nArgValues,

155 MlirValue const *argValues) {

158 unwrap(rewriter)->mergeBlocks(unwrap(source), unwrap(dest), unwrappedArgs);

159 }

160

162 MlirOperation existingOp) {

164 }

165

167 MlirOperation existingOp) {

169 }

170

172 MlirBlock existingBlock) {

173 unwrap(rewriter)->moveBlockBefore(unwrap(block), unwrap(existingBlock));

174 }

175

177 MlirOperation op) {

178 unwrap(rewriter)->startOpModification(unwrap(op));

179 }

180

182 MlirOperation op) {

183 unwrap(rewriter)->finalizeOpModification(unwrap(op));

184 }

185

187 MlirOperation op) {

188 unwrap(rewriter)->cancelOpModification(unwrap(op));

189 }

190

192 MlirValue from, MlirValue to) {

194 }

195

197 intptr_t nValues,

198 MlirValue const *from,

199 MlirValue const *to) {

204 unwrap(rewriter)->replaceAllUsesWith(unwrappedFromVals, unwrappedToVals);

205 }

206

208 MlirOperation from,

209 intptr_t nTo,

210 MlirValue const *to) {

213 unwrap(rewriter)->replaceAllOpUsesWith(unwrap(from), unwrappedToVals);

214 }

215

217 MlirOperation from,

218 MlirOperation to) {

220 }

221

223 MlirOperation op,

224 intptr_t nNewValues,

225 MlirValue const *newValues,

226 MlirBlock block) {

229 unwrap(rewriter)->replaceOpUsesWithinBlock(unwrap(op), unwrappedVals,

231 }

232

234 MlirValue from, MlirValue to,

235 MlirOperation exceptedUser) {

237 unwrap(exceptedUser));

238 }

239

240

241

242

243

246 }

247

250 }

251

254 }

255

256

257

258

259

261 assert(module.ptr && "unexpected null module");

263 }

264

266 return {module};

267 }

268

270 unwrap(MlirFrozenRewritePatternSet module) {

271 assert(module.ptr && "unexpected null module");

273 }

274

276 return {module};

277 }

278

281 op.ptr = nullptr;

282 return wrap(m);

283 }

284

287 op.ptr = nullptr;

288 }

289

292 MlirFrozenRewritePatternSet patterns,

293 MlirGreedyRewriteDriverConfig) {

295 }

296

297

298

299

300

301 #if MLIR_ENABLE_PDL_IN_PATTERNMATCH

302 inline mlir::PDLPatternModule *unwrap(MlirPDLPatternModule module) {

303 assert(module.ptr && "unexpected null module");

304 return static_cast<mlir::PDLPatternModule *>(module.ptr);

305 }

306

307 inline MlirPDLPatternModule wrap(mlir::PDLPatternModule *module) {

308 return {module};

309 }

310

312 return wrap(new mlir::PDLPatternModule(

314 }

315

318 op.ptr = nullptr;

319 }

320

321 MlirRewritePatternSet

324 op.ptr = nullptr;

325 return wrap(m);

326 }

327 #endif

void mlirRewriterBaseReplaceOpUsesWithinBlock(MlirRewriterBase rewriter, MlirOperation op, intptr_t nNewValues, MlirValue const *newValues, MlirBlock block)

Find uses of from within block and replace them with to.

mlir::RewritePatternSet & unwrap(MlirRewritePatternSet module)

RewritePatternSet and FrozenRewritePatternSet API.

void mlirRewriterBaseMergeBlocks(MlirRewriterBase rewriter, MlirBlock source, MlirBlock dest, intptr_t nArgValues, MlirValue const *argValues)

Inline the operations of block 'source' into the end of block 'dest'.

void mlirIRRewriterDestroy(MlirRewriterBase rewriter)

Takes an IRRewriter owned by the caller and destroys it.

void mlirRewriterBaseStartOpModification(MlirRewriterBase rewriter, MlirOperation op)

This method is used to notify the rewriter that an in-place operation modification is about to happen...

MlirOperation mlirRewriterBaseInsert(MlirRewriterBase rewriter, MlirOperation op)

Insert the given operation at the current insertion point and return it.

MlirRewriterBase mlirIRRewriterCreate(MlirContext context)

IRRewriter API.

void mlirRewriterBaseMoveOpAfter(MlirRewriterBase rewriter, MlirOperation op, MlirOperation existingOp)

Unlink this operation from its current block and insert it right after existingOp which may be in the...

void mlirRewriterBaseCloneRegionBefore(MlirRewriterBase rewriter, MlirRegion region, MlirBlock before)

Clone the blocks that belong to "region" before the given position in another region "parent".

void mlirRewriterBaseSetInsertionPointAfter(MlirRewriterBase rewriter, MlirOperation op)

Sets the insertion point to the node after the specified operation, which will cause subsequent inser...

void mlirFrozenRewritePatternSetDestroy(MlirFrozenRewritePatternSet op)

MlirRewritePatternSet wrap(mlir::RewritePatternSet *module)

void mlirRewriterBaseReplaceAllOpUsesWithOperation(MlirRewriterBase rewriter, MlirOperation from, MlirOperation to)

Find uses of from and replace them with to.

void mlirRewriterBaseMoveBlockBefore(MlirRewriterBase rewriter, MlirBlock block, MlirBlock existingBlock)

Unlink this block and insert it right before existingBlock.

void mlirRewriterBaseReplaceAllValueRangeUsesWith(MlirRewriterBase rewriter, intptr_t nValues, MlirValue const *from, MlirValue const *to)

Find uses of from and replace them with to.

void mlirRewriterBaseEraseBlock(MlirRewriterBase rewriter, MlirBlock block)

Erases a block along with all operations inside it.

void mlirRewriterBaseReplaceAllUsesExcept(MlirRewriterBase rewriter, MlirValue from, MlirValue to, MlirOperation exceptedUser)

Find uses of from and replace them with to except if the user is exceptedUser.

MlirBlock mlirRewriterBaseCreateBlockBefore(MlirRewriterBase rewriter, MlirBlock insertBefore, intptr_t nArgTypes, MlirType const *argTypes, MlirLocation const *locations)

Block and operation creation/insertion/cloning.

MlirLogicalResult mlirApplyPatternsAndFoldGreedily(MlirModule op, MlirFrozenRewritePatternSet patterns, MlirGreedyRewriteDriverConfig)

void mlirRewriterBaseSetInsertionPointToStart(MlirRewriterBase rewriter, MlirBlock block)

Sets the insertion point to the start of the specified block.

MlirContext mlirRewriterBaseGetContext(MlirRewriterBase rewriter)

RewriterBase API inherited from OpBuilder.

void mlirRewriterBaseReplaceAllOpUsesWithValueRange(MlirRewriterBase rewriter, MlirOperation from, intptr_t nTo, MlirValue const *to)

Find uses of from and replace them with to.

MlirOperation mlirRewriterBaseClone(MlirRewriterBase rewriter, MlirOperation op)

Creates a deep copy of the specified operation.

void mlirRewriterBaseInlineBlockBefore(MlirRewriterBase rewriter, MlirBlock source, MlirOperation op, intptr_t nArgValues, MlirValue const *argValues)

Inline the operations of block 'source' before the operation 'op'.

void mlirRewriterBaseReplaceOpWithValues(MlirRewriterBase rewriter, MlirOperation op, intptr_t nValues, MlirValue const *values)

Replace the results of the given (original) operation with the specified list of values (replacements...

void mlirRewriterBaseCancelOpModification(MlirRewriterBase rewriter, MlirOperation op)

This method cancels a pending in-place modification.

void mlirRewriterBaseSetInsertionPointAfterValue(MlirRewriterBase rewriter, MlirValue value)

Sets the insertion point to the node after the specified value.

void mlirRewriterBaseSetInsertionPointToEnd(MlirRewriterBase rewriter, MlirBlock block)

Sets the insertion point to the end of the specified block.

MlirOperation mlirRewriterBaseCloneWithoutRegions(MlirRewriterBase rewriter, MlirOperation op)

Creates a deep copy of this operation but keep the operation regions empty.

MlirBlock mlirRewriterBaseGetBlock(MlirRewriterBase rewriter)

Returns the current block of the rewriter.

void mlirRewriterBaseClearInsertionPoint(MlirRewriterBase rewriter)

Insertion points methods.

void mlirRewriterBaseInlineRegionBefore(MlirRewriterBase rewriter, MlirRegion region, MlirBlock before)

RewriterBase API.

void mlirRewriterBaseReplaceOpWithOperation(MlirRewriterBase rewriter, MlirOperation op, MlirOperation newOp)

Replace the results of the given (original) operation with the specified new op (replacement).

void mlirRewriterBaseReplaceAllUsesWith(MlirRewriterBase rewriter, MlirValue from, MlirValue to)

Find uses of from and replace them with to.

MlirFrozenRewritePatternSet mlirFreezeRewritePattern(MlirRewritePatternSet op)

FrozenRewritePatternSet API.

void mlirRewriterBaseFinalizeOpModification(MlirRewriterBase rewriter, MlirOperation op)

This method is used to signal the end of an in-place modification of the given operation.

MlirRewriterBase mlirIRRewriterCreateFromOp(MlirOperation op)

Create an IRRewriter and transfer ownership to the caller.

void mlirRewriterBaseMoveOpBefore(MlirRewriterBase rewriter, MlirOperation op, MlirOperation existingOp)

Unlink this operation from its current block and insert it right before existingOp which may be in th...

void mlirRewriterBaseSetInsertionPointBefore(MlirRewriterBase rewriter, MlirOperation op)

Sets the insertion point to the specified operation, which will cause subsequent insertions to go rig...

MlirBlock mlirRewriterBaseGetInsertionBlock(MlirRewriterBase rewriter)

Return the block the current insertion point belongs to.

void mlirRewriterBaseEraseOp(MlirRewriterBase rewriter, MlirOperation op)

Erases an operation that is known to have no uses.

static MlirBlock createBlock(const nb::sequence &pyArgTypes, const std::optional< nb::sequence > &pyArgLocs)

Create a block, using the current location context if no locations are specified.

static MLIRContext * getContext(OpFoldResult val)

static llvm::ArrayRef< CppTy > unwrapList(size_t size, CTy *first, llvm::SmallVectorImpl< CppTy > &storage)

This class represents a frozen set of patterns that can be processed by a pattern applicator.

This class coordinates rewriting a piece of IR outside of a pattern rewrite, providing a way to keep ...

This class acts as an owning reference to an op, and will automatically destroy the held op on destru...

MLIR_CAPI_EXPORTED void mlirPDLPatternModuleDestroy(MlirPDLPatternModule op)

MLIR_CAPI_EXPORTED MlirPDLPatternModule mlirPDLPatternModuleFromModule(MlirModule op)

MLIR_CAPI_EXPORTED MlirRewritePatternSet mlirRewritePatternSetFromPDLPatternModule(MlirPDLPatternModule op)

Include the generated interface declarations.

LogicalResult applyPatternsGreedily(Region &region, const FrozenRewritePatternSet &patterns, GreedyRewriteConfig config=GreedyRewriteConfig(), bool *changed=nullptr)

Rewrite ops in the given region, which must be isolated from above, by repeatedly applying the highes...

Operation * cloneWithoutRegions(OpBuilder &b, Operation *op, TypeRange newResultTypes, ValueRange newOperands)

const FrozenRewritePatternSet & patterns

Operation * clone(OpBuilder &b, Operation *op, TypeRange newResultTypes, ValueRange newOperands)

A logical result value, essentially a boolean with named states.