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,15 @@ 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
+ LLVMContext &Ctx = MIRBuilder.getContext ();
237
+ Ctx.diagnose (DiagnosticInfoInlineAsm (
238
+ Call, " invalid constraint '" + Info.ConstraintCode + " ': " + Msg));
239
+ // TODO: Recover if fallback isn't used. Otherwise let the fallback to DAG
240
+ // kick in.
241
+ return false ;
242
+ };
243
+
234
244
ExtraFlags ExtraInfo (Call);
235
245
unsigned ArgNo = 0 ; // ArgNo - The argument of the CallInst.
236
246
unsigned ResNo = 0 ; // ResNo - The result number of the next output.
@@ -243,8 +253,8 @@ bool InlineAsmLowering::lowerInlineAsm(
243
253
OpInfo.CallOperandVal = const_cast <Value *>(Call.getArgOperand (ArgNo));
244
254
245
255
if (isa<BasicBlock>(OpInfo.CallOperandVal )) {
246
- LLVM_DEBUG ( dbgs () << " Basic block input operands not supported yet \n " );
247
- return false ;
256
+ return ConstraintError (OpInfo,
257
+ " basic block input operands not supported yet " ) ;
248
258
}
249
259
250
260
Type *OpTy = OpInfo.CallOperandVal ->getType ();
@@ -258,9 +268,8 @@ bool InlineAsmLowering::lowerInlineAsm(
258
268
259
269
// FIXME: Support aggregate input operands
260
270
if (!OpTy->isSingleValueType ()) {
261
- LLVM_DEBUG (
262
- dbgs () << " Aggregate input operands are not supported yet\n " );
263
- return false ;
271
+ return ConstraintError (OpInfo,
272
+ " aggregate input operands not supported yet" );
264
273
}
265
274
266
275
OpInfo.ConstraintVT =
@@ -344,9 +353,8 @@ bool InlineAsmLowering::lowerInlineAsm(
344
353
345
354
// Find a register that we can use.
346
355
if (OpInfo.Regs .empty ()) {
347
- LLVM_DEBUG (dbgs ()
348
- << " Couldn't allocate output register for constraint\n " );
349
- return false ;
356
+ return ConstraintError (
357
+ OpInfo, " could not allocate output register for constraint" );
350
358
}
351
359
352
360
// Add information to the INLINEASM instruction to know that this
@@ -389,13 +397,13 @@ bool InlineAsmLowering::lowerInlineAsm(
389
397
390
398
const InlineAsm::Flag MatchedOperandFlag (Inst->getOperand (InstFlagIdx).getImm ());
391
399
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 ;
400
+ return ConstraintError (
401
+ OpInfo,
402
+ " matching input constraint to mem operand not supported; this "
403
+ " should be target specific" );
395
404
}
396
405
if (!MatchedOperandFlag.isRegDefKind () && !MatchedOperandFlag.isRegDefEarlyClobberKind ()) {
397
- LLVM_DEBUG (dbgs () << " Unknown matching constraint\n " );
398
- return false ;
406
+ return ConstraintError (OpInfo, " unknown matching constraint" );
399
407
}
400
408
401
409
// We want to tie input to register in next operand.
@@ -425,9 +433,10 @@ bool InlineAsmLowering::lowerInlineAsm(
425
433
426
434
if (OpInfo.ConstraintType == TargetLowering::C_Other &&
427
435
OpInfo.isIndirect ) {
428
- LLVM_DEBUG (dbgs () << " Indirect input operands with unknown constraint "
429
- " not supported yet\n " );
430
- return false ;
436
+ return ConstraintError (
437
+ OpInfo,
438
+ " indirect input operands with unknown constraint not supported "
439
+ " yet" );
431
440
}
432
441
433
442
if (OpInfo.ConstraintType == TargetLowering::C_Immediate ||
@@ -437,9 +446,7 @@ bool InlineAsmLowering::lowerInlineAsm(
437
446
if (!lowerAsmOperandForConstraint (OpInfo.CallOperandVal ,
438
447
OpInfo.ConstraintCode , Ops,
439
448
MIRBuilder)) {
440
- LLVM_DEBUG (dbgs () << " Don't support constraint: "
441
- << OpInfo.ConstraintCode << " yet\n " );
442
- return false ;
449
+ return ConstraintError (OpInfo, " unsupported constraint" );
443
450
}
444
451
445
452
assert (Ops.size () > 0 &&
@@ -456,9 +463,8 @@ bool InlineAsmLowering::lowerInlineAsm(
456
463
if (OpInfo.ConstraintType == TargetLowering::C_Memory) {
457
464
458
465
if (!OpInfo.isIndirect ) {
459
- LLVM_DEBUG (dbgs ()
460
- << " Cannot indirectify memory input operands yet\n " );
461
- return false ;
466
+ return ConstraintError (
467
+ OpInfo, " indirect memory input operands are not supported yet" );
462
468
}
463
469
464
470
assert (OpInfo.isIndirect && " Operand must be indirect to be a mem!" );
@@ -482,18 +488,15 @@ bool InlineAsmLowering::lowerInlineAsm(
482
488
" Unknown constraint type!" );
483
489
484
490
if (OpInfo.isIndirect ) {
485
- LLVM_DEBUG (dbgs () << " Can't handle indirect register inputs yet "
486
- " for constraint '"
487
- << OpInfo.ConstraintCode << " '\n " );
488
- return false ;
491
+ return ConstraintError (
492
+ OpInfo, " indirect register inputs are not supported yet" );
489
493
}
490
494
491
495
// Copy the input into the appropriate registers.
492
496
if (OpInfo.Regs .empty ()) {
493
- LLVM_DEBUG (
494
- dbgs ()
495
- << " Couldn't allocate input register for register constraint\n " );
496
- return false ;
497
+ return ConstraintError (
498
+ OpInfo,
499
+ " could not allocate input register for register constraint" );
497
500
}
498
501
499
502
unsigned NumRegs = OpInfo.Regs .size ();
@@ -503,9 +506,10 @@ bool InlineAsmLowering::lowerInlineAsm(
503
506
" source registers" );
504
507
505
508
if (NumRegs > 1 ) {
506
- LLVM_DEBUG (dbgs () << " Input operands with multiple input registers are "
507
- " not supported yet\n " );
508
- return false ;
509
+ return ConstraintError (
510
+ OpInfo,
511
+ " input operands with multiple input registers are not supported "
512
+ " yet" );
509
513
}
510
514
511
515
InlineAsm::Flag Flag (InlineAsm::Kind::RegUse, NumRegs);
0 commit comments