From a6946d3c8ef4d686ddd7666083edfffdc779d847 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Fri, 31 Aug 2018 04:17:16 -0300 Subject: [PATCH] Add OpBranchConditional --- include/sirit/sirit.h | 4 ++++ src/insts/flow.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index 1fe338f..499f068 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -167,6 +167,10 @@ public: /// Unconditional jump to label. Ref Branch(Ref target_label); + /// If condition is true branch to true_label, otherwise branch to false_label. + Ref BranchConditional(Ref condition, Ref true_label, Ref false_label, + std::uint32_t true_weight = 0, std::uint32_t false_weight = 0); + /// Returns with no value from a function with void return type. Ref Return(); diff --git a/src/insts/flow.cpp b/src/insts/flow.cpp index a9edf5c..d559fe1 100644 --- a/src/insts/flow.cpp +++ b/src/insts/flow.cpp @@ -36,6 +36,19 @@ Ref Module::Branch(Ref target_label) { return AddCode(op); } +Ref Module::BranchConditional(Ref condition, Ref true_label, Ref false_label, + std::uint32_t true_weight, std::uint32_t false_weight) { + Op* op{new Op(spv::Op::OpBranchConditional)}; + op->Add(condition); + op->Add(true_label); + op->Add(false_label); + if (true_weight != 0 || false_weight != 0) { + op->Add(Literal(true_weight)); + op->Add(Literal(false_weight)); + } + return AddCode(op); +} + Ref Module::Return() { return AddCode(spv::Op::OpReturn); }