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