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 TargetMachine& tgt,
19 const MachineInstrDescriptor* Desc,
21 unsigned NumRealOpCodes)
22 : target(tgt), desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) {
23 // FIXME: TargetInstrDescriptors should not be global
24 assert(TargetInstrDescriptors == NULL && desc != NULL);
25 TargetInstrDescriptors = desc; // initialize global variable
28 MachineInstrInfo::~MachineInstrInfo() {
29 TargetInstrDescriptors = NULL; // reset global variable
33 bool MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
34 int64_t intValue) const {
35 // First, check if opCode has an immed field.
37 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
38 if (maxImmedValue != 0)
40 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
41 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
42 // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
44 // Now check if the constant fits
45 if (intValue <= (int64_t) maxImmedValue &&
46 intValue >= -((int64_t) maxImmedValue+1))
53 bool MachineInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
54 assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
55 return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));