* Fix one more bug in PIC codegen: extra load is needed for *all*
[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   Reloc::Model RelocationModel;
33   CodeModel::Model CMModel;
34 }
35 namespace {
36   cl::opt<bool, true> PrintCode("print-machineinstrs",
37     cl::desc("Print generated machine code"),
38     cl::location(PrintMachineCode), cl::init(false));
39
40   cl::opt<bool, true>
41     DisableFPElim("disable-fp-elim",
42                   cl::desc("Disable frame pointer elimination optimization"),
43                   cl::location(NoFramePointerElim),
44                   cl::init(false));
45   cl::opt<bool, true>
46   DisableExcessPrecision("disable-excess-fp-precision",
47                cl::desc("Disable optimizations that may increase FP precision"),
48                cl::location(NoExcessFPPrecision),
49                cl::init(false));
50   cl::opt<bool, true>
51   EnableUnsafeFPMath("enable-unsafe-fp-math",
52                cl::desc("Enable optimizations that may decrease FP precision"),
53                cl::location(UnsafeFPMath),
54                cl::init(false));
55   cl::opt<bool, true>
56   EnableFiniteOnltFPMath("enable-finite-only-fp-math",
57                cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
58                cl::location(FiniteOnlyFPMathOption),
59                cl::init(false));
60   cl::opt<bool, true>
61   GenerateSoftFloatCalls("soft-float",
62                cl::desc("Generate software floating point library calls"),
63                cl::location(UseSoftFloat),
64                cl::init(false));
65   cl::opt<bool, true>
66   DontPlaceZerosInBSS("nozero-initialized-in-bss",
67                cl::desc("Don't place zero-initialized symbols into bss section"),
68                cl::location(NoZerosInBSS),
69                cl::init(false));
70
71   cl::opt<llvm::Reloc::Model, true>
72   DefRelocationModel(
73     "relocation-model",
74     cl::desc("Choose relocation model"),
75     cl::location(RelocationModel),
76     cl::init(Reloc::Default),
77     cl::values(
78       clEnumValN(Reloc::Default, "default",
79                  "  Target default relocation model"),
80       clEnumValN(Reloc::Static, "static",
81                  "  Non-relocatable code"),
82       clEnumValN(Reloc::PIC_, "pic",
83                  "  Fully relocatable, position independent code"),
84       clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
85                  "  Relocatable external references, non-relocatable code"),
86       clEnumValEnd));
87   cl::opt<llvm::CodeModel::Model, true>
88   DefCodeModel(
89     "code-model",
90     cl::desc("Choose relocation model"),
91     cl::location(CMModel),
92     cl::init(CodeModel::Default),
93     cl::values(
94       clEnumValN(CodeModel::Default, "default",
95                  "  Target default code model"),
96       clEnumValN(CodeModel::Small, "small",
97                  "  Small code model"),
98       clEnumValN(CodeModel::Kernel, "kernel",
99                  "  Kernel code model"),
100       clEnumValN(CodeModel::Medium, "medium",
101                  "  Medium code model"),
102       clEnumValN(CodeModel::Large, "large",
103                  "  Large code model"),
104       clEnumValEnd));
105 }
106
107 //---------------------------------------------------------------------------
108 // TargetMachine Class
109 //
110
111 TargetMachine::~TargetMachine() {
112   delete AsmInfo;
113 }
114
115 /// getRelocationModel - Returns the code generation relocation model. The
116 /// choices are static, PIC, and dynamic-no-pic, and target default.
117 Reloc::Model TargetMachine::getRelocationModel() {
118   return RelocationModel;
119 }
120
121 /// setRelocationModel - Sets the code generation relocation model.
122 void TargetMachine::setRelocationModel(Reloc::Model Model) {
123   RelocationModel = Model;
124 }
125
126 /// getCodeModel - Returns the code model. The choices are small, kernel,
127 /// medium, large, and target default.
128 CodeModel::Model TargetMachine::getCodeModel() {
129   return CMModel;
130 }
131
132 /// setCodeModel - Sets the code model.
133 void TargetMachine::setCodeModel(CodeModel::Model Model) {
134   CMModel = Model;
135 }
136
137 namespace llvm {
138   /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
139   /// option is specified on the command line. If this returns false (default),
140   /// the code generator is not allowed to assume that FP arithmetic arguments
141   /// and results are never NaNs or +-Infs.
142   bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
143 }
144