13 #ifndef MLIR_TABLEGEN_CODEGENHELPERS_H 14 #define MLIR_TABLEGEN_CODEGENHELPERS_H 18 #include "llvm/ADT/DenseMap.h" 19 #include "llvm/ADT/MapVector.h" 20 #include "llvm/ADT/StringExtras.h" 21 #include "llvm/ADT/StringRef.h" 33 template <
typename... Parameters>
34 std::string
strfmt(
const char *fmt, Parameters &&...parameters) {
35 return llvm::formatv(fmt, std::forward<Parameters>(parameters)...).str();
42 : name(name.str()), os(os) {
43 os <<
"#ifdef " << name <<
"\n" 44 <<
"#undef " << name <<
"\n\n";
50 llvm::raw_ostream &os;
62 emitNamespaceStarts(os, cppNamespace);
66 for (StringRef ns : llvm::reverse(namespaces))
67 os <<
"} // namespace " << ns <<
"\n";
71 void emitNamespaceStarts(raw_ostream &os, StringRef cppNamespace) {
72 llvm::SplitString(cppNamespace, namespaces,
"::");
73 for (StringRef ns : namespaces)
74 os <<
"namespace " << ns <<
" {\n";
102 const llvm::RecordKeeper &records);
131 StringRef getTypeConstraintFn(
const Constraint &constraint)
const;
154 StringRef getSuccessorConstraintFn(
const Constraint &constraint)
const;
163 StringRef getRegionConstraintFn(
const Constraint &constraint)
const;
167 void emitTypeConstraints();
169 void emitAttrConstraints();
171 void emitSuccessorConstraints();
173 void emitRegionConstraints();
176 void emitPatternConstraints();
188 std::string uniqueOutputLabel;
191 using ConstraintMap = llvm::MapVector<
Constraint, std::string,
195 void emitConstraints(
const ConstraintMap &constraints, StringRef selfName,
196 const char *codeTemplate);
199 std::string getUniqueName(StringRef kind,
unsigned index);
201 void collectConstraint(ConstraintMap &map, StringRef kind,
202 Constraint constraint);
206 ConstraintMap typeConstraints;
208 ConstraintMap attrConstraints;
210 ConstraintMap successorConstraints;
212 ConstraintMap regionConstraints;
220 template <
typename T>
static std::string
apply(T &&t) {
221 return std::string(std::forward<T>(t));
225 static std::string
apply(
const Twine &twine) {
229 template <
typename OptionalT>
241 apply(std::forward<T>(t));
247 #endif // MLIR_TABLEGEN_CODEGENHELPERS_H Include the generated interface declarations.
Explicitly register a set of "builtin" types.
static std::string apply(const Twine &twine)
static std::string apply(T &&t)
IfDefScope(llvm::StringRef name, llvm::raw_ostream &os)
static constexpr const bool value
static std::string apply(Optional< OptionalT > optional)
StringRef getCppNamespace() const
std::string strfmt(const char *fmt, Parameters &&...parameters)
This class deduplicates shared operation verification code by emitting static functions alongside the...
static std::string escapeString(std::string str)
Escape special characters such as ' ' and quotation marks.
std::string stringify(T &&t)
Generically convert a value to a std::string.
NamespaceEmitter(raw_ostream &os, StringRef cppNamespace)
NamespaceEmitter(raw_ostream &os, const Dialect &dialect)