blob: 9b9eeb2abed80297ec6ee4ac6770563ede5632db [file] [log] [blame]
Anton Korobeynikov4403b932009-07-16 13:27:25 +00001//==-- SystemZISelDAGToDAG.cpp - A dag to dag inst selector for SystemZ ---===//
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 an instruction selector for the SystemZ target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "SystemZ.h"
15#include "SystemZISelLowering.h"
16#include "SystemZTargetMachine.h"
17#include "llvm/DerivedTypes.h"
18#include "llvm/Function.h"
19#include "llvm/Intrinsics.h"
20#include "llvm/CallingConv.h"
21#include "llvm/Constants.h"
22#include "llvm/CodeGen/MachineFrameInfo.h"
23#include "llvm/CodeGen/MachineFunction.h"
24#include "llvm/CodeGen/MachineInstrBuilder.h"
25#include "llvm/CodeGen/MachineRegisterInfo.h"
26#include "llvm/CodeGen/SelectionDAG.h"
27#include "llvm/CodeGen/SelectionDAGISel.h"
28#include "llvm/Target/TargetLowering.h"
29#include "llvm/Support/Compiler.h"
30#include "llvm/Support/Debug.h"
31using namespace llvm;
32
33/// SystemZDAGToDAGISel - SystemZ specific code to select SystemZ machine
34/// instructions for SelectionDAG operations.
35///
36namespace {
37 class SystemZDAGToDAGISel : public SelectionDAGISel {
38 SystemZTargetLowering &Lowering;
39 const SystemZSubtarget &Subtarget;
40
41 public:
42 SystemZDAGToDAGISel(SystemZTargetMachine &TM, CodeGenOpt::Level OptLevel)
43 : SelectionDAGISel(TM, OptLevel),
44 Lowering(*TM.getTargetLowering()),
45 Subtarget(*TM.getSubtargetImpl()) { }
46
47 virtual void InstructionSelect();
48
49 virtual const char *getPassName() const {
50 return "SystemZ DAG->DAG Pattern Instruction Selection";
51 }
52
53 // Include the pieces autogenerated from the target description.
54 #include "SystemZGenDAGISel.inc"
55
56 private:
57 SDNode *Select(SDValue Op);
58
59 #ifndef NDEBUG
60 unsigned Indent;
61 #endif
62 };
63} // end anonymous namespace
64
65/// createSystemZISelDag - This pass converts a legalized DAG into a
66/// SystemZ-specific DAG, ready for instruction scheduling.
67///
68FunctionPass *llvm::createSystemZISelDag(SystemZTargetMachine &TM,
69 CodeGenOpt::Level OptLevel) {
70 return new SystemZDAGToDAGISel(TM, OptLevel);
71}
72
73
74/// InstructionSelect - This callback is invoked by
75/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
76void SystemZDAGToDAGISel::InstructionSelect() {
77 DEBUG(BB->dump());
78
79 // Codegen the basic block.
80#ifndef NDEBUG
81 DOUT << "===== Instruction selection begins:\n";
82 Indent = 0;
83#endif
84 SelectRoot(*CurDAG);
85#ifndef NDEBUG
86 DOUT << "===== Instruction selection ends:\n";
87#endif
88
89 CurDAG->RemoveDeadNodes();
90}
91
92SDNode *SystemZDAGToDAGISel::Select(SDValue Op) {
93 SDNode *Node = Op.getNode();
94 DebugLoc dl = Op.getDebugLoc();
95
96 // Dump information about the Node being selected
97 #ifndef NDEBUG
98 DOUT << std::string(Indent, ' ') << "Selecting: ";
99 DEBUG(Node->dump(CurDAG));
100 DOUT << "\n";
101 Indent += 2;
102 #endif
103
104 // If we have a custom node, we already have selected!
105 if (Node->isMachineOpcode()) {
106 #ifndef NDEBUG
107 DOUT << std::string(Indent-2, ' ') << "== ";
108 DEBUG(Node->dump(CurDAG));
109 DOUT << "\n";
110 Indent -= 2;
111 #endif
112 return NULL;
113 }
114
115 // Select the default instruction
116 SDNode *ResNode = SelectCode(Op);
117
118 #ifndef NDEBUG
119 DOUT << std::string(Indent-2, ' ') << "=> ";
120 if (ResNode == NULL || ResNode == Op.getNode())
121 DEBUG(Op.getNode()->dump(CurDAG));
122 else
123 DEBUG(ResNode->dump(CurDAG));
124 DOUT << "\n";
125 Indent -= 2;
126 #endif
127
128 return ResNode;
129}