CIRCT  20.0.0git
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"
15 #include "circt/Dialect/HW/HWOps.h"
16 
17 using namespace circt;
18 using namespace circt::hw;
19 using namespace circt::ExportSystemC;
20 
21 //===----------------------------------------------------------------------===//
22 // Operation emission patterns.
23 //===----------------------------------------------------------------------===//
24 
25 namespace {
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
30 struct ConstantEmitter : OpEmissionPattern<ConstantOp> {
31  using OpEmissionPattern::OpEmissionPattern;
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.
Definition: DebugAnalysis.h:21
This is a convenience class providing default implementations for operation emission patterns.