blob: 51c1222ab68e69eb6a60af1339f6d130e088f190 [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.
Chris Lattnerf27eeea2002-12-29 02:50:35 +000011// This file also implements TargetCacheInfo.
Chris Lattnerb26bcc52001-09-14 05:34:53 +000012//
13//===----------------------------------------------------------------------===//
Vikram S. Advedaae6992001-07-21 12:42:08 +000014
Vikram S. Adve4a48c332001-11-09 02:20:18 +000015#include "llvm/Target/TargetMachine.h"
Chris Lattnerf27eeea2002-12-29 02:50:35 +000016#include "llvm/Target/TargetCacheInfo.h"
Chris Lattner93fa7052002-10-28 23:55:33 +000017#include "llvm/Type.h"
Chris Lattnerf70e0c22003-12-28 21:23:38 +000018#include "llvm/IntrinsicLowering.h"
19using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000020
Vikram S. Advee1f72802002-09-16 15:39:26 +000021//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +000022// TargetMachine Class
23//
24TargetMachine::TargetMachine(const std::string &name, IntrinsicLowering *il,
25 bool LittleEndian,
26 unsigned char PtrSize, unsigned char PtrAl,
27 unsigned char DoubleAl, unsigned char FloatAl,
28 unsigned char LongAl, unsigned char IntAl,
29 unsigned char ShortAl, unsigned char ByteAl)
30 : Name(name), DataLayout(name, LittleEndian,
31 PtrSize, PtrAl, DoubleAl, FloatAl, LongAl,
32 IntAl, ShortAl, ByteAl) {
33 IL = il ? il : new DefaultIntrinsicLowering();
34}
Vikram S. Advedaae6992001-07-21 12:42:08 +000035
Vikram S. Adve0799fc42001-09-18 12:58:33 +000036
Chris Lattnerf70e0c22003-12-28 21:23:38 +000037
38TargetMachine::~TargetMachine() {
39 delete IL;
40}
41
42
43
44
Chris Lattner62eaf7e2002-10-29 21:47:50 +000045unsigned TargetMachine::findOptimalStorageSize(const Type *Ty) const {
Chris Lattner37ec8112003-04-26 19:47:36 +000046 // All integer types smaller than ints promote to 4 byte integers.
47 if (Ty->isIntegral() && Ty->getPrimitiveSize() < 4)
48 return 4;
Chris Lattner62eaf7e2002-10-29 21:47:50 +000049
50 return DataLayout.getTypeSize(Ty);
Vikram S. Advedaae6992001-07-21 12:42:08 +000051}
52
Vikram S. Adve44a853c2001-07-28 04:09:37 +000053
54//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +000055// TargetCacheInfo Class
56//
Vikram S. Adve4a48c332001-11-09 02:20:18 +000057
Chris Lattnerf27eeea2002-12-29 02:50:35 +000058void TargetCacheInfo::Initialize() {
Vikram S. Adve4a48c332001-11-09 02:20:18 +000059 numLevels = 2;
60 cacheLineSizes.push_back(16); cacheLineSizes.push_back(32);
61 cacheSizes.push_back(1 << 15); cacheSizes.push_back(1 << 20);
62 cacheAssoc.push_back(1); cacheAssoc.push_back(4);
63}