Create/store/and delete the TargetObjInfo object.
[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/TargetObjInfo.h"
17 #include "llvm/Target/TargetOptions.h"
18 #include "llvm/Support/CommandLine.h"
19 using namespace llvm;
20
21 //---------------------------------------------------------------------------
22 // Command-line options that tend to be useful on more than one back-end.
23 //
24
25 namespace llvm {
26   bool PrintMachineCode;
27   bool NoFramePointerElim;
28   bool NoExcessFPPrecision;
29   bool UnsafeFPMath;
30   bool FiniteOnlyFPMathOption;
31   bool UseSoftFloat;
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
66   cl::opt<llvm::Reloc::Model, true>
67   DefRelocationModel(
68     "relocation-model",
69     cl::desc("Choose relocation model"),
70     cl::location(RelocationModel),
71     cl::init(Reloc::Default),
72     cl::values(
73       clEnumValN(Reloc::Default, "default",
74                  "  Target default relocation model"),
75       clEnumValN(Reloc::Static, "static",
76                  "  Non-relocatable code"),
77       clEnumValN(Reloc::PIC_, "pic",
78                  "  Fully relocatable, position independent code"),
79       clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
80                  "  Relocatable external references, non-relocatable code"),
81       clEnumValEnd));
82   cl::opt<llvm::CodeModel::Model, true>
83   DefCodeModel(
84     "code-model",
85     cl::desc("Choose relocation model"),
86     cl::location(CMModel),
87     cl::init(CodeModel::Default),
88     cl::values(
89       clEnumValN(CodeModel::Default, "default",
90                  "  Target default code model"),
91       clEnumValN(CodeModel::Small, "small",
92                  "  Small code model"),
93       clEnumValN(CodeModel::Kernel, "kernel",
94                  "  Kernel code model"),
95       clEnumValN(CodeModel::Medium, "medium",
96                  "  Medium code model"),
97       clEnumValN(CodeModel::Large, "large",
98                  "  Large code model"),
99       clEnumValEnd));
100 }
101
102 //---------------------------------------------------------------------------
103 // TargetMachine Class
104 //
105
106 TargetMachine::~TargetMachine() {
107   delete AsmInfo;
108   delete ObjInfo;
109 }
110
111 /// getRelocationModel - Returns the code generation relocation model. The
112 /// choices are static, PIC, and dynamic-no-pic, and target default.
113 Reloc::Model TargetMachine::getRelocationModel() {
114   return RelocationModel;
115 }
116
117 /// setRelocationModel - Sets the code generation relocation model.
118 void TargetMachine::setRelocationModel(Reloc::Model Model) {
119   RelocationModel = Model;
120 }
121
122 /// getCodeModel - Returns the code model. The choices are small, kernel,
123 /// medium, large, and target default.
124 CodeModel::Model TargetMachine::getCodeModel() {
125   return CMModel;
126 }
127
128 /// setCodeModel - Sets the code model.
129 void TargetMachine::setCodeModel(CodeModel::Model Model) {
130   CMModel = Model;
131 }
132
133 namespace llvm {
134   /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
135   /// option is specified on the command line. If this returns false (default),
136   /// the code generator is not allowed to assume that FP arithmetic arguments
137   /// and results are never NaNs or +-Infs.
138   bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
139 }
140