1 //===-- TargetMachine.cpp - General Target Information ---------------------==// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // 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/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" 20 using namespace llvm; 21 22 //--------------------------------------------------------------------------- 23 // Command-line options that tend to be useful on more than one back-end. 24 // 25 26 namespace llvm { 27 bool StrongPHIElim; 28 bool HasDivModLibcall; 29 bool AsmVerbosityDefault(false); 30 } 31 32 static cl::opt<bool> 33 DataSections("fdata-sections", 34 cl::desc("Emit data into separate sections"), 35 cl::init(false)); 36 static cl::opt<bool> 37 FunctionSections("ffunction-sections", 38 cl::desc("Emit functions into separate sections"), 39 cl::init(false)); 40 41 //--------------------------------------------------------------------------- 42 // TargetMachine Class 43 // 44 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), 50 MCRelaxAll(false), 51 MCNoExecStack(false), 52 MCSaveTempLabels(false), 53 MCUseLoc(true), 54 MCUseCFI(true), 55 MCUseDwarfDirectory(false), 56 Options(Options) { 57 } 58 59 TargetMachine::~TargetMachine() { 60 delete CodeGenInfo; 61 delete AsmInfo; 62 } 63 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 { 67 if (!CodeGenInfo) 68 return Reloc::Default; 69 return CodeGenInfo->getRelocationModel(); 70 } 71 72 /// getCodeModel - Returns the code model. The choices are small, kernel, 73 /// medium, large, and target default. 74 CodeModel::Model TargetMachine::getCodeModel() const { 75 if (!CodeGenInfo) 76 return CodeModel::Default; 77 return CodeGenInfo->getCodeModel(); 78 } 79 80 /// getOptLevel - Returns the optimization level: None, Less, 81 /// Default, or Aggressive. 82 CodeGenOpt::Level TargetMachine::getOptLevel() const { 83 if (!CodeGenInfo) 84 return CodeGenOpt::Default; 85 return CodeGenInfo->getOptLevel(); 86 } 87 88 bool TargetMachine::getAsmVerbosityDefault() { 89 return AsmVerbosityDefault; 90 } 91 92 void TargetMachine::setAsmVerbosityDefault(bool V) { 93 AsmVerbosityDefault = V; 94 } 95 96 bool TargetMachine::getFunctionSections() { 97 return FunctionSections; 98 } 99 100 bool TargetMachine::getDataSections() { 101 return DataSections; 102 } 103 104 void TargetMachine::setFunctionSections(bool V) { 105 FunctionSections = V; 106 } 107 108 void TargetMachine::setDataSections(bool V) { 109 DataSections = V; 110 } 111 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(); 120 } 121 122 return NoFramePointerElim; 123 } 124 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; 131 } 132 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; 137 } 138 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 { 143 return TrapFuncName; 144 } 145