• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_COMPILER_MLIR_HLO_INCLUDE_MLIR_HLO_DIALECT_MHLO_IR_CHLO_OPS_H_
17 #define TENSORFLOW_COMPILER_MLIR_HLO_INCLUDE_MLIR_HLO_DIALECT_MHLO_IR_CHLO_OPS_H_
18 
19 #include "llvm/ADT/StringRef.h"
20 #include "mlir-hlo/Dialect/mhlo/IR/infer_fusibility_op_interface.h"
21 #include "mlir/IR/BuiltinTypes.h"
22 #include "mlir/IR/Dialect.h"
23 #include "mlir/IR/DialectImplementation.h"
24 #include "mlir/IR/MLIRContext.h"
25 #include "mlir/IR/OpDefinition.h"
26 #include "mlir/IR/Operation.h"
27 #include "mlir/IR/TypeUtilities.h"
28 #include "mlir/IR/Types.h"
29 #include "mlir/Interfaces/InferTypeOpInterface.h"
30 #include "mlir/Interfaces/SideEffectInterfaces.h"
31 
32 namespace mlir {
33 namespace chlo {
34 
35 class HloClientDialect : public Dialect {
36   void initialize();
37 
38  public:
HloClientDialect(MLIRContext * context)39   explicit HloClientDialect(MLIRContext* context)
40       : Dialect(getDialectNamespace(), context,
41                 TypeID::get<HloClientDialect>()) {
42     initialize();
43   }
getDialectNamespace()44   static StringRef getDialectNamespace() { return "chlo"; }
45 };
46 
47 }  // namespace chlo
48 }  // namespace mlir
49 
50 #define GET_OP_CLASSES
51 #include "mlir-hlo/Dialect/mhlo/IR/chlo_ops.h.inc"
52 
53 namespace mlir {
54 namespace chlo {
55 
56 template <typename T>
getConstantLike(OpBuilder & b,Location loc,T constant,Value val)57 static Value getConstantLike(OpBuilder& b, Location loc, T constant,
58                              Value val) {
59   Type ty = getElementTypeOrSelf(val.getType());
60 
61   auto getAttr = [&]() -> Attribute {
62     if (ty.isa<IntegerType>()) return b.getIntegerAttr(ty, constant);
63     if (ty.isa<FloatType>()) return b.getFloatAttr(ty, constant);
64     llvm_unreachable("unhandled element type");
65   };
66   return b.create<ConstantLikeOp>(loc, getAttr(), val);
67 }
68 
69 Value getConstantLike(OpBuilder& b, Location loc, const APFloat& constant,
70                       Value val);
71 
72 Value getConstantLikeMaxFiniteValue(OpBuilder& b, Location loc, Value val);
73 
74 Value getConstantLikeInfValue(OpBuilder& b, Location loc, Value val,
75                               bool negative);
76 
77 Value getConstantLikeSmallestFiniteValue(OpBuilder& b, Location loc, Value val);
78 
79 }  // namespace chlo
80 }  // namespace mlir
81 
82 #endif  // TENSORFLOW_COMPILER_MLIR_HLO_INCLUDE_MLIR_HLO_DIALECT_MHLO_IR_CHLO_OPS_H_
83