@@ -213,17 +213,6 @@ static bool buildAnyextOrCopy(Register Dst, Register Src,
213213 return true ;
214214}
215215
216- static bool reportInlineAsmConstraintError (const CallBase &Call,
217- const GISelAsmOperandInfo &Info,
218- Twine Msg) {
219- LLVMContext &Ctx = Call.getContext ();
220- Ctx.diagnose (DiagnosticInfoInlineAsm (
221- Call, " invalid constraint '" + Info.ConstraintCode + " ': " + Msg));
222- // TODO(?): Allow selection to continue by recovering/leaving the gMIR in a
223- // good state, like the DAG does.
224- return false ;
225- }
226-
227216bool InlineAsmLowering::lowerInlineAsm (
228217 MachineIRBuilder &MIRBuilder, const CallBase &Call,
229218 std::function<ArrayRef<Register>(const Value &Val)> GetOrCreateVRegs)
@@ -243,6 +232,16 @@ bool InlineAsmLowering::lowerInlineAsm(
243232 TargetLowering::AsmOperandInfoVector TargetConstraints =
244233 TLI->ParseConstraints (DL, TRI, Call);
245234
235+ const auto ConstraintError = [&](const GISelAsmOperandInfo &Info, Twine Msg) {
236+ LLVMContext &Ctx = MIRBuilder.getContext ();
237+ Ctx.diagnose (DiagnosticInfoInlineAsm (
238+ Call, " invalid constraint '" + Info.ConstraintCode + " ' in '" +
239+ MF.getName () + " ': " + Msg));
240+ // TODO: Recover if fallback isn't used. Otherwise let the fallback to DAG
241+ // kick in.
242+ return false ;
243+ };
244+
246245 ExtraFlags ExtraInfo (Call);
247246 unsigned ArgNo = 0 ; // ArgNo - The argument of the CallInst.
248247 unsigned ResNo = 0 ; // ResNo - The result number of the next output.
@@ -255,8 +254,8 @@ bool InlineAsmLowering::lowerInlineAsm(
255254 OpInfo.CallOperandVal = const_cast <Value *>(Call.getArgOperand (ArgNo));
256255
257256 if (isa<BasicBlock>(OpInfo.CallOperandVal )) {
258- return reportInlineAsmConstraintError (
259- Call, OpInfo, " basic block input operands not supported yet" );
257+ return ConstraintError (OpInfo,
258+ " basic block input operands not supported yet" );
260259 }
261260
262261 Type *OpTy = OpInfo.CallOperandVal ->getType ();
@@ -270,8 +269,8 @@ bool InlineAsmLowering::lowerInlineAsm(
270269
271270 // FIXME: Support aggregate input operands
272271 if (!OpTy->isSingleValueType ()) {
273- return reportInlineAsmConstraintError (
274- Call, OpInfo, " aggregate input operands not supported yet" );
272+ return ConstraintError (OpInfo,
273+ " aggregate input operands not supported yet" );
275274 }
276275
277276 OpInfo.ConstraintVT =
@@ -355,8 +354,8 @@ bool InlineAsmLowering::lowerInlineAsm(
355354
356355 // Find a register that we can use.
357356 if (OpInfo.Regs .empty ()) {
358- return reportInlineAsmConstraintError (
359- Call, OpInfo, " couldn't allocate output register for constraint" );
357+ return ConstraintError (
358+ OpInfo, " could not allocate output register for constraint" );
360359 }
361360
362361 // Add information to the INLINEASM instruction to know that this
@@ -399,14 +398,13 @@ bool InlineAsmLowering::lowerInlineAsm(
399398
400399 const InlineAsm::Flag MatchedOperandFlag (Inst->getOperand (InstFlagIdx).getImm ());
401400 if (MatchedOperandFlag.isMemKind ()) {
402- return reportInlineAsmConstraintError (
403- Call, OpInfo,
401+ return ConstraintError (
402+ OpInfo,
404403 " matching input constraint to mem operand not supported; this "
405404 " should be target specific" );
406405 }
407406 if (!MatchedOperandFlag.isRegDefKind () && !MatchedOperandFlag.isRegDefEarlyClobberKind ()) {
408- return reportInlineAsmConstraintError (Call, OpInfo,
409- " unknown matching constraint" );
407+ return ConstraintError (OpInfo, " unknown matching constraint" );
410408 }
411409
412410 // We want to tie input to register in next operand.
@@ -436,8 +434,8 @@ bool InlineAsmLowering::lowerInlineAsm(
436434
437435 if (OpInfo.ConstraintType == TargetLowering::C_Other &&
438436 OpInfo.isIndirect ) {
439- return reportInlineAsmConstraintError (
440- Call, OpInfo,
437+ return ConstraintError (
438+ OpInfo,
441439 " indirect input operands with unknown constraint not supported "
442440 " yet" );
443441 }
@@ -449,8 +447,7 @@ bool InlineAsmLowering::lowerInlineAsm(
449447 if (!lowerAsmOperandForConstraint (OpInfo.CallOperandVal ,
450448 OpInfo.ConstraintCode , Ops,
451449 MIRBuilder)) {
452- return reportInlineAsmConstraintError (Call, OpInfo,
453- " unsupported constraint" );
450+ return ConstraintError (OpInfo, " unsupported constraint" );
454451 }
455452
456453 assert (Ops.size () > 0 &&
@@ -467,9 +464,8 @@ bool InlineAsmLowering::lowerInlineAsm(
467464 if (OpInfo.ConstraintType == TargetLowering::C_Memory) {
468465
469466 if (!OpInfo.isIndirect ) {
470- return reportInlineAsmConstraintError (
471- Call, OpInfo,
472- " indirect memory input operands are not supported yet" );
467+ return ConstraintError (
468+ OpInfo, " indirect memory input operands are not supported yet" );
473469 }
474470
475471 assert (OpInfo.isIndirect && " Operand must be indirect to be a mem!" );
@@ -493,15 +489,15 @@ bool InlineAsmLowering::lowerInlineAsm(
493489 " Unknown constraint type!" );
494490
495491 if (OpInfo.isIndirect ) {
496- return reportInlineAsmConstraintError (
497- Call, OpInfo, " indirect register inputs are not supported yet" );
492+ return ConstraintError (
493+ OpInfo, " indirect register inputs are not supported yet" );
498494 }
499495
500496 // Copy the input into the appropriate registers.
501497 if (OpInfo.Regs .empty ()) {
502- return reportInlineAsmConstraintError (
503- Call, OpInfo,
504- " couldn't allocate input register for register constraint" );
498+ return ConstraintError (
499+ OpInfo,
500+ " could not allocate input register for register constraint" );
505501 }
506502
507503 unsigned NumRegs = OpInfo.Regs .size ();
@@ -511,8 +507,8 @@ bool InlineAsmLowering::lowerInlineAsm(
511507 " source registers" );
512508
513509 if (NumRegs > 1 ) {
514- return reportInlineAsmConstraintError (
515- Call, OpInfo,
510+ return ConstraintError (
511+ OpInfo,
516512 " input operands with multiple input registers are not supported "
517513 " yet" );
518514 }
0 commit comments