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