14 #ifndef CIRCT_TARGET_EXPORTSYSTEMC_EMISSIONPATTERN_H
15 #define CIRCT_TARGET_EXPORTSYSTEMC_EMISSIONPATTERN_H
18 #include "mlir/IR/Operation.h"
22 namespace ExportSystemC {
24 class EmissionPrinter;
98 template <
typename E,
typename... Args>
99 static std::unique_ptr<E>
create(Args &&...args) {
101 std::make_unique<E>(std::forward<Args>(args)...);
118 OperationName(operationName, context).getAsOpaquePointer()) {}
159 virtual bool match(Attribute attr) = 0;
167 template <
typename Op>
197 template <
typename Ty>
207 bool match(Type type)
override {
return isa<Ty>(type); }
215 template <
typename A>
225 bool match(Attribute attr)
override {
return isa<A>(attr); }
236 template <
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>{
246 0, (addImpl<Es>(std::forward<ConstructorArg>(arg),
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>
267 PatternBase::create<E>(std::forward<Args>(args)...);
277 template <
typename PatternTy,
typename KeyTy>
284 DenseMap<KeyTy, std::vector<PatternTy *>>;
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;
RewritePatternSet pattern
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.
std::vector< std::unique_ptr< PatternTy > > patterns
std::enable_if_t< std::is_base_of< PatternTy, E >::value > addImpl(Args &&...args)
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.
This is intended to be the driving class for all pattern-based IR emission.
This class intends to collect a set of emission patterns in a way to provide fast lookups,...
DenseMap< KeyTy, std::vector< PatternTy * > > OpSpecificNativePatternListT
A map of type specific native patterns.
const OpSpecificNativePatternListT & getSpecificNativePatterns() const
Return the native patterns held by this set.
FrozenEmissionPatternSet()
std::vector< std::unique_ptr< PatternTy > > NativePatternListT
std::shared_ptr< Impl > impl
A pointer to the internal pattern list.
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)
This is indented to be the base class for all emission patterns.
const void * getRootValue() const
Get a unique identifier for the C++ type the pattern is matching on.
PatternBase(const void *rootValue)
static std::unique_ptr< E > create(Args &&...args)
Precedence
This enum encodes the precedence of C++ expressions.
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
This is intended to be the base class for all emission patterns matching on attributes.
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
This is a convenience class providing default implementations for attribute emission patterns.
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.
This is intended to be the base class for all emission patterns matching on operations.
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.
This is a convenience class providing default implementations for operation emission patterns.
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.
This is intended to be the base class for all emission patterns matching on types.
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
This is a convenience class providing default implementations for type emission patterns.
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.