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

David Sherwood via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 2 06:31:40 PST 2020


david-arm added inline comments.


================
Comment at: llvm/include/llvm/Analysis/InstructionCost.h:57
+  }
+
+  bool isValid() const { return State == Valid; }
----------------
ctetreau wrote:
> 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;
>   }
> ```
I think this request seems sensible to me, although this code does fail debug builds for me due to ambiguous operator<< overloads. I think I can work around this with an explicit getter, i.e.

  template <typename T>
  InstructionCost getValid(const T &Val) { ... }



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

https://reviews.llvm.org/D91174



More information about the llvm-commits mailing list