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