CodeGen still defaults to non-verbose asm, but llc now overrides it and default to...
[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 DisableJumpTables;
43   bool StrongPHIElim;
44   bool DisableRedZone;
45   bool AsmVerbosityDefault(false);
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 DisableSwitchTables(cl::Hidden, "disable-jump-tables", 
158   cl::desc("Do not generate jump tables."),
159   cl::location(DisableJumpTables),
160   cl::init(false));
161 static cl::opt<bool, true>
162 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
163   cl::desc("Use strong PHI elimination."),
164   cl::location(StrongPHIElim),
165   cl::init(false));
166 static cl::opt<bool, true>
167 DisableRedZoneOption("disable-red-zone",
168   cl::desc("Do not emit code that uses the red zone."),
169   cl::location(DisableRedZone),
170   cl::init(false));
171
172 //---------------------------------------------------------------------------
173 // TargetMachine Class
174 //
175
176 TargetMachine::~TargetMachine() {
177   delete AsmInfo;
178 }
179
180 /// getRelocationModel - Returns the code generation relocation model. The
181 /// choices are static, PIC, and dynamic-no-pic, and target default.
182 Reloc::Model TargetMachine::getRelocationModel() {
183   return RelocationModel;
184 }
185
186 /// setRelocationModel - Sets the code generation relocation model.
187 void TargetMachine::setRelocationModel(Reloc::Model Model) {
188   RelocationModel = Model;
189 }
190
191 /// getCodeModel - Returns the code model. The choices are small, kernel,
192 /// medium, large, and target default.
193 CodeModel::Model TargetMachine::getCodeModel() {
194   return CMModel;
195 }
196
197 /// setCodeModel - Sets the code model.
198 void TargetMachine::setCodeModel(CodeModel::Model Model) {
199   CMModel = Model;
200 }
201
202 bool TargetMachine::getAsmVerbosityDefault() {
203   return AsmVerbosityDefault;
204 }
205
206 void TargetMachine::setAsmVerbosityDefault(bool V) {
207   AsmVerbosityDefault = V;
208 }
209
210 namespace llvm {
211   /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
212   /// is specified on the command line.  When this flag is off(default), the
213   /// code generator is not allowed to generate mad (multiply add) if the
214   /// result is "less precise" than doing those operations individually.
215   bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
216
217   /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
218   /// option is specified on the command line. If this returns false (default),
219   /// the code generator is not allowed to assume that FP arithmetic arguments
220   /// and results are never NaNs or +-Infs.
221   bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
222   
223   /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
224   /// that the rounding mode of the FPU can change from its default.
225   bool HonorSignDependentRoundingFPMath() {
226     return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
227   }
228 }
229