Skip to content

Commit 3ad342a

Browse files
committed
Merge branch 'sotoc-issue-48-private-scopes' into 'aurora_offloading_prototype'
Fix generated double declaration of private vars Closes llvm#48 See merge request NEC-RWTH-Projects/clang!27
2 parents 58b757f + 4912b4c commit 3ad342a

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

clang/tools/sotoc/src/TargetCode.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,15 @@ void TargetCode::generateFunctionPrologue(TargetCodeRegion *TCR,
137137
Out << "void *__sotoc_var_";
138138
nDim.push_back(dim); // push total number of dimensions
139139
} else {
140-
DEBUGP("Generating code for non-array type");
141140
Out << (*i)->getType().getAsString() << " ";
142141
if (!(*i)->getType().getTypePtr()->isPointerType()) {
143142
if (C) {
144143
// Parameters which are not first private (e.g., explicit mapped vars)
145144
// are passed by reference, all others by value.
146-
if (!(C->getClauseKind() ==
147-
clang::OpenMPClauseKind::OMPC_firstprivate)) {
145+
if (C->getClauseKind() !=
146+
clang::OpenMPClauseKind::OMPC_firstprivate &&
147+
C->getClauseKind() !=
148+
clang::OpenMPClauseKind::OMPC_private) {
148149
Out << "*__sotoc_var_";
149150
}
150151
}
@@ -192,8 +193,10 @@ void TargetCode::generateFunctionPrologue(TargetCodeRegion *TCR,
192193
if (C) {
193194
// Parameters which are not first private (e.g., explicit mapped vars)
194195
// are passed by reference, all others by value.
195-
if (!(C->getClauseKind() ==
196-
clang::OpenMPClauseKind::OMPC_firstprivate)) {
196+
if (C->getClauseKind() !=
197+
clang::OpenMPClauseKind::OMPC_firstprivate &&
198+
C->getClauseKind() !=
199+
clang::OpenMPClauseKind::OMPC_private) {
197200
auto VarName = (*I)->getDeclName().getAsString();
198201
Out << " " << (*I)->getType().getAsString() << " " << VarName
199202
<< " = "
@@ -242,8 +245,10 @@ void TargetCode::generateFunctionEpilogue(TargetCodeRegion *TCR,
242245
if (C) {
243246
// Parameters which are not first private (e.g., explicit mapped vars)
244247
// are passed by reference, all others by value.
245-
if (!(C->getClauseKind() ==
246-
clang::OpenMPClauseKind::OMPC_firstprivate)) {
248+
if (C->getClauseKind() !=
249+
clang::OpenMPClauseKind::OMPC_firstprivate &&
250+
C->getClauseKind() !=
251+
clang::OpenMPClauseKind::OMPC_private) {
247252
auto VarName = (*I)->getDeclName().getAsString();
248253
Out << "\n *__sotoc_var_" << VarName << " = " << VarName << ";";
249254
}

clang/tools/sotoc/src/TargetCodeFragment.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ std::string TargetCodeRegion::PrintLocalVarsFromClauses() {
218218
if (C->getClauseKind() == clang::OpenMPClauseKind::OMPC_private) {
219219
auto PC = llvm::dyn_cast<clang::OMPPrivateClause>(C);
220220
for (auto Var : PC->varlists()) {
221+
222+
// If the variable is already captured -> do not print
223+
if (auto *DRE = llvm::dyn_cast<clang::DeclRefExpr>(Var)) {
224+
auto *VarDecl = DRE->getDecl();
225+
if(std::find(CapturedVars.begin(), CapturedVars.end(), VarDecl) != CapturedVars.end()) {
226+
continue;
227+
}
228+
}
221229
std::string PrettyStr = "";
222230
llvm::raw_string_ostream PrettyOS(PrettyStr);
223231
Var->printPretty(PrettyOS, NULL, PP);

clang/tools/sotoc/test/target/multiple_regions2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main() {
1414
#pragma omp parallel for private(j)
1515
for(i=0; i<42; i++)
1616
{
17-
for(i=0; i<42; i++){}
17+
for(j=0; j<42; j++){}
1818
}
1919

2020
#pragma omp parallel for

0 commit comments

Comments
 (0)