Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1 | //===- InstrInfoEmitter.cpp - Generate a Instruction Set Desc. ------------===// |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | d303203 | 2003-10-20 20:20:30 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 8adcd9f | 2007-12-29 20:37:13 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | d303203 | 2003-10-20 20:20:30 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 9 | // |
| 10 | // This tablegen backend is responsible for emitting a description of the target |
| 11 | // instruction set for the code generator. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 15 | |
| 16 | #include "CodeGenDAGPatterns.h" |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 17 | #include "CodeGenSchedule.h" |
Chris Lattner | fce9603 | 2004-08-01 04:04:35 +0000 | [diff] [blame] | 18 | #include "CodeGenTarget.h" |
Craig Topper | 91773ab | 2012-04-01 18:14:14 +0000 | [diff] [blame] | 19 | #include "SequenceToOffsetTable.h" |
Chandler Carruth | 91d19d8 | 2012-12-04 10:37:14 +0000 | [diff] [blame] | 20 | #include "TableGenBackends.h" |
Chris Lattner | 06fa176 | 2009-08-24 03:52:50 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/StringExtras.h" |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 22 | #include "llvm/TableGen/Error.h" |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 23 | #include "llvm/TableGen/Record.h" |
| 24 | #include "llvm/TableGen/TableGenBackend.h" |
Jeff Cohen | 9e1784d | 2005-11-01 18:04:06 +0000 | [diff] [blame] | 25 | #include <algorithm> |
Benjamin Kramer | b0640db | 2012-03-23 11:35:30 +0000 | [diff] [blame] | 26 | #include <cstdio> |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 27 | #include <map> |
| 28 | #include <vector> |
Chris Lattner | 6847866 | 2004-08-01 03:55:39 +0000 | [diff] [blame] | 29 | using namespace llvm; |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 30 | |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 31 | namespace { |
| 32 | class InstrInfoEmitter { |
| 33 | RecordKeeper &Records; |
| 34 | CodeGenDAGPatterns CDP; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 35 | const CodeGenSchedModels &SchedModels; |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 36 | |
| 37 | public: |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 38 | InstrInfoEmitter(RecordKeeper &R): |
| 39 | Records(R), CDP(R), SchedModels(CDP.getTargetInfo().getSchedModels()) {} |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 40 | |
| 41 | // run - Output the instruction set description. |
| 42 | void run(raw_ostream &OS); |
| 43 | |
| 44 | private: |
| 45 | void emitEnums(raw_ostream &OS); |
| 46 | |
| 47 | typedef std::map<std::vector<std::string>, unsigned> OperandInfoMapTy; |
Tom Stellard | b162d94 | 2013-06-25 21:22:09 +0000 | [diff] [blame] | 48 | |
| 49 | /// The keys of this map are maps which have OpName enum values as their keys |
| 50 | /// and instruction operand indices as their values. The values of this map |
| 51 | /// are lists of instruction names. |
| 52 | typedef std::map<std::map<unsigned, unsigned>, |
| 53 | std::vector<std::string> > OpNameMapTy; |
| 54 | typedef std::map<std::string, unsigned>::iterator StrUintMapIter; |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 55 | void emitRecord(const CodeGenInstruction &Inst, unsigned Num, |
| 56 | Record *InstrInfo, |
| 57 | std::map<std::vector<Record*>, unsigned> &EL, |
| 58 | const OperandInfoMapTy &OpInfo, |
| 59 | raw_ostream &OS); |
Ahmed Bougacha | 3137759 | 2013-11-17 21:24:41 +0000 | [diff] [blame^] | 60 | void emitOperandTypesEnum(raw_ostream &OS, const CodeGenTarget &Target); |
Tom Stellard | b162d94 | 2013-06-25 21:22:09 +0000 | [diff] [blame] | 61 | void initOperandMapData( |
| 62 | const std::vector<const CodeGenInstruction *> NumberedInstructions, |
| 63 | const std::string &Namespace, |
| 64 | std::map<std::string, unsigned> &Operands, |
| 65 | OpNameMapTy &OperandMap); |
| 66 | void emitOperandNameMappings(raw_ostream &OS, const CodeGenTarget &Target, |
| 67 | const std::vector<const CodeGenInstruction*> &NumberedInstructions); |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 68 | |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 69 | // Operand information. |
| 70 | void EmitOperandInfo(raw_ostream &OS, OperandInfoMapTy &OperandInfoIDs); |
| 71 | std::vector<std::string> GetOperandInfo(const CodeGenInstruction &Inst); |
| 72 | }; |
| 73 | } // End anonymous namespace |
| 74 | |
Chris Lattner | 85467a1 | 2008-01-06 01:21:51 +0000 | [diff] [blame] | 75 | static void PrintDefList(const std::vector<Record*> &Uses, |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 76 | unsigned Num, raw_ostream &OS) { |
Craig Topper | 5a4bcc7 | 2012-03-08 08:22:45 +0000 | [diff] [blame] | 77 | OS << "static const uint16_t ImplicitList" << Num << "[] = { "; |
Chris Lattner | 99df668 | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 78 | for (unsigned i = 0, e = Uses.size(); i != e; ++i) |
| 79 | OS << getQualifiedName(Uses[i]) << ", "; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 80 | OS << "0 };\n"; |
| 81 | } |
| 82 | |
Chris Lattner | 626b89d | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 83 | //===----------------------------------------------------------------------===// |
Chris Lattner | 626b89d | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 84 | // Operand Info Emission. |
| 85 | //===----------------------------------------------------------------------===// |
| 86 | |
Chris Lattner | 33f5a51 | 2006-11-06 23:49:51 +0000 | [diff] [blame] | 87 | std::vector<std::string> |
| 88 | InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) { |
| 89 | std::vector<std::string> Result; |
Owen Anderson | a84be6c | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 90 | |
Chris Lattner | d8adec7 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 91 | for (unsigned i = 0, e = Inst.Operands.size(); i != e; ++i) { |
Chris Lattner | ba7b367 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 92 | // Handle aggregate operands and normal operands the same way by expanding |
| 93 | // either case into a list of operands for this op. |
Chris Lattner | d8adec7 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 94 | std::vector<CGIOperandList::OperandInfo> OperandList; |
Chris Lattner | 33f5a51 | 2006-11-06 23:49:51 +0000 | [diff] [blame] | 95 | |
Chris Lattner | ba7b367 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 96 | // This might be a multiple operand thing. Targets like X86 have |
| 97 | // registers in their multi-operand operands. It may also be an anonymous |
| 98 | // operand, which has a single operand, but no declared class for the |
| 99 | // operand. |
David Greene | af8ee2c | 2011-07-29 22:43:06 +0000 | [diff] [blame] | 100 | DagInit *MIOI = Inst.Operands[i].MIOperandInfo; |
Owen Anderson | a84be6c | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 101 | |
Chris Lattner | ba7b367 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 102 | if (!MIOI || MIOI->getNumArgs() == 0) { |
| 103 | // Single, anonymous, operand. |
Chris Lattner | d8adec7 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 104 | OperandList.push_back(Inst.Operands[i]); |
Chris Lattner | 6bc0304 | 2005-11-19 07:05:57 +0000 | [diff] [blame] | 105 | } else { |
Chris Lattner | d8adec7 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 106 | for (unsigned j = 0, e = Inst.Operands[i].MINumOperands; j != e; ++j) { |
| 107 | OperandList.push_back(Inst.Operands[i]); |
Chris Lattner | 33f5a51 | 2006-11-06 23:49:51 +0000 | [diff] [blame] | 108 | |
Sean Silva | 88eb8dd | 2012-10-10 20:24:47 +0000 | [diff] [blame] | 109 | Record *OpR = cast<DefInit>(MIOI->getArg(j))->getDef(); |
Chris Lattner | ba7b367 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 110 | OperandList.back().Rec = OpR; |
Chris Lattner | 6bc0304 | 2005-11-19 07:05:57 +0000 | [diff] [blame] | 111 | } |
Chris Lattner | d02bd5b | 2005-08-19 18:46:26 +0000 | [diff] [blame] | 112 | } |
Chris Lattner | ba7b367 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 113 | |
| 114 | for (unsigned j = 0, e = OperandList.size(); j != e; ++j) { |
| 115 | Record *OpR = OperandList[j].Rec; |
| 116 | std::string Res; |
Owen Anderson | a84be6c | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 117 | |
| 118 | if (OpR->isSubClassOf("RegisterOperand")) |
| 119 | OpR = OpR->getValueAsDef("RegClass"); |
Chris Lattner | ba7b367 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 120 | if (OpR->isSubClassOf("RegisterClass")) |
| 121 | Res += getQualifiedName(OpR) + "RegClassID, "; |
Chris Lattner | f323953 | 2009-07-29 21:10:12 +0000 | [diff] [blame] | 122 | else if (OpR->isSubClassOf("PointerLikeRegClass")) |
| 123 | Res += utostr(OpR->getValueAsInt("RegClassKind")) + ", "; |
Chris Lattner | ba7b367 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 124 | else |
Dan Gohman | 882bb29 | 2010-06-18 18:13:55 +0000 | [diff] [blame] | 125 | // -1 means the operand does not have a fixed register class. |
| 126 | Res += "-1, "; |
Owen Anderson | a84be6c | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 127 | |
Chris Lattner | ba7b367 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 128 | // Fill in applicable flags. |
| 129 | Res += "0"; |
Owen Anderson | a84be6c | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 130 | |
Chris Lattner | ba7b367 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 131 | // Ptr value whose register class is resolved via callback. |
Chris Lattner | 426bc7c | 2009-07-29 20:43:05 +0000 | [diff] [blame] | 132 | if (OpR->isSubClassOf("PointerLikeRegClass")) |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 133 | Res += "|(1<<MCOI::LookupPtrRegClass)"; |
Chris Lattner | ba7b367 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 134 | |
| 135 | // Predicate operands. Check to see if the original unexpanded operand |
Tim Northover | 4218044 | 2013-08-22 09:57:11 +0000 | [diff] [blame] | 136 | // was of type PredicateOp. |
| 137 | if (Inst.Operands[i].Rec->isSubClassOf("PredicateOp")) |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 138 | Res += "|(1<<MCOI::Predicate)"; |
Owen Anderson | a84be6c | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 139 | |
Evan Cheng | 6e3c705 | 2007-07-10 18:05:01 +0000 | [diff] [blame] | 140 | // Optional def operands. Check to see if the original unexpanded operand |
| 141 | // was of type OptionalDefOperand. |
Chris Lattner | d8adec7 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 142 | if (Inst.Operands[i].Rec->isSubClassOf("OptionalDefOperand")) |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 143 | Res += "|(1<<MCOI::OptionalDef)"; |
Evan Cheng | 6e3c705 | 2007-07-10 18:05:01 +0000 | [diff] [blame] | 144 | |
Craig Topper | b358499 | 2012-03-11 01:57:56 +0000 | [diff] [blame] | 145 | // Fill in operand type. |
| 146 | Res += ", MCOI::"; |
| 147 | assert(!Inst.Operands[i].OperandType.empty() && "Invalid operand type."); |
| 148 | Res += Inst.Operands[i].OperandType; |
| 149 | |
Chris Lattner | ba7b367 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 150 | // Fill in constraint info. |
Chris Lattner | a9dfb1b | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 151 | Res += ", "; |
Owen Anderson | a84be6c | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 152 | |
Chris Lattner | d8adec7 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 153 | const CGIOperandList::ConstraintInfo &Constraint = |
| 154 | Inst.Operands[i].Constraints[j]; |
Chris Lattner | a9dfb1b | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 155 | if (Constraint.isNone()) |
| 156 | Res += "0"; |
| 157 | else if (Constraint.isEarlyClobber()) |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 158 | Res += "(1 << MCOI::EARLY_CLOBBER)"; |
Chris Lattner | a9dfb1b | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 159 | else { |
| 160 | assert(Constraint.isTied()); |
| 161 | Res += "((" + utostr(Constraint.getTiedOperand()) + |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 162 | " << 16) | (1 << MCOI::TIED_TO))"; |
Chris Lattner | a9dfb1b | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 163 | } |
Owen Anderson | a84be6c | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 164 | |
Chris Lattner | ba7b367 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 165 | Result.push_back(Res); |
| 166 | } |
Chris Lattner | d02bd5b | 2005-08-19 18:46:26 +0000 | [diff] [blame] | 167 | } |
Evan Cheng | ac79c7c | 2006-11-01 00:27:05 +0000 | [diff] [blame] | 168 | |
Chris Lattner | d02bd5b | 2005-08-19 18:46:26 +0000 | [diff] [blame] | 169 | return Result; |
| 170 | } |
| 171 | |
Owen Anderson | a84be6c | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 172 | void InstrInfoEmitter::EmitOperandInfo(raw_ostream &OS, |
Chris Lattner | 626b89d | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 173 | OperandInfoMapTy &OperandInfoIDs) { |
| 174 | // ID #0 is for no operand info. |
| 175 | unsigned OperandListNum = 0; |
| 176 | OperandInfoIDs[std::vector<std::string>()] = ++OperandListNum; |
Owen Anderson | a84be6c | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 177 | |
Chris Lattner | 626b89d | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 178 | OS << "\n"; |
| 179 | const CodeGenTarget &Target = CDP.getTargetInfo(); |
| 180 | for (CodeGenTarget::inst_iterator II = Target.inst_begin(), |
| 181 | E = Target.inst_end(); II != E; ++II) { |
Chris Lattner | 4763dbe | 2010-03-19 01:00:55 +0000 | [diff] [blame] | 182 | std::vector<std::string> OperandInfo = GetOperandInfo(**II); |
Chris Lattner | 626b89d | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 183 | unsigned &N = OperandInfoIDs[OperandInfo]; |
| 184 | if (N != 0) continue; |
Owen Anderson | a84be6c | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 185 | |
Chris Lattner | 626b89d | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 186 | N = ++OperandListNum; |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 187 | OS << "static const MCOperandInfo OperandInfo" << N << "[] = { "; |
Chris Lattner | 626b89d | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 188 | for (unsigned i = 0, e = OperandInfo.size(); i != e; ++i) |
| 189 | OS << "{ " << OperandInfo[i] << " }, "; |
| 190 | OS << "};\n"; |
| 191 | } |
| 192 | } |
| 193 | |
Tom Stellard | b162d94 | 2013-06-25 21:22:09 +0000 | [diff] [blame] | 194 | |
| 195 | /// Initialize data structures for generating operand name mappings. |
| 196 | /// |
| 197 | /// \param Operands [out] A map used to generate the OpName enum with operand |
| 198 | /// names as its keys and operand enum values as its values. |
| 199 | /// \param OperandMap [out] A map for representing the operand name mappings for |
| 200 | /// each instructions. This is used to generate the OperandMap table as |
| 201 | /// well as the getNamedOperandIdx() function. |
| 202 | void InstrInfoEmitter::initOperandMapData( |
| 203 | const std::vector<const CodeGenInstruction *> NumberedInstructions, |
| 204 | const std::string &Namespace, |
| 205 | std::map<std::string, unsigned> &Operands, |
| 206 | OpNameMapTy &OperandMap) { |
| 207 | |
| 208 | unsigned NumOperands = 0; |
| 209 | for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) { |
| 210 | const CodeGenInstruction *Inst = NumberedInstructions[i]; |
| 211 | if (!Inst->TheDef->getValueAsBit("UseNamedOperandTable")) { |
| 212 | continue; |
| 213 | } |
| 214 | std::map<unsigned, unsigned> OpList; |
| 215 | for (unsigned j = 0, je = Inst->Operands.size(); j != je; ++j) { |
| 216 | const CGIOperandList::OperandInfo &Info = Inst->Operands[j]; |
| 217 | StrUintMapIter I = Operands.find(Info.Name); |
| 218 | |
| 219 | if (I == Operands.end()) { |
| 220 | I = Operands.insert(Operands.begin(), |
| 221 | std::pair<std::string, unsigned>(Info.Name, NumOperands++)); |
| 222 | } |
| 223 | OpList[I->second] = Info.MIOperandNo; |
| 224 | } |
| 225 | OperandMap[OpList].push_back(Namespace + "::" + Inst->TheDef->getName()); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | /// Generate a table and function for looking up the indices of operands by |
| 230 | /// name. |
| 231 | /// |
| 232 | /// This code generates: |
| 233 | /// - An enum in the llvm::TargetNamespace::OpName namespace, with one entry |
| 234 | /// for each operand name. |
| 235 | /// - A 2-dimensional table called OperandMap for mapping OpName enum values to |
| 236 | /// operand indices. |
| 237 | /// - A function called getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx) |
| 238 | /// for looking up the operand index for an instruction, given a value from |
| 239 | /// OpName enum |
| 240 | void InstrInfoEmitter::emitOperandNameMappings(raw_ostream &OS, |
| 241 | const CodeGenTarget &Target, |
| 242 | const std::vector<const CodeGenInstruction*> &NumberedInstructions) { |
| 243 | |
| 244 | const std::string &Namespace = Target.getInstNamespace(); |
| 245 | std::string OpNameNS = "OpName"; |
| 246 | // Map of operand names to their enumeration value. This will be used to |
| 247 | // generate the OpName enum. |
| 248 | std::map<std::string, unsigned> Operands; |
| 249 | OpNameMapTy OperandMap; |
| 250 | |
| 251 | initOperandMapData(NumberedInstructions, Namespace, Operands, OperandMap); |
| 252 | |
| 253 | OS << "#ifdef GET_INSTRINFO_OPERAND_ENUM\n"; |
| 254 | OS << "#undef GET_INSTRINFO_OPERAND_ENUM\n"; |
| 255 | OS << "namespace llvm {"; |
| 256 | OS << "namespace " << Namespace << " {\n"; |
| 257 | OS << "namespace " << OpNameNS << " { \n"; |
| 258 | OS << "enum {\n"; |
| 259 | for (StrUintMapIter i = Operands.begin(), e = Operands.end(); i != e; ++i) |
| 260 | OS << " " << i->first << " = " << i->second << ",\n"; |
| 261 | |
| 262 | OS << "OPERAND_LAST"; |
| 263 | OS << "\n};\n"; |
| 264 | OS << "} // End namespace OpName\n"; |
| 265 | OS << "} // End namespace " << Namespace << "\n"; |
| 266 | OS << "} // End namespace llvm\n"; |
| 267 | OS << "#endif //GET_INSTRINFO_OPERAND_ENUM\n"; |
| 268 | |
| 269 | OS << "#ifdef GET_INSTRINFO_NAMED_OPS\n"; |
| 270 | OS << "#undef GET_INSTRINFO_NAMED_OPS\n"; |
| 271 | OS << "namespace llvm {"; |
| 272 | OS << "namespace " << Namespace << " {\n"; |
| 273 | OS << "int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx) {\n"; |
Aaron Ballman | e59e358 | 2013-07-15 16:53:32 +0000 | [diff] [blame] | 274 | if (!Operands.empty()) { |
| 275 | OS << " static const int16_t OperandMap [][" << Operands.size() |
| 276 | << "] = {\n"; |
| 277 | for (OpNameMapTy::iterator i = OperandMap.begin(), e = OperandMap.end(); |
| 278 | i != e; ++i) { |
| 279 | const std::map<unsigned, unsigned> &OpList = i->first; |
| 280 | OS << "{"; |
Tom Stellard | b162d94 | 2013-06-25 21:22:09 +0000 | [diff] [blame] | 281 | |
Aaron Ballman | e59e358 | 2013-07-15 16:53:32 +0000 | [diff] [blame] | 282 | // Emit a row of the OperandMap table |
| 283 | for (unsigned ii = 0, ie = Operands.size(); ii != ie; ++ii) |
| 284 | OS << (OpList.count(ii) == 0 ? -1 : (int)OpList.find(ii)->second) |
| 285 | << ", "; |
Tom Stellard | b162d94 | 2013-06-25 21:22:09 +0000 | [diff] [blame] | 286 | |
Aaron Ballman | e59e358 | 2013-07-15 16:53:32 +0000 | [diff] [blame] | 287 | OS << "},\n"; |
| 288 | } |
| 289 | OS << "};\n"; |
| 290 | |
| 291 | OS << " switch(Opcode) {\n"; |
| 292 | unsigned TableIndex = 0; |
| 293 | for (OpNameMapTy::iterator i = OperandMap.begin(), e = OperandMap.end(); |
| 294 | i != e; ++i) { |
| 295 | std::vector<std::string> &OpcodeList = i->second; |
| 296 | |
| 297 | for (unsigned ii = 0, ie = OpcodeList.size(); ii != ie; ++ii) |
| 298 | OS << " case " << OpcodeList[ii] << ":\n"; |
| 299 | |
| 300 | OS << " return OperandMap[" << TableIndex++ << "][NamedIdx];\n"; |
| 301 | } |
| 302 | OS << " default: return -1;\n"; |
| 303 | OS << " }\n"; |
| 304 | } else { |
| 305 | // There are no operands, so no need to emit anything |
| 306 | OS << " return -1;\n"; |
Tom Stellard | b162d94 | 2013-06-25 21:22:09 +0000 | [diff] [blame] | 307 | } |
Tom Stellard | b162d94 | 2013-06-25 21:22:09 +0000 | [diff] [blame] | 308 | OS << "}\n"; |
| 309 | OS << "} // End namespace " << Namespace << "\n"; |
| 310 | OS << "} // End namespace llvm\n"; |
| 311 | OS << "#endif //GET_INSTRINFO_NAMED_OPS\n"; |
| 312 | |
| 313 | } |
| 314 | |
Ahmed Bougacha | 3137759 | 2013-11-17 21:24:41 +0000 | [diff] [blame^] | 315 | /// Generate an enum for all the operand types for this target, under the |
| 316 | /// llvm::TargetNamespace::OpTypes namespace. |
| 317 | /// Operand types are all definitions derived of the Operand Target.td class. |
| 318 | void InstrInfoEmitter::emitOperandTypesEnum(raw_ostream &OS, |
| 319 | const CodeGenTarget &Target) { |
| 320 | |
| 321 | const std::string &Namespace = Target.getInstNamespace(); |
| 322 | std::vector<Record *> Operands = Records.getAllDerivedDefinitions("Operand"); |
| 323 | |
| 324 | OS << "\n#ifdef GET_INSTRINFO_OPERAND_TYPES_ENUM\n"; |
| 325 | OS << "#undef GET_INSTRINFO_OPERAND_TYPES_ENUM\n"; |
| 326 | OS << "namespace llvm {"; |
| 327 | OS << "namespace " << Namespace << " {\n"; |
| 328 | OS << "namespace OpTypes { \n"; |
| 329 | OS << "enum OperandType {\n"; |
| 330 | |
| 331 | for (unsigned oi = 0, oe = Operands.size(); oi != oe; ++oi) { |
| 332 | if (!Operands[oi]->isAnonymous()) |
| 333 | OS << " " << Operands[oi]->getName() << " = " << oi << ",\n"; |
| 334 | } |
| 335 | |
| 336 | OS << " OPERAND_TYPE_LIST_END" << "\n};\n"; |
| 337 | OS << "} // End namespace OpTypes\n"; |
| 338 | OS << "} // End namespace " << Namespace << "\n"; |
| 339 | OS << "} // End namespace llvm\n"; |
| 340 | OS << "#endif // GET_INSTRINFO_OPERAND_TYPES_ENUM\n"; |
| 341 | } |
| 342 | |
Chris Lattner | 626b89d | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 343 | //===----------------------------------------------------------------------===// |
| 344 | // Main Output. |
| 345 | //===----------------------------------------------------------------------===// |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 346 | |
| 347 | // run - Emit the main instruction description records for the target... |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 348 | void InstrInfoEmitter::run(raw_ostream &OS) { |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 349 | emitSourceFileHeader("Target Instruction Enum Values", OS); |
Evan Cheng | 1e210d0 | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 350 | emitEnums(OS); |
| 351 | |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 352 | emitSourceFileHeader("Target Instruction Descriptors", OS); |
Evan Cheng | 1e210d0 | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 353 | |
| 354 | OS << "\n#ifdef GET_INSTRINFO_MC_DESC\n"; |
| 355 | OS << "#undef GET_INSTRINFO_MC_DESC\n"; |
| 356 | |
Chris Lattner | c9d99ef | 2004-08-17 03:08:28 +0000 | [diff] [blame] | 357 | OS << "namespace llvm {\n\n"; |
| 358 | |
Dan Gohman | fc4ad7de | 2008-04-03 00:02:49 +0000 | [diff] [blame] | 359 | CodeGenTarget &Target = CDP.getTargetInfo(); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 360 | const std::string &TargetName = Target.getName(); |
| 361 | Record *InstrInfo = Target.getInstructionSet(); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 362 | |
Chris Lattner | 99df668 | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 363 | // Keep track of all of the def lists we have emitted already. |
| 364 | std::map<std::vector<Record*>, unsigned> EmittedLists; |
Chris Lattner | 99df668 | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 365 | unsigned ListNumber = 0; |
Owen Anderson | a84be6c | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 366 | |
Chris Lattner | 99df668 | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 367 | // Emit all of the instruction's implicit uses and defs. |
Chris Lattner | c860eca | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 368 | for (CodeGenTarget::inst_iterator II = Target.inst_begin(), |
| 369 | E = Target.inst_end(); II != E; ++II) { |
Chris Lattner | 4763dbe | 2010-03-19 01:00:55 +0000 | [diff] [blame] | 370 | Record *Inst = (*II)->TheDef; |
Chris Lattner | 742606a | 2005-10-28 22:59:53 +0000 | [diff] [blame] | 371 | std::vector<Record*> Uses = Inst->getValueAsListOfDefs("Uses"); |
| 372 | if (!Uses.empty()) { |
Chris Lattner | 99df668 | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 373 | unsigned &IL = EmittedLists[Uses]; |
Chris Lattner | 85467a1 | 2008-01-06 01:21:51 +0000 | [diff] [blame] | 374 | if (!IL) PrintDefList(Uses, IL = ++ListNumber, OS); |
Chris Lattner | 99df668 | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 375 | } |
Chris Lattner | 742606a | 2005-10-28 22:59:53 +0000 | [diff] [blame] | 376 | std::vector<Record*> Defs = Inst->getValueAsListOfDefs("Defs"); |
| 377 | if (!Defs.empty()) { |
| 378 | unsigned &IL = EmittedLists[Defs]; |
Chris Lattner | 85467a1 | 2008-01-06 01:21:51 +0000 | [diff] [blame] | 379 | if (!IL) PrintDefList(Defs, IL = ++ListNumber, OS); |
Chris Lattner | 99df668 | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 380 | } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Chris Lattner | 626b89d | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 383 | OperandInfoMapTy OperandInfoIDs; |
Owen Anderson | a84be6c | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 384 | |
Chris Lattner | 220d001 | 2005-08-19 16:57:28 +0000 | [diff] [blame] | 385 | // Emit all of the operand info records. |
Chris Lattner | 626b89d | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 386 | EmitOperandInfo(OS, OperandInfoIDs); |
Owen Anderson | a84be6c | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 387 | |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 388 | // Emit all of the MCInstrDesc records in their ENUM ordering. |
Chris Lattner | 220d001 | 2005-08-19 16:57:28 +0000 | [diff] [blame] | 389 | // |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 390 | OS << "\nextern const MCInstrDesc " << TargetName << "Insts[] = {\n"; |
Chris Lattner | 918be52 | 2010-03-19 00:34:35 +0000 | [diff] [blame] | 391 | const std::vector<const CodeGenInstruction*> &NumberedInstructions = |
| 392 | Target.getInstructionsByEnumValue(); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 393 | |
Chris Lattner | db2a5f0 | 2006-01-27 01:44:09 +0000 | [diff] [blame] | 394 | for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) |
| 395 | emitRecord(*NumberedInstructions[i], i, InstrInfo, EmittedLists, |
Evan Cheng | 105974d | 2011-06-27 23:47:21 +0000 | [diff] [blame] | 396 | OperandInfoIDs, OS); |
Evan Cheng | df8974e | 2011-06-28 20:29:03 +0000 | [diff] [blame] | 397 | OS << "};\n\n"; |
| 398 | |
Craig Topper | 91773ab | 2012-04-01 18:14:14 +0000 | [diff] [blame] | 399 | // Build an array of instruction names |
| 400 | SequenceToOffsetTable<std::string> InstrNames; |
Benjamin Kramer | bf152d5 | 2012-02-10 13:18:44 +0000 | [diff] [blame] | 401 | for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) { |
| 402 | const CodeGenInstruction *Instr = NumberedInstructions[i]; |
Craig Topper | 91773ab | 2012-04-01 18:14:14 +0000 | [diff] [blame] | 403 | InstrNames.add(Instr->TheDef->getName()); |
| 404 | } |
| 405 | |
| 406 | InstrNames.layout(); |
| 407 | OS << "extern const char " << TargetName << "InstrNameData[] = {\n"; |
| 408 | InstrNames.emit(OS, printChar); |
| 409 | OS << "};\n\n"; |
| 410 | |
| 411 | OS << "extern const unsigned " << TargetName <<"InstrNameIndices[] = {"; |
| 412 | for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) { |
Benjamin Kramer | bf152d5 | 2012-02-10 13:18:44 +0000 | [diff] [blame] | 413 | if (i % 8 == 0) |
| 414 | OS << "\n "; |
Craig Topper | 91773ab | 2012-04-01 18:14:14 +0000 | [diff] [blame] | 415 | const CodeGenInstruction *Instr = NumberedInstructions[i]; |
| 416 | OS << InstrNames.get(Instr->TheDef->getName()) << "U, "; |
Benjamin Kramer | bf152d5 | 2012-02-10 13:18:44 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | OS << "\n};\n\n"; |
| 420 | |
Evan Cheng | df8974e | 2011-06-28 20:29:03 +0000 | [diff] [blame] | 421 | // MCInstrInfo initialization routine. |
| 422 | OS << "static inline void Init" << TargetName |
| 423 | << "MCInstrInfo(MCInstrInfo *II) {\n"; |
| 424 | OS << " II->InitMCInstrInfo(" << TargetName << "Insts, " |
Benjamin Kramer | bf152d5 | 2012-02-10 13:18:44 +0000 | [diff] [blame] | 425 | << TargetName << "InstrNameIndices, " << TargetName << "InstrNameData, " |
Evan Cheng | df8974e | 2011-06-28 20:29:03 +0000 | [diff] [blame] | 426 | << NumberedInstructions.size() << ");\n}\n\n"; |
| 427 | |
Chris Lattner | c9d99ef | 2004-08-17 03:08:28 +0000 | [diff] [blame] | 428 | OS << "} // End llvm namespace \n"; |
Evan Cheng | 1e210d0 | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 429 | |
| 430 | OS << "#endif // GET_INSTRINFO_MC_DESC\n\n"; |
Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 431 | |
| 432 | // Create a TargetInstrInfo subclass to hide the MC layer initialization. |
| 433 | OS << "\n#ifdef GET_INSTRINFO_HEADER\n"; |
| 434 | OS << "#undef GET_INSTRINFO_HEADER\n"; |
| 435 | |
| 436 | std::string ClassName = TargetName + "GenInstrInfo"; |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 437 | OS << "namespace llvm {\n"; |
Jakob Stoklund Olesen | 9de596e | 2012-11-28 02:35:17 +0000 | [diff] [blame] | 438 | OS << "struct " << ClassName << " : public TargetInstrInfo {\n" |
Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 439 | << " explicit " << ClassName << "(int SO = -1, int DO = -1);\n" |
Juergen Ributzka | dbedae8 | 2013-11-15 22:34:48 +0000 | [diff] [blame] | 440 | << " virtual ~" << ClassName << "();\n" |
Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 441 | << "};\n"; |
| 442 | OS << "} // End llvm namespace \n"; |
| 443 | |
| 444 | OS << "#endif // GET_INSTRINFO_HEADER\n\n"; |
| 445 | |
Juergen Ributzka | dbedae8 | 2013-11-15 22:34:48 +0000 | [diff] [blame] | 446 | OS << "\n#ifdef GET_INSTRINFO_CTOR_DTOR\n"; |
| 447 | OS << "#undef GET_INSTRINFO_CTOR_DTOR\n"; |
Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 448 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 449 | OS << "namespace llvm {\n"; |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 450 | OS << "extern const MCInstrDesc " << TargetName << "Insts[];\n"; |
Jakob Stoklund Olesen | e308489 | 2012-03-15 18:05:57 +0000 | [diff] [blame] | 451 | OS << "extern const unsigned " << TargetName << "InstrNameIndices[];\n"; |
Craig Topper | 91773ab | 2012-04-01 18:14:14 +0000 | [diff] [blame] | 452 | OS << "extern const char " << TargetName << "InstrNameData[];\n"; |
Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 453 | OS << ClassName << "::" << ClassName << "(int SO, int DO)\n" |
Jakob Stoklund Olesen | 9de596e | 2012-11-28 02:35:17 +0000 | [diff] [blame] | 454 | << " : TargetInstrInfo(SO, DO) {\n" |
Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 455 | << " InitMCInstrInfo(" << TargetName << "Insts, " |
Benjamin Kramer | bf152d5 | 2012-02-10 13:18:44 +0000 | [diff] [blame] | 456 | << TargetName << "InstrNameIndices, " << TargetName << "InstrNameData, " |
Juergen Ributzka | dbedae8 | 2013-11-15 22:34:48 +0000 | [diff] [blame] | 457 | << NumberedInstructions.size() << ");\n}\n" |
| 458 | << ClassName << "::~" << ClassName << "() {}\n"; |
Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 459 | OS << "} // End llvm namespace \n"; |
| 460 | |
Juergen Ributzka | dbedae8 | 2013-11-15 22:34:48 +0000 | [diff] [blame] | 461 | OS << "#endif // GET_INSTRINFO_CTOR_DTOR\n\n"; |
Tom Stellard | b162d94 | 2013-06-25 21:22:09 +0000 | [diff] [blame] | 462 | |
| 463 | emitOperandNameMappings(OS, Target, NumberedInstructions); |
Ahmed Bougacha | 3137759 | 2013-11-17 21:24:41 +0000 | [diff] [blame^] | 464 | |
| 465 | emitOperandTypesEnum(OS, Target); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 466 | } |
| 467 | |
Chris Lattner | c860eca | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 468 | void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num, |
Chris Lattner | 99df668 | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 469 | Record *InstrInfo, |
Chris Lattner | 742606a | 2005-10-28 22:59:53 +0000 | [diff] [blame] | 470 | std::map<std::vector<Record*>, unsigned> &EmittedLists, |
Chris Lattner | 626b89d | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 471 | const OperandInfoMapTy &OpInfo, |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 472 | raw_ostream &OS) { |
Chris Lattner | 27a4c15 | 2008-01-06 01:53:37 +0000 | [diff] [blame] | 473 | int MinOperands = 0; |
Richard Trieu | 2448969 | 2012-10-12 17:57:35 +0000 | [diff] [blame] | 474 | if (!Inst.Operands.empty()) |
Chris Lattner | 511ee68 | 2005-08-19 00:59:49 +0000 | [diff] [blame] | 475 | // Each logical operand can be multiple MI operands. |
Chris Lattner | d8adec7 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 476 | MinOperands = Inst.Operands.back().MIOperandNo + |
| 477 | Inst.Operands.back().MINumOperands; |
Dan Gohman | 6e582c4 | 2008-05-29 19:57:41 +0000 | [diff] [blame] | 478 | |
Evan Cheng | 71adba6 | 2006-11-17 01:46:27 +0000 | [diff] [blame] | 479 | OS << " { "; |
Evan Cheng | c9de9ce | 2007-08-02 00:20:17 +0000 | [diff] [blame] | 480 | OS << Num << ",\t" << MinOperands << ",\t" |
Owen Anderson | 651b230 | 2011-07-13 23:22:26 +0000 | [diff] [blame] | 481 | << Inst.Operands.NumDefs << ",\t" |
Andrew Trick | a88f1bd | 2012-09-18 03:55:55 +0000 | [diff] [blame] | 482 | << SchedModels.getSchedClassIdx(Inst) << ",\t" |
Benjamin Kramer | 8e012f5 | 2012-02-09 11:25:09 +0000 | [diff] [blame] | 483 | << Inst.TheDef->getValueAsInt("Size") << ",\t0"; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 484 | |
| 485 | // Emit all of the target indepedent flags... |
Jakob Stoklund Olesen | df977fe | 2011-09-25 19:21:35 +0000 | [diff] [blame] | 486 | if (Inst.isPseudo) OS << "|(1<<MCID::Pseudo)"; |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 487 | if (Inst.isReturn) OS << "|(1<<MCID::Return)"; |
| 488 | if (Inst.isBranch) OS << "|(1<<MCID::Branch)"; |
| 489 | if (Inst.isIndirectBranch) OS << "|(1<<MCID::IndirectBranch)"; |
| 490 | if (Inst.isCompare) OS << "|(1<<MCID::Compare)"; |
| 491 | if (Inst.isMoveImm) OS << "|(1<<MCID::MoveImm)"; |
| 492 | if (Inst.isBitcast) OS << "|(1<<MCID::Bitcast)"; |
Jakob Stoklund Olesen | 2382d32 | 2012-08-16 23:11:47 +0000 | [diff] [blame] | 493 | if (Inst.isSelect) OS << "|(1<<MCID::Select)"; |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 494 | if (Inst.isBarrier) OS << "|(1<<MCID::Barrier)"; |
| 495 | if (Inst.hasDelaySlot) OS << "|(1<<MCID::DelaySlot)"; |
| 496 | if (Inst.isCall) OS << "|(1<<MCID::Call)"; |
| 497 | if (Inst.canFoldAsLoad) OS << "|(1<<MCID::FoldableAsLoad)"; |
| 498 | if (Inst.mayLoad) OS << "|(1<<MCID::MayLoad)"; |
| 499 | if (Inst.mayStore) OS << "|(1<<MCID::MayStore)"; |
| 500 | if (Inst.isPredicable) OS << "|(1<<MCID::Predicable)"; |
| 501 | if (Inst.isConvertibleToThreeAddress) OS << "|(1<<MCID::ConvertibleTo3Addr)"; |
| 502 | if (Inst.isCommutable) OS << "|(1<<MCID::Commutable)"; |
| 503 | if (Inst.isTerminator) OS << "|(1<<MCID::Terminator)"; |
| 504 | if (Inst.isReMaterializable) OS << "|(1<<MCID::Rematerializable)"; |
| 505 | if (Inst.isNotDuplicable) OS << "|(1<<MCID::NotDuplicable)"; |
| 506 | if (Inst.Operands.hasOptionalDef) OS << "|(1<<MCID::HasOptionalDef)"; |
| 507 | if (Inst.usesCustomInserter) OS << "|(1<<MCID::UsesCustomInserter)"; |
Andrew Trick | 52363bd | 2011-09-20 18:22:31 +0000 | [diff] [blame] | 508 | if (Inst.hasPostISelHook) OS << "|(1<<MCID::HasPostISelHook)"; |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 509 | if (Inst.Operands.isVariadic)OS << "|(1<<MCID::Variadic)"; |
| 510 | if (Inst.hasSideEffects) OS << "|(1<<MCID::UnmodeledSideEffects)"; |
| 511 | if (Inst.isAsCheapAsAMove) OS << "|(1<<MCID::CheapAsAMove)"; |
| 512 | if (Inst.hasExtraSrcRegAllocReq) OS << "|(1<<MCID::ExtraSrcRegAllocReq)"; |
| 513 | if (Inst.hasExtraDefRegAllocReq) OS << "|(1<<MCID::ExtraDefRegAllocReq)"; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 514 | |
| 515 | // Emit all of the target-specific flags... |
David Greene | af8ee2c | 2011-07-29 22:43:06 +0000 | [diff] [blame] | 516 | BitsInit *TSF = Inst.TheDef->getValueAsBitsInit("TSFlags"); |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 517 | if (!TSF) |
| 518 | PrintFatalError("no TSFlags?"); |
Jakob Stoklund Olesen | b93331f | 2010-04-05 03:10:20 +0000 | [diff] [blame] | 519 | uint64_t Value = 0; |
| 520 | for (unsigned i = 0, e = TSF->getNumBits(); i != e; ++i) { |
Sean Silva | fb509ed | 2012-10-10 20:24:43 +0000 | [diff] [blame] | 521 | if (BitInit *Bit = dyn_cast<BitInit>(TSF->getBit(i))) |
Jakob Stoklund Olesen | b93331f | 2010-04-05 03:10:20 +0000 | [diff] [blame] | 522 | Value |= uint64_t(Bit->getValue()) << i; |
| 523 | else |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 524 | PrintFatalError("Invalid TSFlags bit in " + Inst.TheDef->getName()); |
Jakob Stoklund Olesen | b93331f | 2010-04-05 03:10:20 +0000 | [diff] [blame] | 525 | } |
| 526 | OS << ", 0x"; |
| 527 | OS.write_hex(Value); |
Eric Christopher | 223c481 | 2010-06-09 16:16:48 +0000 | [diff] [blame] | 528 | OS << "ULL, "; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 529 | |
| 530 | // Emit the implicit uses and defs lists... |
Chris Lattner | 742606a | 2005-10-28 22:59:53 +0000 | [diff] [blame] | 531 | std::vector<Record*> UseList = Inst.TheDef->getValueAsListOfDefs("Uses"); |
| 532 | if (UseList.empty()) |
Jim Laskey | 4b49c23 | 2006-07-21 21:15:20 +0000 | [diff] [blame] | 533 | OS << "NULL, "; |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 534 | else |
Chris Lattner | 742606a | 2005-10-28 22:59:53 +0000 | [diff] [blame] | 535 | OS << "ImplicitList" << EmittedLists[UseList] << ", "; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 536 | |
Chris Lattner | 742606a | 2005-10-28 22:59:53 +0000 | [diff] [blame] | 537 | std::vector<Record*> DefList = Inst.TheDef->getValueAsListOfDefs("Defs"); |
| 538 | if (DefList.empty()) |
Jim Laskey | 4b49c23 | 2006-07-21 21:15:20 +0000 | [diff] [blame] | 539 | OS << "NULL, "; |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 540 | else |
Chris Lattner | 742606a | 2005-10-28 22:59:53 +0000 | [diff] [blame] | 541 | OS << "ImplicitList" << EmittedLists[DefList] << ", "; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 542 | |
Chris Lattner | 220d001 | 2005-08-19 16:57:28 +0000 | [diff] [blame] | 543 | // Emit the operand info. |
Chris Lattner | 33f5a51 | 2006-11-06 23:49:51 +0000 | [diff] [blame] | 544 | std::vector<std::string> OperandInfo = GetOperandInfo(Inst); |
Chris Lattner | d02bd5b | 2005-08-19 18:46:26 +0000 | [diff] [blame] | 545 | if (OperandInfo.empty()) |
| 546 | OS << "0"; |
Chris Lattner | 220d001 | 2005-08-19 16:57:28 +0000 | [diff] [blame] | 547 | else |
Chris Lattner | 626b89d | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 548 | OS << "OperandInfo" << OpInfo.find(OperandInfo)->second; |
Jakob Stoklund Olesen | b93331f | 2010-04-05 03:10:20 +0000 | [diff] [blame] | 549 | |
Joey Gouly | 0e76fa7 | 2013-09-12 10:28:05 +0000 | [diff] [blame] | 550 | CodeGenTarget &Target = CDP.getTargetInfo(); |
| 551 | if (Inst.HasComplexDeprecationPredicate) |
| 552 | // Emit a function pointer to the complex predicate method. |
| 553 | OS << ",0" |
| 554 | << ",&get" << Inst.DeprecatedReason << "DeprecationInfo"; |
| 555 | else if (!Inst.DeprecatedReason.empty()) |
| 556 | // Emit the Subtarget feature. |
| 557 | OS << "," << Target.getInstNamespace() << "::" << Inst.DeprecatedReason |
| 558 | << ",0"; |
| 559 | else |
| 560 | // Instruction isn't deprecated. |
| 561 | OS << ",0,0"; |
| 562 | |
Chris Lattner | c860eca | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 563 | OS << " }, // Inst #" << Num << " = " << Inst.TheDef->getName() << "\n"; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 564 | } |
Evan Cheng | 1e210d0 | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 565 | |
| 566 | // emitEnums - Print out enum values for all of the instructions. |
| 567 | void InstrInfoEmitter::emitEnums(raw_ostream &OS) { |
Evan Cheng | 1e210d0 | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 568 | |
| 569 | OS << "\n#ifdef GET_INSTRINFO_ENUM\n"; |
| 570 | OS << "#undef GET_INSTRINFO_ENUM\n"; |
| 571 | |
| 572 | OS << "namespace llvm {\n\n"; |
| 573 | |
| 574 | CodeGenTarget Target(Records); |
| 575 | |
| 576 | // We must emit the PHI opcode first... |
| 577 | std::string Namespace = Target.getInstNamespace(); |
Jim Grosbach | dac4a95 | 2012-04-11 21:02:30 +0000 | [diff] [blame] | 578 | |
Evan Cheng | 1e210d0 | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 579 | if (Namespace.empty()) { |
| 580 | fprintf(stderr, "No instructions defined!\n"); |
| 581 | exit(1); |
| 582 | } |
| 583 | |
| 584 | const std::vector<const CodeGenInstruction*> &NumberedInstructions = |
| 585 | Target.getInstructionsByEnumValue(); |
| 586 | |
| 587 | OS << "namespace " << Namespace << " {\n"; |
| 588 | OS << " enum {\n"; |
| 589 | for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) { |
| 590 | OS << " " << NumberedInstructions[i]->TheDef->getName() |
| 591 | << "\t= " << i << ",\n"; |
| 592 | } |
| 593 | OS << " INSTRUCTION_LIST_END = " << NumberedInstructions.size() << "\n"; |
Vincent Lejeune | 7deccf0 | 2013-09-03 19:43:28 +0000 | [diff] [blame] | 594 | OS << " };\n"; |
| 595 | OS << "namespace Sched {\n"; |
| 596 | OS << " enum {\n"; |
| 597 | for (unsigned i = 0, e = SchedModels.numInstrSchedClasses(); i != e; ++i) { |
| 598 | OS << " " << SchedModels.getSchedClass(i).Name |
| 599 | << "\t= " << i << ",\n"; |
| 600 | } |
| 601 | OS << " SCHED_LIST_END = " << SchedModels.numInstrSchedClasses() << "\n"; |
| 602 | OS << " };\n}\n}\n"; |
Evan Cheng | 1e210d0 | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 603 | OS << "} // End llvm namespace \n"; |
| 604 | |
| 605 | OS << "#endif // GET_INSTRINFO_ENUM\n\n"; |
| 606 | } |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 607 | |
| 608 | namespace llvm { |
| 609 | |
| 610 | void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) { |
| 611 | InstrInfoEmitter(RK).run(OS); |
Sebastian Pop | 5c87daf | 2012-10-25 15:54:06 +0000 | [diff] [blame] | 612 | EmitMapTable(RK, OS); |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | } // End llvm namespace |