@@ -213,17 +213,6 @@ static bool buildAnyextOrCopy(Register Dst, Register Src,
213
213
return true ;
214
214
}
215
215
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
-
227
216
bool InlineAsmLowering::lowerInlineAsm (
228
217
MachineIRBuilder &MIRBuilder, const CallBase &Call,
229
218
std::function<ArrayRef<Register>(const Value &Val)> GetOrCreateVRegs)
@@ -243,6 +232,16 @@ bool InlineAsmLowering::lowerInlineAsm(
243
232
TargetLowering::AsmOperandInfoVector TargetConstraints =
244
233
TLI->ParseConstraints (DL, TRI, Call);
245
234
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
+
246
245
ExtraFlags ExtraInfo (Call);
247
246
unsigned ArgNo = 0 ; // ArgNo - The argument of the CallInst.
248
247
unsigned ResNo = 0 ; // ResNo - The result number of the next output.
@@ -255,8 +254,8 @@ bool InlineAsmLowering::lowerInlineAsm(
255
254
OpInfo.CallOperandVal = const_cast <Value *>(Call.getArgOperand (ArgNo));
256
255
257
256
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" );
260
259
}
261
260
262
261
Type *OpTy = OpInfo.CallOperandVal ->getType ();
@@ -270,8 +269,8 @@ bool InlineAsmLowering::lowerInlineAsm(
270
269
271
270
// FIXME: Support aggregate input operands
272
271
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" );
275
274
}
276
275
277
276
OpInfo.ConstraintVT =
@@ -355,8 +354,8 @@ bool InlineAsmLowering::lowerInlineAsm(
355
354
356
355
// Find a register that we can use.
357
356
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" );
360
359
}
361
360
362
361
// Add information to the INLINEASM instruction to know that this
@@ -399,14 +398,13 @@ bool InlineAsmLowering::lowerInlineAsm(
399
398
400
399
const InlineAsm::Flag MatchedOperandFlag (Inst->getOperand (InstFlagIdx).getImm ());
401
400
if (MatchedOperandFlag.isMemKind ()) {
402
- return reportInlineAsmConstraintError (
403
- Call, OpInfo,
401
+ return ConstraintError (
402
+ OpInfo,
404
403
" matching input constraint to mem operand not supported; this "
405
404
" should be target specific" );
406
405
}
407
406
if (!MatchedOperandFlag.isRegDefKind () && !MatchedOperandFlag.isRegDefEarlyClobberKind ()) {
408
- return reportInlineAsmConstraintError (Call, OpInfo,
409
- " unknown matching constraint" );
407
+ return ConstraintError (OpInfo, " unknown matching constraint" );
410
408
}
411
409
412
410
// We want to tie input to register in next operand.
@@ -436,8 +434,8 @@ bool InlineAsmLowering::lowerInlineAsm(
436
434
437
435
if (OpInfo.ConstraintType == TargetLowering::C_Other &&
438
436
OpInfo.isIndirect ) {
439
- return reportInlineAsmConstraintError (
440
- Call, OpInfo,
437
+ return ConstraintError (
438
+ OpInfo,
441
439
" indirect input operands with unknown constraint not supported "
442
440
" yet" );
443
441
}
@@ -449,8 +447,7 @@ bool InlineAsmLowering::lowerInlineAsm(
449
447
if (!lowerAsmOperandForConstraint (OpInfo.CallOperandVal ,
450
448
OpInfo.ConstraintCode , Ops,
451
449
MIRBuilder)) {
452
- return reportInlineAsmConstraintError (Call, OpInfo,
453
- " unsupported constraint" );
450
+ return ConstraintError (OpInfo, " unsupported constraint" );
454
451
}
455
452
456
453
assert (Ops.size () > 0 &&
@@ -467,9 +464,8 @@ bool InlineAsmLowering::lowerInlineAsm(
467
464
if (OpInfo.ConstraintType == TargetLowering::C_Memory) {
468
465
469
466
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" );
473
469
}
474
470
475
471
assert (OpInfo.isIndirect && " Operand must be indirect to be a mem!" );
@@ -493,15 +489,15 @@ bool InlineAsmLowering::lowerInlineAsm(
493
489
" Unknown constraint type!" );
494
490
495
491
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" );
498
494
}
499
495
500
496
// Copy the input into the appropriate registers.
501
497
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" );
505
501
}
506
502
507
503
unsigned NumRegs = OpInfo.Regs .size ();
@@ -511,8 +507,8 @@ bool InlineAsmLowering::lowerInlineAsm(
511
507
" source registers" );
512
508
513
509
if (NumRegs > 1 ) {
514
- return reportInlineAsmConstraintError (
515
- Call, OpInfo,
510
+ return ConstraintError (
511
+ OpInfo,
516
512
" input operands with multiple input registers are not supported "
517
513
" yet" );
518
514
}
0 commit comments