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