1 //===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Target/TargetInstrInfo.h"
14 #include "llvm/CodeGen/MachineInstr.h"
15 #include "llvm/Constant.h"
16 #include "llvm/DerivedTypes.h"
18 // External object describing the machine instructions
19 // Initialized only when the TargetMachine class is created
20 // and reset when that class is destroyed.
22 const TargetInstrDescriptor* TargetInstrDescriptors = 0;
25 TargetInstrInfo::TargetInstrInfo(const TargetInstrDescriptor* Desc,
27 unsigned NumRealOpCodes)
28 : desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) {
29 // FIXME: TargetInstrDescriptors should not be global
30 assert(TargetInstrDescriptors == NULL && desc != NULL);
31 TargetInstrDescriptors = desc; // initialize global variable
34 TargetInstrInfo::~TargetInstrInfo() {
35 TargetInstrDescriptors = NULL; // reset global variable
38 bool TargetInstrInfo::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 TargetInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
59 assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
60 return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));