1 //===-- PIC16ISelLowering.h - PIC16 DAG Lowering Interface ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the interfaces that PIC16 uses to lower LLVM code into a
13 //===----------------------------------------------------------------------===//
15 #ifndef PIC16ISELLOWERING_H
16 #define PIC16ISELLOWERING_H
19 #include "PIC16Subtarget.h"
20 #include "llvm/CodeGen/SelectionDAG.h"
21 #include "llvm/Target/TargetLowering.h"
27 // Start the numbering from where ISD NodeType finishes.
28 FIRST_NUMBER = ISD::BUILTIN_OP_END,
30 Lo, // Low 8-bits of GlobalAddress.
31 Hi, // High 8-bits of GlobalAddress.
33 PIC16LdArg, // This is replica of PIC16Load but used to load function
34 // arguments and is being used for facilitating for some
35 // store removal optimizations.
44 LSLF, // PIC16 Logical shift left
45 LRLF, // PIC16 Logical shift right
46 RLF, // Rotate left through carry
47 RRF, // Rotate right through carry
48 CALL, // PIC16 Call instruction
49 SUBCC, // Compare for equality or inequality.
50 SELECT_ICC, // Psuedo to be caught in schedular and expanded to brcond.
51 BRCOND, // Conditional branch.
56 // Keep track of different address spaces.
58 RAM_SPACE = 0, // RAM address space
59 ROM_SPACE = 1 // ROM address space number is 1
71 //===--------------------------------------------------------------------===//
72 // TargetLowering Implementation
73 //===--------------------------------------------------------------------===//
74 class PIC16TargetLowering : public TargetLowering {
76 explicit PIC16TargetLowering(PIC16TargetMachine &TM);
78 /// getTargetNodeName - This method returns the name of a target specific
80 virtual const char *getTargetNodeName(unsigned Opcode) const;
81 /// getSetCCResultType - Return the ISD::SETCC ValueType
82 virtual MVT getSetCCResultType(MVT ValType) const;
83 SDValue LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG);
84 SDValue LowerShift(SDValue Op, SelectionDAG &DAG);
85 SDValue LowerADD(SDValue Op, SelectionDAG &DAG);
86 SDValue LowerSUB(SDValue Op, SelectionDAG &DAG);
87 SDValue LowerBinOp(SDValue Op, SelectionDAG &DAG);
88 SDValue LowerCALL(SDValue Op, SelectionDAG &DAG);
89 SDValue LowerRET(SDValue Op, SelectionDAG &DAG);
90 SDValue LowerCallReturn(SDValue Op, SDValue Chain, SDValue FrameAddress,
91 SDValue InFlag, SelectionDAG &DAG);
92 SDValue LowerCallArguments(SDValue Op, SDValue Chain, SDValue FrameAddress,
93 SDValue InFlag, SelectionDAG &DAG);
94 SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG);
95 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG);
96 SDValue LowerStopPoint(SDValue Op, SelectionDAG &DAG);
97 SDValue getPIC16Cmp(SDValue LHS, SDValue RHS, unsigned OrigCC, SDValue &CC,
98 SelectionDAG &DAG, DebugLoc dl);
99 virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI,
100 MachineBasicBlock *MBB) const;
103 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
104 virtual void ReplaceNodeResults(SDNode *N,
105 SmallVectorImpl<SDValue> &Results,
107 virtual void LowerOperationWrapper(SDNode *N,
108 SmallVectorImpl<SDValue> &Results,
111 SDValue ExpandStore(SDNode *N, SelectionDAG &DAG);
112 SDValue ExpandLoad(SDNode *N, SelectionDAG &DAG);
113 SDValue ExpandGlobalAddress(SDNode *N, SelectionDAG &DAG);
114 SDValue ExpandExternalSymbol(SDNode *N, SelectionDAG &DAG);
115 SDValue ExpandFrameIndex(SDNode *N, SelectionDAG &DAG);
117 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
118 SDValue PerformPIC16LoadCombine(SDNode *N, DAGCombinerInfo &DCI) const;
119 SDValue PerformStoreCombine(SDNode *N, DAGCombinerInfo &DCI) const;
121 // This function returns the Tmp Offset for FrameIndex. If any TmpOffset
122 // already exists for the FI then it returns the same else it creates the
123 // new offset and returns.
124 unsigned GetTmpOffsetForFI(unsigned FI);
125 void ResetTmpOffsetMap() { FiTmpOffsetMap.clear(); SetTmpSize(0); }
127 // Return the size of Tmp variable
128 unsigned GetTmpSize() { return TmpSize; }
129 void SetTmpSize(unsigned Size) { TmpSize = Size; }
132 // If the Node is a BUILD_PAIR representing a direct Address,
133 // then this function will return true.
134 bool isDirectAddress(const SDValue &Op);
136 // If the Node is a DirectAddress in ROM_SPACE then this
137 // function will return true
138 bool isRomAddress(const SDValue &Op);
140 // Extract the Lo and Hi component of Op.
141 void GetExpandedParts(SDValue Op, SelectionDAG &DAG, SDValue &Lo,
145 // Load pointer can be a direct or indirect address. In PIC16 direct
146 // addresses need Banksel and Indirect addresses need to be loaded to
147 // FSR first. Handle address specific cases here.
148 void LegalizeAddress(SDValue Ptr, SelectionDAG &DAG, SDValue &Chain,
149 SDValue &NewPtr, unsigned &Offset, DebugLoc dl);
151 // FrameIndex should be broken down into ExternalSymbol and FrameOffset.
152 void LegalizeFrameIndex(SDValue Op, SelectionDAG &DAG, SDValue &ES,
155 // We can not have both operands of a binary operation in W.
156 // This function is used to put one operand on stack and generate a load.
157 SDValue ConvertToMemOperand(SDValue Op, SelectionDAG &DAG, DebugLoc dl);
159 // This function checks if we need to put an operand of an operation on
160 // stack and generate a load or not.
161 bool NeedToConvertToMemOp(SDValue Op, unsigned &MemOp);
163 /// Subtarget - Keep a pointer to the PIC16Subtarget around so that we can
164 /// make the right decision when generating code for different targets.
165 const PIC16Subtarget *Subtarget;
168 // Extending the LIB Call framework of LLVM
169 // to hold the names of PIC16Libcalls.
170 const char *PIC16LibcallNames[PIC16ISD::PIC16UnknownCall];
172 // To set and retrieve the lib call names.
173 void setPIC16LibcallName(PIC16ISD::PIC16Libcall Call, const char *Name);
174 const char *getPIC16LibcallName(PIC16ISD::PIC16Libcall Call);
176 // Make PIC16 Libcall.
177 SDValue MakePIC16Libcall(PIC16ISD::PIC16Libcall Call, MVT RetVT,
178 const SDValue *Ops, unsigned NumOps, bool isSigned,
179 SelectionDAG &DAG, DebugLoc dl);
181 // Check if operation has a direct load operand.
182 inline bool isDirectLoad(const SDValue Op);
185 // The frameindexes generated for spill/reload are stack based.
186 // This maps maintain zero based indexes for these FIs.
187 std::map<unsigned, unsigned> FiTmpOffsetMap;
192 #endif // PIC16ISELLOWERING_H