[llvm] TargetInstrInfo: make getOperandLatency return optional (NFC) (PR #73769)
Francesco Petrogalli via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 1 00:31:25 PST 2023
================
@@ -202,24 +204,25 @@ class InstrItineraryData {
/// Compute and return the use operand latency of a given itinerary
/// class and operand index if the value is produced by an instruction of the
/// specified itinerary class and def operand index.
- int getOperandLatency(unsigned DefClass, unsigned DefIdx,
- unsigned UseClass, unsigned UseIdx) const {
+ std::optional<unsigned> getOperandLatency(unsigned DefClass, unsigned DefIdx,
+ unsigned UseClass,
+ unsigned UseIdx) const {
if (isEmpty())
- return -1;
+ return std::nullopt;
- int DefCycle = getOperandCycle(DefClass, DefIdx);
- if (DefCycle == -1)
- return -1;
+ std::optional<unsigned> DefCycle = getOperandCycle(DefClass, DefIdx);
+ std::optional<unsigned> UseCycle = getOperandCycle(UseClass, UseIdx);
+ if (!DefCycle || !UseCycle)
+ return std::nullopt;
- int UseCycle = getOperandCycle(UseClass, UseIdx);
- if (UseCycle == -1)
- return -1;
+ if (UseCycle > *DefCycle + 1)
----------------
fpetrogalli wrote:
Is this needed? The old code
```cpp
int DefCycle = getOperandCycle(DefClass, DefIdx);
if (DefCycle == -1)
return -1;
int UseCycle = getOperandCycle(UseClass, UseIdx);
if (UseCycle == -1)
return -1;
```
seems to be already fully handled by
```cpp
std::optional<unsigned> DefCycle = getOperandCycle(DefClass, DefIdx);
std::optional<unsigned> UseCycle = getOperandCycle(UseClass, UseIdx);
if (!DefCycle || !UseCycle)
return std::nullopt;
```
Am I missing something?
https://github.com/llvm/llvm-project/pull/73769
More information about the llvm-commits
mailing list