diff options
author | ReinUsesLisp <[email protected]> | 2021-04-11 02:02:40 -0300 |
---|---|---|
committer | ReinUsesLisp <[email protected]> | 2021-04-11 02:02:43 -0300 |
commit | 51d541f1a1fae66ba5dbd7816e283c8a723690db (patch) | |
tree | 7ceed35916bb37ac6509eb90552d082b0a9f27a0 /include | |
parent | f1cccfd0f3dc9737da7db0e716a7d2da2400651b (diff) | |
download | sirit-51d541f1a1fae66ba5dbd7816e283c8a723690db.tar.gz sirit-51d541f1a1fae66ba5dbd7816e283c8a723690db.zip |
Remove forward references and add phi node patching
The previous API for forward declarations broke when more than one
definition was done. Forward references on instructions that are not
labels were only needed for phi nodes, so it has been replaced with a
deferred phi node instruction and a method to patch these after
everything has been defined.
Diffstat (limited to 'include')
-rw-r--r-- | include/sirit/sirit.h | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index f3925bb..d442191 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -12,6 +12,7 @@ #include <optional> #include <span> #include <string> +#include <functional> #include <string_view> #include <type_traits> #include <unordered_set> @@ -52,6 +53,9 @@ public: */ std::vector<std::uint32_t> Assemble() const; + /// Patches deferred phi nodes calling the passed function on each phi argument + void PatchDeferredPhi(const std::function<Id(std::size_t index)>& func); + /// Adds a SPIR-V extension. void AddExtension(std::string extension_name); @@ -87,15 +91,6 @@ public: AddExecutionMode(entry_point, mode, std::span<const Literal>({literals...})); } - /// Generate a new id for forward declarations - [[nodiscard]] Id ForwardDeclarationId(); - - /// Returns the current generator id, useful for self-referencing phi nodes - [[nodiscard]] Id CurrentId() const noexcept; - - /// Assign a new id and return the old one, useful for defining forward declarations - Id ExchangeCurrentId(Id new_current_id); - /** * Adds an existing label to the code * @param label Label to insert into code. @@ -253,6 +248,12 @@ public: */ Id OpPhi(Id result_type, std::span<const Id> operands); + /** + * The SSA phi function. This instruction will be revisited when patching phi nodes. + * @param operands An immutable span of block pairs + */ + Id DeferredOpPhi(Id result_type, std::span<const Id> blocks); + /// Declare a structured loop. Id OpLoopMerge(Id merge_block, Id continue_target, spv::LoopControlMask loop_control, std::span<const Id> literals = {}); @@ -1236,6 +1237,7 @@ private: std::unique_ptr<Declarations> declarations; std::unique_ptr<Stream> global_variables; std::unique_ptr<Stream> code; + std::vector<std::uint32_t> deferred_phi_nodes; }; } // namespace Sirit |