Chris Lattner | 33ccf7e | 2003-08-03 17:24:10 +0000 | [diff] [blame] | 1 | //===- InstrInfoEmitter.cpp - Generate a Instruction Set Desc. ------------===// |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | 01d4582 | 2003-10-20 20:20:30 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 3060910 | 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 | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | 01d4582 | 2003-10-20 20:20:30 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 33ccf7e | 2003-08-03 17:24:10 +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 | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 15 | |
| 16 | #include "CodeGenDAGPatterns.h" |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 17 | #include "CodeGenSchedule.h" |
Chris Lattner | 803a5f6 | 2004-08-01 04:04:35 +0000 | [diff] [blame] | 18 | #include "CodeGenTarget.h" |
Craig Topper | 413b2e7 | 2012-04-01 18:14:14 +0000 | [diff] [blame] | 19 | #include "SequenceToOffsetTable.h" |
Chandler Carruth | 4ffd89f | 2012-12-04 10:37:14 +0000 | [diff] [blame] | 20 | #include "TableGenBackends.h" |
Chris Lattner | 23132b1 | 2009-08-24 03:52:50 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/StringExtras.h" |
Joerg Sonnenberger | 61131ab | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 22 | #include "llvm/TableGen/Error.h" |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 23 | #include "llvm/TableGen/Record.h" |
| 24 | #include "llvm/TableGen/TableGenBackend.h" |
Jeff Cohen | cb366d9 | 2005-11-01 18:04:06 +0000 | [diff] [blame] | 25 | #include <algorithm> |
Benjamin Kramer | 901b858 | 2012-03-23 11:35:30 +0000 | [diff] [blame] | 26 | #include <cstdio> |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 27 | #include <map> |
| 28 | #include <vector> |
Chris Lattner | 2082ebe | 2004-08-01 03:55:39 +0000 | [diff] [blame] | 29 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 30 | |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 31 | namespace { |
| 32 | class InstrInfoEmitter { |
| 33 | RecordKeeper &Records; |
| 34 | CodeGenDAGPatterns CDP; |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 35 | const CodeGenSchedModels &SchedModels; |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 36 | |
| 37 | public: |
Andrew Trick | 2661b41 | 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 | 6f36fa9 | 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 | 898b9f0 | 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 | 6f36fa9 | 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); |
Tom Stellard | 898b9f0 | 2013-06-25 21:22:09 +0000 | [diff] [blame] | 60 | void initOperandMapData( |
| 61 | const std::vector<const CodeGenInstruction *> NumberedInstructions, |
| 62 | const std::string &Namespace, |
| 63 | std::map<std::string, unsigned> &Operands, |
| 64 | OpNameMapTy &OperandMap); |
| 65 | void emitOperandNameMappings(raw_ostream &OS, const CodeGenTarget &Target, |
| 66 | const std::vector<const CodeGenInstruction*> &NumberedInstructions); |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 67 | |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 68 | // Operand information. |
| 69 | void EmitOperandInfo(raw_ostream &OS, OperandInfoMapTy &OperandInfoIDs); |
| 70 | std::vector<std::string> GetOperandInfo(const CodeGenInstruction &Inst); |
| 71 | }; |
| 72 | } // End anonymous namespace |
| 73 | |
Chris Lattner | 5fbe275 | 2008-01-06 01:21:51 +0000 | [diff] [blame] | 74 | static void PrintDefList(const std::vector<Record*> &Uses, |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 75 | unsigned Num, raw_ostream &OS) { |
Craig Topper | fac2598 | 2012-03-08 08:22:45 +0000 | [diff] [blame] | 76 | OS << "static const uint16_t ImplicitList" << Num << "[] = { "; |
Chris Lattner | a3ac88d | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 77 | for (unsigned i = 0, e = Uses.size(); i != e; ++i) |
| 78 | OS << getQualifiedName(Uses[i]) << ", "; |
Chris Lattner | a3ae614 | 2003-08-03 21:57:51 +0000 | [diff] [blame] | 79 | OS << "0 };\n"; |
| 80 | } |
| 81 | |
Chris Lattner | ef8339b | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 82 | //===----------------------------------------------------------------------===// |
Chris Lattner | ef8339b | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 83 | // Operand Info Emission. |
| 84 | //===----------------------------------------------------------------------===// |
| 85 | |
Chris Lattner | a0cca4a | 2006-11-06 23:49:51 +0000 | [diff] [blame] | 86 | std::vector<std::string> |
| 87 | InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) { |
| 88 | std::vector<std::string> Result; |
Owen Anderson | bea6f61 | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 89 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 90 | for (unsigned i = 0, e = Inst.Operands.size(); i != e; ++i) { |
Chris Lattner | f196839 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 91 | // Handle aggregate operands and normal operands the same way by expanding |
| 92 | // either case into a list of operands for this op. |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 93 | std::vector<CGIOperandList::OperandInfo> OperandList; |
Chris Lattner | a0cca4a | 2006-11-06 23:49:51 +0000 | [diff] [blame] | 94 | |
Chris Lattner | f196839 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 95 | // This might be a multiple operand thing. Targets like X86 have |
| 96 | // registers in their multi-operand operands. It may also be an anonymous |
| 97 | // operand, which has a single operand, but no declared class for the |
| 98 | // operand. |
David Greene | 05bce0b | 2011-07-29 22:43:06 +0000 | [diff] [blame] | 99 | DagInit *MIOI = Inst.Operands[i].MIOperandInfo; |
Owen Anderson | bea6f61 | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 100 | |
Chris Lattner | f196839 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 101 | if (!MIOI || MIOI->getNumArgs() == 0) { |
| 102 | // Single, anonymous, operand. |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 103 | OperandList.push_back(Inst.Operands[i]); |
Chris Lattner | 65303d6 | 2005-11-19 07:05:57 +0000 | [diff] [blame] | 104 | } else { |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 105 | for (unsigned j = 0, e = Inst.Operands[i].MINumOperands; j != e; ++j) { |
| 106 | OperandList.push_back(Inst.Operands[i]); |
Chris Lattner | a0cca4a | 2006-11-06 23:49:51 +0000 | [diff] [blame] | 107 | |
Sean Silva | 3f7b7f8 | 2012-10-10 20:24:47 +0000 | [diff] [blame] | 108 | Record *OpR = cast<DefInit>(MIOI->getArg(j))->getDef(); |
Chris Lattner | f196839 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 109 | OperandList.back().Rec = OpR; |
Chris Lattner | 65303d6 | 2005-11-19 07:05:57 +0000 | [diff] [blame] | 110 | } |
Chris Lattner | d5aa3e2 | 2005-08-19 18:46:26 +0000 | [diff] [blame] | 111 | } |
Chris Lattner | f196839 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 112 | |
| 113 | for (unsigned j = 0, e = OperandList.size(); j != e; ++j) { |
| 114 | Record *OpR = OperandList[j].Rec; |
| 115 | std::string Res; |
Owen Anderson | bea6f61 | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 116 | |
| 117 | if (OpR->isSubClassOf("RegisterOperand")) |
| 118 | OpR = OpR->getValueAsDef("RegClass"); |
Chris Lattner | f196839 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 119 | if (OpR->isSubClassOf("RegisterClass")) |
| 120 | Res += getQualifiedName(OpR) + "RegClassID, "; |
Chris Lattner | cb778a8 | 2009-07-29 21:10:12 +0000 | [diff] [blame] | 121 | else if (OpR->isSubClassOf("PointerLikeRegClass")) |
| 122 | Res += utostr(OpR->getValueAsInt("RegClassKind")) + ", "; |
Chris Lattner | f196839 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 123 | else |
Dan Gohman | a606d95 | 2010-06-18 18:13:55 +0000 | [diff] [blame] | 124 | // -1 means the operand does not have a fixed register class. |
| 125 | Res += "-1, "; |
Owen Anderson | bea6f61 | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 126 | |
Chris Lattner | f196839 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 127 | // Fill in applicable flags. |
| 128 | Res += "0"; |
Owen Anderson | bea6f61 | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 129 | |
Chris Lattner | f196839 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 130 | // Ptr value whose register class is resolved via callback. |
Chris Lattner | a938ac6 | 2009-07-29 20:43:05 +0000 | [diff] [blame] | 131 | if (OpR->isSubClassOf("PointerLikeRegClass")) |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 132 | Res += "|(1<<MCOI::LookupPtrRegClass)"; |
Chris Lattner | f196839 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 133 | |
| 134 | // Predicate operands. Check to see if the original unexpanded operand |
| 135 | // was of type PredicateOperand. |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 136 | if (Inst.Operands[i].Rec->isSubClassOf("PredicateOperand")) |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 137 | Res += "|(1<<MCOI::Predicate)"; |
Owen Anderson | bea6f61 | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 138 | |
Evan Cheng | 88cc092 | 2007-07-10 18:05:01 +0000 | [diff] [blame] | 139 | // Optional def operands. Check to see if the original unexpanded operand |
| 140 | // was of type OptionalDefOperand. |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 141 | if (Inst.Operands[i].Rec->isSubClassOf("OptionalDefOperand")) |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 142 | Res += "|(1<<MCOI::OptionalDef)"; |
Evan Cheng | 88cc092 | 2007-07-10 18:05:01 +0000 | [diff] [blame] | 143 | |
Craig Topper | 39bdc55 | 2012-03-11 01:57:56 +0000 | [diff] [blame] | 144 | // Fill in operand type. |
| 145 | Res += ", MCOI::"; |
| 146 | assert(!Inst.Operands[i].OperandType.empty() && "Invalid operand type."); |
| 147 | Res += Inst.Operands[i].OperandType; |
| 148 | |
Chris Lattner | f196839 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 149 | // Fill in constraint info. |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 150 | Res += ", "; |
Owen Anderson | bea6f61 | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 151 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 152 | const CGIOperandList::ConstraintInfo &Constraint = |
| 153 | Inst.Operands[i].Constraints[j]; |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 154 | if (Constraint.isNone()) |
| 155 | Res += "0"; |
| 156 | else if (Constraint.isEarlyClobber()) |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 157 | Res += "(1 << MCOI::EARLY_CLOBBER)"; |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 158 | else { |
| 159 | assert(Constraint.isTied()); |
| 160 | Res += "((" + utostr(Constraint.getTiedOperand()) + |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 161 | " << 16) | (1 << MCOI::TIED_TO))"; |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 162 | } |
Owen Anderson | bea6f61 | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 163 | |
Chris Lattner | f196839 | 2006-11-10 02:01:40 +0000 | [diff] [blame] | 164 | Result.push_back(Res); |
| 165 | } |
Chris Lattner | d5aa3e2 | 2005-08-19 18:46:26 +0000 | [diff] [blame] | 166 | } |
Evan Cheng | e2ba897 | 2006-11-01 00:27:05 +0000 | [diff] [blame] | 167 | |
Chris Lattner | d5aa3e2 | 2005-08-19 18:46:26 +0000 | [diff] [blame] | 168 | return Result; |
| 169 | } |
| 170 | |
Owen Anderson | bea6f61 | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 171 | void InstrInfoEmitter::EmitOperandInfo(raw_ostream &OS, |
Chris Lattner | ef8339b | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 172 | OperandInfoMapTy &OperandInfoIDs) { |
| 173 | // ID #0 is for no operand info. |
| 174 | unsigned OperandListNum = 0; |
| 175 | OperandInfoIDs[std::vector<std::string>()] = ++OperandListNum; |
Owen Anderson | bea6f61 | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 176 | |
Chris Lattner | ef8339b | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 177 | OS << "\n"; |
| 178 | const CodeGenTarget &Target = CDP.getTargetInfo(); |
| 179 | for (CodeGenTarget::inst_iterator II = Target.inst_begin(), |
| 180 | E = Target.inst_end(); II != E; ++II) { |
Chris Lattner | 6a91b18 | 2010-03-19 01:00:55 +0000 | [diff] [blame] | 181 | std::vector<std::string> OperandInfo = GetOperandInfo(**II); |
Chris Lattner | ef8339b | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 182 | unsigned &N = OperandInfoIDs[OperandInfo]; |
| 183 | if (N != 0) continue; |
Owen Anderson | bea6f61 | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 184 | |
Chris Lattner | ef8339b | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 185 | N = ++OperandListNum; |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 186 | OS << "static const MCOperandInfo OperandInfo" << N << "[] = { "; |
Chris Lattner | ef8339b | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 187 | for (unsigned i = 0, e = OperandInfo.size(); i != e; ++i) |
| 188 | OS << "{ " << OperandInfo[i] << " }, "; |
| 189 | OS << "};\n"; |
| 190 | } |
| 191 | } |
| 192 | |
Tom Stellard | 898b9f0 | 2013-06-25 21:22:09 +0000 | [diff] [blame] | 193 | |
| 194 | /// Initialize data structures for generating operand name mappings. |
| 195 | /// |
| 196 | /// \param Operands [out] A map used to generate the OpName enum with operand |
| 197 | /// names as its keys and operand enum values as its values. |
| 198 | /// \param OperandMap [out] A map for representing the operand name mappings for |
| 199 | /// each instructions. This is used to generate the OperandMap table as |
| 200 | /// well as the getNamedOperandIdx() function. |
| 201 | void InstrInfoEmitter::initOperandMapData( |
| 202 | const std::vector<const CodeGenInstruction *> NumberedInstructions, |
| 203 | const std::string &Namespace, |
| 204 | std::map<std::string, unsigned> &Operands, |
| 205 | OpNameMapTy &OperandMap) { |
| 206 | |
| 207 | unsigned NumOperands = 0; |
| 208 | for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) { |
| 209 | const CodeGenInstruction *Inst = NumberedInstructions[i]; |
| 210 | if (!Inst->TheDef->getValueAsBit("UseNamedOperandTable")) { |
| 211 | continue; |
| 212 | } |
| 213 | std::map<unsigned, unsigned> OpList; |
| 214 | for (unsigned j = 0, je = Inst->Operands.size(); j != je; ++j) { |
| 215 | const CGIOperandList::OperandInfo &Info = Inst->Operands[j]; |
| 216 | StrUintMapIter I = Operands.find(Info.Name); |
| 217 | |
| 218 | if (I == Operands.end()) { |
| 219 | I = Operands.insert(Operands.begin(), |
| 220 | std::pair<std::string, unsigned>(Info.Name, NumOperands++)); |
| 221 | } |
| 222 | OpList[I->second] = Info.MIOperandNo; |
| 223 | } |
| 224 | OperandMap[OpList].push_back(Namespace + "::" + Inst->TheDef->getName()); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | /// Generate a table and function for looking up the indices of operands by |
| 229 | /// name. |
| 230 | /// |
| 231 | /// This code generates: |
| 232 | /// - An enum in the llvm::TargetNamespace::OpName namespace, with one entry |
| 233 | /// for each operand name. |
| 234 | /// - A 2-dimensional table called OperandMap for mapping OpName enum values to |
| 235 | /// operand indices. |
| 236 | /// - A function called getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx) |
| 237 | /// for looking up the operand index for an instruction, given a value from |
| 238 | /// OpName enum |
| 239 | void InstrInfoEmitter::emitOperandNameMappings(raw_ostream &OS, |
| 240 | const CodeGenTarget &Target, |
| 241 | const std::vector<const CodeGenInstruction*> &NumberedInstructions) { |
| 242 | |
| 243 | const std::string &Namespace = Target.getInstNamespace(); |
| 244 | std::string OpNameNS = "OpName"; |
| 245 | // Map of operand names to their enumeration value. This will be used to |
| 246 | // generate the OpName enum. |
| 247 | std::map<std::string, unsigned> Operands; |
| 248 | OpNameMapTy OperandMap; |
| 249 | |
| 250 | initOperandMapData(NumberedInstructions, Namespace, Operands, OperandMap); |
| 251 | |
| 252 | OS << "#ifdef GET_INSTRINFO_OPERAND_ENUM\n"; |
| 253 | OS << "#undef GET_INSTRINFO_OPERAND_ENUM\n"; |
| 254 | OS << "namespace llvm {"; |
| 255 | OS << "namespace " << Namespace << " {\n"; |
| 256 | OS << "namespace " << OpNameNS << " { \n"; |
| 257 | OS << "enum {\n"; |
| 258 | for (StrUintMapIter i = Operands.begin(), e = Operands.end(); i != e; ++i) |
| 259 | OS << " " << i->first << " = " << i->second << ",\n"; |
| 260 | |
| 261 | OS << "OPERAND_LAST"; |
| 262 | OS << "\n};\n"; |
| 263 | OS << "} // End namespace OpName\n"; |
| 264 | OS << "} // End namespace " << Namespace << "\n"; |
| 265 | OS << "} // End namespace llvm\n"; |
| 266 | OS << "#endif //GET_INSTRINFO_OPERAND_ENUM\n"; |
| 267 | |
| 268 | OS << "#ifdef GET_INSTRINFO_NAMED_OPS\n"; |
| 269 | OS << "#undef GET_INSTRINFO_NAMED_OPS\n"; |
| 270 | OS << "namespace llvm {"; |
| 271 | OS << "namespace " << Namespace << " {\n"; |
| 272 | OS << "int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx) {\n"; |
Aaron Ballman | 54911a5 | 2013-07-15 16:53:32 +0000 | [diff] [blame^] | 273 | if (!Operands.empty()) { |
| 274 | OS << " static const int16_t OperandMap [][" << Operands.size() |
| 275 | << "] = {\n"; |
| 276 | for (OpNameMapTy::iterator i = OperandMap.begin(), e = OperandMap.end(); |
| 277 | i != e; ++i) { |
| 278 | const std::map<unsigned, unsigned> &OpList = i->first; |
| 279 | OS << "{"; |
Tom Stellard | 898b9f0 | 2013-06-25 21:22:09 +0000 | [diff] [blame] | 280 | |
Aaron Ballman | 54911a5 | 2013-07-15 16:53:32 +0000 | [diff] [blame^] | 281 | // Emit a row of the OperandMap table |
| 282 | for (unsigned ii = 0, ie = Operands.size(); ii != ie; ++ii) |
| 283 | OS << (OpList.count(ii) == 0 ? -1 : (int)OpList.find(ii)->second) |
| 284 | << ", "; |
Tom Stellard | 898b9f0 | 2013-06-25 21:22:09 +0000 | [diff] [blame] | 285 | |
Aaron Ballman | 54911a5 | 2013-07-15 16:53:32 +0000 | [diff] [blame^] | 286 | OS << "},\n"; |
| 287 | } |
| 288 | OS << "};\n"; |
| 289 | |
| 290 | OS << " switch(Opcode) {\n"; |
| 291 | unsigned TableIndex = 0; |
| 292 | for (OpNameMapTy::iterator i = OperandMap.begin(), e = OperandMap.end(); |
| 293 | i != e; ++i) { |
| 294 | std::vector<std::string> &OpcodeList = i->second; |
| 295 | |
| 296 | for (unsigned ii = 0, ie = OpcodeList.size(); ii != ie; ++ii) |
| 297 | OS << " case " << OpcodeList[ii] << ":\n"; |
| 298 | |
| 299 | OS << " return OperandMap[" << TableIndex++ << "][NamedIdx];\n"; |
| 300 | } |
| 301 | OS << " default: return -1;\n"; |
| 302 | OS << " }\n"; |
| 303 | } else { |
| 304 | // There are no operands, so no need to emit anything |
| 305 | OS << " return -1;\n"; |
Tom Stellard | 898b9f0 | 2013-06-25 21:22:09 +0000 | [diff] [blame] | 306 | } |
Tom Stellard | 898b9f0 | 2013-06-25 21:22:09 +0000 | [diff] [blame] | 307 | OS << "}\n"; |
| 308 | OS << "} // End namespace " << Namespace << "\n"; |
| 309 | OS << "} // End namespace llvm\n"; |
| 310 | OS << "#endif //GET_INSTRINFO_NAMED_OPS\n"; |
| 311 | |
| 312 | } |
| 313 | |
Chris Lattner | ef8339b | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 314 | //===----------------------------------------------------------------------===// |
| 315 | // Main Output. |
| 316 | //===----------------------------------------------------------------------===// |
Chris Lattner | a3ae614 | 2003-08-03 21:57:51 +0000 | [diff] [blame] | 317 | |
| 318 | // run - Emit the main instruction description records for the target... |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 319 | void InstrInfoEmitter::run(raw_ostream &OS) { |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 320 | emitSourceFileHeader("Target Instruction Enum Values", OS); |
Evan Cheng | 22fee2d | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 321 | emitEnums(OS); |
| 322 | |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 323 | emitSourceFileHeader("Target Instruction Descriptors", OS); |
Evan Cheng | 22fee2d | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 324 | |
| 325 | OS << "\n#ifdef GET_INSTRINFO_MC_DESC\n"; |
| 326 | OS << "#undef GET_INSTRINFO_MC_DESC\n"; |
| 327 | |
Chris Lattner | 2c38413 | 2004-08-17 03:08:28 +0000 | [diff] [blame] | 328 | OS << "namespace llvm {\n\n"; |
| 329 | |
Dan Gohman | ee4fa19 | 2008-04-03 00:02:49 +0000 | [diff] [blame] | 330 | CodeGenTarget &Target = CDP.getTargetInfo(); |
Chris Lattner | 7884b75 | 2003-08-07 05:39:09 +0000 | [diff] [blame] | 331 | const std::string &TargetName = Target.getName(); |
| 332 | Record *InstrInfo = Target.getInstructionSet(); |
Chris Lattner | a3ae614 | 2003-08-03 21:57:51 +0000 | [diff] [blame] | 333 | |
Chris Lattner | a3ac88d | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 334 | // Keep track of all of the def lists we have emitted already. |
| 335 | std::map<std::vector<Record*>, unsigned> EmittedLists; |
Chris Lattner | a3ac88d | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 336 | unsigned ListNumber = 0; |
Owen Anderson | bea6f61 | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 337 | |
Chris Lattner | a3ac88d | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 338 | // Emit all of the instruction's implicit uses and defs. |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 339 | for (CodeGenTarget::inst_iterator II = Target.inst_begin(), |
| 340 | E = Target.inst_end(); II != E; ++II) { |
Chris Lattner | 6a91b18 | 2010-03-19 01:00:55 +0000 | [diff] [blame] | 341 | Record *Inst = (*II)->TheDef; |
Chris Lattner | 366080c | 2005-10-28 22:59:53 +0000 | [diff] [blame] | 342 | std::vector<Record*> Uses = Inst->getValueAsListOfDefs("Uses"); |
| 343 | if (!Uses.empty()) { |
Chris Lattner | a3ac88d | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 344 | unsigned &IL = EmittedLists[Uses]; |
Chris Lattner | 5fbe275 | 2008-01-06 01:21:51 +0000 | [diff] [blame] | 345 | if (!IL) PrintDefList(Uses, IL = ++ListNumber, OS); |
Chris Lattner | a3ac88d | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 346 | } |
Chris Lattner | 366080c | 2005-10-28 22:59:53 +0000 | [diff] [blame] | 347 | std::vector<Record*> Defs = Inst->getValueAsListOfDefs("Defs"); |
| 348 | if (!Defs.empty()) { |
| 349 | unsigned &IL = EmittedLists[Defs]; |
Chris Lattner | 5fbe275 | 2008-01-06 01:21:51 +0000 | [diff] [blame] | 350 | if (!IL) PrintDefList(Defs, IL = ++ListNumber, OS); |
Chris Lattner | a3ac88d | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 351 | } |
Chris Lattner | a3ae614 | 2003-08-03 21:57:51 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Chris Lattner | ef8339b | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 354 | OperandInfoMapTy OperandInfoIDs; |
Owen Anderson | bea6f61 | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 355 | |
Chris Lattner | 0e384b6 | 2005-08-19 16:57:28 +0000 | [diff] [blame] | 356 | // Emit all of the operand info records. |
Chris Lattner | ef8339b | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 357 | EmitOperandInfo(OS, OperandInfoIDs); |
Owen Anderson | bea6f61 | 2011-06-27 21:06:21 +0000 | [diff] [blame] | 358 | |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 359 | // Emit all of the MCInstrDesc records in their ENUM ordering. |
Chris Lattner | 0e384b6 | 2005-08-19 16:57:28 +0000 | [diff] [blame] | 360 | // |
Benjamin Kramer | 1a2f988 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 361 | OS << "\nextern const MCInstrDesc " << TargetName << "Insts[] = {\n"; |
Chris Lattner | f650278 | 2010-03-19 00:34:35 +0000 | [diff] [blame] | 362 | const std::vector<const CodeGenInstruction*> &NumberedInstructions = |
| 363 | Target.getInstructionsByEnumValue(); |
Chris Lattner | a3ae614 | 2003-08-03 21:57:51 +0000 | [diff] [blame] | 364 | |
Chris Lattner | f52e261 | 2006-01-27 01:44:09 +0000 | [diff] [blame] | 365 | for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) |
| 366 | emitRecord(*NumberedInstructions[i], i, InstrInfo, EmittedLists, |
Evan Cheng | 4db3748 | 2011-06-27 23:47:21 +0000 | [diff] [blame] | 367 | OperandInfoIDs, OS); |
Evan Cheng | 94b01f6 | 2011-06-28 20:29:03 +0000 | [diff] [blame] | 368 | OS << "};\n\n"; |
| 369 | |
Craig Topper | 413b2e7 | 2012-04-01 18:14:14 +0000 | [diff] [blame] | 370 | // Build an array of instruction names |
| 371 | SequenceToOffsetTable<std::string> InstrNames; |
Benjamin Kramer | c667ba6 | 2012-02-10 13:18:44 +0000 | [diff] [blame] | 372 | for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) { |
| 373 | const CodeGenInstruction *Instr = NumberedInstructions[i]; |
Craig Topper | 413b2e7 | 2012-04-01 18:14:14 +0000 | [diff] [blame] | 374 | InstrNames.add(Instr->TheDef->getName()); |
| 375 | } |
| 376 | |
| 377 | InstrNames.layout(); |
| 378 | OS << "extern const char " << TargetName << "InstrNameData[] = {\n"; |
| 379 | InstrNames.emit(OS, printChar); |
| 380 | OS << "};\n\n"; |
| 381 | |
| 382 | OS << "extern const unsigned " << TargetName <<"InstrNameIndices[] = {"; |
| 383 | for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) { |
Benjamin Kramer | c667ba6 | 2012-02-10 13:18:44 +0000 | [diff] [blame] | 384 | if (i % 8 == 0) |
| 385 | OS << "\n "; |
Craig Topper | 413b2e7 | 2012-04-01 18:14:14 +0000 | [diff] [blame] | 386 | const CodeGenInstruction *Instr = NumberedInstructions[i]; |
| 387 | OS << InstrNames.get(Instr->TheDef->getName()) << "U, "; |
Benjamin Kramer | c667ba6 | 2012-02-10 13:18:44 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | OS << "\n};\n\n"; |
| 391 | |
Evan Cheng | 94b01f6 | 2011-06-28 20:29:03 +0000 | [diff] [blame] | 392 | // MCInstrInfo initialization routine. |
| 393 | OS << "static inline void Init" << TargetName |
| 394 | << "MCInstrInfo(MCInstrInfo *II) {\n"; |
| 395 | OS << " II->InitMCInstrInfo(" << TargetName << "Insts, " |
Benjamin Kramer | c667ba6 | 2012-02-10 13:18:44 +0000 | [diff] [blame] | 396 | << TargetName << "InstrNameIndices, " << TargetName << "InstrNameData, " |
Evan Cheng | 94b01f6 | 2011-06-28 20:29:03 +0000 | [diff] [blame] | 397 | << NumberedInstructions.size() << ");\n}\n\n"; |
| 398 | |
Chris Lattner | 2c38413 | 2004-08-17 03:08:28 +0000 | [diff] [blame] | 399 | OS << "} // End llvm namespace \n"; |
Evan Cheng | 22fee2d | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 400 | |
| 401 | OS << "#endif // GET_INSTRINFO_MC_DESC\n\n"; |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 402 | |
| 403 | // Create a TargetInstrInfo subclass to hide the MC layer initialization. |
| 404 | OS << "\n#ifdef GET_INSTRINFO_HEADER\n"; |
| 405 | OS << "#undef GET_INSTRINFO_HEADER\n"; |
| 406 | |
| 407 | std::string ClassName = TargetName + "GenInstrInfo"; |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 408 | OS << "namespace llvm {\n"; |
Jakob Stoklund Olesen | a9fa4fd | 2012-11-28 02:35:17 +0000 | [diff] [blame] | 409 | OS << "struct " << ClassName << " : public TargetInstrInfo {\n" |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 410 | << " explicit " << ClassName << "(int SO = -1, int DO = -1);\n" |
| 411 | << "};\n"; |
| 412 | OS << "} // End llvm namespace \n"; |
| 413 | |
| 414 | OS << "#endif // GET_INSTRINFO_HEADER\n\n"; |
| 415 | |
| 416 | OS << "\n#ifdef GET_INSTRINFO_CTOR\n"; |
| 417 | OS << "#undef GET_INSTRINFO_CTOR\n"; |
| 418 | |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 419 | OS << "namespace llvm {\n"; |
Benjamin Kramer | 1a2f988 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 420 | OS << "extern const MCInstrDesc " << TargetName << "Insts[];\n"; |
Jakob Stoklund Olesen | bcfa982 | 2012-03-15 18:05:57 +0000 | [diff] [blame] | 421 | OS << "extern const unsigned " << TargetName << "InstrNameIndices[];\n"; |
Craig Topper | 413b2e7 | 2012-04-01 18:14:14 +0000 | [diff] [blame] | 422 | OS << "extern const char " << TargetName << "InstrNameData[];\n"; |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 423 | OS << ClassName << "::" << ClassName << "(int SO, int DO)\n" |
Jakob Stoklund Olesen | a9fa4fd | 2012-11-28 02:35:17 +0000 | [diff] [blame] | 424 | << " : TargetInstrInfo(SO, DO) {\n" |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 425 | << " InitMCInstrInfo(" << TargetName << "Insts, " |
Benjamin Kramer | c667ba6 | 2012-02-10 13:18:44 +0000 | [diff] [blame] | 426 | << TargetName << "InstrNameIndices, " << TargetName << "InstrNameData, " |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 427 | << NumberedInstructions.size() << ");\n}\n"; |
| 428 | OS << "} // End llvm namespace \n"; |
| 429 | |
| 430 | OS << "#endif // GET_INSTRINFO_CTOR\n\n"; |
Tom Stellard | 898b9f0 | 2013-06-25 21:22:09 +0000 | [diff] [blame] | 431 | |
| 432 | emitOperandNameMappings(OS, Target, NumberedInstructions); |
Chris Lattner | a3ae614 | 2003-08-03 21:57:51 +0000 | [diff] [blame] | 433 | } |
| 434 | |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 435 | void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num, |
Chris Lattner | a3ac88d | 2005-08-18 21:36:47 +0000 | [diff] [blame] | 436 | Record *InstrInfo, |
Chris Lattner | 366080c | 2005-10-28 22:59:53 +0000 | [diff] [blame] | 437 | std::map<std::vector<Record*>, unsigned> &EmittedLists, |
Chris Lattner | ef8339b | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 438 | const OperandInfoMapTy &OpInfo, |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 439 | raw_ostream &OS) { |
Chris Lattner | a529a37 | 2008-01-06 01:53:37 +0000 | [diff] [blame] | 440 | int MinOperands = 0; |
Richard Trieu | 5628920 | 2012-10-12 17:57:35 +0000 | [diff] [blame] | 441 | if (!Inst.Operands.empty()) |
Chris Lattner | d98958f | 2005-08-19 00:59:49 +0000 | [diff] [blame] | 442 | // Each logical operand can be multiple MI operands. |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 443 | MinOperands = Inst.Operands.back().MIOperandNo + |
| 444 | Inst.Operands.back().MINumOperands; |
Dan Gohman | d35121a | 2008-05-29 19:57:41 +0000 | [diff] [blame] | 445 | |
Evan Cheng | fb1aab0 | 2006-11-17 01:46:27 +0000 | [diff] [blame] | 446 | OS << " { "; |
Evan Cheng | b591082 | 2007-08-02 00:20:17 +0000 | [diff] [blame] | 447 | OS << Num << ",\t" << MinOperands << ",\t" |
Owen Anderson | 1688441 | 2011-07-13 23:22:26 +0000 | [diff] [blame] | 448 | << Inst.Operands.NumDefs << ",\t" |
Andrew Trick | e3dbc98 | 2012-09-18 03:55:55 +0000 | [diff] [blame] | 449 | << SchedModels.getSchedClassIdx(Inst) << ",\t" |
Benjamin Kramer | 133f9d9 | 2012-02-09 11:25:09 +0000 | [diff] [blame] | 450 | << Inst.TheDef->getValueAsInt("Size") << ",\t0"; |
Chris Lattner | a3ae614 | 2003-08-03 21:57:51 +0000 | [diff] [blame] | 451 | |
| 452 | // Emit all of the target indepedent flags... |
Jakob Stoklund Olesen | c291e2f | 2011-09-25 19:21:35 +0000 | [diff] [blame] | 453 | if (Inst.isPseudo) OS << "|(1<<MCID::Pseudo)"; |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 454 | if (Inst.isReturn) OS << "|(1<<MCID::Return)"; |
| 455 | if (Inst.isBranch) OS << "|(1<<MCID::Branch)"; |
| 456 | if (Inst.isIndirectBranch) OS << "|(1<<MCID::IndirectBranch)"; |
| 457 | if (Inst.isCompare) OS << "|(1<<MCID::Compare)"; |
| 458 | if (Inst.isMoveImm) OS << "|(1<<MCID::MoveImm)"; |
| 459 | if (Inst.isBitcast) OS << "|(1<<MCID::Bitcast)"; |
Jakob Stoklund Olesen | f2c64ef | 2012-08-16 23:11:47 +0000 | [diff] [blame] | 460 | if (Inst.isSelect) OS << "|(1<<MCID::Select)"; |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 461 | if (Inst.isBarrier) OS << "|(1<<MCID::Barrier)"; |
| 462 | if (Inst.hasDelaySlot) OS << "|(1<<MCID::DelaySlot)"; |
| 463 | if (Inst.isCall) OS << "|(1<<MCID::Call)"; |
| 464 | if (Inst.canFoldAsLoad) OS << "|(1<<MCID::FoldableAsLoad)"; |
| 465 | if (Inst.mayLoad) OS << "|(1<<MCID::MayLoad)"; |
| 466 | if (Inst.mayStore) OS << "|(1<<MCID::MayStore)"; |
| 467 | if (Inst.isPredicable) OS << "|(1<<MCID::Predicable)"; |
| 468 | if (Inst.isConvertibleToThreeAddress) OS << "|(1<<MCID::ConvertibleTo3Addr)"; |
| 469 | if (Inst.isCommutable) OS << "|(1<<MCID::Commutable)"; |
| 470 | if (Inst.isTerminator) OS << "|(1<<MCID::Terminator)"; |
| 471 | if (Inst.isReMaterializable) OS << "|(1<<MCID::Rematerializable)"; |
| 472 | if (Inst.isNotDuplicable) OS << "|(1<<MCID::NotDuplicable)"; |
| 473 | if (Inst.Operands.hasOptionalDef) OS << "|(1<<MCID::HasOptionalDef)"; |
| 474 | if (Inst.usesCustomInserter) OS << "|(1<<MCID::UsesCustomInserter)"; |
Andrew Trick | 83a8031 | 2011-09-20 18:22:31 +0000 | [diff] [blame] | 475 | if (Inst.hasPostISelHook) OS << "|(1<<MCID::HasPostISelHook)"; |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 476 | if (Inst.Operands.isVariadic)OS << "|(1<<MCID::Variadic)"; |
| 477 | if (Inst.hasSideEffects) OS << "|(1<<MCID::UnmodeledSideEffects)"; |
| 478 | if (Inst.isAsCheapAsAMove) OS << "|(1<<MCID::CheapAsAMove)"; |
| 479 | if (Inst.hasExtraSrcRegAllocReq) OS << "|(1<<MCID::ExtraSrcRegAllocReq)"; |
| 480 | if (Inst.hasExtraDefRegAllocReq) OS << "|(1<<MCID::ExtraDefRegAllocReq)"; |
Chris Lattner | a3ae614 | 2003-08-03 21:57:51 +0000 | [diff] [blame] | 481 | |
| 482 | // Emit all of the target-specific flags... |
David Greene | 05bce0b | 2011-07-29 22:43:06 +0000 | [diff] [blame] | 483 | BitsInit *TSF = Inst.TheDef->getValueAsBitsInit("TSFlags"); |
Joerg Sonnenberger | 61131ab | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 484 | if (!TSF) |
| 485 | PrintFatalError("no TSFlags?"); |
Jakob Stoklund Olesen | fddb766 | 2010-04-05 03:10:20 +0000 | [diff] [blame] | 486 | uint64_t Value = 0; |
| 487 | for (unsigned i = 0, e = TSF->getNumBits(); i != e; ++i) { |
Sean Silva | 6cfc806 | 2012-10-10 20:24:43 +0000 | [diff] [blame] | 488 | if (BitInit *Bit = dyn_cast<BitInit>(TSF->getBit(i))) |
Jakob Stoklund Olesen | fddb766 | 2010-04-05 03:10:20 +0000 | [diff] [blame] | 489 | Value |= uint64_t(Bit->getValue()) << i; |
| 490 | else |
Joerg Sonnenberger | 61131ab | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 491 | PrintFatalError("Invalid TSFlags bit in " + Inst.TheDef->getName()); |
Jakob Stoklund Olesen | fddb766 | 2010-04-05 03:10:20 +0000 | [diff] [blame] | 492 | } |
| 493 | OS << ", 0x"; |
| 494 | OS.write_hex(Value); |
Eric Christopher | 622dffd | 2010-06-09 16:16:48 +0000 | [diff] [blame] | 495 | OS << "ULL, "; |
Chris Lattner | a3ae614 | 2003-08-03 21:57:51 +0000 | [diff] [blame] | 496 | |
| 497 | // Emit the implicit uses and defs lists... |
Chris Lattner | 366080c | 2005-10-28 22:59:53 +0000 | [diff] [blame] | 498 | std::vector<Record*> UseList = Inst.TheDef->getValueAsListOfDefs("Uses"); |
| 499 | if (UseList.empty()) |
Jim Laskey | cd4317e | 2006-07-21 21:15:20 +0000 | [diff] [blame] | 500 | OS << "NULL, "; |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 501 | else |
Chris Lattner | 366080c | 2005-10-28 22:59:53 +0000 | [diff] [blame] | 502 | OS << "ImplicitList" << EmittedLists[UseList] << ", "; |
Chris Lattner | a3ae614 | 2003-08-03 21:57:51 +0000 | [diff] [blame] | 503 | |
Chris Lattner | 366080c | 2005-10-28 22:59:53 +0000 | [diff] [blame] | 504 | std::vector<Record*> DefList = Inst.TheDef->getValueAsListOfDefs("Defs"); |
| 505 | if (DefList.empty()) |
Jim Laskey | cd4317e | 2006-07-21 21:15:20 +0000 | [diff] [blame] | 506 | OS << "NULL, "; |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 507 | else |
Chris Lattner | 366080c | 2005-10-28 22:59:53 +0000 | [diff] [blame] | 508 | OS << "ImplicitList" << EmittedLists[DefList] << ", "; |
Chris Lattner | a3ae614 | 2003-08-03 21:57:51 +0000 | [diff] [blame] | 509 | |
Chris Lattner | 0e384b6 | 2005-08-19 16:57:28 +0000 | [diff] [blame] | 510 | // Emit the operand info. |
Chris Lattner | a0cca4a | 2006-11-06 23:49:51 +0000 | [diff] [blame] | 511 | std::vector<std::string> OperandInfo = GetOperandInfo(Inst); |
Chris Lattner | d5aa3e2 | 2005-08-19 18:46:26 +0000 | [diff] [blame] | 512 | if (OperandInfo.empty()) |
| 513 | OS << "0"; |
Chris Lattner | 0e384b6 | 2005-08-19 16:57:28 +0000 | [diff] [blame] | 514 | else |
Chris Lattner | ef8339b | 2008-01-06 01:20:13 +0000 | [diff] [blame] | 515 | OS << "OperandInfo" << OpInfo.find(OperandInfo)->second; |
Jakob Stoklund Olesen | fddb766 | 2010-04-05 03:10:20 +0000 | [diff] [blame] | 516 | |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 517 | OS << " }, // Inst #" << Num << " = " << Inst.TheDef->getName() << "\n"; |
Chris Lattner | a3ae614 | 2003-08-03 21:57:51 +0000 | [diff] [blame] | 518 | } |
Evan Cheng | 22fee2d | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 519 | |
| 520 | // emitEnums - Print out enum values for all of the instructions. |
| 521 | void InstrInfoEmitter::emitEnums(raw_ostream &OS) { |
Evan Cheng | 22fee2d | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 522 | |
| 523 | OS << "\n#ifdef GET_INSTRINFO_ENUM\n"; |
| 524 | OS << "#undef GET_INSTRINFO_ENUM\n"; |
| 525 | |
| 526 | OS << "namespace llvm {\n\n"; |
| 527 | |
| 528 | CodeGenTarget Target(Records); |
| 529 | |
| 530 | // We must emit the PHI opcode first... |
| 531 | std::string Namespace = Target.getInstNamespace(); |
Jim Grosbach | bf1aab1 | 2012-04-11 21:02:30 +0000 | [diff] [blame] | 532 | |
Evan Cheng | 22fee2d | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 533 | if (Namespace.empty()) { |
| 534 | fprintf(stderr, "No instructions defined!\n"); |
| 535 | exit(1); |
| 536 | } |
| 537 | |
| 538 | const std::vector<const CodeGenInstruction*> &NumberedInstructions = |
| 539 | Target.getInstructionsByEnumValue(); |
| 540 | |
| 541 | OS << "namespace " << Namespace << " {\n"; |
| 542 | OS << " enum {\n"; |
| 543 | for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) { |
| 544 | OS << " " << NumberedInstructions[i]->TheDef->getName() |
| 545 | << "\t= " << i << ",\n"; |
| 546 | } |
| 547 | OS << " INSTRUCTION_LIST_END = " << NumberedInstructions.size() << "\n"; |
| 548 | OS << " };\n}\n"; |
| 549 | OS << "} // End llvm namespace \n"; |
| 550 | |
| 551 | OS << "#endif // GET_INSTRINFO_ENUM\n\n"; |
| 552 | } |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 553 | |
| 554 | namespace llvm { |
| 555 | |
| 556 | void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) { |
| 557 | InstrInfoEmitter(RK).run(OS); |
Sebastian Pop | becdf4d | 2012-10-25 15:54:06 +0000 | [diff] [blame] | 558 | EmitMapTable(RK, OS); |
Jakob Stoklund Olesen | 6f36fa9 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | } // End llvm namespace |