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