| 1 | //===-- Error.h -------------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_TOOLS_LLVM_EXEGESIS_ERROR_H |
| 10 | #define LLVM_TOOLS_LLVM_EXEGESIS_ERROR_H |
| 11 | |
| 12 | #include "llvm/ADT/Twine.h" |
| 13 | #include "llvm/Support/Error.h" |
| 14 | |
| 15 | namespace llvm { |
| 16 | namespace exegesis { |
| 17 | |
| 18 | // A class representing failures that happened within llvm-exegesis, they are |
| 19 | // used to report informations to the user. |
| 20 | class Failure : public StringError { |
| 21 | public: |
| 22 | Failure(const Twine &S) : StringError(S, inconvertibleErrorCode()) {} |
| 23 | }; |
| 24 | |
| 25 | // A class representing failures that happened during clustering calculations. |
| 26 | class ClusteringError : public ErrorInfo<ClusteringError> { |
| 27 | public: |
| 28 | static char ID; |
| 29 | ClusteringError(const Twine &S) : Msg(S.str()) {} |
| 30 | |
| 31 | void log(raw_ostream &OS) const override; |
| 32 | |
| 33 | std::error_code convertToErrorCode() const override; |
| 34 | |
| 35 | private: |
| 36 | std::string Msg; |
| 37 | }; |
| 38 | |
| 39 | // A class representing a non-descript snippet execution failure. This class |
| 40 | // is designed to sub-classed into more specific failures that contain |
| 41 | // additional data about the specific error that they represent. Instead of |
| 42 | // halting the program, the errors are reported in the output. |
| 43 | class SnippetExecutionFailure : public ErrorInfo<SnippetExecutionFailure> { |
| 44 | public: |
| 45 | static char ID; |
| 46 | |
| 47 | std::error_code convertToErrorCode() const override; |
| 48 | }; |
| 49 | |
| 50 | // A class representing specifically segmentation faults that happen during |
| 51 | // snippet execution. |
| 52 | class SnippetSegmentationFault : public SnippetExecutionFailure { |
| 53 | public: |
| 54 | static char ID; |
| 55 | SnippetSegmentationFault(uintptr_t SegFaultAddress) |
| 56 | : Address(SegFaultAddress) {}; |
| 57 | |
| 58 | uintptr_t getAddress() { return Address; } |
| 59 | |
| 60 | void log(raw_ostream &OS) const override; |
| 61 | |
| 62 | private: |
| 63 | uintptr_t Address; |
| 64 | }; |
| 65 | |
| 66 | // A class representing all other non-specific failures that happen during |
| 67 | // snippet execution. |
| 68 | class SnippetSignal : public SnippetExecutionFailure { |
| 69 | public: |
| 70 | static char ID; |
| 71 | SnippetSignal(int Signal) : SignalNumber(Signal){}; |
| 72 | |
| 73 | void log(raw_ostream &OS) const override; |
| 74 | |
| 75 | private: |
| 76 | int SignalNumber; |
| 77 | }; |
| 78 | |
| 79 | // A class representing a case where a perf counter was only partially |
| 80 | // scheduled, most likely due to perf counter contention. |
| 81 | struct PerfCounterNotFullyEnabled |
| 82 | : public ErrorInfo<PerfCounterNotFullyEnabled> { |
| 83 | static char ID; |
| 84 | PerfCounterNotFullyEnabled() {} |
| 85 | |
| 86 | void log(raw_ostream &OS) const override; |
| 87 | |
| 88 | std::error_code convertToErrorCode() const override; |
| 89 | }; |
| 90 | |
| 91 | } // namespace exegesis |
| 92 | } // namespace llvm |
| 93 | |
| 94 | #endif |
| 95 | |