1 //===-- TargetMachine.cpp - General Target Information ---------------------==//
3 // This file describes the general parts of a Target machine.
4 // This file also implements the InstInfo interface as well...
6 //===----------------------------------------------------------------------===//
8 #include "llvm/Target/InstInfo.h"
9 #include "llvm/DerivedTypes.h"
11 //---------------------------------------------------------------------------
12 // class TargetMachine
15 // Machine description.
17 //---------------------------------------------------------------------------
19 // function TargetMachine::findOptimalStorageSize
22 // 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.
26 unsigned int TargetMachine::findOptimalStorageSize(const Type* ty) const {
27 switch(ty->getPrimitiveID()) {
31 case Type::UShortTyID:
33 return optSizeForSubWordData;
36 return DataLayout.getTypeSize(ty);
41 //---------------------------------------------------------------------------
42 // class MachineInstructionInfo
43 // Interface to description of machine instructions
44 //---------------------------------------------------------------------------
48 MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* _desc,
49 unsigned int _descSize,
50 unsigned int _numRealOpCodes)
51 : desc(_desc), descSize(_descSize), numRealOpCodes(_numRealOpCodes)
53 assert(TargetInstrDescriptors == NULL && desc != NULL);
54 TargetInstrDescriptors = desc; // initialize global variable
58 MachineInstrInfo::~MachineInstrInfo() {
59 TargetInstrDescriptors = NULL; // reset global variable
64 MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
65 int64_t intValue) const
67 // First, check if opCode has an immed field.
69 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
70 if (maxImmedValue != 0) {
71 // Now check if the constant fits
72 if (intValue <= (int64_t) maxImmedValue &&
73 intValue >= -((int64_t) maxImmedValue+1))