blob: 80cc5fa75f96a0adaca7a0b8bc3cea1381a189fe [file] [log] [blame]
Chris Lattnerb26bcc52001-09-14 05:34:53 +00001//===-- TargetMachine.cpp - General Target Information ---------------------==//
Misha Brukmanf976c852005-04-21 22:55:34 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Brukmanf976c852005-04-21 22:55:34 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattnerb26bcc52001-09-14 05:34:53 +00009//
10// This file describes the general parts of a Target machine.
11//
12//===----------------------------------------------------------------------===//
Vikram S. Advedaae6992001-07-21 12:42:08 +000013
Evan Chenge5667632010-04-21 03:18:23 +000014#include "llvm/CodeGen/MachineFunction.h"
15#include "llvm/CodeGen/MachineFrameInfo.h"
Chris Lattneraf76e592009-08-22 20:48:53 +000016#include "llvm/MC/MCAsmInfo.h"
Misha Brukmane67d5fb2004-06-21 21:20:23 +000017#include "llvm/Target/TargetMachine.h"
Evan Cheng4c1aa862006-02-22 20:19:42 +000018#include "llvm/Target/TargetOptions.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000019#include "llvm/Support/CommandLine.h"
Chris Lattnerf70e0c22003-12-28 21:23:38 +000020using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000021
Vikram S. Advee1f72802002-09-16 15:39:26 +000022//---------------------------------------------------------------------------
Brian Gaeke323819e2004-03-04 19:16:23 +000023// Command-line options that tend to be useful on more than one back-end.
24//
25
Misha Brukmanf90e4022004-06-21 21:44:12 +000026namespace llvm {
Owen Anderson95dad832008-10-07 20:22:28 +000027 bool StrongPHIElim;
Evan Cheng2c69f8e2011-04-07 00:58:44 +000028 bool HasDivModLibcall;
Evan Cheng42bf74b2009-03-25 01:47:28 +000029 bool AsmVerbosityDefault(false);
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000030}
Misha Brukman0fb5a662004-06-21 21:08:45 +000031
Chris Lattner43ac7212010-04-13 00:36:43 +000032static cl::opt<bool>
33DataSections("fdata-sections",
34 cl::desc("Emit data into separate sections"),
35 cl::init(false));
36static cl::opt<bool>
37FunctionSections("ffunction-sections",
38 cl::desc("Emit functions into separate sections"),
39 cl::init(false));
Rafael Espindola0f9827c2011-08-30 19:29:02 +000040
Brian Gaeke323819e2004-03-04 19:16:23 +000041//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +000042// TargetMachine Class
43//
Misha Brukman167deff2004-08-10 23:10:25 +000044
Evan Chengebdeeab2011-07-08 01:53:10 +000045TargetMachine::TargetMachine(const Target &T,
Nick Lewycky8a8d4792011-12-02 22:16:29 +000046 StringRef TT, StringRef CPU, StringRef FS,
47 const TargetOptions &Options)
Benjamin Kramere236dc62011-07-20 01:27:58 +000048 : TheTarget(T), TargetTriple(TT), TargetCPU(CPU), TargetFS(FS),
49 CodeGenInfo(0), AsmInfo(0),
Rafael Espindola195a0ce2010-11-19 02:26:16 +000050 MCRelaxAll(false),
Rafael Espindoladd0dfdf2011-01-23 18:50:12 +000051 MCNoExecStack(false),
Daniel Dunbara7b8c2b2011-03-28 22:49:19 +000052 MCSaveTempLabels(false),
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +000053 MCUseLoc(true),
Nick Lewycky44d798d2011-10-17 23:05:28 +000054 MCUseCFI(true),
Nick Lewycky8a8d4792011-12-02 22:16:29 +000055 MCUseDwarfDirectory(false),
56 Options(Options) {
Anton Korobeynikov0eebf652009-06-08 22:53:56 +000057}
58
Chris Lattnerf70e0c22003-12-28 21:23:38 +000059TargetMachine::~TargetMachine() {
Benjamin Kramere236dc62011-07-20 01:27:58 +000060 delete CodeGenInfo;
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000061 delete AsmInfo;
Chris Lattnerf70e0c22003-12-28 21:23:38 +000062}
63
Evan Cheng4c1aa862006-02-22 20:19:42 +000064/// getRelocationModel - Returns the code generation relocation model. The
65/// choices are static, PIC, and dynamic-no-pic, and target default.
Evan Cheng43966132011-07-19 06:37:02 +000066Reloc::Model TargetMachine::getRelocationModel() const {
67 if (!CodeGenInfo)
68 return Reloc::Default;
69 return CodeGenInfo->getRelocationModel();
Evan Cheng4c1aa862006-02-22 20:19:42 +000070}
Evan Cheng80235d52006-05-23 18:18:46 +000071
Evan Cheng152ed052006-07-06 01:53:36 +000072/// getCodeModel - Returns the code model. The choices are small, kernel,
73/// medium, large, and target default.
Evan Cheng34ad6db2011-07-20 07:51:56 +000074CodeModel::Model TargetMachine::getCodeModel() const {
75 if (!CodeGenInfo)
76 return CodeModel::Default;
77 return CodeGenInfo->getCodeModel();
Evan Cheng152ed052006-07-06 01:53:36 +000078}
79
Evan Chengb95fc312011-11-16 08:38:26 +000080/// getOptLevel - Returns the optimization level: None, Less,
81/// Default, or Aggressive.
82CodeGenOpt::Level TargetMachine::getOptLevel() const {
83 if (!CodeGenInfo)
84 return CodeGenOpt::Default;
85 return CodeGenInfo->getOptLevel();
86}
87
Evan Cheng42bf74b2009-03-25 01:47:28 +000088bool TargetMachine::getAsmVerbosityDefault() {
89 return AsmVerbosityDefault;
90}
91
92void TargetMachine::setAsmVerbosityDefault(bool V) {
93 AsmVerbosityDefault = V;
94}
95
Chris Lattner43ac7212010-04-13 00:36:43 +000096bool TargetMachine::getFunctionSections() {
97 return FunctionSections;
98}
99
100bool TargetMachine::getDataSections() {
101 return DataSections;
102}
103
104void TargetMachine::setFunctionSections(bool V) {
105 FunctionSections = V;
106}
107
108void TargetMachine::setDataSections(bool V) {
109 DataSections = V;
110}
111
Nick Lewycky8a8d4792011-12-02 22:16:29 +0000112/// DisableFramePointerElim - This returns true if frame pointer elimination
113/// optimization should be disabled for the given machine function.
114bool 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 Chenge5667632010-04-21 03:18:23 +0000120 }
121
Nick Lewycky8a8d4792011-12-02 22:16:29 +0000122 return NoFramePointerElim;
123}
Mon P Wangbc65ca82009-03-20 05:06:58 +0000124
Nick Lewycky8a8d4792011-12-02 22:16:29 +0000125/// 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.
129bool TargetOptions::LessPreciseFPMAD() const {
130 return UnsafeFPMath || LessPreciseFPMADOption;
131}
Evan Cheng4da0c7c2011-04-08 21:37:21 +0000132
Nick Lewycky8a8d4792011-12-02 22:16:29 +0000133/// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
134/// that the rounding mode of the FPU can change from its default.
135bool 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.
142StringRef TargetOptions::getTrapFunctionName() const {
143 return TrapFuncName;
Reid Spencer077b3872006-05-24 19:05:21 +0000144}