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 DontPlaceZerosInBSS("nozero-initialized-in-bss",
89 cl::desc("Don't place zero-initialized symbols into bss section"),
90 cl::location(NoZerosInBSS),
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),
97 static cl::opt<bool, true>
98 EnableUnwindTables("unwind-tables",
99 cl::desc("Generate unwinding tables for all functions"),
100 cl::location(UnwindTablesMandatory),
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),
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"),
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),
124 clEnumValN(CodeModel::Default, "default",
125 "Target default code model"),
126 clEnumValN(CodeModel::Small, "small",
128 clEnumValN(CodeModel::Kernel, "kernel",
129 "Kernel code model"),
130 clEnumValN(CodeModel::Medium, "medium",
131 "Medium code model"),
132 clEnumValN(CodeModel::Large, "large",
135 static cl::opt<bool, true>
136 EnablePerformTailCallOpt("tailcallopt",
137 cl::desc("Turn on tail call optimization."),
138 cl::location(PerformTailCallOpt),
140 static cl::opt<unsigned, true>
141 OverrideStackAlignment("stack-alignment",
142 cl::desc("Override default stack alignment"),
143 cl::location(StackAlignment),
145 static cl::opt<bool, true>
146 EnableRealignStack("realign-stack",
147 cl::desc("Realign stack if needed"),
148 cl::location(RealignStack),
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),
155 static cl::opt<bool, true>
156 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
157 cl::desc("Use strong PHI elimination."),
158 cl::location(StrongPHIElim),
161 //---------------------------------------------------------------------------
162 // TargetMachine Class
165 TargetMachine::~TargetMachine() {
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;
175 /// setRelocationModel - Sets the code generation relocation model.
176 void TargetMachine::setRelocationModel(Reloc::Model Model) {
177 RelocationModel = Model;
180 /// getCodeModel - Returns the code model. The choices are small, kernel,
181 /// medium, large, and target default.
182 CodeModel::Model TargetMachine::getCodeModel() {
186 /// setCodeModel - Sets the code model.
187 void TargetMachine::setCodeModel(CodeModel::Model Model) {
191 bool TargetMachine::getAsmVerbosityDefault() {
192 return AsmVerbosityDefault;
195 void TargetMachine::setAsmVerbosityDefault(bool V) {
196 AsmVerbosityDefault = V;
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; }
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; }
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;