CIRCT 20.0.0git
Loading...
Searching...
No Matches
LLHDDialect.cpp
Go to the documentation of this file.
1//===- LLHDDialect.cpp - Implement the LLHD 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 LLHD dialect.
10//
11//===----------------------------------------------------------------------===//
12
17#include "circt/Support/LLVM.h"
18#include "mlir/IR/DialectImplementation.h"
19#include "mlir/Transforms/InliningUtils.h"
20
21using namespace circt;
22using namespace circt::llhd;
23
24//===----------------------------------------------------------------------===//
25// LLHDDialect Interfaces
26//===----------------------------------------------------------------------===//
27
28namespace {
29/// This class defines the interface for handling inlining with LLHD operations.
30struct LLHDInlinerInterface : public mlir::DialectInlinerInterface {
31 using mlir::DialectInlinerInterface::DialectInlinerInterface;
32
33 //===--------------------------------------------------------------------===//
34 // Analysis Hooks
35 //===--------------------------------------------------------------------===//
36
37 /// All operations within LLHD can be inlined.
38 bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
39 return true;
40 }
41
42 bool isLegalToInline(Region *, Region *src, bool, IRMapping &) const final {
43 return false;
44 }
45};
46} // end anonymous namespace
47
48//===----------------------------------------------------------------------===//
49// LLHD Dialect
50//===----------------------------------------------------------------------===//
51
52void LLHDDialect::initialize() {
53 registerTypes();
54 registerAttributes();
55
56 addOperations<
57#define GET_OP_LIST
58#include "circt/Dialect/LLHD/IR/LLHD.cpp.inc"
59 >();
60
61 addInterfaces<LLHDInlinerInterface>();
62}
63
64Operation *LLHDDialect::materializeConstant(OpBuilder &builder, Attribute value,
65 Type type, Location loc) {
66 if (auto timeAttr = dyn_cast<TimeAttr>(value))
67 return builder.create<llhd::ConstantTimeOp>(loc, type, timeAttr);
68
69 if (auto intAttr = dyn_cast<IntegerAttr>(value))
70 return builder.create<hw::ConstantOp>(loc, type, intAttr);
71
72 return nullptr;
73}
74
75#include "circt/Dialect/LLHD/IR/LLHDDialect.cpp.inc"
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.