New temporary option -new-cc-modeling-scheme to test the new cc modeling scheme.
[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 HonorSignDependentRoundingFPMathOption;
31   bool UseSoftFloat;
32   bool NoZerosInBSS;
33   bool ExceptionHandling;
34   bool NewCCModeling;
35   Reloc::Model RelocationModel;
36   CodeModel::Model CMModel;
37 }
38 namespace {
39   cl::opt<bool, true> PrintCode("print-machineinstrs",
40     cl::desc("Print generated machine code"),
41     cl::location(PrintMachineCode), cl::init(false));
42
43   cl::opt<bool, true>
44     DisableFPElim("disable-fp-elim",
45                   cl::desc("Disable frame pointer elimination optimization"),
46                   cl::location(NoFramePointerElim),
47                   cl::init(false));
48   cl::opt<bool, true>
49   DisableExcessPrecision("disable-excess-fp-precision",
50                cl::desc("Disable optimizations that may increase FP precision"),
51                cl::location(NoExcessFPPrecision),
52                cl::init(false));
53   cl::opt<bool, true>
54   EnableUnsafeFPMath("enable-unsafe-fp-math",
55                cl::desc("Enable optimizations that may decrease FP precision"),
56                cl::location(UnsafeFPMath),
57                cl::init(false));
58   cl::opt<bool, true>
59   EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
60                cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
61                cl::location(FiniteOnlyFPMathOption),
62                cl::init(false));
63   cl::opt<bool, true>
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),
68                cl::init(false));
69
70   cl::opt<bool, true>
71   GenerateSoftFloatCalls("soft-float",
72                cl::desc("Generate software floating point library calls"),
73                cl::location(UseSoftFloat),
74                cl::init(false));
75   cl::opt<bool, true>
76   DontPlaceZerosInBSS("nozero-initialized-in-bss",
77               cl::desc("Don't place zero-initialized symbols into bss section"),
78               cl::location(NoZerosInBSS),
79               cl::init(false));
80   cl::opt<bool, true>
81   EnableExceptionHandling("enable-eh",
82                cl::desc("Exception handling should be emitted."),
83                cl::location(ExceptionHandling),
84                cl::init(false));
85
86   cl::opt<llvm::Reloc::Model, true>
87   DefRelocationModel(
88     "relocation-model",
89     cl::desc("Choose relocation model"),
90     cl::location(RelocationModel),
91     cl::init(Reloc::Default),
92     cl::values(
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"),
101       clEnumValEnd));
102   cl::opt<llvm::CodeModel::Model, true>
103   DefCodeModel(
104     "code-model",
105     cl::desc("Choose code model"),
106     cl::location(CMModel),
107     cl::init(CodeModel::Default),
108     cl::values(
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"),
119       clEnumValEnd));
120   cl::opt<bool, true>
121   EnableNewCCModeling("new-cc-modeling-scheme",
122                       cl::desc("New CC modeling scheme."),
123                       cl::location(NewCCModeling),
124                       cl::init(false));
125 }
126
127 //---------------------------------------------------------------------------
128 // TargetMachine Class
129 //
130
131 TargetMachine::~TargetMachine() {
132   delete AsmInfo;
133 }
134
135 /// getRelocationModel - Returns the code generation relocation model. The
136 /// choices are static, PIC, and dynamic-no-pic, and target default.
137 Reloc::Model TargetMachine::getRelocationModel() {
138   return RelocationModel;
139 }
140
141 /// setRelocationModel - Sets the code generation relocation model.
142 void TargetMachine::setRelocationModel(Reloc::Model Model) {
143   RelocationModel = Model;
144 }
145
146 /// getCodeModel - Returns the code model. The choices are small, kernel,
147 /// medium, large, and target default.
148 CodeModel::Model TargetMachine::getCodeModel() {
149   return CMModel;
150 }
151
152 /// setCodeModel - Sets the code model.
153 void TargetMachine::setCodeModel(CodeModel::Model Model) {
154   CMModel = Model;
155 }
156
157 namespace llvm {
158   /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
159   /// option is specified on the command line. If this returns false (default),
160   /// the code generator is not allowed to assume that FP arithmetic arguments
161   /// and results are never NaNs or +-Infs.
162   bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
163   
164   /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
165   /// that the rounding mode of the FPU can change from its default.
166   bool HonorSignDependentRoundingFPMath() {
167     return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
168   }
169 }
170