blob: cf4cbc6800235ee6322656c439ed3ebb64c07967 [file] [log] [blame]
Vikram S. Advedaae6992001-07-21 12:42:08 +00001// $Id$
2//***************************************************************************
3// File:
4// TargetMachine.cpp
5//
6// Purpose:
7//
8// History:
9// 7/12/01 - Vikram Adve - Created
10//**************************************************************************/
11
12
Vikram S. Advedaae6992001-07-21 12:42:08 +000013//*************************** User Include Files ***************************/
14
Chris Lattner7e583cf2001-07-21 20:58:30 +000015#include "llvm/CodeGen/TargetMachine.h"
Chris Lattner68498ce2001-07-21 23:24:48 +000016#include "llvm/DerivedTypes.h"
Vikram S. Advedaae6992001-07-21 12:42:08 +000017
Vikram S. Adve44a853c2001-07-28 04:09:37 +000018//************************ Exported Constants ******************************/
19
20
21// External object describing the machine instructions
22// Initialized only when the TargetMachine class is created
23// and reset when that class is destroyed.
24//
25const MachineInstrDescriptor* TargetInstrDescriptors = NULL;
26
Vikram S. Advedaae6992001-07-21 12:42:08 +000027
28//************************ Class Implementations **************************/
29
Vikram S. Advedaae6992001-07-21 12:42:08 +000030//---------------------------------------------------------------------------
Vikram S. Adve44a853c2001-07-28 04:09:37 +000031// class TargetMachine
Vikram S. Advedaae6992001-07-21 12:42:08 +000032//
33// Purpose:
Vikram S. Adve44a853c2001-07-28 04:09:37 +000034// Machine description.
35//
Vikram S. Advedaae6992001-07-21 12:42:08 +000036//---------------------------------------------------------------------------
37
Vikram S. Adve44a853c2001-07-28 04:09:37 +000038
39// function TargetMachine::findOptimalStorageSize
40//
41// Purpose:
Vikram S. Adve44a853c2001-07-28 04:09:37 +000042// This default implementation assumes that all sub-word data items use
43// space equal to optSizeForSubWordData, and all other primitive data
44// items use space according to the type.
45//
Chris Lattner3a13c7e2001-08-27 15:50:41 +000046unsigned int TargetMachine::findOptimalStorageSize(const Type* ty) const {
47 switch(ty->getPrimitiveID()) {
48 case Type::BoolTyID:
49 case Type::UByteTyID:
50 case Type::SByteTyID:
51 case Type::UShortTyID:
52 case Type::ShortTyID:
53 return optSizeForSubWordData;
Vikram S. Advedaae6992001-07-21 12:42:08 +000054
Chris Lattner3a13c7e2001-08-27 15:50:41 +000055 default:
56 return DataLayout.getTypeSize(ty);
57 }
Vikram S. Advedaae6992001-07-21 12:42:08 +000058}
59
Vikram S. Adve44a853c2001-07-28 04:09:37 +000060
61//---------------------------------------------------------------------------
62// class MachineInstructionInfo
63// Interface to description of machine instructions
64//---------------------------------------------------------------------------
65
66
67/*ctor*/
68MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* _desc,
69 unsigned int _descSize)
70 : desc(_desc), descSize(_descSize)
71{
72 assert(TargetInstrDescriptors == NULL && desc != NULL);
73 TargetInstrDescriptors = desc; // initialize global variable
74}
75
76
77/*dtor*/
78MachineInstrInfo::~MachineInstrInfo()
79{
80 TargetInstrDescriptors = NULL; // reset global variable
81}
82
83
84bool
85MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
86 int64_t intValue) const
87{
88 // First, check if opCode has an immed field.
89 bool isSignExtended;
90 uint64_t maxImmedValue = this->maxImmedConstant(opCode, isSignExtended);
91 if (maxImmedValue != 0)
92 {
93 // Now check if the constant fits
94 if (intValue <= (int64_t) maxImmedValue &&
95 intValue >= -((int64_t) maxImmedValue+1))
96 return true;
97 }
98
99 return false;
100}
101
Vikram S. Advedaae6992001-07-21 12:42:08 +0000102//---------------------------------------------------------------------------