@@ -578,35 +578,64 @@ LoongArchTargetLowering::lowerINTRINSIC_W_CHAIN(SDValue Op,
578
578
}
579
579
}
580
580
581
+ // Helper function that emits error message for intrinsics with void return
582
+ // value.
583
+ static SDValue emitIntrinsicErrorMessage (SDValue Op, StringRef Name,
584
+ StringRef ErrorMsg,
585
+ SelectionDAG &DAG) {
586
+
587
+ DAG.getContext ()->emitError (" argument to '" + Name + " ' " + ErrorMsg);
588
+ return Op.getOperand (0 );
589
+ }
590
+
581
591
SDValue LoongArchTargetLowering::lowerINTRINSIC_VOID (SDValue Op,
582
592
SelectionDAG &DAG) const {
583
593
SDLoc DL (Op);
584
594
MVT GRLenVT = Subtarget.getGRLenVT ();
595
+ SDValue Op0 = Op.getOperand (0 );
596
+ SDValue Op2 = Op.getOperand (2 );
597
+ const StringRef ErrorMsgOOR = " out of range" ;
585
598
586
599
switch (Op.getConstantOperandVal (1 )) {
587
600
default :
588
601
// TODO: Add more Intrinsics.
589
602
return SDValue ();
590
603
case Intrinsic::loongarch_dbar: {
591
- SDValue Op0 = Op.getOperand (0 );
592
- SDValue Op2 = Op.getOperand (2 );
593
- if (!isa<ConstantSDNode>(Op2)) {
594
- DAG.getContext ()->emitError (" argument to '__builtin_loongarch_dbar' must "
595
- " be a constant integer" );
596
- return Op.getOperand (0 );
597
- }
598
604
unsigned Imm = cast<ConstantSDNode>(Op2)->getZExtValue ();
599
- if (!isUInt<15 >(Imm)) {
600
- DAG.getContext ()->emitError (
601
- " argument to '__builtin_loongarch_dbar' out of range" );
602
- return Op0;
603
- }
605
+ if (!isUInt<15 >(Imm))
606
+ return emitIntrinsicErrorMessage (Op, " __builtin_loongarch_dbar" ,
607
+ ErrorMsgOOR, DAG);
604
608
605
- if (GRLenVT == MVT::i32 )
606
- return Op;
607
609
return DAG.getNode (LoongArchISD::DBAR, DL, MVT::Other, Op0,
608
610
DAG.getConstant (Imm, DL, GRLenVT));
609
611
}
612
+ case Intrinsic::loongarch_ibar: {
613
+ unsigned Imm = cast<ConstantSDNode>(Op2)->getZExtValue ();
614
+ if (!isUInt<15 >(Imm))
615
+ return emitIntrinsicErrorMessage (Op, " __builtin_loongarch_ibar" ,
616
+ ErrorMsgOOR, DAG);
617
+
618
+ return DAG.getNode (LoongArchISD::IBAR, DL, MVT::Other, Op0,
619
+ DAG.getConstant (Imm, DL, GRLenVT));
620
+ }
621
+ case Intrinsic::loongarch_break: {
622
+ unsigned Imm = cast<ConstantSDNode>(Op2)->getZExtValue ();
623
+ if (!isUInt<15 >(Imm))
624
+ return emitIntrinsicErrorMessage (Op, " __builtin_loongarch_break" ,
625
+ ErrorMsgOOR, DAG);
626
+
627
+ return DAG.getNode (LoongArchISD::BREAK, DL, MVT::Other, Op0,
628
+ DAG.getConstant (Imm, DL, GRLenVT));
629
+ }
630
+ case Intrinsic::loongarch_syscall: {
631
+ unsigned Imm = cast<ConstantSDNode>(Op2)->getZExtValue ();
632
+ if (!isUInt<15 >(Imm))
633
+ return emitIntrinsicErrorMessage (Op, " __builtin_loongarch_syscall" ,
634
+ ErrorMsgOOR, DAG);
635
+
636
+ return DAG.getNode (LoongArchISD::SYSCALL, DL, MVT::Other, Op0,
637
+ DAG.getConstant (Imm, DL, GRLenVT));
638
+ }
610
639
}
611
640
}
612
641
@@ -1354,6 +1383,9 @@ const char *LoongArchTargetLowering::getTargetNodeName(unsigned Opcode) const {
1354
1383
NODE_NAME_CASE (CLZ_W)
1355
1384
NODE_NAME_CASE (CTZ_W)
1356
1385
NODE_NAME_CASE (DBAR)
1386
+ NODE_NAME_CASE (IBAR)
1387
+ NODE_NAME_CASE (BREAK)
1388
+ NODE_NAME_CASE (SYSCALL)
1357
1389
NODE_NAME_CASE (CRC_W_D_W)
1358
1390
}
1359
1391
#undef NODE_NAME_CASE
0 commit comments