blob: 78571f46fbbb7358f757835dfd9d90c9fa742517 [file] [log] [blame]
Sanjiv Gupta0e687712008-05-13 09:02:57 +00001//===-- 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 Gupta0e687712008-05-13 09:02:57 +000018#include "PIC16.h"
19#include "PIC16Subtarget.h"
Sanjiv Gupta2010b3e2008-05-14 11:31:39 +000020#include "llvm/CodeGen/SelectionDAG.h"
21#include "llvm/Target/TargetLowering.h"
Sanjiv Gupta0e687712008-05-13 09:02:57 +000022
23namespace llvm {
24 namespace PIC16ISD {
25 enum NodeType {
26 // Start the numbering from where ISD NodeType finishes.
Dan Gohman0ba2bcf2008-09-23 18:42:32 +000027 FIRST_NUMBER = ISD::BUILTIN_OP_END,
Sanjiv Gupta0e687712008-05-13 09:02:57 +000028
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000029 Lo, // Low 8-bits of GlobalAddress.
30 Hi, // High 8-bits of GlobalAddress.
31 PIC16Load,
Sanjiv Gupta1b046942009-01-13 19:18:47 +000032 PIC16LdWF,
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000033 PIC16Store,
Sanjiv Gupta1b046942009-01-13 19:18:47 +000034 PIC16StWF,
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000035 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 Gupta1b046942009-01-13 19:18:47 +000043 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 Guptab1b5ffd2008-11-19 11:00:54 +000047 Dummy
48 };
Sanjiv Gupta0e687712008-05-13 09:02:57 +000049
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000050 // 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 Gupta0e687712008-05-13 09:02:57 +000054 };
Sanjiv Gupta08b9b052009-01-21 05:44:05 +000055 enum PIC16Libcall {
56 MUL_I8,
Sanjiv Gupta1b046942009-01-13 19:18:47 +000057 SRA_I8,
58 SLL_I8,
59 SRL_I8,
Sanjiv Gupta1b046942009-01-13 19:18:47 +000060 PIC16UnknownCall
61 };
Sanjiv Gupta0e687712008-05-13 09:02:57 +000062 }
63
Sanjiv Gupta1b046942009-01-13 19:18:47 +000064
Sanjiv Gupta0e687712008-05-13 09:02:57 +000065 //===--------------------------------------------------------------------===//
66 // TargetLowering Implementation
67 //===--------------------------------------------------------------------===//
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000068 class PIC16TargetLowering : public TargetLowering {
Sanjiv Gupta0e687712008-05-13 09:02:57 +000069 public:
Sanjiv Gupta0e687712008-05-13 09:02:57 +000070 explicit PIC16TargetLowering(PIC16TargetMachine &TM);
71
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000072 /// getTargetNodeName - This method returns the name of a target specific
73 /// DAG node.
Sanjiv Gupta0e687712008-05-13 09:02:57 +000074 virtual const char *getTargetNodeName(unsigned Opcode) const;
Sanjiv Gupta1b046942009-01-13 19:18:47 +000075 /// getSetCCResultType - Return the ISD::SETCC ValueType
76 virtual MVT getSetCCResultType(MVT ValType) const;
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000077 SDValue LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG);
Sanjiv Gupta08b9b052009-01-21 05:44:05 +000078 SDValue LowerShift(SDValue Op, SelectionDAG &DAG);
Sanjiv Gupta1b046942009-01-13 19:18:47 +000079 SDValue LowerADD(SDValue Op, SelectionDAG &DAG);
80 SDValue LowerSUB(SDValue Op, SelectionDAG &DAG);
Sanjiv Gupta8f78fa82008-11-26 10:53:50 +000081 SDValue LowerBinOp(SDValue Op, SelectionDAG &DAG);
Sanjiv Gupta1b046942009-01-13 19:18:47 +000082 SDValue LowerCALL(SDValue Op, SelectionDAG &DAG);
83 SDValue LowerRET(SDValue Op, SelectionDAG &DAG);
84 SDValue LowerCallReturn(SDValue Op, SDValue Chain, SDValue FrameAddress,
85 SDValue InFlag, SelectionDAG &DAG);
86 SDValue LowerCallArguments(SDValue Op, SDValue Chain, SDValue FrameAddress,
87 SDValue InFlag, SelectionDAG &DAG);
88 SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG);
89 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG);
90 SDValue getPIC16Cmp(SDValue LHS, SDValue RHS, unsigned OrigCC, SDValue &CC,
91 SelectionDAG &DAG);
92 virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI,
93 MachineBasicBlock *MBB);
Sanjiv Gupta0e687712008-05-13 09:02:57 +000094
Sanjiv Gupta1b046942009-01-13 19:18:47 +000095
Sanjiv Gupta08b9b052009-01-21 05:44:05 +000096 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
Sanjiv Gupta1b046942009-01-13 19:18:47 +000097 virtual void ReplaceNodeResults(SDNode *N,
98 SmallVectorImpl<SDValue> &Results,
Duncan Sands1607f052008-12-01 11:39:25 +000099 SelectionDAG &DAG);
Duncan Sands9fbc7e22009-01-21 09:00:29 +0000100 virtual void LowerOperationWrapper(SDNode *N,
101 SmallVectorImpl<SDValue> &Results,
102 SelectionDAG &DAG);
Sanjiv Gupta08b9b052009-01-21 05:44:05 +0000103
Duncan Sands1607f052008-12-01 11:39:25 +0000104 SDValue ExpandStore(SDNode *N, SelectionDAG &DAG);
105 SDValue ExpandLoad(SDNode *N, SelectionDAG &DAG);
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000106 //SDValue ExpandAdd(SDNode *N, SelectionDAG &DAG);
Duncan Sands1607f052008-12-01 11:39:25 +0000107 SDValue ExpandGlobalAddress(SDNode *N, SelectionDAG &DAG);
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000108 SDValue ExpandExternalSymbol(SDNode *N, SelectionDAG &DAG);
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000109 SDValue ExpandFrameIndex(SDNode *N, SelectionDAG &DAG);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000110
111 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
112 SDValue PerformPIC16LoadCombine(SDNode *N, DAGCombinerInfo &DCI) const;
113
114 private:
115 // If the Node is a BUILD_PAIR representing representing an Address
116 // then this function will return true
117 bool isDirectAddress(const SDValue &Op);
118
119 // If the Node is a DirectAddress in ROM_SPACE then this
120 // function will return true
121 bool isRomAddress(const SDValue &Op);
122
123 // To extract chain value from the SDValue Nodes
124 // This function will help to maintain the chain extracting
125 // code at one place. In case of any change in future it will
126 // help maintain the code
127 SDValue getChain(SDValue &Op);
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000128
129 SDValue getOutFlag(SDValue &Op);
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000130
131
132 // Extract the Lo and Hi component of Op.
133 void GetExpandedParts(SDValue Op, SelectionDAG &DAG, SDValue &Lo,
134 SDValue &Hi);
135
136
137 // Load pointer can be a direct or indirect address. In PIC16 direct
138 // addresses need Banksel and Indirect addresses need to be loaded to
139 // FSR first. Handle address specific cases here.
140 void LegalizeAddress(SDValue Ptr, SelectionDAG &DAG, SDValue &Chain,
141 SDValue &NewPtr, unsigned &Offset);
142
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000143 // FrameIndex should be broken down into ExternalSymbol and FrameOffset.
144 void LegalizeFrameIndex(SDValue Op, SelectionDAG &DAG, SDValue &ES,
145 int &Offset);
146
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000147 // We can not have both operands of a binary operation in W.
148 // This function is used to put one operand on stack and generate a load.
149 SDValue ConvertToMemOperand(SDValue Op, SelectionDAG &DAG);
150
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000151 // This function checks if we need to put an operand of an operation on
152 // stack and generate a load or not.
153 bool NeedToConvertToMemOp(SDValue Op, unsigned &MemOp);
154
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +0000155 /// Subtarget - Keep a pointer to the PIC16Subtarget around so that we can
156 /// make the right decision when generating code for different targets.
157 const PIC16Subtarget *Subtarget;
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000158
159
160 // Extending the LIB Call framework of LLVM
Sanjiv Gupta08b9b052009-01-21 05:44:05 +0000161 // To hold the names of PIC16Libcalls
162 const char *PIC16LibcallNames[PIC16ISD::PIC16UnknownCall];
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000163
164 // To set and retrieve the lib call names
Sanjiv Gupta08b9b052009-01-21 05:44:05 +0000165 void setPIC16LibcallName(PIC16ISD::PIC16Libcall Call, const char *Name);
166 const char *getPIC16LibcallName(PIC16ISD::PIC16Libcall Call);
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000167
Sanjiv Gupta08b9b052009-01-21 05:44:05 +0000168 // Make PIC16 Libcall
169 SDValue MakePIC16Libcall(PIC16ISD::PIC16Libcall Call, MVT RetVT,
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000170 const SDValue *Ops, unsigned NumOps, bool isSigned,
171 SelectionDAG &DAG);
172
173 // Check if operation has a direct load operand.
174 inline bool isDirectLoad(const SDValue Op);
175
176 // Create the symbol and index for function frame
177 void getCurrentFrameIndex(SelectionDAG &DAG, SDValue &ES,
178 unsigned SlotSize, int &FI);
179
180 SDValue getCurrentFrame(SelectionDAG &DAG);
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000181 };
182} // namespace llvm
183
184#endif // PIC16ISELLOWERING_H