2001-09-14 13:34:53 +08:00
|
|
|
//===-- TargetMachine.cpp - General Target Information ---------------------==//
|
|
|
|
//
|
|
|
|
// This file describes the general parts of a Target machine.
|
2001-11-09 10:20:18 +08:00
|
|
|
// This file also implements MachineInstrInfo and MachineCacheInfo.
|
2001-09-14 13:34:53 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-21 20:42:08 +08:00
|
|
|
|
2001-11-09 10:20:18 +08:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2001-09-18 20:58:33 +08:00
|
|
|
#include "llvm/Target/MachineInstrInfo.h"
|
2001-11-09 10:20:18 +08:00
|
|
|
#include "llvm/Target/MachineCacheInfo.h"
|
2001-07-22 07:24:48 +08:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2001-07-21 20:42:08 +08:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
2001-07-28 12:09:37 +08:00
|
|
|
// class TargetMachine
|
2001-07-21 20:42:08 +08:00
|
|
|
//
|
|
|
|
// Purpose:
|
2001-07-28 12:09:37 +08:00
|
|
|
// Machine description.
|
|
|
|
//
|
2001-07-21 20:42:08 +08:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2001-09-18 20:58:33 +08:00
|
|
|
|
2001-07-28 12:09:37 +08: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-09-18 20:58:33 +08: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 20:42:08 +08:00
|
|
|
|
2001-09-18 20:58:33 +08:00
|
|
|
default:
|
|
|
|
return DataLayout.getTypeSize(ty);
|
|
|
|
}
|
2001-07-21 20:42:08 +08:00
|
|
|
}
|
|
|
|
|
2001-07-28 12:09:37 +08:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// class MachineInstructionInfo
|
|
|
|
// Interface to description of machine instructions
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/*ctor*/
|
2001-11-08 13:15:08 +08:00
|
|
|
MachineInstrInfo::MachineInstrInfo(const TargetMachine& tgt,
|
|
|
|
const MachineInstrDescriptor* _desc,
|
2001-08-29 07:09:36 +08:00
|
|
|
unsigned int _descSize,
|
|
|
|
unsigned int _numRealOpCodes)
|
2001-11-08 13:15:08 +08:00
|
|
|
: target(tgt),
|
|
|
|
desc(_desc), descSize(_descSize), numRealOpCodes(_numRealOpCodes)
|
2001-07-28 12:09:37 +08:00
|
|
|
{
|
2001-09-15 00:08:12 +08:00
|
|
|
// FIXME: TargetInstrDescriptors should not be global
|
2001-07-28 12:09:37 +08:00
|
|
|
assert(TargetInstrDescriptors == NULL && desc != NULL);
|
|
|
|
TargetInstrDescriptors = desc; // initialize global variable
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-18 20:58:33 +08:00
|
|
|
MachineInstrInfo::~MachineInstrInfo()
|
|
|
|
{
|
2001-07-28 12:09:37 +08: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 23:43:58 +08:00
|
|
|
uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
|
2001-09-18 20:58:33 +08:00
|
|
|
if (maxImmedValue != 0)
|
|
|
|
{
|
|
|
|
// Now check if the constant fits
|
|
|
|
if (intValue <= (int64_t) maxImmedValue &&
|
|
|
|
intValue >= -((int64_t) maxImmedValue+1))
|
|
|
|
return true;
|
|
|
|
}
|
2001-07-28 12:09:37 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2001-11-09 10:20:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// class MachineCacheInfo
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
// Describes properties of the target cache architecture.
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*ctor*/
|
|
|
|
MachineCacheInfo::MachineCacheInfo(const TargetMachine& tgt)
|
|
|
|
: target(tgt)
|
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MachineCacheInfo::Initialize()
|
|
|
|
{
|
|
|
|
numLevels = 2;
|
|
|
|
cacheLineSizes.push_back(16); cacheLineSizes.push_back(32);
|
|
|
|
cacheSizes.push_back(1 << 15); cacheSizes.push_back(1 << 20);
|
|
|
|
cacheAssoc.push_back(1); cacheAssoc.push_back(4);
|
|
|
|
}
|