40 static std::unique_ptr<IfConversionStatistics>
43 return std::make_unique<IfConversionStatistics>(sourceFile);
68 for (
auto & node : region.
Nodes())
76 for (
size_t n = 0; n < structuralNode->nsubregions(); n++)
78 const auto subregion = structuralNode->subregion(n);
82 else if (is<rvsdg::SimpleOperation>(&node))
100 for (
auto [branchResult, gammaOutput] : gammaNode.
GetExitVars())
102 const auto region0Argument =
104 const auto region1Argument =
107 if (region0Argument ==
nullptr || region1Argument ==
nullptr)
114 const auto origin0 = region0Argument->
input()->
origin();
115 const auto origin1 = region1Argument->input()->origin();
117 if (origin0 == origin1)
124 const auto matchNode = rvsdg::TryGetOwnerNode<rvsdg::SimpleNode>(*gammaPredicate);
125 if (is<rvsdg::MatchOperation>(matchNode))
127 const auto matchOperation =
128 util::assertedCast<const rvsdg::MatchOperation>(&matchNode->GetOperation());
129 JLM_ASSERT(matchOperation->nalternatives() == 2);
130 JLM_ASSERT(std::distance(matchOperation->begin(), matchOperation->end()) == 1);
132 const auto matchOrigin = matchNode->input(0)->origin();
133 const auto caseValue = matchOperation->begin()->first;
134 const auto caseSubregion = matchOperation->begin()->second;
135 const auto defaultSubregion = matchOperation->default_alternative();
136 const auto numMatchBits = matchOperation->nbits();
137 JLM_ASSERT(caseSubregion != defaultSubregion);
139 if (numMatchBits == 1 && caseValue == caseSubregion)
145 auto & selectNode = rvsdg::CreateOpNode<SelectOperation>(
146 { matchOrigin, origin1, origin0 },
147 gammaOutput->Type());
148 gammaOutput->divert_users(selectNode.output(0));
154 auto & constantNode = rvsdg::CreateOpNode<IntegerConstantOperation>(
157 auto & eqNode = rvsdg::CreateOpNode<IntegerEqOperation>(
158 { constantNode.output(0), matchOrigin },
161 auto trueAlternative = caseSubregion == 0 ? origin0 : origin1;
162 auto falseAlternative = caseSubregion == 0 ? origin1 : origin0;
163 auto & selectNode = rvsdg::CreateOpNode<SelectOperation>(
164 { eqNode.output(0), trueAlternative, falseAlternative },
165 gammaOutput->Type());
166 gammaOutput->divert_users(selectNode.output(0));
171 const auto falseAlternative = origin0;
172 const auto trueAlternative = origin1;
173 auto & controlToIntNode = rvsdg::CreateOpNode<ControlToIntOperation>(
177 auto & selectNode = rvsdg::CreateOpNode<SelectOperation>(
178 { controlToIntNode.output(0), trueAlternative, falseAlternative },
179 gammaOutput->Type());
180 gammaOutput->divert_users(selectNode.output(0));
If-Conversion Transformation statistics.
~IfConversionStatistics() override=default
static std::unique_ptr< IfConversionStatistics > Create(const util::FilePath &sourceFile)
IfConversionStatistics(const util::FilePath &sourceFile)
If-Conversion Transformation.
void Run(rvsdg::RvsdgModule &module, util::StatisticsCollector &statisticsCollector) override
Perform RVSDG transformation.
static void HandleGammaNode(const rvsdg::GammaNode &gammaNode)
static void HandleRegion(rvsdg::Region ®ion)
~IfConversion() noexcept override
static std::shared_ptr< const BitType > Create(std::size_t nbits)
Creates bit type of specified width.
static std::shared_ptr< const ControlType > Create(std::size_t nalternatives)
Instantiates control type.
Conditional operator / pattern matching.
std::vector< ExitVar > GetExitVars() const
Gets all exit variables for this gamma.
rvsdg::Input * predicate() const noexcept
Region & GetRootRegion() const noexcept
rvsdg::Region * region() const noexcept
void divert_users(jlm::rvsdg::Output *new_origin)
Represents the argument of a region.
StructuralInput * input() const noexcept
Represent acyclic RVSDG subgraphs.
NodeRange Nodes() noexcept
const std::optional< util::FilePath > & SourceFilePath() const noexcept
size_t nsubregions() const noexcept
void CollectDemandedStatistics(std::unique_ptr< Statistics > statistics)
util::Timer & GetTimer(const std::string &name)
Statistics(const Statistics::Id &statisticsId, util::FilePath sourceFile)
util::Timer & AddTimer(std::string name)
#define JLM_UNREACHABLE(msg)
Global memory state passed between functions.
static const char * Timer