summaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm16/include/llvm/MCA/SourceMgr.h
diff options
context:
space:
mode:
authorvvvv <[email protected]>2024-02-06 20:01:22 +0300
committervvvv <[email protected]>2024-02-06 20:22:16 +0300
commit0203b7a9a40828bb2bd4c32029b79ff0ea3d1f8f (patch)
treee630d0d5bd0bd29fc8c2d2842ed2cfde781b993a /contrib/libs/llvm16/include/llvm/MCA/SourceMgr.h
parentba27db76d99d12a4f1c06960b5449423218614c4 (diff)
llvm16 targets
Diffstat (limited to 'contrib/libs/llvm16/include/llvm/MCA/SourceMgr.h')
-rw-r--r--contrib/libs/llvm16/include/llvm/MCA/SourceMgr.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/contrib/libs/llvm16/include/llvm/MCA/SourceMgr.h b/contrib/libs/llvm16/include/llvm/MCA/SourceMgr.h
new file mode 100644
index 00000000000..2327ad9a4ab
--- /dev/null
+++ b/contrib/libs/llvm16/include/llvm/MCA/SourceMgr.h
@@ -0,0 +1,99 @@
+#pragma once
+
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+#endif
+
+//===--------------------- SourceMgr.h --------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+/// \file
+/// This file contains abstract class SourceMgr and the default implementation,
+/// CircularSourceMgr.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_MCA_SOURCEMGR_H
+#define LLVM_MCA_SOURCEMGR_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/MCA/Instruction.h"
+
+namespace llvm {
+namespace mca {
+
+// MSVC >= 19.15, < 19.20 need to see the definition of class Instruction to
+// prevent compiler error C2139 about intrinsic type trait '__is_assignable'.
+typedef std::pair<unsigned, const Instruction &> SourceRef;
+
+/// Abstracting the input code sequence (a sequence of MCInst) and assigning
+/// unique identifiers to every instruction in the sequence.
+struct SourceMgr {
+ using UniqueInst = std::unique_ptr<Instruction>;
+
+ /// Provides a fixed range of \a UniqueInst to iterate.
+ virtual ArrayRef<UniqueInst> getInstructions() const = 0;
+
+ /// (Fixed) Number of \a UniqueInst. Returns the size of
+ /// \a getInstructions by default.
+ virtual size_t size() const { return getInstructions().size(); }
+
+ /// Whether there is any \a SourceRef to inspect / peek next.
+ /// Note that returning false from this doesn't mean the instruction
+ /// stream has ended.
+ virtual bool hasNext() const = 0;
+
+ /// Whether the instruction stream has eneded.
+ virtual bool isEnd() const = 0;
+
+ /// The next \a SourceRef.
+ virtual SourceRef peekNext() const = 0;
+
+ /// Advance to the next \a SourceRef.
+ virtual void updateNext() = 0;
+
+ virtual ~SourceMgr() {}
+};
+
+/// The default implementation of \a SourceMgr. It always takes a fixed number
+/// of instructions and provides an option to loop the given sequence for a
+/// certain iterations.
+class CircularSourceMgr : public SourceMgr {
+ ArrayRef<UniqueInst> Sequence;
+ unsigned Current;
+ const unsigned Iterations;
+ static const unsigned DefaultIterations = 100;
+
+public:
+ CircularSourceMgr(ArrayRef<UniqueInst> S, unsigned Iter)
+ : Sequence(S), Current(0U), Iterations(Iter ? Iter : DefaultIterations) {}
+
+ ArrayRef<UniqueInst> getInstructions() const override { return Sequence; }
+
+ unsigned getNumIterations() const { return Iterations; }
+ bool hasNext() const override {
+ return Current < (Iterations * Sequence.size());
+ }
+ bool isEnd() const override { return !hasNext(); }
+
+ SourceRef peekNext() const override {
+ assert(hasNext() && "Already at end of sequence!");
+ return SourceRef(Current, *Sequence[Current % Sequence.size()]);
+ }
+
+ void updateNext() override { ++Current; }
+};
+
+} // namespace mca
+} // namespace llvm
+
+#endif // LLVM_MCA_SOURCEMGR_H
+
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif