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 // This file implements the TargetInstrInfo class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "llvm/Target/TargetInstrInfo.h" 00015 #include "llvm/CodeGen/MachineInstr.h" 00016 #include "llvm/Constant.h" 00017 #include "llvm/DerivedTypes.h" 00018 using namespace llvm; 00019 00020 namespace llvm { 00021 // External object describing the machine instructions Initialized only when 00022 // the TargetMachine class is created and reset when that class is destroyed. 00023 // 00024 // FIXME: UGLY SPARCV9 HACK! 00025 const TargetInstrDescriptor* TargetInstrDescriptors = 0; 00026 } 00027 00028 TargetInstrInfo::TargetInstrInfo(const TargetInstrDescriptor* Desc, 00029 unsigned numOpcodes) 00030 : desc(Desc), NumOpcodes(numOpcodes) { 00031 // FIXME: TargetInstrDescriptors should not be global 00032 assert(TargetInstrDescriptors == NULL && desc != NULL 00033 && "TargetMachine data structure corrupt; maybe you tried to create another TargetMachine? (only one may exist in a program)"); 00034 TargetInstrDescriptors = desc; // initialize global variable 00035 } 00036 00037 TargetInstrInfo::~TargetInstrInfo() { 00038 TargetInstrDescriptors = NULL; // reset global variable 00039 } 00040 00041 // FIXME: SPARCV9 SPECIFIC! 00042 bool TargetInstrInfo::constantFitsInImmedField(MachineOpCode opCode, 00043 int64_t intValue) const { 00044 // First, check if opCode has an immed field. 00045 bool isSignExtended; 00046 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended); 00047 if (maxImmedValue != 0) 00048 { 00049 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH 00050 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char. 00051 // See CreateUIntSetInstruction in SparcInstrInfo.cpp. 00052 00053 // Now check if the constant fits 00054 if (intValue <= (int64_t) maxImmedValue && 00055 intValue >= -((int64_t) maxImmedValue+1)) 00056 return true; 00057 } 00058 00059 return false; 00060 } 00061 00062 // commuteInstruction - The default implementation of this method just exchanges 00063 // operand 1 and 2. 00064 MachineInstr *TargetInstrInfo::commuteInstruction(MachineInstr *MI) const { 00065 assert(MI->getOperand(1).isRegister() && MI->getOperand(2).isRegister() && 00066 "This only knows how to commute register operands so far"); 00067 unsigned Reg1 = MI->getOperand(1).getReg(); 00068 unsigned Reg2 = MI->getOperand(1).getReg(); 00069 MI->SetMachineOperandReg(2, Reg1); 00070 MI->SetMachineOperandReg(1, Reg2); 00071 return MI; 00072 }