14#ifndef CIRCT_TARGET_EXPORTSYSTEMC_EMISSIONPATTERN_H
15#define CIRCT_TARGET_EXPORTSYSTEMC_EMISSIONPATTERN_H
18#include "mlir/IR/Operation.h"
98 template <
typename E,
typename... Args>
99 static std::unique_ptr<E>
create(Args &&...args) {
100 std::unique_ptr<E> pattern =
101 std::make_unique<E>(std::forward<Args>(args)...);
118 OperationName(operationName,
context).getAsOpaquePointer()) {}
159 virtual bool match(Attribute attr) = 0;
167template <
typename Op>
197template <
typename Ty>
207 bool match(Type type)
override {
return isa<Ty>(type); }
225 bool match(Attribute attr)
override {
return isa<A>(attr); }
236template <
typename PatternTy>
241 template <
typename... Es,
typename ConstructorArg,
242 typename... ConstructorArgs,
243 typename = std::enable_if_t<
sizeof...(Es) != 0>>
244 void add(ConstructorArg &&arg, ConstructorArgs &&...args) {
245 (void)std::initializer_list<int>{
247 std::forward<ConstructorArgs>(args)...),
252 template <
typename... Es,
typename = std::enable_if_t<
sizeof...(Es) != 0>>
254 (void)std::initializer_list<int>{0, (
addImpl<Es>(), 0)...};
263 template <
typename E,
typename... Args>
264 std::enable_if_t<std::is_base_of<PatternTy, E>::value>
266 std::unique_ptr<E> pattern =
268 patterns.emplace_back(std::move(pattern));
277template <
typename PatternTy,
typename KeyTy>
284 DenseMap<KeyTy, std::vector<PatternTy *>>;
290 :
impl(std::make_shared<Impl>()) {
291 for (std::unique_ptr<PatternTy> &pat :
patterns.getNativePatterns()) {
292 impl->nativeOpSpecificPatternMap[KeyTy::getFromOpaquePointer(
293 pat->getRootValue())]
294 .push_back(pat.get());
295 impl->nativeOpSpecificPatternList.push_back(std::move(pat));
301 return impl->nativeOpSpecificPatternMap;
static std::unique_ptr< Context > context
This class collects a set of emission patterns with base type 'PatternTy'.
std::vector< std::unique_ptr< PatternTy > > & getNativePatterns()
Get all the emission patterns added to this set.
void add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add a new emission pattern that requires additional constructor arguments to this set.
void add()
Add a new emission pattern to the set.
std::enable_if_t< std::is_base_of< PatternTy, E >::value > addImpl(Args &&...args)
This is intended to be the driving class for all pattern-based IR emission.
std::vector< std::unique_ptr< PatternTy > > NativePatternListT
DenseMap< KeyTy, std::vector< PatternTy * > > OpSpecificNativePatternListT
A map of type specific native patterns.
FrozenEmissionPatternSet()
std::shared_ptr< Impl > impl
const OpSpecificNativePatternListT & getSpecificNativePatterns() const
Return the native patterns held by this set.
FrozenEmissionPatternSet(EmissionPatternSet< PatternTy > &&patterns)
Freeze the patterns held in patterns, and take ownership.
This class allows a pattern's match function for inlining to pass its result's precedence to the patt...
Precedence getPrecedence() const
MatchResult(Precedence precedence)
PatternBase(const void *rootValue)
const void * getRootValue() const
Get a unique identifier for the C++ type the pattern is matching on.
static std::unique_ptr< E > create(Args &&...args)
Precedence
This enum encodes the precedence of C++ expressions.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
AttrEmissionPatternBase(TypeID typeId)
virtual bool match(Attribute attr)=0
Checks if this pattern is applicable to the given attribute.
virtual void emitAttr(Attribute attr, EmissionPrinter &p)=0
Emit the given attribute to the emission printer.
virtual ~AttrEmissionPatternBase()=default
bool match(Attribute attr) override
Checks if this pattern is applicable to the given attribute.
virtual void emitAttr(A attr, EmissionPrinter &p)=0
Emit the given attribute to the emission printer.
void emitAttr(Attribute attr, EmissionPrinter &p) final
Emit the given attribute to the emission printer.
The internal implementation of the frozen pattern set.
OpSpecificNativePatternListT nativeOpSpecificPatternMap
The set of emission patterns that are matched to specific kinds.
NativePatternListT nativeOpSpecificPatternList
The full native rewrite list.
virtual void emitInlined(mlir::Value value, EmissionPrinter &p)=0
Emit the expression for the given value.
OpEmissionPatternBase(StringRef operationName, MLIRContext *context)
virtual bool matchStatement(mlir::Operation *op)=0
Checks if this pattern is applicable to the given operation for statement emission.
virtual void emitStatement(mlir::Operation *op, EmissionPrinter &p)=0
Emit zero or more statements for the given operation.
virtual ~OpEmissionPatternBase()=default
virtual MatchResult matchInlinable(Value value)=0
Checks if this pattern is applicable to the given value to emit an inlinable expression.
OpEmissionPattern(MLIRContext *context)
void emitInlined(mlir::Value value, EmissionPrinter &p) override
Emit the expression for the given value.
bool matchStatement(mlir::Operation *op) override
Checks if this pattern is applicable to the given operation for statement emission.
void emitStatement(mlir::Operation *op, EmissionPrinter &p) final
Emit zero or more statements for the given operation.
virtual void emitStatement(Op op, EmissionPrinter &p)
Emit zero (default) or more statements for the given operation.
MatchResult matchInlinable(Value value) override
Checks if this pattern is applicable to the given value to emit an inlinable expression.
TypeEmissionPatternBase(TypeID typeId)
virtual bool match(Type type)=0
Checks if this pattern is applicable to the given type.
virtual void emitType(Type type, EmissionPrinter &p)=0
Emit the given type to the emission printer.
virtual ~TypeEmissionPatternBase()=default
void emitType(Type type, EmissionPrinter &p) final
Emit the given type to the emission printer.
virtual void emitType(Ty type, EmissionPrinter &p)=0
Emit the given type to the emission printer.
bool match(Type type) override
Checks if this pattern is applicable to the given type.