From cbc455e643f9de39db734ed56bab61c149048cf5 Mon Sep 17 00:00:00 2001 From: Lukas Steiner Date: Wed, 23 Sep 2020 16:05:54 +0200 Subject: [PATCH] Make unused attribute compatible to all compilers. --- DRAMSys/library/CMakeLists.txt | 1 + DRAMSys/library/src/common/DebugManager.h | 8 ++++++++ .../src/configuration/TemperatureSimConfig.h | 6 +++--- DRAMSys/library/src/controller/Command.h | 2 +- DRAMSys/library/src/controller/Controller.cpp | 4 ++-- DRAMSys/library/src/controller/Controller.h | 2 +- .../src/controller/ControllerRecordable.cpp | 14 +++++++------- DRAMSys/library/src/controller/cmdmux/CmdMuxIF.h | 2 +- .../library/src/controller/cmdmux/CmdMuxOldest.cpp | 2 +- .../library/src/controller/cmdmux/CmdMuxOldest.h | 2 +- .../library/src/controller/cmdmux/CmdMuxStrict.cpp | 2 +- .../library/src/controller/cmdmux/CmdMuxStrict.h | 2 +- DRAMSys/library/src/simulation/DRAMSys.cpp | 2 +- .../src/simulation/TemperatureController.cpp | 4 ++-- .../library/src/simulation/dram/DramRecordable.cpp | 12 ++++++------ 15 files changed, 37 insertions(+), 28 deletions(-) diff --git a/DRAMSys/library/CMakeLists.txt b/DRAMSys/library/CMakeLists.txt index 67bf3d92..93f9b0b7 100644 --- a/DRAMSys/library/CMakeLists.txt +++ b/DRAMSys/library/CMakeLists.txt @@ -55,6 +55,7 @@ endif() add_subdirectory(src/common/third_party/DRAMPower) # Add nlohmann: +set(JSON_BuildTests OFF) add_subdirectory(src/common/third_party/nlohmann) # Add SystemC: diff --git a/DRAMSys/library/src/common/DebugManager.h b/DRAMSys/library/src/common/DebugManager.h index df80035d..a0a6a4e6 100644 --- a/DRAMSys/library/src/common/DebugManager.h +++ b/DRAMSys/library/src/common/DebugManager.h @@ -37,6 +37,14 @@ #ifndef DEBUGMANAGER_H #define DEBUGMANAGER_H +#if __has_cpp_attribute(maybe_unused) + #define NDEBUG_UNUSED(var_decl) [[maybe_unused]] var_decl +#elif (__GNUC__ || __clang__) + #define NDEBUG_UNUSED(var_decl) var_decl __attribute__((unused)) +#else + #define NDEBUG_UNUSED(var_decl) var_decl +#endif + #ifdef NDEBUG #define PRINTDEBUGMESSAGE(sender, message) {} #else diff --git a/DRAMSys/library/src/configuration/TemperatureSimConfig.h b/DRAMSys/library/src/configuration/TemperatureSimConfig.h index baa4bb67..b7c8431a 100644 --- a/DRAMSys/library/src/configuration/TemperatureSimConfig.h +++ b/DRAMSys/library/src/configuration/TemperatureSimConfig.h @@ -112,14 +112,14 @@ struct TemperatureSimConfig void showTemperatureSimConfig() { - int i __attribute__((unused)) = 0; - for (auto e __attribute__((unused)) : powerInitialValues) + NDEBUG_UNUSED(int i) = 0; + for (NDEBUG_UNUSED(auto e) : powerInitialValues) { PRINTDEBUGMESSAGE("TemperatureSimConfig", "powerInitialValues[" + std::to_string(i++) + "]: " + std::to_string(e)); } i = 0; - for (auto e __attribute__((unused)) : powerThresholds) + for (NDEBUG_UNUSED(auto e) : powerThresholds) { PRINTDEBUGMESSAGE("TemperatureSimConfig", "powerThreshold[" + std::to_string(i++) + "]: " + std::to_string(e)); diff --git a/DRAMSys/library/src/controller/Command.h b/DRAMSys/library/src/controller/Command.h index 70d6ea9d..d058ab63 100644 --- a/DRAMSys/library/src/controller/Command.h +++ b/DRAMSys/library/src/controller/Command.h @@ -115,6 +115,6 @@ struct CommandTuple }; }; -using readyCommands_t = std::vector; +using ReadyCommands = std::vector; #endif // COMMAND_H diff --git a/DRAMSys/library/src/controller/Controller.cpp b/DRAMSys/library/src/controller/Controller.cpp index 789a7a13..735ba8ec 100644 --- a/DRAMSys/library/src/controller/Controller.cpp +++ b/DRAMSys/library/src/controller/Controller.cpp @@ -373,7 +373,7 @@ unsigned int Controller::transport_dbg(tlm_generic_payload &trans) void Controller::finishBeginReq() { - uint64_t id __attribute__((unused)) = DramExtension::getPayloadID(payloadToAcquire); + NDEBUG_UNUSED(uint64_t id) = DramExtension::getPayloadID(payloadToAcquire); PRINTDEBUGMESSAGE(name(), "Payload " + std::to_string(id) + " entered system."); if (totalNumberOfPayloads == 0) @@ -419,7 +419,7 @@ void Controller::startBeginResp() void Controller::finishEndResp() { - uint64_t id __attribute__((unused)) = DramExtension::getPayloadID(payloadToRelease); + NDEBUG_UNUSED(uint64_t id) = DramExtension::getPayloadID(payloadToRelease); PRINTDEBUGMESSAGE(name(), "Payload " + std::to_string(id) + " left system."); payloadToRelease->release(); diff --git a/DRAMSys/library/src/controller/Controller.h b/DRAMSys/library/src/controller/Controller.h index 1d934214..9002c007 100644 --- a/DRAMSys/library/src/controller/Controller.h +++ b/DRAMSys/library/src/controller/Controller.h @@ -75,7 +75,7 @@ protected: private: unsigned totalNumberOfPayloads = 0; std::vector ranksNumberOfPayloads; - readyCommands_t readyCommands; + ReadyCommands readyCommands; MemSpec *memSpec; diff --git a/DRAMSys/library/src/controller/ControllerRecordable.cpp b/DRAMSys/library/src/controller/ControllerRecordable.cpp index 5cf82735..8ca3f8c2 100644 --- a/DRAMSys/library/src/controller/ControllerRecordable.cpp +++ b/DRAMSys/library/src/controller/ControllerRecordable.cpp @@ -72,13 +72,13 @@ void ControllerRecordable::recordPhase(tlm_generic_payload &trans, tlm_phase pha { sc_time recTime = delay + sc_time_stamp(); - unsigned int thr __attribute__((unused)) = DramExtension::getExtension(trans).getThread().ID(); - unsigned int ch __attribute__((unused)) = DramExtension::getExtension(trans).getChannel().ID(); - unsigned int bg __attribute__((unused)) = DramExtension::getExtension(trans).getBankGroup().ID(); - unsigned int bank __attribute__((unused)) = DramExtension::getExtension(trans).getBank().ID(); - unsigned int row __attribute__((unused)) = DramExtension::getExtension(trans).getRow().ID(); - unsigned int col __attribute__((unused)) = DramExtension::getExtension(trans).getColumn().ID(); - uint64_t id __attribute__((unused)) = DramExtension::getExtension(trans).getPayloadID(); + NDEBUG_UNUSED(unsigned thr) = DramExtension::getExtension(trans).getThread().ID(); + NDEBUG_UNUSED(unsigned ch) = DramExtension::getExtension(trans).getChannel().ID(); + NDEBUG_UNUSED(unsigned bg) = DramExtension::getExtension(trans).getBankGroup().ID(); + NDEBUG_UNUSED(unsigned bank) = DramExtension::getExtension(trans).getBank().ID(); + NDEBUG_UNUSED(unsigned row) = DramExtension::getExtension(trans).getRow().ID(); + NDEBUG_UNUSED(unsigned col) = DramExtension::getExtension(trans).getColumn().ID(); + NDEBUG_UNUSED(uint64_t id) = DramExtension::getExtension(trans).getPayloadID(); PRINTDEBUGMESSAGE(name(), "Recording " + getPhaseName(phase) + " thread " + std::to_string(thr) + " channel " + std::to_string(ch) + " bank group " + std::to_string( diff --git a/DRAMSys/library/src/controller/cmdmux/CmdMuxIF.h b/DRAMSys/library/src/controller/cmdmux/CmdMuxIF.h index d016167b..49e0318c 100644 --- a/DRAMSys/library/src/controller/cmdmux/CmdMuxIF.h +++ b/DRAMSys/library/src/controller/cmdmux/CmdMuxIF.h @@ -45,7 +45,7 @@ class CmdMuxIF { public: virtual ~CmdMuxIF() {} - virtual CommandTuple::Type selectCommand(readyCommands_t &) = 0; + virtual CommandTuple::Type selectCommand(ReadyCommands &) = 0; }; #endif // CMDMUXIF_H diff --git a/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.cpp b/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.cpp index 0ca2b37f..8091756b 100644 --- a/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.cpp +++ b/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.cpp @@ -38,7 +38,7 @@ using namespace tlm; -CommandTuple::Type CmdMuxOldest::selectCommand(readyCommands_t &readyCommands) +CommandTuple::Type CmdMuxOldest::selectCommand(ReadyCommands &readyCommands) { readyCommands.erase(std::remove_if(readyCommands.begin(), readyCommands.end(), [](CommandTuple::Type element) { diff --git a/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.h b/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.h index fe2058ea..6b93a44e 100644 --- a/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.h +++ b/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.h @@ -40,7 +40,7 @@ class CmdMuxOldest : public CmdMuxIF { public: - CommandTuple::Type selectCommand(readyCommands_t &); + CommandTuple::Type selectCommand(ReadyCommands &); }; #endif // CMDMUXOLDEST_H diff --git a/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.cpp b/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.cpp index 0648322c..a2334a1b 100644 --- a/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.cpp +++ b/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.cpp @@ -39,7 +39,7 @@ using namespace tlm; CommandTuple::Type -CmdMuxStrict::selectCommand(readyCommands_t &readyCommands) +CmdMuxStrict::selectCommand(ReadyCommands &readyCommands) { readyCommands.erase(std::remove_if(readyCommands.begin(), readyCommands.end(), [](CommandTuple::Type element) { diff --git a/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.h b/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.h index 330f01a8..f105dcc1 100644 --- a/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.h +++ b/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.h @@ -40,7 +40,7 @@ class CmdMuxStrict : public CmdMuxIF { public: - CommandTuple::Type selectCommand(readyCommands_t &); + CommandTuple::Type selectCommand(ReadyCommands &); private: uint64_t nextPayloadID = 0; diff --git a/DRAMSys/library/src/simulation/DRAMSys.cpp b/DRAMSys/library/src/simulation/DRAMSys.cpp index fca962a1..f890734f 100644 --- a/DRAMSys/library/src/simulation/DRAMSys.cpp +++ b/DRAMSys/library/src/simulation/DRAMSys.cpp @@ -166,7 +166,7 @@ void DRAMSys::logo() #undef BOLDTXT } -void DRAMSys::setupDebugManager(const std::string &traceName __attribute__((unused))) +void DRAMSys::setupDebugManager(NDEBUG_UNUSED(const std::string &traceName)) { #ifndef NDEBUG auto &dbg = DebugManager::getInstance(); diff --git a/DRAMSys/library/src/simulation/TemperatureController.cpp b/DRAMSys/library/src/simulation/TemperatureController.cpp index f6d9b384..a350af2c 100644 --- a/DRAMSys/library/src/simulation/TemperatureController.cpp +++ b/DRAMSys/library/src/simulation/TemperatureController.cpp @@ -164,8 +164,8 @@ void TemperatureController::temperatureThread() updateTemperatures(); double p = adjustThermalSimPeriod(); - int i __attribute__((unused)) = 0; - for (auto t __attribute__((unused)) : temperatureValues) { + NDEBUG_UNUSED(int i) = 0; + for (NDEBUG_UNUSED(auto t) : temperatureValues) { PRINTDEBUGMESSAGE(name(), "Temperature[" + std::to_string(i++) + "] is " + std::to_string(t)); } diff --git a/DRAMSys/library/src/simulation/dram/DramRecordable.cpp b/DRAMSys/library/src/simulation/dram/DramRecordable.cpp index 3b9215ef..46bd709f 100644 --- a/DRAMSys/library/src/simulation/dram/DramRecordable.cpp +++ b/DRAMSys/library/src/simulation/dram/DramRecordable.cpp @@ -88,12 +88,12 @@ void DramRecordable::recordPhase(tlm_generic_payload &trans, tlm_phase if (phase == END_PDNA || phase == END_PDNP || phase == END_SREF) recTime += this->memSpec->getCommandLength(phaseToCommand(phase)); - unsigned int thr __attribute__((unused)) = DramExtension::getExtension(trans).getThread().ID(); - unsigned int ch __attribute__((unused)) = DramExtension::getExtension(trans).getChannel().ID(); - unsigned int bg __attribute__((unused)) = DramExtension::getExtension(trans).getBankGroup().ID(); - unsigned int bank __attribute__((unused)) = DramExtension::getExtension(trans).getBank().ID(); - unsigned int row __attribute__((unused)) = DramExtension::getExtension(trans).getRow().ID(); - unsigned int col __attribute__((unused)) = DramExtension::getExtension(trans).getColumn().ID(); + NDEBUG_UNUSED(unsigned thr) = DramExtension::getExtension(trans).getThread().ID(); + NDEBUG_UNUSED(unsigned ch) = DramExtension::getExtension(trans).getChannel().ID(); + NDEBUG_UNUSED(unsigned bg) = DramExtension::getExtension(trans).getBankGroup().ID(); + NDEBUG_UNUSED(unsigned bank) = DramExtension::getExtension(trans).getBank().ID(); + NDEBUG_UNUSED(unsigned row) = DramExtension::getExtension(trans).getRow().ID(); + NDEBUG_UNUSED(unsigned col) = DramExtension::getExtension(trans).getColumn().ID(); PRINTDEBUGMESSAGE(this->name(), "Recording " + getPhaseName(phase) + " thread " + std::to_string(thr) + " channel " + std::to_string(ch) + " bank group " + std::to_string(