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