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/GlobalAlias.h"
15 #include "llvm/GlobalValue.h"
16 #include "llvm/GlobalVariable.h"
17 #include "llvm/MC/MCAsmInfo.h"
18 #include "llvm/MC/MCCodeGenInfo.h"
19 #include "llvm/Target/TargetMachine.h"
20 #include "llvm/Support/CommandLine.h"
23 //---------------------------------------------------------------------------
24 // Command-line options that tend to be useful on more than one back-end.
28 bool HasDivModLibcall;
29 bool AsmVerbosityDefault(false);
33 DataSections("fdata-sections",
34 cl::desc("Emit data into separate sections"),
37 FunctionSections("ffunction-sections",
38 cl::desc("Emit functions into separate sections"),
41 //---------------------------------------------------------------------------
42 // TargetMachine Class
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),
52 MCSaveTempLabels(false),
55 MCUseDwarfDirectory(false),
59 TargetMachine::~TargetMachine() {
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 {
68 return Reloc::Default;
69 return CodeGenInfo->getRelocationModel();
72 /// getCodeModel - Returns the code model. The choices are small, kernel,
73 /// medium, large, and target default.
74 CodeModel::Model TargetMachine::getCodeModel() const {
76 return CodeModel::Default;
77 return CodeGenInfo->getCodeModel();
80 TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const {
81 // If GV is an alias then use the aliasee for determining
83 if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV))
84 GV = GA->resolveAliasedGlobal(false);
85 const GlobalVariable *Var = cast<GlobalVariable>(GV);
87 bool isLocal = Var->hasLocalLinkage();
88 bool isDeclaration = Var->isDeclaration();
89 // FIXME: what should we do for protected and internal visibility?
90 // For variables, is internal different from hidden?
91 bool isHidden = Var->hasHiddenVisibility();
93 if (getRelocationModel() == Reloc::PIC_ &&
94 !Options.PositionIndependentExecutable) {
95 if (isLocal || isHidden)
96 return TLSModel::LocalDynamic;
98 return TLSModel::GeneralDynamic;
100 if (!isDeclaration || isHidden)
101 return TLSModel::LocalExec;
103 return TLSModel::InitialExec;
107 /// getOptLevel - Returns the optimization level: None, Less,
108 /// Default, or Aggressive.
109 CodeGenOpt::Level TargetMachine::getOptLevel() const {
111 return CodeGenOpt::Default;
112 return CodeGenInfo->getOptLevel();
115 bool TargetMachine::getAsmVerbosityDefault() {
116 return AsmVerbosityDefault;
119 void TargetMachine::setAsmVerbosityDefault(bool V) {
120 AsmVerbosityDefault = V;
123 bool TargetMachine::getFunctionSections() {
124 return FunctionSections;
127 bool TargetMachine::getDataSections() {
131 void TargetMachine::setFunctionSections(bool V) {
132 FunctionSections = V;
135 void TargetMachine::setDataSections(bool V) {