1 //===-- TargetMachine.cpp - General Target Information ---------------------==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the general parts of a Target machine.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/MachineFunction.h"
15 #include "llvm/CodeGen/MachineFrameInfo.h"
16 #include "llvm/MC/MCAsmInfo.h"
17 #include "llvm/Target/TargetMachine.h"
18 #include "llvm/Target/TargetOptions.h"
19 #include "llvm/Support/CommandLine.h"
22 //---------------------------------------------------------------------------
23 // Command-line options that tend to be useful on more than one back-end.
28 bool HasDivModLibcall;
29 bool AsmVerbosityDefault(false);
33 DataSections("fdata-sections",
34 cl::desc("Emit data into separate sections"),
37 FunctionSections("ffunction-sections",
38 cl::desc("Emit functions into separate sections"),
41 //---------------------------------------------------------------------------
42 // TargetMachine Class
45 TargetMachine::TargetMachine(const Target &T,
46 StringRef TT, StringRef CPU, StringRef FS,
47 const TargetOptions &Options)
48 : TheTarget(T), TargetTriple(TT), TargetCPU(CPU), TargetFS(FS),
49 CodeGenInfo(0), AsmInfo(0),
52 MCSaveTempLabels(false),
55 MCUseDwarfDirectory(false),
59 TargetMachine::~TargetMachine() {
64 /// getRelocationModel - Returns the code generation relocation model. The
65 /// choices are static, PIC, and dynamic-no-pic, and target default.
66 Reloc::Model TargetMachine::getRelocationModel() const {
68 return Reloc::Default;
69 return CodeGenInfo->getRelocationModel();
72 /// getCodeModel - Returns the code model. The choices are small, kernel,
73 /// medium, large, and target default.
74 CodeModel::Model TargetMachine::getCodeModel() const {
76 return CodeModel::Default;
77 return CodeGenInfo->getCodeModel();
80 /// getOptLevel - Returns the optimization level: None, Less,
81 /// Default, or Aggressive.
82 CodeGenOpt::Level TargetMachine::getOptLevel() const {
84 return CodeGenOpt::Default;
85 return CodeGenInfo->getOptLevel();
88 bool TargetMachine::getAsmVerbosityDefault() {
89 return AsmVerbosityDefault;
92 void TargetMachine::setAsmVerbosityDefault(bool V) {
93 AsmVerbosityDefault = V;
96 bool TargetMachine::getFunctionSections() {
97 return FunctionSections;
100 bool TargetMachine::getDataSections() {
104 void TargetMachine::setFunctionSections(bool V) {
105 FunctionSections = V;
108 void TargetMachine::setDataSections(bool V) {
112 /// DisableFramePointerElim - This returns true if frame pointer elimination
113 /// optimization should be disabled for the given machine function.
114 bool TargetOptions::DisableFramePointerElim(const MachineFunction &MF) const {
115 // Check to see if we should eliminate non-leaf frame pointers and then
116 // check to see if we should eliminate all frame pointers.
117 if (NoFramePointerElimNonLeaf && !NoFramePointerElim) {
118 const MachineFrameInfo *MFI = MF.getFrameInfo();
119 return MFI->hasCalls();
122 return NoFramePointerElim;
125 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
126 /// is specified on the command line. When this flag is off(default), the
127 /// code generator is not allowed to generate mad (multiply add) if the
128 /// result is "less precise" than doing those operations individually.
129 bool TargetOptions::LessPreciseFPMAD() const {
130 return UnsafeFPMath || LessPreciseFPMADOption;
133 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
134 /// that the rounding mode of the FPU can change from its default.
135 bool TargetOptions::HonorSignDependentRoundingFPMath() const {
136 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
139 /// getTrapFunctionName - If this returns a non-empty string, this means isel
140 /// should lower Intrinsic::trap to a call to the specified function name
141 /// instead of an ISD::TRAP node.
142 StringRef TargetOptions::getTrapFunctionName() const {