CIRCT 20.0.0git
Loading...
Searching...
No Matches
RTGTestDialect.cpp
Go to the documentation of this file.
1//===- RTGTestDialect.cpp - Implement the RTGTest 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 RTGTest dialect.
10//
11//===----------------------------------------------------------------------===//
12
17#include "mlir/IR/Builders.h"
18#include "mlir/IR/BuiltinTypes.h"
19#include "mlir/IR/DialectImplementation.h"
20#include "llvm/ADT/TypeSwitch.h"
21
22using namespace circt;
23using namespace rtgtest;
24
25//===----------------------------------------------------------------------===//
26// Dialect specification.
27//===----------------------------------------------------------------------===//
28
29void RTGTestDialect::initialize() {
30 registerTypes();
31 registerAttributes();
32 // Register operations.
33 addOperations<
34#define GET_OP_LIST
35#include "circt/Dialect/RTGTest/IR/RTGTest.cpp.inc"
36 >();
37}
38
39/// Registered hook to materialize a single constant operation from a given
40/// attribute value with the desired resultant type. This method should use
41/// the provided builder to create the operation without changing the
42/// insertion position. The generated operation is expected to be constant
43/// like, i.e. single result, zero operands, non side-effecting, etc. On
44/// success, this hook should return the value generated to represent the
45/// constant value. Otherwise, it should return null on failure.
46Operation *RTGTestDialect::materializeConstant(OpBuilder &builder,
47 Attribute value, Type type,
48 Location loc) {
49 return TypeSwitch<Attribute, Operation *>(value)
50 .Case<CPUAttr>([&](auto attr) -> Operation * {
51 if (isa<CPUType>(type))
52 return builder.create<CPUDeclOp>(loc, type, attr);
53 return nullptr;
54 })
55 .Case<rtg::RegisterAttrInterface>([&](auto attr) -> Operation * {
56 if (isa<rtg::RegisterTypeInterface>(type))
57 return builder.create<rtg::FixedRegisterOp>(loc, attr);
58 return nullptr;
59 })
60 .Case<Imm12Attr, Imm21Attr, Imm32Attr>(
61 [&](auto attr) { return builder.create<ImmediateOp>(loc, attr); })
62 .Default([](auto attr) { return nullptr; });
63}
64
65#include "circt/Dialect/RTGTest/IR/RTGTestEnums.cpp.inc"
66
67#include "circt/Dialect/RTGTest/IR/RTGTestDialect.cpp.inc"
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.