diff --git a/flang/lib/Semantics/mod-file.h b/flang/lib/Semantics/mod-file.h --- a/flang/lib/Semantics/mod-file.h +++ b/flang/lib/Semantics/mod-file.h @@ -76,6 +76,7 @@ llvm::raw_ostream &PutAttrs(llvm::raw_ostream &, Attrs, const std::string * = nullptr, bool = false, std::string before = ","s, std::string after = ""s) const; + void PutDirective(llvm::raw_ostream &, const Symbol &); }; class ModFileReader { diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp --- a/flang/lib/Semantics/mod-file.cpp +++ b/flang/lib/Semantics/mod-file.cpp @@ -330,6 +330,7 @@ [](const MiscDetails &) {}, [&](const auto &) { PutEntity(decls_, symbol); + PutDirective(decls_, symbol); if (symbol.test(Symbol::Flag::OmpThreadprivate)) { decls_ << "!$omp threadprivate(" << symbol.name() << ")\n"; } @@ -874,6 +875,30 @@ return os; } +void ModFileWriter::PutDirective(llvm::raw_ostream &os, const Symbol &symbol) { + if (symbol.test(Symbol::Flag::AccDeclare)) { + os << "!$acc declare "; + if (symbol.test(Symbol::Flag::AccCopy)) { + os << "copy"; + } else if (symbol.test(Symbol::Flag::AccCopyIn)) { + os << "copyin"; + } else if (symbol.test(Symbol::Flag::AccCopyOut)) { + os << "copyout"; + } else if (symbol.test(Symbol::Flag::AccCreate)) { + os << "create"; + } else if (symbol.test(Symbol::Flag::AccPresent)) { + os << "present"; + } else if (symbol.test(Symbol::Flag::AccDevicePtr)) { + os << "deviceptr"; + } else if (symbol.test(Symbol::Flag::AccDeviceResident)) { + os << "device_resident"; + } else if (symbol.test(Symbol::Flag::AccLink)) { + os << "link"; + } + os << "(" << symbol.name() << ")\n"; + } +} + struct Temp { Temp(int fd, std::string path) : fd{fd}, path{path} {} Temp(Temp &&t) : fd{std::exchange(t.fd, -1)}, path{std::move(t.path)} {} diff --git a/flang/test/Semantics/OpenACC/acc-module.f90 b/flang/test/Semantics/OpenACC/acc-module.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Semantics/OpenACC/acc-module.f90 @@ -0,0 +1,29 @@ +! RUN: %flang_fc1 -fsyntax-only -module-dir %S -fopenacc %s | cat %S/acc_mod.mod | FileCheck %s + +! UNSUPPORTED: system-windows + +module acc_mod + real :: data_create(100) + !$acc declare create(data_create) + + real :: data_copyin(10) + !$acc declare copyin(data_copyin) + + real :: data_device_resident(20) + !$acc declare device_resident(data_device_resident) + + integer :: data_link(50) + !$acc declare link(data_link) +end module + +! CHECK: !mod$ v1 sum:{{.*}} +! CHECK-LABEL: module acc_mod +! CHECK: real(4)::data_create(1_8:100_8) +! CHECK: !$acc declare create(data_create) +! CHECK: real(4)::data_copyin(1_8:10_8) +! CHECK: !$acc declare copyin(data_copyin) +! CHECK: real(4)::data_device_resident(1_8:20_8) +! CHECK: !$acc declare device_resident(data_device_resident) +! CHECK: integer(4)::data_link(1_8:50_8) +! CHECK: !$acc declare link(data_link) +! CHECK: end