From c374bfd9fdff02a0cff85d005488967b1b0f675e Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Fri, 12 Feb 2021 21:08:46 -0300 Subject: [PATCH] Add Phi support --- include/sirit/sirit.h | 6 ++++++ src/instructions/flow.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index 781f84a..0a204d7 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -232,6 +232,12 @@ public: // Flow + /** + * The SSA phi function. + * @param operands An immutable span of variable, parent block pairs + */ + Id OpPhi(Id result_type, std::span operands); + /// Declare a structured loop. Id OpLoopMerge(Id merge_block, Id continue_target, spv::LoopControlMask loop_control, std::span literals = {}); diff --git a/src/instructions/flow.cpp b/src/instructions/flow.cpp index e40800c..85700d2 100644 --- a/src/instructions/flow.cpp +++ b/src/instructions/flow.cpp @@ -12,6 +12,12 @@ namespace Sirit { +Id Module::OpPhi(Id result_type, std::span operands) { + assert(operands.size() % 2 == 0); + code->Reserve(3 + operands.size()); + return *code << OpId{spv::Op::OpPhi, result_type} << operands << EndOp{}; +} + Id Module::OpLoopMerge(Id merge_block, Id continue_target, spv::LoopControlMask loop_control, std::span literals) { code->Reserve(4 + literals.size());