Move the TLSModel information into the TargetMachine rather than hiding
[oota-llvm.git] / lib / Target / TargetMachine.cpp
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     if (isLocal || isHidden)
87       return TLSModel::LocalDynamic;
88     else
89       return TLSModel::GeneralDynamic;
90   } else {
91     if (!isDeclaration || isHidden)
92       return TLSModel::LocalExec;
93     else
94       return TLSModel::InitialExec;
95   }
96 }
97
98 /// getOptLevel - Returns the optimization level: None, Less,
99 /// Default, or Aggressive.
100 CodeGenOpt::Level TargetMachine::getOptLevel() const {
101   if (!CodeGenInfo)
102     return CodeGenOpt::Default;
103   return CodeGenInfo->getOptLevel();
104 }
105
106 bool TargetMachine::getAsmVerbosityDefault() {
107   return AsmVerbosityDefault;
108 }
109
110 void TargetMachine::setAsmVerbosityDefault(bool V) {
111   AsmVerbosityDefault = V;
112 }
113
114 bool TargetMachine::getFunctionSections() {
115   return FunctionSections;
116 }
117
118 bool TargetMachine::getDataSections() {
119   return DataSections;
120 }
121
122 void TargetMachine::setFunctionSections(bool V) {
123   FunctionSections = V;
124 }
125
126 void TargetMachine::setDataSections(bool V) {
127   DataSections = V;
128 }
129