@@ -335,6 +335,8 @@ bool TypeSetByHwMode::intersect(SetType &Out, const SetType &In) {
335335 using WildPartT = std::pair<MVT, std::function<bool (MVT)>>;
336336 static const WildPartT WildParts[] = {
337337 {MVT::iPTR, [](MVT T) { return T.isScalarInteger () || T == MVT::iPTR; }},
338+ {MVT::cPTR,
339+ [](MVT T) { return T.isCheriCapability () || T == MVT::cPTR; }},
338340 };
339341
340342 bool Changed = false ;
@@ -816,6 +818,11 @@ void TypeInfer::expandOverloads(TypeSetByHwMode::SetType &Out,
816818 if (Out.count (MVT::pAny)) {
817819 Out.erase (MVT::pAny);
818820 Out.insert (MVT::iPTR);
821+ for (MVT T : MVT::cheri_capability_valuetypes ()) {
822+ if (Legal.count (T)) {
823+ Out.insert (MVT::cPTR);
824+ }
825+ }
819826 } else if (Out.count (MVT::iAny)) {
820827 Out.erase (MVT::iAny);
821828 for (MVT T : MVT::integer_valuetypes ())
@@ -1647,9 +1654,11 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode &N,
16471654 case SDTCisVT:
16481655 // Operand must be a particular type.
16491656 return NodeToApply.UpdateNodeType (ResNo, VVT, TP);
1650- case SDTCisPtrTy:
1651- // Operand must be same as target pointer type.
1652- return NodeToApply.UpdateNodeType (ResNo, MVT::iPTR, TP);
1657+ case SDTCisPtrTy: {
1658+ // Operand must be a legal pointer (iPTR, or possibly cPTR) type.
1659+ const auto &PtrTys = TP.getDAGPatterns ().getLegalPtrTypes ();
1660+ return NodeToApply.UpdateNodeType (ResNo, PtrTys, TP);
1661+ }
16531662 case SDTCisInt:
16541663 // Require it to be one of the legal integer VTs.
16551664 return TI.EnforceInteger (NodeToApply.getExtType (ResNo));
@@ -3260,6 +3269,7 @@ CodeGenDAGPatterns::CodeGenDAGPatterns(const RecordKeeper &R,
32603269 PatternRewriterFn PatternRewriter)
32613270 : Records(R), Target(R), Intrinsics(R),
32623271 LegalVTS(Target.getLegalValueTypes()),
3272+ LegalPtrVTS(ComputeLegalPtrTypes()),
32633273 PatternRewriter(std::move(PatternRewriter)) {
32643274 ParseNodeInfo ();
32653275 ParseNodeTransforms ();
@@ -3295,6 +3305,36 @@ const Record *CodeGenDAGPatterns::getSDNodeNamed(StringRef Name) const {
32953305 return N;
32963306}
32973307
3308+ // Compute the subset of iPTR and cPTR legal for each mode, coalescing into the
3309+ // default mode where possible to avoid predicate explosion.
3310+ TypeSetByHwMode CodeGenDAGPatterns::ComputeLegalPtrTypes () const {
3311+ auto LegalPtrsForSet = [](const MachineValueTypeSet &In) {
3312+ MachineValueTypeSet Out;
3313+ Out.insert (MVT::iPTR);
3314+ for (MVT T : MVT::cheri_capability_valuetypes ()) {
3315+ if (In.count (T)) {
3316+ Out.insert (MVT::cPTR);
3317+ break ;
3318+ }
3319+ }
3320+ return Out;
3321+ };
3322+
3323+ const auto &LegalTypes = getLegalTypes ();
3324+ MachineValueTypeSet LegalPtrsDefault =
3325+ LegalPtrsForSet (LegalTypes.get (DefaultMode));
3326+
3327+ TypeSetByHwMode LegalPtrTypes;
3328+ for (const auto &I : LegalTypes) {
3329+ MachineValueTypeSet S = LegalPtrsForSet (I.second );
3330+ if (I.first != DefaultMode && S == LegalPtrsDefault)
3331+ continue ;
3332+ LegalPtrTypes.getOrCreate (I.first ).insert (S);
3333+ }
3334+
3335+ return LegalPtrTypes;
3336+ }
3337+
32983338// Parse all of the SDNode definitions for the target, populating SDNodes.
32993339void CodeGenDAGPatterns::ParseNodeInfo () {
33003340 const CodeGenHwModes &CGH = getTargetInfo ().getHwModes ();
0 commit comments