Program Listing for File pass_registry.h

Return to documentation for file (include/pass_registry.h)

#ifndef MINDSPORE_LITE_INCLUDE_REGISTRY_PASS_REGISTRY_H_
#define MINDSPORE_LITE_INCLUDE_REGISTRY_PASS_REGISTRY_H_

#include <vector>
#include <string>
#include <memory>
#include "include/lite_utils.h"
#include "include/api/dual_abi_helper.h"

namespace mindspore {
namespace registry {
class PassBase;
using PassBasePtr = std::shared_ptr<PassBase>;
enum  PassPosition { POSITION_BEGIN = 0, POSITION_END = 1 };

class  PassRegistry {
 public:
  inline PassRegistry(const std::string &pass_name, const PassBasePtr &pass);

  inline PassRegistry(PassPosition position, const std::vector<std::string> &names);

  ~PassRegistry() = default;

  inline static std::vector<std::string> GetOuterScheduleTask(PassPosition position);

  inline static PassBasePtr GetPassFromStoreRoom(const std::string &pass_name);

 private:
  PassRegistry(const std::vector<char> &pass_name, const PassBasePtr &pass);
  PassRegistry(PassPosition position, const std::vector<std::vector<char>> &names);
  static std::vector<std::vector<char>> GetOuterScheduleTaskInner(PassPosition position);
  static PassBasePtr GetPassFromStoreRoom(const std::vector<char> &pass_name_char);
};

PassRegistry::PassRegistry(const std::string &pass_name, const PassBasePtr &pass)
    : PassRegistry(StringToChar(pass_name), pass) {}

PassRegistry::PassRegistry(PassPosition position, const std::vector<std::string> &names)
    : PassRegistry(position, VectorStringToChar(names)) {}

std::vector<std::string> PassRegistry::GetOuterScheduleTask(PassPosition position) {
  return VectorCharToString(GetOuterScheduleTaskInner(position));
}

PassBasePtr PassRegistry::GetPassFromStoreRoom(const std::string &pass_name) {
  return GetPassFromStoreRoom(StringToChar(pass_name));
}
#define REG_PASS(name, pass) \
  static mindspore::registry::PassRegistry g_##name##PassReg(#name, std::make_shared<pass>());

#define REG_SCHEDULED_PASS(position, names) static mindspore::registry::PassRegistry g_##position(position, names);
}  // namespace registry
}  // namespace mindspore

#endif  // MINDSPORE_LITE_INCLUDE_REGISTRY_PASS_REGISTRY_H_