CIRCT 24.0.0git
Loading...
Searching...
No Matches
ProjectionUtils.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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// Helpers to reason about `llhd.sig.*` projections: the portion of a signal's
10// storage they select, and whether two projections provably target disjoint
11// storage.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef CIRCT_SUPPORT_PROJECTIONUTILS_H
16#define CIRCT_SUPPORT_PROJECTIONUTILS_H
17
19#include "circt/Support/LLVM.h"
20#include "mlir/IR/Value.h"
21
22#include <utility>
23#include <variant>
24
25namespace circt {
26namespace llhd {
27
28/// Portion of a signal selected by a projection, with a statically known
29/// offset and width in bits.
31 uint64_t offset = 0;
32 uint64_t width = 1;
33};
34
35/// Portion of a signal selected by a projection with a dynamic index. The
36/// exact offset is unknown.
38 Value index;
39};
40
41/// Portion of the signal operand that is selected by a projection.
42using ProjectionRange = std::variant<ConstProjectionRange, DynProjectionRange>;
43
44/// Helper to check if a projection range is dynamic or not.
45inline bool isDynamic(const ProjectionRange &range) {
46 return std::holds_alternative<DynProjectionRange>(range);
47}
48
49/// Return the type stored in a signal or projection.
50inline Type getStoredType(Value slot) {
51 return cast<RefType>(slot.getType()).getNestedType();
52}
53
54/// Check if an op is one of the supported projection types.
55bool isProjection(const Operation *op);
56
57/// Calculate a projection's range.
58/// Returns nullopt if the range could not be calculated for this projection.
59/// Asserts if the provided Operation is not a (supported) projection.
60std::optional<ProjectionRange> getProjectionRange(Operation *op);
61
62/// Check whether two projections provably describe disjoint storage.
64
65/// Given a signal or a projection, walk back the projection chain until you
66/// find the root signal declaration. A nullptr is returned if at any point of
67/// the use-def chain we encounter an Operation that is not a (supported)
68/// projection.
69Operation *getRootSignal(Value sig);
70
71/// Given a signal or a projection, find the root signal declaration by
72/// traversing the projection chain. Optionally, if the projection chain is
73/// fully constant, return the portion of the original signal that this
74/// operation probes or drives. A null Operation is returned if the use-def
75/// chain does not bottom-out in a signal declaration, and a null range is
76/// returned if a dynamic index is found.
77std::pair<Operation *, std::optional<ProjectionRange>>
78getRootSignalAndRange(Value sig);
79
80} // namespace llhd
81} // namespace circt
82
83#endif // CIRCT_SUPPORT_PROJECTIONUTILS_H
std::pair< Operation *, std::optional< ProjectionRange > > getRootSignalAndRange(Value sig)
Given a signal or a projection, find the root signal declaration by traversing the projection chain.
std::optional< ProjectionRange > getProjectionRange(Operation *op)
Calculate a projection's range.
std::variant< ConstProjectionRange, DynProjectionRange > ProjectionRange
Portion of the signal operand that is selected by a projection.
Type getStoredType(Value slot)
Return the type stored in a signal or projection.
Operation * getRootSignal(Value sig)
Given a signal or a projection, walk back the projection chain until you find the root signal declara...
bool isProjection(const Operation *op)
Check if an op is one of the supported projection types.
bool isDynamic(const ProjectionRange &range)
Helper to check if a projection range is dynamic or not.
bool isProvablyDisjoint(const ProjectionRange &a, const ProjectionRange &b)
Check whether two projections provably describe disjoint storage.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Portion of a signal selected by a projection, with a statically known offset and width in bits.
Portion of a signal selected by a projection with a dynamic index.