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;
44 static cl::opt<bool, true> PrintCode("print-machineinstrs",
45 cl::desc("Print generated machine code"),
46 cl::location(PrintMachineCode), cl::init(false));
48 static cl::opt<bool, true>
49 DisableFPElim("disable-fp-elim",
50 cl::desc("Disable frame pointer elimination optimization"),
51 cl::location(NoFramePointerElim),
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),
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),
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),
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),
75 static cl::opt<bool, true>
76 GenerateSoftFloatCalls("soft-float",
77 cl::desc("Generate software floating point library calls"),
78 cl::location(UseSoftFloat),
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),
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),
90 static cl::opt<bool, true>
91 EnableUnwindTables("unwind-tables",
92 cl::desc("Generate unwinding tables for all functions"),
93 cl::location(UnwindTablesMandatory),
96 static cl::opt<llvm::Reloc::Model, true>
99 cl::desc("Choose relocation model"),
100 cl::location(RelocationModel),
101 cl::init(Reloc::Default),
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"),
112 static cl::opt<llvm::CodeModel::Model, true>
115 cl::desc("Choose code model"),
116 cl::location(CMModel),
117 cl::init(CodeModel::Default),
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"),
131 static cl::opt<bool, true>
132 EnablePerformTailCallOpt("tailcallopt",
133 cl::desc("Turn on tail call optimization."),
134 cl::location(PerformTailCallOpt),
136 static cl::opt<bool, true>
137 EnableOptimizeForSize("optimize-size",
138 cl::desc("Optimize for size."),
139 cl::location(OptimizeForSize),
142 static cl::opt<unsigned, true>
143 OverrideStackAlignment("stack-alignment",
144 cl::desc("Override default stack alignment"),
145 cl::location(StackAlignment),
148 static cl::opt<bool, true>
149 EnableRealignStack("realign-stack",
150 cl::desc("Realign stack if needed"),
151 cl::location(RealignStack),
154 static cl::opt<bool, true>
155 AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
156 cl::location(VerboseAsm),
160 //---------------------------------------------------------------------------
161 // TargetMachine Class
164 TargetMachine::~TargetMachine() {
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;
174 /// setRelocationModel - Sets the code generation relocation model.
175 void TargetMachine::setRelocationModel(Reloc::Model Model) {
176 RelocationModel = Model;
179 /// getCodeModel - Returns the code model. The choices are small, kernel,
180 /// medium, large, and target default.
181 CodeModel::Model TargetMachine::getCodeModel() {
185 /// setCodeModel - Sets the code model.
186 void TargetMachine::setCodeModel(CodeModel::Model Model) {
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; }
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;