blob: aecc88556707249e3918f00a578ee6bedb8dc629 [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.
Chris Lattnerc7634612001-09-14 15:43:58 +00004// This file also implements the InstInfo interface as well...
Chris Lattnerb26bcc52001-09-14 05:34:53 +00005//
6//===----------------------------------------------------------------------===//
Vikram S. Advedaae6992001-07-21 12:42:08 +00007
Chris Lattnerc7634612001-09-14 15:43:58 +00008#include "llvm/Target/InstInfo.h"
Chris Lattner68498ce2001-07-21 23:24:48 +00009#include "llvm/DerivedTypes.h"
Vikram S. Advedaae6992001-07-21 12:42:08 +000010
Vikram S. Advedaae6992001-07-21 12:42:08 +000011//---------------------------------------------------------------------------
Vikram S. Adve44a853c2001-07-28 04:09:37 +000012// class TargetMachine
Vikram S. Advedaae6992001-07-21 12:42:08 +000013//
14// Purpose:
Vikram S. Adve44a853c2001-07-28 04:09:37 +000015// Machine description.
16//
Vikram S. Advedaae6992001-07-21 12:42:08 +000017//---------------------------------------------------------------------------
18
Vikram S. Adve44a853c2001-07-28 04:09:37 +000019// function TargetMachine::findOptimalStorageSize
20//
21// Purpose:
Vikram S. Adve44a853c2001-07-28 04:09:37 +000022// This default implementation assumes that all sub-word data items use
23// space equal to optSizeForSubWordData, and all other primitive data
24// items use space according to the type.
25//
Chris Lattner3a13c7e2001-08-27 15:50:41 +000026unsigned int TargetMachine::findOptimalStorageSize(const Type* ty) const {
27 switch(ty->getPrimitiveID()) {
28 case Type::BoolTyID:
29 case Type::UByteTyID:
30 case Type::SByteTyID:
31 case Type::UShortTyID:
32 case Type::ShortTyID:
33 return optSizeForSubWordData;
Vikram S. Advedaae6992001-07-21 12:42:08 +000034
Chris Lattner3a13c7e2001-08-27 15:50:41 +000035 default:
36 return DataLayout.getTypeSize(ty);
37 }
Vikram S. Advedaae6992001-07-21 12:42:08 +000038}
39
Vikram S. Adve44a853c2001-07-28 04:09:37 +000040
41//---------------------------------------------------------------------------
42// class MachineInstructionInfo
43// Interface to description of machine instructions
44//---------------------------------------------------------------------------
45
46
47/*ctor*/
48MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* _desc,
Vikram S. Advebf242332001-08-28 23:09:36 +000049 unsigned int _descSize,
50 unsigned int _numRealOpCodes)
51 : desc(_desc), descSize(_descSize), numRealOpCodes(_numRealOpCodes)
Vikram S. Adve44a853c2001-07-28 04:09:37 +000052{
Chris Lattner78a81a22001-09-14 16:08:12 +000053 // FIXME: TargetInstrDescriptors should not be global
Vikram S. Adve44a853c2001-07-28 04:09:37 +000054 assert(TargetInstrDescriptors == NULL && desc != NULL);
55 TargetInstrDescriptors = desc; // initialize global variable
56}
57
58
Chris Lattnerc7634612001-09-14 15:43:58 +000059MachineInstrInfo::~MachineInstrInfo() {
Vikram S. Adve44a853c2001-07-28 04:09:37 +000060 TargetInstrDescriptors = NULL; // reset global variable
61}
62
63
64bool
65MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
66 int64_t intValue) const
67{
68 // First, check if opCode has an immed field.
69 bool isSignExtended;
Chris Lattnerc7634612001-09-14 15:43:58 +000070 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
71 if (maxImmedValue != 0) {
72 // Now check if the constant fits
73 if (intValue <= (int64_t) maxImmedValue &&
74 intValue >= -((int64_t) maxImmedValue+1))
75 return true;
76 }
Vikram S. Adve44a853c2001-07-28 04:09:37 +000077
78 return false;
79}