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/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"
21 //---------------------------------------------------------------------------
22 // Command-line options that tend to be useful on more than one back-end.
26 bool HasDivModLibcall;
27 bool AsmVerbosityDefault(false);
31 DataSections("fdata-sections",
32 cl::desc("Emit data into separate sections"),
35 FunctionSections("ffunction-sections",
36 cl::desc("Emit functions into separate sections"),
39 //---------------------------------------------------------------------------
40 // TargetMachine Class
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),
50 MCSaveTempLabels(false),
53 MCUseDwarfDirectory(false),
57 TargetMachine::~TargetMachine() {
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 {
66 return Reloc::Default;
67 return CodeGenInfo->getRelocationModel();
70 /// getCodeModel - Returns the code model. The choices are small, kernel,
71 /// medium, large, and target default.
72 CodeModel::Model TargetMachine::getCodeModel() const {
74 return CodeModel::Default;
75 return CodeGenInfo->getCodeModel();
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();
85 if (getRelocationModel() == Reloc::PIC_ &&
86 !Options.PositionIndependentExecutable) {
87 if (isLocal || isHidden)
88 return TLSModel::LocalDynamic;
90 return TLSModel::GeneralDynamic;
92 if (!isDeclaration || isHidden)
93 return TLSModel::LocalExec;
95 return TLSModel::InitialExec;
99 /// getOptLevel - Returns the optimization level: None, Less,
100 /// Default, or Aggressive.
101 CodeGenOpt::Level TargetMachine::getOptLevel() const {
103 return CodeGenOpt::Default;
104 return CodeGenInfo->getOptLevel();
107 bool TargetMachine::getAsmVerbosityDefault() {
108 return AsmVerbosityDefault;
111 void TargetMachine::setAsmVerbosityDefault(bool V) {
112 AsmVerbosityDefault = V;
115 bool TargetMachine::getFunctionSections() {
116 return FunctionSections;
119 bool TargetMachine::getDataSections() {
123 void TargetMachine::setFunctionSections(bool V) {
124 FunctionSections = V;
127 void TargetMachine::setDataSections(bool V) {