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 : desc(Desc), NumOpcodes(numOpcodes) {
29 // FIXME: TargetInstrDescriptors should not be global
30 assert(TargetInstrDescriptors == NULL && desc != NULL
31 && "TargetMachine data structure corrupt; maybe you tried to create another TargetMachine? (only one may exist in a program)");
32 TargetInstrDescriptors = desc; // initialize global variable
35 TargetInstrInfo::~TargetInstrInfo() {
36 TargetInstrDescriptors = NULL; // reset global variable
39 bool TargetInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
40 int64_t intValue) const {
41 // First, check if opCode has an immed field.
43 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
44 if (maxImmedValue != 0)
46 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
47 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
48 // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
50 // Now check if the constant fits
51 if (intValue <= (int64_t) maxImmedValue &&
52 intValue >= -((int64_t) maxImmedValue+1))
59 } // End llvm namespace