/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
#ifndef TVM_S_TIR_META_SCHEDULE_EXTRACTED_TASK_H_
#define TVM_S_TIR_META_SCHEDULE_EXTRACTED_TASK_H_

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/ffi/string.h>
#include <tvm/ir/module.h>
#include <tvm/target/target.h>

namespace tvm {
namespace tirx {
class PrimFunc;
}  // namespace tirx
namespace te {
class Tensor;
}  // namespace te
}  // namespace tvm

namespace tvm {
namespace s_tir {
namespace meta_schedule {

/*! \brief A tuning task extracted from the high-level IR */
class ExtractedTaskNode : public ffi::Object {
 public:
  /*! \brief The name of the task extracted */
  ffi::String task_name;
  /*! \brief The high-level IR */
  IRModule mod;
  /*! \brief Target */
  Target target;
  /*! \brief A list of low-level IRs that the high-level IR could potentially dispatch to */
  ffi::Array<IRModule> dispatched;
  /*! \brief Weight of the task */
  int weight;

  static void RegisterReflection() {
    namespace refl = tvm::ffi::reflection;
    refl::ObjectDef<ExtractedTaskNode>()
        .def_ro("task_name", &ExtractedTaskNode::task_name)
        .def_ro("mod", &ExtractedTaskNode::mod)
        .def_ro("target", &ExtractedTaskNode::target)
        .def_ro("dispatched", &ExtractedTaskNode::dispatched)
        .def_ro("weight", &ExtractedTaskNode::weight);
  }

  static constexpr const bool _type_mutable = true;
  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.ExtractedTask", ExtractedTaskNode,
                                    ffi::Object);
};

/*!
 * \brief Managed reference to ExtractedTaskNode
 * \sa ExtractedTaskNode
 */
class ExtractedTask : public ffi::ObjectRef {
 public:
  explicit ExtractedTask(ffi::String task_name, IRModule mod, Target target,
                         ffi::Array<IRModule> dispatched, int weight);
  TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ExtractedTask, ffi::ObjectRef, ExtractedTaskNode);
};

}  // namespace meta_schedule
}  // namespace s_tir
}  // namespace tvm

#endif  // TVM_S_TIR_META_SCHEDULE_EXTRACTED_TASK_H_
