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/GlobalValue.h" 15 #include "llvm/MC/MCAsmInfo.h" 16 #include "llvm/MC/MCCodeGenInfo.h" 17 #include "llvm/Target/TargetMachine.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 HasDivModLibcall; 27 bool AsmVerbosityDefault(false); 28 } 29 30 static cl::opt<bool> 31 DataSections("fdata-sections", 32 cl::desc("Emit data into separate sections"), 33 cl::init(false)); 34 static cl::opt<bool> 35 FunctionSections("ffunction-sections", 36 cl::desc("Emit functions into separate sections"), 37 cl::init(false)); 38 39 //--------------------------------------------------------------------------- 40 // TargetMachine Class 41 // 42 43 TargetMachine::TargetMachine(const Target &T, 44 StringRef TT, StringRef CPU, StringRef FS, 45 const TargetOptions &Options) 46 : TheTarget(T), TargetTriple(TT), TargetCPU(CPU), TargetFS(FS), 47 CodeGenInfo(0), AsmInfo(0), 48 MCRelaxAll(false), 49 MCNoExecStack(false), 50 MCSaveTempLabels(false), 51 MCUseLoc(true), 52 MCUseCFI(true), 53 MCUseDwarfDirectory(false), 54 Options(Options) { 55 } 56 57 TargetMachine::~TargetMachine() { 58 delete CodeGenInfo; 59 delete AsmInfo; 60 } 61 62 /// getRelocationModel - Returns the code generation relocation model. The 63 /// choices are static, PIC, and dynamic-no-pic, and target default. 64 Reloc::Model TargetMachine::getRelocationModel() const { 65 if (!CodeGenInfo) 66 return Reloc::Default; 67 return CodeGenInfo->getRelocationModel(); 68 } 69 70 /// getCodeModel - Returns the code model. The choices are small, kernel, 71 /// medium, large, and target default. 72 CodeModel::Model TargetMachine::getCodeModel() const { 73 if (!CodeGenInfo) 74 return CodeModel::Default; 75 return CodeGenInfo->getCodeModel(); 76 } 77 78 TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const { 79 bool isLocal = GV->hasLocalLinkage(); 80 bool isDeclaration = GV->isDeclaration(); 81 // FIXME: what should we do for protected and internal visibility? 82 // For variables, is internal different from hidden? 83 bool isHidden = GV->hasHiddenVisibility(); 84 85 if (getRelocationModel() == Reloc::PIC_ && 86 !Options.PositionIndependentExecutable) { 87 if (isLocal || isHidden) 88 return TLSModel::LocalDynamic; 89 else 90 return TLSModel::GeneralDynamic; 91 } else { 92 if (!isDeclaration || isHidden) 93 return TLSModel::LocalExec; 94 else 95 return TLSModel::InitialExec; 96 } 97 } 98 99 /// getOptLevel - Returns the optimization level: None, Less, 100 /// Default, or Aggressive. 101 CodeGenOpt::Level TargetMachine::getOptLevel() const { 102 if (!CodeGenInfo) 103 return CodeGenOpt::Default; 104 return CodeGenInfo->getOptLevel(); 105 } 106 107 bool TargetMachine::getAsmVerbosityDefault() { 108 return AsmVerbosityDefault; 109 } 110 111 void TargetMachine::setAsmVerbosityDefault(bool V) { 112 AsmVerbosityDefault = V; 113 } 114 115 bool TargetMachine::getFunctionSections() { 116 return FunctionSections; 117 } 118 119 bool TargetMachine::getDataSections() { 120 return DataSections; 121 } 122 123 void TargetMachine::setFunctionSections(bool V) { 124 FunctionSections = V; 125 } 126 127 void TargetMachine::setDataSections(bool V) { 128 DataSections = V; 129 } 130 131