Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 1 | //===-- PTXISelLowering.cpp - PTX DAG Lowering Implementation -------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the PTXTargetLowering class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "PTXISelLowering.h" |
| 15 | #include "PTXRegisterInfo.h" |
| 16 | #include "llvm/Support/ErrorHandling.h" |
| 17 | #include "llvm/CodeGen/SelectionDAG.h" |
| 18 | #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" |
| 19 | |
| 20 | using namespace llvm; |
| 21 | |
| 22 | PTXTargetLowering::PTXTargetLowering(TargetMachine &TM) |
| 23 | : TargetLowering(TM, new TargetLoweringObjectFileELF()) { |
| 24 | // Set up the register classes. |
| 25 | addRegisterClass(MVT::i1, PTX::PredsRegisterClass); |
| 26 | |
| 27 | // Compute derived properties from the register classes |
| 28 | computeRegisterProperties(); |
| 29 | } |
| 30 | |
| 31 | const char *PTXTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 32 | switch (Opcode) { |
| 33 | default: llvm_unreachable("Unknown opcode"); |
| 34 | case PTXISD::EXIT: return "PTXISD::EXIT"; |
Che-Liang Chiou | f9930da | 2010-09-25 07:46:17 +0000 | [diff] [blame^] | 35 | case PTXISD::RET: return "PTXISD::RET"; |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
| 39 | //===----------------------------------------------------------------------===// |
| 40 | // Calling Convention Implementation |
| 41 | //===----------------------------------------------------------------------===// |
| 42 | |
| 43 | SDValue PTXTargetLowering:: |
| 44 | LowerFormalArguments(SDValue Chain, |
| 45 | CallingConv::ID CallConv, |
| 46 | bool isVarArg, |
| 47 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 48 | DebugLoc dl, |
| 49 | SelectionDAG &DAG, |
| 50 | SmallVectorImpl<SDValue> &InVals) const { |
| 51 | return Chain; |
| 52 | } |
| 53 | |
| 54 | SDValue PTXTargetLowering:: |
| 55 | LowerReturn(SDValue Chain, |
| 56 | CallingConv::ID CallConv, |
| 57 | bool isVarArg, |
| 58 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 59 | const SmallVectorImpl<SDValue> &OutVals, |
| 60 | DebugLoc dl, |
| 61 | SelectionDAG &DAG) const { |
Che-Liang Chiou | f9930da | 2010-09-25 07:46:17 +0000 | [diff] [blame^] | 62 | assert(!isVarArg && "PTX does not support var args."); |
| 63 | |
| 64 | switch (CallConv) { |
| 65 | default: |
| 66 | llvm_unreachable("Unsupported calling convention."); |
| 67 | case CallingConv::PTX_Kernel: |
| 68 | assert(Outs.size() == 0 && "Kernel must return void."); |
| 69 | return DAG.getNode(PTXISD::EXIT, dl, MVT::Other, Chain); |
| 70 | case CallingConv::PTX_Device: |
| 71 | assert(Outs.size() <= 1 && "Can at most return one value."); |
| 72 | break; |
| 73 | } |
| 74 | |
| 75 | // PTX_Device |
| 76 | |
| 77 | if (Outs.size() == 0) |
| 78 | return DAG.getNode(PTXISD::RET, dl, MVT::Other, Chain); |
| 79 | |
| 80 | // TODO: allocate return register |
| 81 | SDValue Flag; |
| 82 | return DAG.getNode(PTXISD::RET, dl, MVT::Other, Chain, Flag); |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 83 | } |