diff --git a/example/ExampleMain.cpp b/example/ExampleMain.cpp index 57c02f0..bc20d42 100644 --- a/example/ExampleMain.cpp +++ b/example/ExampleMain.cpp @@ -117,6 +117,8 @@ void createFunctionExample(Module &module, const Twine &name) { p2->setName("p2"); b.create(p2); + assert(xd::ExampleDialect::isDialectOp(*cast(p2))); + SmallVector varArgs; varArgs.push_back(p1); varArgs.push_back(p2); diff --git a/lib/TableGen/GenDialect.cpp b/lib/TableGen/GenDialect.cpp index 1d35849..fb26aed 100644 --- a/lib/TableGen/GenDialect.cpp +++ b/lib/TableGen/GenDialect.cpp @@ -107,6 +107,9 @@ class Builder; public: static Key& getKey(); + static bool isDialectOp(::llvm::CallInst& op); + static bool isDialectOp(::llvm::Function& func); + static bool isDialectOp(::llvm::StringRef funcName); private: $Dialect(::llvm::LLVMContext& context); @@ -298,6 +301,18 @@ void llvm_dialects::genDialectDefs(raw_ostream& out, RecordKeeper& records) { return s_key; } + bool $Dialect::isDialectOp(::llvm::CallInst& op) { + return isDialectOp(op.getCalledFunction()->getName()); + } + + bool $Dialect::isDialectOp(::llvm::Function& func) { + return isDialectOp(func.getName()); + } + + bool $Dialect::isDialectOp(::llvm::StringRef funcName) { + return funcName.starts_with("$namespace."); + } + ::llvm_dialects::Dialect* $Dialect::make(::llvm::LLVMContext& context) { $0 return new $Dialect(context); diff --git a/test/example/generated/ExampleDialect.cpp.inc b/test/example/generated/ExampleDialect.cpp.inc index 3e37730..563158f 100644 --- a/test/example/generated/ExampleDialect.cpp.inc +++ b/test/example/generated/ExampleDialect.cpp.inc @@ -30,6 +30,18 @@ namespace xd { return s_key; } + bool ExampleDialect::isDialectOp(::llvm::CallInst& op) { + return isDialectOp(op.getCalledFunction()->getName()); + } + + bool ExampleDialect::isDialectOp(::llvm::Function& func) { + return isDialectOp(func.getName()); + } + + bool ExampleDialect::isDialectOp(::llvm::StringRef funcName) { + return funcName.starts_with("xd."); + } + ::llvm_dialects::Dialect* ExampleDialect::make(::llvm::LLVMContext& context) { auto verifierBuild = [](::llvm_dialects::VisitorBuilder<::llvm_dialects::VerifierState> &builder) { diff --git a/test/example/generated/ExampleDialect.h.inc b/test/example/generated/ExampleDialect.h.inc index d6b2a5f..1918a5e 100644 --- a/test/example/generated/ExampleDialect.h.inc +++ b/test/example/generated/ExampleDialect.h.inc @@ -32,6 +32,9 @@ namespace xd { public: static Key& getKey(); + static bool isDialectOp(::llvm::CallInst& op); + static bool isDialectOp(::llvm::Function& func); + static bool isDialectOp(::llvm::StringRef funcName); private: ExampleDialect(::llvm::LLVMContext& context);