implement movri
[oota-llvm.git] / lib / Target / ARM / ARMISelDAGToDAG.cpp
1 //===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines an instruction selector for the ARM target.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "ARM.h"
15 #include "ARMTargetMachine.h"
16 #include "llvm/DerivedTypes.h"
17 #include "llvm/Function.h"
18 #include "llvm/Intrinsics.h"
19 #include "llvm/CodeGen/MachineFrameInfo.h"
20 #include "llvm/CodeGen/MachineFunction.h"
21 #include "llvm/CodeGen/MachineInstrBuilder.h"
22 #include "llvm/CodeGen/SelectionDAG.h"
23 #include "llvm/CodeGen/SelectionDAGISel.h"
24 #include "llvm/CodeGen/SSARegMap.h"
25 #include "llvm/Target/TargetLowering.h"
26 #include "llvm/Support/Debug.h"
27 #include <iostream>
28 #include <set>
29 using namespace llvm;
30
31 namespace ARMISD {
32   enum {
33     FIRST_NUMBER = ISD::BUILTIN_OP_END+ARM::INSTRUCTION_LIST_END,
34     RET_FLAG,
35   };
36 }
37
38 namespace {
39   class ARMTargetLowering : public TargetLowering {
40   public:
41     ARMTargetLowering(TargetMachine &TM);
42     virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
43
44     virtual std::pair<SDOperand, SDOperand>
45       LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg,
46                   unsigned CC,
47                   bool isTailCall, SDOperand Callee, ArgListTy &Args,
48                   SelectionDAG &DAG);
49
50   };
51
52 }
53
54 ARMTargetLowering::ARMTargetLowering(TargetMachine &TM)
55   : TargetLowering(TM) {
56   setOperationAction(ISD::RET, MVT::Other, Custom);
57 }
58
59 std::pair<SDOperand, SDOperand>
60 ARMTargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
61                                  bool isVarArg, unsigned CC,
62                                  bool isTailCall, SDOperand Callee,
63                                  ArgListTy &Args, SelectionDAG &DAG) {
64   assert(0 && "Not implemented");
65   abort();
66 }
67
68 static SDOperand LowerRET(SDOperand Op, SelectionDAG &DAG) {
69   SDOperand Copy;
70   switch(Op.getNumOperands()) {
71   default:
72     assert(0 && "Do not know how to return this many arguments!");
73     abort();
74   case 1:
75     return SDOperand(); // ret void is legal
76   case 2:
77     Copy = DAG.getCopyToReg(Op.getOperand(0), ARM::R0, Op.getOperand(1), SDOperand());
78     break;
79   }
80
81   return DAG.getNode(ARMISD::RET_FLAG, MVT::Other, Copy, Copy.getValue(1));
82 }
83
84 static SDOperand LowerFORMAL_ARGUMENTS(SDOperand Op, SelectionDAG &DAG) {
85   assert(0 && "Not implemented");
86 }
87
88 SDOperand ARMTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
89   switch (Op.getOpcode()) {
90   default:
91     assert(0 && "Should not custom lower this!");
92     abort();
93   case ISD::FORMAL_ARGUMENTS:
94     return LowerFORMAL_ARGUMENTS(Op, DAG);
95   case ISD::RET:
96     return LowerRET(Op, DAG);
97   }
98 }
99
100 //===----------------------------------------------------------------------===//
101 // Instruction Selector Implementation
102 //===----------------------------------------------------------------------===//
103
104 //===--------------------------------------------------------------------===//
105 /// ARMDAGToDAGISel - ARM specific code to select ARM machine
106 /// instructions for SelectionDAG operations.
107 ///
108 namespace {
109 class ARMDAGToDAGISel : public SelectionDAGISel {
110   ARMTargetLowering Lowering;
111
112 public:
113   ARMDAGToDAGISel(TargetMachine &TM)
114     : SelectionDAGISel(Lowering), Lowering(TM) {
115   }
116
117   void Select(SDOperand &Result, SDOperand Op);
118   virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
119
120   // Include the pieces autogenerated from the target description.
121 #include "ARMGenDAGISel.inc"
122 };
123
124 void ARMDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
125   DEBUG(BB->dump());
126
127   DAG.setRoot(SelectRoot(DAG.getRoot()));
128   CodeGenMap.clear();
129   DAG.RemoveDeadNodes();
130
131   ScheduleAndEmitDAG(DAG);
132 }
133
134 void ARMDAGToDAGISel::Select(SDOperand &Result, SDOperand Op) {
135   SelectCode(Result, Op);
136 }
137
138 }  // end anonymous namespace
139
140 /// createARMISelDag - This pass converts a legalized DAG into a
141 /// ARM-specific DAG, ready for instruction scheduling.
142 ///
143 FunctionPass *llvm::createARMISelDag(TargetMachine &TM) {
144   return new ARMDAGToDAGISel(TM);
145 }