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