1 //===-- TargetMachine.cpp - General Target Information ---------------------==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the general parts of a Target machine.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Target/TargetAsmInfo.h"
15 #include "llvm/Target/TargetMachine.h"
16 #include "llvm/Target/TargetOptions.h"
17 #include "llvm/Support/CommandLine.h"
20 //---------------------------------------------------------------------------
21 // Command-line options that tend to be useful on more than one back-end.
25 bool LessPreciseFPMADOption;
26 bool PrintMachineCode;
27 bool NoFramePointerElim;
28 bool NoExcessFPPrecision;
30 bool FiniteOnlyFPMathOption;
31 bool HonorSignDependentRoundingFPMathOption;
35 bool ExceptionHandling;
36 bool UnwindTablesMandatory;
37 Reloc::Model RelocationModel;
38 CodeModel::Model CMModel;
39 bool PerformTailCallOpt;
40 unsigned StackAlignment;
42 bool DisableJumpTables;
44 bool AsmVerbosityDefault(false);
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),
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),
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),
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),
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),
76 static cl::opt<bool, true>
77 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
79 cl::desc("Force codegen to assume rounding mode can change dynamically"),
80 cl::location(HonorSignDependentRoundingFPMathOption),
82 static cl::opt<bool, true>
83 GenerateSoftFloatCalls("soft-float",
84 cl::desc("Generate software floating point library calls"),
85 cl::location(UseSoftFloat),
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),
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),
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),
102 static cl::opt<bool, true>
103 EnableUnwindTables("unwind-tables",
104 cl::desc("Generate unwinding tables for all functions"),
105 cl::location(UnwindTablesMandatory),
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),
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"),
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),
129 clEnumValN(CodeModel::Default, "default",
130 "Target default code model"),
131 clEnumValN(CodeModel::Small, "small",
133 clEnumValN(CodeModel::Kernel, "kernel",
134 "Kernel code model"),
135 clEnumValN(CodeModel::Medium, "medium",
136 "Medium code model"),
137 clEnumValN(CodeModel::Large, "large",
140 static cl::opt<bool, true>
141 EnablePerformTailCallOpt("tailcallopt",
142 cl::desc("Turn on tail call optimization."),
143 cl::location(PerformTailCallOpt),
145 static cl::opt<unsigned, true>
146 OverrideStackAlignment("stack-alignment",
147 cl::desc("Override default stack alignment"),
148 cl::location(StackAlignment),
150 static cl::opt<bool, true>
151 EnableRealignStack("realign-stack",
152 cl::desc("Realign stack if needed"),
153 cl::location(RealignStack),
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),
160 static cl::opt<bool, true>
161 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
162 cl::desc("Use strong PHI elimination."),
163 cl::location(StrongPHIElim),
166 //---------------------------------------------------------------------------
167 // TargetMachine Class
170 TargetMachine::~TargetMachine() {
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;
180 /// setRelocationModel - Sets the code generation relocation model.
181 void TargetMachine::setRelocationModel(Reloc::Model Model) {
182 RelocationModel = Model;
185 /// getCodeModel - Returns the code model. The choices are small, kernel,
186 /// medium, large, and target default.
187 CodeModel::Model TargetMachine::getCodeModel() {
191 /// setCodeModel - Sets the code model.
192 void TargetMachine::setCodeModel(CodeModel::Model Model) {
196 bool TargetMachine::getAsmVerbosityDefault() {
197 return AsmVerbosityDefault;
200 void TargetMachine::setAsmVerbosityDefault(bool V) {
201 AsmVerbosityDefault = V;
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; }
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; }
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;