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;
39 unsigned StackAlignment;
42 bool DisableJumpTables;
45 static cl::opt<bool, true> PrintCode("print-machineinstrs",
46 cl::desc("Print generated machine code"),
47 cl::location(PrintMachineCode), cl::init(false));
49 static cl::opt<bool, true>
50 DisableFPElim("disable-fp-elim",
51 cl::desc("Disable frame pointer elimination optimization"),
52 cl::location(NoFramePointerElim),
54 static cl::opt<bool, true>
55 DisableExcessPrecision("disable-excess-fp-precision",
56 cl::desc("Disable optimizations that may increase FP precision"),
57 cl::location(NoExcessFPPrecision),
59 static cl::opt<bool, true>
60 EnableUnsafeFPMath("enable-unsafe-fp-math",
61 cl::desc("Enable optimizations that may decrease FP precision"),
62 cl::location(UnsafeFPMath),
64 static cl::opt<bool, true>
65 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
66 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
67 cl::location(FiniteOnlyFPMathOption),
69 static cl::opt<bool, true>
70 EnableHonorSignDependentRoundingFPMath(cl::Hidden,
71 "enable-sign-dependent-rounding-fp-math",
72 cl::desc("Force codegen to assume rounding mode can change dynamically"),
73 cl::location(HonorSignDependentRoundingFPMathOption),
76 static cl::opt<bool, true>
77 GenerateSoftFloatCalls("soft-float",
78 cl::desc("Generate software floating point library calls"),
79 cl::location(UseSoftFloat),
81 static cl::opt<bool, true>
82 DontPlaceZerosInBSS("nozero-initialized-in-bss",
83 cl::desc("Don't place zero-initialized symbols into bss section"),
84 cl::location(NoZerosInBSS),
86 static cl::opt<bool, true>
87 EnableExceptionHandling("enable-eh",
88 cl::desc("Emit DWARF exception handling (default if target supports)"),
89 cl::location(ExceptionHandling),
91 static cl::opt<bool, true>
92 EnableUnwindTables("unwind-tables",
93 cl::desc("Generate unwinding tables for all functions"),
94 cl::location(UnwindTablesMandatory),
97 static cl::opt<llvm::Reloc::Model, true>
100 cl::desc("Choose relocation model"),
101 cl::location(RelocationModel),
102 cl::init(Reloc::Default),
104 clEnumValN(Reloc::Default, "default",
105 " Target default relocation model"),
106 clEnumValN(Reloc::Static, "static",
107 " Non-relocatable code"),
108 clEnumValN(Reloc::PIC_, "pic",
109 " Fully relocatable, position independent code"),
110 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
111 " Relocatable external references, non-relocatable code"),
113 static cl::opt<llvm::CodeModel::Model, true>
116 cl::desc("Choose code model"),
117 cl::location(CMModel),
118 cl::init(CodeModel::Default),
120 clEnumValN(CodeModel::Default, "default",
121 " Target default code model"),
122 clEnumValN(CodeModel::Small, "small",
123 " Small code model"),
124 clEnumValN(CodeModel::Kernel, "kernel",
125 " Kernel code model"),
126 clEnumValN(CodeModel::Medium, "medium",
127 " Medium code model"),
128 clEnumValN(CodeModel::Large, "large",
129 " Large code model"),
132 static cl::opt<bool, true>
133 EnablePerformTailCallOpt("tailcallopt",
134 cl::desc("Turn on tail call optimization."),
135 cl::location(PerformTailCallOpt),
137 static cl::opt<bool, true>
138 EnableOptimizeForSize("optimize-size",
139 cl::desc("Optimize for size."),
140 cl::location(OptimizeForSize),
143 static cl::opt<unsigned, true>
144 OverrideStackAlignment("stack-alignment",
145 cl::desc("Override default stack alignment"),
146 cl::location(StackAlignment),
149 static cl::opt<bool, true>
150 EnableRealignStack("realign-stack",
151 cl::desc("Realign stack if needed"),
152 cl::location(RealignStack),
155 static cl::opt<bool, true>
156 AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
157 cl::location(VerboseAsm),
160 static cl::opt<bool, true>
161 DisableSwitchTables(cl::Hidden, "disable-jump-tables",
162 cl::desc("Do not generate jump tables."),
163 cl::location(DisableJumpTables),
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) {
197 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
198 /// option is specified on the command line. If this returns false (default),
199 /// the code generator is not allowed to assume that FP arithmetic arguments
200 /// and results are never NaNs or +-Infs.
201 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
203 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
204 /// that the rounding mode of the FPU can change from its default.
205 bool HonorSignDependentRoundingFPMath() {
206 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;