diff options
Diffstat (limited to 'flang/lib/Lower/Bridge.cpp')
-rw-r--r-- | flang/lib/Lower/Bridge.cpp | 87 |
1 files changed, 62 insertions, 25 deletions
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp index 92aae79..75048c1 100644 --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -2167,10 +2167,35 @@ private: /// - structured and unstructured concurrent loops void genFIR(const Fortran::parser::DoConstruct &doConstruct) { setCurrentPositionAt(doConstruct); - // Collect loop nest information. - // Generate begin loop code directly for infinite and while loops. Fortran::lower::pft::Evaluation &eval = getEval(); bool unstructuredContext = eval.lowerAsUnstructured(); + + // Loops with induction variables inside OpenACC compute constructs + // need special handling to ensure that the IVs are privatized. + if (Fortran::lower::isInsideOpenACCComputeConstruct(*builder)) { + mlir::Operation *loopOp = Fortran::lower::genOpenACCLoopFromDoConstruct( + *this, bridge.getSemanticsContext(), localSymbols, doConstruct, eval); + bool success = loopOp != nullptr; + if (success) { + // Sanity check that the builder insertion point is inside the newly + // generated loop. + assert( + loopOp->getRegion(0).isAncestor( + builder->getInsertionPoint()->getBlock()->getParent()) && + "builder insertion point is not inside the newly generated loop"); + + // Loop body code. + auto iter = eval.getNestedEvaluations().begin(); + for (auto end = --eval.getNestedEvaluations().end(); iter != end; + ++iter) + genFIR(*iter, unstructuredContext); + return; + } + // Fall back to normal loop handling. + } + + // Collect loop nest information. + // Generate begin loop code directly for infinite and while loops. Fortran::lower::pft::Evaluation &doStmtEval = eval.getFirstNestedEvaluation(); auto *doStmt = doStmtEval.getIf<Fortran::parser::NonLabelDoStmt>(); @@ -3124,7 +3149,7 @@ private: Fortran::lower::pft::Evaluation *curEval = &getEval(); if (accLoop || accCombined) { - int64_t loopCount; + uint64_t loopCount; if (accLoop) { const Fortran::parser::AccBeginLoopDirective &beginLoopDir = std::get<Fortran::parser::AccBeginLoopDirective>(accLoop->t); @@ -3142,7 +3167,7 @@ private: if (curEval->lowerAsStructured()) { curEval = &curEval->getFirstNestedEvaluation(); - for (int64_t i = 1; i < loopCount; i++) + for (uint64_t i = 1; i < loopCount; i++) curEval = &*std::next(curEval->getNestedEvaluations().begin()); } } @@ -6682,27 +6707,30 @@ Fortran::lower::LoweringBridge::LoweringBridge( loweringOptions{loweringOptions}, envDefaults{envDefaults}, languageFeatures{languageFeatures} { // Register the diagnostic handler. - context.getDiagEngine().registerHandler([](mlir::Diagnostic &diag) { - llvm::raw_ostream &os = llvm::errs(); - switch (diag.getSeverity()) { - case mlir::DiagnosticSeverity::Error: - os << "error: "; - break; - case mlir::DiagnosticSeverity::Remark: - os << "info: "; - break; - case mlir::DiagnosticSeverity::Warning: - os << "warning: "; - break; - default: - break; - } - if (!mlir::isa<mlir::UnknownLoc>(diag.getLocation())) - os << diag.getLocation() << ": "; - os << diag << '\n'; - os.flush(); - return mlir::success(); - }); + if (loweringOptions.getRegisterMLIRDiagnosticsHandler()) { + diagHandlerID = + context.getDiagEngine().registerHandler([](mlir::Diagnostic &diag) { + llvm::raw_ostream &os = llvm::errs(); + switch (diag.getSeverity()) { + case mlir::DiagnosticSeverity::Error: + os << "error: "; + break; + case mlir::DiagnosticSeverity::Remark: + os << "info: "; + break; + case mlir::DiagnosticSeverity::Warning: + os << "warning: "; + break; + default: + break; + } + if (!mlir::isa<mlir::UnknownLoc>(diag.getLocation())) + os << diag.getLocation() << ": "; + os << diag << '\n'; + os.flush(); + return mlir::success(); + }); + } auto getPathLocation = [&semanticsContext, &context]() -> mlir::Location { std::optional<std::string> path; @@ -6733,6 +6761,10 @@ Fortran::lower::LoweringBridge::LoweringBridge( fir::setKindMapping(*module, kindMap); fir::setTargetCPU(*module, targetMachine.getTargetCPU()); fir::setTuneCPU(*module, targetOpts.cpuToTuneFor); + fir::setAtomicIgnoreDenormalMode(*module, + targetOpts.atomicIgnoreDenormalMode); + fir::setAtomicFineGrainedMemory(*module, targetOpts.atomicFineGrainedMemory); + fir::setAtomicRemoteMemory(*module, targetOpts.atomicRemoteMemory); fir::setTargetFeatures(*module, targetMachine.getTargetFeatureString()); fir::support::setMLIRDataLayout(*module, targetMachine.createDataLayout()); fir::setIdent(*module, Fortran::common::getFlangFullVersion()); @@ -6740,6 +6772,11 @@ Fortran::lower::LoweringBridge::LoweringBridge( fir::setCommandline(*module, *cgOpts.RecordCommandLine); } +Fortran::lower::LoweringBridge::~LoweringBridge() { + if (diagHandlerID) + context.getDiagEngine().eraseHandler(*diagHandlerID); +} + void Fortran::lower::genCleanUpInRegionIfAny( mlir::Location loc, fir::FirOpBuilder &builder, mlir::Region ®ion, Fortran::lower::StatementContext &context) { |