Skip to content

Commit

Permalink
Merge branch 'sotoc-issue-25' into 'aurora_offloading_prototype'
Browse files Browse the repository at this point in the history
Remove the use of Rewriter in code generation

Closes llvm#25

See merge request NEC-RWTH-Projects/clang!20
  • Loading branch information
manorom committed Mar 28, 2019
2 parents cbc5483 + dd2f3d7 commit 6a8009d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
31 changes: 8 additions & 23 deletions clang/tools/sotoc/src/TargetCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,15 @@ void TargetCode::generateCode(llvm::raw_ostream &Out) {
std::shared_ptr<TargetCodeFragment> Frag = *i;
auto *TCR = llvm::dyn_cast<TargetCodeRegion>(Frag.get());

auto PrettyCode = Frag->PrintPretty();

// This is a workaround, since "Decl::print" includes "pragma omp declare".
if (PrettyCode != "")
TargetCodeRewriter.ReplaceText(Frag->getSpellingRange(), PrettyCode);

if (TCR) {
generateFunctionPrologue(TCR);
generateFunctionPrologue(TCR, Out);
}

Out << Frag->PrintPretty();

if (TCR) {
generateFunctionEpilogue(TCR);
generateFunctionEpilogue(TCR, Out);
}
Out << "\n";
Out << TargetCodeRewriter.getRewrittenText(Frag->getSpellingRange());

if (Frag->NeedsSemicolon) {
Out << ";";
Expand All @@ -97,12 +91,10 @@ void TargetCode::generateCode(llvm::raw_ostream &Out) {
}
}

void TargetCode::generateFunctionPrologue(TargetCodeRegion *TCR) {
void TargetCode::generateFunctionPrologue(TargetCodeRegion *TCR,
llvm::raw_ostream &Out) {

std::string Prologue;
llvm::raw_string_ostream Out(Prologue);

auto tmpSL = TCR->getStartLoc();

std::list<int> nDim;
std::list<std::string> DimString;
Expand Down Expand Up @@ -204,15 +196,10 @@ void TargetCode::generateFunctionPrologue(TargetCodeRegion *TCR) {
}
}
Out << "\n";

if (TargetCodeRewriter.InsertTextBefore(tmpSL, Out.str()) == true)
llvm::errs() << "ERROR: Prologue was not written\n";
}

void TargetCode::generateFunctionEpilogue(TargetCodeRegion *TCR) {
std::stringstream Out;
auto tmpSL = TCR->getEndLoc();

void TargetCode::generateFunctionEpilogue(TargetCodeRegion *TCR,
llvm::raw_ostream &Out) {
if (OmpPragma(TCR).needsStructuredBlock()) {
Out << "\n}";
}
Expand Down Expand Up @@ -244,8 +231,6 @@ void TargetCode::generateFunctionEpilogue(TargetCodeRegion *TCR) {
}

Out << "\n}\n";
if (TargetCodeRewriter.InsertTextBefore(tmpSL, Out.str()) == true)
llvm::errs() << "ERROR: Epilogue was not written\n";
}

std::string TargetCode::generateFunctionName(TargetCodeRegion *TCR) {
Expand Down
4 changes: 2 additions & 2 deletions clang/tools/sotoc/src/TargetCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ class TargetCode {
/// Generates a function prologue for a target region.
/// This prologue consists of a function declaration and code to copy local
/// variables into scope.
void generateFunctionPrologue(TargetCodeRegion *TCR);
void generateFunctionPrologue(TargetCodeRegion *TCR, llvm::raw_ostream &Out);
/// Generates a function epilogue for a target region.
/// This prologue consists of a code to copy variables from the local scope
/// back.
void generateFunctionEpilogue(TargetCodeRegion *TCR);
void generateFunctionEpilogue(TargetCodeRegion *TCR, llvm::raw_ostream &Out);
/// Generate a function name for a target region.
std::string generateFunctionName(TargetCodeRegion *TCR);

Expand Down

0 comments on commit 6a8009d

Please sign in to comment.