blob: a03f4b84425e54bd3c615525b643b48aa1b590e6 [file] [log] [blame]
Chris Lattner158e0a3e2018-07-08 20:51:38 -07001//===- 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"
21using namespace mlir;
22
23Builder::Builder(Module *module) : context(module->getContext()) {}
24
25// Types.
26PrimitiveType *Builder::getAffineIntType() {
27 return Type::getAffineInt(context);
28}
29
30PrimitiveType *Builder::getBF16Type() { return Type::getBF16(context); }
31
32PrimitiveType *Builder::getF16Type() { return Type::getF16(context); }
33
34PrimitiveType *Builder::getF32Type() { return Type::getF32(context); }
35
36PrimitiveType *Builder::getF64Type() { return Type::getF64(context); }
37
38IntegerType *Builder::getIntegerType(unsigned width) {
39 return Type::getInteger(width, context);
40}
41
42FunctionType *Builder::getFunctionType(ArrayRef<Type *> inputs,
43 ArrayRef<Type *> results) {
44 return FunctionType::get(inputs, results, context);
45}
46
47VectorType *Builder::getVectorType(ArrayRef<unsigned> shape,
48 Type *elementType) {
49 return VectorType::get(shape, elementType);
50}
51
52RankedTensorType *Builder::getTensorType(ArrayRef<int> shape,
53 Type *elementType) {
54 return RankedTensorType::get(shape, elementType);
55}
56
57UnrankedTensorType *Builder::getTensorType(Type *elementType) {
58 return UnrankedTensorType::get(elementType);
59}