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 // External object describing the machine instructions
13 // Initialized only when the TargetMachine class is created
14 // and reset when that class is destroyed.
16 const MachineInstrDescriptor* TargetInstrDescriptors = 0;
18 //---------------------------------------------------------------------------
19 // class MachineInstructionInfo
20 // Interface to description of machine instructions
21 //---------------------------------------------------------------------------
24 MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* Desc,
26 unsigned NumRealOpCodes)
27 : desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) {
28 // FIXME: TargetInstrDescriptors should not be global
29 assert(TargetInstrDescriptors == NULL && desc != NULL);
30 TargetInstrDescriptors = desc; // initialize global variable
33 MachineInstrInfo::~MachineInstrInfo() {
34 TargetInstrDescriptors = NULL; // reset global variable
38 bool MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
39 int64_t intValue) const {
40 // First, check if opCode has an immed field.
42 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
43 if (maxImmedValue != 0)
45 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
46 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
47 // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
49 // Now check if the constant fits
50 if (intValue <= (int64_t) maxImmedValue &&
51 intValue >= -((int64_t) maxImmedValue+1))
58 bool MachineInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
59 assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
60 return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));