CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
73 lines
3.5 KiB
C++
73 lines
3.5 KiB
C++
// Copyright Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
|
|
#include <rocRoller/CodeGen/Instruction.hpp>
|
|
#include <rocRoller/Context_fwd.hpp>
|
|
#include <rocRoller/Expression_fwd.hpp>
|
|
#include <rocRoller/KernelGraph/ControlGraph/Operation.hpp>
|
|
#include <rocRoller/Utilities/Generator.hpp>
|
|
|
|
namespace rocRoller
|
|
{
|
|
namespace KernelGraph
|
|
{
|
|
/**
|
|
* @brief Generates conditional code for ConditionalOp nodes.
|
|
*
|
|
* Handles ConditionalMode::Branch, ConditionalMode::Exec, and ConditionalMode::BranchAndExec cases.
|
|
*/
|
|
class ConditionalGenerator
|
|
{
|
|
public:
|
|
ConditionalGenerator(ContextPtr context);
|
|
|
|
/**
|
|
* @brief Generate instructions for a ConditionalOp node.
|
|
*
|
|
* Dispatches to the appropriate implementation based on @p mode:
|
|
* - ConditionalMode::Branch: evaluates the condition, branches over the true body
|
|
* if false, generates the true body, branches to the bottom label, then
|
|
* optionally generates the else body.
|
|
* - ConditionalMode::Exec or ConditionalMode::BranchAndExec: saves the EXEC mask,
|
|
* AND-masks with the condition VCC, generates the true body, optionally generates
|
|
* the else body with the complementary mask, then restores the EXEC mask.
|
|
* When mode is BranchAndExec, additionally branches over each body when EXECZ is
|
|
* set (i.e. the entire EXEC mask is zero).
|
|
*
|
|
* @param condition The condition expression (already fast-arithmetic transformed).
|
|
* @param labelBase Base string for generated labels; should encode both the
|
|
* conditionName and the control graph node tag to ensure uniqueness.
|
|
* @param trueBodyFn Callback to generate instructions for the true (Body) nodes.
|
|
* @param elseBodyFn Callback to generate instructions for the else (Else) nodes,
|
|
* or empty if there is no else body.
|
|
* @param mode The ConditionalMode to use.
|
|
*/
|
|
Generator<Instruction>
|
|
genConditional(Expression::ExpressionPtr condition,
|
|
std::string const& labelBase,
|
|
std::function<Generator<Instruction>()> trueBodyFn,
|
|
std::function<Generator<Instruction>()> elseBodyFn,
|
|
ControlGraph::ConditionalMode mode);
|
|
|
|
private:
|
|
ContextPtr m_context;
|
|
|
|
Generator<Instruction> genBranch(Expression::ExpressionPtr condition,
|
|
std::string const& labelBase,
|
|
std::function<Generator<Instruction>()> trueBodyFn,
|
|
std::function<Generator<Instruction>()> elseBodyFn);
|
|
|
|
Generator<Instruction> genExec(Expression::ExpressionPtr condition,
|
|
std::string const& labelBase,
|
|
std::function<Generator<Instruction>()> trueBodyFn,
|
|
std::function<Generator<Instruction>()> elseBodyFn,
|
|
ControlGraph::ConditionalMode mode);
|
|
};
|
|
}
|
|
}
|