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