-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[VPlan] Support isa/dyn_cast from VPRecipeBase to VPIRMetadata (NFC). #166245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
cc88413
ac805f4
723d7d0
cb3e110
0c52096
8f488f3
effe8a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -3869,6 +3869,77 @@ template <> | |||||||
| struct CastInfo<VPPhiAccessors, const VPRecipeBase *> | ||||||||
| : CastInfoVPPhiAccessors<const VPRecipeBase *> {}; | ||||||||
|
|
||||||||
| /// Casting from VPRecipeBase -> VPIRMetadata is supported for all recipe types | ||||||||
| /// implementing VPIRMetadata. Used by isa<> & co. | ||||||||
| namespace detail { | ||||||||
| /// Returns const VPIRMetadata* if input is const, and VPIRMetadata* otherwise. | ||||||||
| template <typename RecipeBasePtrTy> | ||||||||
| static inline auto castToVPIRMetadata(RecipeBasePtrTy R) -> std::conditional_t< | ||||||||
| std::is_const_v<std::remove_pointer_t<RecipeBasePtrTy>>, | ||||||||
| const VPIRMetadata *, VPIRMetadata *> { | ||||||||
| switch (R->getVPDefID()) { | ||||||||
| case VPDef::VPInstructionSC: | ||||||||
| return cast<VPInstruction>(R); | ||||||||
| case VPDef::VPWidenSC: | ||||||||
| return cast<VPWidenRecipe>(R); | ||||||||
| case VPDef::VPWidenCastSC: | ||||||||
| return cast<VPWidenCastRecipe>(R); | ||||||||
| case VPDef::VPWidenIntrinsicSC: | ||||||||
| return cast<VPWidenIntrinsicRecipe>(R); | ||||||||
| case VPDef::VPWidenCallSC: | ||||||||
| return cast<VPWidenCallRecipe>(R); | ||||||||
| case VPDef::VPWidenSelectSC: | ||||||||
| return cast<VPWidenSelectRecipe>(R); | ||||||||
| case VPDef::VPReplicateSC: | ||||||||
| return cast<VPReplicateRecipe>(R); | ||||||||
| case VPDef::VPInterleaveSC: | ||||||||
| return cast<VPInterleaveRecipe>(R); | ||||||||
| case VPDef::VPInterleaveEVLSC: | ||||||||
| return cast<VPInterleaveEVLRecipe>(R); | ||||||||
| case VPDef::VPWidenLoadSC: | ||||||||
| return cast<VPWidenLoadRecipe>(R); | ||||||||
| case VPDef::VPWidenLoadEVLSC: | ||||||||
| return cast<VPWidenLoadEVLRecipe>(R); | ||||||||
| case VPDef::VPWidenStoreSC: | ||||||||
| return cast<VPWidenStoreRecipe>(R); | ||||||||
| case VPDef::VPWidenStoreEVLSC: | ||||||||
| return cast<VPWidenStoreEVLRecipe>(R); | ||||||||
| default: | ||||||||
| llvm_unreachable("invalid recipe for VPIRMetadata cast"); | ||||||||
| } | ||||||||
| } | ||||||||
| } // namespace detail | ||||||||
|
|
||||||||
| /// Support casting from VPRecipeBase -> VPIRMetadata, by down-casting to the | ||||||||
| /// recipe types implementing VPIRMetadata. Used by cast<>, dyn_cast<> & co. | ||||||||
| template <typename SrcTy> | ||||||||
| struct CastInfoVPIRMetadata : public CastIsPossible<VPIRMetadata, SrcTy> { | ||||||||
| static inline bool isPossible(SrcTy R) { | ||||||||
| return isa<VPInstruction, VPWidenRecipe, VPWidenCastRecipe, | ||||||||
| VPWidenIntrinsicRecipe, VPWidenCallRecipe, VPWidenSelectRecipe, | ||||||||
| VPReplicateRecipe, VPInterleaveRecipe, VPInterleaveEVLRecipe, | ||||||||
| VPWidenLoadRecipe, VPWidenLoadEVLRecipe, VPWidenStoreRecipe, | ||||||||
| VPWidenStoreEVLRecipe>(R); | ||||||||
|
Comment on lines
+3920
to
+3924
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to note at VPIRMetadata that any recipe inheriting from it should be listed here. Also for VPPhiAccessors.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added thanks |
||||||||
| } | ||||||||
|
|
||||||||
| using Self = CastInfo<VPIRMetadata, SrcTy>; | ||||||||
| using RetTy = decltype(detail::castToVPIRMetadata(std::declval<SrcTy>())); | ||||||||
|
|
||||||||
| static inline RetTy doCast(SrcTy R) { return detail::castToVPIRMetadata(R); } | ||||||||
|
||||||||
| static inline RetTy doCast(SrcTy R) { return detail::castToVPIRMetadata(R); } | |
| /// doCast is used by cast<>. | |
| static inline RetTy doCast(SrcTy R) { return detail::castToVPIRMetadata(R); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| static inline RetTy doCastIfPossible(SrcTy R) { | |
| /// doCastIfPossible is used by dyn_cast<>. | |
| static inline RetTy doCastIfPossible(SrcTy R) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't we casting from a const to a non-const pointer here - is this safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(somehow my response seem to got lost, but that should be taken care of now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Independent consistency follow-up: should the above down-casting to VPPhiAccessors also support non/const-ness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above supports const/non-const with const_cast. I can update it to use the same approach as here, after this PR lands