CIRCT 23.0.0git
Loading...
Searching...
No Matches
HWToLLVM.h
Go to the documentation of this file.
1//===- HWToLLVM.h - HW to LLVM pass entry point -----------------*- 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// This header file defines prototypes that expose the HWToLLVM pass
10// constructors.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef CIRCT_CONVERSION_HWTOLLVM_HWTOLLVM_H
15#define CIRCT_CONVERSION_HWTOLLVM_HWTOLLVM_H
16
18#include "circt/Support/LLVM.h"
19#include "mlir/Interfaces/DataLayoutInterfaces.h"
20#include <memory>
21
22namespace mlir {
23class LLVMTypeConverter;
24namespace LLVM {
25class GlobalOp;
26} // namespace LLVM
27} // namespace mlir
28
29namespace circt {
30
31#define GEN_PASS_DECL_CONVERTHWTOLLVM
32#include "circt/Conversion/Passes.h.inc"
33
34class Namespace;
35
37 /// Convert an index into a HW ArrayType or StructType to LLVM Endianess.
38 static uint32_t convertToLLVMEndianess(Type type, uint32_t index);
39
40 /// Get the index of a specific StructType field in the LLVM lowering of the
41 /// StructType
42 static uint32_t llvmIndexOfStructField(hw::StructType type,
43 StringRef fieldName);
44};
45
46/// Helper class mapping array values (HW or LLVM Dialect) to pointers to
47/// buffers containing the array value.
49 /// Spill HW array values produced by 'foreign' dialects on the stack.
50 /// The converter is used to map HW array types to the corresponding
51 /// LLVM array types. Should be called before dialect conversion.
52 void spillNonHWOps(mlir::OpBuilder &builder,
53 mlir::LLVMTypeConverter &converter,
54 Operation *containerOp);
55
56 /// Map an LLVM array value to an LLVM pointer.
57 /// For the entire lifetime of the array value the pointer must
58 /// refer to a valid buffer containing the respective array value.
59 void map(mlir::Value arrayValue, mlir::Value bufferPtr);
60
61 /// Retrieve a pointer to a buffer containing the given array
62 /// value (HW or LLVM Dialect). The buffer must not be modified or
63 /// deallocated. Returns a null value if no buffer has been mapped.
64 Value lookup(Value arrayValue);
65
66private:
67 Value spillLLVMArrayValue(OpBuilder &builder, Location loc, Value llvmArray);
68 Value spillHWArrayValue(OpBuilder &builder, Location loc,
69 mlir::LLVMTypeConverter &converter, Value hwArray);
70
71 llvm::DenseMap<Value, Value> spillMap;
72};
73
74/// Get the HW to LLVM type conversions.
75void populateHWToLLVMTypeConversions(mlir::LLVMTypeConverter &converter,
76 mlir::DataLayout &layout);
77
78/// Get the HW to LLVM conversion patterns.
79/// Note: The spill cache may only be used when conversion
80/// pattern rollback is disabled.
82 mlir::LLVMTypeConverter &converter, RewritePatternSet &patterns,
83 Namespace &globals,
84 DenseMap<std::pair<Type, ArrayAttr>, mlir::LLVM::GlobalOp>
85 &constAggregateGlobalsMap,
86 std::optional<HWToLLVMArraySpillCache> &spillCacheOpt);
87
88} // namespace circt
89
90#endif // CIRCT_CONVERSION_HWTOLLVM_HWTOLLVM_H
A namespace that is used to store existing names and generate new names in some scope within the IR.
Definition Namespace.h:30
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
void populateHWToLLVMTypeConversions(mlir::LLVMTypeConverter &converter, mlir::DataLayout &layout)
Get the HW to LLVM type conversions.
void populateHWToLLVMConversionPatterns(mlir::LLVMTypeConverter &converter, RewritePatternSet &patterns, Namespace &globals, DenseMap< std::pair< Type, ArrayAttr >, mlir::LLVM::GlobalOp > &constAggregateGlobalsMap, std::optional< HWToLLVMArraySpillCache > &spillCacheOpt)
Get the HW to LLVM conversion patterns.
Helper class mapping array values (HW or LLVM Dialect) to pointers to buffers containing the array va...
Definition HWToLLVM.h:48
Value spillHWArrayValue(OpBuilder &builder, Location loc, mlir::LLVMTypeConverter &converter, Value hwArray)
Definition HWToLLVM.cpp:185
Value lookup(Value arrayValue)
Retrieve a pointer to a buffer containing the given array value (HW or LLVM Dialect).
Definition HWToLLVM.cpp:152
void spillNonHWOps(mlir::OpBuilder &builder, mlir::LLVMTypeConverter &converter, Operation *containerOp)
Spill HW array values produced by 'foreign' dialects on the stack.
Definition HWToLLVM.cpp:110
void map(mlir::Value arrayValue, mlir::Value bufferPtr)
Map an LLVM array value to an LLVM pointer.
Definition HWToLLVM.cpp:144
Value spillLLVMArrayValue(OpBuilder &builder, Location loc, Value llvmArray)
Definition HWToLLVM.cpp:170
llvm::DenseMap< Value, Value > spillMap
Definition HWToLLVM.h:71
static uint32_t convertToLLVMEndianess(Type type, uint32_t index)
Convert an index into a HW ArrayType or StructType to LLVM Endianess.
Definition HWToLLVM.cpp:41
static uint32_t llvmIndexOfStructField(hw::StructType type, StringRef fieldName)
Get the index of a specific StructType field in the LLVM lowering of the StructType.
Definition HWToLLVM.cpp:53