1 /* Copyright 2019 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 // This file defines the operations used in the standard MLIR TensorFlow dialect 17 // after control dependences are raise to the standard form. 18 19 #ifndef TENSORFLOW_COMPILER_MLIR_TENSORFLOW_IR_TF_OPS_H_ 20 #define TENSORFLOW_COMPILER_MLIR_TENSORFLOW_IR_TF_OPS_H_ 21 22 #include "mlir/Analysis/CallInterfaces.h" // TF:llvm-project 23 #include "mlir/Dialect/Traits.h" // TF:llvm-project 24 #include "mlir/IR/Attributes.h" // TF:llvm-project 25 #include "mlir/IR/Builders.h" // TF:llvm-project 26 #include "mlir/IR/Dialect.h" // TF:llvm-project 27 #include "mlir/IR/Matchers.h" // TF:llvm-project 28 #include "mlir/IR/Module.h" // TF:llvm-project 29 #include "mlir/IR/OpImplementation.h" // TF:llvm-project 30 #include "mlir/IR/StandardTypes.h" // TF:llvm-project 31 #include "mlir/IR/TypeUtilities.h" // TF:llvm-project 32 #include "tensorflow/compiler/mlir/tensorflow/ir/tf_traits.h" 33 #include "tensorflow/compiler/mlir/tensorflow/ir/tf_types.h" 34 35 namespace mlir { 36 namespace TF { 37 38 class TensorFlowDialect : public Dialect { 39 public: 40 TensorFlowDialect(MLIRContext *context); 41 getDialectNamespace()42 static StringRef getDialectNamespace() { return "tf"; } 43 44 // Gradient attribute ("tf.gradient") in the list of NamedAttributes in a 45 // function references to its gradient function. This attribute in TensorFlow 46 // Dialect is used to model TF GradientDef. GetGradientAttrName() returns the 47 // string description of gradient attribute. GetGradientAttrName()48 static StringRef GetGradientAttrName() { return "tf.gradient"; } 49 50 // This attribute marks if a function is stateful. 51 // Returns the string description of stateful attribute. GetStatefulAttrName()52 static StringRef GetStatefulAttrName() { return "tf.signature.is_stateful"; } 53 54 // Parse a type registered to this dialect. 55 Type parseType(DialectAsmParser &parser) const override; 56 57 // Prints a type registered to this dialect. 58 void printType(Type ty, DialectAsmPrinter &os) const override; 59 60 // Parses resource type with potential subtypes. 61 Type ParseResourceType(DialectAsmParser &parser, Location loc) const; 62 63 // Prints resource type with potential subtypes. 64 void PrintResourceType(ResourceType ty, DialectAsmPrinter &os) const; 65 66 // Parse and print variant type. It may have subtypes inferred using shape 67 // inference. 68 Type ParseVariantType(DialectAsmParser &parser, Location loc) const; 69 void PrintVariantType(VariantType ty, DialectAsmPrinter &os) const; 70 71 // Registered hook to materialize a constant operation from a given attribute 72 // value with the desired resultant type. 73 Operation *materializeConstant(OpBuilder &builder, Attribute value, Type type, 74 Location loc) override; 75 }; 76 77 // TODO(b/131258166): TensorFlow's mutex.h defines a `mutex_lock` macro, whose 78 // purpose is to catch bug on `tensorflow::mutex_lock`. We don't use 79 // `tensorflow::mutex_lock` here but we have ops (`tf.MutexLock` and 80 // `tf.ConsumeMutexLock`) with getter methods named as `mutex_lock()`. Need to 81 // undefine here to avoid expanding the getter symbol as macro when including 82 // both mutex.h and this header file. 83 #undef mutex_lock 84 85 #define GET_OP_CLASSES 86 #include "tensorflow/compiler/mlir/tensorflow/ir/tf_ops.h.inc" 87 88 } // namespace TF 89 } // namespace mlir 90 91 #endif // TENSORFLOW_COMPILER_MLIR_TENSORFLOW_IR_TF_OPS_H_ 92