LLVM API Documentation

HexagonMCInst.cpp
Go to the documentation of this file.
00001 //===- HexagonMCInst.cpp - Hexagon sub-class of MCInst --------------------===//
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 class extends MCInst to allow some Hexagon VLIW annotations.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "HexagonInstrInfo.h"
00015 #include "MCTargetDesc/HexagonBaseInfo.h"
00016 #include "MCTargetDesc/HexagonMCInst.h"
00017 #include "MCTargetDesc/HexagonMCTargetDesc.h"
00018 
00019 using namespace llvm;
00020 
00021 // Return the slots used by the insn.
00022 unsigned HexagonMCInst::getUnits(const HexagonTargetMachine* TM) const {
00023   const HexagonInstrInfo *QII = TM->getSubtargetImpl()->getInstrInfo();
00024   const InstrItineraryData *II =
00025       TM->getSubtargetImpl()->getInstrItineraryData();
00026   const InstrStage*
00027     IS = II->beginStage(QII->get(this->getOpcode()).getSchedClass());
00028 
00029   return (IS->getUnits());
00030 }
00031 
00032 // Return the Hexagon ISA class for the insn.
00033 unsigned HexagonMCInst::getType() const {
00034   const uint64_t F = MCID->TSFlags;
00035 
00036   return ((F >> HexagonII::TypePos) & HexagonII::TypeMask);
00037 }
00038 
00039 // Return whether the insn is an actual insn.
00040 bool HexagonMCInst::isCanon() const {
00041   return (!MCID->isPseudo() &&
00042           !isPrefix() &&
00043           getType() != HexagonII::TypeENDLOOP);
00044 }
00045 
00046 // Return whether the insn is a prefix.
00047 bool HexagonMCInst::isPrefix() const {
00048   return (getType() == HexagonII::TypePREFIX);
00049 }
00050 
00051 // Return whether the insn is solo, i.e., cannot be in a packet.
00052 bool HexagonMCInst::isSolo() const {
00053   const uint64_t F = MCID->TSFlags;
00054   return ((F >> HexagonII::SoloPos) & HexagonII::SoloMask);
00055 }
00056 
00057 // Return whether the insn is a new-value consumer.
00058 bool HexagonMCInst::isNewValue() const {
00059   const uint64_t F = MCID->TSFlags;
00060   return ((F >> HexagonII::NewValuePos) & HexagonII::NewValueMask);
00061 }
00062 
00063 // Return whether the instruction is a legal new-value producer.
00064 bool HexagonMCInst::hasNewValue() const {
00065   const uint64_t F = MCID->TSFlags;
00066   return ((F >> HexagonII::hasNewValuePos) & HexagonII::hasNewValueMask);
00067 }
00068 
00069 // Return the operand that consumes or produces a new value.
00070 const MCOperand& HexagonMCInst::getNewValue() const {
00071   const uint64_t F = MCID->TSFlags;
00072   const unsigned O = (F >> HexagonII::NewValueOpPos) &
00073                      HexagonII::NewValueOpMask;
00074   const MCOperand& MCO = getOperand(O);
00075 
00076   assert ((isNewValue() || hasNewValue()) && MCO.isReg());
00077   return (MCO);
00078 }
00079 
00080 // Return whether the instruction needs to be constant extended.
00081 // 1) Always return true if the instruction has 'isExtended' flag set.
00082 //
00083 // isExtendable:
00084 // 2) For immediate extended operands, return true only if the value is
00085 //    out-of-range.
00086 // 3) For global address, always return true.
00087 
00088 bool HexagonMCInst::isConstExtended(void) const {
00089   if (isExtended())
00090     return true;
00091 
00092   if (!isExtendable())
00093     return false;
00094 
00095   short ExtOpNum = getCExtOpNum();
00096   int MinValue   = getMinValue();
00097   int MaxValue   = getMaxValue();
00098   const MCOperand& MO = getOperand(ExtOpNum);
00099 
00100   // We could be using an instruction with an extendable immediate and shoehorn
00101   // a global address into it. If it is a global address it will be constant
00102   // extended. We do this for COMBINE.
00103   // We currently only handle isGlobal() because it is the only kind of
00104   // object we are going to end up with here for now.
00105   // In the future we probably should add isSymbol(), etc.
00106   if (MO.isExpr())
00107     return true;
00108 
00109   // If the extendable operand is not 'Immediate' type, the instruction should
00110   // have 'isExtended' flag set.
00111   assert(MO.isImm() && "Extendable operand must be Immediate type");
00112 
00113   int ImmValue = MO.getImm();
00114   return (ImmValue < MinValue || ImmValue > MaxValue);
00115 }
00116 
00117 // Return whether the instruction must be always extended.
00118 bool HexagonMCInst::isExtended(void) const {
00119   const uint64_t F = MCID->TSFlags;
00120   return (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask;
00121 }
00122 
00123 // Return true if the instruction may be extended based on the operand value.
00124 bool HexagonMCInst::isExtendable(void) const {
00125   const uint64_t F = MCID->TSFlags;
00126   return (F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask;
00127 }
00128 
00129 // Return number of bits in the constant extended operand.
00130 unsigned HexagonMCInst::getBitCount(void) const {
00131   const uint64_t F = MCID->TSFlags;
00132   return ((F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask);
00133 }
00134 
00135 // Return constant extended operand number.
00136 unsigned short HexagonMCInst::getCExtOpNum(void) const {
00137   const uint64_t F = MCID->TSFlags;
00138   return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask);
00139 }
00140 
00141 // Return whether the operand can be constant extended.
00142 bool HexagonMCInst::isOperandExtended(const unsigned short OperandNum) const {
00143   const uint64_t F = MCID->TSFlags;
00144   return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask)
00145           == OperandNum;
00146 }
00147 
00148 // Return the min value that a constant extendable operand can have
00149 // without being extended.
00150 int HexagonMCInst::getMinValue(void) const {
00151   const uint64_t F = MCID->TSFlags;
00152   unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
00153                     & HexagonII::ExtentSignedMask;
00154   unsigned bits =  (F >> HexagonII::ExtentBitsPos)
00155                     & HexagonII::ExtentBitsMask;
00156 
00157   if (isSigned) // if value is signed
00158     return -1U << (bits - 1);
00159   else
00160     return 0;
00161 }
00162 
00163 // Return the max value that a constant extendable operand can have
00164 // without being extended.
00165 int HexagonMCInst::getMaxValue(void) const {
00166   const uint64_t F = MCID->TSFlags;
00167   unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
00168                     & HexagonII::ExtentSignedMask;
00169   unsigned bits =  (F >> HexagonII::ExtentBitsPos)
00170                     & HexagonII::ExtentBitsMask;
00171 
00172   if (isSigned) // if value is signed
00173     return ~(-1U << (bits - 1));
00174   else
00175     return ~(-1U << bits);
00176 }