LLVM API Documentation

TargetInstrInfo.cpp

Go to the documentation of this file.
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 
00042 // commuteInstruction - The default implementation of this method just exchanges
00043 // operand 1 and 2.
00044 MachineInstr *TargetInstrInfo::commuteInstruction(MachineInstr *MI) const {
00045   assert(MI->getOperand(1).isRegister() && MI->getOperand(2).isRegister() &&
00046          "This only knows how to commute register operands so far");
00047   unsigned Reg1 = MI->getOperand(1).getReg();
00048   unsigned Reg2 = MI->getOperand(2).getReg();
00049   MI->getOperand(2).setReg(Reg1);
00050   MI->getOperand(1).setReg(Reg2);
00051   return MI;
00052 }