From 70cac41a2b7e4a7a28c36a544c9813c833d494bb Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Wed, 12 Feb 2020 20:52:23 -0600 Subject: Reapply "[OpenMP][IRBuilder] Perform finalization (incl. outlining) late" Reapply 8a56d64d7620b3764f10f03f3a1e307fcdd72c2f with minor fixes. The problem was that cancellation can cause new edges to the parallel region exit block which is not outlined. The CodeExtractor will encode the information which "exit" was taken as a return value. The fix is to ensure we do not return any value from the outlined function, to prevent control to value conversion we ensure a single exit block for the outlined region. This reverts commit 3aac953afa34885a72df96f2b703b65f85cbb149. --- clang/lib/CodeGen/CodeGenFunction.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp') diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index b7506b5..4798de0 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -32,6 +32,7 @@ #include "clang/Basic/TargetInfo.h" #include "clang/CodeGen/CGFunctionInfo.h" #include "clang/Frontend/FrontendDiagnostic.h" +#include "llvm/Frontend/OpenMP/OMPIRBuilder.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/FPEnv.h" @@ -104,6 +105,14 @@ CodeGenFunction::~CodeGenFunction() { if (getLangOpts().OpenMP && CurFn) CGM.getOpenMPRuntime().functionFinished(*this); + + // If we have an OpenMPIRBuilder we want to finalize functions (incl. + // outlining etc) at some point. Doing it once the function codegen is done + // seems to be a reasonable spot. We do it here, as opposed to the deletion + // time of the CodeGenModule, because we have to ensure the IR has not yet + // been "emitted" to the outside, thus, modifications are still sensible. + if (llvm::OpenMPIRBuilder *OMPBuilder = CGM.getOpenMPIRBuilder()) + OMPBuilder->finalize(); } // Map the LangOption for rounding mode into -- cgit v1.1