const Fortran::parser::AllCookedSources &allCooked,
llvm::StringRef triple, fir::KindMapping &kindMap,
const Fortran::lower::LoweringOptions &loweringOptions,
- const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
- llvm::StringRef filePath) {
+ const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults) {
return LoweringBridge(ctx, semanticsContext, defaultKinds, intrinsics,
targetCharacteristics, allCooked, triple, kindMap,
- loweringOptions, envDefaults, filePath);
+ loweringOptions, envDefaults);
}
//===--------------------------------------------------------------------===//
const Fortran::parser::AllCookedSources &cooked, llvm::StringRef triple,
fir::KindMapping &kindMap,
const Fortran::lower::LoweringOptions &loweringOptions,
- const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
- llvm::StringRef filePath);
+ const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults);
LoweringBridge() = delete;
LoweringBridge(const LoweringBridge &) = delete;
ci.getInvocation().getSemanticsContext().targetCharacteristics(),
ci.getParsing().allCooked(), ci.getInvocation().getTargetOpts().triple,
kindMap, ci.getInvocation().getLoweringOpts(),
- ci.getInvocation().getFrontendOpts().envDefaults,
- getCurrentFileOrBufferName());
+ ci.getInvocation().getFrontendOpts().envDefaults);
// Fetch module from lb, so we can set
mlirModule = std::make_unique<mlir::ModuleOp>(lb.getModule());
llvm::PassInstrumentationCallbacks pic;
llvm::PipelineTuningOptions pto;
std::optional<llvm::PGOOptions> pgoOpt;
- llvm::StandardInstrumentations si(
- llvmModule->getContext(), opts.DebugPassManager);
+ llvm::StandardInstrumentations si(llvmModule->getContext(),
+ opts.DebugPassManager);
si.registerCallbacks(pic, &fam);
llvm::PassBuilder pb(tm.get(), pto, pgoOpt, &pic);
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
#include <optional>
#define DEBUG_TYPE "flang-lower-bridge"
const Fortran::parser::AllCookedSources &cooked, llvm::StringRef triple,
fir::KindMapping &kindMap,
const Fortran::lower::LoweringOptions &loweringOptions,
- const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
- llvm::StringRef filePath)
+ const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults)
: semanticsContext{semanticsContext}, defaultKinds{defaultKinds},
intrinsics{intrinsics}, targetCharacteristics{targetCharacteristics},
cooked{&cooked}, context{context}, kindMap{kindMap},
return mlir::success();
});
+ auto getPathLocation = [&semanticsContext, &context]() -> mlir::Location {
+ std::optional<std::string> path;
+ const auto &allSources{semanticsContext.allCookedSources().allSources()};
+ if (auto initial{allSources.GetFirstFileProvenance()};
+ initial && !initial->empty()) {
+ if (const auto *sourceFile{allSources.GetSourceFile(initial->start())}) {
+ path = sourceFile->path();
+ }
+ }
+
+ if (path.has_value()) {
+ llvm::SmallString<256> curPath(*path);
+ llvm::sys::fs::make_absolute(curPath);
+ llvm::sys::path::remove_dots(curPath);
+ return mlir::FileLineColLoc::get(&context, curPath.str(), /*line=*/0,
+ /*col=*/0);
+ } else {
+ return mlir::UnknownLoc::get(&context);
+ }
+ };
+
// Create the module and attach the attributes.
module = std::make_unique<mlir::ModuleOp>(
- mlir::ModuleOp::create(mlir::FileLineColLoc::get(
- &getMLIRContext(), filePath, /*line=*/0, /*col=*/0)));
+ mlir::ModuleOp::create(getPathLocation()));
assert(module.get() && "module was not created");
fir::setTargetTriple(*module.get(), triple);
fir::setKindMapping(*module.get(), kindMap);
--- /dev/null
+! Test that the module has the location information
+
+! RUN: %flang_fc1 -mmlir --mlir-print-debuginfo -emit-fir -o - %s | FileCheck %s
+
+! REQUIRES: linux
+
+subroutine sb1()
+end subroutine
+
+! CHECK: module attributes
+! CHECK: func.func @_QPsb1() {
+! CHECK: }
+! CHECK: } loc(#[[MODULE_LOC:.*]])
+! CHECK: #[[MODULE_LOC]] = loc("/{{.*}}flang/test/Lower/module-debug-file-loc-linux.f90":0:0)
auto burnside = Fortran::lower::LoweringBridge::create(
ctx, semanticsContext, defKinds, semanticsContext.intrinsics(),
semanticsContext.targetCharacteristics(), parsing.allCooked(), "",
- kindMap, loweringOptions, {}, inputFilename);
+ kindMap, loweringOptions, {});
burnside.lower(parseTree, semanticsContext);
mlir::ModuleOp mlirModule = burnside.getModule();
std::error_code ec;