llvm.org GIT mirror llvm / f9930da
Add ret instruction to PTX backend git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114788 91177308-0d34-0410-b5e6-96231b3b80d8 Che-Liang Chiou 8 years ago
11 changed file(s) with 53 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
7878 /// X86_ThisCall - Similar to X86_StdCall. Passes first argument in ECX,
7979 /// others via stack. Callee is responsible for stack cleaning. MSVC uses
8080 /// this by default for methods in its ABI.
81 X86_ThisCall = 70
81 X86_ThisCall = 70,
82
83 /// PTX_Kernel - Call to a PTX kernel.
84 /// Passes all arguments in parameter space.
85 PTX_Kernel = 71,
86
87 /// PTX_Device - Call to a PTX device function.
88 /// Passes all arguments in register or parameter space.
89 PTX_Device = 72
8290 };
8391 } // End CallingConv namespace
8492
543543 KEYWORD(arm_aapcscc);
544544 KEYWORD(arm_aapcs_vfpcc);
545545 KEYWORD(msp430_intrcc);
546 KEYWORD(ptx_kernel);
547 KEYWORD(ptx_device);
546548
547549 KEYWORD(cc);
548550 KEYWORD(c);
10831083 /// ::= 'arm_aapcscc'
10841084 /// ::= 'arm_aapcs_vfpcc'
10851085 /// ::= 'msp430_intrcc'
1086 /// ::= 'ptx_kernel'
1087 /// ::= 'ptx_device'
10861088 /// ::= 'cc' UINT
10871089 ///
10881090 bool LLParser::ParseOptionalCallingConv(CallingConv::ID &CC) {
10981100 case lltok::kw_arm_aapcscc: CC = CallingConv::ARM_AAPCS; break;
10991101 case lltok::kw_arm_aapcs_vfpcc:CC = CallingConv::ARM_AAPCS_VFP; break;
11001102 case lltok::kw_msp430_intrcc: CC = CallingConv::MSP430_INTR; break;
1103 case lltok::kw_ptx_kernel: CC = CallingConv::PTX_Kernel; break;
1104 case lltok::kw_ptx_device: CC = CallingConv::PTX_Device; break;
11011105 case lltok::kw_cc: {
11021106 unsigned ArbitraryCC;
11031107 Lex.Lex();
7171 kw_x86_stdcallcc, kw_x86_fastcallcc, kw_x86_thiscallcc,
7272 kw_arm_apcscc, kw_arm_aapcscc, kw_arm_aapcs_vfpcc,
7373 kw_msp430_intrcc,
74 kw_ptx_kernel, kw_ptx_device,
7475
7576 kw_signext,
7677 kw_zeroext,
3131 switch (Opcode) {
3232 default: llvm_unreachable("Unknown opcode");
3333 case PTXISD::EXIT: return "PTXISD::EXIT";
34 case PTXISD::RET: return "PTXISD::RET";
3435 }
3536 }
3637
5758 const SmallVectorImpl &OutVals,
5859 DebugLoc dl,
5960 SelectionDAG &DAG) const {
60 return DAG.getNode(PTXISD::EXIT, dl, MVT::Other, Chain);
61 assert(!isVarArg && "PTX does not support var args.");
62
63 switch (CallConv) {
64 default:
65 llvm_unreachable("Unsupported calling convention.");
66 case CallingConv::PTX_Kernel:
67 assert(Outs.size() == 0 && "Kernel must return void.");
68 return DAG.getNode(PTXISD::EXIT, dl, MVT::Other, Chain);
69 case CallingConv::PTX_Device:
70 assert(Outs.size() <= 1 && "Can at most return one value.");
71 break;
72 }
73
74 // PTX_Device
75
76 if (Outs.size() == 0)
77 return DAG.getNode(PTXISD::RET, dl, MVT::Other, Chain);
78
79 // TODO: allocate return register
80 SDValue Flag;
81 return DAG.getNode(PTXISD::RET, dl, MVT::Other, Chain, Flag);
6182 }
2323 namespace PTXISD {
2424 enum NodeType {
2525 FIRST_NUMBER = ISD::BUILTIN_OP_END,
26 EXIT
26 EXIT,
27 RET
2728 };
2829 } // namespace PTXISD
2930
2222
2323 def PTXexit
2424 : SDNode<"PTXISD::EXIT", SDTNone, [SDNPHasChain]>;
25 def PTXret
26 : SDNode<"PTXISD::RET", SDTNone, [SDNPHasChain]>;
2527
2628 //===----------------------------------------------------------------------===//
2729 // Instructions
2931
3032 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
3133 def EXIT : InstPTX<(outs), (ins), "exit", [(PTXexit)]>;
34 def RET : InstPTX<(outs), (ins), "ret", [(PTXret)]>;
3235 }
15781578 case CallingConv::ARM_AAPCS: Out << "arm_aapcscc "; break;
15791579 case CallingConv::ARM_AAPCS_VFP:Out << "arm_aapcs_vfpcc "; break;
15801580 case CallingConv::MSP430_INTR: Out << "msp430_intrcc "; break;
1581 case CallingConv::PTX_Kernel: Out << "ptx_kernel"; break;
1582 case CallingConv::PTX_Device: Out << "ptx_device"; break;
15811583 default: Out << "cc" << F->getCallingConv() << " "; break;
15821584 }
15831585
18461848 case CallingConv::ARM_AAPCS: Out << " arm_aapcscc "; break;
18471849 case CallingConv::ARM_AAPCS_VFP:Out << " arm_aapcs_vfpcc "; break;
18481850 case CallingConv::MSP430_INTR: Out << " msp430_intrcc "; break;
1851 case CallingConv::PTX_Kernel: Out << " ptx_kernel"; break;
1852 case CallingConv::PTX_Device: Out << " ptx_device"; break;
18491853 default: Out << " cc" << CI->getCallingConv(); break;
18501854 }
18511855
19001904 case CallingConv::ARM_AAPCS: Out << " arm_aapcscc "; break;
19011905 case CallingConv::ARM_AAPCS_VFP:Out << " arm_aapcs_vfpcc "; break;
19021906 case CallingConv::MSP430_INTR: Out << " msp430_intrcc "; break;
1907 case CallingConv::PTX_Kernel: Out << " ptx_kernel"; break;
1908 case CallingConv::PTX_Device: Out << " ptx_device"; break;
19031909 default: Out << " cc" << II->getCallingConv(); break;
19041910 }
19051911
684684 case CallingConv::Cold:
685685 case CallingConv::X86_FastCall:
686686 case CallingConv::X86_ThisCall:
687 case CallingConv::PTX_Kernel:
688 case CallingConv::PTX_Device:
687689 Assert1(!F.isVarArg(),
688690 "Varargs functions must have C calling conventions!", &F);
689691 break;
0 ; RUN: llc < %s -march=ptx | FileCheck %s
11
2 define void @t1() {
2 define ptx_kernel void @t1() {
33 ;CHECK: exit;
44 ret void
55 }
4848 syn keyword llvmKeyword except deplibs
4949 syn keyword llvmKeyword volatile fastcc coldcc cc ccc
5050 syn keyword llvmKeyword x86_stdcallcc x86_fastcallcc
51 syn keyword llvmKeyword ptx_kernel ptx_device
5152 syn keyword llvmKeyword signext zeroext inreg sret nounwind noreturn
5253 syn keyword llvmKeyword nocapture byval nest readnone readonly noalias
5354 syn keyword llvmKeyword inlinehint noinline alwaysinline optsize ssp sspreq