Unbreak the JIT with SSE
[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 unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) {
32   // We strongly match "alpha*".
33   std::string TT = M.getTargetTriple();
34   if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
35       TT[3] == 'h' && TT[4] == 'a')
36     return 20;
37
38   if (M.getEndianness()  == Module::LittleEndian &&
39       M.getPointerSize() == Module::Pointer64)
40     return 10;                                   // Weak match
41   else if (M.getEndianness() != Module::AnyEndianness ||
42            M.getPointerSize() != Module::AnyPointerSize)
43     return 0;                                    // Match for some other target
44
45   return getJITMatchQuality()/2;
46 }
47
48 unsigned AlphaTargetMachine::getJITMatchQuality() {
49 #ifdef __alpha
50   return 10;
51 #else
52   return 0;
53 #endif
54 }
55
56 AlphaTargetMachine::AlphaTargetMachine(const Module &M, IntrinsicLowering *IL,
57                                        const std::string &FS)
58   : TargetMachine("alpha", IL, true),
59     FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
60     JITInfo(*this),
61     Subtarget(M, FS)
62 {
63   DEBUG(std::cerr << "FS is " << FS << "\n");
64 }
65
66 /// addPassesToEmitFile - Add passes to the specified pass manager to implement
67 /// a static compiler for this target.
68 ///
69 bool AlphaTargetMachine::addPassesToEmitFile(PassManager &PM,
70                                              std::ostream &Out,
71                                              CodeGenFileType FileType,
72                                              bool Fast) {
73   if (FileType != TargetMachine::AssemblyFile) return true;
74
75   PM.add(createLoopStrengthReducePass());
76   PM.add(createCFGSimplificationPass());
77
78  
79   // FIXME: Implement efficient support for garbage collection intrinsics.
80   PM.add(createLowerGCPass());
81
82   // FIXME: Implement the invoke/unwind instructions!
83   PM.add(createLowerInvokePass());
84
85   // FIXME: Implement the switch instruction in the instruction selector!
86   PM.add(createLowerSwitchPass());
87
88   // Make sure that no unreachable blocks are instruction selected.
89   PM.add(createUnreachableBlockEliminationPass());
90
91   PM.add(createAlphaISelDag(*this));
92
93   if (PrintMachineCode)
94     PM.add(createMachineFunctionPrinterPass(&std::cerr));
95
96   PM.add(createRegisterAllocator());
97
98   if (PrintMachineCode)
99     PM.add(createMachineFunctionPrinterPass(&std::cerr));
100
101   PM.add(createPrologEpilogCodeInserter());
102
103   // Must run branch selection immediately preceding the asm printer
104   //PM.add(createAlphaBranchSelectionPass());
105
106   PM.add(createAlphaCodePrinterPass(Out, *this));
107
108   PM.add(createMachineCodeDeleter());
109   return false;
110 }
111
112 void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
113
114   PM.add(createLoopStrengthReducePass());
115   PM.add(createCFGSimplificationPass());
116
117   // FIXME: Implement efficient support for garbage collection intrinsics.
118   PM.add(createLowerGCPass());
119
120   // FIXME: Implement the invoke/unwind instructions!
121   PM.add(createLowerInvokePass());
122
123   // FIXME: Implement the switch instruction in the instruction selector!
124   PM.add(createLowerSwitchPass());
125
126   // Make sure that no unreachable blocks are instruction selected.
127   PM.add(createUnreachableBlockEliminationPass());
128
129   PM.add(createAlphaISelDag(TM));
130
131   if (PrintMachineCode)
132     PM.add(createMachineFunctionPrinterPass(&std::cerr));
133
134   PM.add(createRegisterAllocator());
135
136   if (PrintMachineCode)
137     PM.add(createMachineFunctionPrinterPass(&std::cerr));
138
139   PM.add(createPrologEpilogCodeInserter());
140
141   // Must run branch selection immediately preceding the asm printer
142   //PM.add(createAlphaBranchSelectionPass());
143
144 }
145
146 bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
147                                                     MachineCodeEmitter &MCE) {
148   PM.add(createAlphaCodeEmitterPass(MCE));
149   // Delete machine code for this function
150   PM.add(createMachineCodeDeleter());
151   return false;
152 }