Add a new option.
[oota-llvm.git] / lib / Target / TargetMachine.cpp
1 //===-- TargetMachine.cpp - General Target Information ---------------------==//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
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"
18 using namespace llvm;
19
20 //---------------------------------------------------------------------------
21 // Command-line options that tend to be useful on more than one back-end.
22 //
23
24 namespace llvm {
25   bool PrintMachineCode;
26   bool NoFramePointerElim;
27   bool NoExcessFPPrecision;
28   bool UnsafeFPMath;
29   bool FiniteOnlyFPMathOption;
30   bool UseSoftFloat;
31   bool NoZerosInBSS;
32   bool ExceptionHandling;
33   Reloc::Model RelocationModel;
34   CodeModel::Model CMModel;
35 }
36 namespace {
37   cl::opt<bool, true> PrintCode("print-machineinstrs",
38     cl::desc("Print generated machine code"),
39     cl::location(PrintMachineCode), cl::init(false));
40
41   cl::opt<bool, true>
42     DisableFPElim("disable-fp-elim",
43                   cl::desc("Disable frame pointer elimination optimization"),
44                   cl::location(NoFramePointerElim),
45                   cl::init(false));
46   cl::opt<bool, true>
47   DisableExcessPrecision("disable-excess-fp-precision",
48                cl::desc("Disable optimizations that may increase FP precision"),
49                cl::location(NoExcessFPPrecision),
50                cl::init(false));
51   cl::opt<bool, true>
52   EnableUnsafeFPMath("enable-unsafe-fp-math",
53                cl::desc("Enable optimizations that may decrease FP precision"),
54                cl::location(UnsafeFPMath),
55                cl::init(false));
56   cl::opt<bool, true>
57   EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
58                cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
59                cl::location(FiniteOnlyFPMathOption),
60                cl::init(false));
61   cl::opt<bool, true>
62   EnableHonorSignDependentRoundingFPMath(cl::Hidden,
63                "enable-sign-dependent-rounding-fp-math",
64        cl::desc("Force codegen to assume rounding mode can change dynamically"),
65                cl::location(HonorSignDependentRoundingFPMathOption),
66                cl::init(false));
67
68   cl::opt<bool, true>
69   GenerateSoftFloatCalls("soft-float",
70                cl::desc("Generate software floating point library calls"),
71                cl::location(UseSoftFloat),
72                cl::init(false));
73   cl::opt<bool, true>
74   DontPlaceZerosInBSS("nozero-initialized-in-bss",
75               cl::desc("Don't place zero-initialized symbols into bss section"),
76               cl::location(NoZerosInBSS),
77               cl::init(false));
78   cl::opt<bool, true>
79   EnableExceptionHandling("enable-eh",
80                cl::desc("Exception handling should be emitted."),
81                cl::location(ExceptionHandling),
82                cl::init(false));
83
84   cl::opt<llvm::Reloc::Model, true>
85   DefRelocationModel(
86     "relocation-model",
87     cl::desc("Choose relocation model"),
88     cl::location(RelocationModel),
89     cl::init(Reloc::Default),
90     cl::values(
91       clEnumValN(Reloc::Default, "default",
92                  "  Target default relocation model"),
93       clEnumValN(Reloc::Static, "static",
94                  "  Non-relocatable code"),
95       clEnumValN(Reloc::PIC_, "pic",
96                  "  Fully relocatable, position independent code"),
97       clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
98                  "  Relocatable external references, non-relocatable code"),
99       clEnumValEnd));
100   cl::opt<llvm::CodeModel::Model, true>
101   DefCodeModel(
102     "code-model",
103     cl::desc("Choose code model"),
104     cl::location(CMModel),
105     cl::init(CodeModel::Default),
106     cl::values(
107       clEnumValN(CodeModel::Default, "default",
108                  "  Target default code model"),
109       clEnumValN(CodeModel::Small, "small",
110                  "  Small code model"),
111       clEnumValN(CodeModel::Kernel, "kernel",
112                  "  Kernel code model"),
113       clEnumValN(CodeModel::Medium, "medium",
114                  "  Medium code model"),
115       clEnumValN(CodeModel::Large, "large",
116                  "  Large code model"),
117       clEnumValEnd));
118 }
119
120 //---------------------------------------------------------------------------
121 // TargetMachine Class
122 //
123
124 TargetMachine::~TargetMachine() {
125   delete AsmInfo;
126 }
127
128 /// getRelocationModel - Returns the code generation relocation model. The
129 /// choices are static, PIC, and dynamic-no-pic, and target default.
130 Reloc::Model TargetMachine::getRelocationModel() {
131   return RelocationModel;
132 }
133
134 /// setRelocationModel - Sets the code generation relocation model.
135 void TargetMachine::setRelocationModel(Reloc::Model Model) {
136   RelocationModel = Model;
137 }
138
139 /// getCodeModel - Returns the code model. The choices are small, kernel,
140 /// medium, large, and target default.
141 CodeModel::Model TargetMachine::getCodeModel() {
142   return CMModel;
143 }
144
145 /// setCodeModel - Sets the code model.
146 void TargetMachine::setCodeModel(CodeModel::Model Model) {
147   CMModel = Model;
148 }
149
150 namespace llvm {
151   /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
152   /// option is specified on the command line. If this returns false (default),
153   /// the code generator is not allowed to assume that FP arithmetic arguments
154   /// and results are never NaNs or +-Infs.
155   bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
156   
157   /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
158   /// that the rounding mode of the FPU can change from its default.
159   bool HonorSignDependentRoundingFPMath() {
160     return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
161   }
162 }
163