1 //===- FoldedIntrinsics.h - MLIR EDSC Intrinsics for Linalg -----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef MLIR_DIALECT_LINALG_EDSC_FOLDEDINTRINSICS_H_
9 #define MLIR_DIALECT_LINALG_EDSC_FOLDEDINTRINSICS_H_
10 
11 #include "mlir/Dialect/Linalg/EDSC/Builders.h"
12 #include "mlir/Dialect/Linalg/EDSC/Intrinsics.h"
13 
14 #include "mlir/Transforms/FoldUtils.h"
15 
16 namespace mlir {
17 namespace edsc {
18 namespace intrinsics {
19 
20 template <typename Op>
21 struct FoldedValueBuilder {
22   // Builder-based
23   template <typename... Args>
FoldedValueBuilderFoldedValueBuilder24   FoldedValueBuilder(OperationFolder *folder, Args... args) {
25     value = folder ? folder->create<Op>(ScopedContext::getBuilderRef(),
26                                         ScopedContext::getLocation(), args...)
27                    : ScopedContext::getBuilderRef().create<Op>(
28                          ScopedContext::getLocation(), args...);
29   }
30 
ValueFoldedValueBuilder31   operator Value() { return value; }
32   Value value;
33 };
34 
35 using folded_std_constant_index = FoldedValueBuilder<ConstantIndexOp>;
36 using folded_std_constant_float = FoldedValueBuilder<ConstantFloatOp>;
37 using folded_std_constant_int = FoldedValueBuilder<ConstantIntOp>;
38 using folded_std_constant = FoldedValueBuilder<ConstantOp>;
39 using folded_std_dim = FoldedValueBuilder<DimOp>;
40 using folded_std_muli = FoldedValueBuilder<MulIOp>;
41 using folded_std_addi = FoldedValueBuilder<AddIOp>;
42 using folded_std_addf = FoldedValueBuilder<AddFOp>;
43 using folded_std_alloc = FoldedValueBuilder<AllocOp>;
44 using folded_std_constant = FoldedValueBuilder<ConstantOp>;
45 using folded_std_constant_float = FoldedValueBuilder<ConstantFloatOp>;
46 using folded_std_constant_index = FoldedValueBuilder<ConstantIndexOp>;
47 using folded_std_constant_int = FoldedValueBuilder<ConstantIntOp>;
48 using folded_std_dim = FoldedValueBuilder<DimOp>;
49 using folded_std_extract_element = FoldedValueBuilder<ExtractElementOp>;
50 using folded_std_index_cast = FoldedValueBuilder<IndexCastOp>;
51 using folded_std_muli = FoldedValueBuilder<MulIOp>;
52 using folded_std_mulf = FoldedValueBuilder<MulFOp>;
53 using folded_std_memref_cast = FoldedValueBuilder<MemRefCastOp>;
54 using folded_std_select = FoldedValueBuilder<SelectOp>;
55 using folded_std_load = FoldedValueBuilder<LoadOp>;
56 using folded_std_subi = FoldedValueBuilder<SubIOp>;
57 using folded_std_sub_view = FoldedValueBuilder<SubViewOp>;
58 using folded_std_tanh = FoldedValueBuilder<TanhOp>;
59 using folded_std_tensor_load = FoldedValueBuilder<TensorLoadOp>;
60 using folded_std_view = FoldedValueBuilder<ViewOp>;
61 using folded_std_zero_extendi = FoldedValueBuilder<ZeroExtendIOp>;
62 using folded_std_sign_extendi = FoldedValueBuilder<SignExtendIOp>;
63 } // namespace intrinsics
64 } // namespace edsc
65 } // namespace mlir
66 
67 #endif // MLIR_DIALECT_LINALG_EDSC_FOLDEDINTRINSICS_H_
68