CIRCT 22.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 <memory>
20
21namespace mlir {
22class LLVMTypeConverter;
23namespace LLVM {
24class GlobalOp;
25} // namespace LLVM
26} // namespace mlir
27
28namespace circt {
29
30#define GEN_PASS_DECL_CONVERTHWTOLLVM
31#include "circt/Conversion/Passes.h.inc"
32
33class Namespace;
34
36 /// Convert an index into a HW ArrayType or StructType to LLVM Endianess.
37 static uint32_t convertToLLVMEndianess(Type type, uint32_t index);
38
39 /// Get the index of a specific StructType field in the LLVM lowering of the
40 /// StructType
41 static uint32_t llvmIndexOfStructField(hw::StructType type,
42 StringRef fieldName);
43};
44
45/// Helper class mapping array values (HW or LLVM Dialect) to pointers to
46/// buffers containing the array value.
48 /// Spill HW array values produced by 'foreign' dialects on the stack.
49 /// The converter is used to map HW array types to the corresponding
50 /// LLVM array types. Should be called before dialect conversion.
51 void spillNonHWOps(mlir::OpBuilder &builder,
52 mlir::LLVMTypeConverter &converter,
53 Operation *containerOp);
54
55 /// Map an LLVM array value to an LLVM pointer.
56 /// For the entire lifetime of the array value the pointer must
57 /// refer to a valid buffer containing the respective array value.
58 void map(mlir::Value arrayValue, mlir::Value bufferPtr);
59
60 /// Retrieve a pointer to a buffer containing the given array
61 /// value (HW or LLVM Dialect). The buffer must not be modified or
62 /// deallocated. Returns a null value if no buffer has been mapped.
63 Value lookup(Value arrayValue);
64
65private:
66 Value spillLLVMArrayValue(OpBuilder &builder, Location loc, Value llvmArray);
67 Value spillHWArrayValue(OpBuilder &builder, Location loc,
68 mlir::LLVMTypeConverter &converter, Value hwArray);
69
70 llvm::DenseMap<Value, Value> spillMap;
71};
72
73/// Get the HW to LLVM type conversions.
74void populateHWToLLVMTypeConversions(mlir::LLVMTypeConverter &converter);
75
76/// Get the HW to LLVM conversion patterns.
77/// Note: The spill cache may only be used when conversion
78/// pattern rollback is disabled.
80 mlir::LLVMTypeConverter &converter, RewritePatternSet &patterns,
81 Namespace &globals,
82 DenseMap<std::pair<Type, ArrayAttr>, mlir::LLVM::GlobalOp>
83 &constAggregateGlobalsMap,
84 std::optional<HWToLLVMArraySpillCache> &spillCacheOpt);
85
86} // namespace circt
87
88#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)
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:47
Value spillHWArrayValue(OpBuilder &builder, Location loc, mlir::LLVMTypeConverter &converter, Value hwArray)
Definition HWToLLVM.cpp:175
Value lookup(Value arrayValue)
Retrieve a pointer to a buffer containing the given array value (HW or LLVM Dialect).
Definition HWToLLVM.cpp:142
void spillNonHWOps(mlir::OpBuilder &builder, mlir::LLVMTypeConverter &converter, Operation *containerOp)
Spill HW array values produced by 'foreign' dialects on the stack.
Definition HWToLLVM.cpp:100
void map(mlir::Value arrayValue, mlir::Value bufferPtr)
Map an LLVM array value to an LLVM pointer.
Definition HWToLLVM.cpp:134
Value spillLLVMArrayValue(OpBuilder &builder, Location loc, Value llvmArray)
Definition HWToLLVM.cpp:160
llvm::DenseMap< Value, Value > spillMap
Definition HWToLLVM.h:70
static uint32_t convertToLLVMEndianess(Type type, uint32_t index)
Convert an index into a HW ArrayType or StructType to LLVM Endianess.
Definition HWToLLVM.cpp:38
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:50