Skip to content

Commit

Permalink
Merge pull request #582 from sstsimulator/devel
Browse files Browse the repository at this point in the history
Automatically Merged using SST Master Branch Merger
  • Loading branch information
sst-autotester authored Oct 10, 2020
2 parents b2b8438 + 39eaf74 commit dd87374
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 39 deletions.
21 changes: 5 additions & 16 deletions bin/clang/astConsumers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,13 @@ SkeletonASTConsumer::HandleTopLevelDecl(DeclGroupRef DR)
{
for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b){
Decl* d = *b;
switch(d->getKind()){
case Decl::Function: {
FunctionDecl* fd = cast<FunctionDecl>(d);
//the function decl will have its body filled in later
//possibly - we need to make sure to only add the function once
if (fd->isThisDeclarationADefinition()){
//also, we only really care about the definition anyway
allTopLevelDecls_.push_back(d);
}
if (isNullWhitelisted(fd->getNameAsString())){
CompilerGlobals::astNodeMetadata.nullSafeFunctions[fd] = nullptr;
}
if (d->getKind() == Decl::Function){
FunctionDecl* fd = cast<FunctionDecl>(d);
if (isNullWhitelisted(fd->getNameAsString())){
CompilerGlobals::astNodeMetadata.nullSafeFunctions[fd] = nullptr;
}
break;
default:
allTopLevelDecls_.push_back(d);
break;
}
allTopLevelDecls_.push_back(d);
}
return true;
}
Expand Down
26 changes: 16 additions & 10 deletions bin/clang/astVisitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,9 @@ SkeletonASTVisitor::TraverseCallExpr(CallExpr* expr, DataRecursionQueue* /*queu
PragmaActivateGuard pag(expr, this);
if (pag.skipVisit()) return true;

//first go into the call expression to see if we should even keep it
//we might get a delete exception, in which case we should skip traversal
//if we got here, we are safe to modify the function name
if (CompilerGlobals::modeActive(SKELETONIZE | SHADOWIZE)) {
Expr* fxn = getUnderlyingExpr(const_cast<Expr*>(expr->getCallee()));
if (fxn->getStmtClass() == Stmt::DeclRefExprClass){
Expand Down Expand Up @@ -1939,6 +1942,9 @@ SkeletonASTVisitor::traverseFunctionBody(clang::Stmt* s)
bool
SkeletonASTVisitor::TraverseFunctionDecl(clang::FunctionDecl* D)
{
if (!D->isThisDeclarationADefinition()){
return true;
}
if (D->isMain() && CompilerGlobals::refactorMain){
replaceMain(D);
} else if (D->isTemplateInstantiation()
Expand Down Expand Up @@ -2399,7 +2405,6 @@ SkeletonASTVisitor::TraverseArraySubscriptExpr(ArraySubscriptExpr* expr, DataRec
PushGuard<Expr*> pg(activeDerefs_, expr);
TraverseStmt(expr->getBase());
TraverseStmt(expr->getIdx());

return true;
}

Expand Down Expand Up @@ -2443,7 +2448,7 @@ SkeletonASTVisitor::TraverseDecl(Decl *D)
PragmaActivateGuard pag(D, this);
if (pag.skipVisit()) return true;

RecursiveASTVisitor<SkeletonASTVisitor>::TraverseDecl(D);
return RecursiveASTVisitor<SkeletonASTVisitor>::TraverseDecl(D);
} catch (DeclDeleteException& e) {
if (e.deleted != D) throw e;
}
Expand All @@ -2461,10 +2466,8 @@ void
PragmaActivateGuard::deletePragmaText(SSTPragma *prg)
{
//eliminate the pragma text
if (prg->depth == 0){
SourceRange rng(prg->pragmaDirectiveLoc, prg->endPragmaLoc);
::replace(rng, "");
}
SourceRange rng(prg->pragmaDirectiveLoc, prg->endPragmaLoc);
::replace(rng, "");
}

void
Expand Down Expand Up @@ -2699,16 +2702,19 @@ bool
FirstPassASTVisitor::TraverseFunctionDecl(FunctionDecl *fd, DataRecursionQueue* /*queue*/)
{
PushGuard<FunctionDecl*> pg(CompilerGlobals::astContextLists.enclosingFunctionDecls, fd);
Parent::TraverseFunctionDecl(fd);
return true;
PragmaActivateGuard pag(fd, this, true/*always do first pass pragmas*/);
if (fd->isThisDeclarationADefinition()){
return Parent::TraverseFunctionDecl(fd);
} else {
return true;
}
}

bool
FirstPassASTVisitor::TraverseCompoundStmt(CompoundStmt* cs, DataRecursionQueue* /*queue*/)
{
PushGuard<CompoundStmt*> pg(CompilerGlobals::astContextLists.compoundStmtBlocks, cs);
Parent::TraverseCompoundStmt(cs);
return true;
return Parent::TraverseCompoundStmt(cs);
}

FirstPassASTVisitor::FirstPassASTVisitor(SSTPragmaList& prgs) :
Expand Down
4 changes: 3 additions & 1 deletion bin/clang/pragmas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ static void tokenToString(const Token& tok, std::ostream& os)
case tok::kw_true:
os << "true";
break;
case tok::kw_void:
os << "void";
break;
case tok::kw_false:
os << "false";
break;
Expand Down Expand Up @@ -265,7 +268,6 @@ SSTPragmaHandler::configure(bool delOnUse, Token& /*PragmaTok*/, Preprocessor&
maxPragmaDepth = 0;
}
--pragmaDepth;
fsp->depth = pragmaDepth;
}

void
Expand Down
1 change: 0 additions & 1 deletion bin/clang/pragmas.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ struct SSTPragma {
clang::SourceLocation startPragmaLoc;
clang::SourceLocation endPragmaLoc;
clang::SourceLocation targetLoc;
int depth;
bool deleteOnUse;
std::uintptr_t classId;

Expand Down
50 changes: 43 additions & 7 deletions sstmac/hardware/pisces/pisces_arbitrator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,31 @@ Questions? Contact [email protected]
#define one_indent " "
#define two_indent " "

#if 0
#if PISCES_DEBUG_INDIVIDUAL_HISTORY
#define dprintf(flag, ...) \
history_.push_back(sprockit::sprintf(__VA_ARGS__))
#else
#define dprintf(flag, ...) debug_printf(flag, __VA_ARGS__)
#endif

#if PISCES_DETAILED_DEBUG
#define pflow_arb_debug_printf_l0(format_str, ...) \
debug_printf(sprockit::dbg::pisces, \
dprintf(sprockit::dbg::pisces, \
" [arbitrator] " format_str , \
__VA_ARGS__)

#define pflow_arb_debug_printf_l1(format_str, ...) \
debug_printf(sprockit::dbg::pisces, \
dprintf(sprockit::dbg::pisces, \
one_indent " [arbitrator] " format_str , \
__VA_ARGS__)

#define pflow_arb_debug_printf_l2(format_str, ...) \
debug_printf(sprockit::dbg::pisces, \
dprintf(sprockit::dbg::pisces, \
two_indent " [arbitrator] " format_str , \
__VA_ARGS__)

#define pflow_arb_debug_print_l2(format_str) \
debug_printf(sprockit::dbg::pisces, \
dprintf(sprockit::dbg::pisces, \
two_indent " [arbitrator] " format_str "%s", "")
#else
#define pflow_arb_debug_printf_l0(format_str, ...)
Expand Down Expand Up @@ -188,6 +195,10 @@ PiscesCutThroughArbitrator::clearOut(Timestamp now)
cut_through_epoch_debug("clearing at %9.5e", now.sec());
Timestamp end = epoch->start + epoch->numCycles * cycleLength_;
if (now <= epoch->start){
if (!epoch->next){
//this is the last epoch, restore it to full size
epoch->numCycles = std::numeric_limits<uint32_t>::max();
}
return;
} else if (now < end){
if (epoch->next){
Expand All @@ -205,6 +216,16 @@ PiscesCutThroughArbitrator::clearOut(Timestamp now)
Epoch* next = epoch->next;
delete epoch;
head_ = next;
#if SSTMAC_SANITY_CHECK
if (head_ == nullptr){
#if PISCES_DEBUG_INDIVIDUAL_HISTORY
for (auto& str : history_){
std::cerr << str << std::endl;
}
#endif
spkt_abort_printf("internal error: head epoch is null in PiscesCutThroughArbitrator");
}
#endif
epoch = next;
} else {
//this is the last epoch - restore it to "full size"
Expand All @@ -223,6 +244,16 @@ PiscesCutThroughArbitrator::advance(Epoch* epoch, Epoch* prev)
if (prev) prev->next = epoch->next;
else head_ = next;
delete epoch;
#if SSTMAC_SANITY_CHECK
if (head_ == nullptr){
#if PISCES_DEBUG_INDIVIDUAL_HISTORY
for (auto& str : history_){
std::cerr << str << std::endl;
}
#endif
spkt_abort_printf("internal error: head epoch is null in PiscesCutThroughArbitrator");
}
#endif
return next;
}

Expand All @@ -232,7 +263,7 @@ PiscesCutThroughArbitrator::arbitrate(IncomingPacket &st)
pflow_arb_debug_printf_l0("Cut-through: arbitrator %p starting packet %p:%llu of size %u with byte_delay=%9.5e epoch_delay=%9.5e start=%9.5e: %s",
this, st.pkt, st.pkt->flowId(), st.pkt->numBytes(), st.pkt->byteDelay().sec(),
byteDelay_.sec(), st.now.sec(),
(st.pkt->orig() ? sprockit::toString(st.pkt->orig()).c_str() : "null payload"));
(st.pkt->flow() ? sprockit::toString(st.pkt->flow()).c_str() : "null payload"));

#define PRINT_EPOCHS 0
#if PRINT_EPOCHS
Expand All @@ -257,6 +288,11 @@ PiscesCutThroughArbitrator::arbitrate(IncomingPacket &st)
while (bytesLeft > 2){ //we often end up with 1,2 byte stragglers - ignore them for efficiency
#if SSTMAC_SANITY_CHECK
if (!epoch){
#if PISCES_DEBUG_INDIVIDUAL_HISTORY
for (auto& str : history_){
std::cerr << str << std::endl;
}
#endif
spkt_abort_printf("ran out of epochs on arbitrator %p: this should not be possible", this);
}
#endif
Expand All @@ -265,7 +301,7 @@ PiscesCutThroughArbitrator::arbitrate(IncomingPacket &st)
if (st.pkt->byteDelay() <= cycleLength_){
//every cycle gets used, arriving faster than leaving
if (epoch->numCycles <= bytesLeft){
cut_through_arb_debug_noargs("used all cycles")
cut_through_arb_debug_noargs("used all cycles");
//epoch is completely busy
bytesSent += epoch->numCycles;
bytesLeft -= epoch->numCycles;
Expand Down
6 changes: 6 additions & 0 deletions sstmac/hardware/pisces/pisces_arbitrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ Questions? Contact [email protected]
#include <sprockit/factory.h>
#include <sstmac/hardware/noise/noise.h>

#define PISCES_DEBUG_INDIVIDUAL_HISTORY 0
#define PISCES_DETAILED_DEBUG 0

namespace sstmac {
namespace hw {

Expand Down Expand Up @@ -99,6 +102,9 @@ class PiscesBandwidthArbitrator

protected:
TimeDelta byteDelay_;
#if PISCES_DEBUG_INDIVIDUAL_HISTORY
std::vector<std::string> history_;
#endif

};

Expand Down
4 changes: 0 additions & 4 deletions sstmac/replacements/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,10 @@ extern "C" {
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#endif

#if defined(__clang__) // Only include S2S things if clang
#pragma sst null_ptr safe
#endif
void* sstmac_memset(void* ptr, int value, unsigned long sz);

#if defined(__clang__) // Only include S2S things if clang
#pragma sst null_ptr safe
#endif
void* sstmac_memcpy(void* dst, const void* src, unsigned long sz);

#if defined(__clang__) // Add back the warnings
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile.clang_tests
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ CLANGTESTS = \
pragma_sst_scoped_replace_cpp \
pragma_sst_replace_cpp \
pragma_sst_memory_cpp \
pragma_sst_multi_pragma_cpp \
pragma_sst_compute_cpp \
pragma_sst_compute_global_var_cpp \
pragma_sst_loop_count_cpp \
Expand Down
68 changes: 68 additions & 0 deletions tests/clang_src2src/pragma_sst_multi_pragma.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
Copyright 2009-2020 National Technology and Engineering Solutions of Sandia,
LLC (NTESS). Under the terms of Contract DE-NA-0003525, the U.S. Government
retains certain rights in this software.
Sandia National Laboratories is a multimission laboratory managed and operated
by National Technology and Engineering Solutions of Sandia, LLC., a wholly
owned subsidiary of Honeywell International, Inc., for the U.S. Department of
Energy's National Nuclear Security Administration under contract DE-NA0003525.
Copyright (c) 2009-2020, NTESS
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Questions? Contact [email protected]
*/

int fxn()
{
int i=0;
int mul = 0;
double* x = new double[10];
int* idx = new int[5];
#pragma sst memory 10
#pragma sst compute
for (i=0; i < 5; ++i){
mul *= i;
for (int j=0; j < 10; ++j){
mul += (j-1);
x[j] += i;
mul -= x[j];
j=7;
mul += x[j];
mul *= x[idx[i]];
idx[i] -= 3;
mul *= x[idx[i]];
}
}
return 0;
}

1 change: 1 addition & 0 deletions tests/reference/test_clang_pragma_sst_memory_cpp.ref-out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ int fxn()
double* x = new double[10];
int* idx = new int[5];


{ uint64_t flops=0; uint64_t readBytes=0; uint64_t writeBytes=0; uint64_t intops=0; { uint64_t tripCount0=(((5)-(0))); intops += tripCount0*1;{ uint64_t tripCount1=tripCount0*(((10)-(0))); flops += tripCount1*1; readBytes += tripCount1*36; writeBytes += tripCount1*12; intops += tripCount1*16;}}readBytes=1000;sstmac_compute_detailed(flops,intops,readBytes); }


Expand Down
26 changes: 26 additions & 0 deletions tests/reference/test_clang_pragma_sst_multi_pragma_cpp.ref-out
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
int fxn()
{
int i=0;
int mul = 0;
double* x = new double[10];
int* idx = new int[5];


{ uint64_t flops=0; uint64_t readBytes=0; uint64_t writeBytes=0; uint64_t intops=0; { uint64_t tripCount0=(((5)-(0))); intops += tripCount0*1;{ uint64_t tripCount1=tripCount0*(((10)-(0))); flops += tripCount1*1; readBytes += tripCount1*36; writeBytes += tripCount1*12; intops += tripCount1*16;}}readBytes=10;sstmac_compute_detailed(flops,intops,readBytes); }












return 0;
}
#include <sstmac/software/process/cppglobal.h>
#include <sstmac/software/process/memoize.h>

1 change: 1 addition & 0 deletions tests/reference/test_clang_pragma_sst_replace_cpp.ref-out
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void fxn3()
int x = 42;



for (int i=0; i < 3; ++i){
int x = 10;
int z = 42;
Expand Down

0 comments on commit dd87374

Please sign in to comment.