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