Skip to content

Commit 86845b8

Browse files
[GISel][CombinerHelper] Add a function that chains a list of generators together
1 parent 50981ad commit 86845b8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,21 @@ adderGenerator(const int32_t From, const int32_t To, const int32_t StepSize) {
316316
};
317317
}
318318

319+
// Move to the next generator if it is exhausted allowing to chain generators
320+
std::function<std::optional<int32_t>()> concatGenerators(
321+
SmallVector<std::function<std::optional<int32_t>()>> Generators) {
322+
auto *GeneratorIterator = Generators.begin();
323+
324+
return [GeneratorIterator, Generators]() mutable {
325+
std::optional<int32_t> GenValue = (*GeneratorIterator)();
326+
if (!GenValue.has_value() && GeneratorIterator != Generators.end()) {
327+
GeneratorIterator++;
328+
GenValue = (*GeneratorIterator)();
329+
}
330+
return GenValue;
331+
};
332+
}
333+
319334
Register CombinerHelper::createUnmergeValue(MachineInstr &MI,
320335
const Register SrcReg,
321336
const Register DstReg,

0 commit comments

Comments
 (0)