1 | //====- LoweringHelpers.h - Lowering helper functions ---------------------===// |
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 | // |
9 | // This file declares helper functions for lowering from CIR to LLVM or MLIR. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | #ifndef LLVM_CLANG_CIR_LOWERINGHELPERS_H |
13 | #define LLVM_CLANG_CIR_LOWERINGHELPERS_H |
14 | |
15 | #include "mlir/IR/BuiltinAttributes.h" |
16 | #include "mlir/Transforms/DialectConversion.h" |
17 | #include "clang/CIR/Dialect/IR/CIRDialect.h" |
18 | |
19 | mlir::DenseElementsAttr |
20 | convertStringAttrToDenseElementsAttr(cir::ConstArrayAttr attr, mlir::Type type); |
21 | |
22 | template <typename StorageTy> StorageTy getZeroInitFromType(mlir::Type ty); |
23 | template <> mlir::APInt getZeroInitFromType(mlir::Type ty); |
24 | template <> mlir::APFloat getZeroInitFromType(mlir::Type ty); |
25 | |
26 | template <typename AttrTy, typename StorageTy> |
27 | void convertToDenseElementsAttrImpl(cir::ConstArrayAttr attr, |
28 | llvm::SmallVectorImpl<StorageTy> &values); |
29 | |
30 | template <typename AttrTy, typename StorageTy> |
31 | mlir::DenseElementsAttr |
32 | convertToDenseElementsAttr(cir::ConstArrayAttr attr, |
33 | const llvm::SmallVectorImpl<int64_t> &dims, |
34 | mlir::Type type); |
35 | |
36 | std::optional<mlir::Attribute> |
37 | lowerConstArrayAttr(cir::ConstArrayAttr constArr, |
38 | const mlir::TypeConverter *converter); |
39 | |
40 | #endif |
41 | |