blob: b9a68789ab59755e0b06fc8569570bbf86685851 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- TargetMachine.cpp - General Target Information ---------------------==//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the general parts of a Target machine.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Target/TargetAsmInfo.h"
15#include "llvm/Target/TargetMachine.h"
16#include "llvm/Target/TargetOptions.h"
17#include "llvm/Support/CommandLine.h"
18using namespace llvm;
19
20//---------------------------------------------------------------------------
21// Command-line options that tend to be useful on more than one back-end.
22//
23
24namespace llvm {
25 bool PrintMachineCode;
26 bool NoFramePointerElim;
27 bool NoExcessFPPrecision;
28 bool UnsafeFPMath;
29 bool FiniteOnlyFPMathOption;
30 bool HonorSignDependentRoundingFPMathOption;
31 bool UseSoftFloat;
32 bool NoZerosInBSS;
33 bool ExceptionHandling;
34 Reloc::Model RelocationModel;
35 CodeModel::Model CMModel;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +000036 bool PerformTailCallOpt;
Devang Patela2101692008-03-25 21:02:35 +000037 bool OptimizeForSize;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000038}
39namespace {
40 cl::opt<bool, true> PrintCode("print-machineinstrs",
41 cl::desc("Print generated machine code"),
42 cl::location(PrintMachineCode), cl::init(false));
43
44 cl::opt<bool, true>
45 DisableFPElim("disable-fp-elim",
46 cl::desc("Disable frame pointer elimination optimization"),
47 cl::location(NoFramePointerElim),
48 cl::init(false));
49 cl::opt<bool, true>
50 DisableExcessPrecision("disable-excess-fp-precision",
51 cl::desc("Disable optimizations that may increase FP precision"),
52 cl::location(NoExcessFPPrecision),
53 cl::init(false));
54 cl::opt<bool, true>
55 EnableUnsafeFPMath("enable-unsafe-fp-math",
56 cl::desc("Enable optimizations that may decrease FP precision"),
57 cl::location(UnsafeFPMath),
58 cl::init(false));
59 cl::opt<bool, true>
60 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
61 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
62 cl::location(FiniteOnlyFPMathOption),
63 cl::init(false));
64 cl::opt<bool, true>
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),
69 cl::init(false));
70
71 cl::opt<bool, true>
72 GenerateSoftFloatCalls("soft-float",
73 cl::desc("Generate software floating point library calls"),
74 cl::location(UseSoftFloat),
75 cl::init(false));
76 cl::opt<bool, true>
77 DontPlaceZerosInBSS("nozero-initialized-in-bss",
78 cl::desc("Don't place zero-initialized symbols into bss section"),
79 cl::location(NoZerosInBSS),
80 cl::init(false));
81 cl::opt<bool, true>
82 EnableExceptionHandling("enable-eh",
83 cl::desc("Exception handling should be emitted."),
84 cl::location(ExceptionHandling),
85 cl::init(false));
86
87 cl::opt<llvm::Reloc::Model, true>
88 DefRelocationModel(
89 "relocation-model",
90 cl::desc("Choose relocation model"),
91 cl::location(RelocationModel),
92 cl::init(Reloc::Default),
93 cl::values(
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"),
102 clEnumValEnd));
103 cl::opt<llvm::CodeModel::Model, true>
104 DefCodeModel(
105 "code-model",
106 cl::desc("Choose code model"),
107 cl::location(CMModel),
108 cl::init(CodeModel::Default),
109 cl::values(
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"),
120 clEnumValEnd));
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000121
122 cl::opt<bool, true>
123 EnablePerformTailCallOpt("tailcallopt",
124 cl::desc("Turn on tail call optimization."),
125 cl::location(PerformTailCallOpt),
126 cl::init(false));
Devang Patela2101692008-03-25 21:02:35 +0000127 cl::opt<bool, true>
128 EnableOptimizeForSize("optimizeforsize",
129 cl::desc("Optimize for size."),
130 cl::location(OptimizeForSize),
131 cl::init(false));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000132}
133
134//---------------------------------------------------------------------------
135// TargetMachine Class
136//
137
138TargetMachine::~TargetMachine() {
139 delete AsmInfo;
140}
141
142/// getRelocationModel - Returns the code generation relocation model. The
143/// choices are static, PIC, and dynamic-no-pic, and target default.
144Reloc::Model TargetMachine::getRelocationModel() {
145 return RelocationModel;
146}
147
148/// setRelocationModel - Sets the code generation relocation model.
149void TargetMachine::setRelocationModel(Reloc::Model Model) {
150 RelocationModel = Model;
151}
152
153/// getCodeModel - Returns the code model. The choices are small, kernel,
154/// medium, large, and target default.
155CodeModel::Model TargetMachine::getCodeModel() {
156 return CMModel;
157}
158
159/// setCodeModel - Sets the code model.
160void TargetMachine::setCodeModel(CodeModel::Model Model) {
161 CMModel = Model;
162}
163
164namespace llvm {
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; }
170
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;
175 }
176}
177