blob: de8bd2b024bff508819bd0a57e830746281d0d12 [file] [log] [blame]
Sanjiv Gupta09bb4202008-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 Gupta09bb4202008-05-13 09:02:57 +000018#include "PIC16.h"
19#include "PIC16Subtarget.h"
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +000020#include "llvm/CodeGen/SelectionDAG.h"
21#include "llvm/Target/TargetLowering.h"
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000022
23namespace llvm {
24 namespace PIC16ISD {
25 enum NodeType {
26 // Start the numbering from where ISD NodeType finishes.
Dan Gohman868636e2008-09-23 18:42:32 +000027 FIRST_NUMBER = ISD::BUILTIN_OP_END,
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000028
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000029 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 };
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000043
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000044 // 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
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000048 };
49 }
50
51 //===--------------------------------------------------------------------===//
52 // TargetLowering Implementation
53 //===--------------------------------------------------------------------===//
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000054 class PIC16TargetLowering : public TargetLowering {
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000055 public:
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000056 explicit PIC16TargetLowering(PIC16TargetMachine &TM);
57
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000058 /// getTargetNodeName - This method returns the name of a target specific
59 /// DAG node.
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000060 virtual const char *getTargetNodeName(unsigned Opcode) const;
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000061 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);
Sanjiv Guptaecfffdb2008-11-26 10:53:50 +000067 SDValue LowerBinOp(SDValue Op, SelectionDAG &DAG);
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000068
Duncan Sands7d9834b2008-12-01 11:39:25 +000069 /// ReplaceNodeResults - Replace the results of node with an illegal result
70 /// type with new values built out of custom code.
71 ///
72 virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
73 SelectionDAG &DAG);
74
75 SDValue ExpandStore(SDNode *N, SelectionDAG &DAG);
76 SDValue ExpandLoad(SDNode *N, SelectionDAG &DAG);
77// SDNode *ExpandAdd(SDNode *N, SelectionDAG &DAG);
78 SDValue ExpandGlobalAddress(SDNode *N, SelectionDAG &DAG);
79 SDValue ExpandShift(SDNode *N, SelectionDAG &DAG);
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000080
81 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
82 SDValue PerformPIC16LoadCombine(SDNode *N, DAGCombinerInfo &DCI) const;
83
84 private:
85 // If the Node is a BUILD_PAIR representing representing an Address
86 // then this function will return true
87 bool isDirectAddress(const SDValue &Op);
88
89 // If the Node is a DirectAddress in ROM_SPACE then this
90 // function will return true
91 bool isRomAddress(const SDValue &Op);
92
93 // To extract chain value from the SDValue Nodes
94 // This function will help to maintain the chain extracting
95 // code at one place. In case of any change in future it will
96 // help maintain the code
97 SDValue getChain(SDValue &Op);
98
99
100 // Extract the Lo and Hi component of Op.
101 void GetExpandedParts(SDValue Op, SelectionDAG &DAG, SDValue &Lo,
102 SDValue &Hi);
103
104
105 // Load pointer can be a direct or indirect address. In PIC16 direct
106 // addresses need Banksel and Indirect addresses need to be loaded to
107 // FSR first. Handle address specific cases here.
108 void LegalizeAddress(SDValue Ptr, SelectionDAG &DAG, SDValue &Chain,
109 SDValue &NewPtr, unsigned &Offset);
110
111 // We can not have both operands of a binary operation in W.
112 // This function is used to put one operand on stack and generate a load.
113 SDValue ConvertToMemOperand(SDValue Op, SelectionDAG &DAG);
114
115 /// Subtarget - Keep a pointer to the PIC16Subtarget around so that we can
116 /// make the right decision when generating code for different targets.
117 const PIC16Subtarget *Subtarget;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000118 };
119} // namespace llvm
120
121#endif // PIC16ISELLOWERING_H