/*
 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
 * Licensed 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.
 */

// Autogenerated file -- DO NOT EDIT!

#ifndef PANDA_COMPILER_EVENTS_GEN_H
#define PANDA_COMPILER_EVENTS_GEN_H

#include <fstream>

namespace ark::compiler {

class Graph;

class EventWriter {
public:
    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
    EventWriter(std::string_view className, std::string_view methodName) {
        std::copy(className.begin(), className.begin() + std::min(className.size(), BUF_SIZE - 1) + 1,
                  className_.data());
        std::copy(methodName.begin(), methodName.begin() + std::min(methodName.size(), BUF_SIZE - 1) + 1,
                  methodName_.data());
    }

    static void Init(const std::string& filePath) {
        EventWriter::events_file_.open(filePath, std::ios::out);
    }

    // NOLINTBEGIN(readability-identifier-naming)
    void EventBranchElimination(uint32_t if_block_id, uint32_t if_block_pc, uint32_t cond_inst_id, uint32_t cond_inst_pc, const char* condition_type, bool removed_edge_type) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "branch-elimination" << ',';
        events_file_ << "if_block_id" << ":" << if_block_id << "," << "if_block_pc" << ":" << if_block_pc << "," << "cond_inst_id" << ":" << cond_inst_id << "," << "cond_inst_pc" << ":" << cond_inst_pc << "," << "condition_type" << ":" << condition_type << "," << "removed_edge_type" << ":" << removed_edge_type;
        events_file_ << std::endl;
    }
    void EventCodeSink(uint32_t sunk_inst_id, uint32_t sunk_inst_pc, uint32_t from_bb_id, uint32_t to_bb_id) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "code-sink" << ',';
        events_file_ << "sunk_inst_id" << ":" << sunk_inst_id << "," << "sunk_inst_pc" << ":" << sunk_inst_pc << "," << "from_bb_id" << ":" << from_bb_id << "," << "to_bb_id" << ":" << to_bb_id;
        events_file_ << std::endl;
    }
    void EventChecksElimination(const char* name, uint32_t inst_id, uint32_t pc) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "checks-elimination" << ',';
        events_file_ << "name" << ":" << name << "," << "inst_id" << ":" << inst_id << "," << "pc" << ":" << pc;
        events_file_ << std::endl;
    }
    void EventCleanup(uint32_t removed_inst_id, uint32_t removed_inst_pc) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "cleanup" << ',';
        events_file_ << "removed_inst_id" << ":" << removed_inst_id << "," << "removed_inst_pc" << ":" << removed_inst_pc;
        events_file_ << std::endl;
    }
    void EventCse(uint32_t removed_inst_id, uint32_t removed_inst_pc) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "cse" << ',';
        events_file_ << "removed_inst_id" << ":" << removed_inst_id << "," << "removed_inst_pc" << ":" << removed_inst_pc;
        events_file_ << std::endl;
    }
    void EventDeoptimizeElimination(const char* name, uint32_t inst_id, uint32_t pc) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "deoptimize-elimination" << ',';
        events_file_ << "name" << ":" << name << "," << "inst_id" << ":" << inst_id << "," << "pc" << ":" << pc;
        events_file_ << std::endl;
    }
    void EventSaveStateOptimization(const char* name, uint32_t inst_id, uint32_t pc) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "save-state-optimization" << ',';
        events_file_ << "name" << ":" << name << "," << "inst_id" << ":" << inst_id << "," << "pc" << ":" << pc;
        events_file_ << std::endl;
    }
    void EventIfConversion(uint32_t merge_block_id, uint32_t merge_block_pc, const char* merge_type, int32_t removed_block_id1, int32_t removed_block_id2, int32_t removed_block_id3) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "if-conversion" << ',';
        events_file_ << "merge_block_id" << ":" << merge_block_id << "," << "merge_block_pc" << ":" << merge_block_pc << "," << "merge_type" << ":" << merge_type << "," << "removed_block_id1" << ":" << removed_block_id1 << "," << "removed_block_id2" << ":" << removed_block_id2 << "," << "removed_block_id3" << ":" << removed_block_id3;
        events_file_ << std::endl;
    }
    void EventInlining(const char* inlined_method) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "inlining" << ',';
        events_file_ << "inlined_method" << ":" << inlined_method;
        events_file_ << std::endl;
    }
    void EventLse(uint32_t removed_inst_id, uint32_t removed_inst_pc, uint32_t dominant_inst_id, uint32_t dominant_inst_pc, const char* code) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "lse" << ',';
        events_file_ << "removed_inst_id" << ":" << removed_inst_id << "," << "removed_inst_pc" << ":" << removed_inst_pc << "," << "dominant_inst_id" << ":" << dominant_inst_id << "," << "dominant_inst_pc" << ":" << dominant_inst_pc << "," << "code" << ":" << code;
        events_file_ << std::endl;
    }
    void EventRedundantLoopElimination(uint32_t loop_id, uint32_t loop_head_pc) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "redundant-loop-elimination" << ',';
        events_file_ << "loop_id" << ":" << loop_id << "," << "loop_head_pc" << ":" << loop_head_pc;
        events_file_ << std::endl;
    }
    void EventLoopUnroll(uint32_t loop_id, uint32_t loop_head_pc, uint32_t unroll_factor, uint32_t cloneable_inst_count, const char* unroll_type) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "loop-unroll" << ',';
        events_file_ << "loop_id" << ":" << loop_id << "," << "loop_head_pc" << ":" << loop_head_pc << "," << "unroll_factor" << ":" << unroll_factor << "," << "cloneable_inst_count" << ":" << cloneable_inst_count << "," << "unroll_type" << ":" << unroll_type;
        events_file_ << std::endl;
    }
    void EventLoopPeeling(uint32_t loop_id, uint32_t loop_head_pc, uint32_t loop_exit_pc, uint32_t moved_inst_count) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "loop-peeling" << ',';
        events_file_ << "loop_id" << ":" << loop_id << "," << "loop_head_pc" << ":" << loop_head_pc << "," << "loop_exit_pc" << ":" << loop_exit_pc << "," << "moved_inst_count" << ":" << moved_inst_count;
        events_file_ << std::endl;
    }
    void EventMemoryCoalescing(uint32_t first_inst_id, uint32_t first_inst_pc, uint32_t second_inst_id, uint32_t second_inst_pc, uint32_t new_inst_id, const char * type) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "memory-coalescing" << ',';
        events_file_ << "first_inst_id" << ":" << first_inst_id << "," << "first_inst_pc" << ":" << first_inst_pc << "," << "second_inst_id" << ":" << second_inst_id << "," << "second_inst_pc" << ":" << second_inst_pc << "," << "new_inst_id" << ":" << new_inst_id << "," << "type" << ":" << type;
        events_file_ << std::endl;
    }
    void EventPeephole(const char* name, uint32_t inst_id, uint32_t pc) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "peephole" << ',';
        events_file_ << "name" << ":" << name << "," << "inst_id" << ":" << inst_id << "," << "pc" << ":" << pc;
        events_file_ << std::endl;
    }
    void EventScheduler(uint32_t block_id, uint32_t block_pc, uint32_t old_cycles, uint32_t num_barriers, uint32_t critical_path, uint32_t new_cycles) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "scheduler" << ',';
        events_file_ << "block_id" << ":" << block_id << "," << "block_pc" << ":" << block_pc << "," << "old_cycles" << ":" << old_cycles << "," << "num_barriers" << ":" << num_barriers << "," << "critical_path" << ":" << critical_path << "," << "new_cycles" << ":" << new_cycles;
        events_file_ << std::endl;
    }
    void EventGvn(uint32_t inst_id, uint32_t inst_pc, uint32_t equal_inst_id, uint32_t equal_inst_pc) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "gvn" << ',';
        events_file_ << "inst_id" << ":" << inst_id << "," << "inst_pc" << ":" << inst_pc << "," << "equal_inst_id" << ":" << equal_inst_id << "," << "equal_inst_pc" << ":" << equal_inst_pc;
        events_file_ << std::endl;
    }
    void EventLicm(uint32_t inst_id, uint32_t inst_pc, uint32_t old_loop_id, uint32_t new_loop_id) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "licm" << ',';
        events_file_ << "inst_id" << ":" << inst_id << "," << "inst_pc" << ":" << inst_pc << "," << "old_loop_id" << ":" << old_loop_id << "," << "new_loop_id" << ":" << new_loop_id;
        events_file_ << std::endl;
    }
    void EventLowering(const char* name, uint32_t inst_id, uint32_t pc) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "lowering" << ',';
        events_file_ << "name" << ":" << name << "," << "inst_id" << ":" << inst_id << "," << "pc" << ":" << pc;
        events_file_ << std::endl;
    }
    void EventRegAlloc(uint32_t sf_inst_id, const char* sf_purpose, const char* sf_type, uint32_t src, uint32_t dst, const char* reg_type) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "reg-alloc" << ',';
        events_file_ << "sf_inst_id" << ":" << sf_inst_id << "," << "sf_purpose" << ":" << sf_purpose << "," << "sf_type" << ":" << sf_type << "," << "src" << ":" << src << "," << "dst" << ":" << dst << "," << "reg_type" << ":" << reg_type;
        events_file_ << std::endl;
    }
    // NOLINTEND(readability-identifier-naming)

public:
    // TODO (a.popov) synchronize object in multithreaded mode
    // NOLINTNEXTLINE(cert-err58-cpp,fuchsia-statically-constructed-objects,readability-identifier-naming)
    static inline std::ofstream events_file_;

private:
    static constexpr size_t BUF_SIZE = 512;
    std::array<char, BUF_SIZE> className_;
    std::array<char, BUF_SIZE> methodName_;
};

}  // namespace ark::compiler

#endif  // PANDA_COMPILER_EVENTS_GEN_H
