Add new function attribute - noimplicitfloat
[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 AsmVerbosityDefault(false);
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 EnableFPMAD("enable-fp-mad",
63   cl::desc("Enable less precise MAD instructions to be generated"),
64   cl::location(LessPreciseFPMADOption),
65   cl::init(false));
66 static cl::opt<bool, true>
67 EnableUnsafeFPMath("enable-unsafe-fp-math",
68   cl::desc("Enable optimizations that may decrease FP precision"),
69   cl::location(UnsafeFPMath),
70   cl::init(false));
71 static cl::opt<bool, true>
72 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
73   cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
74   cl::location(FiniteOnlyFPMathOption),
75   cl::init(false));
76 static cl::opt<bool, true>
77 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
78   cl::Hidden,
79   cl::desc("Force codegen to assume rounding mode can change dynamically"),
80   cl::location(HonorSignDependentRoundingFPMathOption),
81   cl::init(false));
82 static cl::opt<bool, true>
83 GenerateSoftFloatCalls("soft-float",
84   cl::desc("Generate software floating point library calls"),
85   cl::location(UseSoftFloat),
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 DisableSwitchTables(cl::Hidden, "disable-jump-tables", 
152   cl::desc("Do not generate jump tables."),
153   cl::location(DisableJumpTables),
154   cl::init(false));
155 static cl::opt<bool, true>
156 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
157   cl::desc("Use strong PHI elimination."),
158   cl::location(StrongPHIElim),
159   cl::init(false));
160
161 //---------------------------------------------------------------------------
162 // TargetMachine Class
163 //
164
165 TargetMachine::~TargetMachine() {
166   delete AsmInfo;
167 }
168
169 /// getRelocationModel - Returns the code generation relocation model. The
170 /// choices are static, PIC, and dynamic-no-pic, and target default.
171 Reloc::Model TargetMachine::getRelocationModel() {
172   return RelocationModel;
173 }
174
175 /// setRelocationModel - Sets the code generation relocation model.
176 void TargetMachine::setRelocationModel(Reloc::Model Model) {
177   RelocationModel = Model;
178 }
179
180 /// getCodeModel - Returns the code model. The choices are small, kernel,
181 /// medium, large, and target default.
182 CodeModel::Model TargetMachine::getCodeModel() {
183   return CMModel;
184 }
185
186 /// setCodeModel - Sets the code model.
187 void TargetMachine::setCodeModel(CodeModel::Model Model) {
188   CMModel = Model;
189 }
190
191 bool TargetMachine::getAsmVerbosityDefault() {
192   return AsmVerbosityDefault;
193 }
194
195 void TargetMachine::setAsmVerbosityDefault(bool V) {
196   AsmVerbosityDefault = V;
197 }
198
199 namespace llvm {
200   /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
201   /// is specified on the command line.  When this flag is off(default), the
202   /// code generator is not allowed to generate mad (multiply add) if the
203   /// result is "less precise" than doing those operations individually.
204   bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
205
206   /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
207   /// option is specified on the command line. If this returns false (default),
208   /// the code generator is not allowed to assume that FP arithmetic arguments
209   /// and results are never NaNs or +-Infs.
210   bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
211   
212   /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
213   /// that the rounding mode of the FPU can change from its default.
214   bool HonorSignDependentRoundingFPMath() {
215     return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
216   }
217 }
218