Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 1 | //===- CodeGenInstruction.cpp - CodeGen Instruction Class Wrapper ---------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the CodeGenInstruction class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "CodeGenInstruction.h" |
Chris Lattner | 9414ae5 | 2010-03-27 20:09:24 +0000 | [diff] [blame] | 15 | #include "CodeGenTarget.h" |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 16 | #include "Record.h" |
| 17 | #include "llvm/ADT/StringExtras.h" |
Benjamin Kramer | d4f1959 | 2010-01-11 18:03:24 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 19 | #include <set> |
| 20 | using namespace llvm; |
| 21 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 22 | //===----------------------------------------------------------------------===// |
| 23 | // CGIOperandList Implementation |
| 24 | //===----------------------------------------------------------------------===// |
Jim Grosbach | 0680172 | 2009-12-16 19:43:02 +0000 | [diff] [blame] | 25 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 26 | CGIOperandList::CGIOperandList(Record *R) : TheDef(R) { |
| 27 | isPredicable = false; |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 28 | hasOptionalDef = false; |
Chris Lattner | 8f707e1 | 2008-01-07 05:19:29 +0000 | [diff] [blame] | 29 | isVariadic = false; |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 30 | |
Chris Lattner | f55eed2 | 2010-03-18 21:07:39 +0000 | [diff] [blame] | 31 | DagInit *OutDI = R->getValueAsDag("OutOperandList"); |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 32 | |
Chris Lattner | f55eed2 | 2010-03-18 21:07:39 +0000 | [diff] [blame] | 33 | if (DefInit *Init = dynamic_cast<DefInit*>(OutDI->getOperator())) { |
Chris Lattner | b0be4d2 | 2010-03-18 20:56:35 +0000 | [diff] [blame] | 34 | if (Init->getDef()->getName() != "outs") |
Chris Lattner | cedef1c | 2010-03-18 20:50:52 +0000 | [diff] [blame] | 35 | throw R->getName() + ": invalid def name for output list: use 'outs'"; |
| 36 | } else |
| 37 | throw R->getName() + ": invalid output list: use 'outs'"; |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 38 | |
Chris Lattner | f55eed2 | 2010-03-18 21:07:39 +0000 | [diff] [blame] | 39 | NumDefs = OutDI->getNumArgs(); |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 40 | |
Chris Lattner | f55eed2 | 2010-03-18 21:07:39 +0000 | [diff] [blame] | 41 | DagInit *InDI = R->getValueAsDag("InOperandList"); |
| 42 | if (DefInit *Init = dynamic_cast<DefInit*>(InDI->getOperator())) { |
Chris Lattner | b0be4d2 | 2010-03-18 20:56:35 +0000 | [diff] [blame] | 43 | if (Init->getDef()->getName() != "ins") |
Chris Lattner | cedef1c | 2010-03-18 20:50:52 +0000 | [diff] [blame] | 44 | throw R->getName() + ": invalid def name for input list: use 'ins'"; |
| 45 | } else |
| 46 | throw R->getName() + ": invalid input list: use 'ins'"; |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 47 | |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 48 | unsigned MIOperandNo = 0; |
| 49 | std::set<std::string> OperandNames; |
Chris Lattner | f55eed2 | 2010-03-18 21:07:39 +0000 | [diff] [blame] | 50 | for (unsigned i = 0, e = InDI->getNumArgs()+OutDI->getNumArgs(); i != e; ++i){ |
| 51 | Init *ArgInit; |
| 52 | std::string ArgName; |
| 53 | if (i < NumDefs) { |
| 54 | ArgInit = OutDI->getArg(i); |
| 55 | ArgName = OutDI->getArgName(i); |
| 56 | } else { |
| 57 | ArgInit = InDI->getArg(i-NumDefs); |
| 58 | ArgName = InDI->getArgName(i-NumDefs); |
| 59 | } |
| 60 | |
| 61 | DefInit *Arg = dynamic_cast<DefInit*>(ArgInit); |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 62 | if (!Arg) |
| 63 | throw "Illegal operand for the '" + R->getName() + "' instruction!"; |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 64 | |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 65 | Record *Rec = Arg->getDef(); |
| 66 | std::string PrintMethod = "printOperand"; |
Jim Grosbach | 5013f74 | 2010-10-12 22:21:57 +0000 | [diff] [blame] | 67 | std::string EncoderMethod; |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 68 | unsigned NumOps = 1; |
| 69 | DagInit *MIOpInfo = 0; |
| 70 | if (Rec->isSubClassOf("Operand")) { |
| 71 | PrintMethod = Rec->getValueAsString("PrintMethod"); |
Jim Grosbach | 5013f74 | 2010-10-12 22:21:57 +0000 | [diff] [blame] | 72 | // If there is an explicit encoder method, use it. |
| 73 | if (Rec->getValue("EncoderMethod")) |
| 74 | EncoderMethod = Rec->getValueAsString("EncoderMethod"); |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 75 | MIOpInfo = Rec->getValueAsDag("MIOperandInfo"); |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 76 | |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 77 | // Verify that MIOpInfo has an 'ops' root value. |
| 78 | if (!dynamic_cast<DefInit*>(MIOpInfo->getOperator()) || |
| 79 | dynamic_cast<DefInit*>(MIOpInfo->getOperator()) |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 80 | ->getDef()->getName() != "ops") |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 81 | throw "Bad value for MIOperandInfo in operand '" + Rec->getName() + |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 82 | "'\n"; |
| 83 | |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 84 | // If we have MIOpInfo, then we have #operands equal to number of entries |
| 85 | // in MIOperandInfo. |
| 86 | if (unsigned NumArgs = MIOpInfo->getNumArgs()) |
| 87 | NumOps = NumArgs; |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 88 | |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 89 | if (Rec->isSubClassOf("PredicateOperand")) |
| 90 | isPredicable = true; |
| 91 | else if (Rec->isSubClassOf("OptionalDefOperand")) |
| 92 | hasOptionalDef = true; |
| 93 | } else if (Rec->getName() == "variable_ops") { |
Chris Lattner | 8f707e1 | 2008-01-07 05:19:29 +0000 | [diff] [blame] | 94 | isVariadic = true; |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 95 | continue; |
Jim Grosbach | f0a4fad | 2009-12-15 19:28:13 +0000 | [diff] [blame] | 96 | } else if (!Rec->isSubClassOf("RegisterClass") && |
Dan Gohman | e4c67cd | 2008-05-31 02:11:25 +0000 | [diff] [blame] | 97 | Rec->getName() != "ptr_rc" && Rec->getName() != "unknown") |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 98 | throw "Unknown operand class '" + Rec->getName() + |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 99 | "' in '" + R->getName() + "' instruction!"; |
| 100 | |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 101 | // Check that the operand has a name and that it's unique. |
Chris Lattner | f55eed2 | 2010-03-18 21:07:39 +0000 | [diff] [blame] | 102 | if (ArgName.empty()) |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 103 | throw "In instruction '" + R->getName() + "', operand #" + utostr(i) + |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 104 | " has no name!"; |
Chris Lattner | f55eed2 | 2010-03-18 21:07:39 +0000 | [diff] [blame] | 105 | if (!OperandNames.insert(ArgName).second) |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 106 | throw "In instruction '" + R->getName() + "', operand #" + utostr(i) + |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 107 | " has the same name as a previous operand!"; |
| 108 | |
Jim Grosbach | 5013f74 | 2010-10-12 22:21:57 +0000 | [diff] [blame] | 109 | OperandList.push_back(OperandInfo(Rec, ArgName, PrintMethod, EncoderMethod, |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 110 | MIOperandNo, NumOps, MIOpInfo)); |
| 111 | MIOperandNo += NumOps; |
| 112 | } |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 115 | |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 116 | /// getOperandNamed - Return the index of the operand with the specified |
| 117 | /// non-empty name. If the instruction does not have an operand with the |
| 118 | /// specified name, throw an exception. |
| 119 | /// |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 120 | unsigned CGIOperandList::getOperandNamed(StringRef Name) const { |
Jim Grosbach | 0185507 | 2010-10-11 18:25:51 +0000 | [diff] [blame] | 121 | unsigned OpIdx; |
| 122 | if (hasOperandNamed(Name, OpIdx)) return OpIdx; |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 123 | throw "'" + TheDef->getName() + "' does not have an operand named '$" + |
| 124 | Name.str() + "'!"; |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Jim Grosbach | 0185507 | 2010-10-11 18:25:51 +0000 | [diff] [blame] | 127 | /// hasOperandNamed - Query whether the instruction has an operand of the |
| 128 | /// given name. If so, return true and set OpIdx to the index of the |
| 129 | /// operand. Otherwise, return false. |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 130 | bool CGIOperandList::hasOperandNamed(StringRef Name, unsigned &OpIdx) const { |
Jim Grosbach | 0185507 | 2010-10-11 18:25:51 +0000 | [diff] [blame] | 131 | assert(!Name.empty() && "Cannot search for operand with no name!"); |
| 132 | for (unsigned i = 0, e = OperandList.size(); i != e; ++i) |
| 133 | if (OperandList[i].Name == Name) { |
| 134 | OpIdx = i; |
| 135 | return true; |
| 136 | } |
| 137 | return false; |
| 138 | } |
| 139 | |
Jim Grosbach | f0a4fad | 2009-12-15 19:28:13 +0000 | [diff] [blame] | 140 | std::pair<unsigned,unsigned> |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 141 | CGIOperandList::ParseOperandName(const std::string &Op, bool AllowWholeOp) { |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 142 | if (Op.empty() || Op[0] != '$') |
| 143 | throw TheDef->getName() + ": Illegal operand name: '" + Op + "'"; |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 144 | |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 145 | std::string OpName = Op.substr(1); |
| 146 | std::string SubOpName; |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 147 | |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 148 | // Check to see if this is $foo.bar. |
| 149 | std::string::size_type DotIdx = OpName.find_first_of("."); |
| 150 | if (DotIdx != std::string::npos) { |
| 151 | SubOpName = OpName.substr(DotIdx+1); |
| 152 | if (SubOpName.empty()) |
| 153 | throw TheDef->getName() + ": illegal empty suboperand name in '" +Op +"'"; |
| 154 | OpName = OpName.substr(0, DotIdx); |
| 155 | } |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 156 | |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 157 | unsigned OpIdx = getOperandNamed(OpName); |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 158 | |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 159 | if (SubOpName.empty()) { // If no suboperand name was specified: |
| 160 | // If one was needed, throw. |
| 161 | if (OperandList[OpIdx].MINumOperands > 1 && !AllowWholeOp && |
| 162 | SubOpName.empty()) |
| 163 | throw TheDef->getName() + ": Illegal to refer to" |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 164 | " whole operand part of complex operand '" + Op + "'"; |
| 165 | |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 166 | // Otherwise, return the operand. |
| 167 | return std::make_pair(OpIdx, 0U); |
| 168 | } |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 169 | |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 170 | // Find the suboperand number involved. |
| 171 | DagInit *MIOpInfo = OperandList[OpIdx].MIOperandInfo; |
| 172 | if (MIOpInfo == 0) |
| 173 | throw TheDef->getName() + ": unknown suboperand name in '" + Op + "'"; |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 174 | |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 175 | // Find the operand with the right name. |
| 176 | for (unsigned i = 0, e = MIOpInfo->getNumArgs(); i != e; ++i) |
| 177 | if (MIOpInfo->getArgName(i) == SubOpName) |
| 178 | return std::make_pair(OpIdx, i); |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 179 | |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 180 | // Otherwise, didn't find it! |
| 181 | throw TheDef->getName() + ": unknown suboperand name in '" + Op + "'"; |
| 182 | } |
Chris Lattner | 9414ae5 | 2010-03-27 20:09:24 +0000 | [diff] [blame] | 183 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame^] | 184 | static void ParseConstraint(const std::string &CStr, CGIOperandList &Ops) { |
| 185 | // EARLY_CLOBBER: @early $reg |
| 186 | std::string::size_type wpos = CStr.find_first_of(" \t"); |
| 187 | std::string::size_type start = CStr.find_first_not_of(" \t"); |
| 188 | std::string Tok = CStr.substr(start, wpos - start); |
| 189 | if (Tok == "@earlyclobber") { |
| 190 | std::string Name = CStr.substr(wpos+1); |
| 191 | wpos = Name.find_first_not_of(" \t"); |
| 192 | if (wpos == std::string::npos) |
| 193 | throw "Illegal format for @earlyclobber constraint: '" + CStr + "'"; |
| 194 | Name = Name.substr(wpos); |
| 195 | std::pair<unsigned,unsigned> Op = Ops.ParseOperandName(Name, false); |
| 196 | |
| 197 | // Build the string for the operand |
| 198 | if (!Ops[Op.first].Constraints[Op.second].isNone()) |
| 199 | throw "Operand '" + Name + "' cannot have multiple constraints!"; |
| 200 | Ops[Op.first].Constraints[Op.second] = |
| 201 | CGIOperandList::ConstraintInfo::getEarlyClobber(); |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | // Only other constraint is "TIED_TO" for now. |
| 206 | std::string::size_type pos = CStr.find_first_of('='); |
| 207 | assert(pos != std::string::npos && "Unrecognized constraint"); |
| 208 | start = CStr.find_first_not_of(" \t"); |
| 209 | std::string Name = CStr.substr(start, pos - start); |
| 210 | |
| 211 | // TIED_TO: $src1 = $dst |
| 212 | wpos = Name.find_first_of(" \t"); |
| 213 | if (wpos == std::string::npos) |
| 214 | throw "Illegal format for tied-to constraint: '" + CStr + "'"; |
| 215 | std::string DestOpName = Name.substr(0, wpos); |
| 216 | std::pair<unsigned,unsigned> DestOp = Ops.ParseOperandName(DestOpName, false); |
| 217 | |
| 218 | Name = CStr.substr(pos+1); |
| 219 | wpos = Name.find_first_not_of(" \t"); |
| 220 | if (wpos == std::string::npos) |
| 221 | throw "Illegal format for tied-to constraint: '" + CStr + "'"; |
| 222 | |
| 223 | std::pair<unsigned,unsigned> SrcOp = |
| 224 | Ops.ParseOperandName(Name.substr(wpos), false); |
| 225 | if (SrcOp > DestOp) |
| 226 | throw "Illegal tied-to operand constraint '" + CStr + "'"; |
| 227 | |
| 228 | |
| 229 | unsigned FlatOpNo = Ops.getFlattenedOperandNumber(SrcOp); |
| 230 | |
| 231 | if (!Ops[DestOp.first].Constraints[DestOp.second].isNone()) |
| 232 | throw "Operand '" + DestOpName + "' cannot have multiple constraints!"; |
| 233 | Ops[DestOp.first].Constraints[DestOp.second] = |
| 234 | CGIOperandList::ConstraintInfo::getTied(FlatOpNo); |
| 235 | } |
| 236 | |
| 237 | static void ParseConstraints(const std::string &CStr, CGIOperandList &Ops) { |
| 238 | // Make sure the constraints list for each operand is large enough to hold |
| 239 | // constraint info, even if none is present. |
| 240 | for (unsigned i = 0, e = Ops.size(); i != e; ++i) |
| 241 | Ops[i].Constraints.resize(Ops[i].MINumOperands); |
| 242 | |
| 243 | if (CStr.empty()) return; |
| 244 | |
| 245 | const std::string delims(","); |
| 246 | std::string::size_type bidx, eidx; |
| 247 | |
| 248 | bidx = CStr.find_first_not_of(delims); |
| 249 | while (bidx != std::string::npos) { |
| 250 | eidx = CStr.find_first_of(delims, bidx); |
| 251 | if (eidx == std::string::npos) |
| 252 | eidx = CStr.length(); |
| 253 | |
| 254 | ParseConstraint(CStr.substr(bidx, eidx - bidx), Ops); |
| 255 | bidx = CStr.find_first_not_of(delims, eidx); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | void CGIOperandList::ProcessDisableEncoding(std::string DisableEncoding) { |
| 260 | while (1) { |
| 261 | std::string OpName; |
| 262 | tie(OpName, DisableEncoding) = getToken(DisableEncoding, " ,\t"); |
| 263 | if (OpName.empty()) break; |
| 264 | |
| 265 | // Figure out which operand this is. |
| 266 | std::pair<unsigned,unsigned> Op = ParseOperandName(OpName, false); |
| 267 | |
| 268 | // Mark the operand as not-to-be encoded. |
| 269 | if (Op.second >= OperandList[Op.first].DoNotEncode.size()) |
| 270 | OperandList[Op.first].DoNotEncode.resize(Op.second+1); |
| 271 | OperandList[Op.first].DoNotEncode[Op.second] = true; |
| 272 | } |
| 273 | |
| 274 | } |
| 275 | |
| 276 | //===----------------------------------------------------------------------===// |
| 277 | // CodeGenInstruction Implementation |
| 278 | //===----------------------------------------------------------------------===// |
| 279 | |
| 280 | CodeGenInstruction::CodeGenInstruction(Record *R) : TheDef(R), Operands(R) { |
| 281 | Namespace = R->getValueAsString("Namespace"); |
| 282 | AsmString = R->getValueAsString("AsmString"); |
| 283 | |
| 284 | isReturn = R->getValueAsBit("isReturn"); |
| 285 | isBranch = R->getValueAsBit("isBranch"); |
| 286 | isIndirectBranch = R->getValueAsBit("isIndirectBranch"); |
| 287 | isCompare = R->getValueAsBit("isCompare"); |
| 288 | isBarrier = R->getValueAsBit("isBarrier"); |
| 289 | isCall = R->getValueAsBit("isCall"); |
| 290 | canFoldAsLoad = R->getValueAsBit("canFoldAsLoad"); |
| 291 | mayLoad = R->getValueAsBit("mayLoad"); |
| 292 | mayStore = R->getValueAsBit("mayStore"); |
| 293 | isPredicable = Operands.isPredicable || R->getValueAsBit("isPredicable"); |
| 294 | isConvertibleToThreeAddress = R->getValueAsBit("isConvertibleToThreeAddress"); |
| 295 | isCommutable = R->getValueAsBit("isCommutable"); |
| 296 | isTerminator = R->getValueAsBit("isTerminator"); |
| 297 | isReMaterializable = R->getValueAsBit("isReMaterializable"); |
| 298 | hasDelaySlot = R->getValueAsBit("hasDelaySlot"); |
| 299 | usesCustomInserter = R->getValueAsBit("usesCustomInserter"); |
| 300 | hasCtrlDep = R->getValueAsBit("hasCtrlDep"); |
| 301 | isNotDuplicable = R->getValueAsBit("isNotDuplicable"); |
| 302 | hasSideEffects = R->getValueAsBit("hasSideEffects"); |
| 303 | neverHasSideEffects = R->getValueAsBit("neverHasSideEffects"); |
| 304 | isAsCheapAsAMove = R->getValueAsBit("isAsCheapAsAMove"); |
| 305 | hasExtraSrcRegAllocReq = R->getValueAsBit("hasExtraSrcRegAllocReq"); |
| 306 | hasExtraDefRegAllocReq = R->getValueAsBit("hasExtraDefRegAllocReq"); |
| 307 | ImplicitDefs = R->getValueAsListOfDefs("Defs"); |
| 308 | ImplicitUses = R->getValueAsListOfDefs("Uses"); |
| 309 | |
| 310 | if (neverHasSideEffects + hasSideEffects > 1) |
| 311 | throw R->getName() + ": multiple conflicting side-effect flags set!"; |
| 312 | |
| 313 | // Parse Constraints. |
| 314 | ParseConstraints(R->getValueAsString("Constraints"), Operands); |
| 315 | |
| 316 | // Parse the DisableEncoding field. |
| 317 | Operands.ProcessDisableEncoding(R->getValueAsString("DisableEncoding")); |
| 318 | } |
Chris Lattner | 9414ae5 | 2010-03-27 20:09:24 +0000 | [diff] [blame] | 319 | |
| 320 | /// HasOneImplicitDefWithKnownVT - If the instruction has at least one |
| 321 | /// implicit def and it has a known VT, return the VT, otherwise return |
| 322 | /// MVT::Other. |
| 323 | MVT::SimpleValueType CodeGenInstruction:: |
| 324 | HasOneImplicitDefWithKnownVT(const CodeGenTarget &TargetInfo) const { |
| 325 | if (ImplicitDefs.empty()) return MVT::Other; |
| 326 | |
| 327 | // Check to see if the first implicit def has a resolvable type. |
| 328 | Record *FirstImplicitDef = ImplicitDefs[0]; |
| 329 | assert(FirstImplicitDef->isSubClassOf("Register")); |
| 330 | const std::vector<MVT::SimpleValueType> &RegVTs = |
| 331 | TargetInfo.getRegisterVTs(FirstImplicitDef); |
| 332 | if (RegVTs.size() == 1) |
| 333 | return RegVTs[0]; |
| 334 | return MVT::Other; |
| 335 | } |
| 336 | |
Chris Lattner | 4d43d0f | 2010-11-01 01:07:14 +0000 | [diff] [blame] | 337 | |
| 338 | /// FlattenAsmStringVariants - Flatten the specified AsmString to only |
| 339 | /// include text from the specified variant, returning the new string. |
| 340 | std::string CodeGenInstruction:: |
| 341 | FlattenAsmStringVariants(StringRef Cur, unsigned Variant) { |
| 342 | std::string Res = ""; |
| 343 | |
| 344 | for (;;) { |
| 345 | // Find the start of the next variant string. |
| 346 | size_t VariantsStart = 0; |
| 347 | for (size_t e = Cur.size(); VariantsStart != e; ++VariantsStart) |
| 348 | if (Cur[VariantsStart] == '{' && |
| 349 | (VariantsStart == 0 || (Cur[VariantsStart-1] != '$' && |
| 350 | Cur[VariantsStart-1] != '\\'))) |
| 351 | break; |
| 352 | |
| 353 | // Add the prefix to the result. |
| 354 | Res += Cur.slice(0, VariantsStart); |
| 355 | if (VariantsStart == Cur.size()) |
| 356 | break; |
| 357 | |
| 358 | ++VariantsStart; // Skip the '{'. |
| 359 | |
| 360 | // Scan to the end of the variants string. |
| 361 | size_t VariantsEnd = VariantsStart; |
| 362 | unsigned NestedBraces = 1; |
| 363 | for (size_t e = Cur.size(); VariantsEnd != e; ++VariantsEnd) { |
| 364 | if (Cur[VariantsEnd] == '}' && Cur[VariantsEnd-1] != '\\') { |
| 365 | if (--NestedBraces == 0) |
| 366 | break; |
| 367 | } else if (Cur[VariantsEnd] == '{') |
| 368 | ++NestedBraces; |
| 369 | } |
| 370 | |
| 371 | // Select the Nth variant (or empty). |
| 372 | StringRef Selection = Cur.slice(VariantsStart, VariantsEnd); |
| 373 | for (unsigned i = 0; i != Variant; ++i) |
| 374 | Selection = Selection.split('|').second; |
| 375 | Res += Selection.split('|').first; |
| 376 | |
| 377 | assert(VariantsEnd != Cur.size() && |
| 378 | "Unterminated variants in assembly string!"); |
| 379 | Cur = Cur.substr(VariantsEnd + 1); |
| 380 | } |
| 381 | |
| 382 | return Res; |
| 383 | } |
| 384 | |