Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 1 | //===-- PIC16ISelLowering.h - PIC16 DAG Lowering Interface ------*- C++ -*-===// |
| 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 defines the interfaces that PIC16 uses to lower LLVM code into a |
| 11 | // selection DAG. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef PIC16ISELLOWERING_H |
| 16 | #define PIC16ISELLOWERING_H |
| 17 | |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 18 | #include "PIC16.h" |
| 19 | #include "PIC16Subtarget.h" |
Sanjiv Gupta | 2010b3e | 2008-05-14 11:31:39 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/SelectionDAG.h" |
| 21 | #include "llvm/Target/TargetLowering.h" |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
| 24 | namespace PIC16ISD { |
| 25 | enum NodeType { |
| 26 | // Start the numbering from where ISD NodeType finishes. |
Dan Gohman | 0ba2bcf | 2008-09-23 18:42:32 +0000 | [diff] [blame] | 27 | FIRST_NUMBER = ISD::BUILTIN_OP_END, |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 28 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 29 | Lo, // Low 8-bits of GlobalAddress. |
| 30 | Hi, // High 8-bits of GlobalAddress. |
| 31 | PIC16Load, |
Sanjiv Gupta | b84d5a4 | 2009-04-02 17:42:00 +0000 | [diff] [blame^] | 32 | PIC16LdArg, // This is replica of PIC16Load but used to load function |
| 33 | // arguments and is being used for facilitating for some |
| 34 | // store removal optimizations. |
| 35 | |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 36 | PIC16LdWF, |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 37 | PIC16Store, |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 38 | PIC16StWF, |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 39 | Banksel, |
| 40 | MTLO, |
| 41 | MTHI, |
| 42 | BCF, |
| 43 | LSLF, // PIC16 Logical shift left |
| 44 | LRLF, // PIC16 Logical shift right |
| 45 | RLF, // Rotate left through carry |
| 46 | RRF, // Rotate right through carry |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 47 | CALL, // PIC16 Call instruction |
| 48 | SUBCC, // Compare for equality or inequality. |
| 49 | SELECT_ICC, // Psuedo to be caught in schedular and expanded to brcond. |
| 50 | BRCOND, // Conditional branch. |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 51 | Dummy |
| 52 | }; |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 53 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 54 | // Keep track of different address spaces. |
| 55 | enum AddressSpace { |
| 56 | RAM_SPACE = 0, // RAM address space |
| 57 | ROM_SPACE = 1 // ROM address space number is 1 |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 58 | }; |
Sanjiv Gupta | 08b9b05 | 2009-01-21 05:44:05 +0000 | [diff] [blame] | 59 | enum PIC16Libcall { |
| 60 | MUL_I8, |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 61 | SRA_I8, |
| 62 | SLL_I8, |
| 63 | SRL_I8, |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 64 | PIC16UnknownCall |
| 65 | }; |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 68 | |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 69 | //===--------------------------------------------------------------------===// |
| 70 | // TargetLowering Implementation |
| 71 | //===--------------------------------------------------------------------===// |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 72 | class PIC16TargetLowering : public TargetLowering { |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 73 | public: |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 74 | explicit PIC16TargetLowering(PIC16TargetMachine &TM); |
| 75 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 76 | /// getTargetNodeName - This method returns the name of a target specific |
| 77 | /// DAG node. |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 78 | virtual const char *getTargetNodeName(unsigned Opcode) const; |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 79 | /// getSetCCResultType - Return the ISD::SETCC ValueType |
| 80 | virtual MVT getSetCCResultType(MVT ValType) const; |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 81 | SDValue LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG); |
Sanjiv Gupta | 08b9b05 | 2009-01-21 05:44:05 +0000 | [diff] [blame] | 82 | SDValue LowerShift(SDValue Op, SelectionDAG &DAG); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 83 | SDValue LowerADD(SDValue Op, SelectionDAG &DAG); |
| 84 | SDValue LowerSUB(SDValue Op, SelectionDAG &DAG); |
Sanjiv Gupta | 8f78fa8 | 2008-11-26 10:53:50 +0000 | [diff] [blame] | 85 | SDValue LowerBinOp(SDValue Op, SelectionDAG &DAG); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 86 | SDValue LowerCALL(SDValue Op, SelectionDAG &DAG); |
| 87 | SDValue LowerRET(SDValue Op, SelectionDAG &DAG); |
| 88 | SDValue LowerCallReturn(SDValue Op, SDValue Chain, SDValue FrameAddress, |
| 89 | SDValue InFlag, SelectionDAG &DAG); |
| 90 | SDValue LowerCallArguments(SDValue Op, SDValue Chain, SDValue FrameAddress, |
| 91 | SDValue InFlag, SelectionDAG &DAG); |
| 92 | SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG); |
| 93 | SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG); |
| 94 | SDValue getPIC16Cmp(SDValue LHS, SDValue RHS, unsigned OrigCC, SDValue &CC, |
Dale Johannesen | 2fabcb2 | 2009-02-05 01:01:16 +0000 | [diff] [blame] | 95 | SelectionDAG &DAG, DebugLoc dl); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 96 | virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | 1fdbc1d | 2009-02-07 16:15:20 +0000 | [diff] [blame] | 97 | MachineBasicBlock *MBB) const; |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 98 | |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 99 | |
Sanjiv Gupta | 08b9b05 | 2009-01-21 05:44:05 +0000 | [diff] [blame] | 100 | virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 101 | virtual void ReplaceNodeResults(SDNode *N, |
| 102 | SmallVectorImpl<SDValue> &Results, |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 103 | SelectionDAG &DAG); |
Duncan Sands | 9fbc7e2 | 2009-01-21 09:00:29 +0000 | [diff] [blame] | 104 | virtual void LowerOperationWrapper(SDNode *N, |
| 105 | SmallVectorImpl<SDValue> &Results, |
| 106 | SelectionDAG &DAG); |
Sanjiv Gupta | 08b9b05 | 2009-01-21 05:44:05 +0000 | [diff] [blame] | 107 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 108 | SDValue ExpandStore(SDNode *N, SelectionDAG &DAG); |
| 109 | SDValue ExpandLoad(SDNode *N, SelectionDAG &DAG); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 110 | SDValue ExpandGlobalAddress(SDNode *N, SelectionDAG &DAG); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 111 | SDValue ExpandExternalSymbol(SDNode *N, SelectionDAG &DAG); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 112 | SDValue ExpandFrameIndex(SDNode *N, SelectionDAG &DAG); |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 113 | |
| 114 | SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; |
| 115 | SDValue PerformPIC16LoadCombine(SDNode *N, DAGCombinerInfo &DCI) const; |
Sanjiv Gupta | b84d5a4 | 2009-04-02 17:42:00 +0000 | [diff] [blame^] | 116 | SDValue PerformStoreCombine(SDNode *N, DAGCombinerInfo &DCI) const; |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 117 | |
| 118 | private: |
Sanjiv Gupta | b84d5a4 | 2009-04-02 17:42:00 +0000 | [diff] [blame^] | 119 | // If the Node is a BUILD_PAIR representing a direct Address, |
| 120 | // then this function will return true. |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 121 | bool isDirectAddress(const SDValue &Op); |
| 122 | |
| 123 | // If the Node is a DirectAddress in ROM_SPACE then this |
| 124 | // function will return true |
| 125 | bool isRomAddress(const SDValue &Op); |
| 126 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 127 | // Extract the Lo and Hi component of Op. |
| 128 | void GetExpandedParts(SDValue Op, SelectionDAG &DAG, SDValue &Lo, |
| 129 | SDValue &Hi); |
| 130 | |
| 131 | |
| 132 | // Load pointer can be a direct or indirect address. In PIC16 direct |
| 133 | // addresses need Banksel and Indirect addresses need to be loaded to |
| 134 | // FSR first. Handle address specific cases here. |
| 135 | void LegalizeAddress(SDValue Ptr, SelectionDAG &DAG, SDValue &Chain, |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 136 | SDValue &NewPtr, unsigned &Offset, DebugLoc dl); |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 137 | |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 138 | // FrameIndex should be broken down into ExternalSymbol and FrameOffset. |
| 139 | void LegalizeFrameIndex(SDValue Op, SelectionDAG &DAG, SDValue &ES, |
| 140 | int &Offset); |
| 141 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 142 | // We can not have both operands of a binary operation in W. |
| 143 | // This function is used to put one operand on stack and generate a load. |
Dale Johannesen | 2fabcb2 | 2009-02-05 01:01:16 +0000 | [diff] [blame] | 144 | SDValue ConvertToMemOperand(SDValue Op, SelectionDAG &DAG, DebugLoc dl); |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 145 | |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 146 | // This function checks if we need to put an operand of an operation on |
| 147 | // stack and generate a load or not. |
| 148 | bool NeedToConvertToMemOp(SDValue Op, unsigned &MemOp); |
| 149 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 150 | /// Subtarget - Keep a pointer to the PIC16Subtarget around so that we can |
| 151 | /// make the right decision when generating code for different targets. |
| 152 | const PIC16Subtarget *Subtarget; |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 153 | |
| 154 | |
| 155 | // Extending the LIB Call framework of LLVM |
Sanjiv Gupta | b84d5a4 | 2009-04-02 17:42:00 +0000 | [diff] [blame^] | 156 | // to hold the names of PIC16Libcalls. |
Sanjiv Gupta | 08b9b05 | 2009-01-21 05:44:05 +0000 | [diff] [blame] | 157 | const char *PIC16LibcallNames[PIC16ISD::PIC16UnknownCall]; |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 158 | |
Sanjiv Gupta | b84d5a4 | 2009-04-02 17:42:00 +0000 | [diff] [blame^] | 159 | // To set and retrieve the lib call names. |
Sanjiv Gupta | 08b9b05 | 2009-01-21 05:44:05 +0000 | [diff] [blame] | 160 | void setPIC16LibcallName(PIC16ISD::PIC16Libcall Call, const char *Name); |
| 161 | const char *getPIC16LibcallName(PIC16ISD::PIC16Libcall Call); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 162 | |
Sanjiv Gupta | b84d5a4 | 2009-04-02 17:42:00 +0000 | [diff] [blame^] | 163 | // Make PIC16 Libcall. |
Sanjiv Gupta | 08b9b05 | 2009-01-21 05:44:05 +0000 | [diff] [blame] | 164 | SDValue MakePIC16Libcall(PIC16ISD::PIC16Libcall Call, MVT RetVT, |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 165 | const SDValue *Ops, unsigned NumOps, bool isSigned, |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 166 | SelectionDAG &DAG, DebugLoc dl); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 167 | |
| 168 | // Check if operation has a direct load operand. |
| 169 | inline bool isDirectLoad(const SDValue Op); |
| 170 | |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 171 | }; |
| 172 | } // namespace llvm |
| 173 | |
| 174 | #endif // PIC16ISELLOWERING_H |