13 #ifndef MLIR_TABLEGEN_CODEGENHELPERS_H
14 #define MLIR_TABLEGEN_CODEGENHELPERS_H
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/MapVector.h"
21 #include "llvm/ADT/StringExtras.h"
22 #include "llvm/ADT/StringRef.h"
34 template <
typename... Parameters>
35 std::string
strfmt(
const char *fmt, Parameters &&...parameters) {
36 return llvm::formatv(fmt, std::forward<Parameters>(parameters)...).str();
43 : name(name.str()), os(os) {
44 os <<
"#ifdef " << name <<
"\n"
45 <<
"#undef " << name <<
"\n\n";
51 llvm::raw_ostream &os;
63 emitNamespaceStarts(os, cppNamespace);
67 for (StringRef ns : llvm::reverse(namespaces))
68 os <<
"} // namespace " << ns <<
"\n";
72 void emitNamespaceStarts(raw_ostream &os, StringRef cppNamespace) {
73 llvm::SplitString(cppNamespace, namespaces,
"::");
74 for (StringRef ns : namespaces)
75 os <<
"namespace " << ns <<
" {\n";
105 const llvm::RecordKeeper &records,
153 std::optional<StringRef>
175 void emitTypeConstraints();
177 void emitAttrConstraints();
179 void emitSuccessorConstraints();
181 void emitRegionConstraints();
184 void emitPatternConstraints();
194 std::string uniqueOutputLabel;
197 using ConstraintMap = llvm::MapVector<
Constraint, std::string,
201 void emitConstraints(
const ConstraintMap &constraints, StringRef selfName,
202 const char *codeTemplate);
205 std::string getUniqueName(StringRef kind,
unsigned index);
207 void collectConstraint(ConstraintMap &map, StringRef kind,
212 ConstraintMap typeConstraints;
214 ConstraintMap attrConstraints;
216 ConstraintMap successorConstraints;
218 ConstraintMap regionConstraints;
227 template <
typename T>
229 return std::string(std::forward<T>(t));
234 static std::string
apply(
const Twine &twine) {
return twine.str(); }
236 template <
typename OptionalT>
238 static std::string
apply(std::optional<OptionalT> optional) {
245 template <
typename T>
248 apply(std::forward<T>(t));
StringRef getCppNamespace() const
IfDefScope(llvm::StringRef name, llvm::raw_ostream &os)
NamespaceEmitter(raw_ostream &os, const Dialect &dialect)
NamespaceEmitter(raw_ostream &os, StringRef cppNamespace)
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.
void emitOpConstraints(ArrayRef< const llvm::Record * > opDefs)
Collect and unique all compatible type, attribute, successor, and region constraints from the operati...
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.
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)