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/MC/MCAsmInfo.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 HasDivModLibcall; 26 bool AsmVerbosityDefault(false); 27 } 28 29 static cl::opt<bool> 30 DataSections("fdata-sections", 31 cl::desc("Emit data into separate sections"), 32 cl::init(false)); 33 static cl::opt<bool> 34 FunctionSections("ffunction-sections", 35 cl::desc("Emit functions into separate sections"), 36 cl::init(false)); 37 38 //--------------------------------------------------------------------------- 39 // TargetMachine Class 40 // 41 42 TargetMachine::TargetMachine(const Target &T, 43 StringRef TT, StringRef CPU, StringRef FS, 44 const TargetOptions &Options) 45 : TheTarget(T), TargetTriple(TT), TargetCPU(CPU), TargetFS(FS), 46 CodeGenInfo(0), AsmInfo(0), 47 MCRelaxAll(false), 48 MCNoExecStack(false), 49 MCSaveTempLabels(false), 50 MCUseLoc(true), 51 MCUseCFI(true), 52 MCUseDwarfDirectory(false), 53 Options(Options) { 54 } 55 56 TargetMachine::~TargetMachine() { 57 delete CodeGenInfo; 58 delete AsmInfo; 59 } 60 61 /// getRelocationModel - Returns the code generation relocation model. The 62 /// choices are static, PIC, and dynamic-no-pic, and target default. 63 Reloc::Model TargetMachine::getRelocationModel() const { 64 if (!CodeGenInfo) 65 return Reloc::Default; 66 return CodeGenInfo->getRelocationModel(); 67 } 68 69 /// getCodeModel - Returns the code model. The choices are small, kernel, 70 /// medium, large, and target default. 71 CodeModel::Model TargetMachine::getCodeModel() const { 72 if (!CodeGenInfo) 73 return CodeModel::Default; 74 return CodeGenInfo->getCodeModel(); 75 } 76 77 /// getOptLevel - Returns the optimization level: None, Less, 78 /// Default, or Aggressive. 79 CodeGenOpt::Level TargetMachine::getOptLevel() const { 80 if (!CodeGenInfo) 81 return CodeGenOpt::Default; 82 return CodeGenInfo->getOptLevel(); 83 } 84 85 bool TargetMachine::getAsmVerbosityDefault() { 86 return AsmVerbosityDefault; 87 } 88 89 void TargetMachine::setAsmVerbosityDefault(bool V) { 90 AsmVerbosityDefault = V; 91 } 92 93 bool TargetMachine::getFunctionSections() { 94 return FunctionSections; 95 } 96 97 bool TargetMachine::getDataSections() { 98 return DataSections; 99 } 100 101 void TargetMachine::setFunctionSections(bool V) { 102 FunctionSections = V; 103 } 104 105 void TargetMachine::setDataSections(bool V) { 106 DataSections = V; 107 } 108 109