CIRCT 24.0.0git
Loading...
Searching...
No Matches
SeqDialect.cpp
Go to the documentation of this file.
1//===- SeqDialect.cpp - Implement the Seq dialect -----------------------===//
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 implements the Seq dialect.
10//
11//===----------------------------------------------------------------------===//
12
17#include "mlir/IR/Builders.h"
18#include "mlir/IR/BuiltinTypes.h"
19#include "mlir/IR/DialectImplementation.h"
20
21using namespace circt;
22using namespace seq;
23
24namespace {
25struct SeqProbeTypeDialectInterface : public hw::ProbeTypeDialectInterface {
27
28 bool isValidProbeElementType(Type type) const override {
29 return isa<ClockType>(type);
30 }
31};
32} // namespace
33
34//===----------------------------------------------------------------------===//
35// Dialect specification.
36//===----------------------------------------------------------------------===//
37
38void SeqDialect::initialize() {
39 registerTypes();
40 registerAttributes();
41
42 // Register operations.
43 addInterfaces<SeqProbeTypeDialectInterface>();
44}
45
46/// Registered hook to materialize a single constant operation from a given
47/// attribute value with the desired resultant type. This method should use
48/// the provided builder to create the operation without changing the
49/// insertion position. The generated operation is expected to be constant
50/// like, i.e. single result, zero operands, non side-effecting, etc. On
51/// success, this hook should return the value generated to represent the
52/// constant value. Otherwise, it should return null on failure.
53Operation *SeqDialect::materializeConstant(OpBuilder &builder, Attribute value,
54 Type type, Location loc) {
55 // Integer constants.
56 if (auto intType = dyn_cast<IntegerType>(type))
57 if (auto attrValue = dyn_cast<IntegerAttr>(value))
58 return hw::ConstantOp::create(builder, loc, type, attrValue);
59
60 if (isa<ClockType>(type))
61 if (auto attrValue = dyn_cast<ClockConstAttr>(value))
62 return seq::ConstClockOp::create(builder, loc, attrValue);
63
64 return nullptr;
65}
66
67#include "circt/Dialect/Seq/SeqDialect.cpp.inc"
create(data_type, value)
Definition hw.py:433
bool isValidProbeElementType(mlir::Type type)
Return true if type is a valid probe payload.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition seq.py:1
ProbeTypeDialectInterface(mlir::Dialect *dialect)
Definition HWTypes.h:55