1 //===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
4 //===----------------------------------------------------------------------===//
6 #include "llvm/Target/TargetInstrInfo.h"
7 #include "llvm/CodeGen/MachineInstr.h"
8 #include "llvm/Constant.h"
9 #include "llvm/DerivedTypes.h"
11 // External object describing the machine instructions
12 // Initialized only when the TargetMachine class is created
13 // and reset when that class is destroyed.
15 const TargetInstrDescriptor* TargetInstrDescriptors = 0;
18 TargetInstrInfo::TargetInstrInfo(const TargetInstrDescriptor* 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 TargetInstrInfo::~TargetInstrInfo() {
28 TargetInstrDescriptors = NULL; // reset global variable
31 bool TargetInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
32 int64_t intValue) const {
33 // First, check if opCode has an immed field.
35 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
36 if (maxImmedValue != 0)
38 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
39 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
40 // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
42 // Now check if the constant fits
43 if (intValue <= (int64_t) maxImmedValue &&
44 intValue >= -((int64_t) maxImmedValue+1))
51 bool TargetInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
52 assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
53 return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));