MLIR  18.0.0git
Go to the documentation of this file.
1 //===- Utils.h - General Arith transformation utilities ----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This header file defines prototypes for various transformation utilities for
10 // the Arith dialect. These are not passes by themselves but are used
11 // either by passes, optimization sequences, or in turn by other transformation
12 // utilities.
13 //
14 //===----------------------------------------------------------------------===//
20 #include "mlir/IR/Matchers.h"
21 #include "mlir/IR/PatternMatch.h"
22 #include "mlir/IR/Value.h"
24 namespace mlir {
26 /// Matches a ConstantIndexOp.
27 detail::op_matcher<arith::ConstantIndexOp> matchConstantIndex();
29 llvm::SmallBitVector getPositionsOfShapeOne(unsigned rank,
30  ArrayRef<int64_t> shape);
32 /// Converts an OpFoldResult to a Value. Returns the fold result if it casts to
33 /// a Value or creates a ConstantIndexOp if it casts to an IntegerAttribute.
34 /// Other attribute types are not supported.
35 Value getValueOrCreateConstantIndexOp(OpBuilder &b, Location loc,
36  OpFoldResult ofr);
38 /// Similar to the other overload, but converts multiple OpFoldResults into
39 /// Values.
40 SmallVector<Value>
41 getValueOrCreateConstantIndexOp(OpBuilder &b, Location loc,
42  ArrayRef<OpFoldResult> valueOrAttrVec);
44 /// Create a cast from an index-like value (index or integer) to another
45 /// index-like value. If the value type and the target type are the same, it
46 /// returns the original value.
47 Value getValueOrCreateCastToIndexLike(OpBuilder &b, Location loc,
48  Type targetType, Value value);
50 /// Converts a scalar value `operand` to type `toType`. If the value doesn't
51 /// convert, a warning will be issued and the operand is returned as is (which
52 /// will presumably yield a verification issue downstream).
53 Value convertScalarToDtype(OpBuilder &b, Location loc, Value operand,
54  Type toType, bool isUnsignedCast);
56 /// Helper struct to build simple arithmetic quantities with minimal type
57 /// inference support.
58 struct ArithBuilder {
59  ArithBuilder(OpBuilder &b, Location loc) : b(b), loc(loc) {}
61  Value _and(Value lhs, Value rhs);
62  Value add(Value lhs, Value rhs);
63  Value sub(Value lhs, Value rhs);
64  Value mul(Value lhs, Value rhs);
65  Value select(Value cmp, Value lhs, Value rhs);
66  Value sgt(Value lhs, Value rhs);
67  Value slt(Value lhs, Value rhs);
69 private:
70  OpBuilder &b;
71  Location loc;
72 };
73 } // namespace mlir
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
This class helps build Operations.
Definition: Builders.h:206
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:93
This header declares functions that assist transformations in the MemRef dialect.
Value convertScalarToDtype(OpBuilder &b, Location loc, Value operand, Type toType, bool isUnsignedCast)
Converts a scalar value operand to type toType.
Definition: Utils.cpp:168
Value getValueOrCreateCastToIndexLike(OpBuilder &b, Location loc, Type targetType, Value value)
Create a cast from an index-like value (index or integer) to another index-like value.
Definition: Utils.cpp:49
Value getValueOrCreateConstantIndexOp(OpBuilder &b, Location loc, OpFoldResult ofr)
Converts an OpFoldResult to a Value.
Definition: Utils.cpp:40
llvm::SmallBitVector getPositionsOfShapeOne(unsigned rank, ArrayRef< int64_t > shape)
Definition: Utils.cpp:28
detail::op_matcher< arith::ConstantIndexOp > matchConstantIndex()
Matches a ConstantIndexOp.
Definition: Utils.cpp:24
Helper struct to build simple arithmetic quantities with minimal type inference support.
Definition: Utils.h:58
Value mul(Value lhs, Value rhs)
Definition: Utils.cpp:213
Value _and(Value lhs, Value rhs)
Definition: Utils.cpp:200
Value slt(Value lhs, Value rhs)
Definition: Utils.cpp:223
ArithBuilder(OpBuilder &b, Location loc)
Definition: Utils.h:59
Value select(Value cmp, Value lhs, Value rhs)
Definition: Utils.cpp:228
Value add(Value lhs, Value rhs)
Definition: Utils.cpp:203
Value sgt(Value lhs, Value rhs)
Definition: Utils.cpp:218
Value sub(Value lhs, Value rhs)
Definition: Utils.cpp:208