1 /* Copyright 2021 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 #include "tensorflow/core/runtime_fallback/opdefs/tfrt_fallback.h" 16 17 #include "mlir/IR/BuiltinTypes.h" // from @llvm-project 18 #include "mlir/IR/DialectImplementation.h" // from @llvm-project 19 #include "mlir/IR/OpDefinition.h" // from @llvm-project 20 #include "mlir/IR/TypeUtilities.h" // from @llvm-project 21 22 namespace tfrt { 23 namespace fallback { 24 FallbackDialect(MLIRContext * context)25FallbackDialect::FallbackDialect(MLIRContext *context) 26 : Dialect(/*name=*/"tfrt_fallback", context, 27 TypeID::get<FallbackDialect>()) { 28 addTypes<TFTensorType>(); 29 30 addOperations< 31 #define GET_OP_LIST 32 #include "tensorflow/core/runtime_fallback/opdefs/tfrt_fallback.cpp.inc" 33 >(); 34 } 35 36 /// Parse a type registered to this dialect. parseType(DialectAsmParser & parser) const37Type FallbackDialect::parseType(DialectAsmParser &parser) const { 38 StringRef keyword; 39 if (parser.parseKeyword(&keyword)) return Type(); 40 41 if (keyword == "tf_tensor") return TFTensorType::get(getContext()); 42 43 parser.emitError(parser.getNameLoc(), "unknown type: ") << keyword; 44 return Type(); 45 } 46 47 /// Print a type registered to this dialect. printType(Type type,DialectAsmPrinter & os) const48void FallbackDialect::printType(Type type, DialectAsmPrinter &os) const { 49 if (type.isa<TFTensorType>()) { 50 os << "tf_tensor"; 51 return; 52 } 53 54 llvm_unreachable("unexpected fallback type kind"); 55 } 56 57 } // namespace fallback 58 } // namespace tfrt 59 60 //===----------------------------------------------------------------------===// 61 // TableGen'd op method definitions 62 //===----------------------------------------------------------------------===// 63 64 #define GET_OP_CLASSES 65 #include "tensorflow/core/runtime_fallback/opdefs/tfrt_fallback.cpp.inc" 66