1 //===-- TargetMachine.cpp - General Target Information ---------------------==//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file describes the general parts of a Target machine.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Target/TargetAsmInfo.h"
15 #include "llvm/Target/TargetMachine.h"
16 #include "llvm/Target/TargetOptions.h"
17 #include "llvm/Support/CommandLine.h"
20 //---------------------------------------------------------------------------
21 // Command-line options that tend to be useful on more than one back-end.
25 bool PrintMachineCode;
26 bool NoFramePointerElim;
27 bool NoExcessFPPrecision;
29 bool FiniteOnlyFPMathOption;
32 bool ExceptionHandling;
33 Reloc::Model RelocationModel;
34 CodeModel::Model CMModel;
37 cl::opt<bool, true> PrintCode("print-machineinstrs",
38 cl::desc("Print generated machine code"),
39 cl::location(PrintMachineCode), cl::init(false));
42 DisableFPElim("disable-fp-elim",
43 cl::desc("Disable frame pointer elimination optimization"),
44 cl::location(NoFramePointerElim),
47 DisableExcessPrecision("disable-excess-fp-precision",
48 cl::desc("Disable optimizations that may increase FP precision"),
49 cl::location(NoExcessFPPrecision),
52 EnableUnsafeFPMath("enable-unsafe-fp-math",
53 cl::desc("Enable optimizations that may decrease FP precision"),
54 cl::location(UnsafeFPMath),
57 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
58 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
59 cl::location(FiniteOnlyFPMathOption),
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),
69 GenerateSoftFloatCalls("soft-float",
70 cl::desc("Generate software floating point library calls"),
71 cl::location(UseSoftFloat),
74 DontPlaceZerosInBSS("nozero-initialized-in-bss",
75 cl::desc("Don't place zero-initialized symbols into bss section"),
76 cl::location(NoZerosInBSS),
79 EnableExceptionHandling("enable-eh",
80 cl::desc("Exception handling should be emitted."),
81 cl::location(ExceptionHandling),
84 cl::opt<llvm::Reloc::Model, true>
87 cl::desc("Choose relocation model"),
88 cl::location(RelocationModel),
89 cl::init(Reloc::Default),
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"),
100 cl::opt<llvm::CodeModel::Model, true>
103 cl::desc("Choose code model"),
104 cl::location(CMModel),
105 cl::init(CodeModel::Default),
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"),
120 //---------------------------------------------------------------------------
121 // TargetMachine Class
124 TargetMachine::~TargetMachine() {
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;
134 /// setRelocationModel - Sets the code generation relocation model.
135 void TargetMachine::setRelocationModel(Reloc::Model Model) {
136 RelocationModel = Model;
139 /// getCodeModel - Returns the code model. The choices are small, kernel,
140 /// medium, large, and target default.
141 CodeModel::Model TargetMachine::getCodeModel() {
145 /// setCodeModel - Sets the code model.
146 void TargetMachine::setCodeModel(CodeModel::Model Model) {
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; }
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;