blob: 31277ff3cda384fc1d681f12609075a9d73cfcaa [file] [log] [blame]
Chris Lattnerb26bcc52001-09-14 05:34:53 +00001//===-- TargetMachine.cpp - General Target Information ---------------------==//
2//
3// This file describes the general parts of a Target machine.
Vikram S. Adve4a48c332001-11-09 02:20:18 +00004// This file also implements MachineInstrInfo and MachineCacheInfo.
Chris Lattnerb26bcc52001-09-14 05:34:53 +00005//
6//===----------------------------------------------------------------------===//
Vikram S. Advedaae6992001-07-21 12:42:08 +00007
Vikram S. Adve4a48c332001-11-09 02:20:18 +00008#include "llvm/Target/TargetMachine.h"
Vikram S. Adve0799fc42001-09-18 12:58:33 +00009#include "llvm/Target/MachineInstrInfo.h"
Vikram S. Adve4a48c332001-11-09 02:20:18 +000010#include "llvm/Target/MachineCacheInfo.h"
Vikram S. Advee1f72802002-09-16 15:39:26 +000011#include "llvm/Function.h"
Vikram S. Advee5b25652002-09-20 00:52:43 +000012
Vikram S. Advee1f72802002-09-16 15:39:26 +000013//---------------------------------------------------------------------------
Vikram S. Adve44a853c2001-07-28 04:09:37 +000014// class TargetMachine
Vikram S. Advedaae6992001-07-21 12:42:08 +000015//
16// Purpose:
Vikram S. Adve44a853c2001-07-28 04:09:37 +000017// Machine description.
18//
Vikram S. Advedaae6992001-07-21 12:42:08 +000019//---------------------------------------------------------------------------
20
Vikram S. Adve0799fc42001-09-18 12:58:33 +000021
Vikram S. Adve44a853c2001-07-28 04:09:37 +000022// function TargetMachine::findOptimalStorageSize
23//
24// Purpose:
Vikram S. Adve44a853c2001-07-28 04:09:37 +000025// This default implementation assumes that all sub-word data items use
26// space equal to optSizeForSubWordData, and all other primitive data
27// items use space according to the type.
28//
Vikram S. Adve0799fc42001-09-18 12:58:33 +000029unsigned int
30TargetMachine::findOptimalStorageSize(const Type* ty) const
31{
32 switch(ty->getPrimitiveID())
33 {
34 case Type::BoolTyID:
35 case Type::UByteTyID:
36 case Type::SByteTyID:
37 case Type::UShortTyID:
38 case Type::ShortTyID:
39 return optSizeForSubWordData;
Vikram S. Advedaae6992001-07-21 12:42:08 +000040
Vikram S. Adve0799fc42001-09-18 12:58:33 +000041 default:
42 return DataLayout.getTypeSize(ty);
43 }
Vikram S. Advedaae6992001-07-21 12:42:08 +000044}
45
Vikram S. Adve44a853c2001-07-28 04:09:37 +000046
47//---------------------------------------------------------------------------
48// class MachineInstructionInfo
49// Interface to description of machine instructions
50//---------------------------------------------------------------------------
51
52
53/*ctor*/
Vikram S. Adve7a2f1e72001-11-08 05:15:08 +000054MachineInstrInfo::MachineInstrInfo(const TargetMachine& tgt,
55 const MachineInstrDescriptor* _desc,
Vikram S. Advebf242332001-08-28 23:09:36 +000056 unsigned int _descSize,
57 unsigned int _numRealOpCodes)
Vikram S. Adve7a2f1e72001-11-08 05:15:08 +000058 : target(tgt),
59 desc(_desc), descSize(_descSize), numRealOpCodes(_numRealOpCodes)
Vikram S. Adve44a853c2001-07-28 04:09:37 +000060{
Chris Lattner78a81a22001-09-14 16:08:12 +000061 // FIXME: TargetInstrDescriptors should not be global
Vikram S. Adve44a853c2001-07-28 04:09:37 +000062 assert(TargetInstrDescriptors == NULL && desc != NULL);
63 TargetInstrDescriptors = desc; // initialize global variable
64}
65
66
Vikram S. Adve0799fc42001-09-18 12:58:33 +000067MachineInstrInfo::~MachineInstrInfo()
68{
Vikram S. Adve44a853c2001-07-28 04:09:37 +000069 TargetInstrDescriptors = NULL; // reset global variable
70}
71
72
73bool
74MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
75 int64_t intValue) const
76{
77 // First, check if opCode has an immed field.
78 bool isSignExtended;
Chris Lattnerc7634612001-09-14 15:43:58 +000079 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
Vikram S. Adve0799fc42001-09-18 12:58:33 +000080 if (maxImmedValue != 0)
81 {
Vikram S. Advee1f72802002-09-16 15:39:26 +000082 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
83 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
84 // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
85
Vikram S. Adve0799fc42001-09-18 12:58:33 +000086 // Now check if the constant fits
87 if (intValue <= (int64_t) maxImmedValue &&
88 intValue >= -((int64_t) maxImmedValue+1))
89 return true;
90 }
Vikram S. Adve44a853c2001-07-28 04:09:37 +000091
92 return false;
93}
Vikram S. Adve4a48c332001-11-09 02:20:18 +000094
95
96//---------------------------------------------------------------------------
97// class MachineCacheInfo
98//
99// Purpose:
100// Describes properties of the target cache architecture.
101//---------------------------------------------------------------------------
102
103/*ctor*/
104MachineCacheInfo::MachineCacheInfo(const TargetMachine& tgt)
105 : target(tgt)
106{
107 Initialize();
108}
109
110void
111MachineCacheInfo::Initialize()
112{
113 numLevels = 2;
114 cacheLineSizes.push_back(16); cacheLineSizes.push_back(32);
115 cacheSizes.push_back(1 << 15); cacheSizes.push_back(1 << 20);
116 cacheAssoc.push_back(1); cacheAssoc.push_back(4);
117}