Add a new constructor
[oota-llvm.git] / lib / Target / TargetMachine.cpp
1 //===-- TargetMachine.cpp - General Target Information ---------------------==//
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 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the general parts of a Target machine.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Target/TargetMachine.h"
15 #include "llvm/Type.h"
16 #include "llvm/IntrinsicLowering.h"
17 using namespace llvm;
18
19 //---------------------------------------------------------------------------
20 // TargetMachine Class
21 //
22 TargetMachine::TargetMachine(const std::string &name, IntrinsicLowering *il,
23                              bool LittleEndian,
24                              unsigned char PtrSize, unsigned char PtrAl,
25                              unsigned char DoubleAl, unsigned char FloatAl,
26                              unsigned char LongAl, unsigned char IntAl,
27                              unsigned char ShortAl, unsigned char ByteAl)
28   : Name(name), DataLayout(name, LittleEndian,
29                            PtrSize, PtrAl, DoubleAl, FloatAl, LongAl,
30                            IntAl, ShortAl, ByteAl) {
31   IL = il ? il : new DefaultIntrinsicLowering();
32 }
33 TargetMachine::TargetMachine(const std::string &name, IntrinsicLowering *il,
34                              const Module &M)
35   : Name(name), DataLayout(name, &M) {
36   IL = il ? il : new DefaultIntrinsicLowering();
37 }
38
39 TargetMachine::~TargetMachine() {
40   delete IL;
41 }
42
43 unsigned TargetMachine::findOptimalStorageSize(const Type *Ty) const {
44   // All integer types smaller than ints promote to 4 byte integers.
45   if (Ty->isIntegral() && Ty->getPrimitiveSize() < 4)
46     return 4;
47
48   return DataLayout.getTypeSize(Ty);
49 }