CIRCT 20.0.0git
Loading...
Searching...
No Matches
HWEmissionPatterns.cpp
Go to the documentation of this file.
1//===- HWEmissionPatterns.cpp - HW Dialect Emission Patterns --------------===//
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 implements the emission patterns for the HW dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#include "HWEmissionPatterns.h"
14#include "../EmissionPrinter.h"
16
17using namespace circt;
18using namespace circt::hw;
19using namespace circt::ExportSystemC;
20
21//===----------------------------------------------------------------------===//
22// Operation emission patterns.
23//===----------------------------------------------------------------------===//
24
25namespace {
26/// The ConstantOp always inlines its value. Examples:
27/// * hw.constant 5 : i32 ==> 5
28/// * hw.constant 0 : i1 ==> false
29/// * hw.constant 1 : i1 ==> true
30struct ConstantEmitter : OpEmissionPattern<ConstantOp> {
32
33 MatchResult matchInlinable(Value value) override {
34 if (value.getDefiningOp<ConstantOp>())
35 return Precedence::LIT;
36 return {};
37 }
38
39 void emitInlined(Value value, EmissionPrinter &p) override {
40 p.emitAttr(value.getDefiningOp<ConstantOp>().getValueAttr());
41 }
42};
43} // namespace
44
45//===----------------------------------------------------------------------===//
46// Register Operation and Type emission patterns.
47//===----------------------------------------------------------------------===//
48
50 MLIRContext *context) {
51 patterns.add<ConstantEmitter>(context);
52}
This class collects a set of emission patterns with base type 'PatternTy'.
This is intended to be the driving class for all pattern-based IR emission.
void emitAttr(Attribute attr)
Emit the given attribute to the ostream associated with this printer according to the emission patter...
This class allows a pattern's match function for inlining to pass its result's precedence to the patt...
void populateHWEmitters(OpEmissionPatternSet &patterns, MLIRContext *context)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
This is a convenience class providing default implementations for operation emission patterns.
void emitInlined(mlir::Value value, EmissionPrinter &p) override
Emit the expression for the given value.
MatchResult matchInlinable(Value value) override
Checks if this pattern is applicable to the given value to emit an inlinable expression.