blob: d508b32a399287a2d09b38dea8d9396948f147d5 [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
Vikram S. Adve0799fc42001-09-18 12:58:33 +00008#include "llvm/Target/MachineInstrInfo.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. Adve0799fc42001-09-18 12:58:33 +000019
Vikram S. Adve44a853c2001-07-28 04:09:37 +000020// function TargetMachine::findOptimalStorageSize
21//
22// Purpose:
Vikram S. Adve44a853c2001-07-28 04:09:37 +000023// This default implementation assumes that all sub-word data items use
24// space equal to optSizeForSubWordData, and all other primitive data
25// items use space according to the type.
26//
Vikram S. Adve0799fc42001-09-18 12:58:33 +000027unsigned int
28TargetMachine::findOptimalStorageSize(const Type* ty) const
29{
30 switch(ty->getPrimitiveID())
31 {
32 case Type::BoolTyID:
33 case Type::UByteTyID:
34 case Type::SByteTyID:
35 case Type::UShortTyID:
36 case Type::ShortTyID:
37 return optSizeForSubWordData;
Vikram S. Advedaae6992001-07-21 12:42:08 +000038
Vikram S. Adve0799fc42001-09-18 12:58:33 +000039 default:
40 return DataLayout.getTypeSize(ty);
41 }
Vikram S. Advedaae6992001-07-21 12:42:08 +000042}
43
Vikram S. Adve44a853c2001-07-28 04:09:37 +000044
45//---------------------------------------------------------------------------
46// class MachineInstructionInfo
47// Interface to description of machine instructions
48//---------------------------------------------------------------------------
49
50
51/*ctor*/
52MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* _desc,
Vikram S. Advebf242332001-08-28 23:09:36 +000053 unsigned int _descSize,
54 unsigned int _numRealOpCodes)
55 : desc(_desc), descSize(_descSize), numRealOpCodes(_numRealOpCodes)
Vikram S. Adve44a853c2001-07-28 04:09:37 +000056{
Chris Lattner78a81a22001-09-14 16:08:12 +000057 // FIXME: TargetInstrDescriptors should not be global
Vikram S. Adve44a853c2001-07-28 04:09:37 +000058 assert(TargetInstrDescriptors == NULL && desc != NULL);
59 TargetInstrDescriptors = desc; // initialize global variable
60}
61
62
Vikram S. Adve0799fc42001-09-18 12:58:33 +000063MachineInstrInfo::~MachineInstrInfo()
64{
Vikram S. Adve44a853c2001-07-28 04:09:37 +000065 TargetInstrDescriptors = NULL; // reset global variable
66}
67
68
69bool
70MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
71 int64_t intValue) const
72{
73 // First, check if opCode has an immed field.
74 bool isSignExtended;
Chris Lattnerc7634612001-09-14 15:43:58 +000075 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
Vikram S. Adve0799fc42001-09-18 12:58:33 +000076 if (maxImmedValue != 0)
77 {
78 // Now check if the constant fits
79 if (intValue <= (int64_t) maxImmedValue &&
80 intValue >= -((int64_t) maxImmedValue+1))
81 return true;
82 }
Vikram S. Adve44a853c2001-07-28 04:09:37 +000083
84 return false;
85}