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"
37template <
typename... Parameters>
38std::string
strfmt(
const char *fmt, Parameters &&...parameters) {
39 return llvm::formatv(fmt, std::forward<Parameters>(parameters)...).str();
52 std::optional<llvm::NamespaceEmitter> nsEmitter;
88 const llvm::RecordKeeper &records,
136 std::optional<StringRef>
153 std::optional<StringRef>
175 void emitTypeConstraints();
177 void emitAttrConstraints();
179 void emitPropConstraints();
181 void emitSuccessorConstraints();
183 void emitRegionConstraints();
196 std::string uniqueOutputLabel;
199 using ConstraintMap = llvm::MapVector<
Constraint, std::string,
203 void emitConstraints(
const ConstraintMap &constraints, StringRef selfName,
204 const char *codeTemplate,
208 std::string getUniqueName(StringRef kind,
unsigned index);
210 void collectConstraint(ConstraintMap &map, StringRef kind,
215 ConstraintMap typeConstraints;
217 ConstraintMap attrConstraints;
219 ConstraintMap propConstraints;
221 ConstraintMap successorConstraints;
223 ConstraintMap regionConstraints;
232 template <
typename T>
234 return std::string(std::forward<T>(t));
239 static std::string
apply(
const Twine &twine) {
return twine.str(); }
241template <
typename OptionalT>
243 static std::string
apply(std::optional<OptionalT> optional) {
253 apply(std::forward<T>(t));
265 StringRef message,
const FmtContext &ctx,
DialectNamespaceEmitter(raw_ostream &os, const Dialect &dialect)
StringRef getCppNamespace() const
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 buildErrorStreamingString(StringRef message, const FmtContext &ctx, ErrorStreamType errorStreamType=ErrorStreamType::InString)
Helper to generate a C++ streaming error message from a given message.
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)
ErrorStreamType
This class represents how an error stream string being constructed will be consumed.
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)