TargetInstrInfo.h revision 4683f9bfb4dc2f5557e8a7a229912e7f2ed366ca
1cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//===-- llvm/Target/InstrInfo.h - Target Instruction Information --*-C++-*-==// 2cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// 3cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// This file describes the target machine instructions to the code generator. 4cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// 5cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//===---------------------------------------------------------------------===// 6cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com 7cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com#ifndef LLVM_TARGET_MACHINEINSTRINFO_H 8cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com#define LLVM_TARGET_MACHINEINSTRINFO_H 9cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com 108cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "Support/DataTypes.h" 118cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include <vector> 128cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 138cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass MachineInstrDescriptor; 148cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass MachineInstr; 158cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass TargetMachine; 168cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass Value; 178cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass Instruction; 188cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass Constant; 198cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass Function; 208cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass MachineCodeForInstruction; 218cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 228cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com//--------------------------------------------------------------------------- 238cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// Data types used to define information about a single machine instruction 248cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com//--------------------------------------------------------------------------- 258cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 268cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comtypedef int MachineOpCode; 278cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comtypedef unsigned InstrSchedClass; 288cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 298cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst MachineOpCode INVALID_MACHINE_OPCODE = -1; 308cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 318cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 328cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// Global variable holding an array of descriptors for machine instructions. 338cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// The actual object needs to be created separately for each target machine. 348cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// This variable is initialized and reset by class MachineInstrInfo. 358cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// 368cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// FIXME: This should be a property of the target so that more than one target 378cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// at a time can be active... 388cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// 398cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comextern const MachineInstrDescriptor *TargetInstrDescriptors; 408cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 418cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 428cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com//--------------------------------------------------------------------------- 438cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// struct MachineInstrDescriptor: 448cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// Predefined information about each machine instruction. 458cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// Designed to initialized statically. 468cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// 478cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// class MachineInstructionInfo 488cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// Interface to description of machine instructions 498cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// 508cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com//--------------------------------------------------------------------------- 518cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 528cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst unsigned M_NOP_FLAG = 1 << 0; 538cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst unsigned M_BRANCH_FLAG = 1 << 1; 548cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst unsigned M_CALL_FLAG = 1 << 2; 558cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst unsigned M_RET_FLAG = 1 << 3; 568cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst unsigned M_ARITH_FLAG = 1 << 4; 578cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst unsigned M_CC_FLAG = 1 << 6; 588cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst unsigned M_LOGICAL_FLAG = 1 << 6; 598cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst unsigned M_INT_FLAG = 1 << 7; 608cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst unsigned M_FLOAT_FLAG = 1 << 8; 618cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst unsigned M_CONDL_FLAG = 1 << 9; 628cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst unsigned M_LOAD_FLAG = 1 << 10; 638cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst unsigned M_PREFETCH_FLAG = 1 << 11; 648cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst unsigned M_STORE_FLAG = 1 << 12; 658cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst unsigned M_DUMMY_PHI_FLAG = 1 << 13; 668cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comconst unsigned M_PSEUDO_FLAG = 1 << 14; 678cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 688cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 698cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comstruct MachineInstrDescriptor { 708cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const char * Name; // Assembly language mnemonic for the opcode. 718cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com int numOperands; // Number of args; -1 if variable #args 728cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com int resultPos; // Position of the result; -1 if no result 738cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned maxImmedConst; // Largest +ve constant in IMMMED field or 0. 748cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool immedIsSignExtended; // Is IMMED field sign-extended? If so, 758cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // smallest -ve value is -(maxImmedConst+1). 768cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned numDelaySlots; // Number of delay slots after instruction 778cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned latency; // Latency in machine cycles 788cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com InstrSchedClass schedClass; // enum identifying instr sched class 798cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned iclass; // flags identifying machine instr class 808cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com}; 818cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 828cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 838cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass MachineInstrInfo { 848cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const MachineInstrDescriptor* desc; // raw array to allow static init'n 858cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned descSize; // number of entries in the desc array 868cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned numRealOpCodes; // number of non-dummy op codes 878cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 888cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineInstrInfo(const MachineInstrInfo &); // DO NOT IMPLEMENT 898cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com void operator=(const MachineInstrInfo &); // DO NOT IMPLEMENT 908cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.compublic: 918cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineInstrInfo(const MachineInstrDescriptor *desc, unsigned descSize, 928cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned numRealOpCodes); 938cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual ~MachineInstrInfo(); 948cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 958cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned getNumRealOpCodes() const { return numRealOpCodes; } 968cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned getNumTotalOpCodes() const { return descSize; } 978cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 988cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com /// get - Return the machine instruction descriptor that corresponds to the 998cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com /// specified instruction opcode. 1008cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com /// 1018cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const MachineInstrDescriptor& get(MachineOpCode opCode) const { 1028cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com assert(opCode >= 0 && opCode < (int)descSize); 1038cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return desc[opCode]; 1048cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1058cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1068cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const char *getName(MachineOpCode opCode) const { 1078cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).Name; 1088cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1098cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1108cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com int getNumOperands(MachineOpCode opCode) const { 1118cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).numOperands; 1128cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1138cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1148cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com int getResultPos(MachineOpCode opCode) const { 1158cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).resultPos; 1168cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1178cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1188cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned getNumDelaySlots(MachineOpCode opCode) const { 1198cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).numDelaySlots; 1208cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1218cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1228cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com InstrSchedClass getSchedClass(MachineOpCode opCode) const { 1238cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).schedClass; 1248cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1258cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1268cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 1278cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Query instruction class flags according to the machine-independent 1288cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // flags listed above. 1298cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 1308cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned getIClass(MachineOpCode opCode) const { 1318cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass; 1328cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1338cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isNop(MachineOpCode opCode) const { 1348cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_NOP_FLAG; 1358cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1368cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isBranch(MachineOpCode opCode) const { 1378cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_BRANCH_FLAG; 1388cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1398cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isCall(MachineOpCode opCode) const { 1408cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_CALL_FLAG; 1418cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1428cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isReturn(MachineOpCode opCode) const { 1438cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_RET_FLAG; 1448cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1458cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isControlFlow(MachineOpCode opCode) const { 1468cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_BRANCH_FLAG 1478cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com || get(opCode).iclass & M_CALL_FLAG 1488cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com || get(opCode).iclass & M_RET_FLAG; 1498cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1508cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isArith(MachineOpCode opCode) const { 1518cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_ARITH_FLAG; 1528cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1538cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isCCInstr(MachineOpCode opCode) const { 1548cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_CC_FLAG; 1558cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1568cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isLogical(MachineOpCode opCode) const { 1578cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_LOGICAL_FLAG; 1588cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1598cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isIntInstr(MachineOpCode opCode) const { 1608cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_INT_FLAG; 1618cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1628cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isFloatInstr(MachineOpCode opCode) const { 1638cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_FLOAT_FLAG; 1648cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1658cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isConditional(MachineOpCode opCode) const { 1668cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_CONDL_FLAG; 1678cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1688cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isLoad(MachineOpCode opCode) const { 1698cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_LOAD_FLAG; 1708cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1718cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isPrefetch(MachineOpCode opCode) const { 1728cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_PREFETCH_FLAG; 1738cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1748cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isLoadOrPrefetch(MachineOpCode opCode) const { 1758cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_LOAD_FLAG 1768cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com || get(opCode).iclass & M_PREFETCH_FLAG; 1778cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1788cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isStore(MachineOpCode opCode) const { 1798cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_STORE_FLAG; 1808cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1818cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isMemoryAccess(MachineOpCode opCode) const { 1828cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_LOAD_FLAG 1838cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com || get(opCode).iclass & M_PREFETCH_FLAG 1848cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com || get(opCode).iclass & M_STORE_FLAG; 1858cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1868cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isDummyPhiInstr(const MachineOpCode opCode) const { 1878cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_DUMMY_PHI_FLAG; 1888cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1898cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool isPseudoInstr(const MachineOpCode opCode) const { 1908cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).iclass & M_PSEUDO_FLAG; 1918cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 1928cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 1938cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Check if an instruction can be issued before its operands are ready, 1948cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // or if a subsequent instruction that uses its result can be issued 1958cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // before the results are ready. 1968cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Default to true since most instructions on many architectures allow this. 1978cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 1988cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual bool hasOperandInterlock(MachineOpCode opCode) const { 1998cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return true; 2008cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 2018cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 2028cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual bool hasResultInterlock(MachineOpCode opCode) const { 2038cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return true; 2048cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 2058cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 2068cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 2078cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Latencies for individual instructions and instruction pairs 2088cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 2098cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual int minLatency(MachineOpCode opCode) const { 2108cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).latency; 2118cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 2128cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 2138cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual int maxLatency(MachineOpCode opCode) const { 2148cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).latency; 2158cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 2168cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 2178cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 2188cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Which operand holds an immediate constant? Returns -1 if none 2198cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 2208cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual int getImmedConstantPos(MachineOpCode opCode) const { 2218cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return -1; // immediate position is machine specific, so say -1 == "none" 2228cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 2238cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 2248cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Check if the specified constant fits in the immediate field 2258cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // of this machine instruction 2268cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 2278cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual bool constantFitsInImmedField(MachineOpCode opCode, 2288cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com int64_t intValue) const; 2298cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 2308cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Return the largest +ve constant that can be held in the IMMMED field 2318cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // of this machine instruction. 2328cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // isSignExtended is set to true if the value is sign-extended before use 2338cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // (this is true for all immediate fields in SPARC instructions). 2348cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Return 0 if the instruction has no IMMED field. 2358cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 2368cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual uint64_t maxImmedConstant(MachineOpCode opCode, 2378cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com bool &isSignExtended) const { 2388cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com isSignExtended = get(opCode).immedIsSignExtended; 2398cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return get(opCode).maxImmedConst; 2408cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 2418cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 2428cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com //------------------------------------------------------------------------- 2438cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Queries about representation of LLVM quantities (e.g., constants) 2448cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com //------------------------------------------------------------------------- 2458cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 2468cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com /// ConstantTypeMustBeLoaded - Test if this type of constant must be loaded 2478cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com /// from memory into a register, i.e., cannot be set bitwise in register and 2488cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com /// cannot use immediate fields of instructions. Note that this only makes 2498cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com /// sense for primitive types. 2508cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com /// 2518cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual bool ConstantTypeMustBeLoaded(const Constant* CV) const; 2528cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 2538cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Test if this constant may not fit in the immediate field of the 2548cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // machine instructions (probably) generated for this instruction. 2558cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 2568cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual bool ConstantMayNotFitInImmedField(const Constant* CV, 2578cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com const Instruction* I) const { 2588cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com return true; // safe but very conservative 2598cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com } 2608cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 2618cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com //------------------------------------------------------------------------- 2628cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Code generation support for creating individual machine instructions 2638cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com //------------------------------------------------------------------------- 2648cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 2658cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Get certain common op codes for the current target. this and all the 2668cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Create* methods below should be moved to a machine code generation class 2678cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 2688cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual MachineOpCode getNOPOpCode() const = 0; 2698cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 2708cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Create an instruction sequence to put the constant `val' into 2718cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // the virtual register `dest'. `val' may be a Constant or a 2728cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // GlobalValue, viz., the constant address of a global variable or function. 2738cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // The generated instructions are returned in `mvec'. 2748cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Any temp. registers (TmpInstruction) created are recorded in mcfi. 2758cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Symbolic constants or constants that must be accessed from memory 2768cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // are added to the constant pool via MachineFunction::get(F). 2778cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 2788cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual void CreateCodeToLoadConst(const TargetMachine& target, 2798cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Function* F, 2808cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Value* val, 2818cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Instruction* dest, 2828cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com std::vector<MachineInstr*>& mvec, 2838cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineCodeForInstruction& mcfi) const=0; 2848cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 2858cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Create an instruction sequence to copy an integer value `val' 2868cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // to a floating point value `dest' by copying to memory and back. 2878cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // val must be an integral type. dest must be a Float or Double. 2888cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // The generated instructions are returned in `mvec'. 2898cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Any temp. registers (TmpInstruction) created are recorded in mcfi. 2908cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Any stack space required is allocated via mcff. 2918cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 2928cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual void CreateCodeToCopyIntToFloat(const TargetMachine& target, 2938cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Function* F, 2948cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Value* val, 2958cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Instruction* dest, 2968cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com std::vector<MachineInstr*>& mvec, 2978cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineCodeForInstruction& mcfi)const=0; 2988cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 2998cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Similarly, create an instruction sequence to copy an FP value 3008cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // `val' to an integer value `dest' by copying to memory and back. 3018cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // The generated instructions are returned in `mvec'. 3028cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Any temp. registers (TmpInstruction) created are recorded in mcfi. 3038cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Any stack space required is allocated via mcff. 3048cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 3058cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual void CreateCodeToCopyFloatToInt(const TargetMachine& target, 3068cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Function* F, 3078cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Value* val, 3088cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Instruction* dest, 3098cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com std::vector<MachineInstr*>& mvec, 3108cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineCodeForInstruction& mcfi)const=0; 3118cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 3128cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Create instruction(s) to copy src to dest, for arbitrary types 3138cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // The generated instructions are returned in `mvec'. 3148cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Any temp. registers (TmpInstruction) created are recorded in mcfi. 3158cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Any stack space required is allocated via mcff. 3168cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 3178cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual void CreateCopyInstructionsByType(const TargetMachine& target, 3188cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Function* F, 3198cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Value* src, 3208cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Instruction* dest, 3218cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com std::vector<MachineInstr*>& mvec, 3228cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineCodeForInstruction& mcfi)const=0; 3238cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 3248cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Create instruction sequence to produce a sign-extended register value 3258cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // from an arbitrary sized value (sized in bits, not bytes). 3268cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // The generated instructions are appended to `mvec'. 3278cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Any temp. registers (TmpInstruction) created are recorded in mcfi. 3288cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Any stack space required is allocated via mcff. 3298cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 3308cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual void CreateSignExtensionInstructions(const TargetMachine& target, 3318cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Function* F, 3328cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Value* srcVal, 3338cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Value* destVal, 3348cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned numLowBits, 3358cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com std::vector<MachineInstr*>& mvec, 3368cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineCodeForInstruction& mcfi) const=0; 3378cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 3388cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Create instruction sequence to produce a zero-extended register value 3398cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // from an arbitrary sized value (sized in bits, not bytes). 3408cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // The generated instructions are appended to `mvec'. 3418cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Any temp. registers (TmpInstruction) created are recorded in mcfi. 3428cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // Any stack space required is allocated via mcff. 3438cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com // 3448cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com virtual void CreateZeroExtensionInstructions(const TargetMachine& target, 3458cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Function* F, 3468cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Value* srcVal, 3478cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com Value* destVal, 3488cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com unsigned srcSizeInBits, 3498cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com std::vector<MachineInstr*>& mvec, 3508cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com MachineCodeForInstruction& mcfi) const=0; 3518cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com}; 3528cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com 3538cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#endif 3548cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com