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 | |
Evan Cheng | 4158a0f | 2010-04-21 03:18:23 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/MachineFunction.h" |
| 15 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Chris Lattner | 7b26fce | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCAsmInfo.h" |
Misha Brukman | 0bfea68 | 2004-06-21 21:20:23 +0000 | [diff] [blame] | 17 | #include "llvm/Target/TargetMachine.h" |
Evan Cheng | 73136df | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetOptions.h" |
Reid Spencer | 7c16caa | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 19 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | 5d23600 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 20 | using namespace llvm; |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 21 | |
Vikram S. Adve | 36d3e03 | 2002-09-16 15:39:26 +0000 | [diff] [blame] | 22 | //--------------------------------------------------------------------------- |
Brian Gaeke | 8351d8c | 2004-03-04 19:16:23 +0000 | [diff] [blame] | 23 | // Command-line options that tend to be useful on more than one back-end. |
| 24 | // |
| 25 | |
Misha Brukman | 96041e5 | 2004-06-21 21:44:12 +0000 | [diff] [blame] | 26 | namespace llvm { |
Owen Anderson | 1d338fc | 2008-10-07 20:22:28 +0000 | [diff] [blame] | 27 | bool StrongPHIElim; |
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)); |
Rafael Espindola | ddc0f87 | 2011-08-30 19:29:02 +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 | |
Evan Cheng | ecb2908 | 2011-11-16 08:38:26 +0000 | [diff] [blame] | 80 | /// getOptLevel - Returns the optimization level: None, Less, |
| 81 | /// Default, or Aggressive. |
| 82 | CodeGenOpt::Level TargetMachine::getOptLevel() const { |
| 83 | if (!CodeGenInfo) |
| 84 | return CodeGenOpt::Default; |
| 85 | return CodeGenInfo->getOptLevel(); |
| 86 | } |
| 87 | |
Evan Cheng | 5e5a63c | 2009-03-25 01:47:28 +0000 | [diff] [blame] | 88 | bool TargetMachine::getAsmVerbosityDefault() { |
| 89 | return AsmVerbosityDefault; |
| 90 | } |
| 91 | |
| 92 | void TargetMachine::setAsmVerbosityDefault(bool V) { |
| 93 | AsmVerbosityDefault = V; |
| 94 | } |
| 95 | |
Chris Lattner | 5b212a3 | 2010-04-13 00:36:43 +0000 | [diff] [blame] | 96 | bool TargetMachine::getFunctionSections() { |
| 97 | return FunctionSections; |
| 98 | } |
| 99 | |
| 100 | bool TargetMachine::getDataSections() { |
| 101 | return DataSections; |
| 102 | } |
| 103 | |
| 104 | void TargetMachine::setFunctionSections(bool V) { |
| 105 | FunctionSections = V; |
| 106 | } |
| 107 | |
| 108 | void TargetMachine::setDataSections(bool V) { |
| 109 | DataSections = V; |
| 110 | } |
| 111 | |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame^] | 112 | /// DisableFramePointerElim - This returns true if frame pointer elimination |
| 113 | /// optimization should be disabled for the given machine function. |
| 114 | bool TargetOptions::DisableFramePointerElim(const MachineFunction &MF) const { |
| 115 | // Check to see if we should eliminate non-leaf frame pointers and then |
| 116 | // check to see if we should eliminate all frame pointers. |
| 117 | if (NoFramePointerElimNonLeaf && !NoFramePointerElim) { |
| 118 | const MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 119 | return MFI->hasCalls(); |
Evan Cheng | 4158a0f | 2010-04-21 03:18:23 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame^] | 122 | return NoFramePointerElim; |
| 123 | } |
Mon P Wang | f67448a | 2009-03-20 05:06:58 +0000 | [diff] [blame] | 124 | |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame^] | 125 | /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option |
| 126 | /// is specified on the command line. When this flag is off(default), the |
| 127 | /// code generator is not allowed to generate mad (multiply add) if the |
| 128 | /// result is "less precise" than doing those operations individually. |
| 129 | bool TargetOptions::LessPreciseFPMAD() const { |
| 130 | return UnsafeFPMath || LessPreciseFPMADOption; |
| 131 | } |
Evan Cheng | 74d92c1 | 2011-04-08 21:37:21 +0000 | [diff] [blame] | 132 | |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame^] | 133 | /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume |
| 134 | /// that the rounding mode of the FPU can change from its default. |
| 135 | bool TargetOptions::HonorSignDependentRoundingFPMath() const { |
| 136 | return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption; |
| 137 | } |
| 138 | |
| 139 | /// getTrapFunctionName - If this returns a non-empty string, this means isel |
| 140 | /// should lower Intrinsic::trap to a call to the specified function name |
| 141 | /// instead of an ISD::TRAP node. |
| 142 | StringRef TargetOptions::getTrapFunctionName() const { |
| 143 | return TrapFuncName; |
Reid Spencer | 94531bf | 2006-05-24 19:05:21 +0000 | [diff] [blame] | 144 | } |