16
16
#include " llvm/CodeGen/MachineOperand.h"
17
17
#include " llvm/CodeGen/MachineRegisterInfo.h"
18
18
#include " llvm/CodeGen/TargetLowering.h"
19
+ #include " llvm/IR/DiagnosticInfo.h"
19
20
#include " llvm/IR/Module.h"
20
21
21
22
#define DEBUG_TYPE " inline-asm-lowering"
@@ -231,6 +232,19 @@ bool InlineAsmLowering::lowerInlineAsm(
231
232
TargetLowering::AsmOperandInfoVector TargetConstraints =
232
233
TLI->ParseConstraints (DL, TRI, Call);
233
234
235
+ const auto ConstraintError = [&](const GISelAsmOperandInfo &Info, Twine Msg) {
236
+ // Use warnings in combination with a "return false" to trigger the fallback
237
+ // path. If fallback isn't enabled, then another error will be emitted later
238
+ // and the warnings will provide context as to why the error occured.
239
+ LLVMContext &Ctx = MIRBuilder.getContext ();
240
+ Ctx.diagnose (DiagnosticInfoInlineAsm (
241
+ Call, " invalid constraint '" + Info.ConstraintCode + " ': " + Msg,
242
+ DS_Warning));
243
+ // TODO: If we could detect that the fallback isn't enabled, we could
244
+ // recover here by defining all result registers as G_IMPLICIT_DEF.
245
+ return false ;
246
+ };
247
+
234
248
ExtraFlags ExtraInfo (Call);
235
249
unsigned ArgNo = 0 ; // ArgNo - The argument of the CallInst.
236
250
unsigned ResNo = 0 ; // ResNo - The result number of the next output.
@@ -243,8 +257,8 @@ bool InlineAsmLowering::lowerInlineAsm(
243
257
OpInfo.CallOperandVal = const_cast <Value *>(Call.getArgOperand (ArgNo));
244
258
245
259
if (isa<BasicBlock>(OpInfo.CallOperandVal )) {
246
- LLVM_DEBUG ( dbgs () << " Basic block input operands not supported yet \n " );
247
- return false ;
260
+ return ConstraintError (OpInfo,
261
+ " basic block input operands not supported yet " ) ;
248
262
}
249
263
250
264
Type *OpTy = OpInfo.CallOperandVal ->getType ();
@@ -258,9 +272,8 @@ bool InlineAsmLowering::lowerInlineAsm(
258
272
259
273
// FIXME: Support aggregate input operands
260
274
if (!OpTy->isSingleValueType ()) {
261
- LLVM_DEBUG (
262
- dbgs () << " Aggregate input operands are not supported yet\n " );
263
- return false ;
275
+ return ConstraintError (OpInfo,
276
+ " aggregate input operands not supported yet" );
264
277
}
265
278
266
279
OpInfo.ConstraintVT =
@@ -344,9 +357,8 @@ bool InlineAsmLowering::lowerInlineAsm(
344
357
345
358
// Find a register that we can use.
346
359
if (OpInfo.Regs .empty ()) {
347
- LLVM_DEBUG (dbgs ()
348
- << " Couldn't allocate output register for constraint\n " );
349
- return false ;
360
+ return ConstraintError (
361
+ OpInfo, " could not allocate output register for constraint" );
350
362
}
351
363
352
364
// Add information to the INLINEASM instruction to know that this
@@ -389,13 +401,13 @@ bool InlineAsmLowering::lowerInlineAsm(
389
401
390
402
const InlineAsm::Flag MatchedOperandFlag (Inst->getOperand (InstFlagIdx).getImm ());
391
403
if (MatchedOperandFlag.isMemKind ()) {
392
- LLVM_DEBUG (dbgs () << " Matching input constraint to mem operand not "
393
- " supported. This should be target specific.\n " );
394
- return false ;
404
+ return ConstraintError (
405
+ OpInfo,
406
+ " matching input constraint to mem operand not supported; this "
407
+ " should be target specific" );
395
408
}
396
409
if (!MatchedOperandFlag.isRegDefKind () && !MatchedOperandFlag.isRegDefEarlyClobberKind ()) {
397
- LLVM_DEBUG (dbgs () << " Unknown matching constraint\n " );
398
- return false ;
410
+ return ConstraintError (OpInfo, " unknown matching constraint" );
399
411
}
400
412
401
413
// We want to tie input to register in next operand.
@@ -425,9 +437,10 @@ bool InlineAsmLowering::lowerInlineAsm(
425
437
426
438
if (OpInfo.ConstraintType == TargetLowering::C_Other &&
427
439
OpInfo.isIndirect ) {
428
- LLVM_DEBUG (dbgs () << " Indirect input operands with unknown constraint "
429
- " not supported yet\n " );
430
- return false ;
440
+ return ConstraintError (
441
+ OpInfo,
442
+ " indirect input operands with unknown constraint not supported "
443
+ " yet" );
431
444
}
432
445
433
446
if (OpInfo.ConstraintType == TargetLowering::C_Immediate ||
@@ -437,9 +450,7 @@ bool InlineAsmLowering::lowerInlineAsm(
437
450
if (!lowerAsmOperandForConstraint (OpInfo.CallOperandVal ,
438
451
OpInfo.ConstraintCode , Ops,
439
452
MIRBuilder)) {
440
- LLVM_DEBUG (dbgs () << " Don't support constraint: "
441
- << OpInfo.ConstraintCode << " yet\n " );
442
- return false ;
453
+ return ConstraintError (OpInfo, " unsupported constraint" );
443
454
}
444
455
445
456
assert (Ops.size () > 0 &&
@@ -456,9 +467,8 @@ bool InlineAsmLowering::lowerInlineAsm(
456
467
if (OpInfo.ConstraintType == TargetLowering::C_Memory) {
457
468
458
469
if (!OpInfo.isIndirect ) {
459
- LLVM_DEBUG (dbgs ()
460
- << " Cannot indirectify memory input operands yet\n " );
461
- return false ;
470
+ return ConstraintError (
471
+ OpInfo, " indirect memory input operands are not supported yet" );
462
472
}
463
473
464
474
assert (OpInfo.isIndirect && " Operand must be indirect to be a mem!" );
@@ -482,18 +492,15 @@ bool InlineAsmLowering::lowerInlineAsm(
482
492
" Unknown constraint type!" );
483
493
484
494
if (OpInfo.isIndirect ) {
485
- LLVM_DEBUG (dbgs () << " Can't handle indirect register inputs yet "
486
- " for constraint '"
487
- << OpInfo.ConstraintCode << " '\n " );
488
- return false ;
495
+ return ConstraintError (
496
+ OpInfo, " indirect register inputs are not supported yet" );
489
497
}
490
498
491
499
// Copy the input into the appropriate registers.
492
500
if (OpInfo.Regs .empty ()) {
493
- LLVM_DEBUG (
494
- dbgs ()
495
- << " Couldn't allocate input register for register constraint\n " );
496
- return false ;
501
+ return ConstraintError (
502
+ OpInfo,
503
+ " could not allocate input register for register constraint" );
497
504
}
498
505
499
506
unsigned NumRegs = OpInfo.Regs .size ();
@@ -503,9 +510,10 @@ bool InlineAsmLowering::lowerInlineAsm(
503
510
" source registers" );
504
511
505
512
if (NumRegs > 1 ) {
506
- LLVM_DEBUG (dbgs () << " Input operands with multiple input registers are "
507
- " not supported yet\n " );
508
- return false ;
513
+ return ConstraintError (
514
+ OpInfo,
515
+ " input operands with multiple input registers are not supported "
516
+ " yet" );
509
517
}
510
518
511
519
InlineAsm::Flag Flag (InlineAsm::Kind::RegUse, NumRegs);
0 commit comments