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