2001-09-14 05:34:53 +00:00
|
|
|
//===-- TargetMachine.cpp - General Target Information ---------------------==//
|
|
|
|
//
|
|
|
|
// This file describes the general parts of a Target machine.
|
2001-09-14 15:43:58 +00:00
|
|
|
// This file also implements the InstInfo interface as well...
|
2001-09-14 05:34:53 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-21 12:42:08 +00:00
|
|
|
|
2001-09-14 15:43:58 +00:00
|
|
|
#include "llvm/Target/InstInfo.h"
|
2001-07-21 23:24:48 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2001-07-21 12:42:08 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
2001-07-28 04:09:37 +00:00
|
|
|
// class TargetMachine
|
2001-07-21 12:42:08 +00:00
|
|
|
//
|
|
|
|
// Purpose:
|
2001-07-28 04:09:37 +00:00
|
|
|
// Machine description.
|
|
|
|
//
|
2001-07-21 12:42:08 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2001-07-28 04:09:37 +00:00
|
|
|
// function TargetMachine::findOptimalStorageSize
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
// This default implementation assumes that all sub-word data items use
|
|
|
|
// space equal to optSizeForSubWordData, and all other primitive data
|
|
|
|
// items use space according to the type.
|
|
|
|
//
|
2001-08-27 15:50:41 +00:00
|
|
|
unsigned int TargetMachine::findOptimalStorageSize(const Type* ty) const {
|
|
|
|
switch(ty->getPrimitiveID()) {
|
|
|
|
case Type::BoolTyID:
|
|
|
|
case Type::UByteTyID:
|
|
|
|
case Type::SByteTyID:
|
|
|
|
case Type::UShortTyID:
|
|
|
|
case Type::ShortTyID:
|
|
|
|
return optSizeForSubWordData;
|
2001-07-21 12:42:08 +00:00
|
|
|
|
2001-08-27 15:50:41 +00:00
|
|
|
default:
|
|
|
|
return DataLayout.getTypeSize(ty);
|
|
|
|
}
|
2001-07-21 12:42:08 +00:00
|
|
|
}
|
|
|
|
|
2001-07-28 04:09:37 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// class MachineInstructionInfo
|
|
|
|
// Interface to description of machine instructions
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/*ctor*/
|
|
|
|
MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* _desc,
|
2001-08-28 23:09:36 +00:00
|
|
|
unsigned int _descSize,
|
|
|
|
unsigned int _numRealOpCodes)
|
|
|
|
: desc(_desc), descSize(_descSize), numRealOpCodes(_numRealOpCodes)
|
2001-07-28 04:09:37 +00:00
|
|
|
{
|
|
|
|
assert(TargetInstrDescriptors == NULL && desc != NULL);
|
|
|
|
TargetInstrDescriptors = desc; // initialize global variable
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-14 15:43:58 +00:00
|
|
|
MachineInstrInfo::~MachineInstrInfo() {
|
2001-07-28 04:09:37 +00:00
|
|
|
TargetInstrDescriptors = NULL; // reset global variable
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
|
|
|
|
int64_t intValue) const
|
|
|
|
{
|
|
|
|
// First, check if opCode has an immed field.
|
|
|
|
bool isSignExtended;
|
2001-09-14 15:43:58 +00:00
|
|
|
uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
|
|
|
|
if (maxImmedValue != 0) {
|
|
|
|
// Now check if the constant fits
|
|
|
|
if (intValue <= (int64_t) maxImmedValue &&
|
|
|
|
intValue >= -((int64_t) maxImmedValue+1))
|
|
|
|
return true;
|
|
|
|
}
|
2001-07-28 04:09:37 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|