blob: 30199be06ae08931d34b1702514ba064cdda7a57 [file] [log] [blame]
Chris Lattnerb26bcc52001-09-14 05:34:53 +00001//===-- TargetMachine.cpp - General Target Information ---------------------==//
John Criswellb576c942003-10-20 19:43:21 +00002//
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 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
Vikram S. Adve4a48c332001-11-09 02:20:18 +000014#include "llvm/Target/TargetMachine.h"
Chris Lattner93fa7052002-10-28 23:55:33 +000015#include "llvm/Type.h"
Chris Lattnerf70e0c22003-12-28 21:23:38 +000016#include "llvm/IntrinsicLowering.h"
17using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000018
Vikram S. Advee1f72802002-09-16 15:39:26 +000019//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +000020// TargetMachine Class
21//
22TargetMachine::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}
Vikram S. Advedaae6992001-07-21 12:42:08 +000033
Chris Lattnerf70e0c22003-12-28 21:23:38 +000034TargetMachine::~TargetMachine() {
35 delete IL;
36}
37
Chris Lattner62eaf7e2002-10-29 21:47:50 +000038unsigned TargetMachine::findOptimalStorageSize(const Type *Ty) const {
Chris Lattner37ec8112003-04-26 19:47:36 +000039 // All integer types smaller than ints promote to 4 byte integers.
40 if (Ty->isIntegral() && Ty->getPrimitiveSize() < 4)
41 return 4;
Chris Lattner62eaf7e2002-10-29 21:47:50 +000042
43 return DataLayout.getTypeSize(Ty);
Vikram S. Advedaae6992001-07-21 12:42:08 +000044}