Reverting r55898 to r55909. One of these patches was causing an ICE during the full...
[oota-llvm.git] / lib / Target / TargetMachine.cpp
1 //===-- TargetMachine.cpp - General Target Information ---------------------==//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the general parts of a Target machine.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Target/TargetAsmInfo.h"
15 #include "llvm/Target/TargetMachine.h"
16 #include "llvm/Target/TargetOptions.h"
17 #include "llvm/Support/CommandLine.h"
18 using namespace llvm;
19
20 //---------------------------------------------------------------------------
21 // Command-line options that tend to be useful on more than one back-end.
22 //
23
24 namespace llvm {
25   bool PrintMachineCode;
26   bool NoFramePointerElim;
27   bool NoExcessFPPrecision;
28   bool UnsafeFPMath;
29   bool FiniteOnlyFPMathOption;
30   bool HonorSignDependentRoundingFPMathOption;
31   bool UseSoftFloat;
32   bool NoZerosInBSS;
33   bool ExceptionHandling;
34   bool UnwindTablesMandatory;
35   Reloc::Model RelocationModel;
36   CodeModel::Model CMModel;
37   bool PerformTailCallOpt;
38   bool OptimizeForSize;
39   unsigned StackAlignment;
40   bool RealignStack;
41   bool VerboseAsm;
42   bool DisableJumpTables;
43   StackCanaries::Model StackProtectors;
44 }
45
46 static cl::opt<bool, true> PrintCode("print-machineinstrs",
47   cl::desc("Print generated machine code"),
48   cl::location(PrintMachineCode), cl::init(false));
49
50 static cl::opt<bool, true>
51 DisableFPElim("disable-fp-elim",
52               cl::desc("Disable frame pointer elimination optimization"),
53               cl::location(NoFramePointerElim),
54               cl::init(false));
55 static cl::opt<bool, true>
56 DisableExcessPrecision("disable-excess-fp-precision",
57              cl::desc("Disable optimizations that may increase FP precision"),
58              cl::location(NoExcessFPPrecision),
59              cl::init(false));
60 static cl::opt<bool, true>
61 EnableUnsafeFPMath("enable-unsafe-fp-math",
62              cl::desc("Enable optimizations that may decrease FP precision"),
63              cl::location(UnsafeFPMath),
64              cl::init(false));
65 static cl::opt<bool, true>
66 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
67              cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
68              cl::location(FiniteOnlyFPMathOption),
69              cl::init(false));
70 static cl::opt<bool, true>
71 EnableHonorSignDependentRoundingFPMath(cl::Hidden,
72              "enable-sign-dependent-rounding-fp-math",
73      cl::desc("Force codegen to assume rounding mode can change dynamically"),
74              cl::location(HonorSignDependentRoundingFPMathOption),
75              cl::init(false));
76
77 static cl::opt<bool, true>
78 GenerateSoftFloatCalls("soft-float",
79              cl::desc("Generate software floating point library calls"),
80              cl::location(UseSoftFloat),
81              cl::init(false));
82 static cl::opt<bool, true>
83 DontPlaceZerosInBSS("nozero-initialized-in-bss",
84             cl::desc("Don't place zero-initialized symbols into bss section"),
85             cl::location(NoZerosInBSS),
86             cl::init(false));
87 static cl::opt<bool, true>
88 EnableExceptionHandling("enable-eh",
89              cl::desc("Emit DWARF exception handling (default if target supports)"),
90              cl::location(ExceptionHandling),
91              cl::init(false));
92 static cl::opt<bool, true>
93 EnableUnwindTables("unwind-tables",
94              cl::desc("Generate unwinding tables for all functions"),
95              cl::location(UnwindTablesMandatory),
96              cl::init(false));
97
98 static cl::opt<llvm::Reloc::Model, true>
99 DefRelocationModel(
100   "relocation-model",
101   cl::desc("Choose relocation model"),
102   cl::location(RelocationModel),
103   cl::init(Reloc::Default),
104   cl::values(
105     clEnumValN(Reloc::Default, "default",
106                "  Target default relocation model"),
107     clEnumValN(Reloc::Static, "static",
108                "  Non-relocatable code"),
109     clEnumValN(Reloc::PIC_, "pic",
110                "  Fully relocatable, position independent code"),
111     clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
112                "  Relocatable external references, non-relocatable code"),
113     clEnumValEnd));
114 static cl::opt<llvm::CodeModel::Model, true>
115 DefCodeModel(
116   "code-model",
117   cl::desc("Choose code model"),
118   cl::location(CMModel),
119   cl::init(CodeModel::Default),
120   cl::values(
121     clEnumValN(CodeModel::Default, "default",
122                "  Target default code model"),
123     clEnumValN(CodeModel::Small, "small",
124                "  Small code model"),
125     clEnumValN(CodeModel::Kernel, "kernel",
126                "  Kernel code model"),
127     clEnumValN(CodeModel::Medium, "medium",
128                "  Medium code model"),
129     clEnumValN(CodeModel::Large, "large",
130                "  Large code model"),
131     clEnumValEnd));
132
133 static cl::opt<bool, true>
134 EnablePerformTailCallOpt("tailcallopt",
135                          cl::desc("Turn on tail call optimization."),
136                          cl::location(PerformTailCallOpt),
137                          cl::init(false));
138 static cl::opt<bool, true>
139 EnableOptimizeForSize("optimize-size",
140                       cl::desc("Optimize for size."),
141                       cl::location(OptimizeForSize),
142                       cl::init(false));
143
144 static cl::opt<unsigned, true>
145 OverrideStackAlignment("stack-alignment",
146                        cl::desc("Override default stack alignment"),
147                        cl::location(StackAlignment),
148                        cl::init(0));
149
150 static cl::opt<bool, true>
151 EnableRealignStack("realign-stack",
152                    cl::desc("Realign stack if needed"),
153                    cl::location(RealignStack),
154                    cl::init(true));
155
156 static cl::opt<bool, true>
157 AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
158            cl::location(VerboseAsm),
159            cl::init(false));
160
161 static cl::opt<bool, true>
162 DisableSwitchTables(cl::Hidden, "disable-jump-tables", 
163            cl::desc("Do not generate jump tables."),
164            cl::location(DisableJumpTables),
165            cl::init(false));
166
167 static cl::opt<llvm::StackCanaries::Model, true>
168 GenerateStackProtectors("stack-protector",
169                         cl::desc("Generate stack protectors"),
170                         cl::location(StackProtectors),
171                         cl::init(StackCanaries::Default),
172                         cl::values(
173                          clEnumValN(StackCanaries::Default, "default",
174                            "  No stack protectors"),
175                          clEnumValN(StackCanaries::On, "on",
176                            "  Generate stack protectors for functions that"
177                            "need them"),
178                          clEnumValN(StackCanaries::Always, "all",
179                            "  Generate stack protectors for all functions"),
180                          clEnumValEnd));
181
182 //---------------------------------------------------------------------------
183 // TargetMachine Class
184 //
185
186 TargetMachine::~TargetMachine() {
187   delete AsmInfo;
188 }
189
190 /// getRelocationModel - Returns the code generation relocation model. The
191 /// choices are static, PIC, and dynamic-no-pic, and target default.
192 Reloc::Model TargetMachine::getRelocationModel() {
193   return RelocationModel;
194 }
195
196 /// setRelocationModel - Sets the code generation relocation model.
197 void TargetMachine::setRelocationModel(Reloc::Model Model) {
198   RelocationModel = Model;
199 }
200
201 /// getCodeModel - Returns the code model. The choices are small, kernel,
202 /// medium, large, and target default.
203 CodeModel::Model TargetMachine::getCodeModel() {
204   return CMModel;
205 }
206
207 /// setCodeModel - Sets the code model.
208 void TargetMachine::setCodeModel(CodeModel::Model Model) {
209   CMModel = Model;
210 }
211
212 namespace llvm {
213   /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
214   /// option is specified on the command line. If this returns false (default),
215   /// the code generator is not allowed to assume that FP arithmetic arguments
216   /// and results are never NaNs or +-Infs.
217   bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
218   
219   /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
220   /// that the rounding mode of the FPU can change from its default.
221   bool HonorSignDependentRoundingFPMath() {
222     return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
223   }
224 }
225