2018-07-23 00:54:28 +00:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
//*************************************************************************
|
|
|
|
// DESCRIPTION: Verilator: Threading's logic to mtask partitioner
|
|
|
|
//
|
2019-11-08 03:33:59 +00:00
|
|
|
// Code available from: https://verilator.org
|
2018-07-23 00:54:28 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2021-01-01 15:29:54 +00:00
|
|
|
// Copyright 2003-2021 by Wilson Snyder. This program is free software; you
|
2020-03-21 15:24:24 +00:00
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2018-07-23 00:54:28 +00:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
// Version 2.0.
|
2020-03-21 15:24:24 +00:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2018-07-23 00:54:28 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
2019-10-05 00:17:11 +00:00
|
|
|
|
2021-03-04 02:57:07 +00:00
|
|
|
#ifndef VERILATOR_V3PARTITION_H_
|
|
|
|
#define VERILATOR_V3PARTITION_H_
|
2018-07-23 00:54:28 +00:00
|
|
|
|
|
|
|
#include "config_build.h"
|
|
|
|
#include "verilatedos.h"
|
|
|
|
|
|
|
|
#include "V3Graph.h"
|
|
|
|
#include "V3OrderGraph.h"
|
|
|
|
|
2018-10-14 17:43:24 +00:00
|
|
|
#include <list>
|
|
|
|
|
2018-07-23 00:54:28 +00:00
|
|
|
class LogicMTask;
|
2021-03-12 23:10:45 +00:00
|
|
|
using Vx2MTaskMap = std::unordered_map<const MTaskMoveVertex*, LogicMTask*>;
|
2018-07-23 00:54:28 +00:00
|
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
/// V3Partition takes the fine-grained logic graph from V3Order and
|
|
|
|
/// collapses it into a coarse-grained graph of AbstractLogicMTask's, each
|
|
|
|
/// of which contains of set of the logic nodes from the fine-grained
|
|
|
|
/// graph.
|
|
|
|
|
2020-11-19 02:32:16 +00:00
|
|
|
class V3Partition final {
|
2018-07-23 00:54:28 +00:00
|
|
|
// MEMBERS
|
|
|
|
V3Graph* m_fineDepsGraphp; // Fine-grained dependency graph
|
|
|
|
public:
|
|
|
|
// CONSTRUCTORS
|
|
|
|
explicit V3Partition(V3Graph* fineDepsGraphp)
|
2020-08-16 13:55:36 +00:00
|
|
|
: m_fineDepsGraphp{fineDepsGraphp} {}
|
2020-11-17 00:56:16 +00:00
|
|
|
~V3Partition() = default;
|
2018-07-23 00:54:28 +00:00
|
|
|
|
|
|
|
// METHODS
|
|
|
|
|
|
|
|
// Fill in the provided empty graph with AbstractLogicMTask's and their
|
|
|
|
// interdependencies.
|
|
|
|
void go(V3Graph* mtasksp);
|
|
|
|
|
|
|
|
static void selfTest();
|
2021-09-27 02:51:11 +00:00
|
|
|
static void selfTestNormalizeCosts();
|
2018-07-23 00:54:28 +00:00
|
|
|
|
|
|
|
// Print out a hash of the shape of graphp. Only needed to debug the
|
|
|
|
// origin of some nondeterminism; otherwise this is pretty useless.
|
|
|
|
static void hashGraphDebug(const V3Graph* graphp, const char* debugName);
|
|
|
|
|
|
|
|
// Print debug stats about graphp whose nodes must be AbstractMTask's.
|
2018-10-14 22:39:33 +00:00
|
|
|
static void debugMTaskGraphStats(const V3Graph* graphp, const string& stage);
|
2018-07-23 00:54:28 +00:00
|
|
|
|
|
|
|
// Operate on the final ExecMTask graph, immediately prior to code
|
|
|
|
// generation time.
|
|
|
|
static void finalize();
|
2020-04-14 02:51:35 +00:00
|
|
|
|
2018-07-23 00:54:28 +00:00
|
|
|
private:
|
|
|
|
static void setupMTaskDeps(V3Graph* mtasksp, const Vx2MTaskMap* vx2mtaskp);
|
|
|
|
|
|
|
|
VL_DEBUG_FUNC; // Declare debug()
|
|
|
|
VL_UNCOPYABLE(V3Partition);
|
|
|
|
};
|
|
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
// Map a pointer into a id, for e.g. nodep to mtask mappings
|
|
|
|
|
2020-11-19 02:32:16 +00:00
|
|
|
class PartPtrIdMap final {
|
2018-07-23 00:54:28 +00:00
|
|
|
private:
|
|
|
|
// TYPES
|
|
|
|
// MEMBERS
|
2020-08-15 17:11:27 +00:00
|
|
|
mutable vluint64_t m_nextId = 0;
|
2021-03-12 22:26:53 +00:00
|
|
|
mutable std::unordered_map<const void*, vluint64_t> m_id;
|
2020-04-14 02:51:35 +00:00
|
|
|
|
2018-07-23 00:54:28 +00:00
|
|
|
public:
|
|
|
|
// CONSTRUCTORS
|
2020-11-17 00:56:16 +00:00
|
|
|
PartPtrIdMap() = default;
|
2018-07-23 00:54:28 +00:00
|
|
|
// METHODS
|
|
|
|
vluint64_t findId(const void* ptrp) const {
|
2020-08-16 15:43:49 +00:00
|
|
|
const auto it = m_id.find(ptrp);
|
2020-03-15 22:34:09 +00:00
|
|
|
if (it != m_id.end()) return it->second;
|
2018-07-23 00:54:28 +00:00
|
|
|
m_id[ptrp] = m_nextId;
|
|
|
|
return m_nextId++;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // Guard
|