[llvm] [CodeGen] Use a range-based for loop (NFC) (PR #97177)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 29 17:01:37 PDT 2024
kazutakahirata wrote:
> Isn't that loop just a `find_first_of()`?
It is. If we save the iterator range to a temporary variable, it may be doable. That is:
```
if (MI && MI->isInlineAsm())
MI->emitError(...);
else if (MI)
MI->emitError(...);
```
would become something like:
```
auto RegInstrs = MRI->reg_instructions(VirtReg->reg());
auto MI = llvm::find_if(RegInstrs, [&](const MachineInstr &MIR) {
return MIR->isInlineAsm();
});
if (MI != RegInstrs.end())
MI->emitError(...);
else if (!RegInstrs.empty())
std::prev(RegInstrs.end())->emitError(...);
```
I sort of like the original code because `MI` encodes everything we need.
https://github.com/llvm/llvm-project/pull/97177
More information about the llvm-commits
mailing list