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 | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 32 | PIC16LdWF, |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 33 | PIC16Store, |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 34 | PIC16StWF, |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 35 | Banksel, |
| 36 | MTLO, |
| 37 | MTHI, |
| 38 | BCF, |
| 39 | LSLF, // PIC16 Logical shift left |
| 40 | LRLF, // PIC16 Logical shift right |
| 41 | RLF, // Rotate left through carry |
| 42 | RRF, // Rotate right through carry |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 43 | CALL, // PIC16 Call instruction |
| 44 | SUBCC, // Compare for equality or inequality. |
| 45 | SELECT_ICC, // Psuedo to be caught in schedular and expanded to brcond. |
| 46 | BRCOND, // Conditional branch. |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 47 | Dummy |
| 48 | }; |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 49 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 50 | // Keep track of different address spaces. |
| 51 | enum AddressSpace { |
| 52 | RAM_SPACE = 0, // RAM address space |
| 53 | ROM_SPACE = 1 // ROM address space number is 1 |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 54 | }; |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 55 | enum PIC16LibCall { |
| 56 | SRA_I8, |
| 57 | SLL_I8, |
| 58 | SRL_I8, |
| 59 | SRA_I16, |
| 60 | SLL_I16, |
| 61 | SRL_I16, |
| 62 | SRA_I32, |
| 63 | SLL_I32, |
| 64 | SRL_I32, |
| 65 | PIC16UnknownCall |
| 66 | }; |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 69 | |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 70 | //===--------------------------------------------------------------------===// |
| 71 | // TargetLowering Implementation |
| 72 | //===--------------------------------------------------------------------===// |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 73 | class PIC16TargetLowering : public TargetLowering { |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 74 | public: |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 75 | explicit PIC16TargetLowering(PIC16TargetMachine &TM); |
| 76 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 77 | /// getTargetNodeName - This method returns the name of a target specific |
| 78 | /// DAG node. |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 79 | virtual const char *getTargetNodeName(unsigned Opcode) const; |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 80 | /// getSetCCResultType - Return the ISD::SETCC ValueType |
| 81 | virtual MVT getSetCCResultType(MVT ValType) const; |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 82 | SDValue LowerOperation(SDValue Op, SelectionDAG &DAG); |
| 83 | SDValue LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 84 | SDValue LowerADD(SDValue Op, SelectionDAG &DAG); |
| 85 | SDValue LowerSUB(SDValue Op, SelectionDAG &DAG); |
Sanjiv Gupta | 8f78fa8 | 2008-11-26 10:53:50 +0000 | [diff] [blame] | 86 | SDValue LowerBinOp(SDValue Op, SelectionDAG &DAG); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 87 | SDValue LowerCALL(SDValue Op, SelectionDAG &DAG); |
| 88 | SDValue LowerRET(SDValue Op, SelectionDAG &DAG); |
| 89 | SDValue LowerCallReturn(SDValue Op, SDValue Chain, SDValue FrameAddress, |
| 90 | SDValue InFlag, SelectionDAG &DAG); |
| 91 | SDValue LowerCallArguments(SDValue Op, SDValue Chain, SDValue FrameAddress, |
| 92 | SDValue InFlag, SelectionDAG &DAG); |
| 93 | SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG); |
| 94 | SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG); |
| 95 | SDValue getPIC16Cmp(SDValue LHS, SDValue RHS, unsigned OrigCC, SDValue &CC, |
| 96 | SelectionDAG &DAG); |
| 97 | virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI, |
| 98 | MachineBasicBlock *MBB); |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 99 | |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 100 | |
| 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 | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 104 | SDValue ExpandStore(SDNode *N, SelectionDAG &DAG); |
| 105 | SDValue ExpandLoad(SDNode *N, SelectionDAG &DAG); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 106 | //SDValue ExpandAdd(SDNode *N, SelectionDAG &DAG); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 107 | SDValue ExpandGlobalAddress(SDNode *N, SelectionDAG &DAG); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 108 | SDValue ExpandExternalSymbol(SDNode *N, SelectionDAG &DAG); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 109 | SDValue ExpandShift(SDNode *N, SelectionDAG &DAG); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 110 | SDValue ExpandFrameIndex(SDNode *N, SelectionDAG &DAG); |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 111 | |
| 112 | SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; |
| 113 | SDValue PerformPIC16LoadCombine(SDNode *N, DAGCombinerInfo &DCI) const; |
| 114 | |
| 115 | private: |
| 116 | // If the Node is a BUILD_PAIR representing representing an Address |
| 117 | // then this function will return true |
| 118 | bool isDirectAddress(const SDValue &Op); |
| 119 | |
| 120 | // If the Node is a DirectAddress in ROM_SPACE then this |
| 121 | // function will return true |
| 122 | bool isRomAddress(const SDValue &Op); |
| 123 | |
| 124 | // To extract chain value from the SDValue Nodes |
| 125 | // This function will help to maintain the chain extracting |
| 126 | // code at one place. In case of any change in future it will |
| 127 | // help maintain the code |
| 128 | SDValue getChain(SDValue &Op); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 129 | |
| 130 | SDValue getOutFlag(SDValue &Op); |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 131 | |
| 132 | |
| 133 | // Extract the Lo and Hi component of Op. |
| 134 | void GetExpandedParts(SDValue Op, SelectionDAG &DAG, SDValue &Lo, |
| 135 | SDValue &Hi); |
| 136 | |
| 137 | |
| 138 | // Load pointer can be a direct or indirect address. In PIC16 direct |
| 139 | // addresses need Banksel and Indirect addresses need to be loaded to |
| 140 | // FSR first. Handle address specific cases here. |
| 141 | void LegalizeAddress(SDValue Ptr, SelectionDAG &DAG, SDValue &Chain, |
| 142 | SDValue &NewPtr, unsigned &Offset); |
| 143 | |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 144 | // FrameIndex should be broken down into ExternalSymbol and FrameOffset. |
| 145 | void LegalizeFrameIndex(SDValue Op, SelectionDAG &DAG, SDValue &ES, |
| 146 | int &Offset); |
| 147 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 148 | // We can not have both operands of a binary operation in W. |
| 149 | // This function is used to put one operand on stack and generate a load. |
| 150 | SDValue ConvertToMemOperand(SDValue Op, SelectionDAG &DAG); |
| 151 | |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 152 | // This function checks if we need to put an operand of an operation on |
| 153 | // stack and generate a load or not. |
| 154 | bool NeedToConvertToMemOp(SDValue Op, unsigned &MemOp); |
| 155 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 156 | /// Subtarget - Keep a pointer to the PIC16Subtarget around so that we can |
| 157 | /// make the right decision when generating code for different targets. |
| 158 | const PIC16Subtarget *Subtarget; |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame^] | 159 | |
| 160 | |
| 161 | // Extending the LIB Call framework of LLVM |
| 162 | // To hold the names of PIC16LibCalls |
| 163 | const char *PIC16LibCallNames[PIC16ISD::PIC16UnknownCall]; |
| 164 | |
| 165 | // To set and retrieve the lib call names |
| 166 | void setPIC16LibCallName(PIC16ISD::PIC16LibCall Call, const char *Name); |
| 167 | const char *getPIC16LibCallName(PIC16ISD::PIC16LibCall Call); |
| 168 | |
| 169 | // Make PIC16 LibCall |
| 170 | SDValue MakePIC16LibCall(PIC16ISD::PIC16LibCall Call, MVT RetVT, |
| 171 | const SDValue *Ops, unsigned NumOps, bool isSigned, |
| 172 | SelectionDAG &DAG); |
| 173 | |
| 174 | // Check if operation has a direct load operand. |
| 175 | inline bool isDirectLoad(const SDValue Op); |
| 176 | |
| 177 | // Create the symbol and index for function frame |
| 178 | void getCurrentFrameIndex(SelectionDAG &DAG, SDValue &ES, |
| 179 | unsigned SlotSize, int &FI); |
| 180 | |
| 181 | SDValue getCurrentFrame(SelectionDAG &DAG); |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 182 | }; |
| 183 | } // namespace llvm |
| 184 | |
| 185 | #endif // PIC16ISELLOWERING_H |