make DAG isel the default
[oota-llvm.git] / lib / Target / Alpha / AlphaTargetMachine.cpp
1 //===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "Alpha.h"
14 #include "AlphaJITInfo.h"
15 #include "AlphaTargetMachine.h"
16 #include "llvm/Module.h"
17 #include "llvm/CodeGen/Passes.h"
18 #include "llvm/Target/TargetOptions.h"
19 #include "llvm/Target/TargetMachineRegistry.h"
20 #include "llvm/Transforms/Scalar.h"
21 #include "llvm/Support/Debug.h"
22 #include <iostream>
23
24 using namespace llvm;
25
26 namespace {
27   // Register the targets
28   RegisterTarget<AlphaTargetMachine> X("alpha", "  Alpha (incomplete)");
29 }
30
31 namespace llvm {
32   cl::opt<bool> DisableAlphaDAG("disable-alpha-dag-isel",
33                              cl::desc("Disable DAG ISEL for Alpha"),
34                              cl::Hidden);
35 }
36
37 unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
38   // We strongly match "alpha*".
39   std::string TT = M.getTargetTriple();
40   if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
41       TT[3] == 'h' && TT[4] == 'a')
42     return 20;
43
44   if (M.getEndianness()  == Module::LittleEndian &&
45       M.getPointerSize() == Module::Pointer64)
46     return 10;                                   // Weak match
47   else if (M.getEndianness() != Module::AnyEndianness ||
48            M.getPointerSize() != Module::AnyPointerSize)
49     return 0;                                    // Match for some other target
50
51   return getJITMatchQuality()/2;
52 }
53
54 unsigned AlphaTargetMachine::getJITMatchQuality() {
55 #ifdef __alpha
56   return 10;
57 #else
58   return 0;
59 #endif
60 }
61
62 AlphaTargetMachine::AlphaTargetMachine(const Module &M, IntrinsicLowering *IL,
63                                        const std::string &FS)
64   : TargetMachine("alpha", IL, true),
65     FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
66     JITInfo(*this),
67     Subtarget(M, FS)
68 {
69   DEBUG(std::cerr << "FS is " << FS << "\n");
70 }
71
72 /// addPassesToEmitFile - Add passes to the specified pass manager to implement
73 /// a static compiler for this target.
74 ///
75 bool AlphaTargetMachine::addPassesToEmitFile(PassManager &PM,
76                                              std::ostream &Out,
77                                              CodeGenFileType FileType,
78                                              bool Fast) {
79   if (FileType != TargetMachine::AssemblyFile) return true;
80
81   PM.add(createLoopStrengthReducePass());
82   PM.add(createCFGSimplificationPass());
83
84  
85   // FIXME: Implement efficient support for garbage collection intrinsics.
86   PM.add(createLowerGCPass());
87
88   // FIXME: Implement the invoke/unwind instructions!
89   PM.add(createLowerInvokePass());
90
91   // FIXME: Implement the switch instruction in the instruction selector!
92   PM.add(createLowerSwitchPass());
93
94   // Make sure that no unreachable blocks are instruction selected.
95   PM.add(createUnreachableBlockEliminationPass());
96
97   if (!DisableAlphaDAG)
98     PM.add(createAlphaISelDag(*this));
99   else
100     PM.add(createAlphaPatternInstructionSelector(*this));
101
102   if (PrintMachineCode)
103     PM.add(createMachineFunctionPrinterPass(&std::cerr));
104
105   PM.add(createRegisterAllocator());
106
107   if (PrintMachineCode)
108     PM.add(createMachineFunctionPrinterPass(&std::cerr));
109
110   PM.add(createPrologEpilogCodeInserter());
111
112   // Must run branch selection immediately preceding the asm printer
113   //PM.add(createAlphaBranchSelectionPass());
114
115   PM.add(createAlphaCodePrinterPass(Out, *this));
116
117   PM.add(createMachineCodeDeleter());
118   return false;
119 }
120
121 void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
122
123   PM.add(createLoopStrengthReducePass());
124   PM.add(createCFGSimplificationPass());
125
126   // FIXME: Implement efficient support for garbage collection intrinsics.
127   PM.add(createLowerGCPass());
128
129   // FIXME: Implement the invoke/unwind instructions!
130   PM.add(createLowerInvokePass());
131
132   // FIXME: Implement the switch instruction in the instruction selector!
133   PM.add(createLowerSwitchPass());
134
135   // Make sure that no unreachable blocks are instruction selected.
136   PM.add(createUnreachableBlockEliminationPass());
137
138   PM.add(createAlphaPatternInstructionSelector(TM));
139
140   if (PrintMachineCode)
141     PM.add(createMachineFunctionPrinterPass(&std::cerr));
142
143   PM.add(createRegisterAllocator());
144
145   if (PrintMachineCode)
146     PM.add(createMachineFunctionPrinterPass(&std::cerr));
147
148   PM.add(createPrologEpilogCodeInserter());
149
150   // Must run branch selection immediately preceding the asm printer
151   //PM.add(createAlphaBranchSelectionPass());
152
153 }
154
155 bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
156                                                     MachineCodeEmitter &MCE) {
157   PM.add(createAlphaCodeEmitterPass(MCE));
158   // Delete machine code for this function
159   PM.add(createMachineCodeDeleter());
160   return false;
161 }