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";
103 const llvm::RecordKeeper &records);
147 std::optional<StringRef>
169 void emitTypeConstraints();
171 void emitAttrConstraints();
173 void emitSuccessorConstraints();
175 void emitRegionConstraints();
178 void emitPatternConstraints();
190 std::string uniqueOutputLabel;
193 using ConstraintMap = llvm::MapVector<
Constraint, std::string,
197 void emitConstraints(
const ConstraintMap &constraints, StringRef selfName,
198 const char *codeTemplate);
201 std::string getUniqueName(StringRef kind,
unsigned index);
203 void collectConstraint(ConstraintMap &map, StringRef kind,
208 ConstraintMap typeConstraints;
210 ConstraintMap attrConstraints;
212 ConstraintMap successorConstraints;
214 ConstraintMap regionConstraints;
223 template <
typename T>
225 return std::string(std::forward<T>(t));
230 static std::string
apply(
const Twine &twine) {
return twine.str(); }
232 template <
typename OptionalT>
234 static std::string
apply(std::optional<OptionalT> optional) {
241 template <
typename T>
244 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 ...
void emitOpConstraints(ArrayRef< llvm::Record * > opDefs, bool emitDecl)
Collect and unique all compatible type, attribute, successor, and region constraints from the operati...
std::optional< StringRef > getAttrConstraintFn(const Constraint &constraint) const
Get the name of the static function used for the given attribute constraint.
StaticVerifierFunctionEmitter(raw_ostream &os, const llvm::RecordKeeper &records)
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.
Include the generated interface declarations.
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)