This is an archive of the discontinued LLVM Phabricator instance.

[NFC][Metadata] Change MDNode::operands()'s return type from op_range to ArrayRef<MDOperand>
ClosedPublic

Authored by yurai007 on Jul 12 2022, 7:59 AM.

Diff Detail

Event Timeline

yurai007 created this revision.Jul 12 2022, 7:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2022, 7:59 AM
yurai007 requested review of this revision.Jul 12 2022, 7:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2022, 7:59 AM
dexonsmith added inline comments.Jul 12 2022, 10:40 AM
llvm/include/llvm/IR/Metadata.h
1348

I’m surprised SmallVector doesn’t have a generic constructor from ArrayRef. I wonder if it should?

(why did the iterator_range work before, but ArrayRef doesn’t?)

yurai007 added inline comments.Jul 13 2022, 6:30 AM
llvm/include/llvm/IR/Metadata.h
1348

That's because SmallVector has appropriate constructor:

template <typename RangeTy>
explicit SmallVector(const iterator_range<RangeTy> &R);

but is lacking one for ArrayRef. However from what I can see by browsing containers definitions in llvm/ADT, convenience constructors taking ArrayRefs are not very popular. There is only TinyPtrVector which has one. But the same can be said for iterator_range - only SmallVector constructor takes it.
Even if constructing SmallVector from ArrayRef's iterators seem to not be extremely popular, still, I can find some places in code base (except ones from this change ofc. ) that would benefit from having convenience constructor - files where ArrayRef mask is used like X86ISelLowering.cpp, HexagonISelDAGToDAGHVX.cpp and DAGCombiner.cpp.

dexonsmith accepted this revision.Jul 13 2022, 9:32 AM

This looks good to me, but it’d be nice to clean up further somehow later, maybe by adding a new free function.

llvm/include/llvm/IR/Metadata.h
1348

I was wondering if to_vector<Metadata *>(operands()) would work here, but it doesn’t have a template for the value type. We’d need a new thing, to_vector_of<>, which took the desired value type as the first parameter.

This revision is now accepted and ready to land.Jul 13 2022, 9:32 AM

This looks good to me, but it’d be nice to clean up further somehow later, maybe by adding a new free function.

Thanks for the review! Sure, I'm gonna continue cleaning up this with to_vector_of in next patch.

yurai007 updated this revision to Diff 444529.Jul 13 2022, 11:36 PM

Add main one and missing operands() usage in TypeBasedAliasAnalysis

This revision was landed with ongoing or failed builds.Jul 14 2022, 8:23 AM
This revision was automatically updated to reflect the committed changes.