[PATCH] D91174: [Analysis] Introduce a new InstructionCost class

Christopher Tetreault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 1 08:43:03 PST 2020


ctetreau added inline comments.


================
Comment at: llvm/include/llvm/Analysis/InstructionCost.h:57
+  }
+
+  bool isValid() const { return State == Valid; }
----------------
Feature request: Please add ctors and getters such that you can implicitly convert from various numeric types and Optionals. See D92178 for motivation for this. Locally, I added:

```
  template <typename ConvertsToCostTypeT>
  InstructionCost(const ConvertsToCostTypeT& Val) : Value(Val), State(Valid) {}
  
  template <typename ConvertsToCostTypeT>
  InstructionCost(const Optional<ConvertsToCostTypeT>& Val) {
    if (Val) {
      Value = *Val;
      State = Valid;
    }
    else
      State = Invalid;
  }

  static InstructionCost getInvalid() {
    return getInvalid(0);
  }

  template <typename ConvertsToCostTypeT>
  static InstructionCost getInvalid(const ConvertsToCostTypeT& Val) {
    InstructionCost Tmp(Val);
    Tmp.setInvalid();
    return Tmp;
  }
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91174/new/

https://reviews.llvm.org/D91174



More information about the llvm-commits mailing list