[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:27 PST 2023


================
@@ -180,12 +180,13 @@ static int getItineraryLatency(LLVMDisasmContext *DC, const MCInst &Inst) {
   const MCInstrDesc& Desc = DC->getInstrInfo()->get(Inst.getOpcode());
   unsigned SCClass = Desc.getSchedClass();
 
-  int Latency = 0;
-  for (unsigned OpIdx = 0, OpIdxEnd = Inst.getNumOperands(); OpIdx != OpIdxEnd;
-       ++OpIdx)
-    Latency = std::max(Latency, IID.getOperandCycle(SCClass, OpIdx));
+  unsigned Latency = 0;
 
-  return Latency;
+  for (unsigned Idx = 0, IdxEnd = Inst.getNumOperands(); Idx != IdxEnd; ++Idx)
+    if (std::optional<unsigned> OperCycle = IID.getOperandCycle(SCClass, Idx))
+      Latency = std::max(Latency, *OperCycle);
+
+  return (int)Latency;
----------------
fpetrogalli wrote:

How bad is it going to be if we change this too to return std::optional<unsigned>? ("Bad" as in terms of extra work)

https://github.com/llvm/llvm-project/pull/73769


More information about the llvm-commits mailing list