blob: b9b2526876fda96f9e9a1613d28a592d13b7d9c1 [file] [log] [blame]
Chris Lattner22a6a902001-09-14 05:34:53 +00001//===-- TargetMachine.cpp - General Target Information ---------------------==//
Misha Brukman10468d82005-04-21 22:55:34 +00002//
John Criswell482202a2003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman10468d82005-04-21 22:55:34 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner22a6a902001-09-14 05:34:53 +00009//
10// This file describes the general parts of a Target machine.
11//
12//===----------------------------------------------------------------------===//
Vikram S. Adve3414e782001-07-21 12:42:08 +000013
Chandler Carruth16f0ebc2012-04-08 17:20:55 +000014#include "llvm/GlobalValue.h"
Chris Lattner7b26fce2009-08-22 20:48:53 +000015#include "llvm/MC/MCAsmInfo.h"
Craig Topperd4a964c2012-03-25 18:10:17 +000016#include "llvm/MC/MCCodeGenInfo.h"
Misha Brukman0bfea682004-06-21 21:20:23 +000017#include "llvm/Target/TargetMachine.h"
Reid Spencer7c16caa2004-09-01 22:55:40 +000018#include "llvm/Support/CommandLine.h"
Chris Lattner5d236002003-12-28 21:23:38 +000019using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000020
Vikram S. Adve36d3e032002-09-16 15:39:26 +000021//---------------------------------------------------------------------------
Brian Gaeke8351d8c2004-03-04 19:16:23 +000022// Command-line options that tend to be useful on more than one back-end.
23//
24
Misha Brukman96041e52004-06-21 21:44:12 +000025namespace llvm {
Evan Chenga7c7b542011-04-07 00:58:44 +000026 bool HasDivModLibcall;
Evan Cheng5e5a63c2009-03-25 01:47:28 +000027 bool AsmVerbosityDefault(false);
Chris Lattneraa2372562006-05-24 17:04:05 +000028}
Misha Brukman069ca062004-06-21 21:08:45 +000029
Chris Lattner5b212a32010-04-13 00:36:43 +000030static cl::opt<bool>
31DataSections("fdata-sections",
32 cl::desc("Emit data into separate sections"),
33 cl::init(false));
34static cl::opt<bool>
35FunctionSections("ffunction-sections",
36 cl::desc("Emit functions into separate sections"),
37 cl::init(false));
Andrew Tricke77e84e2012-01-13 06:30:30 +000038
Brian Gaeke8351d8c2004-03-04 19:16:23 +000039//---------------------------------------------------------------------------
Chris Lattner5d236002003-12-28 21:23:38 +000040// TargetMachine Class
41//
Misha Brukman3decf862004-08-10 23:10:25 +000042
Evan Cheng4d1ca962011-07-08 01:53:10 +000043TargetMachine::TargetMachine(const Target &T,
Nick Lewycky50f02cb2011-12-02 22:16:29 +000044 StringRef TT, StringRef CPU, StringRef FS,
45 const TargetOptions &Options)
Benjamin Kramercc38ef62011-07-20 01:27:58 +000046 : TheTarget(T), TargetTriple(TT), TargetCPU(CPU), TargetFS(FS),
47 CodeGenInfo(0), AsmInfo(0),
Rafael Espindolab58867c2010-11-19 02:26:16 +000048 MCRelaxAll(false),
Rafael Espindolac5efca42011-01-23 18:50:12 +000049 MCNoExecStack(false),
Daniel Dunbar3e2b3352011-03-28 22:49:19 +000050 MCSaveTempLabels(false),
Rafael Espindolaa3181d12011-04-30 03:44:37 +000051 MCUseLoc(true),
Nick Lewycky40f8f2f2011-10-17 23:05:28 +000052 MCUseCFI(true),
Nick Lewycky50f02cb2011-12-02 22:16:29 +000053 MCUseDwarfDirectory(false),
54 Options(Options) {
Anton Korobeynikov77d19432009-06-08 22:53:56 +000055}
56
Chris Lattner5d236002003-12-28 21:23:38 +000057TargetMachine::~TargetMachine() {
Benjamin Kramercc38ef62011-07-20 01:27:58 +000058 delete CodeGenInfo;
Jim Laskeyae92ce82006-09-07 23:39:26 +000059 delete AsmInfo;
Chris Lattner5d236002003-12-28 21:23:38 +000060}
61
Evan Cheng73136df2006-02-22 20:19:42 +000062/// getRelocationModel - Returns the code generation relocation model. The
63/// choices are static, PIC, and dynamic-no-pic, and target default.
Evan Cheng2129f592011-07-19 06:37:02 +000064Reloc::Model TargetMachine::getRelocationModel() const {
65 if (!CodeGenInfo)
66 return Reloc::Default;
67 return CodeGenInfo->getRelocationModel();
Evan Cheng73136df2006-02-22 20:19:42 +000068}
Evan Chengac4f66f2006-05-23 18:18:46 +000069
Evan Cheng04417462006-07-06 01:53:36 +000070/// getCodeModel - Returns the code model. The choices are small, kernel,
71/// medium, large, and target default.
Evan Chengefd9b422011-07-20 07:51:56 +000072CodeModel::Model TargetMachine::getCodeModel() const {
73 if (!CodeGenInfo)
74 return CodeModel::Default;
75 return CodeGenInfo->getCodeModel();
Evan Cheng04417462006-07-06 01:53:36 +000076}
77
Chandler Carruth16f0ebc2012-04-08 17:20:55 +000078TLSModel::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
Chandler Carruthede4a8a2012-04-08 17:51:45 +000085 if (getRelocationModel() == Reloc::PIC_ &&
86 !Options.PositionIndependentExecutable) {
Chandler Carruth16f0ebc2012-04-08 17:20:55 +000087 if (isLocal || isHidden)
88 return TLSModel::LocalDynamic;
89 else
90 return TLSModel::GeneralDynamic;
91 } else {
92 if (!isDeclaration || isHidden)
93 return TLSModel::LocalExec;
94 else
95 return TLSModel::InitialExec;
96 }
97}
98
Evan Chengecb29082011-11-16 08:38:26 +000099/// getOptLevel - Returns the optimization level: None, Less,
100/// Default, or Aggressive.
101CodeGenOpt::Level TargetMachine::getOptLevel() const {
102 if (!CodeGenInfo)
103 return CodeGenOpt::Default;
104 return CodeGenInfo->getOptLevel();
105}
106
Evan Cheng5e5a63c2009-03-25 01:47:28 +0000107bool TargetMachine::getAsmVerbosityDefault() {
108 return AsmVerbosityDefault;
109}
110
111void TargetMachine::setAsmVerbosityDefault(bool V) {
112 AsmVerbosityDefault = V;
113}
114
Chris Lattner5b212a32010-04-13 00:36:43 +0000115bool TargetMachine::getFunctionSections() {
116 return FunctionSections;
117}
118
119bool TargetMachine::getDataSections() {
120 return DataSections;
121}
122
123void TargetMachine::setFunctionSections(bool V) {
124 FunctionSections = V;
125}
126
127void TargetMachine::setDataSections(bool V) {
128 DataSections = V;
129}
130