1616#include " llvm/CodeGen/MachineOperand.h"
1717#include " llvm/CodeGen/MachineRegisterInfo.h"
1818#include " llvm/CodeGen/TargetLowering.h"
19+ #include " llvm/IR/DiagnosticInfo.h"
1920#include " llvm/IR/Module.h"
2021
2122#define DEBUG_TYPE " inline-asm-lowering"
@@ -231,6 +232,15 @@ bool InlineAsmLowering::lowerInlineAsm(
231232 TargetLowering::AsmOperandInfoVector TargetConstraints =
232233 TLI->ParseConstraints (DL, TRI, Call);
233234
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+
234244 ExtraFlags ExtraInfo (Call);
235245 unsigned ArgNo = 0 ; // ArgNo - The argument of the CallInst.
236246 unsigned ResNo = 0 ; // ResNo - The result number of the next output.
@@ -243,8 +253,8 @@ bool InlineAsmLowering::lowerInlineAsm(
243253 OpInfo.CallOperandVal = const_cast <Value *>(Call.getArgOperand (ArgNo));
244254
245255 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 " ) ;
248258 }
249259
250260 Type *OpTy = OpInfo.CallOperandVal ->getType ();
@@ -258,9 +268,8 @@ bool InlineAsmLowering::lowerInlineAsm(
258268
259269 // FIXME: Support aggregate input operands
260270 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" );
264273 }
265274
266275 OpInfo.ConstraintVT =
@@ -344,9 +353,8 @@ bool InlineAsmLowering::lowerInlineAsm(
344353
345354 // Find a register that we can use.
346355 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" );
350358 }
351359
352360 // Add information to the INLINEASM instruction to know that this
@@ -389,13 +397,13 @@ bool InlineAsmLowering::lowerInlineAsm(
389397
390398 const InlineAsm::Flag MatchedOperandFlag (Inst->getOperand (InstFlagIdx).getImm ());
391399 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" );
395404 }
396405 if (!MatchedOperandFlag.isRegDefKind () && !MatchedOperandFlag.isRegDefEarlyClobberKind ()) {
397- LLVM_DEBUG (dbgs () << " Unknown matching constraint\n " );
398- return false ;
406+ return ConstraintError (OpInfo, " unknown matching constraint" );
399407 }
400408
401409 // We want to tie input to register in next operand.
@@ -425,9 +433,10 @@ bool InlineAsmLowering::lowerInlineAsm(
425433
426434 if (OpInfo.ConstraintType == TargetLowering::C_Other &&
427435 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" );
431440 }
432441
433442 if (OpInfo.ConstraintType == TargetLowering::C_Immediate ||
@@ -437,9 +446,7 @@ bool InlineAsmLowering::lowerInlineAsm(
437446 if (!lowerAsmOperandForConstraint (OpInfo.CallOperandVal ,
438447 OpInfo.ConstraintCode , Ops,
439448 MIRBuilder)) {
440- LLVM_DEBUG (dbgs () << " Don't support constraint: "
441- << OpInfo.ConstraintCode << " yet\n " );
442- return false ;
449+ return ConstraintError (OpInfo, " unsupported constraint" );
443450 }
444451
445452 assert (Ops.size () > 0 &&
@@ -456,9 +463,8 @@ bool InlineAsmLowering::lowerInlineAsm(
456463 if (OpInfo.ConstraintType == TargetLowering::C_Memory) {
457464
458465 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" );
462468 }
463469
464470 assert (OpInfo.isIndirect && " Operand must be indirect to be a mem!" );
@@ -482,18 +488,15 @@ bool InlineAsmLowering::lowerInlineAsm(
482488 " Unknown constraint type!" );
483489
484490 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" );
489493 }
490494
491495 // Copy the input into the appropriate registers.
492496 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" );
497500 }
498501
499502 unsigned NumRegs = OpInfo.Regs .size ();
@@ -503,9 +506,10 @@ bool InlineAsmLowering::lowerInlineAsm(
503506 " source registers" );
504507
505508 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" );
509513 }
510514
511515 InlineAsm::Flag Flag (InlineAsm::Kind::RegUse, NumRegs);
0 commit comments