blob: fb7bbbbe2e4eb6ccba459eefe7f2780059818f04 [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
Chris Lattneraf76e592009-08-22 20:48:53 +000014#include "llvm/MC/MCAsmInfo.h"
Misha Brukmane67d5fb2004-06-21 21:20:23 +000015#include "llvm/Target/TargetMachine.h"
Evan Cheng4c1aa862006-02-22 20:19:42 +000016#include "llvm/Target/TargetOptions.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000017#include "llvm/Support/CommandLine.h"
Chris Lattnerf70e0c22003-12-28 21:23:38 +000018using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000019
Vikram S. Advee1f72802002-09-16 15:39:26 +000020//---------------------------------------------------------------------------
Brian Gaeke323819e2004-03-04 19:16:23 +000021// Command-line options that tend to be useful on more than one back-end.
22//
23
Misha Brukmanf90e4022004-06-21 21:44:12 +000024namespace llvm {
Owen Anderson95dad832008-10-07 20:22:28 +000025 bool StrongPHIElim;
Evan Cheng2c69f8e2011-04-07 00:58:44 +000026 bool HasDivModLibcall;
Evan Cheng42bf74b2009-03-25 01:47:28 +000027 bool AsmVerbosityDefault(false);
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000028}
Misha Brukman0fb5a662004-06-21 21:08:45 +000029
Chris Lattner43ac7212010-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));
Rafael Espindola0f9827c2011-08-30 19:29:02 +000038
Brian Gaeke323819e2004-03-04 19:16:23 +000039//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +000040// TargetMachine Class
41//
Misha Brukman167deff2004-08-10 23:10:25 +000042
Evan Chengebdeeab2011-07-08 01:53:10 +000043TargetMachine::TargetMachine(const Target &T,
Nick Lewycky8a8d4792011-12-02 22:16:29 +000044 StringRef TT, StringRef CPU, StringRef FS,
45 const TargetOptions &Options)
Benjamin Kramere236dc62011-07-20 01:27:58 +000046 : TheTarget(T), TargetTriple(TT), TargetCPU(CPU), TargetFS(FS),
47 CodeGenInfo(0), AsmInfo(0),
Rafael Espindola195a0ce2010-11-19 02:26:16 +000048 MCRelaxAll(false),
Rafael Espindoladd0dfdf2011-01-23 18:50:12 +000049 MCNoExecStack(false),
Daniel Dunbara7b8c2b2011-03-28 22:49:19 +000050 MCSaveTempLabels(false),
Rafael Espindolaf1a5c7e2011-04-30 03:44:37 +000051 MCUseLoc(true),
Nick Lewycky44d798d2011-10-17 23:05:28 +000052 MCUseCFI(true),
Nick Lewycky8a8d4792011-12-02 22:16:29 +000053 MCUseDwarfDirectory(false),
54 Options(Options) {
Anton Korobeynikov0eebf652009-06-08 22:53:56 +000055}
56
Chris Lattnerf70e0c22003-12-28 21:23:38 +000057TargetMachine::~TargetMachine() {
Benjamin Kramere236dc62011-07-20 01:27:58 +000058 delete CodeGenInfo;
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000059 delete AsmInfo;
Chris Lattnerf70e0c22003-12-28 21:23:38 +000060}
61
Evan Cheng4c1aa862006-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 Cheng43966132011-07-19 06:37:02 +000064Reloc::Model TargetMachine::getRelocationModel() const {
65 if (!CodeGenInfo)
66 return Reloc::Default;
67 return CodeGenInfo->getRelocationModel();
Evan Cheng4c1aa862006-02-22 20:19:42 +000068}
Evan Cheng80235d52006-05-23 18:18:46 +000069
Evan Cheng152ed052006-07-06 01:53:36 +000070/// getCodeModel - Returns the code model. The choices are small, kernel,
71/// medium, large, and target default.
Evan Cheng34ad6db2011-07-20 07:51:56 +000072CodeModel::Model TargetMachine::getCodeModel() const {
73 if (!CodeGenInfo)
74 return CodeModel::Default;
75 return CodeGenInfo->getCodeModel();
Evan Cheng152ed052006-07-06 01:53:36 +000076}
77
Evan Chengb95fc312011-11-16 08:38:26 +000078/// getOptLevel - Returns the optimization level: None, Less,
79/// Default, or Aggressive.
80CodeGenOpt::Level TargetMachine::getOptLevel() const {
81 if (!CodeGenInfo)
82 return CodeGenOpt::Default;
83 return CodeGenInfo->getOptLevel();
84}
85
Evan Cheng42bf74b2009-03-25 01:47:28 +000086bool TargetMachine::getAsmVerbosityDefault() {
87 return AsmVerbosityDefault;
88}
89
90void TargetMachine::setAsmVerbosityDefault(bool V) {
91 AsmVerbosityDefault = V;
92}
93
Chris Lattner43ac7212010-04-13 00:36:43 +000094bool TargetMachine::getFunctionSections() {
95 return FunctionSections;
96}
97
98bool TargetMachine::getDataSections() {
99 return DataSections;
100}
101
102void TargetMachine::setFunctionSections(bool V) {
103 FunctionSections = V;
104}
105
106void TargetMachine::setDataSections(bool V) {
107 DataSections = V;
108}
109