Skip to content

Commit 220cc9b

Browse files
committed
Merge branch 'sotoc-issue-22' into 'aurora_offloading_prototype'
Add hack to deal with variable list (issue llvm#22) See merge request NEC-RWTH-Projects/clang!16
2 parents 87fe3c8 + c944b8d commit 220cc9b

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

clang/tools/sotoc/src/TargetCode.cpp

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@
2727
#include "llvm/Support/Format.h"
2828
#include "llvm/Support/raw_ostream.h"
2929

30-
#include "TargetCode.h"
3130
#include "Debug.h"
31+
#include "TargetCode.h"
3232

3333
bool TargetCode::addCodeFragment(std::shared_ptr<TargetCodeFragment> Frag,
3434
bool PushFront) {
3535
for (auto &F : CodeFragments) {
3636
// Reject Fragments which are inside Fragments which we already have
37-
if (SM.isPointWithin(Frag->getRealRange().getBegin(),
38-
F->getRealRange().getBegin(),
39-
F->getRealRange().getEnd()) ||
37+
if ((SM.isPointWithin(Frag->getRealRange().getBegin(),
38+
F->getRealRange().getBegin(),
39+
F->getRealRange().getEnd()) &&
40+
Frag->getRealRange().getBegin() != F->getRealRange().getBegin()) ||
4041
SM.isPointWithin(Frag->getRealRange().getEnd(),
4142
F->getRealRange().getBegin(),
4243
F->getRealRange().getEnd())) {
@@ -113,7 +114,7 @@ void TargetCode::generateFunctionPrologue(TargetCodeRegion *TCR) {
113114
}
114115
first = false;
115116

116-
// check for constant or variable length arrays, because of
117+
// check for constant or variable length arrays, because of
117118
// AST representation and naive getType
118119
if (auto t = clang::dyn_cast_or_null<clang::ArrayType>(
119120
(*i)->getType().getTypePtr())) {
@@ -157,8 +158,7 @@ void TargetCode::generateFunctionPrologue(TargetCodeRegion *TCR) {
157158
t->getElementType().getTypePtr());
158159
} while (t != NULL);
159160

160-
Out << " " << elemType << " (*" << VarName
161-
<< ")";
161+
Out << " " << elemType << " (*" << VarName << ")";
162162

163163
// Get number of Dimensions(nDim) and write sizes(DimString)
164164
for (int i = 1; i < nDim.front(); i++) {
@@ -210,8 +210,7 @@ void TargetCode::generateFunctionPrologue(TargetCodeRegion *TCR) {
210210
break;
211211
}
212212
case clang::OpenMPDirectiveKind::OMPD_target_parallel_for_simd: {
213-
Out << " #pragma omp parallel for simd " << TCR->PrintClauses()
214-
<< "\n ";
213+
Out << " #pragma omp parallel for simd " << TCR->PrintClauses() << "\n ";
215214
break;
216215
}
217216
case clang::OpenMPDirectiveKind::OMPD_target_simd: {
@@ -228,8 +227,7 @@ void TargetCode::generateFunctionPrologue(TargetCodeRegion *TCR) {
228227
}
229228
case clang::OpenMPDirectiveKind::
230229
OMPD_target_teams_distribute_parallel_for_simd: {
231-
Out << " #pragma omp parallel for simd " << TCR->PrintClauses()
232-
<< "\n ";
230+
Out << " #pragma omp parallel for simd " << TCR->PrintClauses() << "\n ";
233231
break;
234232
}
235233
case clang::OpenMPDirectiveKind::OMPD_target_teams_distribute_simd: {
@@ -252,17 +250,17 @@ void TargetCode::generateFunctionEpilogue(TargetCodeRegion *TCR) {
252250
// ||
253251
TCR->TargetCodeKind == clang::OpenMPDirectiveKind::OMPD_target_parallel ||
254252
// TCR->TargetCodeKind ==
255-
// clang::OpenMPDirectiveKind::OMPD_target_parallel_for ||
253+
// clang::OpenMPDirectiveKind::OMPD_target_parallel_for ||
256254
// TCR->TargetCodeKind ==
257-
// clang::OpenMPDirectiveKind::OMPD_target_parallel_for_simd ||
255+
// clang::OpenMPDirectiveKind::OMPD_target_parallel_for_simd ||
258256
TCR->TargetCodeKind == clang::OpenMPDirectiveKind::OMPD_target_simd ||
259257
// TCR->TargetCodeKind ==
260258
// clang::OpenMPDirectiveKind::OMPD_target_teams_distribute ||
261259
// TCR->TargetCodeKind == clang::OpenMPDirectiveKind::
262-
// OMPD_target_teams_distribute_parallel_for ||
260+
// OMPD_target_teams_distribute_parallel_for ||
263261
// TCR->TargetCodeKind ==
264-
// clang::OpenMPDirectiveKind::
265-
// OMPD_target_teams_distribute_parallel_for_simd ||
262+
// clang::OpenMPDirectiveKind::
263+
// OMPD_target_teams_distribute_parallel_for_simd ||
266264
TCR->TargetCodeKind ==
267265
clang::OpenMPDirectiveKind::OMPD_target_teams_distribute_simd) {
268266
Out << "\n }";
@@ -318,12 +316,11 @@ std::string TargetCode::generateFunctionName(TargetCodeRegion *TCR) {
318316
}
319317

320318
void TargetCode::handleArrays(const clang::ArrayType **t,
321-
std::list<std::string>& DimString,
322-
int& dim, TargetCodeRegion *TCR,
323-
std::string& elemType) {
319+
std::list<std::string> &DimString, int &dim,
320+
TargetCodeRegion *TCR, std::string &elemType) {
324321
auto OrigT = *t;
325322

326-
if(!t) {
323+
if (!t) {
327324
return;
328325
} else {
329326
// We just remember the last element type
@@ -336,8 +333,8 @@ void TargetCode::handleArrays(const clang::ArrayType **t,
336333
DimString.push_back(t1->getSize().toString(10, false));
337334
++dim;
338335

339-
340-
} else if (auto t1 = clang::dyn_cast_or_null<clang::VariableArrayType>(OrigT)) {
336+
} else if (auto t1 =
337+
clang::dyn_cast_or_null<clang::VariableArrayType>(OrigT)) {
341338
DEBUGP("ArrayType VAT");
342339
std::string PrettyStr = "";
343340
llvm::raw_string_ostream PrettyOS(PrettyStr);
@@ -353,11 +350,10 @@ void TargetCode::handleArrays(const clang::ArrayType **t,
353350
return;
354351
}
355352

356-
357-
(*t) = clang::dyn_cast_or_null<clang::ArrayType>(OrigT->getElementType().getTypePtr());
358-
if(*t) {
353+
(*t) = clang::dyn_cast_or_null<clang::ArrayType>(
354+
OrigT->getElementType().getTypePtr());
355+
if (*t) {
359356
// Recursively handle all dimensions
360357
handleArrays(t, DimString, dim, TCR, elemType);
361358
}
362-
363359
}

0 commit comments

Comments
 (0)