@@ -609,7 +609,7 @@ bool SYCLGenBase::emitAddressExpr(const InlineAsmAddressExpr *Dst) {
609
609
return false ;
610
610
};
611
611
612
- if (CurrInst->is (asmtok::op_ld, asmtok:: op_red))
612
+ if (CurrInst->is (asmtok::op_red))
613
613
OS () << " *" ;
614
614
switch (Dst->getMemoryOpKind ()) {
615
615
case InlineAsmAddressExpr::Imm:
@@ -633,7 +633,7 @@ bool SYCLGenBase::emitAddressExpr(const InlineAsmAddressExpr *Dst) {
633
633
if (tryEmitStmt (Reg, Dst->getSymbol ()))
634
634
return SYCLGenSuccess ();
635
635
636
- if (CurrInst->is (asmtok::op_st))
636
+ if (CurrInst->is (asmtok::op_st, asmtok::op_ld ))
637
637
OS () << llvm::formatv (" (uintptr_t){0}" , Reg);
638
638
else
639
639
OS () << llvm::formatv (" (({0} *)((uintptr_t){1} + {2}))" , Type, Reg,
@@ -2694,16 +2694,10 @@ class SYCLGen : public SYCLGenBase {
2694
2694
return SYCLGenSuccess ();
2695
2695
}
2696
2696
2697
- bool HandleStVec (const InlineAsmInstruction *Inst, int VecNum) {
2698
- std::string Ops;
2699
- if (tryEmitStmt (Ops, Inst->getInputOperand (0 )))
2700
- return SYCLGenError ();
2701
-
2702
- // To extract the values from the string like "{x, y, z, w}" and store them
2703
- // int Values vector
2697
+ std::vector<std::string> extractValues (const std::string &Ops) {
2704
2698
std::vector<std::string> Values;
2705
- size_t start = 1 ; // Skip the '{' character
2706
- size_t end = Ops.find (' ,' , start); // Find the first comma
2699
+ size_t start = 1 ; // Skip the '{' character
2700
+ size_t end = Ops.find (' ,' , start);
2707
2701
2708
2702
while (end != std::string::npos) {
2709
2703
std::string Token = Ops.substr (start, end - start);
@@ -2720,11 +2714,24 @@ class SYCLGen : public SYCLGenBase {
2720
2714
std::string token = Ops.substr (start, Ops.size () - start - 1 );
2721
2715
size_t first = token.find_first_not_of (' ' );
2722
2716
size_t last = token.find_last_not_of (' ' );
2723
-
2724
2717
if (first != std::string::npos && last != std::string::npos) {
2725
2718
Values.push_back (token.substr (first, last - first + 1 ));
2726
2719
}
2727
2720
2721
+ return Values;
2722
+ }
2723
+
2724
+ bool HandleStVec (const InlineAsmInstruction *Inst, int VecNum) {
2725
+ std::string Ops;
2726
+ if (tryEmitStmt (Ops, Inst->getInputOperand (0 )))
2727
+ return SYCLGenError ();
2728
+
2729
+ // To extract the values from the string like "{x, y, z, w}" and store them
2730
+ // int Values vector
2731
+ std::vector<std::string> Values = extractValues (Ops);
2732
+ if (Values.size () != (size_t )VecNum)
2733
+ return SYCLGenError ();
2734
+
2728
2735
std::string Output;
2729
2736
if (tryEmitStmt (Output, Inst->getOutputOperand ()))
2730
2737
return SYCLGenError ();
@@ -2790,6 +2797,43 @@ class SYCLGen : public SYCLGenBase {
2790
2797
return SYCLGenSuccess ();
2791
2798
}
2792
2799
2800
+ bool HandleLdVec (const InlineAsmInstruction *Inst, int VecNum) {
2801
+ std::string Ops;
2802
+ if (tryEmitStmt (Ops, Inst->getOutputOperand ()))
2803
+ return SYCLGenError ();
2804
+
2805
+ // To extract the values from the string like "{x, y, z, w}" and store them
2806
+ // int Values vector
2807
+ std::vector<std::string> Values = extractValues (Ops);
2808
+ if (Values.size () != (size_t )VecNum)
2809
+ return SYCLGenError ();
2810
+
2811
+ std::string Input;
2812
+ if (tryEmitStmt (Input, Inst->getInputOperand (0 )))
2813
+ return SYCLGenError ();
2814
+
2815
+ std::string Type;
2816
+ if (tryEmitType (Type, Inst->getType (0 )))
2817
+ return SYCLGenError ();
2818
+
2819
+ const auto *Src =
2820
+ dyn_cast_or_null<InlineAsmAddressExpr>(Inst->getInputOperand (0 ));
2821
+ if (!Src)
2822
+ return SYCLGenError ();
2823
+
2824
+ for (int Index = 0 ; Index < VecNum; Index++) {
2825
+ OS () << llvm::formatv (" {0} = *(({1} *){2} + {3}){4}" , Values[Index],
2826
+ Type, Input, Index,
2827
+ Index == VecNum - 1 ? " " : " ;\n " );
2828
+ if (Index < VecNum - 1 ) {
2829
+ indent ();
2830
+ }
2831
+ }
2832
+
2833
+ endstmt ();
2834
+ return SYCLGenSuccess ();
2835
+ }
2836
+
2793
2837
bool handle_ld (const InlineAsmInstruction *Inst) override {
2794
2838
if (Inst->getNumInputOperands () != 1 )
2795
2839
return SYCLGenError ();
@@ -2801,14 +2845,32 @@ class SYCLGen : public SYCLGenBase {
2801
2845
2802
2846
if (!Src)
2803
2847
return SYCLGenError ();
2848
+
2849
+ if (Inst->hasAttr (InstAttr::cg)) {
2850
+ if (Inst->hasAttr (InstAttr::v4))
2851
+ return HandleLdVec (Inst, 4 );
2852
+ if (Inst->hasAttr (InstAttr::v2))
2853
+ return HandleLdVec (Inst, 2 );
2854
+ }
2855
+
2804
2856
std::string Type;
2805
2857
if (tryEmitType (Type, Inst->getType (0 )))
2806
2858
return SYCLGenError ();
2807
2859
if (emitStmt (Dst))
2808
2860
return SYCLGenError ();
2809
2861
OS () << " = " ;
2810
- if (emitStmt (Src))
2862
+
2863
+ std::string InOp;
2864
+ if (tryEmitStmt (InOp, Inst->getInputOperand (0 )))
2811
2865
return SYCLGenError ();
2866
+
2867
+ if (Src->getMemoryOpKind () == InlineAsmAddressExpr::RegImm) {
2868
+ OS () << llvm::formatv (" *(({0} *)({1} + {2}))" , Type, InOp,
2869
+ Src->getImmAddr ()->getValue ().getZExtValue ());
2870
+ } else {
2871
+ OS () << " *" << InOp;
2872
+ }
2873
+
2812
2874
endstmt ();
2813
2875
return SYCLGenSuccess ();
2814
2876
}
0 commit comments