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/MachineInstrInfo.h"
9 #include "llvm/DerivedTypes.h"
11 //---------------------------------------------------------------------------
12 // class TargetMachine
15 // Machine description.
17 //---------------------------------------------------------------------------
20 // function TargetMachine::findOptimalStorageSize
23 // 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.
28 TargetMachine::findOptimalStorageSize(const Type* ty) const
30 switch(ty->getPrimitiveID())
35 case Type::UShortTyID:
37 return optSizeForSubWordData;
40 return DataLayout.getTypeSize(ty);
45 //---------------------------------------------------------------------------
46 // class MachineInstructionInfo
47 // Interface to description of machine instructions
48 //---------------------------------------------------------------------------
52 MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* _desc,
53 unsigned int _descSize,
54 unsigned int _numRealOpCodes)
55 : desc(_desc), descSize(_descSize), numRealOpCodes(_numRealOpCodes)
57 // FIXME: TargetInstrDescriptors should not be global
58 assert(TargetInstrDescriptors == NULL && desc != NULL);
59 TargetInstrDescriptors = desc; // initialize global variable
63 MachineInstrInfo::~MachineInstrInfo()
65 TargetInstrDescriptors = NULL; // reset global variable
70 MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
71 int64_t intValue) const
73 // First, check if opCode has an immed field.
75 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
76 if (maxImmedValue != 0)
78 // Now check if the constant fits
79 if (intValue <= (int64_t) maxImmedValue &&
80 intValue >= -((int64_t) maxImmedValue+1))