Skip to content

Commit

Permalink
Allow construction from module and specific entry point name (#5)
Browse files Browse the repository at this point in the history
* Add constructor for llvm::Module + entrypoint name

This is useful when a user generates an llvm::Module that may have
multiple entry points, as the Qwerty compiler/runtime does.

* XaccQuantum: Add setter for accelerator/shots

In my experience, it has been easier to treat XaccQuantum as a singleton
to avoid issues with XACC initializing itself twice.

It is probably cleaner to pass (accelerator, shots) via qiree::Executor,
but this solves my immediate implementaiton problem in the Qwerty
compiler/runtime.

* Address PR comments

* Address PR comments
  • Loading branch information
ausbin authored Dec 18, 2024
1 parent 9c1ff4c commit 8bdee87
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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)
: 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

0 comments on commit 8bdee87

Please sign in to comment.