CodeGenInstruction.h revision 01855071e24e0e3e75306b82267d3ad0b13a0c15
1ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner//===- CodeGenInstruction.h - Instruction Class Wrapper ---------*- C++ -*-===// 23da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman// 3ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner// The LLVM Compiler Infrastructure 4ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner// 53060910e290949a9ac5eda8726d030790c4d60ffChris Lattner// This file is distributed under the University of Illinois Open Source 63060910e290949a9ac5eda8726d030790c4d60ffChris Lattner// License. See LICENSE.TXT for details. 73da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman// 8ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner//===----------------------------------------------------------------------===// 9ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner// 10ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner// This file defines a wrapper class for the 'Instruction' TableGen class. 11ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner// 12ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner//===----------------------------------------------------------------------===// 13ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner 14ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner#ifndef CODEGEN_INSTRUCTION_H 15ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner#define CODEGEN_INSTRUCTION_H 16ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner 1787c5905e0b6f551e21c9a96f1b6418920d908210Chris Lattner#include "llvm/CodeGen/ValueTypes.h" 18ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner#include <string> 19ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner#include <vector> 20ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner#include <utility> 21ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner 22ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattnernamespace llvm { 23ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner class Record; 2465303d6bd777b76735ef179870678a1d14671c54Chris Lattner class DagInit; 259414ae52911f1d62cabd5108e0381b9d17476157Chris Lattner class CodeGenTarget; 26ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner 27d41b30def3181bce4bf87e8bde664d15663165d0Jeff Cohen class CodeGenInstruction { 28d41b30def3181bce4bf87e8bde664d15663165d0Jeff Cohen public: 29ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner Record *TheDef; // The actual record defining this instruction. 30ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner std::string Namespace; // The namespace the instruction is in. 31ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner 32ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner /// AsmString - The format string used to emit a .s file for the 33ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner /// instruction. 34ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner std::string AsmString; 359ed2cee1057e2df3a4305b9c818aa577c8504f59Jim Grosbach 36a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner class ConstraintInfo { 37a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner enum { None, EarlyClobber, Tied } Kind; 38a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner unsigned OtherTiedOperand; 39a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner public: 40a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner ConstraintInfo() : Kind(None) {} 41a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner 42a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner static ConstraintInfo getEarlyClobber() { 43a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner ConstraintInfo I; 44a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner I.Kind = EarlyClobber; 45e555c9f4a54fd854af13f117fc0650ada3df3d24Chris Lattner I.OtherTiedOperand = 0; 46a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner return I; 47a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner } 489ed2cee1057e2df3a4305b9c818aa577c8504f59Jim Grosbach 49a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner static ConstraintInfo getTied(unsigned Op) { 50a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner ConstraintInfo I; 51a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner I.Kind = Tied; 52a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner I.OtherTiedOperand = Op; 53a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner return I; 54a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner } 559ed2cee1057e2df3a4305b9c818aa577c8504f59Jim Grosbach 56a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner bool isNone() const { return Kind == None; } 57a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner bool isEarlyClobber() const { return Kind == EarlyClobber; } 58a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner bool isTied() const { return Kind == Tied; } 599ed2cee1057e2df3a4305b9c818aa577c8504f59Jim Grosbach 60a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner unsigned getTiedOperand() const { 61a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner assert(isTied()); 62a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner return OtherTiedOperand; 63a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner } 64a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner }; 659ed2cee1057e2df3a4305b9c818aa577c8504f59Jim Grosbach 66cf03da0ce913267c4971534e8792297e06535a4eChris Lattner /// OperandInfo - The information we keep track of for each operand in the 67cf03da0ce913267c4971534e8792297e06535a4eChris Lattner /// operand list for a tablegen instruction. 6887c5905e0b6f551e21c9a96f1b6418920d908210Chris Lattner struct OperandInfo { 69cf03da0ce913267c4971534e8792297e06535a4eChris Lattner /// Rec - The definition this operand is declared as. 700e384b66a781fc0ff005f475a7ab151afa054fb0Chris Lattner /// 7187c5905e0b6f551e21c9a96f1b6418920d908210Chris Lattner Record *Rec; 72cf03da0ce913267c4971534e8792297e06535a4eChris Lattner 73cf03da0ce913267c4971534e8792297e06535a4eChris Lattner /// Name - If this operand was assigned a symbolic name, this is it, 74cf03da0ce913267c4971534e8792297e06535a4eChris Lattner /// otherwise, it's empty. 7587c5905e0b6f551e21c9a96f1b6418920d908210Chris Lattner std::string Name; 76cf03da0ce913267c4971534e8792297e06535a4eChris Lattner 77cf03da0ce913267c4971534e8792297e06535a4eChris Lattner /// PrinterMethodName - The method used to print operands of this type in 78cf03da0ce913267c4971534e8792297e06535a4eChris Lattner /// the asmprinter. 79cf03da0ce913267c4971534e8792297e06535a4eChris Lattner std::string PrinterMethodName; 80cf03da0ce913267c4971534e8792297e06535a4eChris Lattner 81cf03da0ce913267c4971534e8792297e06535a4eChris Lattner /// MIOperandNo - Currently (this is meant to be phased out), some logical 82cf03da0ce913267c4971534e8792297e06535a4eChris Lattner /// operands correspond to multiple MachineInstr operands. In the X86 83cf03da0ce913267c4971534e8792297e06535a4eChris Lattner /// target for example, one address operand is represented as 4 84cf03da0ce913267c4971534e8792297e06535a4eChris Lattner /// MachineOperands. Because of this, the operand number in the 85cf03da0ce913267c4971534e8792297e06535a4eChris Lattner /// OperandList may not match the MachineInstr operand num. Until it 86cf03da0ce913267c4971534e8792297e06535a4eChris Lattner /// does, this contains the MI operand index of this operand. 87cf03da0ce913267c4971534e8792297e06535a4eChris Lattner unsigned MIOperandNo; 88cfbf96aa9c3bd317548f72e022ba28a40353f95aChris Lattner unsigned MINumOperands; // The number of operands. 89cf03da0ce913267c4971534e8792297e06535a4eChris Lattner 90f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner /// DoNotEncode - Bools are set to true in this vector for each operand in 91f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner /// the DisableEncoding list. These should not be emitted by the code 92f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner /// emitter. 93f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner std::vector<bool> DoNotEncode; 949ed2cee1057e2df3a4305b9c818aa577c8504f59Jim Grosbach 958ef9d16d3913db11c89fc2d14899e153bdbdc91bNate Begeman /// MIOperandInfo - Default MI operand type. Note an operand may be made 968ef9d16d3913db11c89fc2d14899e153bdbdc91bNate Begeman /// up of multiple MI operands. 9765303d6bd777b76735ef179870678a1d14671c54Chris Lattner DagInit *MIOperandInfo; 989ed2cee1057e2df3a4305b9c818aa577c8504f59Jim Grosbach 990bb75004ff6c0ad26de7610cb873f81ea26fd6caChris Lattner /// Constraint info for this operand. This operand can have pieces, so we 1000bb75004ff6c0ad26de7610cb873f81ea26fd6caChris Lattner /// track constraint info for each. 101a7d479c7bd9723cabdd7c9e1e9a1e6e482f78e7eChris Lattner std::vector<ConstraintInfo> Constraints; 10265303d6bd777b76735ef179870678a1d14671c54Chris Lattner 1039ed2cee1057e2df3a4305b9c818aa577c8504f59Jim Grosbach OperandInfo(Record *R, const std::string &N, const std::string &PMN, 10486193d1190b30a537415fc1c384f4e51039fab74Nate Begeman unsigned MION, unsigned MINO, DagInit *MIOI) 10586193d1190b30a537415fc1c384f4e51039fab74Nate Begeman : Rec(R), Name(N), PrinterMethodName(PMN), MIOperandNo(MION), 10665303d6bd777b76735ef179870678a1d14671c54Chris Lattner MINumOperands(MINO), MIOperandInfo(MIOI) {} 10787c5905e0b6f551e21c9a96f1b6418920d908210Chris Lattner }; 1083da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman 109cedef1ccf0d53693b5e62d524e7ba6b2122231c7Chris Lattner /// NumDefs - Number of def operands declared, this is the number of 110cedef1ccf0d53693b5e62d524e7ba6b2122231c7Chris Lattner /// elements in the instruction's (outs) list. 11164d80e3387f328d21cd9cc06464b5de7861e3f27Evan Cheng /// 11264d80e3387f328d21cd9cc06464b5de7861e3f27Evan Cheng unsigned NumDefs; 11364d80e3387f328d21cd9cc06464b5de7861e3f27Evan Cheng 114ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner /// OperandList - The list of declared operands, along with their declared 115ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner /// type (which is a record). 11687c5905e0b6f551e21c9a96f1b6418920d908210Chris Lattner std::vector<OperandInfo> OperandList; 117ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner 118f506b6b4718d8343c1133daca468e767cd5fb7abChris Lattner /// ImplicitDefs/ImplicitUses - These are lists of registers that are 119f506b6b4718d8343c1133daca468e767cd5fb7abChris Lattner /// implicitly defined and used by the instruction. 120f506b6b4718d8343c1133daca468e767cd5fb7abChris Lattner std::vector<Record*> ImplicitDefs, ImplicitUses; 121f506b6b4718d8343c1133daca468e767cd5fb7abChris Lattner 122ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner // Various boolean values we track for the instruction. 123ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner bool isReturn; 124ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner bool isBranch; 12520ab29068d8a8ec31f26f022634f1e0bc4b1da56Owen Anderson bool isIndirectBranch; 12673739d0bf19af3944aff6afaea2c4eda61061652Bill Wendling bool isCompare; 127ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner bool isBarrier; 128ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner bool isCall; 12915511cf1660cfd6bb8b8e8fca2db9450f50430eeDan Gohman bool canFoldAsLoad; 130dcc8b4f5d3f62ae84aae100638085dedeee91588Chris Lattner bool mayLoad, mayStore; 1315127ce09a4e4379f971280fab461a5f03befddbcEvan Cheng bool isPredicable; 132aad75aa1a235ec1ab121ec2a9c745577493ed323Chris Lattner bool isConvertibleToThreeAddress; 133aad75aa1a235ec1ab121ec2a9c745577493ed323Chris Lattner bool isCommutable; 134ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner bool isTerminator; 135d45eddd214061bf12ad1e6b86497a41725e61d75Dan Gohman bool isReMaterializable; 1365b71d3af35f941585acb50de4909cff20f68680dChris Lattner bool hasDelaySlot; 137533297b58da8c74bec65551e1aface9801fc2259Dan Gohman bool usesCustomInserter; 1388f707e15fbd09ca948b86419bcb0c92470827ac9Chris Lattner bool isVariadic; 1391c3d19eb15b7109f75727bac84c65fcfecb65e51Evan Cheng bool hasCtrlDep; 140eaa91b0a1fc68984aae51f3c4b0cf29b38f89dacEvan Cheng bool isNotDuplicable; 14188cc092ca5bd79480205ee7b01aa39c13f3e35d7Evan Cheng bool hasOptionalDef; 1428370d38adee63b3a4d87bfe81be4aacc55fe7cdaBill Wendling bool hasSideEffects; 1438370d38adee63b3a4d87bfe81be4aacc55fe7cdaBill Wendling bool neverHasSideEffects; 1448370d38adee63b3a4d87bfe81be4aacc55fe7cdaBill Wendling bool isAsCheapAsAMove; 145799d697bf8d45ec404d0d105fc788ea5cf81c841Evan Cheng bool hasExtraSrcRegAllocReq; 146799d697bf8d45ec404d0d105fc788ea5cf81c841Evan Cheng bool hasExtraDefRegAllocReq; 1479ed2cee1057e2df3a4305b9c818aa577c8504f59Jim Grosbach 1480bb75004ff6c0ad26de7610cb873f81ea26fd6caChris Lattner /// ParseOperandName - Parse an operand name like "$foo" or "$foo.bar", 1490bb75004ff6c0ad26de7610cb873f81ea26fd6caChris Lattner /// where $foo is a whole operand and $foo.bar refers to a suboperand. 1500bb75004ff6c0ad26de7610cb873f81ea26fd6caChris Lattner /// This throws an exception if the name is invalid. If AllowWholeOp is 1510bb75004ff6c0ad26de7610cb873f81ea26fd6caChris Lattner /// true, references to operands with suboperands are allowed, otherwise 1520bb75004ff6c0ad26de7610cb873f81ea26fd6caChris Lattner /// not. 1530bb75004ff6c0ad26de7610cb873f81ea26fd6caChris Lattner std::pair<unsigned,unsigned> ParseOperandName(const std::string &Op, 1540bb75004ff6c0ad26de7610cb873f81ea26fd6caChris Lattner bool AllowWholeOp = true); 1559ed2cee1057e2df3a4305b9c818aa577c8504f59Jim Grosbach 1560bb75004ff6c0ad26de7610cb873f81ea26fd6caChris Lattner /// getFlattenedOperandNumber - Flatten a operand/suboperand pair into a 1570bb75004ff6c0ad26de7610cb873f81ea26fd6caChris Lattner /// flat machineinstr operand #. 1580bb75004ff6c0ad26de7610cb873f81ea26fd6caChris Lattner unsigned getFlattenedOperandNumber(std::pair<unsigned,unsigned> Op) const { 1590bb75004ff6c0ad26de7610cb873f81ea26fd6caChris Lattner return OperandList[Op.first].MIOperandNo + Op.second; 1600bb75004ff6c0ad26de7610cb873f81ea26fd6caChris Lattner } 1619ed2cee1057e2df3a4305b9c818aa577c8504f59Jim Grosbach 162f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner /// getSubOperandNumber - Unflatten a operand number into an 163f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner /// operand/suboperand pair. 164f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner std::pair<unsigned,unsigned> getSubOperandNumber(unsigned Op) const { 165f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner for (unsigned i = 0; ; ++i) { 166f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner assert(i < OperandList.size() && "Invalid flat operand #"); 167f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner if (OperandList[i].MIOperandNo+OperandList[i].MINumOperands > Op) 168f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner return std::make_pair(i, Op-OperandList[i].MIOperandNo); 169f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner } 170f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner } 1719ed2cee1057e2df3a4305b9c818aa577c8504f59Jim Grosbach 1729ed2cee1057e2df3a4305b9c818aa577c8504f59Jim Grosbach 173f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner /// isFlatOperandNotEmitted - Return true if the specified flat operand # 174f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner /// should not be emitted with the code emitter. 175f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner bool isFlatOperandNotEmitted(unsigned FlatOpNo) const { 176f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner std::pair<unsigned,unsigned> Op = getSubOperandNumber(FlatOpNo); 177f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner if (OperandList[Op.first].DoNotEncode.size() > Op.second) 178f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner return OperandList[Op.first].DoNotEncode[Op.second]; 179f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner return false; 180f64f9a4b75d07819866bfcf918b922a76d3e1600Chris Lattner } 181ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner 182175580c0f36b026daf9de0adabdb7ddcf7619db6Chris Lattner CodeGenInstruction(Record *R, const std::string &AsmStr); 18387c5905e0b6f551e21c9a96f1b6418920d908210Chris Lattner 18487c5905e0b6f551e21c9a96f1b6418920d908210Chris Lattner /// getOperandNamed - Return the index of the operand with the specified 18587c5905e0b6f551e21c9a96f1b6418920d908210Chris Lattner /// non-empty name. If the instruction does not have an operand with the 18687c5905e0b6f551e21c9a96f1b6418920d908210Chris Lattner /// specified name, throw an exception. 18787c5905e0b6f551e21c9a96f1b6418920d908210Chris Lattner unsigned getOperandNamed(const std::string &Name) const; 1889ed2cee1057e2df3a4305b9c818aa577c8504f59Jim Grosbach 18901855071e24e0e3e75306b82267d3ad0b13a0c15Jim Grosbach /// hasOperandNamed - Query whether the instruction has an operand of the 19001855071e24e0e3e75306b82267d3ad0b13a0c15Jim Grosbach /// given name. If so, return true and set OpIdx to the index of the 19101855071e24e0e3e75306b82267d3ad0b13a0c15Jim Grosbach /// operand. Otherwise, return false. 19201855071e24e0e3e75306b82267d3ad0b13a0c15Jim Grosbach bool hasOperandNamed(const std::string &Name, unsigned &OpIdx) const; 19301855071e24e0e3e75306b82267d3ad0b13a0c15Jim Grosbach 1949414ae52911f1d62cabd5108e0381b9d17476157Chris Lattner /// HasOneImplicitDefWithKnownVT - If the instruction has at least one 1959414ae52911f1d62cabd5108e0381b9d17476157Chris Lattner /// implicit def and it has a known VT, return the VT, otherwise return 1969414ae52911f1d62cabd5108e0381b9d17476157Chris Lattner /// MVT::Other. 1979ed2cee1057e2df3a4305b9c818aa577c8504f59Jim Grosbach MVT::SimpleValueType 1989414ae52911f1d62cabd5108e0381b9d17476157Chris Lattner HasOneImplicitDefWithKnownVT(const CodeGenTarget &TargetInfo) const; 199ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner }; 200ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner} 201ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner 202ec3524064c57fbc2c5976ca301bbaadc94006d07Chris Lattner#endif 203