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 Reloc::Model RelocationModel;
35 CodeModel::Model CMModel;
36 bool PerformTailCallOpt;
39 cl::opt<bool, true> PrintCode("print-machineinstrs",
40 cl::desc("Print generated machine code"),
41 cl::location(PrintMachineCode), cl::init(false));
44 DisableFPElim("disable-fp-elim",
45 cl::desc("Disable frame pointer elimination optimization"),
46 cl::location(NoFramePointerElim),
49 DisableExcessPrecision("disable-excess-fp-precision",
50 cl::desc("Disable optimizations that may increase FP precision"),
51 cl::location(NoExcessFPPrecision),
54 EnableUnsafeFPMath("enable-unsafe-fp-math",
55 cl::desc("Enable optimizations that may decrease FP precision"),
56 cl::location(UnsafeFPMath),
59 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
60 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
61 cl::location(FiniteOnlyFPMathOption),
64 EnableHonorSignDependentRoundingFPMath(cl::Hidden,
65 "enable-sign-dependent-rounding-fp-math",
66 cl::desc("Force codegen to assume rounding mode can change dynamically"),
67 cl::location(HonorSignDependentRoundingFPMathOption),
71 GenerateSoftFloatCalls("soft-float",
72 cl::desc("Generate software floating point library calls"),
73 cl::location(UseSoftFloat),
76 DontPlaceZerosInBSS("nozero-initialized-in-bss",
77 cl::desc("Don't place zero-initialized symbols into bss section"),
78 cl::location(NoZerosInBSS),
81 EnableExceptionHandling("enable-eh",
82 cl::desc("Exception handling should be emitted."),
83 cl::location(ExceptionHandling),
86 cl::opt<llvm::Reloc::Model, true>
89 cl::desc("Choose relocation model"),
90 cl::location(RelocationModel),
91 cl::init(Reloc::Default),
93 clEnumValN(Reloc::Default, "default",
94 " Target default relocation model"),
95 clEnumValN(Reloc::Static, "static",
96 " Non-relocatable code"),
97 clEnumValN(Reloc::PIC_, "pic",
98 " Fully relocatable, position independent code"),
99 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
100 " Relocatable external references, non-relocatable code"),
102 cl::opt<llvm::CodeModel::Model, true>
105 cl::desc("Choose code model"),
106 cl::location(CMModel),
107 cl::init(CodeModel::Default),
109 clEnumValN(CodeModel::Default, "default",
110 " Target default code model"),
111 clEnumValN(CodeModel::Small, "small",
112 " Small code model"),
113 clEnumValN(CodeModel::Kernel, "kernel",
114 " Kernel code model"),
115 clEnumValN(CodeModel::Medium, "medium",
116 " Medium code model"),
117 clEnumValN(CodeModel::Large, "large",
118 " Large code model"),
122 EnablePerformTailCallOpt("tailcallopt",
123 cl::desc("Turn on tail call optimization."),
124 cl::location(PerformTailCallOpt),
128 //---------------------------------------------------------------------------
129 // TargetMachine Class
132 TargetMachine::~TargetMachine() {
136 /// getRelocationModel - Returns the code generation relocation model. The
137 /// choices are static, PIC, and dynamic-no-pic, and target default.
138 Reloc::Model TargetMachine::getRelocationModel() {
139 return RelocationModel;
142 /// setRelocationModel - Sets the code generation relocation model.
143 void TargetMachine::setRelocationModel(Reloc::Model Model) {
144 RelocationModel = Model;
147 /// getCodeModel - Returns the code model. The choices are small, kernel,
148 /// medium, large, and target default.
149 CodeModel::Model TargetMachine::getCodeModel() {
153 /// setCodeModel - Sets the code model.
154 void TargetMachine::setCodeModel(CodeModel::Model Model) {
159 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
160 /// option is specified on the command line. If this returns false (default),
161 /// the code generator is not allowed to assume that FP arithmetic arguments
162 /// and results are never NaNs or +-Infs.
163 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
165 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
166 /// that the rounding mode of the FPU can change from its default.
167 bool HonorSignDependentRoundingFPMath() {
168 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;