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"
@@ -212,6 +213,17 @@ static bool buildAnyextOrCopy(Register Dst, Register Src,
212
213
return true ;
213
214
}
214
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
+
215
227
bool InlineAsmLowering::lowerInlineAsm (
216
228
MachineIRBuilder &MIRBuilder, const CallBase &Call,
217
229
std::function<ArrayRef<Register>(const Value &Val)> GetOrCreateVRegs)
@@ -243,8 +255,8 @@ bool InlineAsmLowering::lowerInlineAsm(
243
255
OpInfo.CallOperandVal = const_cast <Value *>(Call.getArgOperand (ArgNo));
244
256
245
257
if (isa<BasicBlock>(OpInfo.CallOperandVal )) {
246
- LLVM_DEBUG ( dbgs () << " Basic block input operands not supported yet \n " );
247
- return false ;
258
+ return reportInlineAsmConstraintError (
259
+ Call, OpInfo, " basic block input operands not supported yet " ) ;
248
260
}
249
261
250
262
Type *OpTy = OpInfo.CallOperandVal ->getType ();
@@ -258,9 +270,8 @@ bool InlineAsmLowering::lowerInlineAsm(
258
270
259
271
// FIXME: Support aggregate input operands
260
272
if (!OpTy->isSingleValueType ()) {
261
- LLVM_DEBUG (
262
- dbgs () << " Aggregate input operands are not supported yet\n " );
263
- return false ;
273
+ return reportInlineAsmConstraintError (
274
+ Call, OpInfo, " aggregate input operands not supported yet" );
264
275
}
265
276
266
277
OpInfo.ConstraintVT =
@@ -344,9 +355,8 @@ bool InlineAsmLowering::lowerInlineAsm(
344
355
345
356
// Find a register that we can use.
346
357
if (OpInfo.Regs .empty ()) {
347
- LLVM_DEBUG (dbgs ()
348
- << " Couldn't allocate output register for constraint\n " );
349
- return false ;
358
+ return reportInlineAsmConstraintError (
359
+ Call, OpInfo, " couldn't allocate output register for constraint" );
350
360
}
351
361
352
362
// Add information to the INLINEASM instruction to know that this
@@ -389,13 +399,14 @@ bool InlineAsmLowering::lowerInlineAsm(
389
399
390
400
const InlineAsm::Flag MatchedOperandFlag (Inst->getOperand (InstFlagIdx).getImm ());
391
401
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 ;
402
+ return reportInlineAsmConstraintError (
403
+ Call, OpInfo,
404
+ " matching input constraint to mem operand not supported; this "
405
+ " should be target specific" );
395
406
}
396
407
if (!MatchedOperandFlag.isRegDefKind () && !MatchedOperandFlag.isRegDefEarlyClobberKind ()) {
397
- LLVM_DEBUG ( dbgs () << " Unknown matching constraint \n " );
398
- return false ;
408
+ return reportInlineAsmConstraintError (Call, OpInfo,
409
+ " unknown matching constraint " ) ;
399
410
}
400
411
401
412
// We want to tie input to register in next operand.
@@ -425,9 +436,10 @@ bool InlineAsmLowering::lowerInlineAsm(
425
436
426
437
if (OpInfo.ConstraintType == TargetLowering::C_Other &&
427
438
OpInfo.isIndirect ) {
428
- LLVM_DEBUG (dbgs () << " Indirect input operands with unknown constraint "
429
- " not supported yet\n " );
430
- return false ;
439
+ return reportInlineAsmConstraintError (
440
+ Call, OpInfo,
441
+ " indirect input operands with unknown constraint not supported "
442
+ " yet" );
431
443
}
432
444
433
445
if (OpInfo.ConstraintType == TargetLowering::C_Immediate ||
@@ -437,9 +449,8 @@ bool InlineAsmLowering::lowerInlineAsm(
437
449
if (!lowerAsmOperandForConstraint (OpInfo.CallOperandVal ,
438
450
OpInfo.ConstraintCode , Ops,
439
451
MIRBuilder)) {
440
- LLVM_DEBUG (dbgs () << " Don't support constraint: "
441
- << OpInfo.ConstraintCode << " yet\n " );
442
- return false ;
452
+ return reportInlineAsmConstraintError (Call, OpInfo,
453
+ " unsupported constraint" );
443
454
}
444
455
445
456
assert (Ops.size () > 0 &&
@@ -456,9 +467,9 @@ 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 reportInlineAsmConstraintError (
471
+ Call, OpInfo,
472
+ " indirect memory input operands are not supported yet " ) ;
462
473
}
463
474
464
475
assert (OpInfo.isIndirect && " Operand must be indirect to be a mem!" );
@@ -482,18 +493,15 @@ bool InlineAsmLowering::lowerInlineAsm(
482
493
" Unknown constraint type!" );
483
494
484
495
if (OpInfo.isIndirect ) {
485
- LLVM_DEBUG (dbgs () << " Can't handle indirect register inputs yet "
486
- " for constraint '"
487
- << OpInfo.ConstraintCode << " '\n " );
488
- return false ;
496
+ return reportInlineAsmConstraintError (
497
+ Call, OpInfo, " indirect register inputs are not supported yet" );
489
498
}
490
499
491
500
// Copy the input into the appropriate registers.
492
501
if (OpInfo.Regs .empty ()) {
493
- LLVM_DEBUG (
494
- dbgs ()
495
- << " Couldn't allocate input register for register constraint\n " );
496
- return false ;
502
+ return reportInlineAsmConstraintError (
503
+ Call, OpInfo,
504
+ " couldn't allocate input register for register constraint" );
497
505
}
498
506
499
507
unsigned NumRegs = OpInfo.Regs .size ();
@@ -503,9 +511,10 @@ bool InlineAsmLowering::lowerInlineAsm(
503
511
" source registers" );
504
512
505
513
if (NumRegs > 1 ) {
506
- LLVM_DEBUG (dbgs () << " Input operands with multiple input registers are "
507
- " not supported yet\n " );
508
- return false ;
514
+ return reportInlineAsmConstraintError (
515
+ Call, OpInfo,
516
+ " input operands with multiple input registers are not supported "
517
+ " yet" );
509
518
}
510
519
511
520
InlineAsm::Flag Flag (InlineAsm::Kind::RegUse, NumRegs);
0 commit comments