Chris Lattner | 158e0a3e | 2018-07-08 20:51:38 -0700 | [diff] [blame] | 1 | //===- Builders.cpp - Helpers for constructing MLIR Classes ---------------===// |
| 2 | // |
| 3 | // Copyright 2019 The MLIR Authors. |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | // ============================================================================= |
| 17 | |
| 18 | #include "mlir/IR/Builders.h" |
| 19 | #include "mlir/IR/Module.h" |
| 20 | #include "mlir/IR/Types.h" |
| 21 | using namespace mlir; |
| 22 | |
| 23 | Builder::Builder(Module *module) : context(module->getContext()) {} |
| 24 | |
| 25 | // Types. |
| 26 | PrimitiveType *Builder::getAffineIntType() { |
| 27 | return Type::getAffineInt(context); |
| 28 | } |
| 29 | |
| 30 | PrimitiveType *Builder::getBF16Type() { return Type::getBF16(context); } |
| 31 | |
| 32 | PrimitiveType *Builder::getF16Type() { return Type::getF16(context); } |
| 33 | |
| 34 | PrimitiveType *Builder::getF32Type() { return Type::getF32(context); } |
| 35 | |
| 36 | PrimitiveType *Builder::getF64Type() { return Type::getF64(context); } |
| 37 | |
| 38 | IntegerType *Builder::getIntegerType(unsigned width) { |
| 39 | return Type::getInteger(width, context); |
| 40 | } |
| 41 | |
| 42 | FunctionType *Builder::getFunctionType(ArrayRef<Type *> inputs, |
| 43 | ArrayRef<Type *> results) { |
| 44 | return FunctionType::get(inputs, results, context); |
| 45 | } |
| 46 | |
| 47 | VectorType *Builder::getVectorType(ArrayRef<unsigned> shape, |
| 48 | Type *elementType) { |
| 49 | return VectorType::get(shape, elementType); |
| 50 | } |
| 51 | |
| 52 | RankedTensorType *Builder::getTensorType(ArrayRef<int> shape, |
| 53 | Type *elementType) { |
| 54 | return RankedTensorType::get(shape, elementType); |
| 55 | } |
| 56 | |
| 57 | UnrankedTensorType *Builder::getTensorType(Type *elementType) { |
| 58 | return UnrankedTensorType::get(elementType); |
| 59 | } |