Chris Lattner | 22a6a90 | 2001-09-14 05:34:53 +0000 | [diff] [blame] | 1 | //===-- TargetMachine.cpp - General Target Information ---------------------==// |
Misha Brukman | 10468d8 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 10468d8 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 22a6a90 | 2001-09-14 05:34:53 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file describes the general parts of a Target machine. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Vikram S. Adve | 3414e78 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 13 | |
Rafael Espindola | a3088f0 | 2012-06-23 00:30:03 +0000 | [diff] [blame] | 14 | #include "llvm/GlobalAlias.h" |
Chandler Carruth | 16f0ebc | 2012-04-08 17:20:55 +0000 | [diff] [blame] | 15 | #include "llvm/GlobalValue.h" |
Rafael Espindola | a3088f0 | 2012-06-23 00:30:03 +0000 | [diff] [blame] | 16 | #include "llvm/GlobalVariable.h" |
Chris Lattner | 7b26fce | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCAsmInfo.h" |
Craig Topper | d4a964c | 2012-03-25 18:10:17 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCCodeGenInfo.h" |
Misha Brukman | 0bfea68 | 2004-06-21 21:20:23 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetMachine.h" |
Reid Spencer | 7c16caa | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 20 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | 5d23600 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 21 | using namespace llvm; |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 22 | |
Vikram S. Adve | 36d3e03 | 2002-09-16 15:39:26 +0000 | [diff] [blame] | 23 | //--------------------------------------------------------------------------- |
Brian Gaeke | 8351d8c | 2004-03-04 19:16:23 +0000 | [diff] [blame] | 24 | // Command-line options that tend to be useful on more than one back-end. |
| 25 | // |
| 26 | |
Misha Brukman | 96041e5 | 2004-06-21 21:44:12 +0000 | [diff] [blame] | 27 | namespace llvm { |
Evan Cheng | a7c7b54 | 2011-04-07 00:58:44 +0000 | [diff] [blame] | 28 | bool HasDivModLibcall; |
Evan Cheng | 5e5a63c | 2009-03-25 01:47:28 +0000 | [diff] [blame] | 29 | bool AsmVerbosityDefault(false); |
Chris Lattner | aa237256 | 2006-05-24 17:04:05 +0000 | [diff] [blame] | 30 | } |
Misha Brukman | 069ca06 | 2004-06-21 21:08:45 +0000 | [diff] [blame] | 31 | |
Chris Lattner | 5b212a3 | 2010-04-13 00:36:43 +0000 | [diff] [blame] | 32 | static cl::opt<bool> |
| 33 | DataSections("fdata-sections", |
| 34 | cl::desc("Emit data into separate sections"), |
| 35 | cl::init(false)); |
| 36 | static cl::opt<bool> |
| 37 | FunctionSections("ffunction-sections", |
| 38 | cl::desc("Emit functions into separate sections"), |
| 39 | cl::init(false)); |
Andrew Trick | e77e84e | 2012-01-13 06:30:30 +0000 | [diff] [blame] | 40 | |
Brian Gaeke | 8351d8c | 2004-03-04 19:16:23 +0000 | [diff] [blame] | 41 | //--------------------------------------------------------------------------- |
Chris Lattner | 5d23600 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 42 | // TargetMachine Class |
| 43 | // |
Misha Brukman | 3decf86 | 2004-08-10 23:10:25 +0000 | [diff] [blame] | 44 | |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 45 | TargetMachine::TargetMachine(const Target &T, |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 46 | StringRef TT, StringRef CPU, StringRef FS, |
| 47 | const TargetOptions &Options) |
Benjamin Kramer | cc38ef6 | 2011-07-20 01:27:58 +0000 | [diff] [blame] | 48 | : TheTarget(T), TargetTriple(TT), TargetCPU(CPU), TargetFS(FS), |
| 49 | CodeGenInfo(0), AsmInfo(0), |
Rafael Espindola | b58867c | 2010-11-19 02:26:16 +0000 | [diff] [blame] | 50 | MCRelaxAll(false), |
Rafael Espindola | c5efca4 | 2011-01-23 18:50:12 +0000 | [diff] [blame] | 51 | MCNoExecStack(false), |
Daniel Dunbar | 3e2b335 | 2011-03-28 22:49:19 +0000 | [diff] [blame] | 52 | MCSaveTempLabels(false), |
Rafael Espindola | a3181d1 | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 53 | MCUseLoc(true), |
Nick Lewycky | 40f8f2f | 2011-10-17 23:05:28 +0000 | [diff] [blame] | 54 | MCUseCFI(true), |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 55 | MCUseDwarfDirectory(false), |
| 56 | Options(Options) { |
Anton Korobeynikov | 77d1943 | 2009-06-08 22:53:56 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Chris Lattner | 5d23600 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 59 | TargetMachine::~TargetMachine() { |
Benjamin Kramer | cc38ef6 | 2011-07-20 01:27:58 +0000 | [diff] [blame] | 60 | delete CodeGenInfo; |
Jim Laskey | ae92ce8 | 2006-09-07 23:39:26 +0000 | [diff] [blame] | 61 | delete AsmInfo; |
Chris Lattner | 5d23600 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Evan Cheng | 73136df | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 64 | /// getRelocationModel - Returns the code generation relocation model. The |
| 65 | /// choices are static, PIC, and dynamic-no-pic, and target default. |
Evan Cheng | 2129f59 | 2011-07-19 06:37:02 +0000 | [diff] [blame] | 66 | Reloc::Model TargetMachine::getRelocationModel() const { |
| 67 | if (!CodeGenInfo) |
| 68 | return Reloc::Default; |
| 69 | return CodeGenInfo->getRelocationModel(); |
Evan Cheng | 73136df | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 70 | } |
Evan Cheng | ac4f66f | 2006-05-23 18:18:46 +0000 | [diff] [blame] | 71 | |
Evan Cheng | 0441746 | 2006-07-06 01:53:36 +0000 | [diff] [blame] | 72 | /// getCodeModel - Returns the code model. The choices are small, kernel, |
| 73 | /// medium, large, and target default. |
Evan Cheng | efd9b42 | 2011-07-20 07:51:56 +0000 | [diff] [blame] | 74 | CodeModel::Model TargetMachine::getCodeModel() const { |
| 75 | if (!CodeGenInfo) |
| 76 | return CodeModel::Default; |
| 77 | return CodeGenInfo->getCodeModel(); |
Evan Cheng | 0441746 | 2006-07-06 01:53:36 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Chandler Carruth | 16f0ebc | 2012-04-08 17:20:55 +0000 | [diff] [blame] | 80 | TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const { |
Rafael Espindola | a3088f0 | 2012-06-23 00:30:03 +0000 | [diff] [blame] | 81 | // If GV is an alias then use the aliasee for determining |
| 82 | // thread-localness. |
| 83 | if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) |
| 84 | GV = GA->resolveAliasedGlobal(false); |
| 85 | const GlobalVariable *Var = cast<GlobalVariable>(GV); |
| 86 | |
| 87 | bool isLocal = Var->hasLocalLinkage(); |
| 88 | bool isDeclaration = Var->isDeclaration(); |
Chandler Carruth | 16f0ebc | 2012-04-08 17:20:55 +0000 | [diff] [blame] | 89 | // FIXME: what should we do for protected and internal visibility? |
| 90 | // For variables, is internal different from hidden? |
Rafael Espindola | a3088f0 | 2012-06-23 00:30:03 +0000 | [diff] [blame] | 91 | bool isHidden = Var->hasHiddenVisibility(); |
Chandler Carruth | 16f0ebc | 2012-04-08 17:20:55 +0000 | [diff] [blame] | 92 | |
Chandler Carruth | ede4a8a | 2012-04-08 17:51:45 +0000 | [diff] [blame] | 93 | if (getRelocationModel() == Reloc::PIC_ && |
| 94 | !Options.PositionIndependentExecutable) { |
Chandler Carruth | 16f0ebc | 2012-04-08 17:20:55 +0000 | [diff] [blame] | 95 | if (isLocal || isHidden) |
| 96 | return TLSModel::LocalDynamic; |
| 97 | else |
| 98 | return TLSModel::GeneralDynamic; |
| 99 | } else { |
| 100 | if (!isDeclaration || isHidden) |
| 101 | return TLSModel::LocalExec; |
| 102 | else |
| 103 | return TLSModel::InitialExec; |
| 104 | } |
| 105 | } |
| 106 | |
Evan Cheng | ecb2908 | 2011-11-16 08:38:26 +0000 | [diff] [blame] | 107 | /// getOptLevel - Returns the optimization level: None, Less, |
| 108 | /// Default, or Aggressive. |
| 109 | CodeGenOpt::Level TargetMachine::getOptLevel() const { |
| 110 | if (!CodeGenInfo) |
| 111 | return CodeGenOpt::Default; |
| 112 | return CodeGenInfo->getOptLevel(); |
| 113 | } |
| 114 | |
Evan Cheng | 5e5a63c | 2009-03-25 01:47:28 +0000 | [diff] [blame] | 115 | bool TargetMachine::getAsmVerbosityDefault() { |
| 116 | return AsmVerbosityDefault; |
| 117 | } |
| 118 | |
| 119 | void TargetMachine::setAsmVerbosityDefault(bool V) { |
| 120 | AsmVerbosityDefault = V; |
| 121 | } |
| 122 | |
Chris Lattner | 5b212a3 | 2010-04-13 00:36:43 +0000 | [diff] [blame] | 123 | bool TargetMachine::getFunctionSections() { |
| 124 | return FunctionSections; |
| 125 | } |
| 126 | |
| 127 | bool TargetMachine::getDataSections() { |
| 128 | return DataSections; |
| 129 | } |
| 130 | |
| 131 | void TargetMachine::setFunctionSections(bool V) { |
| 132 | FunctionSections = V; |
| 133 | } |
| 134 | |
| 135 | void TargetMachine::setDataSections(bool V) { |
| 136 | DataSections = V; |
| 137 | } |
| 138 | |