switch TL::getValueType to use MVT::getValueType.
[oota-llvm.git] / lib / CodeGen / LLVMTargetMachine.cpp
1 //===-- LLVMTargetMachine.cpp - Implement the LLVMTargetMachine class -----===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the LLVMTargetMachine class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Target/TargetMachine.h"
15 #include "llvm/PassManager.h"
16 #include "llvm/Pass.h"
17 #include "llvm/Assembly/PrintModulePass.h"
18 #include "llvm/Analysis/LoopPass.h"
19 #include "llvm/CodeGen/Passes.h"
20 #include "llvm/Target/TargetOptions.h"
21 #include "llvm/Transforms/Scalar.h"
22 #include "llvm/Support/CommandLine.h"
23 using namespace llvm;
24
25 static cl::opt<bool> PrintLSR("print-lsr-output");
26
27 FileModel::Model
28 LLVMTargetMachine::addPassesToEmitFile(FunctionPassManager &PM,
29                                        std::ostream &Out,
30                                        CodeGenFileType FileType,
31                                        bool Fast) {
32   // Standard LLVM-Level Passes.
33   
34   // Run loop strength reduction before anything else.
35   if (!Fast) {
36     PM.add(createLoopStrengthReducePass(getTargetLowering()));
37     if (PrintLSR)
38       PM.add(new PrintFunctionPass("\n\n*** Code after LSR *** \n", &cerr));
39   }
40   
41   // FIXME: Implement efficient support for garbage collection intrinsics.
42   PM.add(createLowerGCPass());
43   
44   // FIXME: Implement the invoke/unwind instructions!
45   if (!ExceptionHandling)
46     PM.add(createLowerInvokePass(getTargetLowering()));
47   
48   // Make sure that no unreachable blocks are instruction selected.
49   PM.add(createUnreachableBlockEliminationPass());
50
51   // Ask the target for an isel.
52   if (addInstSelector(PM, Fast))
53     return FileModel::Error;
54
55   // Print the instruction selected machine code...
56   if (PrintMachineCode)
57     PM.add(createMachineFunctionPrinterPass(cerr));
58   
59   // Perform register allocation to convert to a concrete x86 representation
60   PM.add(createRegisterAllocator());
61   
62   if (PrintMachineCode)
63     PM.add(createMachineFunctionPrinterPass(cerr));
64
65   // Run post-ra passes.
66   if (addPostRegAlloc(PM, Fast) && PrintMachineCode)
67     PM.add(createMachineFunctionPrinterPass(cerr));
68
69   // Insert prolog/epilog code.  Eliminate abstract frame index references...
70   PM.add(createPrologEpilogCodeInserter());
71   
72   // Branch folding must be run after regalloc and prolog/epilog insertion.
73   if (!Fast)
74     PM.add(createBranchFoldingPass());
75     
76   // Fold redundant debug labels.
77   PM.add(createDebugLabelFoldingPass());
78   
79   if (PrintMachineCode)  // Print the register-allocated code
80     PM.add(createMachineFunctionPrinterPass(cerr));
81
82   if (addPreEmitPass(PM, Fast) && PrintMachineCode)
83     PM.add(createMachineFunctionPrinterPass(cerr));
84
85   switch (FileType) {
86   default:
87     break;
88   case TargetMachine::AssemblyFile:
89     if (addAssemblyEmitter(PM, Fast, Out))
90       return FileModel::Error;
91     return FileModel::AsmFile;
92   case TargetMachine::ObjectFile:
93     if (getMachOWriterInfo())
94       return FileModel::MachOFile;
95     else if (getELFWriterInfo())
96       return FileModel::ElfFile;
97   }
98
99   return FileModel::Error;
100 }
101  
102 /// addPassesToEmitFileFinish - If the passes to emit the specified file had to
103 /// be split up (e.g., to add an object writer pass), this method can be used to
104 /// finish up adding passes to emit the file, if necessary.
105 bool LLVMTargetMachine::addPassesToEmitFileFinish(FunctionPassManager &PM,
106                                                   MachineCodeEmitter *MCE,
107                                                   bool Fast) {
108   if (MCE)
109     addSimpleCodeEmitter(PM, Fast, *MCE);
110
111   // Delete machine code for this function
112   PM.add(createMachineCodeDeleter());
113
114   return false; // success!
115 }
116
117 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
118 /// get machine code emitted.  This uses a MachineCodeEmitter object to handle
119 /// actually outputting the machine code and resolving things like the address
120 /// of functions.  This method should returns true if machine code emission is
121 /// not supported.
122 ///
123 bool LLVMTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
124                                                    MachineCodeEmitter &MCE,
125                                                    bool Fast) {
126   // Standard LLVM-Level Passes.
127   
128   // Run loop strength reduction before anything else.
129   if (!Fast) PM.add(createLoopStrengthReducePass(getTargetLowering()));
130   
131   // FIXME: Implement efficient support for garbage collection intrinsics.
132   PM.add(createLowerGCPass());
133   
134   // FIXME: Implement the invoke/unwind instructions!
135   PM.add(createLowerInvokePass(getTargetLowering()));
136   
137   // Make sure that no unreachable blocks are instruction selected.
138   PM.add(createUnreachableBlockEliminationPass());
139
140   // Ask the target for an isel.
141   if (addInstSelector(PM, Fast))
142     return true;
143
144   // Print the instruction selected machine code...
145   if (PrintMachineCode)
146     PM.add(createMachineFunctionPrinterPass(cerr));
147   
148   // Perform register allocation to convert to a concrete x86 representation
149   PM.add(createRegisterAllocator());
150   
151   if (PrintMachineCode)
152     PM.add(createMachineFunctionPrinterPass(cerr));
153
154   // Run post-ra passes.
155   if (addPostRegAlloc(PM, Fast) && PrintMachineCode)
156     PM.add(createMachineFunctionPrinterPass(cerr));
157
158   // Insert prolog/epilog code.  Eliminate abstract frame index references...
159   PM.add(createPrologEpilogCodeInserter());
160   
161   if (PrintMachineCode)  // Print the register-allocated code
162     PM.add(createMachineFunctionPrinterPass(cerr));
163   
164   // Branch folding must be run after regalloc and prolog/epilog insertion.
165   if (!Fast)
166     PM.add(createBranchFoldingPass());
167   
168   if (addPreEmitPass(PM, Fast) && PrintMachineCode)
169     PM.add(createMachineFunctionPrinterPass(cerr));
170
171   addCodeEmitter(PM, Fast, MCE);
172   
173   // Delete machine code for this function
174   PM.add(createMachineCodeDeleter());
175   
176   return false; // success!
177 }