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 UnwindTablesOptional;
35 Reloc::Model RelocationModel;
36 CodeModel::Model CMModel;
37 bool PerformTailCallOpt;
41 cl::opt<bool, true> PrintCode("print-machineinstrs",
42 cl::desc("Print generated machine code"),
43 cl::location(PrintMachineCode), cl::init(false));
46 DisableFPElim("disable-fp-elim",
47 cl::desc("Disable frame pointer elimination optimization"),
48 cl::location(NoFramePointerElim),
51 DisableExcessPrecision("disable-excess-fp-precision",
52 cl::desc("Disable optimizations that may increase FP precision"),
53 cl::location(NoExcessFPPrecision),
56 EnableUnsafeFPMath("enable-unsafe-fp-math",
57 cl::desc("Enable optimizations that may decrease FP precision"),
58 cl::location(UnsafeFPMath),
61 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
62 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
63 cl::location(FiniteOnlyFPMathOption),
66 EnableHonorSignDependentRoundingFPMath(cl::Hidden,
67 "enable-sign-dependent-rounding-fp-math",
68 cl::desc("Force codegen to assume rounding mode can change dynamically"),
69 cl::location(HonorSignDependentRoundingFPMathOption),
73 GenerateSoftFloatCalls("soft-float",
74 cl::desc("Generate software floating point library calls"),
75 cl::location(UseSoftFloat),
78 DontPlaceZerosInBSS("nozero-initialized-in-bss",
79 cl::desc("Don't place zero-initialized symbols into bss section"),
80 cl::location(NoZerosInBSS),
83 EnableExceptionHandling("enable-eh",
84 cl::desc("Emit DWARF exception handling (default if target supports)"),
85 cl::location(ExceptionHandling),
88 DisableUnwindTables("unwind-tables-optional",
89 cl::desc("Generate unwinding tables only for functions that require them"),
90 cl::location(UnwindTablesOptional),
93 cl::opt<llvm::Reloc::Model, true>
96 cl::desc("Choose relocation model"),
97 cl::location(RelocationModel),
98 cl::init(Reloc::Default),
100 clEnumValN(Reloc::Default, "default",
101 " Target default relocation model"),
102 clEnumValN(Reloc::Static, "static",
103 " Non-relocatable code"),
104 clEnumValN(Reloc::PIC_, "pic",
105 " Fully relocatable, position independent code"),
106 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
107 " Relocatable external references, non-relocatable code"),
109 cl::opt<llvm::CodeModel::Model, true>
112 cl::desc("Choose code model"),
113 cl::location(CMModel),
114 cl::init(CodeModel::Default),
116 clEnumValN(CodeModel::Default, "default",
117 " Target default code model"),
118 clEnumValN(CodeModel::Small, "small",
119 " Small code model"),
120 clEnumValN(CodeModel::Kernel, "kernel",
121 " Kernel code model"),
122 clEnumValN(CodeModel::Medium, "medium",
123 " Medium code model"),
124 clEnumValN(CodeModel::Large, "large",
125 " Large code model"),
129 EnablePerformTailCallOpt("tailcallopt",
130 cl::desc("Turn on tail call optimization."),
131 cl::location(PerformTailCallOpt),
134 EnableOptimizeForSize("optimize-size",
135 cl::desc("Optimize for size."),
136 cl::location(OptimizeForSize),
140 //---------------------------------------------------------------------------
141 // TargetMachine Class
144 TargetMachine::~TargetMachine() {
148 /// getRelocationModel - Returns the code generation relocation model. The
149 /// choices are static, PIC, and dynamic-no-pic, and target default.
150 Reloc::Model TargetMachine::getRelocationModel() {
151 return RelocationModel;
154 /// setRelocationModel - Sets the code generation relocation model.
155 void TargetMachine::setRelocationModel(Reloc::Model Model) {
156 RelocationModel = Model;
159 /// getCodeModel - Returns the code model. The choices are small, kernel,
160 /// medium, large, and target default.
161 CodeModel::Model TargetMachine::getCodeModel() {
165 /// setCodeModel - Sets the code model.
166 void TargetMachine::setCodeModel(CodeModel::Model Model) {
171 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
172 /// option is specified on the command line. If this returns false (default),
173 /// the code generator is not allowed to assume that FP arithmetic arguments
174 /// and results are never NaNs or +-Infs.
175 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
177 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
178 /// that the rounding mode of the FPU can change from its default.
179 bool HonorSignDependentRoundingFPMath() {
180 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;