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 auto [matchNode, matchOperation] =
125 rvsdg::TryGetSimpleNodeAndOptionalOp<rvsdg::MatchOperation>(*gammaPredicate);
128 if (std::distance(matchOperation->begin(), matchOperation->end()) != 1)
141 const auto matchOrigin = matchNode->input(0)->origin();
142 const auto caseValue = matchOperation->begin()->first;
143 const auto caseSubregion = matchOperation->begin()->second;
144 const auto defaultSubregion = matchOperation->default_alternative();
145 const auto numMatchBits = matchOperation->nbits();
146 JLM_ASSERT(caseSubregion != defaultSubregion);
148 if (numMatchBits == 1 && caseValue == caseSubregion)
154 auto & selectNode = rvsdg::CreateOpNode<SelectOperation>(
155 { matchOrigin, origin1, origin0 },
156 gammaOutput->Type());
157 gammaOutput->divert_users(selectNode.output(0));
163 auto & constantNode = rvsdg::CreateOpNode<IntegerConstantOperation>(
166 auto & eqNode = rvsdg::CreateOpNode<IntegerEqOperation>(
167 { constantNode.output(0), matchOrigin },
170 auto trueAlternative = caseSubregion == 0 ? origin0 : origin1;
171 auto falseAlternative = caseSubregion == 0 ? origin1 : origin0;
172 auto & selectNode = rvsdg::CreateOpNode<SelectOperation>(
173 { eqNode.output(0), trueAlternative, falseAlternative },
174 gammaOutput->Type());
175 gammaOutput->divert_users(selectNode.output(0));
180 const auto falseAlternative = origin0;
181 const auto trueAlternative = origin1;
182 auto & controlToIntNode = rvsdg::CreateOpNode<ControlToIntOperation>(
186 auto & selectNode = rvsdg::CreateOpNode<SelectOperation>(
187 { controlToIntNode.output(0), trueAlternative, falseAlternative },
188 gammaOutput->Type());
189 gammaOutput->divert_users(selectNode.output(0));
static jlm::util::StatisticsCollector statisticsCollector
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