Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dialect::isDialectOp helper function. #95

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/ExampleMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ void createFunctionExample(Module &module, const Twine &name) {
p2->setName("p2");
b.create<xd::WriteOp>(p2);

assert(xd::ExampleDialect::isDialectOp(*cast<CallInst>(p2)));

SmallVector<Value *> varArgs;
varArgs.push_back(p1);
varArgs.push_back(p2);
Expand Down
15 changes: 15 additions & 0 deletions lib/TableGen/GenDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Flakebi marked this conversation as resolved.
Show resolved Hide resolved
}

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);
Expand Down
12 changes: 12 additions & 0 deletions test/example/generated/ExampleDialect.cpp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions test/example/generated/ExampleDialect.h.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading