Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 1 | //===--------------------- InstrBuilder.cpp ---------------------*- C++ -*-===// |
| 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 | /// \file |
| 10 | /// |
| 11 | /// This file implements the InstrBuilder interface. |
| 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "InstrBuilder.h" |
Andrea Di Biagio | 2145b13 | 2018-06-20 10:08:11 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/APInt.h" |
Andrea Di Biagio | 2008c7c | 2018-06-04 12:23:07 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/DenseMap.h" |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCInst.h" |
| 19 | #include "llvm/Support/Debug.h" |
Andrea Di Biagio | 24fb4fc | 2018-05-04 13:52:12 +0000 | [diff] [blame] | 20 | #include "llvm/Support/WithColor.h" |
Andrea Di Biagio | 8834779 | 2018-07-09 12:30:55 +0000 | [diff] [blame] | 21 | #include "llvm/Support/raw_ostream.h" |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 22 | |
| 23 | #define DEBUG_TYPE "llvm-mca" |
| 24 | |
Fangrui Song | 5a8fd65 | 2018-10-30 15:56:08 +0000 | [diff] [blame] | 25 | namespace llvm { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 26 | namespace mca { |
| 27 | |
Andrea Di Biagio | 77c26ae | 2018-10-25 11:51:34 +0000 | [diff] [blame] | 28 | InstrBuilder::InstrBuilder(const llvm::MCSubtargetInfo &sti, |
| 29 | const llvm::MCInstrInfo &mcii, |
| 30 | const llvm::MCRegisterInfo &mri, |
| 31 | const llvm::MCInstrAnalysis &mcia) |
| 32 | : STI(sti), MCII(mcii), MRI(mri), MCIA(mcia) { |
| 33 | computeProcResourceMasks(STI.getSchedModel(), ProcResourceMasks); |
| 34 | } |
| 35 | |
Andrea Di Biagio | 94fafdf | 2018-03-24 16:05:36 +0000 | [diff] [blame] | 36 | static void initializeUsedResources(InstrDesc &ID, |
| 37 | const MCSchedClassDesc &SCDesc, |
| 38 | const MCSubtargetInfo &STI, |
| 39 | ArrayRef<uint64_t> ProcResourceMasks) { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 40 | const MCSchedModel &SM = STI.getSchedModel(); |
| 41 | |
| 42 | // Populate resources consumed. |
| 43 | using ResourcePlusCycles = std::pair<uint64_t, ResourceUsage>; |
| 44 | std::vector<ResourcePlusCycles> Worklist; |
Andrea Di Biagio | 2008c7c | 2018-06-04 12:23:07 +0000 | [diff] [blame] | 45 | |
| 46 | // Track cycles contributed by resources that are in a "Super" relationship. |
| 47 | // This is required if we want to correctly match the behavior of method |
| 48 | // SubtargetEmitter::ExpandProcResource() in Tablegen. When computing the set |
| 49 | // of "consumed" processor resources and resource cycles, the logic in |
| 50 | // ExpandProcResource() doesn't update the number of resource cycles |
| 51 | // contributed by a "Super" resource to a group. |
| 52 | // We need to take this into account when we find that a processor resource is |
| 53 | // part of a group, and it is also used as the "Super" of other resources. |
| 54 | // This map stores the number of cycles contributed by sub-resources that are |
| 55 | // part of a "Super" resource. The key value is the "Super" resource mask ID. |
| 56 | DenseMap<uint64_t, unsigned> SuperResources; |
| 57 | |
Andrea Di Biagio | 91bdf24 | 2018-11-09 19:30:20 +0000 | [diff] [blame] | 58 | unsigned NumProcResources = SM.getNumProcResourceKinds(); |
| 59 | APInt Buffers(NumProcResources, 0); |
| 60 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 61 | for (unsigned I = 0, E = SCDesc.NumWriteProcResEntries; I < E; ++I) { |
| 62 | const MCWriteProcResEntry *PRE = STI.getWriteProcResBegin(&SCDesc) + I; |
| 63 | const MCProcResourceDesc &PR = *SM.getProcResource(PRE->ProcResourceIdx); |
| 64 | uint64_t Mask = ProcResourceMasks[PRE->ProcResourceIdx]; |
| 65 | if (PR.BufferSize != -1) |
Andrea Di Biagio | 91bdf24 | 2018-11-09 19:30:20 +0000 | [diff] [blame] | 66 | Buffers.setBit(PRE->ProcResourceIdx); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 67 | CycleSegment RCy(0, PRE->Cycles, false); |
| 68 | Worklist.emplace_back(ResourcePlusCycles(Mask, ResourceUsage(RCy))); |
Andrea Di Biagio | 2008c7c | 2018-06-04 12:23:07 +0000 | [diff] [blame] | 69 | if (PR.SuperIdx) { |
| 70 | uint64_t Super = ProcResourceMasks[PR.SuperIdx]; |
| 71 | SuperResources[Super] += PRE->Cycles; |
| 72 | } |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | // Sort elements by mask popcount, so that we prioritize resource units over |
| 76 | // resource groups, and smaller groups over larger groups. |
Andrea Di Biagio | a769912 | 2018-09-28 10:47:24 +0000 | [diff] [blame] | 77 | sort(Worklist, [](const ResourcePlusCycles &A, const ResourcePlusCycles &B) { |
| 78 | unsigned popcntA = countPopulation(A.first); |
| 79 | unsigned popcntB = countPopulation(B.first); |
| 80 | if (popcntA < popcntB) |
| 81 | return true; |
| 82 | if (popcntA > popcntB) |
| 83 | return false; |
| 84 | return A.first < B.first; |
| 85 | }); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 86 | |
| 87 | uint64_t UsedResourceUnits = 0; |
| 88 | |
| 89 | // Remove cycles contributed by smaller resources. |
| 90 | for (unsigned I = 0, E = Worklist.size(); I < E; ++I) { |
| 91 | ResourcePlusCycles &A = Worklist[I]; |
| 92 | if (!A.second.size()) { |
| 93 | A.second.NumUnits = 0; |
| 94 | A.second.setReserved(); |
| 95 | ID.Resources.emplace_back(A); |
| 96 | continue; |
| 97 | } |
| 98 | |
| 99 | ID.Resources.emplace_back(A); |
| 100 | uint64_t NormalizedMask = A.first; |
| 101 | if (countPopulation(A.first) == 1) { |
| 102 | UsedResourceUnits |= A.first; |
| 103 | } else { |
| 104 | // Remove the leading 1 from the resource group mask. |
| 105 | NormalizedMask ^= PowerOf2Floor(NormalizedMask); |
| 106 | } |
| 107 | |
| 108 | for (unsigned J = I + 1; J < E; ++J) { |
| 109 | ResourcePlusCycles &B = Worklist[J]; |
| 110 | if ((NormalizedMask & B.first) == NormalizedMask) { |
Matt Davis | 8e2c759 | 2018-10-01 23:01:45 +0000 | [diff] [blame] | 111 | B.second.CS.subtract(A.second.size() - SuperResources[A.first]); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 112 | if (countPopulation(B.first) > 1) |
| 113 | B.second.NumUnits++; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | // A SchedWrite may specify a number of cycles in which a resource group |
| 119 | // is reserved. For example (on target x86; cpu Haswell): |
| 120 | // |
| 121 | // SchedWriteRes<[HWPort0, HWPort1, HWPort01]> { |
| 122 | // let ResourceCycles = [2, 2, 3]; |
| 123 | // } |
| 124 | // |
| 125 | // This means: |
| 126 | // Resource units HWPort0 and HWPort1 are both used for 2cy. |
| 127 | // Resource group HWPort01 is the union of HWPort0 and HWPort1. |
| 128 | // Since this write touches both HWPort0 and HWPort1 for 2cy, HWPort01 |
| 129 | // will not be usable for 2 entire cycles from instruction issue. |
| 130 | // |
| 131 | // On top of those 2cy, SchedWriteRes explicitly specifies an extra latency |
| 132 | // of 3 cycles for HWPort01. This tool assumes that the 3cy latency is an |
| 133 | // extra delay on top of the 2 cycles latency. |
| 134 | // During those extra cycles, HWPort01 is not usable by other instructions. |
| 135 | for (ResourcePlusCycles &RPC : ID.Resources) { |
| 136 | if (countPopulation(RPC.first) > 1 && !RPC.second.isReserved()) { |
| 137 | // Remove the leading 1 from the resource group mask. |
| 138 | uint64_t Mask = RPC.first ^ PowerOf2Floor(RPC.first); |
| 139 | if ((Mask & UsedResourceUnits) == Mask) |
| 140 | RPC.second.setReserved(); |
| 141 | } |
| 142 | } |
| 143 | |
Andrea Di Biagio | 91bdf24 | 2018-11-09 19:30:20 +0000 | [diff] [blame] | 144 | // Identify extra buffers that are consumed through super resources. |
| 145 | for (const std::pair<uint64_t, unsigned> &SR : SuperResources) { |
| 146 | for (unsigned I = 1, E = NumProcResources; I < E; ++I) { |
| 147 | const MCProcResourceDesc &PR = *SM.getProcResource(I); |
| 148 | if (PR.BufferSize == -1) |
| 149 | continue; |
| 150 | |
| 151 | uint64_t Mask = ProcResourceMasks[I]; |
| 152 | if (Mask != SR.first && ((Mask & SR.first) == SR.first)) |
| 153 | Buffers.setBit(I); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // Now set the buffers. |
| 158 | if (unsigned NumBuffers = Buffers.countPopulation()) { |
| 159 | ID.Buffers.resize(NumBuffers); |
| 160 | for (unsigned I = 0, E = NumProcResources; I < E && NumBuffers; ++I) { |
| 161 | if (Buffers[I]) { |
| 162 | --NumBuffers; |
| 163 | ID.Buffers[NumBuffers] = ProcResourceMasks[I]; |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 168 | LLVM_DEBUG({ |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 169 | for (const std::pair<uint64_t, ResourceUsage> &R : ID.Resources) |
| 170 | dbgs() << "\t\tMask=" << R.first << ", cy=" << R.second.size() << '\n'; |
| 171 | for (const uint64_t R : ID.Buffers) |
| 172 | dbgs() << "\t\tBuffer Mask=" << R << '\n'; |
Andrea Di Biagio | 7b3d162 | 2018-03-20 12:58:34 +0000 | [diff] [blame] | 173 | }); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | static void computeMaxLatency(InstrDesc &ID, const MCInstrDesc &MCDesc, |
| 177 | const MCSchedClassDesc &SCDesc, |
| 178 | const MCSubtargetInfo &STI) { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 179 | if (MCDesc.isCall()) { |
| 180 | // We cannot estimate how long this call will take. |
| 181 | // Artificially set an arbitrarily high latency (100cy). |
Andrea Di Biagio | c95a130 | 2018-03-13 15:59:59 +0000 | [diff] [blame] | 182 | ID.MaxLatency = 100U; |
| 183 | return; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Andrea Di Biagio | c95a130 | 2018-03-13 15:59:59 +0000 | [diff] [blame] | 186 | int Latency = MCSchedModel::computeInstrLatency(STI, SCDesc); |
| 187 | // If latency is unknown, then conservatively assume a MaxLatency of 100cy. |
| 188 | ID.MaxLatency = Latency < 0 ? 100U : static_cast<unsigned>(Latency); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 191 | static Error verifyOperands(const MCInstrDesc &MCDesc, const MCInst &MCI) { |
| 192 | // Variadic opcodes are not correctly supported. |
| 193 | if (MCDesc.isVariadic()) { |
| 194 | if (MCI.getNumOperands() - MCDesc.getNumOperands()) { |
| 195 | return make_error<InstructionError<MCInst>>( |
| 196 | "Don't know how to process this variadic opcode.", MCI); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | // Count register definitions, and skip non register operands in the process. |
| 201 | unsigned I, E; |
| 202 | unsigned NumExplicitDefs = MCDesc.getNumDefs(); |
| 203 | for (I = 0, E = MCI.getNumOperands(); NumExplicitDefs && I < E; ++I) { |
| 204 | const MCOperand &Op = MCI.getOperand(I); |
| 205 | if (Op.isReg()) |
| 206 | --NumExplicitDefs; |
| 207 | } |
| 208 | |
| 209 | if (NumExplicitDefs) { |
| 210 | return make_error<InstructionError<MCInst>>( |
| 211 | "Expected more register operand definitions.", MCI); |
| 212 | } |
| 213 | |
| 214 | if (MCDesc.hasOptionalDef()) { |
| 215 | // Always assume that the optional definition is the last operand. |
| 216 | const MCOperand &Op = MCI.getOperand(MCDesc.getNumOperands() - 1); |
| 217 | if (I == MCI.getNumOperands() || !Op.isReg()) { |
| 218 | std::string Message = |
| 219 | "expected a register operand for an optional definition. Instruction " |
| 220 | "has not been correctly analyzed."; |
| 221 | return make_error<InstructionError<MCInst>>(Message, MCI); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | return ErrorSuccess(); |
| 226 | } |
| 227 | |
| 228 | void InstrBuilder::populateWrites(InstrDesc &ID, const MCInst &MCI, |
| 229 | unsigned SchedClassID) { |
Andrea Di Biagio | 8834779 | 2018-07-09 12:30:55 +0000 | [diff] [blame] | 230 | const MCInstrDesc &MCDesc = MCII.get(MCI.getOpcode()); |
| 231 | const MCSchedModel &SM = STI.getSchedModel(); |
| 232 | const MCSchedClassDesc &SCDesc = *SM.getSchedClassDesc(SchedClassID); |
| 233 | |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 234 | // Assumptions made by this algorithm: |
| 235 | // 1. The number of explicit and implicit register definitions in a MCInst |
| 236 | // matches the number of explicit and implicit definitions according to |
| 237 | // the opcode descriptor (MCInstrDesc). |
| 238 | // 2. Uses start at index #(MCDesc.getNumDefs()). |
| 239 | // 3. There can only be a single optional register definition, an it is |
| 240 | // always the last operand of the sequence (excluding extra operands |
| 241 | // contributed by variadic opcodes). |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 242 | // |
| 243 | // These assumptions work quite well for most out-of-order in-tree targets |
| 244 | // like x86. This is mainly because the vast majority of instructions is |
| 245 | // expanded to MCInst using a straightforward lowering logic that preserves |
| 246 | // the ordering of the operands. |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 247 | // |
| 248 | // About assumption 1. |
| 249 | // The algorithm allows non-register operands between register operand |
| 250 | // definitions. This helps to handle some special ARM instructions with |
| 251 | // implicit operand increment (-mtriple=armv7): |
| 252 | // |
| 253 | // vld1.32 {d18, d19}, [r1]! @ <MCInst #1463 VLD1q32wb_fixed |
| 254 | // @ <MCOperand Reg:59> |
| 255 | // @ <MCOperand Imm:0> (!!) |
| 256 | // @ <MCOperand Reg:67> |
| 257 | // @ <MCOperand Imm:0> |
| 258 | // @ <MCOperand Imm:14> |
| 259 | // @ <MCOperand Reg:0>> |
| 260 | // |
| 261 | // MCDesc reports: |
| 262 | // 6 explicit operands. |
| 263 | // 1 optional definition |
| 264 | // 2 explicit definitions (!!) |
| 265 | // |
| 266 | // The presence of an 'Imm' operand between the two register definitions |
| 267 | // breaks the assumption that "register definitions are always at the |
| 268 | // beginning of the operand sequence". |
| 269 | // |
| 270 | // To workaround this issue, this algorithm ignores (i.e. skips) any |
| 271 | // non-register operands between register definitions. The optional |
| 272 | // definition is still at index #(NumOperands-1). |
| 273 | // |
| 274 | // According to assumption 2. register reads start at #(NumExplicitDefs-1). |
| 275 | // That means, register R1 from the example is both read and written. |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 276 | unsigned NumExplicitDefs = MCDesc.getNumDefs(); |
| 277 | unsigned NumImplicitDefs = MCDesc.getNumImplicitDefs(); |
| 278 | unsigned NumWriteLatencyEntries = SCDesc.NumWriteLatencyEntries; |
| 279 | unsigned TotalDefs = NumExplicitDefs + NumImplicitDefs; |
| 280 | if (MCDesc.hasOptionalDef()) |
| 281 | TotalDefs++; |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 282 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 283 | ID.Writes.resize(TotalDefs); |
| 284 | // Iterate over the operands list, and skip non-register operands. |
| 285 | // The first NumExplictDefs register operands are expected to be register |
| 286 | // definitions. |
| 287 | unsigned CurrentDef = 0; |
| 288 | unsigned i = 0; |
| 289 | for (; i < MCI.getNumOperands() && CurrentDef < NumExplicitDefs; ++i) { |
| 290 | const MCOperand &Op = MCI.getOperand(i); |
| 291 | if (!Op.isReg()) |
| 292 | continue; |
| 293 | |
| 294 | WriteDescriptor &Write = ID.Writes[CurrentDef]; |
| 295 | Write.OpIndex = i; |
| 296 | if (CurrentDef < NumWriteLatencyEntries) { |
| 297 | const MCWriteLatencyEntry &WLE = |
| 298 | *STI.getWriteLatencyEntry(&SCDesc, CurrentDef); |
| 299 | // Conservatively default to MaxLatency. |
Andrea Di Biagio | 8834779 | 2018-07-09 12:30:55 +0000 | [diff] [blame] | 300 | Write.Latency = |
| 301 | WLE.Cycles < 0 ? ID.MaxLatency : static_cast<unsigned>(WLE.Cycles); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 302 | Write.SClassOrWriteResourceID = WLE.WriteResourceID; |
| 303 | } else { |
| 304 | // Assign a default latency for this write. |
| 305 | Write.Latency = ID.MaxLatency; |
| 306 | Write.SClassOrWriteResourceID = 0; |
| 307 | } |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 308 | Write.IsOptionalDef = false; |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 309 | LLVM_DEBUG({ |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 310 | dbgs() << "\t\t[Def] OpIdx=" << Write.OpIndex |
Andrea Di Biagio | 23fbe7c | 2018-07-13 14:55:47 +0000 | [diff] [blame] | 311 | << ", Latency=" << Write.Latency |
Andrea Di Biagio | 7b3d162 | 2018-03-20 12:58:34 +0000 | [diff] [blame] | 312 | << ", WriteResourceID=" << Write.SClassOrWriteResourceID << '\n'; |
| 313 | }); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 314 | CurrentDef++; |
| 315 | } |
| 316 | |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 317 | assert(CurrentDef == NumExplicitDefs && |
| 318 | "Expected more register operand definitions."); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 319 | for (CurrentDef = 0; CurrentDef < NumImplicitDefs; ++CurrentDef) { |
| 320 | unsigned Index = NumExplicitDefs + CurrentDef; |
| 321 | WriteDescriptor &Write = ID.Writes[Index]; |
Andrea Di Biagio | 21f0fdb | 2018-06-22 16:37:05 +0000 | [diff] [blame] | 322 | Write.OpIndex = ~CurrentDef; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 323 | Write.RegisterID = MCDesc.getImplicitDefs()[CurrentDef]; |
Andrea Di Biagio | 6fd62fe | 2018-04-02 13:46:49 +0000 | [diff] [blame] | 324 | if (Index < NumWriteLatencyEntries) { |
| 325 | const MCWriteLatencyEntry &WLE = |
| 326 | *STI.getWriteLatencyEntry(&SCDesc, Index); |
| 327 | // Conservatively default to MaxLatency. |
Andrea Di Biagio | 8834779 | 2018-07-09 12:30:55 +0000 | [diff] [blame] | 328 | Write.Latency = |
| 329 | WLE.Cycles < 0 ? ID.MaxLatency : static_cast<unsigned>(WLE.Cycles); |
Andrea Di Biagio | 6fd62fe | 2018-04-02 13:46:49 +0000 | [diff] [blame] | 330 | Write.SClassOrWriteResourceID = WLE.WriteResourceID; |
| 331 | } else { |
| 332 | // Assign a default latency for this write. |
| 333 | Write.Latency = ID.MaxLatency; |
| 334 | Write.SClassOrWriteResourceID = 0; |
| 335 | } |
| 336 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 337 | Write.IsOptionalDef = false; |
| 338 | assert(Write.RegisterID != 0 && "Expected a valid phys register!"); |
Andrea Di Biagio | 23fbe7c | 2018-07-13 14:55:47 +0000 | [diff] [blame] | 339 | LLVM_DEBUG({ |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 340 | dbgs() << "\t\t[Def][I] OpIdx=" << ~Write.OpIndex |
Andrea Di Biagio | 23fbe7c | 2018-07-13 14:55:47 +0000 | [diff] [blame] | 341 | << ", PhysReg=" << MRI.getName(Write.RegisterID) |
| 342 | << ", Latency=" << Write.Latency |
| 343 | << ", WriteResourceID=" << Write.SClassOrWriteResourceID << '\n'; |
| 344 | }); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | if (MCDesc.hasOptionalDef()) { |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 348 | WriteDescriptor &Write = ID.Writes[NumExplicitDefs + NumImplicitDefs]; |
| 349 | Write.OpIndex = MCDesc.getNumOperands() - 1; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 350 | // Assign a default latency for this write. |
| 351 | Write.Latency = ID.MaxLatency; |
| 352 | Write.SClassOrWriteResourceID = 0; |
| 353 | Write.IsOptionalDef = true; |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 354 | LLVM_DEBUG({ |
| 355 | dbgs() << "\t\t[Def][O] OpIdx=" << Write.OpIndex |
| 356 | << ", Latency=" << Write.Latency |
| 357 | << ", WriteResourceID=" << Write.SClassOrWriteResourceID << '\n'; |
| 358 | }); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 362 | void InstrBuilder::populateReads(InstrDesc &ID, const MCInst &MCI, |
| 363 | unsigned SchedClassID) { |
Andrea Di Biagio | 8834779 | 2018-07-09 12:30:55 +0000 | [diff] [blame] | 364 | const MCInstrDesc &MCDesc = MCII.get(MCI.getOpcode()); |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 365 | unsigned NumExplicitUses = MCDesc.getNumOperands() - MCDesc.getNumDefs(); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 366 | unsigned NumImplicitUses = MCDesc.getNumImplicitUses(); |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 367 | // Remove the optional definition. |
| 368 | if (MCDesc.hasOptionalDef()) |
| 369 | --NumExplicitUses; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 370 | unsigned TotalUses = NumExplicitUses + NumImplicitUses; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 371 | |
| 372 | ID.Reads.resize(TotalUses); |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 373 | for (unsigned I = 0; I < NumExplicitUses; ++I) { |
| 374 | ReadDescriptor &Read = ID.Reads[I]; |
| 375 | Read.OpIndex = MCDesc.getNumDefs() + I; |
| 376 | Read.UseIndex = I; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 377 | Read.SchedClassID = SchedClassID; |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 378 | LLVM_DEBUG(dbgs() << "\t\t[Use] OpIdx=" << Read.OpIndex |
Andrea Di Biagio | 23fbe7c | 2018-07-13 14:55:47 +0000 | [diff] [blame] | 379 | << ", UseIndex=" << Read.UseIndex << '\n'); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 382 | // For the purpose of ReadAdvance, implicit uses come directly after explicit |
| 383 | // uses. The "UseIndex" must be updated according to that implicit layout. |
| 384 | for (unsigned I = 0; I < NumImplicitUses; ++I) { |
| 385 | ReadDescriptor &Read = ID.Reads[NumExplicitUses + I]; |
| 386 | Read.OpIndex = ~I; |
| 387 | Read.UseIndex = NumExplicitUses + I; |
| 388 | Read.RegisterID = MCDesc.getImplicitUses()[I]; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 389 | Read.SchedClassID = SchedClassID; |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 390 | LLVM_DEBUG(dbgs() << "\t\t[Use][I] OpIdx=" << ~Read.OpIndex |
| 391 | << ", UseIndex=" << Read.UseIndex << ", RegisterID=" |
Andrea Di Biagio | 23fbe7c | 2018-07-13 14:55:47 +0000 | [diff] [blame] | 392 | << MRI.getName(Read.RegisterID) << '\n'); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | |
Andrea Di Biagio | aacd5e1 | 2018-10-04 10:36:49 +0000 | [diff] [blame] | 396 | Error InstrBuilder::verifyInstrDesc(const InstrDesc &ID, |
| 397 | const MCInst &MCI) const { |
| 398 | if (ID.NumMicroOps != 0) |
| 399 | return ErrorSuccess(); |
| 400 | |
| 401 | bool UsesMemory = ID.MayLoad || ID.MayStore; |
| 402 | bool UsesBuffers = !ID.Buffers.empty(); |
| 403 | bool UsesResources = !ID.Resources.empty(); |
| 404 | if (!UsesMemory && !UsesBuffers && !UsesResources) |
| 405 | return ErrorSuccess(); |
| 406 | |
Andrea Di Biagio | 083addf | 2018-10-24 10:56:47 +0000 | [diff] [blame] | 407 | StringRef Message; |
Andrea Di Biagio | aacd5e1 | 2018-10-04 10:36:49 +0000 | [diff] [blame] | 408 | if (UsesMemory) { |
Andrea Di Biagio | 083addf | 2018-10-24 10:56:47 +0000 | [diff] [blame] | 409 | Message = "found an inconsistent instruction that decodes " |
| 410 | "into zero opcodes and that consumes load/store " |
| 411 | "unit resources."; |
Andrea Di Biagio | aacd5e1 | 2018-10-04 10:36:49 +0000 | [diff] [blame] | 412 | } else { |
Andrea Di Biagio | 083addf | 2018-10-24 10:56:47 +0000 | [diff] [blame] | 413 | Message = "found an inconsistent instruction that decodes " |
| 414 | "to zero opcodes and that consumes scheduler " |
| 415 | "resources."; |
Andrea Di Biagio | aacd5e1 | 2018-10-04 10:36:49 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Andrea Di Biagio | 083addf | 2018-10-24 10:56:47 +0000 | [diff] [blame] | 418 | return make_error<InstructionError<MCInst>>(Message, MCI); |
Andrea Di Biagio | aacd5e1 | 2018-10-04 10:36:49 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 421 | Expected<const InstrDesc &> |
| 422 | InstrBuilder::createInstrDescImpl(const MCInst &MCI) { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 423 | assert(STI.getSchedModel().hasInstrSchedModel() && |
| 424 | "Itineraries are not yet supported!"); |
| 425 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 426 | // Obtain the instruction descriptor from the opcode. |
Andrea Di Biagio | 8834779 | 2018-07-09 12:30:55 +0000 | [diff] [blame] | 427 | unsigned short Opcode = MCI.getOpcode(); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 428 | const MCInstrDesc &MCDesc = MCII.get(Opcode); |
| 429 | const MCSchedModel &SM = STI.getSchedModel(); |
| 430 | |
| 431 | // Then obtain the scheduling class information from the instruction. |
Andrea Di Biagio | 49c8591 | 2018-05-04 13:10:10 +0000 | [diff] [blame] | 432 | unsigned SchedClassID = MCDesc.getSchedClass(); |
Andrea Di Biagio | 39e5a56 | 2018-06-04 15:43:09 +0000 | [diff] [blame] | 433 | unsigned CPUID = SM.getProcessorID(); |
| 434 | |
| 435 | // Try to solve variant scheduling classes. |
| 436 | if (SchedClassID) { |
| 437 | while (SchedClassID && SM.getSchedClassDesc(SchedClassID)->isVariant()) |
| 438 | SchedClassID = STI.resolveVariantSchedClass(SchedClassID, &MCI, CPUID); |
| 439 | |
Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 440 | if (!SchedClassID) { |
Andrea Di Biagio | 083addf | 2018-10-24 10:56:47 +0000 | [diff] [blame] | 441 | return make_error<InstructionError<MCInst>>( |
| 442 | "unable to resolve scheduling class for write variant.", MCI); |
Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 443 | } |
Andrea Di Biagio | 39e5a56 | 2018-06-04 15:43:09 +0000 | [diff] [blame] | 444 | } |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 445 | |
Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 446 | // Check if this instruction is supported. Otherwise, report an error. |
Andrea Di Biagio | 8834779 | 2018-07-09 12:30:55 +0000 | [diff] [blame] | 447 | const MCSchedClassDesc &SCDesc = *SM.getSchedClassDesc(SchedClassID); |
| 448 | if (SCDesc.NumMicroOps == MCSchedClassDesc::InvalidNumMicroOps) { |
Andrea Di Biagio | 083addf | 2018-10-24 10:56:47 +0000 | [diff] [blame] | 449 | return make_error<InstructionError<MCInst>>( |
| 450 | "found an unsupported instruction in the input assembly sequence.", |
| 451 | MCI); |
Andrea Di Biagio | 8834779 | 2018-07-09 12:30:55 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 454 | // Create a new empty descriptor. |
Andrea Di Biagio | 7b3d162 | 2018-03-20 12:58:34 +0000 | [diff] [blame] | 455 | std::unique_ptr<InstrDesc> ID = llvm::make_unique<InstrDesc>(); |
Andrea Di Biagio | 39e5a56 | 2018-06-04 15:43:09 +0000 | [diff] [blame] | 456 | ID->NumMicroOps = SCDesc.NumMicroOps; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 457 | |
| 458 | if (MCDesc.isCall()) { |
| 459 | // We don't correctly model calls. |
Andrea Di Biagio | 24fb4fc | 2018-05-04 13:52:12 +0000 | [diff] [blame] | 460 | WithColor::warning() << "found a call in the input assembly sequence.\n"; |
| 461 | WithColor::note() << "call instructions are not correctly modeled. " |
| 462 | << "Assume a latency of 100cy.\n"; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | if (MCDesc.isReturn()) { |
Andrea Di Biagio | 24fb4fc | 2018-05-04 13:52:12 +0000 | [diff] [blame] | 466 | WithColor::warning() << "found a return instruction in the input" |
| 467 | << " assembly sequence.\n"; |
| 468 | WithColor::note() << "program counter updates are ignored.\n"; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | ID->MayLoad = MCDesc.mayLoad(); |
| 472 | ID->MayStore = MCDesc.mayStore(); |
| 473 | ID->HasSideEffects = MCDesc.hasUnmodeledSideEffects(); |
| 474 | |
| 475 | initializeUsedResources(*ID, SCDesc, STI, ProcResourceMasks); |
Andrea Di Biagio | db66efc | 2018-04-25 09:38:58 +0000 | [diff] [blame] | 476 | computeMaxLatency(*ID, MCDesc, SCDesc, STI); |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 477 | |
| 478 | if (Error Err = verifyOperands(MCDesc, MCI)) |
Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 479 | return std::move(Err); |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 480 | |
| 481 | populateWrites(*ID, MCI, SchedClassID); |
| 482 | populateReads(*ID, MCI, SchedClassID); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 483 | |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 484 | LLVM_DEBUG(dbgs() << "\t\tMaxLatency=" << ID->MaxLatency << '\n'); |
| 485 | LLVM_DEBUG(dbgs() << "\t\tNumMicroOps=" << ID->NumMicroOps << '\n'); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 486 | |
Andrea Di Biagio | aacd5e1 | 2018-10-04 10:36:49 +0000 | [diff] [blame] | 487 | // Sanity check on the instruction descriptor. |
| 488 | if (Error Err = verifyInstrDesc(*ID, MCI)) |
| 489 | return std::move(Err); |
| 490 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 491 | // Now add the new descriptor. |
Andrea Di Biagio | 39e5a56 | 2018-06-04 15:43:09 +0000 | [diff] [blame] | 492 | SchedClassID = MCDesc.getSchedClass(); |
| 493 | if (!SM.getSchedClassDesc(SchedClassID)->isVariant()) { |
| 494 | Descriptors[MCI.getOpcode()] = std::move(ID); |
| 495 | return *Descriptors[MCI.getOpcode()]; |
| 496 | } |
| 497 | |
| 498 | VariantDescriptors[&MCI] = std::move(ID); |
| 499 | return *VariantDescriptors[&MCI]; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 502 | Expected<const InstrDesc &> |
| 503 | InstrBuilder::getOrCreateInstrDesc(const MCInst &MCI) { |
Andrea Di Biagio | 39e5a56 | 2018-06-04 15:43:09 +0000 | [diff] [blame] | 504 | if (Descriptors.find_as(MCI.getOpcode()) != Descriptors.end()) |
| 505 | return *Descriptors[MCI.getOpcode()]; |
| 506 | |
| 507 | if (VariantDescriptors.find(&MCI) != VariantDescriptors.end()) |
| 508 | return *VariantDescriptors[&MCI]; |
| 509 | |
| 510 | return createInstrDescImpl(MCI); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 513 | Expected<std::unique_ptr<Instruction>> |
Andrea Di Biagio | 49c8591 | 2018-05-04 13:10:10 +0000 | [diff] [blame] | 514 | InstrBuilder::createInstruction(const MCInst &MCI) { |
Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 515 | Expected<const InstrDesc &> DescOrErr = getOrCreateInstrDesc(MCI); |
| 516 | if (!DescOrErr) |
| 517 | return DescOrErr.takeError(); |
| 518 | const InstrDesc &D = *DescOrErr; |
Andrea Di Biagio | 7b3d162 | 2018-03-20 12:58:34 +0000 | [diff] [blame] | 519 | std::unique_ptr<Instruction> NewIS = llvm::make_unique<Instruction>(D); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 520 | |
Andrea Di Biagio | 9f9cdd4 | 2018-09-18 15:00:06 +0000 | [diff] [blame] | 521 | // Check if this is a dependency breaking instruction. |
Andrea Di Biagio | 8b6c314 | 2018-09-19 15:57:45 +0000 | [diff] [blame] | 522 | APInt Mask; |
| 523 | |
| 524 | unsigned ProcID = STI.getSchedModel().getProcessorID(); |
| 525 | bool IsZeroIdiom = MCIA.isZeroIdiom(MCI, Mask, ProcID); |
| 526 | bool IsDepBreaking = |
| 527 | IsZeroIdiom || MCIA.isDependencyBreaking(MCI, Mask, ProcID); |
Andrea Di Biagio | 6eebbe0 | 2018-10-12 11:23:04 +0000 | [diff] [blame] | 528 | if (MCIA.isOptimizableRegisterMove(MCI, ProcID)) |
| 529 | NewIS->setOptimizableMove(); |
Andrea Di Biagio | 9f9cdd4 | 2018-09-18 15:00:06 +0000 | [diff] [blame] | 530 | |
Andrea Di Biagio | db66efc | 2018-04-25 09:38:58 +0000 | [diff] [blame] | 531 | // Initialize Reads first. |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 532 | for (const ReadDescriptor &RD : D.Reads) { |
| 533 | int RegID = -1; |
Andrea Di Biagio | 21f0fdb | 2018-06-22 16:37:05 +0000 | [diff] [blame] | 534 | if (!RD.isImplicitRead()) { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 535 | // explicit read. |
| 536 | const MCOperand &Op = MCI.getOperand(RD.OpIndex); |
| 537 | // Skip non-register operands. |
| 538 | if (!Op.isReg()) |
| 539 | continue; |
| 540 | RegID = Op.getReg(); |
| 541 | } else { |
| 542 | // Implicit read. |
| 543 | RegID = RD.RegisterID; |
| 544 | } |
| 545 | |
| 546 | // Skip invalid register operands. |
| 547 | if (!RegID) |
| 548 | continue; |
| 549 | |
| 550 | // Okay, this is a register operand. Create a ReadState for it. |
| 551 | assert(RegID > 0 && "Invalid register ID found!"); |
Andrea Di Biagio | 1e6d0aa | 2018-10-25 17:03:51 +0000 | [diff] [blame] | 552 | NewIS->getUses().emplace_back(RD, RegID); |
| 553 | ReadState &RS = NewIS->getUses().back(); |
Andrea Di Biagio | 9f9cdd4 | 2018-09-18 15:00:06 +0000 | [diff] [blame] | 554 | |
Andrea Di Biagio | 8b6c314 | 2018-09-19 15:57:45 +0000 | [diff] [blame] | 555 | if (IsDepBreaking) { |
| 556 | // A mask of all zeroes means: explicit input operands are not |
| 557 | // independent. |
| 558 | if (Mask.isNullValue()) { |
| 559 | if (!RD.isImplicitRead()) |
Andrea Di Biagio | 1e6d0aa | 2018-10-25 17:03:51 +0000 | [diff] [blame] | 560 | RS.setIndependentFromDef(); |
Andrea Di Biagio | 8b6c314 | 2018-09-19 15:57:45 +0000 | [diff] [blame] | 561 | } else { |
| 562 | // Check if this register operand is independent according to `Mask`. |
| 563 | // Note that Mask may not have enough bits to describe all explicit and |
| 564 | // implicit input operands. If this register operand doesn't have a |
| 565 | // corresponding bit in Mask, then conservatively assume that it is |
| 566 | // dependent. |
| 567 | if (Mask.getBitWidth() > RD.UseIndex) { |
| 568 | // Okay. This map describe register use `RD.UseIndex`. |
| 569 | if (Mask[RD.UseIndex]) |
Andrea Di Biagio | 1e6d0aa | 2018-10-25 17:03:51 +0000 | [diff] [blame] | 570 | RS.setIndependentFromDef(); |
Andrea Di Biagio | 8b6c314 | 2018-09-19 15:57:45 +0000 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | } |
Andrea Di Biagio | 4704f03 | 2018-03-20 12:25:54 +0000 | [diff] [blame] | 574 | } |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 575 | |
Andrea Di Biagio | 2145b13 | 2018-06-20 10:08:11 +0000 | [diff] [blame] | 576 | // Early exit if there are no writes. |
| 577 | if (D.Writes.empty()) |
Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 578 | return std::move(NewIS); |
Andrea Di Biagio | 2145b13 | 2018-06-20 10:08:11 +0000 | [diff] [blame] | 579 | |
| 580 | // Track register writes that implicitly clear the upper portion of the |
| 581 | // underlying super-registers using an APInt. |
| 582 | APInt WriteMask(D.Writes.size(), 0); |
| 583 | |
| 584 | // Now query the MCInstrAnalysis object to obtain information about which |
| 585 | // register writes implicitly clear the upper portion of a super-register. |
| 586 | MCIA.clearsSuperRegisters(MRI, MCI, WriteMask); |
| 587 | |
Andrea Di Biagio | db66efc | 2018-04-25 09:38:58 +0000 | [diff] [blame] | 588 | // Initialize writes. |
Andrea Di Biagio | 2145b13 | 2018-06-20 10:08:11 +0000 | [diff] [blame] | 589 | unsigned WriteIndex = 0; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 590 | for (const WriteDescriptor &WD : D.Writes) { |
Andrea Di Biagio | 8834779 | 2018-07-09 12:30:55 +0000 | [diff] [blame] | 591 | unsigned RegID = WD.isImplicitWrite() ? WD.RegisterID |
| 592 | : MCI.getOperand(WD.OpIndex).getReg(); |
Andrea Di Biagio | 3562248 | 2018-03-22 10:19:20 +0000 | [diff] [blame] | 593 | // Check if this is a optional definition that references NoReg. |
Andrea Di Biagio | 2145b13 | 2018-06-20 10:08:11 +0000 | [diff] [blame] | 594 | if (WD.IsOptionalDef && !RegID) { |
| 595 | ++WriteIndex; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 596 | continue; |
Andrea Di Biagio | 2145b13 | 2018-06-20 10:08:11 +0000 | [diff] [blame] | 597 | } |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 598 | |
Andrea Di Biagio | 3562248 | 2018-03-22 10:19:20 +0000 | [diff] [blame] | 599 | assert(RegID && "Expected a valid register ID!"); |
Andrea Di Biagio | 7e32cc8 | 2018-11-23 20:26:57 +0000 | [diff] [blame^] | 600 | NewIS->getDefs().emplace_back(WD, RegID, |
| 601 | /* ClearsSuperRegs */ WriteMask[WriteIndex], |
| 602 | /* WritesZero */ IsZeroIdiom); |
Andrea Di Biagio | 2145b13 | 2018-06-20 10:08:11 +0000 | [diff] [blame] | 603 | ++WriteIndex; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 606 | return std::move(NewIS); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 607 | } |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 608 | } // namespace mca |
Fangrui Song | 5a8fd65 | 2018-10-30 15:56:08 +0000 | [diff] [blame] | 609 | } // namespace llvm |