LLVM API Documentation
00001 //===-- TargetInstrInfo.cpp - Target Instruction Information --------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // 00011 //===----------------------------------------------------------------------===// 00012 00013 #include "llvm/Target/TargetInstrInfo.h" 00014 #include "llvm/CodeGen/MachineInstr.h" 00015 #include "llvm/Constant.h" 00016 #include "llvm/DerivedTypes.h" 00017 00018 namespace llvm { 00019 00020 // External object describing the machine instructions 00021 // Initialized only when the TargetMachine class is created 00022 // and reset when that class is destroyed. 00023 // 00024 const TargetInstrDescriptor* TargetInstrDescriptors = 0; 00025 00026 TargetInstrInfo::TargetInstrInfo(const TargetInstrDescriptor* Desc, 00027 unsigned numOpcodes) 00028 : desc(Desc), NumOpcodes(numOpcodes) { 00029 // FIXME: TargetInstrDescriptors should not be global 00030 assert(TargetInstrDescriptors == NULL && desc != NULL 00031 && "TargetMachine data structure corrupt; maybe you tried to create another TargetMachine? (only one may exist in a program)"); 00032 TargetInstrDescriptors = desc; // initialize global variable 00033 } 00034 00035 TargetInstrInfo::~TargetInstrInfo() { 00036 TargetInstrDescriptors = NULL; // reset global variable 00037 } 00038 00039 bool TargetInstrInfo::constantFitsInImmedField(MachineOpCode opCode, 00040 int64_t intValue) const { 00041 // First, check if opCode has an immed field. 00042 bool isSignExtended; 00043 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended); 00044 if (maxImmedValue != 0) 00045 { 00046 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH 00047 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char. 00048 // See CreateUIntSetInstruction in SparcInstrInfo.cpp. 00049 00050 // Now check if the constant fits 00051 if (intValue <= (int64_t) maxImmedValue && 00052 intValue >= -((int64_t) maxImmedValue+1)) 00053 return true; 00054 } 00055 00056 return false; 00057 } 00058 00059 } // End llvm namespace