Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 1 | //===- CodeGenTarget.cpp - CodeGen Target Class Wrapper -------------------===// |
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 | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 10 | // This class wraps target description classes used by the various code |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 11 | // generation TableGen backends. This makes it easier to access the data and |
| 12 | // provides a single place that needs to check it for validity. All of these |
| 13 | // classes throw exceptions on error conditions. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
Chris Lattner | 803a5f6 | 2004-08-01 04:04:35 +0000 | [diff] [blame] | 17 | #include "CodeGenTarget.h" |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 18 | #include "CodeGenIntrinsics.h" |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 19 | #include "Record.h" |
Chris Lattner | 560a79f | 2004-10-03 19:34:31 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringExtras.h" |
| 21 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | 75ee2eb | 2005-10-14 03:54:49 +0000 | [diff] [blame] | 22 | #include <algorithm> |
Chris Lattner | 2082ebe | 2004-08-01 03:55:39 +0000 | [diff] [blame] | 23 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 24 | |
Chris Lattner | 560a79f | 2004-10-03 19:34:31 +0000 | [diff] [blame] | 25 | static cl::opt<unsigned> |
| 26 | AsmWriterNum("asmwriternum", cl::init(0), |
| 27 | cl::desc("Make -gen-asm-writer emit assembly writer #N")); |
| 28 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 29 | /// getValueType - Return the MVT::SimpleValueType that the specified TableGen |
| 30 | /// record corresponds to. |
| 31 | MVT::SimpleValueType llvm::getValueType(Record *Rec) { |
| 32 | return (MVT::SimpleValueType)Rec->getValueAsInt("Value"); |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 35 | std::string llvm::getName(MVT::SimpleValueType T) { |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 36 | switch (T) { |
Chris Lattner | d3464c1 | 2003-08-07 23:15:21 +0000 | [diff] [blame] | 37 | case MVT::Other: return "UNKNOWN"; |
Evan Cheng | d7c2c86 | 2006-06-15 00:16:37 +0000 | [diff] [blame] | 38 | case MVT::i1: return "MVT::i1"; |
| 39 | case MVT::i8: return "MVT::i8"; |
| 40 | case MVT::i16: return "MVT::i16"; |
| 41 | case MVT::i32: return "MVT::i32"; |
| 42 | case MVT::i64: return "MVT::i64"; |
| 43 | case MVT::i128: return "MVT::i128"; |
Reid Spencer | c4de3de | 2007-04-01 07:20:02 +0000 | [diff] [blame] | 44 | case MVT::iAny: return "MVT::iAny"; |
Dan Gohman | 0fee3ff | 2007-08-16 21:57:19 +0000 | [diff] [blame] | 45 | case MVT::fAny: return "MVT::fAny"; |
Evan Cheng | d7c2c86 | 2006-06-15 00:16:37 +0000 | [diff] [blame] | 46 | case MVT::f32: return "MVT::f32"; |
| 47 | case MVT::f64: return "MVT::f64"; |
| 48 | case MVT::f80: return "MVT::f80"; |
| 49 | case MVT::f128: return "MVT::f128"; |
Dale Johannesen | 317096a | 2007-09-28 01:08:20 +0000 | [diff] [blame] | 50 | case MVT::ppcf128: return "MVT::ppcf128"; |
Evan Cheng | d7c2c86 | 2006-06-15 00:16:37 +0000 | [diff] [blame] | 51 | case MVT::Flag: return "MVT::Flag"; |
Dan Gohman | ba6783e | 2008-08-20 01:44:30 +0000 | [diff] [blame] | 52 | case MVT::isVoid:return "MVT::isVoid"; |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 53 | case MVT::v2i8: return "MVT::v2i8"; |
| 54 | case MVT::v4i8: return "MVT::v4i8"; |
Evan Cheng | d7c2c86 | 2006-06-15 00:16:37 +0000 | [diff] [blame] | 55 | case MVT::v8i8: return "MVT::v8i8"; |
Evan Cheng | d7c2c86 | 2006-06-15 00:16:37 +0000 | [diff] [blame] | 56 | case MVT::v16i8: return "MVT::v16i8"; |
David Greene | 9b9838d | 2009-06-29 16:47:10 +0000 | [diff] [blame] | 57 | case MVT::v32i8: return "MVT::v32i8"; |
| 58 | case MVT::v2i16: return "MVT::v2i16"; |
| 59 | case MVT::v4i16: return "MVT::v4i16"; |
Evan Cheng | d7c2c86 | 2006-06-15 00:16:37 +0000 | [diff] [blame] | 60 | case MVT::v8i16: return "MVT::v8i16"; |
David Greene | 9b9838d | 2009-06-29 16:47:10 +0000 | [diff] [blame] | 61 | case MVT::v16i16: return "MVT::v16i16"; |
| 62 | case MVT::v2i32: return "MVT::v2i32"; |
Evan Cheng | d7c2c86 | 2006-06-15 00:16:37 +0000 | [diff] [blame] | 63 | case MVT::v4i32: return "MVT::v4i32"; |
David Greene | 9b9838d | 2009-06-29 16:47:10 +0000 | [diff] [blame] | 64 | case MVT::v8i32: return "MVT::v8i32"; |
| 65 | case MVT::v1i64: return "MVT::v1i64"; |
Evan Cheng | d7c2c86 | 2006-06-15 00:16:37 +0000 | [diff] [blame] | 66 | case MVT::v2i64: return "MVT::v2i64"; |
David Greene | 9b9838d | 2009-06-29 16:47:10 +0000 | [diff] [blame] | 67 | case MVT::v4i64: return "MVT::v4i64"; |
Evan Cheng | d7c2c86 | 2006-06-15 00:16:37 +0000 | [diff] [blame] | 68 | case MVT::v2f32: return "MVT::v2f32"; |
| 69 | case MVT::v4f32: return "MVT::v4f32"; |
David Greene | 9b9838d | 2009-06-29 16:47:10 +0000 | [diff] [blame] | 70 | case MVT::v8f32: return "MVT::v8f32"; |
Evan Cheng | d7c2c86 | 2006-06-15 00:16:37 +0000 | [diff] [blame] | 71 | case MVT::v2f64: return "MVT::v2f64"; |
David Greene | 9b9838d | 2009-06-29 16:47:10 +0000 | [diff] [blame] | 72 | case MVT::v4f64: return "MVT::v4f64"; |
Christopher Lamb | 8245510 | 2007-07-26 06:41:18 +0000 | [diff] [blame] | 73 | case MVT::v3i32: return "MVT::v3i32"; |
| 74 | case MVT::v3f32: return "MVT::v3f32"; |
Evan Cheng | 6b12516 | 2006-05-17 20:55:51 +0000 | [diff] [blame] | 75 | case MVT::iPTR: return "TLI.getPointerTy()"; |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 76 | case MVT::iPTRAny: return "TLI.getPointerTy()"; |
Chris Lattner | d3464c1 | 2003-08-07 23:15:21 +0000 | [diff] [blame] | 77 | default: assert(0 && "ILLEGAL VALUE TYPE!"); return ""; |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 78 | } |
Chris Lattner | d3464c1 | 2003-08-07 23:15:21 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 81 | std::string llvm::getEnumName(MVT::SimpleValueType T) { |
Chris Lattner | b72fb7e | 2003-08-10 19:50:32 +0000 | [diff] [blame] | 82 | switch (T) { |
Evan Cheng | 2618d07 | 2006-05-17 20:37:59 +0000 | [diff] [blame] | 83 | case MVT::Other: return "MVT::Other"; |
| 84 | case MVT::i1: return "MVT::i1"; |
| 85 | case MVT::i8: return "MVT::i8"; |
| 86 | case MVT::i16: return "MVT::i16"; |
| 87 | case MVT::i32: return "MVT::i32"; |
| 88 | case MVT::i64: return "MVT::i64"; |
| 89 | case MVT::i128: return "MVT::i128"; |
Reid Spencer | c4de3de | 2007-04-01 07:20:02 +0000 | [diff] [blame] | 90 | case MVT::iAny: return "MVT::iAny"; |
Dan Gohman | 0fee3ff | 2007-08-16 21:57:19 +0000 | [diff] [blame] | 91 | case MVT::fAny: return "MVT::fAny"; |
Evan Cheng | 2618d07 | 2006-05-17 20:37:59 +0000 | [diff] [blame] | 92 | case MVT::f32: return "MVT::f32"; |
| 93 | case MVT::f64: return "MVT::f64"; |
| 94 | case MVT::f80: return "MVT::f80"; |
| 95 | case MVT::f128: return "MVT::f128"; |
Dale Johannesen | 317096a | 2007-09-28 01:08:20 +0000 | [diff] [blame] | 96 | case MVT::ppcf128: return "MVT::ppcf128"; |
Evan Cheng | 2618d07 | 2006-05-17 20:37:59 +0000 | [diff] [blame] | 97 | case MVT::Flag: return "MVT::Flag"; |
| 98 | case MVT::isVoid:return "MVT::isVoid"; |
Mon P Wang | 87c8a8f | 2008-12-18 20:03:17 +0000 | [diff] [blame] | 99 | case MVT::v2i8: return "MVT::v2i8"; |
| 100 | case MVT::v4i8: return "MVT::v4i8"; |
Evan Cheng | 2618d07 | 2006-05-17 20:37:59 +0000 | [diff] [blame] | 101 | case MVT::v8i8: return "MVT::v8i8"; |
Evan Cheng | 2618d07 | 2006-05-17 20:37:59 +0000 | [diff] [blame] | 102 | case MVT::v16i8: return "MVT::v16i8"; |
David Greene | 9b9838d | 2009-06-29 16:47:10 +0000 | [diff] [blame] | 103 | case MVT::v32i8: return "MVT::v32i8"; |
| 104 | case MVT::v2i16: return "MVT::v2i16"; |
| 105 | case MVT::v4i16: return "MVT::v4i16"; |
Evan Cheng | 2618d07 | 2006-05-17 20:37:59 +0000 | [diff] [blame] | 106 | case MVT::v8i16: return "MVT::v8i16"; |
David Greene | 9b9838d | 2009-06-29 16:47:10 +0000 | [diff] [blame] | 107 | case MVT::v16i16: return "MVT::v16i16"; |
| 108 | case MVT::v2i32: return "MVT::v2i32"; |
Evan Cheng | 2618d07 | 2006-05-17 20:37:59 +0000 | [diff] [blame] | 109 | case MVT::v4i32: return "MVT::v4i32"; |
David Greene | 9b9838d | 2009-06-29 16:47:10 +0000 | [diff] [blame] | 110 | case MVT::v8i32: return "MVT::v8i32"; |
| 111 | case MVT::v1i64: return "MVT::v1i64"; |
Evan Cheng | 2618d07 | 2006-05-17 20:37:59 +0000 | [diff] [blame] | 112 | case MVT::v2i64: return "MVT::v2i64"; |
David Greene | 9b9838d | 2009-06-29 16:47:10 +0000 | [diff] [blame] | 113 | case MVT::v4i64: return "MVT::v4i64"; |
Evan Cheng | 2618d07 | 2006-05-17 20:37:59 +0000 | [diff] [blame] | 114 | case MVT::v2f32: return "MVT::v2f32"; |
| 115 | case MVT::v4f32: return "MVT::v4f32"; |
David Greene | 9b9838d | 2009-06-29 16:47:10 +0000 | [diff] [blame] | 116 | case MVT::v8f32: return "MVT::v8f32"; |
Evan Cheng | 2618d07 | 2006-05-17 20:37:59 +0000 | [diff] [blame] | 117 | case MVT::v2f64: return "MVT::v2f64"; |
David Greene | 9b9838d | 2009-06-29 16:47:10 +0000 | [diff] [blame] | 118 | case MVT::v4f64: return "MVT::v4f64"; |
Christopher Lamb | 8245510 | 2007-07-26 06:41:18 +0000 | [diff] [blame] | 119 | case MVT::v3i32: return "MVT::v3i32"; |
| 120 | case MVT::v3f32: return "MVT::v3f32"; |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 121 | case MVT::iPTR: return "MVT::iPTR"; |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 122 | case MVT::iPTRAny: return "MVT::iPTRAny"; |
Chris Lattner | b72fb7e | 2003-08-10 19:50:32 +0000 | [diff] [blame] | 123 | default: assert(0 && "ILLEGAL VALUE TYPE!"); return ""; |
| 124 | } |
| 125 | } |
| 126 | |
Chris Lattner | 6cefb77 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 127 | /// getQualifiedName - Return the name of the specified record, with a |
| 128 | /// namespace qualifier if the record contains one. |
| 129 | /// |
| 130 | std::string llvm::getQualifiedName(const Record *R) { |
| 131 | std::string Namespace = R->getValueAsString("Namespace"); |
| 132 | if (Namespace.empty()) return R->getName(); |
| 133 | return Namespace + "::" + R->getName(); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | |
Chris Lattner | d3464c1 | 2003-08-07 23:15:21 +0000 | [diff] [blame] | 138 | |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 139 | /// getTarget - Return the current instance of the Target class. |
| 140 | /// |
Evan Cheng | 2618d07 | 2006-05-17 20:37:59 +0000 | [diff] [blame] | 141 | CodeGenTarget::CodeGenTarget() { |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 142 | std::vector<Record*> Targets = Records.getAllDerivedDefinitions("Target"); |
Misha Brukman | bebdb20 | 2004-06-04 14:59:42 +0000 | [diff] [blame] | 143 | if (Targets.size() == 0) |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 144 | throw std::string("ERROR: No 'Target' subclasses defined!"); |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 145 | if (Targets.size() != 1) |
| 146 | throw std::string("ERROR: Multiple subclasses of Target defined!"); |
| 147 | TargetRec = Targets[0]; |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | |
| 151 | const std::string &CodeGenTarget::getName() const { |
| 152 | return TargetRec->getName(); |
| 153 | } |
| 154 | |
Dan Gohman | 1e0ee4b | 2008-08-20 21:45:57 +0000 | [diff] [blame] | 155 | std::string CodeGenTarget::getInstNamespace() const { |
| 156 | std::string InstNS; |
| 157 | |
| 158 | for (inst_iterator i = inst_begin(), e = inst_end(); i != e; ++i) { |
| 159 | InstNS = i->second.Namespace; |
| 160 | |
| 161 | // Make sure not to pick up "TargetInstrInfo" by accidentally getting |
| 162 | // the namespace off the PHI instruction or something. |
| 163 | if (InstNS != "TargetInstrInfo") |
| 164 | break; |
| 165 | } |
| 166 | |
| 167 | return InstNS; |
| 168 | } |
| 169 | |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 170 | Record *CodeGenTarget::getInstructionSet() const { |
| 171 | return TargetRec->getValueAsDef("InstructionSet"); |
| 172 | } |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 173 | |
Chris Lattner | 175580c | 2004-08-14 22:50:53 +0000 | [diff] [blame] | 174 | /// getAsmWriter - Return the AssemblyWriter definition for this target. |
| 175 | /// |
| 176 | Record *CodeGenTarget::getAsmWriter() const { |
Chris Lattner | b0e103d | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 177 | std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyWriters"); |
| 178 | if (AsmWriterNum >= LI.size()) |
Chris Lattner | 560a79f | 2004-10-03 19:34:31 +0000 | [diff] [blame] | 179 | throw "Target does not have an AsmWriter #" + utostr(AsmWriterNum) + "!"; |
Chris Lattner | b0e103d | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 180 | return LI[AsmWriterNum]; |
Chris Lattner | 175580c | 2004-08-14 22:50:53 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Chris Lattner | 2669311 | 2004-08-16 01:10:21 +0000 | [diff] [blame] | 183 | void CodeGenTarget::ReadRegisters() const { |
| 184 | std::vector<Record*> Regs = Records.getAllDerivedDefinitions("Register"); |
| 185 | if (Regs.empty()) |
| 186 | throw std::string("No 'Register' subclasses defined!"); |
| 187 | |
| 188 | Registers.reserve(Regs.size()); |
| 189 | Registers.assign(Regs.begin(), Regs.end()); |
| 190 | } |
| 191 | |
Chris Lattner | 7a680c6 | 2004-08-21 02:24:57 +0000 | [diff] [blame] | 192 | CodeGenRegister::CodeGenRegister(Record *R) : TheDef(R) { |
| 193 | DeclaredSpillSize = R->getValueAsInt("SpillSize"); |
| 194 | DeclaredSpillAlignment = R->getValueAsInt("SpillAlignment"); |
| 195 | } |
| 196 | |
Chris Lattner | 2669311 | 2004-08-16 01:10:21 +0000 | [diff] [blame] | 197 | const std::string &CodeGenRegister::getName() const { |
| 198 | return TheDef->getName(); |
| 199 | } |
| 200 | |
Chris Lattner | 056afef | 2004-08-21 04:05:00 +0000 | [diff] [blame] | 201 | void CodeGenTarget::ReadRegisterClasses() const { |
| 202 | std::vector<Record*> RegClasses = |
| 203 | Records.getAllDerivedDefinitions("RegisterClass"); |
| 204 | if (RegClasses.empty()) |
| 205 | throw std::string("No 'RegisterClass' subclasses defined!"); |
| 206 | |
| 207 | RegisterClasses.reserve(RegClasses.size()); |
| 208 | RegisterClasses.assign(RegClasses.begin(), RegClasses.end()); |
| 209 | } |
| 210 | |
Evan Cheng | 44a65fa | 2006-05-16 07:05:30 +0000 | [diff] [blame] | 211 | std::vector<unsigned char> CodeGenTarget::getRegisterVTs(Record *R) const { |
| 212 | std::vector<unsigned char> Result; |
| 213 | const std::vector<CodeGenRegisterClass> &RCs = getRegisterClasses(); |
| 214 | for (unsigned i = 0, e = RCs.size(); i != e; ++i) { |
| 215 | const CodeGenRegisterClass &RC = RegisterClasses[i]; |
| 216 | for (unsigned ei = 0, ee = RC.Elements.size(); ei != ee; ++ei) { |
| 217 | if (R == RC.Elements[ei]) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 218 | const std::vector<MVT::SimpleValueType> &InVTs = RC.getValueTypes(); |
Evan Cheng | 44a65fa | 2006-05-16 07:05:30 +0000 | [diff] [blame] | 219 | for (unsigned i = 0, e = InVTs.size(); i != e; ++i) |
| 220 | Result.push_back(InVTs[i]); |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | return Result; |
| 225 | } |
| 226 | |
| 227 | |
Chris Lattner | 056afef | 2004-08-21 04:05:00 +0000 | [diff] [blame] | 228 | CodeGenRegisterClass::CodeGenRegisterClass(Record *R) : TheDef(R) { |
Chris Lattner | c67c18f | 2005-08-19 18:45:20 +0000 | [diff] [blame] | 229 | // Rename anonymous register classes. |
| 230 | if (R->getName().size() > 9 && R->getName()[9] == '.') { |
| 231 | static unsigned AnonCounter = 0; |
| 232 | R->setName("AnonRegClass_"+utostr(AnonCounter++)); |
| 233 | } |
| 234 | |
Nate Begeman | 6510b22 | 2005-12-01 04:51:06 +0000 | [diff] [blame] | 235 | std::vector<Record*> TypeList = R->getValueAsListOfDefs("RegTypes"); |
| 236 | for (unsigned i = 0, e = TypeList.size(); i != e; ++i) { |
| 237 | Record *Type = TypeList[i]; |
| 238 | if (!Type->isSubClassOf("ValueType")) |
| 239 | throw "RegTypes list member '" + Type->getName() + |
| 240 | "' does not derive from the ValueType class!"; |
| 241 | VTs.push_back(getValueType(Type)); |
| 242 | } |
| 243 | assert(!VTs.empty() && "RegisterClass must contain at least one ValueType!"); |
Chris Lattner | ac46893 | 2005-08-19 19:12:51 +0000 | [diff] [blame] | 244 | |
Chris Lattner | b0e103d | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 245 | std::vector<Record*> RegList = R->getValueAsListOfDefs("MemberList"); |
| 246 | for (unsigned i = 0, e = RegList.size(); i != e; ++i) { |
| 247 | Record *Reg = RegList[i]; |
Chris Lattner | 056afef | 2004-08-21 04:05:00 +0000 | [diff] [blame] | 248 | if (!Reg->isSubClassOf("Register")) |
| 249 | throw "Register Class member '" + Reg->getName() + |
| 250 | "' does not derive from the Register class!"; |
| 251 | Elements.push_back(Reg); |
| 252 | } |
Nate Begeman | 6510b22 | 2005-12-01 04:51:06 +0000 | [diff] [blame] | 253 | |
Christopher Lamb | a321125 | 2007-06-13 22:20:15 +0000 | [diff] [blame] | 254 | std::vector<Record*> SubRegClassList = |
| 255 | R->getValueAsListOfDefs("SubRegClassList"); |
| 256 | for (unsigned i = 0, e = SubRegClassList.size(); i != e; ++i) { |
| 257 | Record *SubRegClass = SubRegClassList[i]; |
| 258 | if (!SubRegClass->isSubClassOf("RegisterClass")) |
| 259 | throw "Register Class member '" + SubRegClass->getName() + |
| 260 | "' does not derive from the RegisterClass class!"; |
| 261 | SubRegClasses.push_back(SubRegClass); |
| 262 | } |
| 263 | |
Nate Begeman | 6510b22 | 2005-12-01 04:51:06 +0000 | [diff] [blame] | 264 | // Allow targets to override the size in bits of the RegisterClass. |
| 265 | unsigned Size = R->getValueAsInt("Size"); |
| 266 | |
| 267 | Namespace = R->getValueAsString("Namespace"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 268 | SpillSize = Size ? Size : MVT(VTs[0]).getSizeInBits(); |
Nate Begeman | 6510b22 | 2005-12-01 04:51:06 +0000 | [diff] [blame] | 269 | SpillAlignment = R->getValueAsInt("Alignment"); |
Evan Cheng | a3ca314 | 2007-09-19 01:35:01 +0000 | [diff] [blame] | 270 | CopyCost = R->getValueAsInt("CopyCost"); |
Nate Begeman | 6510b22 | 2005-12-01 04:51:06 +0000 | [diff] [blame] | 271 | MethodBodies = R->getValueAsCode("MethodBodies"); |
| 272 | MethodProtos = R->getValueAsCode("MethodProtos"); |
Chris Lattner | 056afef | 2004-08-21 04:05:00 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | const std::string &CodeGenRegisterClass::getName() const { |
| 276 | return TheDef->getName(); |
| 277 | } |
| 278 | |
Chris Lattner | e9f4ba8 | 2005-09-08 21:43:21 +0000 | [diff] [blame] | 279 | void CodeGenTarget::ReadLegalValueTypes() const { |
| 280 | const std::vector<CodeGenRegisterClass> &RCs = getRegisterClasses(); |
| 281 | for (unsigned i = 0, e = RCs.size(); i != e; ++i) |
Nate Begeman | 6510b22 | 2005-12-01 04:51:06 +0000 | [diff] [blame] | 282 | for (unsigned ri = 0, re = RCs[i].VTs.size(); ri != re; ++ri) |
| 283 | LegalValueTypes.push_back(RCs[i].VTs[ri]); |
Chris Lattner | 75ee2eb | 2005-10-14 03:54:49 +0000 | [diff] [blame] | 284 | |
| 285 | // Remove duplicates. |
| 286 | std::sort(LegalValueTypes.begin(), LegalValueTypes.end()); |
| 287 | LegalValueTypes.erase(std::unique(LegalValueTypes.begin(), |
| 288 | LegalValueTypes.end()), |
| 289 | LegalValueTypes.end()); |
Chris Lattner | e9f4ba8 | 2005-09-08 21:43:21 +0000 | [diff] [blame] | 290 | } |
Chris Lattner | 056afef | 2004-08-21 04:05:00 +0000 | [diff] [blame] | 291 | |
Chris Lattner | 175580c | 2004-08-14 22:50:53 +0000 | [diff] [blame] | 292 | |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 293 | void CodeGenTarget::ReadInstructions() const { |
| 294 | std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction"); |
Chris Lattner | aa77d77 | 2006-01-27 01:45:06 +0000 | [diff] [blame] | 295 | if (Insts.size() <= 2) |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 296 | throw std::string("No 'Instruction' subclasses defined!"); |
| 297 | |
Chris Lattner | aa77d77 | 2006-01-27 01:45:06 +0000 | [diff] [blame] | 298 | // Parse the instructions defined in the .td file. |
Chris Lattner | 175580c | 2004-08-14 22:50:53 +0000 | [diff] [blame] | 299 | std::string InstFormatName = |
| 300 | getAsmWriter()->getValueAsString("InstFormatName"); |
| 301 | |
| 302 | for (unsigned i = 0, e = Insts.size(); i != e; ++i) { |
| 303 | std::string AsmStr = Insts[i]->getValueAsString(InstFormatName); |
| 304 | Instructions.insert(std::make_pair(Insts[i]->getName(), |
| 305 | CodeGenInstruction(Insts[i], AsmStr))); |
| 306 | } |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Chris Lattner | d648867 | 2005-01-22 18:58:51 +0000 | [diff] [blame] | 309 | /// getInstructionsByEnumValue - Return all of the instructions defined by the |
| 310 | /// target, ordered by their enum value. |
| 311 | void CodeGenTarget:: |
| 312 | getInstructionsByEnumValue(std::vector<const CodeGenInstruction*> |
| 313 | &NumberedInstructions) { |
Chris Lattner | aa77d77 | 2006-01-27 01:45:06 +0000 | [diff] [blame] | 314 | std::map<std::string, CodeGenInstruction>::const_iterator I; |
| 315 | I = getInstructions().find("PHI"); |
| 316 | if (I == Instructions.end()) throw "Could not find 'PHI' instruction!"; |
| 317 | const CodeGenInstruction *PHI = &I->second; |
| 318 | |
| 319 | I = getInstructions().find("INLINEASM"); |
| 320 | if (I == Instructions.end()) throw "Could not find 'INLINEASM' instruction!"; |
| 321 | const CodeGenInstruction *INLINEASM = &I->second; |
| 322 | |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 323 | I = getInstructions().find("DBG_LABEL"); |
| 324 | if (I == Instructions.end()) throw "Could not find 'DBG_LABEL' instruction!"; |
| 325 | const CodeGenInstruction *DBG_LABEL = &I->second; |
| 326 | |
| 327 | I = getInstructions().find("EH_LABEL"); |
| 328 | if (I == Instructions.end()) throw "Could not find 'EH_LABEL' instruction!"; |
| 329 | const CodeGenInstruction *EH_LABEL = &I->second; |
| 330 | |
| 331 | I = getInstructions().find("GC_LABEL"); |
| 332 | if (I == Instructions.end()) throw "Could not find 'GC_LABEL' instruction!"; |
| 333 | const CodeGenInstruction *GC_LABEL = &I->second; |
Jim Laskey | a683f9b | 2007-01-26 17:29:20 +0000 | [diff] [blame] | 334 | |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 335 | I = getInstructions().find("DECLARE"); |
| 336 | if (I == Instructions.end()) throw "Could not find 'DECLARE' instruction!"; |
| 337 | const CodeGenInstruction *DECLARE = &I->second; |
| 338 | |
Christopher Lamb | 08d5207 | 2007-07-26 07:48:21 +0000 | [diff] [blame] | 339 | I = getInstructions().find("EXTRACT_SUBREG"); |
| 340 | if (I == Instructions.end()) |
| 341 | throw "Could not find 'EXTRACT_SUBREG' instruction!"; |
| 342 | const CodeGenInstruction *EXTRACT_SUBREG = &I->second; |
| 343 | |
| 344 | I = getInstructions().find("INSERT_SUBREG"); |
| 345 | if (I == Instructions.end()) |
| 346 | throw "Could not find 'INSERT_SUBREG' instruction!"; |
| 347 | const CodeGenInstruction *INSERT_SUBREG = &I->second; |
| 348 | |
Evan Cheng | da47e6e | 2008-03-15 00:03:38 +0000 | [diff] [blame] | 349 | I = getInstructions().find("IMPLICIT_DEF"); |
| 350 | if (I == Instructions.end()) |
| 351 | throw "Could not find 'IMPLICIT_DEF' instruction!"; |
| 352 | const CodeGenInstruction *IMPLICIT_DEF = &I->second; |
| 353 | |
Christopher Lamb | c929823 | 2008-03-16 03:12:01 +0000 | [diff] [blame] | 354 | I = getInstructions().find("SUBREG_TO_REG"); |
| 355 | if (I == Instructions.end()) |
| 356 | throw "Could not find 'SUBREG_TO_REG' instruction!"; |
| 357 | const CodeGenInstruction *SUBREG_TO_REG = &I->second; |
Dan Gohman | f8c7394 | 2009-04-13 15:38:05 +0000 | [diff] [blame] | 358 | |
Dan Gohman | 88c7af0 | 2009-04-13 21:06:25 +0000 | [diff] [blame] | 359 | I = getInstructions().find("COPY_TO_REGCLASS"); |
Dan Gohman | f8c7394 | 2009-04-13 15:38:05 +0000 | [diff] [blame] | 360 | if (I == Instructions.end()) |
Dan Gohman | 88c7af0 | 2009-04-13 21:06:25 +0000 | [diff] [blame] | 361 | throw "Could not find 'COPY_TO_REGCLASS' instruction!"; |
| 362 | const CodeGenInstruction *COPY_TO_REGCLASS = &I->second; |
Dan Gohman | f8c7394 | 2009-04-13 15:38:05 +0000 | [diff] [blame] | 363 | |
Chris Lattner | d648867 | 2005-01-22 18:58:51 +0000 | [diff] [blame] | 364 | // Print out the rest of the instructions now. |
Chris Lattner | d648867 | 2005-01-22 18:58:51 +0000 | [diff] [blame] | 365 | NumberedInstructions.push_back(PHI); |
Chris Lattner | aa77d77 | 2006-01-27 01:45:06 +0000 | [diff] [blame] | 366 | NumberedInstructions.push_back(INLINEASM); |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 367 | NumberedInstructions.push_back(DBG_LABEL); |
| 368 | NumberedInstructions.push_back(EH_LABEL); |
| 369 | NumberedInstructions.push_back(GC_LABEL); |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 370 | NumberedInstructions.push_back(DECLARE); |
Christopher Lamb | 08d5207 | 2007-07-26 07:48:21 +0000 | [diff] [blame] | 371 | NumberedInstructions.push_back(EXTRACT_SUBREG); |
| 372 | NumberedInstructions.push_back(INSERT_SUBREG); |
Evan Cheng | da47e6e | 2008-03-15 00:03:38 +0000 | [diff] [blame] | 373 | NumberedInstructions.push_back(IMPLICIT_DEF); |
Christopher Lamb | c929823 | 2008-03-16 03:12:01 +0000 | [diff] [blame] | 374 | NumberedInstructions.push_back(SUBREG_TO_REG); |
Dan Gohman | 88c7af0 | 2009-04-13 21:06:25 +0000 | [diff] [blame] | 375 | NumberedInstructions.push_back(COPY_TO_REGCLASS); |
Chris Lattner | d648867 | 2005-01-22 18:58:51 +0000 | [diff] [blame] | 376 | for (inst_iterator II = inst_begin(), E = inst_end(); II != E; ++II) |
Jim Laskey | a683f9b | 2007-01-26 17:29:20 +0000 | [diff] [blame] | 377 | if (&II->second != PHI && |
| 378 | &II->second != INLINEASM && |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 379 | &II->second != DBG_LABEL && |
| 380 | &II->second != EH_LABEL && |
| 381 | &II->second != GC_LABEL && |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 382 | &II->second != DECLARE && |
Christopher Lamb | 08d5207 | 2007-07-26 07:48:21 +0000 | [diff] [blame] | 383 | &II->second != EXTRACT_SUBREG && |
Evan Cheng | da47e6e | 2008-03-15 00:03:38 +0000 | [diff] [blame] | 384 | &II->second != INSERT_SUBREG && |
Christopher Lamb | c929823 | 2008-03-16 03:12:01 +0000 | [diff] [blame] | 385 | &II->second != IMPLICIT_DEF && |
Dan Gohman | f8c7394 | 2009-04-13 15:38:05 +0000 | [diff] [blame] | 386 | &II->second != SUBREG_TO_REG && |
Dan Gohman | 88c7af0 | 2009-04-13 21:06:25 +0000 | [diff] [blame] | 387 | &II->second != COPY_TO_REGCLASS) |
Chris Lattner | d648867 | 2005-01-22 18:58:51 +0000 | [diff] [blame] | 388 | NumberedInstructions.push_back(&II->second); |
| 389 | } |
| 390 | |
| 391 | |
Misha Brukman | 35e83cc | 2004-10-14 05:50:43 +0000 | [diff] [blame] | 392 | /// isLittleEndianEncoding - Return whether this target encodes its instruction |
| 393 | /// in little-endian format, i.e. bits laid out in the order [0..n] |
| 394 | /// |
| 395 | bool CodeGenTarget::isLittleEndianEncoding() const { |
| 396 | return getInstructionSet()->getValueAsBit("isLittleEndianEncoding"); |
| 397 | } |
| 398 | |
Evan Cheng | 0fc7198 | 2005-12-08 02:00:36 +0000 | [diff] [blame] | 399 | //===----------------------------------------------------------------------===// |
| 400 | // ComplexPattern implementation |
| 401 | // |
| 402 | ComplexPattern::ComplexPattern(Record *R) { |
Evan Cheng | 3aa39f4 | 2005-12-08 02:14:08 +0000 | [diff] [blame] | 403 | Ty = ::getValueType(R->getValueAsDef("Ty")); |
| 404 | NumOperands = R->getValueAsInt("NumOperands"); |
| 405 | SelectFunc = R->getValueAsString("SelectFunc"); |
| 406 | RootNodes = R->getValueAsListOfDefs("RootNodes"); |
Evan Cheng | 94b3040 | 2006-10-11 21:02:01 +0000 | [diff] [blame] | 407 | |
| 408 | // Parse the properties. |
| 409 | Properties = 0; |
| 410 | std::vector<Record*> PropList = R->getValueAsListOfDefs("Properties"); |
| 411 | for (unsigned i = 0, e = PropList.size(); i != e; ++i) |
| 412 | if (PropList[i]->getName() == "SDNPHasChain") { |
| 413 | Properties |= 1 << SDNPHasChain; |
| 414 | } else if (PropList[i]->getName() == "SDNPOptInFlag") { |
| 415 | Properties |= 1 << SDNPOptInFlag; |
Chris Lattner | ba7e756 | 2008-01-10 07:59:24 +0000 | [diff] [blame] | 416 | } else if (PropList[i]->getName() == "SDNPMayStore") { |
| 417 | Properties |= 1 << SDNPMayStore; |
| 418 | } else if (PropList[i]->getName() == "SDNPMayLoad") { |
| 419 | Properties |= 1 << SDNPMayLoad; |
| 420 | } else if (PropList[i]->getName() == "SDNPSideEffect") { |
| 421 | Properties |= 1 << SDNPSideEffect; |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 422 | } else if (PropList[i]->getName() == "SDNPMemOperand") { |
| 423 | Properties |= 1 << SDNPMemOperand; |
Evan Cheng | 94b3040 | 2006-10-11 21:02:01 +0000 | [diff] [blame] | 424 | } else { |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 425 | errs() << "Unsupported SD Node property '" << PropList[i]->getName() |
| 426 | << "' on ComplexPattern '" << R->getName() << "'!\n"; |
Evan Cheng | 94b3040 | 2006-10-11 21:02:01 +0000 | [diff] [blame] | 427 | exit(1); |
| 428 | } |
Christopher Lamb | 8535624 | 2008-01-31 07:27:46 +0000 | [diff] [blame] | 429 | |
| 430 | // Parse the attributes. |
| 431 | Attributes = 0; |
| 432 | PropList = R->getValueAsListOfDefs("Attributes"); |
| 433 | for (unsigned i = 0, e = PropList.size(); i != e; ++i) |
| 434 | if (PropList[i]->getName() == "CPAttrParentAsRoot") { |
| 435 | Attributes |= 1 << CPAttrParentAsRoot; |
| 436 | } else { |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 437 | errs() << "Unsupported pattern attribute '" << PropList[i]->getName() |
| 438 | << "' on ComplexPattern '" << R->getName() << "'!\n"; |
Christopher Lamb | 8535624 | 2008-01-31 07:27:46 +0000 | [diff] [blame] | 439 | exit(1); |
| 440 | } |
Evan Cheng | 0fc7198 | 2005-12-08 02:00:36 +0000 | [diff] [blame] | 441 | } |
Evan Cheng | 3aa39f4 | 2005-12-08 02:14:08 +0000 | [diff] [blame] | 442 | |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 443 | //===----------------------------------------------------------------------===// |
| 444 | // CodeGenIntrinsic Implementation |
| 445 | //===----------------------------------------------------------------------===// |
| 446 | |
Dale Johannesen | 49de982 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 447 | std::vector<CodeGenIntrinsic> llvm::LoadIntrinsics(const RecordKeeper &RC, |
| 448 | bool TargetOnly) { |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 449 | std::vector<Record*> I = RC.getAllDerivedDefinitions("Intrinsic"); |
Chris Lattner | 8850a1b | 2006-03-27 22:48:18 +0000 | [diff] [blame] | 450 | |
| 451 | std::vector<CodeGenIntrinsic> Result; |
Chris Lattner | 6a160fb | 2006-03-28 00:15:00 +0000 | [diff] [blame] | 452 | |
Dale Johannesen | 49de982 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 453 | for (unsigned i = 0, e = I.size(); i != e; ++i) { |
| 454 | bool isTarget = I[i]->getValueAsBit("isTarget"); |
| 455 | if (isTarget == TargetOnly) |
| 456 | Result.push_back(CodeGenIntrinsic(I[i])); |
| 457 | } |
Chris Lattner | 8850a1b | 2006-03-27 22:48:18 +0000 | [diff] [blame] | 458 | return Result; |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Dan Gohman | ee4fa19 | 2008-04-03 00:02:49 +0000 | [diff] [blame] | 461 | CodeGenIntrinsic::CodeGenIntrinsic(Record *R) { |
Chris Lattner | 2ca956f | 2006-03-24 20:25:01 +0000 | [diff] [blame] | 462 | TheDef = R; |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 463 | std::string DefName = R->getName(); |
| 464 | ModRef = WriteMem; |
Reid Spencer | c4de3de | 2007-04-01 07:20:02 +0000 | [diff] [blame] | 465 | isOverloaded = false; |
Evan Cheng | 6bd9567 | 2008-06-16 20:29:38 +0000 | [diff] [blame] | 466 | isCommutative = false; |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 467 | |
| 468 | if (DefName.size() <= 4 || |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 469 | std::string(DefName.begin(), DefName.begin() + 4) != "int_") |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 470 | throw "Intrinsic '" + DefName + "' does not start with 'int_'!"; |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 471 | |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 472 | EnumName = std::string(DefName.begin()+4, DefName.end()); |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 473 | |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 474 | if (R->getValue("GCCBuiltinName")) // Ignore a missing GCCBuiltinName field. |
| 475 | GCCBuiltinName = R->getValueAsString("GCCBuiltinName"); |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 476 | |
| 477 | TargetPrefix = R->getValueAsString("TargetPrefix"); |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 478 | Name = R->getValueAsString("LLVMName"); |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 479 | |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 480 | if (Name == "") { |
| 481 | // If an explicit name isn't specified, derive one from the DefName. |
| 482 | Name = "llvm."; |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 483 | |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 484 | for (unsigned i = 0, e = EnumName.size(); i != e; ++i) |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 485 | Name += (EnumName[i] == '_') ? '.' : EnumName[i]; |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 486 | } else { |
| 487 | // Verify it starts with "llvm.". |
| 488 | if (Name.size() <= 5 || |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 489 | std::string(Name.begin(), Name.begin() + 5) != "llvm.") |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 490 | throw "Intrinsic '" + DefName + "'s name does not start with 'llvm.'!"; |
| 491 | } |
| 492 | |
| 493 | // If TargetPrefix is specified, make sure that Name starts with |
| 494 | // "llvm.<targetprefix>.". |
| 495 | if (!TargetPrefix.empty()) { |
| 496 | if (Name.size() < 6+TargetPrefix.size() || |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 497 | std::string(Name.begin() + 5, Name.begin() + 6 + TargetPrefix.size()) |
| 498 | != (TargetPrefix + ".")) |
| 499 | throw "Intrinsic '" + DefName + "' does not start with 'llvm." + |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 500 | TargetPrefix + ".'!"; |
| 501 | } |
| 502 | |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 503 | // Parse the list of return types. |
Bob Wilson | d305e70 | 2009-04-16 21:51:05 +0000 | [diff] [blame] | 504 | std::vector<MVT::SimpleValueType> OverloadedVTs; |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 505 | ListInit *TypeList = R->getValueAsListInit("RetTypes"); |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 506 | for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) { |
Chris Lattner | 50d4565 | 2007-02-27 22:08:27 +0000 | [diff] [blame] | 507 | Record *TyEl = TypeList->getElementAsRecord(i); |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 508 | assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!"); |
Bob Wilson | bc03979 | 2009-01-07 00:09:01 +0000 | [diff] [blame] | 509 | MVT::SimpleValueType VT; |
| 510 | if (TyEl->isSubClassOf("LLVMMatchType")) { |
Bob Wilson | d305e70 | 2009-04-16 21:51:05 +0000 | [diff] [blame] | 511 | unsigned MatchTy = TyEl->getValueAsInt("Number"); |
| 512 | assert(MatchTy < OverloadedVTs.size() && |
| 513 | "Invalid matching number!"); |
| 514 | VT = OverloadedVTs[MatchTy]; |
Bob Wilson | bc03979 | 2009-01-07 00:09:01 +0000 | [diff] [blame] | 515 | // It only makes sense to use the extended and truncated vector element |
| 516 | // variants with iAny types; otherwise, if the intrinsic is not |
| 517 | // overloaded, all the types can be specified directly. |
| 518 | assert(((!TyEl->isSubClassOf("LLVMExtendedElementVectorType") && |
| 519 | !TyEl->isSubClassOf("LLVMTruncatedElementVectorType")) || |
| 520 | VT == MVT::iAny) && "Expected iAny type"); |
Bob Wilson | d305e70 | 2009-04-16 21:51:05 +0000 | [diff] [blame] | 521 | } else { |
Bob Wilson | bc03979 | 2009-01-07 00:09:01 +0000 | [diff] [blame] | 522 | VT = getValueType(TyEl->getValueAsDef("VT")); |
Bob Wilson | d305e70 | 2009-04-16 21:51:05 +0000 | [diff] [blame] | 523 | } |
| 524 | if (VT == MVT::iAny || VT == MVT::fAny || VT == MVT::iPTRAny) { |
| 525 | OverloadedVTs.push_back(VT); |
| 526 | isOverloaded |= true; |
| 527 | } |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 528 | IS.RetVTs.push_back(VT); |
| 529 | IS.RetTypeDefs.push_back(TyEl); |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 530 | } |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 531 | |
| 532 | if (IS.RetVTs.size() == 0) |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 533 | throw "Intrinsic '"+DefName+"' needs at least a type for the ret value!"; |
Reid Spencer | c4de3de | 2007-04-01 07:20:02 +0000 | [diff] [blame] | 534 | |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 535 | // Parse the list of parameter types. |
| 536 | TypeList = R->getValueAsListInit("ParamTypes"); |
| 537 | for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) { |
| 538 | Record *TyEl = TypeList->getElementAsRecord(i); |
| 539 | assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!"); |
Bob Wilson | bc03979 | 2009-01-07 00:09:01 +0000 | [diff] [blame] | 540 | MVT::SimpleValueType VT; |
| 541 | if (TyEl->isSubClassOf("LLVMMatchType")) { |
| 542 | unsigned MatchTy = TyEl->getValueAsInt("Number"); |
Bob Wilson | d305e70 | 2009-04-16 21:51:05 +0000 | [diff] [blame] | 543 | assert(MatchTy < OverloadedVTs.size() && |
| 544 | "Invalid matching number!"); |
| 545 | VT = OverloadedVTs[MatchTy]; |
Bob Wilson | bc03979 | 2009-01-07 00:09:01 +0000 | [diff] [blame] | 546 | // It only makes sense to use the extended and truncated vector element |
| 547 | // variants with iAny types; otherwise, if the intrinsic is not |
| 548 | // overloaded, all the types can be specified directly. |
| 549 | assert(((!TyEl->isSubClassOf("LLVMExtendedElementVectorType") && |
| 550 | !TyEl->isSubClassOf("LLVMTruncatedElementVectorType")) || |
| 551 | VT == MVT::iAny) && "Expected iAny type"); |
| 552 | } else |
| 553 | VT = getValueType(TyEl->getValueAsDef("VT")); |
Bob Wilson | d305e70 | 2009-04-16 21:51:05 +0000 | [diff] [blame] | 554 | if (VT == MVT::iAny || VT == MVT::fAny || VT == MVT::iPTRAny) { |
| 555 | OverloadedVTs.push_back(VT); |
| 556 | isOverloaded |= true; |
| 557 | } |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 558 | IS.ParamVTs.push_back(VT); |
| 559 | IS.ParamTypeDefs.push_back(TyEl); |
| 560 | } |
| 561 | |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 562 | // Parse the intrinsic properties. |
| 563 | ListInit *PropList = R->getValueAsListInit("Properties"); |
| 564 | for (unsigned i = 0, e = PropList->getSize(); i != e; ++i) { |
Chris Lattner | 50d4565 | 2007-02-27 22:08:27 +0000 | [diff] [blame] | 565 | Record *Property = PropList->getElementAsRecord(i); |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 566 | assert(Property->isSubClassOf("IntrinsicProperty") && |
| 567 | "Expected a property!"); |
| 568 | |
Chris Lattner | 4b2362e | 2006-04-10 22:02:59 +0000 | [diff] [blame] | 569 | if (Property->getName() == "IntrNoMem") |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 570 | ModRef = NoMem; |
Chris Lattner | 4b2362e | 2006-04-10 22:02:59 +0000 | [diff] [blame] | 571 | else if (Property->getName() == "IntrReadArgMem") |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 572 | ModRef = ReadArgMem; |
| 573 | else if (Property->getName() == "IntrReadMem") |
| 574 | ModRef = ReadMem; |
Chris Lattner | 4b2362e | 2006-04-10 22:02:59 +0000 | [diff] [blame] | 575 | else if (Property->getName() == "IntrWriteArgMem") |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 576 | ModRef = WriteArgMem; |
| 577 | else if (Property->getName() == "IntrWriteMem") |
| 578 | ModRef = WriteMem; |
Evan Cheng | 6bd9567 | 2008-06-16 20:29:38 +0000 | [diff] [blame] | 579 | else if (Property->getName() == "Commutative") |
| 580 | isCommutative = true; |
Chris Lattner | a62c302 | 2009-01-12 01:12:03 +0000 | [diff] [blame] | 581 | else if (Property->isSubClassOf("NoCapture")) { |
| 582 | unsigned ArgNo = Property->getValueAsInt("ArgNo"); |
| 583 | ArgumentAttributes.push_back(std::make_pair(ArgNo, NoCapture)); |
| 584 | } else |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 585 | assert(0 && "Unknown property!"); |
| 586 | } |
| 587 | } |