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"
26 // Start the numbering from where ISD NodeType finishes.
27 FIRST_NUMBER = ISD::BUILTIN_OP_END,
29 Lo, // Low 8-bits of GlobalAddress.
30 Hi, // High 8-bits of GlobalAddress.
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.
43 LSLF, // PIC16 Logical shift left
44 LRLF, // PIC16 Logical shift right
45 RLF, // Rotate left through carry
46 RRF, // Rotate right through carry
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.
55 // Keep track of different address spaces.
57 RAM_SPACE = 0, // RAM address space
58 ROM_SPACE = 1 // ROM address space number is 1
70 //===--------------------------------------------------------------------===//
71 // TargetLowering Implementation
72 //===--------------------------------------------------------------------===//
73 class PIC16TargetLowering : public TargetLowering {
75 explicit PIC16TargetLowering(PIC16TargetMachine &TM);
77 /// getTargetNodeName - This method returns the name of a target specific
79 virtual const char *getTargetNodeName(unsigned Opcode) const;
80 /// getSetCCResultType - Return the ISD::SETCC ValueType
81 virtual MVT getSetCCResultType(MVT ValType) const;
82 SDValue LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG);
83 SDValue LowerShift(SDValue Op, SelectionDAG &DAG);
84 SDValue LowerADD(SDValue Op, SelectionDAG &DAG);
85 SDValue LowerSUB(SDValue Op, SelectionDAG &DAG);
86 SDValue LowerBinOp(SDValue Op, SelectionDAG &DAG);
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 LowerStopPoint(SDValue Op, SelectionDAG &DAG);
96 SDValue getPIC16Cmp(SDValue LHS, SDValue RHS, unsigned OrigCC, SDValue &CC,
97 SelectionDAG &DAG, DebugLoc dl);
98 virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI,
99 MachineBasicBlock *MBB) const;
102 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
103 virtual void ReplaceNodeResults(SDNode *N,
104 SmallVectorImpl<SDValue> &Results,
106 virtual void LowerOperationWrapper(SDNode *N,
107 SmallVectorImpl<SDValue> &Results,
110 SDValue ExpandStore(SDNode *N, SelectionDAG &DAG);
111 SDValue ExpandLoad(SDNode *N, SelectionDAG &DAG);
112 SDValue ExpandGlobalAddress(SDNode *N, SelectionDAG &DAG);
113 SDValue ExpandExternalSymbol(SDNode *N, SelectionDAG &DAG);
114 SDValue ExpandFrameIndex(SDNode *N, SelectionDAG &DAG);
116 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
117 SDValue PerformPIC16LoadCombine(SDNode *N, DAGCombinerInfo &DCI) const;
118 SDValue PerformStoreCombine(SDNode *N, DAGCombinerInfo &DCI) const;
121 // If the Node is a BUILD_PAIR representing a direct Address,
122 // then this function will return true.
123 bool isDirectAddress(const SDValue &Op);
125 // If the Node is a DirectAddress in ROM_SPACE then this
126 // function will return true
127 bool isRomAddress(const SDValue &Op);
129 // Extract the Lo and Hi component of Op.
130 void GetExpandedParts(SDValue Op, SelectionDAG &DAG, SDValue &Lo,
134 // Load pointer can be a direct or indirect address. In PIC16 direct
135 // addresses need Banksel and Indirect addresses need to be loaded to
136 // FSR first. Handle address specific cases here.
137 void LegalizeAddress(SDValue Ptr, SelectionDAG &DAG, SDValue &Chain,
138 SDValue &NewPtr, unsigned &Offset, DebugLoc dl);
140 // FrameIndex should be broken down into ExternalSymbol and FrameOffset.
141 void LegalizeFrameIndex(SDValue Op, SelectionDAG &DAG, SDValue &ES,
144 // We can not have both operands of a binary operation in W.
145 // This function is used to put one operand on stack and generate a load.
146 SDValue ConvertToMemOperand(SDValue Op, SelectionDAG &DAG, DebugLoc dl);
148 // This function checks if we need to put an operand of an operation on
149 // stack and generate a load or not.
150 bool NeedToConvertToMemOp(SDValue Op, unsigned &MemOp);
152 /// Subtarget - Keep a pointer to the PIC16Subtarget around so that we can
153 /// make the right decision when generating code for different targets.
154 const PIC16Subtarget *Subtarget;
157 // Extending the LIB Call framework of LLVM
158 // to hold the names of PIC16Libcalls.
159 const char *PIC16LibcallNames[PIC16ISD::PIC16UnknownCall];
161 // To set and retrieve the lib call names.
162 void setPIC16LibcallName(PIC16ISD::PIC16Libcall Call, const char *Name);
163 const char *getPIC16LibcallName(PIC16ISD::PIC16Libcall Call);
165 // Make PIC16 Libcall.
166 SDValue MakePIC16Libcall(PIC16ISD::PIC16Libcall Call, MVT RetVT,
167 const SDValue *Ops, unsigned NumOps, bool isSigned,
168 SelectionDAG &DAG, DebugLoc dl);
170 // Check if operation has a direct load operand.
171 inline bool isDirectLoad(const SDValue Op);
176 #endif // PIC16ISELLOWERING_H