MLIR  19.0.0git
TypeConsistency.h
Go to the documentation of this file.
1 //===- TypeConsistency.h - Rewrites to improve type consistency -----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Set of rewrites to improve the coherency of types within an LLVM dialect
10 // program. This will adjust operations around a given pointer so they interpret
11 // its pointee type as consistently as possible.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef MLIR_DIALECT_LLVMIR_TRANSFORMS_TYPECONSISTENCY_H
16 #define MLIR_DIALECT_LLVMIR_TRANSFORMS_TYPECONSISTENCY_H
17 
19 #include "mlir/IR/PatternMatch.h"
20 #include "mlir/Pass/Pass.h"
21 
22 namespace mlir {
23 namespace LLVM {
24 
25 #define GEN_PASS_DECL_LLVMTYPECONSISTENCY
26 #include "mlir/Dialect/LLVMIR/Transforms/Passes.h.inc"
27 
28 /// Creates a pass that adjusts operations operating on pointers so they
29 /// interpret pointee types as consistently as possible.
30 std::unique_ptr<Pass> createTypeConsistencyPass();
31 
32 /// Canonicalizes GEPs of which the base type and the pointer's type hint do not
33 /// match. This is done by replacing the original GEP into a GEP with the type
34 /// hint as a base type when an element of the hinted type aligns with the
35 /// original GEP.
37 public:
39 
41  PatternRewriter &rewriter) const override;
42 };
43 
44 /// Splits stores which write into multiple adjacent elements of an aggregate
45 /// through a pointer. Currently, integers and vector are split and stores
46 /// are generated for every element being stored to in a type-consistent manner.
47 /// This is done on a best-effort basis.
48 class SplitStores : public OpRewritePattern<StoreOp> {
49  unsigned maxVectorSplitSize;
50 
51 public:
52  SplitStores(MLIRContext *context, unsigned maxVectorSplitSize)
53  : OpRewritePattern(context), maxVectorSplitSize(maxVectorSplitSize) {}
54 
55  LogicalResult matchAndRewrite(StoreOp store,
56  PatternRewriter &rewrite) const override;
57 };
58 
59 /// Splits GEPs with more than two indices into multiple GEPs with exactly
60 /// two indices. The created GEPs are then guaranteed to index into only
61 /// one aggregate at a time.
62 class SplitGEP : public OpRewritePattern<GEPOp> {
63 public:
65 
66  LogicalResult matchAndRewrite(GEPOp gepOp,
67  PatternRewriter &rewriter) const override;
68 };
69 
70 } // namespace LLVM
71 } // namespace mlir
72 
73 #endif // MLIR_DIALECT_LLVMIR_TRANSFORMS_TYPECONSISTENCY_H
Canonicalizes GEPs of which the base type and the pointer's type hint do not match.
LogicalResult matchAndRewrite(GEPOp gep, PatternRewriter &rewriter) const override
Splits GEPs with more than two indices into multiple GEPs with exactly two indices.
LogicalResult matchAndRewrite(GEPOp gepOp, PatternRewriter &rewriter) const override
Splits stores which write into multiple adjacent elements of an aggregate through a pointer.
SplitStores(MLIRContext *context, unsigned maxVectorSplitSize)
LogicalResult matchAndRewrite(StoreOp store, PatternRewriter &rewrite) const override
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
Definition: PatternMatch.h:785
std::unique_ptr< Pass > createTypeConsistencyPass()
Creates a pass that adjusts operations operating on pointers so they interpret pointee types as consi...
Include the generated interface declarations.
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...
Definition: PatternMatch.h:358
OpRewritePattern(MLIRContext *context, PatternBenefit benefit=1, ArrayRef< StringRef > generatedNames={})
Patterns must specify the root operation name they match against, and can also specify the benefit of...
Definition: PatternMatch.h:362
void rewrite(Operation *op, PatternRewriter &rewriter) const final
Wrappers around the RewritePattern methods that pass the derived op type.
Definition: PatternMatch.h:323