Chris Lattner | b26bcc5 | 2001-09-14 05:34:53 +0000 | [diff] [blame] | 1 | //===-- TargetMachine.cpp - General Target Information ---------------------==// |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 2 | // |
| 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. |
| 7 | // |
| 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 | |
Vikram S. Adve | 4a48c33 | 2001-11-09 02:20:18 +0000 | [diff] [blame] | 14 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 15 | #include "llvm/Type.h" |
Chris Lattner | f70e0c2 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 16 | #include "llvm/IntrinsicLowering.h" |
Brian Gaeke | 323819e | 2004-03-04 19:16:23 +0000 | [diff] [blame^] | 17 | #include "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 | |
| 24 | namespace llvm { |
| 25 | bool PrintMachineCode; |
| 26 | }; |
| 27 | namespace { |
| 28 | cl::opt<bool, true> PrintCode("print-machineinstrs", |
| 29 | cl::desc("Print generated machine code"), |
| 30 | cl::location(PrintMachineCode), cl::init(false)); |
| 31 | }; |
| 32 | |
| 33 | //--------------------------------------------------------------------------- |
Chris Lattner | f70e0c2 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 34 | // TargetMachine Class |
| 35 | // |
| 36 | TargetMachine::TargetMachine(const std::string &name, IntrinsicLowering *il, |
| 37 | bool LittleEndian, |
| 38 | unsigned char PtrSize, unsigned char PtrAl, |
| 39 | unsigned char DoubleAl, unsigned char FloatAl, |
| 40 | unsigned char LongAl, unsigned char IntAl, |
| 41 | unsigned char ShortAl, unsigned char ByteAl) |
| 42 | : Name(name), DataLayout(name, LittleEndian, |
| 43 | PtrSize, PtrAl, DoubleAl, FloatAl, LongAl, |
| 44 | IntAl, ShortAl, ByteAl) { |
| 45 | IL = il ? il : new DefaultIntrinsicLowering(); |
| 46 | } |
Chris Lattner | 2bed9ec | 2004-03-03 02:12:47 +0000 | [diff] [blame] | 47 | TargetMachine::TargetMachine(const std::string &name, IntrinsicLowering *il, |
| 48 | const Module &M) |
| 49 | : Name(name), DataLayout(name, &M) { |
| 50 | IL = il ? il : new DefaultIntrinsicLowering(); |
| 51 | } |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 52 | |
Chris Lattner | f70e0c2 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 53 | TargetMachine::~TargetMachine() { |
| 54 | delete IL; |
| 55 | } |
| 56 | |
Chris Lattner | 62eaf7e | 2002-10-29 21:47:50 +0000 | [diff] [blame] | 57 | unsigned TargetMachine::findOptimalStorageSize(const Type *Ty) const { |
Chris Lattner | 37ec811 | 2003-04-26 19:47:36 +0000 | [diff] [blame] | 58 | // All integer types smaller than ints promote to 4 byte integers. |
| 59 | if (Ty->isIntegral() && Ty->getPrimitiveSize() < 4) |
| 60 | return 4; |
Chris Lattner | 62eaf7e | 2002-10-29 21:47:50 +0000 | [diff] [blame] | 61 | |
| 62 | return DataLayout.getTypeSize(Ty); |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 63 | } |