[PATCH] D104149: [MCA] Adding the CustomBehaviour class to llvm-mca

Andrea Di Biagio via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 15 12:19:41 PDT 2021


andreadb added a comment.

In D104149#2819949 <https://reviews.llvm.org/D104149#2819949>, @holland11 wrote:

>> Could the first argument be `ArrayRef<InstRef> IssuedInst`?
>
> The place that this argument comes from (in the in-order pipeline) is
>
>   class InOrderIssueStage final : public Stage {
>     ...
>     /// Instructions that were issued, but not executed yet.
>     SmallVector<InstRef, 4> IssuedInst;
>     ...
>     ...
>   };
>
> I didn't setup that `SmallVector` and I don't know enough about how those data structures work to know if it would be smart to change it to an ArrayRef or have it get casted into an ArrayRef on its way into the `checkCustomHazard` function (if that's even a possible cast).

If method `checkCustomHazard` is not expected to add/remove and/or modify any elements in IssuedInst, then that SmallVector can simply be passed as an ArrayRef.
You don't need to worry about changing how method `checkCustomHazard` is called, because there is a very convenient constructor in ArrayRef which accepts a SmallVector (https://llvm.org/doxygen/ArrayRef_8h_source.html#l00090).
So, you simply change the signature of your method, and everything should work fine.

Note that by passing a SmallVector as an ArrayRef, you prevent functions from modifying its content. The internal array-like structure is effectively immutable (there are only getters).

There are variations to the concept of "array reference". For example, class MutableArrayRef lets you mutate elements (but not add/remove existing elements). So the array size would still be fixed.

For maximum flexibility, a SmallVector can always be passed around as a SmallVectorImpl. The main difference between SmallVector and SmallVectorImpl, is that SmallVectorImpl doesn't require that you specify the default (template) number of inline elements from the declaration.

I suggest to have a quick look at the docs when you have time. Some of those classes are used very often in llvm. ArrayRef in particular is a very very useful class.

I hope this makes sense.


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

https://reviews.llvm.org/D104149



More information about the llvm-commits mailing list