Make all of the TargetMachine subclasses use the new string TargetData methods.
[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   : TargetMachine("alpha"),
58     DataLayout(std::string("alpha"), std::string("e")),
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   // Make sure that no unreachable blocks are instruction selected.
86   PM.add(createUnreachableBlockEliminationPass());
87
88   PM.add(createAlphaISelDag(*this));
89
90   if (PrintMachineCode)
91     PM.add(createMachineFunctionPrinterPass(&std::cerr));
92
93   PM.add(createRegisterAllocator());
94
95   if (PrintMachineCode)
96     PM.add(createMachineFunctionPrinterPass(&std::cerr));
97
98   PM.add(createPrologEpilogCodeInserter());
99
100   // Must run branch selection immediately preceding the asm printer
101   //PM.add(createAlphaBranchSelectionPass());
102
103   PM.add(createAlphaCodePrinterPass(Out, *this));
104
105   PM.add(createMachineCodeDeleter());
106   return false;
107 }
108
109 void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
110
111   PM.add(createLoopStrengthReducePass());
112   PM.add(createCFGSimplificationPass());
113
114   // FIXME: Implement efficient support for garbage collection intrinsics.
115   PM.add(createLowerGCPass());
116
117   // FIXME: Implement the invoke/unwind instructions!
118   PM.add(createLowerInvokePass());
119
120   // Make sure that no unreachable blocks are instruction selected.
121   PM.add(createUnreachableBlockEliminationPass());
122
123   PM.add(createAlphaISelDag(TM));
124
125   if (PrintMachineCode)
126     PM.add(createMachineFunctionPrinterPass(&std::cerr));
127
128   PM.add(createRegisterAllocator());
129
130   if (PrintMachineCode)
131     PM.add(createMachineFunctionPrinterPass(&std::cerr));
132
133   PM.add(createPrologEpilogCodeInserter());
134
135   // Must run branch selection immediately preceding the asm printer
136   //PM.add(createAlphaBranchSelectionPass());
137
138 }
139
140 bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
141                                                     MachineCodeEmitter &MCE) {
142   PM.add(createAlphaCodeEmitterPass(MCE));
143   // Delete machine code for this function
144   PM.add(createMachineCodeDeleter());
145   return false;
146 }