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

Allow construction from module and specific entry point name #5

Merged
merged 4 commits into from
Dec 18, 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
17 changes: 17 additions & 0 deletions src/qiree/Module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ Module::Module(UPModule&& module) : module_{std::move(module)}
<< module_->getSourceFileName() << "'");
}

//---------------------------------------------------------------------------//
/*!
* Construct with an LLVM module and an entry point.
* Useful when there are multiple entry points.
*/
Module::Module(UPModule&& module, std::string const& entrypoint)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't QIR require a function to be specified as an entry point? or is this for the case where you have more than one entry point in a QIR file (and is that legal?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or is this for the case where you have more than one entry point in a QIR file

Exactly, yeah. Sometimes the Qwerty runtime can produce a QIR module with multiple entry points.

(and is that legal?)

I couldn't anywhere that the spec says that multiple entry points are allowed, but it doesn't seem to say that only one entry point is allowed either.

I learned this was possible from reading the qir-runner source code: 1, 2. The tl;dr is that if there is one entry point, qir-runner uses it, but otherwise they require specifying the name of the entry point to use.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, there's already a similar constructor overload that takes an entrypoint name, just with a filename instead of an llvm::Module:

Module::Module(std::string const& filename, std::string const& entrypoint)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, and I forgot about that function! I wonder if we need to restructure so that the Executor::operator() takes the entry point function name since one module has to be correspond exactly to a single executor, and if we have multiple entry points in one module it would be better not to have to recreate the module each time?

: module_{std::move(module)}
{
QIREE_EXPECT(module_);

// Search for explicitly named entry point
entrypoint_ = module_->getFunction(entrypoint);
QIREE_VALIDATE(entrypoint_,
<< "no entrypoint function '" << entrypoint << "' exists");
}

//---------------------------------------------------------------------------//
/*!
* Construct with an LLVM IR file (bitcode or disassembled).
Expand All @@ -125,6 +141,7 @@ Module::Module(std::string const& filename)
//---------------------------------------------------------------------------//
/*!
* Construct with an LLVM IR file (bitcode or disassembled) and entry point.
* Useful when there are multiple entry points.
*/
Module::Module(std::string const& filename, std::string const& entrypoint)
: module_{load_llvm_module(filename)}
Expand Down
3 changes: 3 additions & 0 deletions src/qiree/Module.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class Module
// Construct from an externally created LLVM module
explicit Module(UPModule&& module);

// Construct from an externally created LLVM module and an entry point
Module(UPModule&& module, std::string const& entrypoint);

// Construct with an LLVM IR file (bitcode or disassembled)
explicit Module(std::string const& filename);

Expand Down
Loading