1 //===-- TargetMachine.cpp - General Target Information ---------------------==//
3 // This file describes the general parts of a Target machine.
4 // This file also implements MachineInstrInfo and MachineCacheInfo.
6 //===----------------------------------------------------------------------===//
8 #include "llvm/Target/MachineInstrInfo.h"
9 #include "llvm/Constant.h"
10 #include "llvm/DerivedTypes.h"
12 //---------------------------------------------------------------------------
13 // class MachineInstructionInfo
14 // Interface to description of machine instructions
15 //---------------------------------------------------------------------------
18 MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* Desc,
20 unsigned NumRealOpCodes)
21 : desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) {
22 // FIXME: TargetInstrDescriptors should not be global
23 assert(TargetInstrDescriptors == NULL && desc != NULL);
24 TargetInstrDescriptors = desc; // initialize global variable
27 MachineInstrInfo::~MachineInstrInfo() {
28 TargetInstrDescriptors = NULL; // reset global variable
32 bool MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
33 int64_t intValue) const {
34 // First, check if opCode has an immed field.
36 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
37 if (maxImmedValue != 0)
39 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
40 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
41 // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
43 // Now check if the constant fits
44 if (intValue <= (int64_t) maxImmedValue &&
45 intValue >= -((int64_t) maxImmedValue+1))
52 bool MachineInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
53 assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
54 return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));