1//===- LoweringOptions.h - Common config for lowering to LLVM ---*- 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//
9// Provides a configuration shared by several conversions targeting the LLVM
10// dialect.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_CONVERSION_LLVMCOMMON_LOWERINGOPTIONS_H
15#define MLIR_CONVERSION_LLVMCOMMON_LOWERINGOPTIONS_H
16
17#include "llvm/IR/DataLayout.h"
18
19namespace mlir {
20
21class DataLayout;
22class MLIRContext;
23
24/// Value to pass as bitwidth for the index type when the converter is expected
25/// to derive the bitwidth from the LLVM data layout.
26static constexpr unsigned kDeriveIndexBitwidthFromDataLayout = 0;
27
28/// Options to control the LLVM lowering. The struct is used to share lowering
29/// options between passes, patterns, and type converter.
30class LowerToLLVMOptions {
31public:
32 explicit LowerToLLVMOptions(MLIRContext *ctx);
33 LowerToLLVMOptions(MLIRContext *ctx, const DataLayout &dl);
34
35 bool useBarePtrCallConv = false;
36
37 enum class AllocLowering {
38 /// Use malloc for heap allocations.
39 Malloc,
40
41 /// Use aligned_alloc for heap allocations.
42 AlignedAlloc,
43
44 /// Do not lower heap allocations. Users must provide their own patterns for
45 /// AllocOp and DeallocOp lowering.
46 None
47 };
48
49 AllocLowering allocLowering = AllocLowering::Malloc;
50
51 bool useGenericFunctions = false;
52
53 /// The data layout of the module to produce. This must be consistent with the
54 /// data layout used in the upper levels of the lowering pipeline.
55 // TODO: this should be replaced by MLIR data layout when one exists.
56 llvm::DataLayout dataLayout = llvm::DataLayout("");
57
58 /// Set the index bitwidth to the given value.
59 void overrideIndexBitwidth(unsigned bitwidth) {
60 assert(bitwidth != kDeriveIndexBitwidthFromDataLayout &&
61 "can only override to a concrete bitwidth");
62 indexBitwidth = bitwidth;
63 }
64
65 /// Get the index bitwidth.
66 unsigned getIndexBitwidth() const { return indexBitwidth; }
67
68private:
69 unsigned indexBitwidth;
70};
71
72} // namespace mlir
73
74#endif // MLIR_CONVERSION_LLVMCOMMON_LOWERINGOPTIONS_H
75

source code of mlir/include/mlir/Conversion/LLVMCommon/LoweringOptions.h