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