Emit declaration for globals and externs.
[oota-llvm.git] / lib / Target / PIC16 / PIC16ISelLowering.h
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
18 #include "PIC16.h"
19 #include "PIC16Subtarget.h"
20 #include "llvm/CodeGen/SelectionDAG.h"
21 #include "llvm/Target/TargetLowering.h"
22
23 namespace llvm {
24   namespace PIC16ISD {
25     enum NodeType {
26       // Start the numbering from where ISD NodeType finishes.
27       FIRST_NUMBER = ISD::BUILTIN_OP_END,
28
29       Lo,            // Low 8-bits of GlobalAddress.
30       Hi,            // High 8-bits of GlobalAddress.
31       PIC16Load,
32       PIC16Store,
33       Banksel,
34       MTLO,
35       MTHI,
36       BCF,
37       LSLF,          // PIC16 Logical shift left
38       LRLF,          // PIC16 Logical shift right
39       RLF,           // Rotate left through carry
40       RRF,           // Rotate right through carry
41       Dummy
42     };
43
44     // Keep track of different address spaces. 
45     enum AddressSpace {
46       RAM_SPACE = 0,   // RAM address space
47       ROM_SPACE = 1    // ROM address space number is 1
48     };
49   }
50
51   //===--------------------------------------------------------------------===//
52   // TargetLowering Implementation
53   //===--------------------------------------------------------------------===//
54   class PIC16TargetLowering : public TargetLowering {
55   public:
56     explicit PIC16TargetLowering(PIC16TargetMachine &TM);
57
58     /// getTargetNodeName - This method returns the name of a target specific
59     /// DAG node.
60     virtual const char *getTargetNodeName(unsigned Opcode) const;
61     SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
62     SDValue LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG);
63     SDValue LowerADDE(SDValue Op, SelectionDAG &DAG);
64     SDValue LowerADDC(SDValue Op, SelectionDAG &DAG);
65     SDValue LowerSUBE(SDValue Op, SelectionDAG &DAG);
66     SDValue LowerSUBC(SDValue Op, SelectionDAG &DAG);
67     SDValue LowerBinOp(SDValue Op, SelectionDAG &DAG);
68
69     SDNode *ReplaceNodeResults(SDNode *N, SelectionDAG &DAG);
70     SDNode *ExpandStore(SDNode *N, SelectionDAG &DAG);
71     SDNode *ExpandLoad(SDNode *N, SelectionDAG &DAG);
72     SDNode *ExpandAdd(SDNode *N, SelectionDAG &DAG);
73     SDNode *ExpandGlobalAddress(SDNode *N, SelectionDAG &DAG);
74     SDNode *ExpandShift(SDNode *N, SelectionDAG &DAG);
75
76     SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; 
77     SDValue PerformPIC16LoadCombine(SDNode *N, DAGCombinerInfo &DCI) const; 
78
79   private:
80     // If the Node is a BUILD_PAIR representing representing an Address
81     // then this function will return true
82     bool isDirectAddress(const SDValue &Op);
83
84     // If the Node is a DirectAddress in ROM_SPACE then this 
85     // function will return true
86     bool isRomAddress(const SDValue &Op);
87
88     // To extract chain value from the SDValue Nodes
89     // This function will help to maintain the chain extracting
90     // code at one place. In case of any change in future it will
91     // help maintain the code
92     SDValue getChain(SDValue &Op);
93
94
95     // Extract the Lo and Hi component of Op. 
96     void GetExpandedParts(SDValue Op, SelectionDAG &DAG, SDValue &Lo, 
97                           SDValue &Hi); 
98
99
100     // Load pointer can be a direct or indirect address. In PIC16 direct
101     // addresses need Banksel and Indirect addresses need to be loaded to
102     // FSR first. Handle address specific cases here.
103     void LegalizeAddress(SDValue Ptr, SelectionDAG &DAG, SDValue &Chain, 
104                          SDValue &NewPtr, unsigned &Offset);
105
106     // We can not have both operands of a binary operation in W.
107     // This function is used to put one operand on stack and generate a load.
108     SDValue ConvertToMemOperand(SDValue Op, SelectionDAG &DAG); 
109
110     /// Subtarget - Keep a pointer to the PIC16Subtarget around so that we can
111     /// make the right decision when generating code for different targets.
112     const PIC16Subtarget *Subtarget;
113   };
114 } // namespace llvm
115
116 #endif // PIC16ISELLOWERING_H