MLIR 22.0.0git
EmulateNarrowType.cpp
Go to the documentation of this file.
1//===- EmulateNarrowType.cpp - Narrow type emulation ----*- C++
2//-*-===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
11
18#include "llvm/Support/MathExtras.h"
19#include <cassert>
20
21using namespace mlir;
22
23//===----------------------------------------------------------------------===//
24// Public Interface Definition
25//===----------------------------------------------------------------------===//
26
28 unsigned targetBitwidth)
29 : loadStoreBitwidth(targetBitwidth) {
30 assert(llvm::isPowerOf2_32(targetBitwidth) &&
31 "Only power-of-two integers are supported");
32
33 // Allow unknown types.
34 addConversion([](Type ty) -> std::optional<Type> { return ty; });
35
36 // Function case.
37 addConversion([this](FunctionType ty) -> std::optional<Type> {
38 SmallVector<Type> inputs;
39 if (failed(convertTypes(ty.getInputs(), inputs)))
40 return nullptr;
41
42 SmallVector<Type> results;
43 if (failed(convertTypes(ty.getResults(), results)))
44 return nullptr;
45
46 return FunctionType::get(ty.getContext(), inputs, results);
47 });
48}
49
51 const NarrowTypeEmulationConverter &typeConverter,
53 // Populate `func.*` conversion patterns.
54 populateFunctionOpInterfaceTypeConversionPattern<func::FuncOp>(patterns,
55 typeConverter);
58}
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
Definition Types.cpp:35
Converts narrow integer or float types that are not supported by the target hardware to wider types.
NarrowTypeEmulationConverter(unsigned targetBitwidth)
void populateArithNarrowTypeEmulationPatterns(const NarrowTypeEmulationConverter &typeConverter, RewritePatternSet &patterns)
Adds patterns to emulate narrow Arith and Function ops into wide supported types.
Include the generated interface declarations.
void populateReturnOpTypeConversionPattern(RewritePatternSet &patterns, const TypeConverter &converter, PatternBenefit benefit=1)
Add a pattern to the given pattern list to rewrite return ops to use operands that have been legalize...
void populateCallOpTypeConversionPattern(RewritePatternSet &patterns, const TypeConverter &converter, PatternBenefit benefit=1)
Add a pattern to the given pattern list to convert the operand and result types of a CallOp with the ...
const FrozenRewritePatternSet & patterns