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 is distributed under the University of Illinois Open Source
00006 // 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/Target/TargetAsmInfo.h"
00016 #include "llvm/Target/TargetRegisterInfo.h"
00017 #include "llvm/Support/ErrorHandling.h"
00018 using namespace llvm;
00019 
00020 //===----------------------------------------------------------------------===//
00021 //  TargetOperandInfo
00022 //===----------------------------------------------------------------------===//
00023 
00024 /// getRegClass - Get the register class for the operand, handling resolution
00025 /// of "symbolic" pointer register classes etc.  If this is not a register
00026 /// operand, this returns null.
00027 const TargetRegisterClass *
00028 TargetOperandInfo::getRegClass(const TargetRegisterInfo *TRI) const {
00029   if (isLookupPtrRegClass())
00030     return TRI->getPointerRegClass(RegClass);
00031   return TRI->getRegClass(RegClass);
00032 }
00033 
00034 //===----------------------------------------------------------------------===//
00035 //  TargetInstrInfo
00036 //===----------------------------------------------------------------------===//
00037 
00038 TargetInstrInfo::TargetInstrInfo(const TargetInstrDesc* Desc,
00039                                  unsigned numOpcodes)
00040   : Descriptors(Desc), NumOpcodes(numOpcodes) {
00041 }
00042 
00043 TargetInstrInfo::~TargetInstrInfo() {
00044 }
00045 
00046 /// insertNoop - Insert a noop into the instruction stream at the specified
00047 /// point.
00048 void TargetInstrInfo::insertNoop(MachineBasicBlock &MBB, 
00049                                  MachineBasicBlock::iterator MI) const {
00050   llvm_unreachable("Target didn't implement insertNoop!");
00051 }
00052 
00053 
00054 bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
00055   const TargetInstrDesc &TID = MI->getDesc();
00056   if (!TID.isTerminator()) return false;
00057   
00058   // Conditional branch is a special case.
00059   if (TID.isBranch() && !TID.isBarrier())
00060     return true;
00061   if (!TID.isPredicable())
00062     return true;
00063   return !isPredicated(MI);
00064 }
00065 
00066 
00067 /// Measure the specified inline asm to determine an approximation of its
00068 /// length.
00069 /// Comments (which run till the next SeparatorChar or newline) do not
00070 /// count as an instruction.
00071 /// Any other non-whitespace text is considered an instruction, with
00072 /// multiple instructions separated by SeparatorChar or newlines.
00073 /// Variable-length instructions are not handled here; this function
00074 /// may be overloaded in the target code to do that.
00075 unsigned TargetInstrInfo::getInlineAsmLength(const char *Str,
00076                                              const TargetAsmInfo &TAI) const {
00077   
00078   
00079   // Count the number of instructions in the asm.
00080   bool atInsnStart = true;
00081   unsigned Length = 0;
00082   for (; *Str; ++Str) {
00083     if (*Str == '\n' || *Str == TAI.getSeparatorChar())
00084       atInsnStart = true;
00085     if (atInsnStart && !isspace(*Str)) {
00086       Length += TAI.getMaxInstLength();
00087       atInsnStart = false;
00088     }
00089     if (atInsnStart && strncmp(Str, TAI.getCommentString(),
00090                                strlen(TAI.getCommentString())) == 0)
00091       atInsnStart = false;
00092   }
00093   
00094   return Length;
00095 }