clang 24.0.0git
LoweringHelpers.h
Go to the documentation of this file.
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/Interfaces/DataLayoutInterfaces.h"
17#include "mlir/Transforms/DialectConversion.h"
19
20mlir::DenseElementsAttr
21convertStringAttrToDenseElementsAttr(cir::ConstArrayAttr attr, mlir::Type type);
22
23template <typename StorageTy> StorageTy getZeroInitFromType(mlir::Type ty);
24template <> mlir::APInt getZeroInitFromType(mlir::Type ty);
25template <> mlir::APFloat getZeroInitFromType(mlir::Type ty);
26
27template <typename AttrTy, typename StorageTy>
28void convertToDenseElementsAttrImpl(cir::ConstArrayAttr attr,
30
31template <typename AttrTy, typename StorageTy>
32mlir::DenseElementsAttr
33convertToDenseElementsAttr(cir::ConstArrayAttr attr,
35 mlir::Type type);
36
37std::optional<mlir::Attribute>
38lowerConstArrayAttr(cir::ConstArrayAttr constArr,
39 const mlir::TypeConverter *converter,
40 mlir::ModuleOp moduleOp = {});
41
42std::optional<mlir::Attribute>
43lowerConstRecordAttr(cir::ConstRecordAttr constRecord,
44 const mlir::TypeConverter *converter,
45 mlir::ModuleOp moduleOp = {});
46
47/// Adjust \p llvmType (the converted type of \p init) to the concrete LLVM type
48/// a global constant initialized with \p init actually lowers to. This differs
49/// from a plain type conversion for flexible-array-member and union
50/// initializers, and the adjustment recurses through nested aggregates. Returns
51/// \p llvmType unchanged when no adjustment is needed. This is the single
52/// source of truth for the shape of a lowered record constant; the
53/// value-producing paths (the insertvalue visitor and lowerConstRecordAttr)
54/// conform to it.
55mlir::Type adjustGlobalTypeForInit(mlir::Type llvmType, mlir::Attribute init,
56 const mlir::TypeConverter &converter,
57 const mlir::DataLayout &dataLayout);
58
59mlir::Value getConstAPInt(mlir::OpBuilder &bld, mlir::Location loc,
60 mlir::Type typ, const llvm::APInt &val);
61
62mlir::Value getConst(mlir::OpBuilder &bld, mlir::Location loc, mlir::Type typ,
63 unsigned val);
64
65mlir::Value createShL(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs);
66
67mlir::Value createAShR(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs);
68
69mlir::Value createAnd(mlir::OpBuilder &bld, mlir::Value lhs,
70 const llvm::APInt &rhs);
71
72mlir::Value createLShR(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs);
73#endif
mlir::DenseElementsAttr convertStringAttrToDenseElementsAttr(cir::ConstArrayAttr attr, mlir::Type type)
mlir::Value createLShR(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs)
mlir::Value createShL(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs)
mlir::Value getConst(mlir::OpBuilder &bld, mlir::Location loc, mlir::Type typ, unsigned val)
mlir::Value getConstAPInt(mlir::OpBuilder &bld, mlir::Location loc, mlir::Type typ, const llvm::APInt &val)
mlir::Type adjustGlobalTypeForInit(mlir::Type llvmType, mlir::Attribute init, const mlir::TypeConverter &converter, const mlir::DataLayout &dataLayout)
Adjust llvmType (the converted type of init) to the concrete LLVM type a global constant initialized ...
mlir::DenseElementsAttr convertToDenseElementsAttr(cir::ConstArrayAttr attr, const llvm::SmallVectorImpl< int64_t > &dims, mlir::Type type)
mlir::Value createAShR(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs)
StorageTy getZeroInitFromType(mlir::Type ty)
mlir::Value createAnd(mlir::OpBuilder &bld, mlir::Value lhs, const llvm::APInt &rhs)
std::optional< mlir::Attribute > lowerConstArrayAttr(cir::ConstArrayAttr constArr, const mlir::TypeConverter *converter, mlir::ModuleOp moduleOp={})
void convertToDenseElementsAttrImpl(cir::ConstArrayAttr attr, llvm::SmallVectorImpl< StorageTy > &values)
std::optional< mlir::Attribute > lowerConstRecordAttr(cir::ConstRecordAttr constRecord, const mlir::TypeConverter *converter, mlir::ModuleOp moduleOp={})