Skip to content

Commit

Permalink
Changed some rules; new formatting run
Browse files Browse the repository at this point in the history
  • Loading branch information
Knute Lingaard authored and Knute Lingaard committed Oct 17, 2023
1 parent ac2f8ad commit a3284b0
Show file tree
Hide file tree
Showing 57 changed files with 2,100 additions and 1,979 deletions.
9 changes: 6 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: BlockIndent
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
Expand Down Expand Up @@ -47,7 +47,10 @@ BraceWrapping:
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: All

# To enable in format-16
# BreakArrays: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Allman
BreakBeforeInheritanceComma: false
Expand All @@ -70,7 +73,7 @@ DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
PackConstructorInitializers: BinPack
PackConstructorInitializers: CurrentLine
BasedOnStyle: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
AllowAllConstructorInitializersOnNextLine: true
Expand Down
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ if(NOT CLANGFORMAT_EXECUTABLE)
set(CLANGFORMAT_EXECUTABLE clang-format)
endif()


set(CLANGFORMAT_SOURCES "$<TARGET_PROPERTY:olympia,SOURCES>")
string(REPLACE ";" " " ${CLANGFORMAT_SOURCES} CLANGFORMAT_SOURCES)

#
# CPUTopology is pretty clean as it is. There's an option to NOT
# collapse the array of structures in clang-format v16, but we're not
# there yet
add_custom_target(olympia_clangformat
find core mss -name "*.[hc]pp" > clang-format-files.out
find core mss -name "*.[hc]pp" | grep -v CPUTopology.cpp > clang-format-files.out
COMMAND
${CLANGFORMAT_EXECUTABLE} -i --files=clang-format-files.out
WORKING_DIRECTORY
Expand Down
4 changes: 2 additions & 2 deletions core/CPU.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// <CPU.cpp> -*- C++ -*-


#include "CPU.hpp"

//! \brief Name of this resource. Required by sparta::UnitFactory
Expand All @@ -9,7 +8,8 @@ constexpr char olympia::CPU::name[];
//! \brief Constructor of this CPU Unit
olympia::CPU::CPU(sparta::TreeNode* node, const olympia::CPU::CPUParameterSet* params) :
sparta::Unit{node}
{}
{
}

//! \brief Destructor of this CPU Unit
olympia::CPU::~CPU() = default;
59 changes: 30 additions & 29 deletions core/CPU.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// <CPU.h> -*- C++ -*-


#pragma once

#include <string>
Expand All @@ -9,34 +8,36 @@
#include "sparta/simulation/TreeNode.hpp"
#include "sparta/simulation/ParameterSet.hpp"

namespace olympia{

/**
* @file CPU.h
* @brief CPU Unit acts as a logical unit containing multiple cores
*/
class CPU : public sparta::Unit{
public:

//! \brief Parameters for CPU model
class CPUParameterSet : public sparta::ParameterSet{
public:
CPUParameterSet(sparta::TreeNode* n) : sparta::ParameterSet(n){}
};

//! \brief Name of this resource. Required by sparta::UnitFactory
static constexpr char name[] = "cpu";
namespace olympia
{

/**
* @brief Constructor for CPU
*
* @param node The node that represents (has a pointer to) the CPU
* @param p The CPU's parameter set
* @file CPU.h
* @brief CPU Unit acts as a logical unit containing multiple cores
*/
CPU(sparta::TreeNode* node, const CPUParameterSet* params);

//! \brief Destructor of the CPU Unit
~CPU();

}; // class CPU
} // namespace olympia
class CPU : public sparta::Unit
{
public:
//! \brief Parameters for CPU model
class CPUParameterSet : public sparta::ParameterSet
{
public:
CPUParameterSet(sparta::TreeNode* n) : sparta::ParameterSet(n) {}
};

//! \brief Name of this resource. Required by sparta::UnitFactory
static constexpr char name[] = "cpu";

/**
* @brief Constructor for CPU
*
* @param node The node that represents (has a pointer to) the CPU
* @param p The CPU's parameter set
*/
CPU(sparta::TreeNode* node, const CPUParameterSet* params);

//! \brief Destructor of the CPU Unit
~CPU();

}; // class CPU
} // namespace olympia
52 changes: 21 additions & 31 deletions core/CPUFactories.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// <CPUFactories.h> -*- C++ -*-


#pragma once

#include "sparta/simulation/ResourceFactory.hpp"
Expand All @@ -20,7 +19,8 @@
#include "Preloader.hpp"
#include "MavisUnit.hpp"

namespace olympia{
namespace olympia
{

/**
* @file CPUFactories.h
Expand All @@ -31,19 +31,17 @@ namespace olympia{
* 1. Contain resource factories to build each core of the CPU
* 2. Contain resource factories to build microarchitectural units in each core
*/
struct CPUFactories{
struct CPUFactories
{

//! \brief Resouce Factory to build a Core Unit
sparta::ResourceFactory<olympia::Core,
olympia::Core::CoreParameterSet> core_rf;
sparta::ResourceFactory<olympia::Core, olympia::Core::CoreParameterSet> core_rf;

//! \brief Resouce Factory to build a Fetch Unit
sparta::ResourceFactory<olympia::Fetch,
olympia::Fetch::FetchParameterSet> fetch_rf;
sparta::ResourceFactory<olympia::Fetch, olympia::Fetch::FetchParameterSet> fetch_rf;

//! \brief Resouce Factory to build a Decode Unit
sparta::ResourceFactory<olympia::Decode,
olympia::Decode::DecodeParameterSet> decode_rf;
sparta::ResourceFactory<olympia::Decode, olympia::Decode::DecodeParameterSet> decode_rf;

//! \brief Resouce Factory to build a Rename Unit
RenameFactory rename_rf;
Expand All @@ -52,47 +50,39 @@ namespace olympia{
DispatchFactory dispatch_rf;

//! \brief Resouce Factory to build a Execute Unit
ExecuteFactory execute_rf;

ExecuteFactory execute_rf;

//! \brief Resouce Factory to build a MMU Unit
sparta::ResourceFactory<olympia::DCache,
olympia::DCache::CacheParameterSet> dcache_rf;
sparta::ResourceFactory<olympia::DCache, olympia::DCache::CacheParameterSet> dcache_rf;

//! \brief Resouce Factory to build a TLB Unit
sparta::ResourceFactory<olympia::SimpleTLB,
olympia::SimpleTLB::TLBParameterSet> tlb_rf;
sparta::ResourceFactory<olympia::SimpleTLB, olympia::SimpleTLB::TLBParameterSet> tlb_rf;

//! \brief Resouce Factory to build a MMU Unit
sparta::ResourceFactory<olympia::MMU,
olympia::MMU::MMUParameterSet> mmu_rf;
sparta::ResourceFactory<olympia::MMU, olympia::MMU::MMUParameterSet> mmu_rf;

//! \brief Resouce Factory to build a LSU Unit
sparta::ResourceFactory<olympia::LSU,
olympia::LSU::LSUParameterSet> lsu_rf;

sparta::ResourceFactory<olympia::LSU, olympia::LSU::LSUParameterSet> lsu_rf;

//! \brief Resouce Factory to build a BIU Unit
sparta::ResourceFactory<olympia_mss::BIU,
olympia_mss::BIU::BIUParameterSet> biu_rf;
sparta::ResourceFactory<olympia_mss::BIU, olympia_mss::BIU::BIUParameterSet> biu_rf;

//! \brief Resouce Factory to build a MSS Unit
sparta::ResourceFactory<olympia_mss::MSS,
olympia_mss::MSS::MSSParameterSet> mss_rf;
sparta::ResourceFactory<olympia_mss::MSS, olympia_mss::MSS::MSSParameterSet> mss_rf;

//! \brief Resouce Factory to build a ROB Unit
sparta::ResourceFactory<olympia::ROB,
olympia::ROB::ROBParameterSet> rob_rf;
sparta::ResourceFactory<olympia::ROB, olympia::ROB::ROBParameterSet> rob_rf;

//! \brief Resouce Factory to build a Flush Unit
sparta::ResourceFactory<olympia::FlushManager,
olympia::FlushManager::FlushManagerParameters> flushmanager_rf;
olympia::FlushManager::FlushManagerParameters>
flushmanager_rf;

//! \brief Resouce Factory to build a Preloader Unit
sparta::ResourceFactory<olympia::Preloader,
olympia::Preloader::PreloaderParameterSet> preloader_rf;
sparta::ResourceFactory<olympia::Preloader, olympia::Preloader::PreloaderParameterSet>
preloader_rf;

//! \brief Set up the Mavis Decode functional unit
MavisFactoy mavis_rf;
MavisFactoy mavis_rf;
}; // struct CPUFactories
} // namespace olympia
} // namespace olympia
70 changes: 37 additions & 33 deletions core/CPUFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// <CPUFactory.cpp> -*- C++ -*-


#include "CPUFactory.hpp"
#include <string>
#include <algorithm>
Expand All @@ -9,7 +8,9 @@
* @brief Constructor for CPUFactory
*/
olympia::CPUFactory::CPUFactory() :
sparta::ResourceFactory<olympia::CPU, olympia::CPU::CPUParameterSet>(){}
sparta::ResourceFactory<olympia::CPU, olympia::CPU::CPUParameterSet>()
{
}

/**
* @brief Destructor for CPUFactory
Expand All @@ -19,8 +20,9 @@ olympia::CPUFactory::~CPUFactory() = default;
/**
* @brief Set the user-defined topology for this microarchitecture
*/
auto olympia::CPUFactory::setTopology(const std::string& topology,
const uint32_t num_cores) -> void{
auto olympia::CPUFactory::setTopology(const std::string & topology, const uint32_t num_cores)
-> void
{
sparta_assert(!topology_);
topology_ = olympia::CPUTopology::allocateTopology(topology);
topology_->setName(topology);
Expand All @@ -31,26 +33,27 @@ auto olympia::CPUFactory::setTopology(const std::string& topology,
* @brief Implemenation : Build the device tree by instantiating resource nodes
*/
auto olympia::CPUFactory::buildTree_(sparta::RootTreeNode* root_node,
const std::vector<olympia::CPUTopology::UnitInfo>& units) -> void
const std::vector<olympia::CPUTopology::UnitInfo> & units)
-> void
{
std::string parent_name, human_name, node_name, replace_with;
for(std::size_t num_of_cores = 0; num_of_cores < topology_->num_cores; ++num_of_cores){
for(const auto& unit : units){
for (std::size_t num_of_cores = 0; num_of_cores < topology_->num_cores; ++num_of_cores)
{
for (const auto & unit : units)
{
parent_name = unit.parent_name;
node_name = unit.name;
human_name = unit.human_name;
replace_with = std::to_string(num_of_cores);
std::replace(parent_name.begin(), parent_name.end(), to_replace_, *replace_with.c_str());
std::replace(parent_name.begin(), parent_name.end(), to_replace_,
*replace_with.c_str());
std::replace(node_name.begin(), node_name.end(), to_replace_, *replace_with.c_str());
std::replace(human_name.begin(), human_name.end(), to_replace_, *replace_with.c_str());
auto parent_node = root_node->getChildAs<sparta::TreeNode>(parent_name);
auto rtn = new sparta::ResourceTreeNode(parent_node,
node_name,
unit.group_name,
unit.group_id,
human_name,
unit.factory);
if(unit.is_private_subtree){
auto rtn = new sparta::ResourceTreeNode(parent_node, node_name, unit.group_name,
unit.group_id, human_name, unit.factory);
if (unit.is_private_subtree)
{
rtn->makeSubtreePrivate();
private_nodes_.emplace_back(rtn);
}
Expand All @@ -61,39 +64,42 @@ auto olympia::CPUFactory::buildTree_(sparta::RootTreeNode* root_node,
// type of the parameters defined in the CoreExtensions. If not
// defined, any unknown extensions are considered pure strings.
rtn->addExtensionFactory(olympia::CoreExtensions::name,
[&]() -> sparta::TreeNode::ExtensionsBase * {return new olympia::CoreExtensions();});
[&]() -> sparta::TreeNode::ExtensionsBase*
{ return new olympia::CoreExtensions(); });
}
}
}

/**
* @brief Implementation : Bind all the ports between different units and set TLBs and preload
*/
auto olympia::CPUFactory::bindTree_(sparta::RootTreeNode* root_node,
const std::vector<olympia::CPUTopology::PortConnectionInfo>& ports) -> void
auto olympia::CPUFactory::bindTree_(
sparta::RootTreeNode* root_node,
const std::vector<olympia::CPUTopology::PortConnectionInfo> & ports) -> void
{
std::string out_port_name, in_port_name,replace_with;
for(std::size_t num_of_cores = 0; num_of_cores < topology_->num_cores; ++num_of_cores)
std::string out_port_name, in_port_name, replace_with;
for (std::size_t num_of_cores = 0; num_of_cores < topology_->num_cores; ++num_of_cores)
{
for(const auto& port : ports)
for (const auto & port : ports)
{
out_port_name = port.output_port_name;
in_port_name = port.input_port_name;
replace_with = std::to_string(num_of_cores);
std::replace(out_port_name.begin(), out_port_name.end(), to_replace_, *replace_with.c_str());
std::replace(in_port_name.begin(), in_port_name.end(), to_replace_, *replace_with.c_str());
std::replace(out_port_name.begin(), out_port_name.end(), to_replace_,
*replace_with.c_str());
std::replace(in_port_name.begin(), in_port_name.end(), to_replace_,
*replace_with.c_str());
sparta::bind(root_node->getChildAs<sparta::Port>(out_port_name),
root_node->getChildAs<sparta::Port>(in_port_name));
}

// Set the TLBs and preload
auto core_tree_node = root_node->getChild(std::string("cpu.core") +
std::to_string(num_of_cores));
auto core_tree_node =
root_node->getChild(std::string("cpu.core") + std::to_string(num_of_cores));
sparta_assert(core_tree_node != nullptr);
(core_tree_node->getChild("mmu")->getResourceAs<olympia::MMU>())->
setTLB(*private_nodes_.at(num_of_cores)->getResourceAs<olympia::SimpleTLB>());
(core_tree_node->getChild("preloader")->getResourceAs<olympia::Preloader>())->
preload();
(core_tree_node->getChild("mmu")->getResourceAs<olympia::MMU>())
->setTLB(*private_nodes_.at(num_of_cores)->getResourceAs<olympia::SimpleTLB>());
(core_tree_node->getChild("preloader")->getResourceAs<olympia::Preloader>())->preload();
}
}

Expand All @@ -119,12 +125,10 @@ auto olympia::CPUFactory::bindTree(sparta::RootTreeNode* root_node) -> void
/**
* @brief Get the list of resources instantiated in this topology
*/
auto olympia::CPUFactory::getResourceNames() const -> const std::vector<std::string>&
auto olympia::CPUFactory::getResourceNames() const -> const std::vector<std::string> &
{
return resource_names_;
}

// Destroy internal components
void olympia::CPUFactory::deleteSubtree(sparta::ResourceTreeNode*) {
to_delete_.clear();
}
void olympia::CPUFactory::deleteSubtree(sparta::ResourceTreeNode*) { to_delete_.clear(); }
Loading

0 comments on commit a3284b0

Please sign in to comment.