MLIR  16.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"
19 
20 //===----------------------------------------------------------------------===//
21 // ArithmeticDialect
22 //===----------------------------------------------------------------------===//
23 
24 #include "mlir/Dialect/Arithmetic/IR/ArithmeticOpsDialect.h.inc"
25 
26 //===----------------------------------------------------------------------===//
27 // Arithmetic Dialect Enum Attributes
28 //===----------------------------------------------------------------------===//
29 
30 #include "mlir/Dialect/Arithmetic/IR/ArithmeticOpsEnums.h.inc"
31 
32 //===----------------------------------------------------------------------===//
33 // Arithmetic Dialect Operations
34 //===----------------------------------------------------------------------===//
35 
36 #define GET_OP_CLASSES
37 #include "mlir/Dialect/Arithmetic/IR/ArithmeticOps.h.inc"
38 
39 namespace mlir {
40 namespace arith {
41 
42 /// Specialization of `arith.constant` op that returns an integer value.
43 class ConstantIntOp : public arith::ConstantOp {
44 public:
45  using arith::ConstantOp::ConstantOp;
46 
47  /// Build a constant int op that produces an integer of the specified width.
48  static void build(OpBuilder &builder, OperationState &result, int64_t value,
49  unsigned width);
50 
51  /// Build a constant int op that produces an integer of the specified type,
52  /// which must be an integer type.
53  static void build(OpBuilder &builder, OperationState &result, int64_t value,
54  Type type);
55 
56  inline int64_t value() {
57  return arith::ConstantOp::getValue().cast<IntegerAttr>().getInt();
58  }
59 
60  static bool classof(Operation *op);
61 };
62 
63 /// Specialization of `arith.constant` op that returns a floating point value.
64 class ConstantFloatOp : public arith::ConstantOp {
65 public:
66  using arith::ConstantOp::ConstantOp;
67 
68  /// Build a constant float op that produces a float of the specified type.
69  static void build(OpBuilder &builder, OperationState &result,
70  const APFloat &value, FloatType type);
71 
72  inline APFloat value() {
73  return arith::ConstantOp::getValue().cast<FloatAttr>().getValue();
74  }
75 
76  static bool classof(Operation *op);
77 };
78 
79 /// Specialization of `arith.constant` op that returns an integer of index type.
80 class ConstantIndexOp : public arith::ConstantOp {
81 public:
82  using arith::ConstantOp::ConstantOp;
83 
84  /// Build a constant int op that produces an index.
85  static void build(OpBuilder &builder, OperationState &result, int64_t value);
86 
87  inline int64_t value() {
88  return arith::ConstantOp::getValue().cast<IntegerAttr>().getInt();
89  }
90 
91  static bool classof(Operation *op);
92 };
93 
94 } // namespace arith
95 } // namespace mlir
96 
97 //===----------------------------------------------------------------------===//
98 // Utility Functions
99 //===----------------------------------------------------------------------===//
100 
101 namespace mlir {
102 namespace arith {
103 
104 /// Compute `lhs` `pred` `rhs`, where `pred` is one of the known integer
105 /// comparison predicates.
106 bool applyCmpPredicate(arith::CmpIPredicate predicate, const APInt &lhs,
107  const APInt &rhs);
108 
109 /// Compute `lhs` `pred` `rhs`, where `pred` is one of the known floating point
110 /// comparison predicates.
111 bool applyCmpPredicate(arith::CmpFPredicate predicate, const APFloat &lhs,
112  const APFloat &rhs);
113 
114 /// Returns the identity value attribute associated with an AtomicRMWKind op.
115 Attribute getIdentityValueAttr(AtomicRMWKind kind, Type resultType,
116  OpBuilder &builder, Location loc);
117 
118 /// Returns the identity value associated with an AtomicRMWKind op.
119 Value getIdentityValue(AtomicRMWKind op, Type resultType, OpBuilder &builder,
120  Location loc);
121 
122 /// Returns the value obtained by applying the reduction operation kind
123 /// associated with a binary AtomicRMWKind op to `lhs` and `rhs`.
124 Value getReductionOp(AtomicRMWKind op, OpBuilder &builder, Location loc,
125  Value lhs, Value rhs);
126 
127 arith::CmpIPredicate invertPredicate(arith::CmpIPredicate pred);
128 } // namespace arith
129 } // namespace mlir
130 
131 #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:43
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:25
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:74
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:64
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:80
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:196