[llvm-dev] [RFC] Should we add isa_or_null<>?

David Greene via llvm-dev llvm-dev at lists.llvm.org
Thu Apr 4 08:30:35 PDT 2019

I don't think that's a correct replacement.

if (var && isa<T>(var)) {

is not the same as:

if (isa_or_null<T>(var)) {

at least according to what "isa_or_null" conveys to me.

not_null_and_isa<T> would seem a better fit, or maybe exists_and_isa<T>.

That said, I'm not sure sure we need a special API for this.  Are
expensive calls used in the way you describe really common?


Don Hinton via llvm-dev <llvm-dev at lists.llvm.org> writes:

> I'd like to propose adding `isa_or_null<>` to replace the following usage pattern that's relatively common in conditionals:
>   var && isa<T>(var)  =>>  isa_or_null<T>(var)
> And in particular when `var` is a method call which might be expensive, e.g.:
>   X->foo() && isa<T>(X->foo())  =>>  isa_or_null<T>(X->foo())
> The implementation could be a simple wrapper around isa<>, and while the IR produced is only slightly more efficient, the elimination of an extra call could be
> worthwhile.
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

More information about the llvm-dev mailing list