Add new function attribute - noredzone.
[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 GenerateNoImplicitFloats("no-implicit-float",
89   cl::desc("Don't generate implicit floating point instructions (x86-only)"),
90   cl::location(NoImplicitFloat),
91   cl::init(false));
92 static cl::opt<bool, true>
93 DontPlaceZerosInBSS("nozero-initialized-in-bss",
94   cl::desc("Don't place zero-initialized symbols into bss section"),
95   cl::location(NoZerosInBSS),
96   cl::init(false));
97 static cl::opt<bool, true>
98 EnableExceptionHandling("enable-eh",
99   cl::desc("Emit DWARF exception handling (default if target supports)"),
100   cl::location(ExceptionHandling),
101   cl::init(false));
102 static cl::opt<bool, true>
103 EnableUnwindTables("unwind-tables",
104   cl::desc("Generate unwinding tables for all functions"),
105   cl::location(UnwindTablesMandatory),
106   cl::init(false));
107
108 static cl::opt<llvm::Reloc::Model, true>
109 DefRelocationModel("relocation-model",
110   cl::desc("Choose relocation model"),
111   cl::location(RelocationModel),
112   cl::init(Reloc::Default),
113   cl::values(
114     clEnumValN(Reloc::Default, "default",
115                "Target default relocation model"),
116     clEnumValN(Reloc::Static, "static",
117                "Non-relocatable code"),
118     clEnumValN(Reloc::PIC_, "pic",
119                "Fully relocatable, position independent code"),
120     clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
121                "Relocatable external references, non-relocatable code"),
122     clEnumValEnd));
123 static cl::opt<llvm::CodeModel::Model, true>
124 DefCodeModel("code-model",
125   cl::desc("Choose code model"),
126   cl::location(CMModel),
127   cl::init(CodeModel::Default),
128   cl::values(
129     clEnumValN(CodeModel::Default, "default",
130                "Target default code model"),
131     clEnumValN(CodeModel::Small, "small",
132                "Small code model"),
133     clEnumValN(CodeModel::Kernel, "kernel",
134                "Kernel code model"),
135     clEnumValN(CodeModel::Medium, "medium",
136                "Medium code model"),
137     clEnumValN(CodeModel::Large, "large",
138                "Large code model"),
139     clEnumValEnd));
140 static cl::opt<bool, true>
141 EnablePerformTailCallOpt("tailcallopt",
142   cl::desc("Turn on tail call optimization."),
143   cl::location(PerformTailCallOpt),
144   cl::init(false));
145 static cl::opt<unsigned, true>
146 OverrideStackAlignment("stack-alignment",
147   cl::desc("Override default stack alignment"),
148   cl::location(StackAlignment),
149   cl::init(0));
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 static cl::opt<bool, true>
156 DisableSwitchTables(cl::Hidden, "disable-jump-tables", 
157   cl::desc("Do not generate jump tables."),
158   cl::location(DisableJumpTables),
159   cl::init(false));
160 static cl::opt<bool, true>
161 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
162   cl::desc("Use strong PHI elimination."),
163   cl::location(StrongPHIElim),
164   cl::init(false));
165
166 //---------------------------------------------------------------------------
167 // TargetMachine Class
168 //
169
170 TargetMachine::~TargetMachine() {
171   delete AsmInfo;
172 }
173
174 /// getRelocationModel - Returns the code generation relocation model. The
175 /// choices are static, PIC, and dynamic-no-pic, and target default.
176 Reloc::Model TargetMachine::getRelocationModel() {
177   return RelocationModel;
178 }
179
180 /// setRelocationModel - Sets the code generation relocation model.
181 void TargetMachine::setRelocationModel(Reloc::Model Model) {
182   RelocationModel = Model;
183 }
184
185 /// getCodeModel - Returns the code model. The choices are small, kernel,
186 /// medium, large, and target default.
187 CodeModel::Model TargetMachine::getCodeModel() {
188   return CMModel;
189 }
190
191 /// setCodeModel - Sets the code model.
192 void TargetMachine::setCodeModel(CodeModel::Model Model) {
193   CMModel = Model;
194 }
195
196 bool TargetMachine::getAsmVerbosityDefault() {
197   return AsmVerbosityDefault;
198 }
199
200 void TargetMachine::setAsmVerbosityDefault(bool V) {
201   AsmVerbosityDefault = V;
202 }
203
204 namespace llvm {
205   /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
206   /// is specified on the command line.  When this flag is off(default), the
207   /// code generator is not allowed to generate mad (multiply add) if the
208   /// result is "less precise" than doing those operations individually.
209   bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
210
211   /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
212   /// option is specified on the command line. If this returns false (default),
213   /// the code generator is not allowed to assume that FP arithmetic arguments
214   /// and results are never NaNs or +-Infs.
215   bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
216   
217   /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
218   /// that the rounding mode of the FPU can change from its default.
219   bool HonorSignDependentRoundingFPMath() {
220     return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
221   }
222 }
223