Chris Lattner | b26bcc5 | 2001-09-14 05:34:53 +0000 | [diff] [blame] | 1 | //===-- TargetMachine.cpp - General Target Information ---------------------==// |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | b26bcc5 | 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 | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 13 | |
Misha Brukman | e67d5fb | 2004-06-21 21:20:23 +0000 | [diff] [blame] | 14 | #include "llvm/Target/TargetMachine.h" |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 15 | #include "llvm/Target/TargetOptions.h" |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 16 | #include "llvm/Type.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 17 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | f70e0c2 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 18 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 19 | |
Vikram S. Adve | e1f7280 | 2002-09-16 15:39:26 +0000 | [diff] [blame] | 20 | //--------------------------------------------------------------------------- |
Brian Gaeke | 323819e | 2004-03-04 19:16:23 +0000 | [diff] [blame] | 21 | // Command-line options that tend to be useful on more than one back-end. |
| 22 | // |
| 23 | |
Misha Brukman | f90e402 | 2004-06-21 21:44:12 +0000 | [diff] [blame] | 24 | namespace llvm { |
| 25 | bool PrintMachineCode; |
| 26 | bool NoFramePointerElim; |
Chris Lattner | 45554a6 | 2005-01-15 06:00:32 +0000 | [diff] [blame] | 27 | bool NoExcessFPPrecision; |
Chris Lattner | 34f74a6 | 2005-04-30 04:09:52 +0000 | [diff] [blame] | 28 | bool UnsafeFPMath; |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 29 | Reloc::Model RelocationModel; |
Misha Brukman | f90e402 | 2004-06-21 21:44:12 +0000 | [diff] [blame] | 30 | }; |
Brian Gaeke | 323819e | 2004-03-04 19:16:23 +0000 | [diff] [blame] | 31 | namespace { |
| 32 | cl::opt<bool, true> PrintCode("print-machineinstrs", |
| 33 | cl::desc("Print generated machine code"), |
| 34 | cl::location(PrintMachineCode), cl::init(false)); |
Misha Brukman | 0fb5a66 | 2004-06-21 21:08:45 +0000 | [diff] [blame] | 35 | |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 36 | cl::opt<bool, true> |
Misha Brukman | 0fb5a66 | 2004-06-21 21:08:45 +0000 | [diff] [blame] | 37 | DisableFPElim("disable-fp-elim", |
| 38 | cl::desc("Disable frame pointer elimination optimization"), |
Misha Brukman | 66d6ee4 | 2004-06-21 21:17:44 +0000 | [diff] [blame] | 39 | cl::location(NoFramePointerElim), |
| 40 | cl::init(false)); |
Chris Lattner | 45554a6 | 2005-01-15 06:00:32 +0000 | [diff] [blame] | 41 | cl::opt<bool, true> |
| 42 | DisableExcessPrecision("disable-excess-fp-precision", |
Nate Begeman | f8b0294 | 2005-04-15 22:12:16 +0000 | [diff] [blame] | 43 | cl::desc("Disable optimizations that may increase FP precision"), |
| 44 | cl::location(NoExcessFPPrecision), |
| 45 | cl::init(false)); |
Chris Lattner | 34f74a6 | 2005-04-30 04:09:52 +0000 | [diff] [blame] | 46 | cl::opt<bool, true> |
| 47 | EnableUnsafeFPMath("enable-unsafe-fp-math", |
| 48 | cl::desc("Enable optimizations that may decrease FP precision"), |
| 49 | cl::location(UnsafeFPMath), |
| 50 | cl::init(false)); |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 51 | cl::opt<llvm::Reloc::Model, true> |
| 52 | DefRelocationModel( |
| 53 | "relocation-model", |
| 54 | cl::desc("Choose relocation model"), |
| 55 | cl::location(RelocationModel), |
| 56 | cl::init(Reloc::Default), |
| 57 | cl::values( |
| 58 | clEnumValN(Reloc::Default, "default", |
| 59 | "Target default relocation model"), |
| 60 | clEnumValN(Reloc::Static, "static", |
| 61 | "Non-relocatable code"), |
| 62 | clEnumValN(Reloc::PIC, "pic", |
| 63 | "Fully relocatable, position independent code"), |
| 64 | clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic", |
| 65 | "Relocatable external references, non-relocatable code"), |
| 66 | clEnumValEnd)); |
Brian Gaeke | 323819e | 2004-03-04 19:16:23 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | //--------------------------------------------------------------------------- |
Chris Lattner | f70e0c2 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 70 | // TargetMachine Class |
| 71 | // |
Chris Lattner | bc641b9 | 2006-03-23 05:43:16 +0000 | [diff] [blame^] | 72 | TargetMachine::TargetMachine(const std::string &name, bool LittleEndian, |
Chris Lattner | f70e0c2 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 73 | unsigned char PtrSize, unsigned char PtrAl, |
| 74 | unsigned char DoubleAl, unsigned char FloatAl, |
| 75 | unsigned char LongAl, unsigned char IntAl, |
Misha Brukman | c8e8764 | 2004-07-23 01:09:52 +0000 | [diff] [blame] | 76 | unsigned char ShortAl, unsigned char ByteAl, |
| 77 | unsigned char BoolAl) |
Chris Lattner | f70e0c2 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 78 | : Name(name), DataLayout(name, LittleEndian, |
| 79 | PtrSize, PtrAl, DoubleAl, FloatAl, LongAl, |
Misha Brukman | c8e8764 | 2004-07-23 01:09:52 +0000 | [diff] [blame] | 80 | IntAl, ShortAl, ByteAl, BoolAl) { |
Chris Lattner | f70e0c2 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 81 | } |
Misha Brukman | 167deff | 2004-08-10 23:10:25 +0000 | [diff] [blame] | 82 | |
Chris Lattner | bc641b9 | 2006-03-23 05:43:16 +0000 | [diff] [blame^] | 83 | TargetMachine::TargetMachine(const std::string &name, const TargetData &TD) |
Misha Brukman | 167deff | 2004-08-10 23:10:25 +0000 | [diff] [blame] | 84 | : Name(name), DataLayout(TD) { |
Misha Brukman | 167deff | 2004-08-10 23:10:25 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Chris Lattner | bc641b9 | 2006-03-23 05:43:16 +0000 | [diff] [blame^] | 87 | TargetMachine::TargetMachine(const std::string &name, const Module &M) |
Chris Lattner | 2bed9ec | 2004-03-03 02:12:47 +0000 | [diff] [blame] | 88 | : Name(name), DataLayout(name, &M) { |
Chris Lattner | 2bed9ec | 2004-03-03 02:12:47 +0000 | [diff] [blame] | 89 | } |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 90 | |
Chris Lattner | f70e0c2 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 91 | TargetMachine::~TargetMachine() { |
Chris Lattner | f70e0c2 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 94 | /// getRelocationModel - Returns the code generation relocation model. The |
| 95 | /// choices are static, PIC, and dynamic-no-pic, and target default. |
| 96 | Reloc::Model TargetMachine::getRelocationModel() { |
| 97 | return RelocationModel; |
| 98 | } |
| 99 | |
| 100 | /// setRelocationModel - Sets the code generation relocation model. |
| 101 | void TargetMachine::setRelocationModel(Reloc::Model Model) { |
| 102 | RelocationModel = Model; |
| 103 | } |