Add a -no-implicit-float flag. This acts like -soft-float, but may generate
[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 NoImplicitFloat;
33   bool NoZerosInBSS;
34   bool ExceptionHandling;
35   bool UnwindTablesMandatory;
36   Reloc::Model RelocationModel;
37   CodeModel::Model CMModel;
38   bool PerformTailCallOpt;
39   unsigned StackAlignment;
40   bool RealignStack;
41   bool VerboseAsm;
42   bool DisableJumpTables;
43   bool StrongPHIElim;
44   bool DisableRedZone;
45 }
46
47 static cl::opt<bool, true>
48 PrintCode("print-machineinstrs",
49   cl::desc("Print generated machine code"),
50   cl::location(PrintMachineCode), cl::init(false));
51 static cl::opt<bool, true>
52 DisableFPElim("disable-fp-elim",
53   cl::desc("Disable frame pointer elimination optimization"),
54   cl::location(NoFramePointerElim),
55   cl::init(false));
56 static cl::opt<bool, true>
57 DisableExcessPrecision("disable-excess-fp-precision",
58   cl::desc("Disable optimizations that may increase FP precision"),
59   cl::location(NoExcessFPPrecision),
60   cl::init(false));
61 static cl::opt<bool, true>
62 EnableUnsafeFPMath("enable-unsafe-fp-math",
63   cl::desc("Enable optimizations that may decrease FP precision"),
64   cl::location(UnsafeFPMath),
65   cl::init(false));
66 static cl::opt<bool, true>
67 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
68   cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
69   cl::location(FiniteOnlyFPMathOption),
70   cl::init(false));
71 static cl::opt<bool, true>
72 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
73   cl::Hidden,
74   cl::desc("Force codegen to assume rounding mode can change dynamically"),
75   cl::location(HonorSignDependentRoundingFPMathOption),
76   cl::init(false));
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 GenerateNoImplicitFloats("no-implicit-float",
84   cl::desc("Don't generate implicit floating point instructions (x86-only)"),
85   cl::location(NoImplicitFloat),
86   cl::init(false));
87 static cl::opt<bool, true>
88 DontPlaceZerosInBSS("nozero-initialized-in-bss",
89   cl::desc("Don't place zero-initialized symbols into bss section"),
90   cl::location(NoZerosInBSS),
91   cl::init(false));
92 static cl::opt<bool, true>
93 EnableExceptionHandling("enable-eh",
94   cl::desc("Emit DWARF exception handling (default if target supports)"),
95   cl::location(ExceptionHandling),
96   cl::init(false));
97 static cl::opt<bool, true>
98 EnableUnwindTables("unwind-tables",
99   cl::desc("Generate unwinding tables for all functions"),
100   cl::location(UnwindTablesMandatory),
101   cl::init(false));
102
103 static cl::opt<llvm::Reloc::Model, true>
104 DefRelocationModel("relocation-model",
105   cl::desc("Choose relocation model"),
106   cl::location(RelocationModel),
107   cl::init(Reloc::Default),
108   cl::values(
109     clEnumValN(Reloc::Default, "default",
110                "Target default relocation model"),
111     clEnumValN(Reloc::Static, "static",
112                "Non-relocatable code"),
113     clEnumValN(Reloc::PIC_, "pic",
114                "Fully relocatable, position independent code"),
115     clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
116                "Relocatable external references, non-relocatable code"),
117     clEnumValEnd));
118 static cl::opt<llvm::CodeModel::Model, true>
119 DefCodeModel("code-model",
120   cl::desc("Choose code model"),
121   cl::location(CMModel),
122   cl::init(CodeModel::Default),
123   cl::values(
124     clEnumValN(CodeModel::Default, "default",
125                "Target default code model"),
126     clEnumValN(CodeModel::Small, "small",
127                "Small code model"),
128     clEnumValN(CodeModel::Kernel, "kernel",
129                "Kernel code model"),
130     clEnumValN(CodeModel::Medium, "medium",
131                "Medium code model"),
132     clEnumValN(CodeModel::Large, "large",
133                "Large code model"),
134     clEnumValEnd));
135 static cl::opt<bool, true>
136 EnablePerformTailCallOpt("tailcallopt",
137   cl::desc("Turn on tail call optimization."),
138   cl::location(PerformTailCallOpt),
139   cl::init(false));
140 static cl::opt<unsigned, true>
141 OverrideStackAlignment("stack-alignment",
142   cl::desc("Override default stack alignment"),
143   cl::location(StackAlignment),
144   cl::init(0));
145 static cl::opt<bool, true>
146 EnableRealignStack("realign-stack",
147   cl::desc("Realign stack if needed"),
148   cl::location(RealignStack),
149   cl::init(true));
150 static cl::opt<bool, true>
151 AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
152   cl::location(VerboseAsm),
153   cl::init(false));
154 static cl::opt<bool, true>
155 DisableSwitchTables(cl::Hidden, "disable-jump-tables", 
156   cl::desc("Do not generate jump tables."),
157   cl::location(DisableJumpTables),
158   cl::init(false));
159 static cl::opt<bool, true>
160 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
161   cl::desc("Use strong PHI elimination."),
162   cl::location(StrongPHIElim),
163   cl::init(false));
164 static cl::opt<bool, true>
165 DisableRedZoneOption("disable-red-zone",
166   cl::desc("Do not emit code that uses the red zone."),
167   cl::location(DisableRedZone),
168   cl::init(false));
169
170 //---------------------------------------------------------------------------
171 // TargetMachine Class
172 //
173
174 TargetMachine::~TargetMachine() {
175   delete AsmInfo;
176 }
177
178 /// getRelocationModel - Returns the code generation relocation model. The
179 /// choices are static, PIC, and dynamic-no-pic, and target default.
180 Reloc::Model TargetMachine::getRelocationModel() {
181   return RelocationModel;
182 }
183
184 /// setRelocationModel - Sets the code generation relocation model.
185 void TargetMachine::setRelocationModel(Reloc::Model Model) {
186   RelocationModel = Model;
187 }
188
189 /// getCodeModel - Returns the code model. The choices are small, kernel,
190 /// medium, large, and target default.
191 CodeModel::Model TargetMachine::getCodeModel() {
192   return CMModel;
193 }
194
195 /// setCodeModel - Sets the code model.
196 void TargetMachine::setCodeModel(CodeModel::Model Model) {
197   CMModel = Model;
198 }
199
200 namespace llvm {
201   /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
202   /// option is specified on the command line. If this returns false (default),
203   /// the code generator is not allowed to assume that FP arithmetic arguments
204   /// and results are never NaNs or +-Infs.
205   bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
206   
207   /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
208   /// that the rounding mode of the FPU can change from its default.
209   bool HonorSignDependentRoundingFPMath() {
210     return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
211   }
212 }
213