Simplify target construction.
[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, const std::string &FS)
57   : DataLayout("e"),
58     FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0),
59     JITInfo(*this),
60     Subtarget(M, FS)
61 {
62   DEBUG(std::cerr << "FS is " << FS << "\n");
63 }
64
65 /// addPassesToEmitFile - Add passes to the specified pass manager to implement
66 /// a static compiler for this target.
67 ///
68 bool AlphaTargetMachine::addPassesToEmitFile(PassManager &PM,
69                                              std::ostream &Out,
70                                              CodeGenFileType FileType,
71                                              bool Fast) {
72   if (FileType != TargetMachine::AssemblyFile) return true;
73
74   PM.add(createLoopStrengthReducePass());
75   PM.add(createCFGSimplificationPass());
76
77  
78   // FIXME: Implement efficient support for garbage collection intrinsics.
79   PM.add(createLowerGCPass());
80
81   // FIXME: Implement the invoke/unwind instructions!
82   PM.add(createLowerInvokePass());
83
84   // Make sure that no unreachable blocks are instruction selected.
85   PM.add(createUnreachableBlockEliminationPass());
86
87   PM.add(createAlphaISelDag(*this));
88
89   if (PrintMachineCode)
90     PM.add(createMachineFunctionPrinterPass(&std::cerr));
91
92   PM.add(createRegisterAllocator());
93
94   if (PrintMachineCode)
95     PM.add(createMachineFunctionPrinterPass(&std::cerr));
96
97   PM.add(createPrologEpilogCodeInserter());
98
99   // Must run branch selection immediately preceding the asm printer
100   //PM.add(createAlphaBranchSelectionPass());
101
102   PM.add(createAlphaCodePrinterPass(Out, *this));
103
104   PM.add(createMachineCodeDeleter());
105   return false;
106 }
107
108 void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
109
110   PM.add(createLoopStrengthReducePass());
111   PM.add(createCFGSimplificationPass());
112
113   // FIXME: Implement efficient support for garbage collection intrinsics.
114   PM.add(createLowerGCPass());
115
116   // FIXME: Implement the invoke/unwind instructions!
117   PM.add(createLowerInvokePass());
118
119   // Make sure that no unreachable blocks are instruction selected.
120   PM.add(createUnreachableBlockEliminationPass());
121
122   PM.add(createAlphaISelDag(TM));
123
124   if (PrintMachineCode)
125     PM.add(createMachineFunctionPrinterPass(&std::cerr));
126
127   PM.add(createRegisterAllocator());
128
129   if (PrintMachineCode)
130     PM.add(createMachineFunctionPrinterPass(&std::cerr));
131
132   PM.add(createPrologEpilogCodeInserter());
133
134   // Must run branch selection immediately preceding the asm printer
135   //PM.add(createAlphaBranchSelectionPass());
136
137 }
138
139 bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
140                                                     MachineCodeEmitter &MCE) {
141   PM.add(createAlphaCodeEmitterPass(*this, MCE));
142   // Delete machine code for this function
143   PM.add(createMachineCodeDeleter());
144   return false;
145 }