MLIR  16.0.0git
Arith.h
Go to the documentation of this file.
1 //===- Arith.h - Arith dialect ------------------------------------*- C++-*-==//
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 #ifndef MLIR_DIALECT_ARITH_IR_ARITH_H_
10 #define MLIR_DIALECT_ARITH_IR_ARITH_H_
11 
12 #include "mlir/IR/Dialect.h"
13 #include "mlir/IR/OpDefinition.h"
20 #include "llvm/ADT/StringExtras.h"
21 
22 //===----------------------------------------------------------------------===//
23 // ArithDialect
24 //===----------------------------------------------------------------------===//
25 
26 #include "mlir/Dialect/Arith/IR/ArithOpsDialect.h.inc"
27 
28 //===----------------------------------------------------------------------===//
29 // Arith Dialect Enum Attributes
30 //===----------------------------------------------------------------------===//
31 
32 #include "mlir/Dialect/Arith/IR/ArithOpsEnums.h.inc"
33 #define GET_ATTRDEF_CLASSES
34 #include "mlir/Dialect/Arith/IR/ArithOpsAttributes.h.inc"
35 
36 //===----------------------------------------------------------------------===//
37 // Arith Interfaces
38 //===----------------------------------------------------------------------===//
39 #include "mlir/Dialect/Arith/IR/ArithOpsInterfaces.h.inc"
40 
41 //===----------------------------------------------------------------------===//
42 // Arith Dialect Operations
43 //===----------------------------------------------------------------------===//
44 
45 #define GET_OP_CLASSES
46 #include "mlir/Dialect/Arith/IR/ArithOps.h.inc"
47 
48 namespace mlir {
49 namespace arith {
50 
51 /// Specialization of `arith.constant` op that returns an integer value.
52 class ConstantIntOp : public arith::ConstantOp {
53 public:
54  using arith::ConstantOp::ConstantOp;
55 
56  /// Build a constant int op that produces an integer of the specified width.
57  static void build(OpBuilder &builder, OperationState &result, int64_t value,
58  unsigned width);
59 
60  /// Build a constant int op that produces an integer of the specified type,
61  /// which must be an integer type.
62  static void build(OpBuilder &builder, OperationState &result, int64_t value,
63  Type type);
64 
65  inline int64_t value() {
66  return arith::ConstantOp::getValue().cast<IntegerAttr>().getInt();
67  }
68 
69  static bool classof(Operation *op);
70 };
71 
72 /// Specialization of `arith.constant` op that returns a floating point value.
73 class ConstantFloatOp : public arith::ConstantOp {
74 public:
75  using arith::ConstantOp::ConstantOp;
76 
77  /// Build a constant float op that produces a float of the specified type.
78  static void build(OpBuilder &builder, OperationState &result,
79  const APFloat &value, FloatType type);
80 
81  inline APFloat value() {
82  return arith::ConstantOp::getValue().cast<FloatAttr>().getValue();
83  }
84 
85  static bool classof(Operation *op);
86 };
87 
88 /// Specialization of `arith.constant` op that returns an integer of index type.
89 class ConstantIndexOp : public arith::ConstantOp {
90 public:
91  using arith::ConstantOp::ConstantOp;
92 
93  /// Build a constant int op that produces an index.
94  static void build(OpBuilder &builder, OperationState &result, int64_t value);
95 
96  inline int64_t value() {
97  return arith::ConstantOp::getValue().cast<IntegerAttr>().getInt();
98  }
99 
100  static bool classof(Operation *op);
101 };
102 
103 } // namespace arith
104 } // namespace mlir
105 
106 //===----------------------------------------------------------------------===//
107 // Utility Functions
108 //===----------------------------------------------------------------------===//
109 
110 namespace mlir {
111 namespace arith {
112 
113 /// Compute `lhs` `pred` `rhs`, where `pred` is one of the known integer
114 /// comparison predicates.
115 bool applyCmpPredicate(arith::CmpIPredicate predicate, const APInt &lhs,
116  const APInt &rhs);
117 
118 /// Compute `lhs` `pred` `rhs`, where `pred` is one of the known floating point
119 /// comparison predicates.
120 bool applyCmpPredicate(arith::CmpFPredicate predicate, const APFloat &lhs,
121  const APFloat &rhs);
122 
123 /// Returns the identity value attribute associated with an AtomicRMWKind op.
124 Attribute getIdentityValueAttr(AtomicRMWKind kind, Type resultType,
125  OpBuilder &builder, Location loc);
126 
127 /// Returns the identity value associated with an AtomicRMWKind op.
128 Value getIdentityValue(AtomicRMWKind op, Type resultType, OpBuilder &builder,
129  Location loc);
130 
131 /// Returns the value obtained by applying the reduction operation kind
132 /// associated with a binary AtomicRMWKind op to `lhs` and `rhs`.
133 Value getReductionOp(AtomicRMWKind op, OpBuilder &builder, Location loc,
134  Value lhs, Value rhs);
135 
136 arith::CmpIPredicate invertPredicate(arith::CmpIPredicate pred);
137 } // namespace arith
138 } // namespace mlir
139 
140 #endif // MLIR_DIALECT_ARITH_IR_ARITH_H_
This class helps build Operations.
Definition: Builders.h:198
Operation is a basic unit of execution within MLIR.
Definition: Operation.h:31
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
Specialization of arith.constant op that returns a floating point value.
Definition: Arith.h:73
static void build(OpBuilder &builder, OperationState &result, const APFloat &value, FloatType type)
Build a constant float op that produces a float of the specified type.
Definition: ArithOps.cpp:168
static bool classof(Operation *op)
Definition: ArithOps.cpp:174
Specialization of arith.constant op that returns an integer of index type.
Definition: Arith.h:89
static void build(OpBuilder &builder, OperationState &result, int64_t value)
Build a constant int op that produces an index.
Definition: ArithOps.cpp:180
static bool classof(Operation *op)
Definition: ArithOps.cpp:186
Specialization of arith.constant op that returns an integer value.
Definition: Arith.h:52
static void build(OpBuilder &builder, OperationState &result, int64_t value, unsigned width)
Build a constant int op that produces an integer of the specified width.
Definition: ArithOps.cpp:147
static bool classof(Operation *op)
Definition: ArithOps.cpp:162
Value getIdentityValue(AtomicRMWKind op, Type resultType, OpBuilder &builder, Location loc)
Returns the identity value associated with an AtomicRMWKind op.
Definition: ArithOps.cpp:2208
bool applyCmpPredicate(arith::CmpIPredicate predicate, const APInt &lhs, const APInt &rhs)
Compute lhs pred rhs, where pred is one of the known integer comparison predicates.
Definition: ArithOps.cpp:1451
Attribute getIdentityValueAttr(AtomicRMWKind kind, Type resultType, OpBuilder &builder, Location loc)
Returns the identity value attribute associated with an AtomicRMWKind op.
Definition: ArithOps.cpp:2161
Value getReductionOp(AtomicRMWKind op, OpBuilder &builder, Location loc, Value lhs, Value rhs)
Returns the value obtained by applying the reduction operation kind associated with a binary AtomicRM...
Definition: ArithOps.cpp:2216
arith::CmpIPredicate invertPredicate(arith::CmpIPredicate pred)
Invert an integer comparison predicate.
Definition: ArithOps.cpp:46
Include the generated interface declarations.
This represents an operation in an abstracted form, suitable for use with the builder APIs.