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 PrintMachineCode;
26 bool NoFramePointerElim;
27 bool NoExcessFPPrecision;
29 bool FiniteOnlyFPMathOption;
30 bool HonorSignDependentRoundingFPMathOption;
33 bool ExceptionHandling;
34 bool UnwindTablesMandatory;
35 Reloc::Model RelocationModel;
36 CodeModel::Model CMModel;
37 bool PerformTailCallOpt;
40 unsigned StackAlignment;
43 static cl::opt<bool, true> PrintCode("print-machineinstrs",
44 cl::desc("Print generated machine code"),
45 cl::location(PrintMachineCode), cl::init(false));
47 static cl::opt<bool, true>
48 DisableFPElim("disable-fp-elim",
49 cl::desc("Disable frame pointer elimination optimization"),
50 cl::location(NoFramePointerElim),
52 static cl::opt<bool, true>
53 DisableExcessPrecision("disable-excess-fp-precision",
54 cl::desc("Disable optimizations that may increase FP precision"),
55 cl::location(NoExcessFPPrecision),
57 static cl::opt<bool, true>
58 EnableUnsafeFPMath("enable-unsafe-fp-math",
59 cl::desc("Enable optimizations that may decrease FP precision"),
60 cl::location(UnsafeFPMath),
62 static cl::opt<bool, true>
63 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
64 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
65 cl::location(FiniteOnlyFPMathOption),
67 static cl::opt<bool, true>
68 EnableHonorSignDependentRoundingFPMath(cl::Hidden,
69 "enable-sign-dependent-rounding-fp-math",
70 cl::desc("Force codegen to assume rounding mode can change dynamically"),
71 cl::location(HonorSignDependentRoundingFPMathOption),
74 static cl::opt<bool, true>
75 GenerateSoftFloatCalls("soft-float",
76 cl::desc("Generate software floating point library calls"),
77 cl::location(UseSoftFloat),
79 static cl::opt<bool, true>
80 DontPlaceZerosInBSS("nozero-initialized-in-bss",
81 cl::desc("Don't place zero-initialized symbols into bss section"),
82 cl::location(NoZerosInBSS),
84 static cl::opt<bool, true>
85 EnableExceptionHandling("enable-eh",
86 cl::desc("Emit DWARF exception handling (default if target supports)"),
87 cl::location(ExceptionHandling),
89 static cl::opt<bool, true>
90 EnableUnwindTables("unwind-tables",
91 cl::desc("Generate unwinding tables for all functions"),
92 cl::location(UnwindTablesMandatory),
95 static cl::opt<llvm::Reloc::Model, true>
98 cl::desc("Choose relocation model"),
99 cl::location(RelocationModel),
100 cl::init(Reloc::Default),
102 clEnumValN(Reloc::Default, "default",
103 " Target default relocation model"),
104 clEnumValN(Reloc::Static, "static",
105 " Non-relocatable code"),
106 clEnumValN(Reloc::PIC_, "pic",
107 " Fully relocatable, position independent code"),
108 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
109 " Relocatable external references, non-relocatable code"),
111 static cl::opt<llvm::CodeModel::Model, true>
114 cl::desc("Choose code model"),
115 cl::location(CMModel),
116 cl::init(CodeModel::Default),
118 clEnumValN(CodeModel::Default, "default",
119 " Target default code model"),
120 clEnumValN(CodeModel::Small, "small",
121 " Small code model"),
122 clEnumValN(CodeModel::Kernel, "kernel",
123 " Kernel code model"),
124 clEnumValN(CodeModel::Medium, "medium",
125 " Medium code model"),
126 clEnumValN(CodeModel::Large, "large",
127 " Large code model"),
130 static cl::opt<bool, true>
131 EnablePerformTailCallOpt("tailcallopt",
132 cl::desc("Turn on tail call optimization."),
133 cl::location(PerformTailCallOpt),
135 static cl::opt<bool, true>
136 EnableOptimizeForSize("optimize-size",
137 cl::desc("Optimize for size."),
138 cl::location(OptimizeForSize),
141 static cl::opt<bool, true>
142 EnableRealignStack("realign-stack",
143 cl::desc("Realign stack if needed"),
144 cl::location(RealignStack),
147 static cl::opt<unsigned, true>
148 OverrideStackAlignment("stack-alignment",
149 cl::desc("Override default stack alignment"),
150 cl::location(StackAlignment),
154 //---------------------------------------------------------------------------
155 // TargetMachine Class
158 TargetMachine::~TargetMachine() {
162 /// getRelocationModel - Returns the code generation relocation model. The
163 /// choices are static, PIC, and dynamic-no-pic, and target default.
164 Reloc::Model TargetMachine::getRelocationModel() {
165 return RelocationModel;
168 /// setRelocationModel - Sets the code generation relocation model.
169 void TargetMachine::setRelocationModel(Reloc::Model Model) {
170 RelocationModel = Model;
173 /// getCodeModel - Returns the code model. The choices are small, kernel,
174 /// medium, large, and target default.
175 CodeModel::Model TargetMachine::getCodeModel() {
179 /// setCodeModel - Sets the code model.
180 void TargetMachine::setCodeModel(CodeModel::Model Model) {
185 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
186 /// option is specified on the command line. If this returns false (default),
187 /// the code generator is not allowed to assume that FP arithmetic arguments
188 /// and results are never NaNs or +-Infs.
189 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
191 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
192 /// that the rounding mode of the FPU can change from its default.
193 bool HonorSignDependentRoundingFPMath() {
194 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;