llvm.org GIT mirror llvm / 1dce032
[NFC][llvm-exegesis] Also promote getSchedClassPoint() into ResolvedSchedClass. Summary: It doesn't need anything from Analysis::SchedClassCluster class, and takes ResolvedSchedClass as param, so this seems rather fitting. Reviewers: courbet, gchatelet Reviewed By: courbet Subscribers: tschuett, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59994 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357263 91177308-0d34-0410-b5e6-96231b3b80d8 Roman Lebedev 1 year, 8 months ago
4 changed file(s) with 83 addition(s) and 86 deletion(s). Raw diff Collapse all Expand all
347347 Centroid.addPoint(Point.Measurements);
348348 }
349349
350 // Returns a ProxResIdx by id or name.
351 static unsigned findProcResIdx(const llvm::MCSubtargetInfo &STI,
352 const llvm::StringRef NameOrId) {
353 // Interpret the key as an ProcResIdx.
354 unsigned ProcResIdx = 0;
355 if (llvm::to_integer(NameOrId, ProcResIdx, 10))
356 return ProcResIdx;
357 // Interpret the key as a ProcRes name.
358 const auto &SchedModel = STI.getSchedModel();
359 for (int I = 0, E = SchedModel.getNumProcResourceKinds(); I < E; ++I) {
360 if (NameOrId == SchedModel.getProcResource(I)->Name)
361 return I;
362 }
363 return 0;
364 }
365
366 std::vector Analysis::SchedClassCluster::getSchedClassPoint(
367 InstructionBenchmark::ModeE Mode, const llvm::MCSubtargetInfo &STI,
368 const ResolvedSchedClass &RSC,
369 ArrayRef Representative) const {
370 const size_t NumMeasurements = Representative.size();
371
372 std::vector SchedClassPoint(NumMeasurements);
373
374 if (Mode == InstructionBenchmark::Latency) {
375 assert(NumMeasurements == 1 && "Latency is a single measure.");
376 BenchmarkMeasure &LatencyMeasure = SchedClassPoint[0];
377
378 // Find the latency.
379 LatencyMeasure.PerInstructionValue = 0.0;
380
381 for (unsigned I = 0; I < RSC.SCDesc->NumWriteLatencyEntries; ++I) {
382 const llvm::MCWriteLatencyEntry *const WLE =
383 STI.getWriteLatencyEntry(RSC.SCDesc, I);
384 LatencyMeasure.PerInstructionValue =
385 std::max(LatencyMeasure.PerInstructionValue, WLE->Cycles);
386 }
387 } else if (Mode == InstructionBenchmark::Uops) {
388 for (const auto &I : llvm::zip(SchedClassPoint, Representative)) {
389 BenchmarkMeasure &Measure = std::get<0>(I);
390 const PerInstructionStats &Stats = std::get<1>(I);
391
392 StringRef Key = Stats.key();
393 uint16_t ProcResIdx = findProcResIdx(STI, Key);
394 if (ProcResIdx > 0) {
395 // Find the pressure on ProcResIdx `Key`.
396 const auto ProcResPressureIt =
397 std::find_if(RSC.IdealizedProcResPressure.begin(),
398 RSC.IdealizedProcResPressure.end(),
399 [ProcResIdx](const std::pair &WPR) {
400 return WPR.first == ProcResIdx;
401 });
402 Measure.PerInstructionValue =
403 ProcResPressureIt == RSC.IdealizedProcResPressure.end()
404 ? 0.0
405 : ProcResPressureIt->second;
406 } else if (Key == "NumMicroOps") {
407 Measure.PerInstructionValue = RSC.SCDesc->NumMicroOps;
408 } else {
409 llvm::errs() << "expected `key` to be either a ProcResIdx or a ProcRes "
410 "name, got "
411 << Key << "\n";
412 return {};
413 }
414 }
415 } else if (Mode == InstructionBenchmark::InverseThroughput) {
416 assert(NumMeasurements == 1 && "Inverse Throughput is a single measure.");
417 BenchmarkMeasure &RThroughputMeasure = SchedClassPoint[0];
418
419 RThroughputMeasure.PerInstructionValue =
420 MCSchedModel::getReciprocalThroughput(STI, *RSC.SCDesc);
421 } else {
422 llvm_unreachable("unimplemented measurement matching mode");
423 }
424
425 return SchedClassPoint;
426 }
427
428350 bool Analysis::SchedClassCluster::measurementsMatch(
429351 const llvm::MCSubtargetInfo &STI, const ResolvedSchedClass &RSC,
430352 const InstructionBenchmarkClustering &Clustering,
439361 Centroid.getAsPoint();
440362
441363 const std::vector SchedClassPoint =
442 getSchedClassPoint(Mode, STI, RSC, Centroid.getStats());
364 RSC.getAsPoint(Mode, STI, Centroid.getStats());
443365 if (SchedClassPoint.empty())
444366 return false; // In Uops mode validate() may not be enough.
445367
6666 // Return the cluster centroid.
6767 const SchedClassClusterCentroid &getCentroid() const { return Centroid; }
6868
69 std::vector
70 getSchedClassPoint(InstructionBenchmark::ModeE Mode,
71 const llvm::MCSubtargetInfo &STI,
72 const ResolvedSchedClass &SC,
73 ArrayRef Representative) const;
74
7569 // Returns true if the cluster representative measurements match that of SC.
7670 bool
7771 measurementsMatch(const llvm::MCSubtargetInfo &STI,
238238 return std::make_pair(SchedClassId, WasVariant);
239239 }
240240
241 // Returns a ProxResIdx by id or name.
242 static unsigned findProcResIdx(const llvm::MCSubtargetInfo &STI,
243 const llvm::StringRef NameOrId) {
244 // Interpret the key as an ProcResIdx.
245 unsigned ProcResIdx = 0;
246 if (llvm::to_integer(NameOrId, ProcResIdx, 10))
247 return ProcResIdx;
248 // Interpret the key as a ProcRes name.
249 const auto &SchedModel = STI.getSchedModel();
250 for (int I = 0, E = SchedModel.getNumProcResourceKinds(); I < E; ++I) {
251 if (NameOrId == SchedModel.getProcResource(I)->Name)
252 return I;
253 }
254 return 0;
255 }
256
257 std::vector ResolvedSchedClass::getAsPoint(
258 InstructionBenchmark::ModeE Mode, const llvm::MCSubtargetInfo &STI,
259 ArrayRef Representative) const {
260 const size_t NumMeasurements = Representative.size();
261
262 std::vector SchedClassPoint(NumMeasurements);
263
264 if (Mode == InstructionBenchmark::Latency) {
265 assert(NumMeasurements == 1 && "Latency is a single measure.");
266 BenchmarkMeasure &LatencyMeasure = SchedClassPoint[0];
267
268 // Find the latency.
269 LatencyMeasure.PerInstructionValue = 0.0;
270
271 for (unsigned I = 0; I < SCDesc->NumWriteLatencyEntries; ++I) {
272 const llvm::MCWriteLatencyEntry *const WLE =
273 STI.getWriteLatencyEntry(SCDesc, I);
274 LatencyMeasure.PerInstructionValue =
275 std::max(LatencyMeasure.PerInstructionValue, WLE->Cycles);
276 }
277 } else if (Mode == InstructionBenchmark::Uops) {
278 for (const auto &I : llvm::zip(SchedClassPoint, Representative)) {
279 BenchmarkMeasure &Measure = std::get<0>(I);
280 const PerInstructionStats &Stats = std::get<1>(I);
281
282 StringRef Key = Stats.key();
283 uint16_t ProcResIdx = findProcResIdx(STI, Key);
284 if (ProcResIdx > 0) {
285 // Find the pressure on ProcResIdx `Key`.
286 const auto ProcResPressureIt = std::find_if(
287 IdealizedProcResPressure.begin(), IdealizedProcResPressure.end(),
288 [ProcResIdx](const std::pair &WPR) {
289 return WPR.first == ProcResIdx;
290 });
291 Measure.PerInstructionValue =
292 ProcResPressureIt == IdealizedProcResPressure.end()
293 ? 0.0
294 : ProcResPressureIt->second;
295 } else if (Key == "NumMicroOps") {
296 Measure.PerInstructionValue = SCDesc->NumMicroOps;
297 } else {
298 llvm::errs() << "expected `key` to be either a ProcResIdx or a ProcRes "
299 "name, got "
300 << Key << "\n";
301 return {};
302 }
303 }
304 } else if (Mode == InstructionBenchmark::InverseThroughput) {
305 assert(NumMeasurements == 1 && "Inverse Throughput is a single measure.");
306 BenchmarkMeasure &RThroughputMeasure = SchedClassPoint[0];
307
308 RThroughputMeasure.PerInstructionValue =
309 MCSchedModel::getReciprocalThroughput(STI, *SCDesc);
310 } else {
311 llvm_unreachable("unimplemented measurement matching mode");
312 }
313
314 return SchedClassPoint;
315 }
316
241317 } // namespace exegesis
242318 } // namespace llvm
66 //===----------------------------------------------------------------------===//
77 ///
88 /// \file
9 /// Analysis output for benchmark results.
9 /// Resolution of MCInst sched class into expanded form for further analysis.
1010 ///
1111 //===----------------------------------------------------------------------===//
1212
1313 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_SCHEDCLASSRESOLUTION_H
1414 #define LLVM_TOOLS_LLVM_EXEGESIS_SCHEDCLASSRESOLUTION_H
1515
16 #include "BenchmarkResult.h"
1617 #include "llvm/MC/MCContext.h"
1718 #include "llvm/MC/MCDisassembler/MCDisassembler.h"
1819 #include "llvm/MC/MCInstPrinter.h"
4344 const llvm::MCInstrInfo &InstrInfo,
4445 const llvm::MCInst &MCI);
4546
47 std::vector
48 getAsPoint(InstructionBenchmark::ModeE Mode, const llvm::MCSubtargetInfo &STI,
49 ArrayRef Representative) const;
50
4651 const unsigned SchedClassId;
4752 const llvm::MCSchedClassDesc *const SCDesc;
4853 const bool WasVariant; // Whether the original class was variant.