14 #ifndef MLIR_TABLEGEN_CODEGENHELPERS_H
15 #define MLIR_TABLEGEN_CODEGENHELPERS_H
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/MapVector.h"
22 #include "llvm/ADT/StringExtras.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/TableGen/CodeGenHelpers.h"
37 template <
typename... Parameters>
38 std::string
strfmt(
const char *fmt, Parameters &&...parameters) {
39 return llvm::formatv(fmt, std::forward<Parameters>(parameters)...).str();
52 std::optional<llvm::NamespaceEmitter> nsEmitter;
79 const llvm::RecordKeeper &records,
127 std::optional<StringRef>
144 std::optional<StringRef>
166 void emitTypeConstraints();
168 void emitAttrConstraints();
170 void emitPropConstraints();
172 void emitSuccessorConstraints();
174 void emitRegionConstraints();
177 void emitPatternConstraints();
187 std::string uniqueOutputLabel;
190 using ConstraintMap = llvm::MapVector<
Constraint, std::string,
194 void emitConstraints(
const ConstraintMap &constraints, StringRef selfName,
195 const char *codeTemplate);
198 std::string getUniqueName(StringRef
kind,
unsigned index);
200 void collectConstraint(ConstraintMap &map, StringRef
kind,
205 ConstraintMap typeConstraints;
207 ConstraintMap attrConstraints;
209 ConstraintMap propConstraints;
211 ConstraintMap successorConstraints;
213 ConstraintMap regionConstraints;
222 template <
typename T>
224 return std::string(std::forward<T>(t));
229 static std::string
apply(
const Twine &twine) {
return twine.str(); }
231 template <
typename OptionalT>
233 static std::string
apply(std::optional<OptionalT> optional) {
240 template <
typename T>
243 apply(std::forward<T>(t));
union mlir::linalg::@1252::ArityGroupAndKind::Kind kind
DialectNamespaceEmitter(raw_ostream &os, const Dialect &dialect)
StringRef getCppNamespace() const
This class deduplicates shared operation verification code by emitting static functions alongside the...
StringRef getRegionConstraintFn(const Constraint &constraint) const
Get the name of the static function used for the given region constraint.
void emitPatternConstraints(const ArrayRef< DagLeaf > constraints)
Unique all compatible type and attribute constraints from a pattern file and emit them at the top of ...
std::optional< StringRef > getAttrConstraintFn(const Constraint &constraint) const
Get the name of the static function used for the given attribute constraint.
std::optional< StringRef > getPropConstraintFn(const Constraint &constraint) const
Get the name of the static function used for the given property constraint.
StaticVerifierFunctionEmitter(raw_ostream &os, const llvm::RecordKeeper &records, StringRef tag="")
Create a constraint uniquer with a unique prefix derived from the record keeper with an optional tag.
void collectOpConstraints(ArrayRef< const llvm::Record * > opDefs)
Collect and unique all the constraints used by operations.
StringRef getTypeConstraintFn(const Constraint &constraint) const
Get the name of the static function used for the given type constraint.
void emitOpConstraints()
Collect and unique all compatible type, attribute, successor, and region constraints from the operati...
StringRef getSuccessorConstraintFn(const Constraint &constraint) const
Get the name of the static function used for the given successor constraint.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
std::string escapeString(StringRef value)
Escape a string using C++ encoding. E.g. foo"bar -> foo\x22bar.
std::string strfmt(const char *fmt, Parameters &&...parameters)
std::string stringify(T &&t)
Generically convert a value to a std::string.
Include the generated interface declarations.
static std::string apply(const Twine &twine)
static std::string apply(std::optional< OptionalT > optional)
static std::string apply(T &&t)