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> lowerConstArrayAttr(
38 cir::ConstArrayAttr constArr, mlir::SymbolTableCollection &symbolTables,
39 const mlir::TypeConverter *converter, mlir::ModuleOp moduleOp = {});
40
41std::optional<mlir::Attribute> lowerConstRecordAttr(
42 cir::ConstRecordAttr constRecord, mlir::SymbolTableCollection &symbolTables,
43 const mlir::TypeConverter *converter, mlir::ModuleOp moduleOp = {});
44
45/// Adjust \p llvmType (the converted type of \p init) to the concrete LLVM type
46/// a global constant initialized with \p init actually lowers to. This differs
47/// from a plain type conversion for flexible-array-member and union
48/// initializers, and the adjustment recurses through nested aggregates. Returns
49/// \p llvmType unchanged when no adjustment is needed. This is the single
50/// source of truth for the shape of a lowered record constant; the
51/// value-producing paths (the insertvalue visitor and lowerConstRecordAttr)
52/// conform to it.
53mlir::Type adjustGlobalTypeForInit(mlir::Type llvmType, mlir::Attribute init,
54 const mlir::TypeConverter &converter,
55 const mlir::DataLayout &dataLayout);
56
57mlir::Value getConstAPInt(mlir::OpBuilder &bld, mlir::Location loc,
58 mlir::Type typ, const llvm::APInt &val);
59
60mlir::Value getConst(mlir::OpBuilder &bld, mlir::Location loc, mlir::Type typ,
61 unsigned val);
62
63mlir::Value createShL(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs);
64
65mlir::Value createAShR(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs);
66
67mlir::Value createAnd(mlir::OpBuilder &bld, mlir::Value lhs,
68 const llvm::APInt &rhs);
69
70mlir::Value createLShR(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs);
71#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)
std::optional< mlir::Attribute > lowerConstRecordAttr(cir::ConstRecordAttr constRecord, mlir::SymbolTableCollection &symbolTables, const mlir::TypeConverter *converter, mlir::ModuleOp moduleOp={})
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)
void convertToDenseElementsAttrImpl(cir::ConstArrayAttr attr, llvm::SmallVectorImpl< StorageTy > &values)
std::optional< mlir::Attribute > lowerConstArrayAttr(cir::ConstArrayAttr constArr, mlir::SymbolTableCollection &symbolTables, const mlir::TypeConverter *converter, mlir::ModuleOp moduleOp={})