Skip to content

Commit

Permalink
Merge branch 'sotoc-issue-48-private-scopes' into 'aurora_offloading_…
Browse files Browse the repository at this point in the history
…prototype'

Fix generated double declaration of private vars

Closes llvm#48

See merge request NEC-RWTH-Projects/clang!27
  • Loading branch information
manorom committed Aug 7, 2019
2 parents 58b757f + 4912b4c commit 3ad342a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
19 changes: 12 additions & 7 deletions clang/tools/sotoc/src/TargetCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,15 @@ void TargetCode::generateFunctionPrologue(TargetCodeRegion *TCR,
Out << "void *__sotoc_var_";
nDim.push_back(dim); // push total number of dimensions
} else {
DEBUGP("Generating code for non-array type");
Out << (*i)->getType().getAsString() << " ";
if (!(*i)->getType().getTypePtr()->isPointerType()) {
if (C) {
// Parameters which are not first private (e.g., explicit mapped vars)
// are passed by reference, all others by value.
if (!(C->getClauseKind() ==
clang::OpenMPClauseKind::OMPC_firstprivate)) {
if (C->getClauseKind() !=
clang::OpenMPClauseKind::OMPC_firstprivate &&
C->getClauseKind() !=
clang::OpenMPClauseKind::OMPC_private) {
Out << "*__sotoc_var_";
}
}
Expand Down Expand Up @@ -192,8 +193,10 @@ void TargetCode::generateFunctionPrologue(TargetCodeRegion *TCR,
if (C) {
// Parameters which are not first private (e.g., explicit mapped vars)
// are passed by reference, all others by value.
if (!(C->getClauseKind() ==
clang::OpenMPClauseKind::OMPC_firstprivate)) {
if (C->getClauseKind() !=
clang::OpenMPClauseKind::OMPC_firstprivate &&
C->getClauseKind() !=
clang::OpenMPClauseKind::OMPC_private) {
auto VarName = (*I)->getDeclName().getAsString();
Out << " " << (*I)->getType().getAsString() << " " << VarName
<< " = "
Expand Down Expand Up @@ -242,8 +245,10 @@ void TargetCode::generateFunctionEpilogue(TargetCodeRegion *TCR,
if (C) {
// Parameters which are not first private (e.g., explicit mapped vars)
// are passed by reference, all others by value.
if (!(C->getClauseKind() ==
clang::OpenMPClauseKind::OMPC_firstprivate)) {
if (C->getClauseKind() !=
clang::OpenMPClauseKind::OMPC_firstprivate &&
C->getClauseKind() !=
clang::OpenMPClauseKind::OMPC_private) {
auto VarName = (*I)->getDeclName().getAsString();
Out << "\n *__sotoc_var_" << VarName << " = " << VarName << ";";
}
Expand Down
8 changes: 8 additions & 0 deletions clang/tools/sotoc/src/TargetCodeFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ std::string TargetCodeRegion::PrintLocalVarsFromClauses() {
if (C->getClauseKind() == clang::OpenMPClauseKind::OMPC_private) {
auto PC = llvm::dyn_cast<clang::OMPPrivateClause>(C);
for (auto Var : PC->varlists()) {

// If the variable is already captured -> do not print
if (auto *DRE = llvm::dyn_cast<clang::DeclRefExpr>(Var)) {
auto *VarDecl = DRE->getDecl();
if(std::find(CapturedVars.begin(), CapturedVars.end(), VarDecl) != CapturedVars.end()) {
continue;
}
}
std::string PrettyStr = "";
llvm::raw_string_ostream PrettyOS(PrettyStr);
Var->printPretty(PrettyOS, NULL, PP);
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/sotoc/test/target/multiple_regions2.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main() {
#pragma omp parallel for private(j)
for(i=0; i<42; i++)
{
for(i=0; i<42; i++){}
for(j=0; j<42; j++){}
}

#pragma omp parallel for
Expand Down

0 comments on commit 3ad342a

Please sign in to comment.