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