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"
20 // External object describing the machine instructions
21 // Initialized only when the TargetMachine class is created
22 // and reset when that class is destroyed.
24 const TargetInstrDescriptor* TargetInstrDescriptors = 0;
26 TargetInstrInfo::TargetInstrInfo(const TargetInstrDescriptor* Desc,
28 unsigned NumRealOpCodes)
29 : desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) {
30 // FIXME: TargetInstrDescriptors should not be global
31 assert(TargetInstrDescriptors == NULL && desc != NULL
32 && "TargetMachine data structure corrupt; maybe you tried to create another TargetMachine? (only one may exist in a program)");
33 TargetInstrDescriptors = desc; // initialize global variable
36 TargetInstrInfo::~TargetInstrInfo() {
37 TargetInstrDescriptors = NULL; // reset global variable
40 bool TargetInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
41 int64_t intValue) const {
42 // First, check if opCode has an immed field.
44 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
45 if (maxImmedValue != 0)
47 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
48 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
49 // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
51 // Now check if the constant fits
52 if (intValue <= (int64_t) maxImmedValue &&
53 intValue >= -((int64_t) maxImmedValue+1))
60 bool TargetInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
61 assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
62 return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
65 } // End llvm namespace