@@ -842,6 +842,26 @@ static void getCopyToPartsVector(SelectionDAG &DAG, const SDLoc &DL,
842842 }
843843}
844844
845+ static void failForInvalidBundles (const CallBase &I, StringRef Name,
846+ ArrayRef<uint32_t > AllowedBundles) {
847+ if (I.hasOperandBundlesOtherThan (AllowedBundles)) {
848+ std::string Error;
849+ for (unsigned i = 0 , e = I.getNumOperandBundles (); i != e; ++i) {
850+ OperandBundleUse U = I.getOperandBundleAt (i);
851+ bool First = true ;
852+ if (is_contained (AllowedBundles, U.getTagID ()))
853+ continue ;
854+ if (!First)
855+ Error += " , " ;
856+ First = false ;
857+ Error += U.getTagName ();
858+ }
859+ reportFatalUsageError (
860+ Twine (" cannot lower " , Name)
861+ .concat (Twine (" with arbitrary operand bundles: " , Error)));
862+ }
863+ }
864+
845865RegsForValue::RegsForValue (const SmallVector<Register, 4 > ®s, MVT regvt,
846866 EVT valuevt, std::optional<CallingConv::ID> CC)
847867 : ValueVTs(1 , valuevt), RegVTs(1 , regvt), Regs(regs),
@@ -3351,30 +3371,12 @@ void SelectionDAGBuilder::visitInvoke(const InvokeInst &I) {
33513371
33523372 // Deopt and ptrauth bundles are lowered in helper functions, and we don't
33533373 // have to do anything here to lower funclet bundles.
3354- constexpr uint32_t kAllowedBundles [] = {
3355- LLVMContext::OB_deopt,
3356- LLVMContext::OB_gc_transition,
3357- LLVMContext::OB_gc_live,
3358- LLVMContext::OB_funclet,
3359- LLVMContext::OB_cfguardtarget,
3360- LLVMContext::OB_ptrauth,
3361- LLVMContext::OB_clang_arc_attachedcall,
3362- LLVMContext::OB_kcfi};
3363- if (I.hasOperandBundlesOtherThan (kAllowedBundles )) {
3364- std::string Error;
3365- for (unsigned i = 0 , e = I.getNumOperandBundles (); i != e; ++i) {
3366- OperandBundleUse U = I.getOperandBundleAt (i);
3367- bool First = true ;
3368- if (is_contained (kAllowedBundles , U.getTagID ()))
3369- continue ;
3370- if (!First)
3371- Error += " , " ;
3372- First = false ;
3373- Error += U.getTagName ();
3374- }
3375- reportFatalUsageError (
3376- Twine (" cannot lower invokes with arbitrary operand bundles: " , Error));
3377- }
3374+ failForInvalidBundles (I, " invokes" ,
3375+ {LLVMContext::OB_deopt, LLVMContext::OB_gc_transition,
3376+ LLVMContext::OB_gc_live, LLVMContext::OB_funclet,
3377+ LLVMContext::OB_cfguardtarget, LLVMContext::OB_ptrauth,
3378+ LLVMContext::OB_clang_arc_attachedcall,
3379+ LLVMContext::OB_kcfi});
33783380
33793381 const Value *Callee (I.getCalledOperand ());
33803382 const Function *Fn = dyn_cast<Function>(Callee);
@@ -3474,10 +3476,8 @@ void SelectionDAGBuilder::visitCallBr(const CallBrInst &I) {
34743476
34753477 // Deopt bundles are lowered in LowerCallSiteWithDeoptBundle, and we don't
34763478 // have to do anything here to lower funclet bundles.
3477- if (I.hasOperandBundlesOtherThan (
3478- {LLVMContext::OB_deopt, LLVMContext::OB_funclet}))
3479- reportFatalUsageError (
3480- " cannot lower callbrs with arbitrary operand bundles!" );
3479+ failForInvalidBundles (I, " callbrs" ,
3480+ {LLVMContext::OB_deopt, LLVMContext::OB_funclet});
34813481
34823482 assert (I.isInlineAsm () && " Only know how to handle inlineasm callbr" );
34833483 visitInlineAsm (I);
@@ -9585,12 +9585,12 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
95859585 // Deopt bundles are lowered in LowerCallSiteWithDeoptBundle, and we don't
95869586 // have to do anything here to lower funclet bundles.
95879587 // CFGuardTarget bundles are lowered in LowerCallTo.
9588- if (I. hasOperandBundlesOtherThan (
9589- {LLVMContext::OB_deopt, LLVMContext::OB_funclet ,
9590- LLVMContext::OB_cfguardtarget , LLVMContext::OB_preallocated ,
9591- LLVMContext::OB_clang_arc_attachedcall , LLVMContext::OB_kcfi ,
9592- LLVMContext::OB_convergencectrl}))
9593- reportFatalUsageError ( " cannot lower calls with arbitrary operand bundles! " );
9588+ failForInvalidBundles (
9589+ I, " calls " ,
9590+ { LLVMContext::OB_deopt , LLVMContext::OB_funclet ,
9591+ LLVMContext::OB_cfguardtarget , LLVMContext::OB_preallocated ,
9592+ LLVMContext::OB_clang_arc_attachedcall, LLVMContext::OB_kcfi,
9593+ LLVMContext::OB_convergencectrl} );
95949594
95959595 SDValue Callee = getValue (I.getCalledOperand ());
95969596
0 commit comments