Skip to content

Commit

Permalink
Merge branch 'sotoc-region-func-name' into 'aurora_offloading_prototype'
Browse files Browse the repository at this point in the history
Sotoc: Fix target region function names

Closes llvm#47

See merge request NEC-RWTH-Projects/clang!26
  • Loading branch information
manorom committed Aug 5, 2019
2 parents a9a2a4a + 8d79131 commit 35ff4a6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
15 changes: 12 additions & 3 deletions clang/tools/sotoc/src/Visitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ llvm::Optional<std::string> getSystemHeaderForDecl(clang::Decl *D) {
std::string(SM.getFilename(SM.getLocForStartOfFile(IncludedFile))));
}

bool FindTargetCodeVisitor::TraverseDecl(clang::Decl *D) {
if (auto *FD = llvm::dyn_cast<clang::FunctionDecl>(D)) {
LastVisitedFuncDecl.push(FD);
}
bool ret = clang::RecursiveASTVisitor<FindTargetCodeVisitor>::TraverseDecl(D);
if (auto *FD = llvm::dyn_cast<clang::FunctionDecl>(D)) {
LastVisitedFuncDecl.pop();
}
return ret;
}

bool FindTargetCodeVisitor::VisitStmt(clang::Stmt *S) {
if (auto *TD = llvm::dyn_cast<clang::OMPTargetDirective>(S)) {
processTargetRegion(TD);
Expand Down Expand Up @@ -151,7 +162,7 @@ bool FindTargetCodeVisitor::processTargetRegion(
}

auto TCR = std::make_shared<TargetCodeRegion>(
CS, TargetDirective, LastVisitedFuncDecl, Context);
CS, TargetDirective, LastVisitedFuncDecl.top(), Context);
// if the target region cannot be added we dont want to parse its args
if (TargetCodeInfo.addCodeFragment(TCR)) {

Expand Down Expand Up @@ -245,8 +256,6 @@ void FindTargetCodeVisitor::addTargetRegionArgs(
bool FindTargetCodeVisitor::VisitDecl(clang::Decl *D) {
auto *FD = llvm::dyn_cast<clang::FunctionDecl>(D);
if (FD) {
LastVisitedFuncDecl = FD;

auto search = FuncDeclWithoutBody.find(FD->getNameAsString());
if (search != FuncDeclWithoutBody.end()) {
Functions.addDecl(D);
Expand Down
3 changes: 2 additions & 1 deletion clang/tools/sotoc/src/Visitors.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class FindTargetCodeVisitor

/// The last function the visitor traversed. This is stored to be able to
/// later compute the function name for the target region.
clang::FunctionDecl *LastVisitedFuncDecl;
std::stack<clang::FunctionDecl *> LastVisitedFuncDecl;
/// Function with 'omp declare target' pragma, for which the visitor has not
/// yet found a body.
std::unordered_set<std::string> FuncDeclWithoutBody;
Expand All @@ -136,6 +136,7 @@ class FindTargetCodeVisitor
clang::ASTContext &Context)
: Context(Context), TargetCodeInfo(Code), DiscoverTypeVisitor(Types),
DiscoverFunctionVisitor(Functions), Functions(Functions){};
bool TraverseDecl(clang::Decl *D);
bool VisitStmt(clang::Stmt *S);
bool VisitDecl(clang::Decl *D);

Expand Down
15 changes: 15 additions & 0 deletions clang/tools/sotoc/test/target/target_region_forward_before.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %sotoc-transform-compile
// RUN: %run-on-host

#include <stdio.h>

int main(){
int bla();
#pragma omp target
printf("%d\n",bla());
}

int bla(){
return 42;
};

0 comments on commit 35ff4a6

Please sign in to comment.