brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.2 KiB · 8b2b7db Raw
131 lines · c
1//===- InternalEventCommon.h - Common internal event basics -----*- 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-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// Provides event types, and class/operator declaration macros.11///12//===----------------------------------------------------------------------===//13 14#ifndef OPENMP_TOOLS_OMPTEST_INCLUDE_INTERNALEVENTCOMMON_H15#define OPENMP_TOOLS_OMPTEST_INCLUDE_INTERNALEVENTCOMMON_H16 17#include "omp-tools.h"18 19#include <cassert>20#include <string>21 22namespace omptest {23 24namespace internal {25/// Enum values are used for comparison of observed and asserted events26/// List is based on OpenMP 5.2 specification, table 19.2 (page 447)27enum class EventTy {28  None,                     // not part of OpenMP spec, used for implementation29  AssertionSyncPoint,       // not part of OpenMP spec, used for implementation30  AssertionSuspend,         // not part of OpenMP spec, used for implementation31  BufferRecord,             // not part of OpenMP spec, used for implementation32  BufferRecordDeallocation, // not part of OpenMP spec, used for implementation33  ThreadBegin,34  ThreadEnd,35  ParallelBegin,36  ParallelEnd,37  Work,38  Dispatch,39  TaskCreate,     // TODO: Implement40  Dependences,    // TODO: Implement41  TaskDependence, // TODO: Implement42  TaskSchedule,   // TODO: Implement43  ImplicitTask,   // TODO: Implement44  Masked,         // TODO: Implement45  SyncRegion,46  MutexAcquire, // TODO: Implement47  Mutex,        // TODO: Implement48  NestLock,     // TODO: Implement49  Flush,        // TODO: Implement50  Cancel,       // TODO: Implement51  DeviceInitialize,52  DeviceFinalize,53  DeviceLoad,54  DeviceUnload,55  BufferRequest,56  BufferComplete,57  TargetDataOp,58  TargetDataOpEmi,59  Target,60  TargetEmi,61  TargetSubmit,62  TargetSubmitEmi,63  ControlTool64};65 66/// Base event class67/// Offers default CTOR, DTOR and CTOR which assigns the actual event type.68struct InternalEvent {69  InternalEvent() : Type(EventTy::None) {}70  InternalEvent(EventTy T) : Type(T) {}71  virtual ~InternalEvent() = default;72 73  virtual bool equals(const InternalEvent *o) const {74    assert(false && "Base class implementation");75    return false;76  };77 78  virtual std::string toString() const {79    std::string S{"InternalEvent: Type="};80    S.append(std::to_string((uint32_t)Type));81    return S;82  }83 84  /// Identifying event type85  EventTy Type;86};87 88/// Specialize EventType member for each derived internal event type.89/// Effectively selecting an event type as initialization value.90template <typename EventType> struct EventTypeOf;91 92/// Actual definition macro for EventTypeOf.93#define event_type_trait(EvTy)                                                 \94  template <> struct EventTypeOf<EvTy> {                                       \95    static constexpr EventTy Value = EventTy::EvTy;                            \96  };97 98/// CRTP (Curiously Recurring Template Pattern) intermediate class99/// Adding a new event type can be achieved by inheriting from an EventBase100/// template instantiation of the new class' name, like this:101/// struct NewEventType : public EventBase<NewEventType>102template <typename Derived> class EventBase : public InternalEvent {103public:104  static constexpr EventTy EventType = EventTypeOf<Derived>::Value;105  EventBase() : InternalEvent(EventType) {}106  virtual ~EventBase() = default;107 108  /// Equals method to cast and dispatch to the specific class operator==109  virtual bool equals(const InternalEvent *o) const override {110    // Note: When the if-condition evaluates to true, the event types are111    // trivially identical. Otherwise, a cast to the Derived pointer would have112    // been impossible.113    if (const auto Other = dynamic_cast<const Derived *>(o))114      return operator==(*static_cast<const Derived *>(this), *Other);115    return false;116  }117 118  /// Basic toString method, which may be overridden with own implementations.119  virtual std::string toString() const override {120    std::string S{"EventBase: Type="};121    S.append(std::to_string((uint32_t)Type));122    return S;123  }124};125 126} // namespace internal127 128} // namespace omptest129 130#endif131