From 38729a7086ae28e1bdd4f13b9500741c5a9920de Mon Sep 17 00:00:00 2001 From: Valentijn van de Beek Date: Mon, 13 May 2024 16:18:33 +0100 Subject: [PATCH] [GISel][CombinerHelper] Add a function that chains a list of generators together --- llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp index 102460631379..4cdd3d553eb4 100644 --- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp @@ -399,6 +399,21 @@ adderGenerator(const int32_t From, const int32_t To, const int32_t StepSize) { }; } +// Move to the next generator if it is exhausted allowing to chain generators +CombinerHelper::GeneratorType +concatGenerators(SmallVector &Generators) { + auto *GeneratorIterator = Generators.begin(); + + return [GeneratorIterator, Generators]() mutable { + std::optional GenValue = (*GeneratorIterator)(); + if (!GenValue.has_value() && GeneratorIterator != Generators.end()) { + GeneratorIterator++; + GenValue = (*GeneratorIterator)(); + } + return GenValue; + }; +} + Register CombinerHelper::createUnmergeValue( MachineInstr &MI, const Register SrcReg, const Register DstReg, const uint8_t DestinationIndex, const uint32_t Start, const uint32_t End) {