blob: 6f2f1235d7a6665cd077241c5a668ea622f17fe9 [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;
Dale Johannesena9b3e482008-04-08 00:10:24 +000034 bool UnwindTablesOptional;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000035 Reloc::Model RelocationModel;
36 CodeModel::Model CMModel;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +000037 bool PerformTailCallOpt;
Devang Patela2101692008-03-25 21:02:35 +000038 bool OptimizeForSize;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039}
40namespace {
41 cl::opt<bool, true> PrintCode("print-machineinstrs",
42 cl::desc("Print generated machine code"),
43 cl::location(PrintMachineCode), cl::init(false));
44
45 cl::opt<bool, true>
46 DisableFPElim("disable-fp-elim",
47 cl::desc("Disable frame pointer elimination optimization"),
48 cl::location(NoFramePointerElim),
49 cl::init(false));
50 cl::opt<bool, true>
51 DisableExcessPrecision("disable-excess-fp-precision",
52 cl::desc("Disable optimizations that may increase FP precision"),
53 cl::location(NoExcessFPPrecision),
54 cl::init(false));
55 cl::opt<bool, true>
56 EnableUnsafeFPMath("enable-unsafe-fp-math",
57 cl::desc("Enable optimizations that may decrease FP precision"),
58 cl::location(UnsafeFPMath),
59 cl::init(false));
60 cl::opt<bool, true>
61 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
62 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
63 cl::location(FiniteOnlyFPMathOption),
64 cl::init(false));
65 cl::opt<bool, true>
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),
70 cl::init(false));
71
72 cl::opt<bool, true>
73 GenerateSoftFloatCalls("soft-float",
74 cl::desc("Generate software floating point library calls"),
75 cl::location(UseSoftFloat),
76 cl::init(false));
77 cl::opt<bool, true>
78 DontPlaceZerosInBSS("nozero-initialized-in-bss",
79 cl::desc("Don't place zero-initialized symbols into bss section"),
80 cl::location(NoZerosInBSS),
81 cl::init(false));
82 cl::opt<bool, true>
83 EnableExceptionHandling("enable-eh",
Dale Johannesena9b3e482008-04-08 00:10:24 +000084 cl::desc("Emit DWARF exception handling (default if target supports)"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000085 cl::location(ExceptionHandling),
86 cl::init(false));
Dale Johannesena9b3e482008-04-08 00:10:24 +000087 cl::opt<bool, true>
Dale Johannesenbfdf0412008-04-08 18:07:49 +000088 DisableUnwindTables("unwind-tables-optional",
89 cl::desc("Generate unwinding tables only for functions that require them"),
Dale Johannesena9b3e482008-04-08 00:10:24 +000090 cl::location(UnwindTablesOptional),
91 cl::init(false));
Dan Gohmanf17a25c2007-07-18 16:29:46 +000092
93 cl::opt<llvm::Reloc::Model, true>
94 DefRelocationModel(
95 "relocation-model",
96 cl::desc("Choose relocation model"),
97 cl::location(RelocationModel),
98 cl::init(Reloc::Default),
99 cl::values(
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"),
108 clEnumValEnd));
109 cl::opt<llvm::CodeModel::Model, true>
110 DefCodeModel(
111 "code-model",
112 cl::desc("Choose code model"),
113 cl::location(CMModel),
114 cl::init(CodeModel::Default),
115 cl::values(
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"),
126 clEnumValEnd));
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000127
128 cl::opt<bool, true>
129 EnablePerformTailCallOpt("tailcallopt",
130 cl::desc("Turn on tail call optimization."),
131 cl::location(PerformTailCallOpt),
132 cl::init(false));
Devang Patela2101692008-03-25 21:02:35 +0000133 cl::opt<bool, true>
Evan Cheng295cc162008-03-25 22:28:39 +0000134 EnableOptimizeForSize("optimize-size",
Devang Patela2101692008-03-25 21:02:35 +0000135 cl::desc("Optimize for size."),
136 cl::location(OptimizeForSize),
137 cl::init(false));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000138}
139
140//---------------------------------------------------------------------------
141// TargetMachine Class
142//
143
144TargetMachine::~TargetMachine() {
145 delete AsmInfo;
146}
147
148/// getRelocationModel - Returns the code generation relocation model. The
149/// choices are static, PIC, and dynamic-no-pic, and target default.
150Reloc::Model TargetMachine::getRelocationModel() {
151 return RelocationModel;
152}
153
154/// setRelocationModel - Sets the code generation relocation model.
155void TargetMachine::setRelocationModel(Reloc::Model Model) {
156 RelocationModel = Model;
157}
158
159/// getCodeModel - Returns the code model. The choices are small, kernel,
160/// medium, large, and target default.
161CodeModel::Model TargetMachine::getCodeModel() {
162 return CMModel;
163}
164
165/// setCodeModel - Sets the code model.
166void TargetMachine::setCodeModel(CodeModel::Model Model) {
167 CMModel = Model;
168}
169
170namespace llvm {
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; }
176
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;
181 }
182}
183