[flang-commits] [flang] [RFC][flang] Replace special symbols in uniqued global names. (PR #104859)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Mon Aug 19 14:16:24 PDT 2024
https://github.com/vzakhari updated https://github.com/llvm/llvm-project/pull/104859
>From 6cee61b3f3882834a4c0acfcb1f804987f763ce0 Mon Sep 17 00:00:00 2001
From: Slava Zakharin <szakharin at nvidia.com>
Date: Mon, 19 Aug 2024 10:42:36 -0700
Subject: [PATCH 1/2] [RFC][flang] Replace special symbols in uniqued global
names.
This change addresses more "issues" as the one resolved in #71338.
Some targets (e.g. NVPTX) do not accept global names containing
`.`. In particular, the global variables created to represent
the runtime information of derived types use `.` in their names.
A derived type's descriptor object may be used in the device code,
e.g. to initialize a descriptor of a variable of this type.
Thus, the runtime type info objects may need to be compiled
for the device.
Moreover, at least the derived types' descriptor objects
may need to be registered (think of `omp declare target`)
for the host-device association so that the addendum pointer
can be properly mapped to the device for descriptors using
a derived type's descriptor as their addendum pointer.
The registration implies knowing the name of the global variable
in the device image so that proper host code can be created.
So it is better to name the globals the same way for the host
and the device.
CompilerGeneratedNamesConversion pass renames all uniqued globals
such that the special symbols (currently `.`) are replaced
with `X`. The pass is supposed to be run for the host and the device.
An option is added to FIR-to-LLVM conversion pass to indicate
whether the new pass has been run before or not. This setting
affects how the codegen computes the names of the derived types'
descriptors for FIR derived types.
fir::NameUniquer now allows `X` to be part of a name, because
the name deconstruction may be applied to the mangled names
after CompilerGeneratedNamesConversion pass.
---
.../flang/Optimizer/CodeGen/CGPasses.td | 6 +-
.../include/flang/Optimizer/CodeGen/CodeGen.h | 10 +++
.../flang/Optimizer/Support/InternalNames.h | 25 ++++--
.../flang/Optimizer/Transforms/Passes.h | 1 +
.../flang/Optimizer/Transforms/Passes.td | 18 +++++
flang/include/flang/Tools/CLOptions.inc | 10 +++
flang/lib/Optimizer/CodeGen/CodeGen.cpp | 13 ++-
flang/lib/Optimizer/Support/InternalNames.cpp | 31 +++++--
flang/lib/Optimizer/Transforms/CMakeLists.txt | 1 +
.../Transforms/CompilerGeneratedNames.cpp | 80 +++++++++++++++++++
flang/lib/Semantics/runtime-type-info.cpp | 65 +++++++++------
.../test/Driver/mlir-debug-pass-pipeline.f90 | 1 +
flang/test/Driver/mlir-pass-pipeline.f90 | 1 +
flang/test/Fir/basic-program.fir | 1 +
flang/test/Fir/convert-to-llvm.fir | 2 +-
flang/test/Fir/convert-type-desc-to-llvm.fir | 29 +++++++
flang/test/Fir/polymorphic.fir | 4 +-
flang/test/Fir/type-descriptor.fir | 4 +-
flang/test/Lower/allocatable-polymorphic.f90 | 14 ++--
flang/test/Lower/dense-array-any-rank.f90 | 6 +-
20 files changed, 267 insertions(+), 55 deletions(-)
create mode 100644 flang/lib/Optimizer/Transforms/CompilerGeneratedNames.cpp
create mode 100644 flang/test/Fir/convert-type-desc-to-llvm.fir
diff --git a/flang/include/flang/Optimizer/CodeGen/CGPasses.td b/flang/include/flang/Optimizer/CodeGen/CGPasses.td
index 989e3943882a19..e9e303df09eeba 100644
--- a/flang/include/flang/Optimizer/CodeGen/CGPasses.td
+++ b/flang/include/flang/Optimizer/CodeGen/CGPasses.td
@@ -36,7 +36,11 @@ def FIRToLLVMLowering : Pass<"fir-to-llvm-ir", "mlir::ModuleOp"> {
Option<"forcedTargetFeatures", "target-features", "std::string",
/*default=*/"", "Override module's target features.">,
Option<"applyTBAA", "apply-tbaa", "bool", /*default=*/"false",
- "Attach TBAA tags to memory accessing operations.">
+ "Attach TBAA tags to memory accessing operations.">,
+ Option<"typeDescriptorsRenamedForAssembly",
+ "type-descriptors-renamed-for-assembly", "bool", /*default=*/"false",
+ "Global variables created to describe derived types "
+ "have been renamed to avoid special symbols in their names.">
];
}
diff --git a/flang/include/flang/Optimizer/CodeGen/CodeGen.h b/flang/include/flang/Optimizer/CodeGen/CodeGen.h
index 06961819bb19c8..390f00e1ac77c2 100644
--- a/flang/include/flang/Optimizer/CodeGen/CodeGen.h
+++ b/flang/include/flang/Optimizer/CodeGen/CodeGen.h
@@ -44,6 +44,16 @@ struct FIRToLLVMPassOptions {
// Force the usage of a unified tbaa tree in TBAABuilder.
bool forceUnifiedTBAATree = false;
+
+ // If set to true, then the global variables created
+ // for the derived types have been renamed to avoid usage
+ // of special symbols that may not be supported by all targets.
+ // The renaming is done by the CompilerGeneratedNamesConversion pass.
+ // If it is true, FIR-to-LLVM pass has to use
+ // fir::NameUniquer::getTypeDescriptorAssemblyName() to take
+ // the name of the global variable corresponding to a derived
+ // type's descriptor.
+ bool typeDescriptorsRenamedForAssembly = false;
};
/// Convert FIR to the LLVM IR dialect with default options.
diff --git a/flang/include/flang/Optimizer/Support/InternalNames.h b/flang/include/flang/Optimizer/Support/InternalNames.h
index 9e13b4a7668b7a..67ab36cf8da7ff 100644
--- a/flang/include/flang/Optimizer/Support/InternalNames.h
+++ b/flang/include/flang/Optimizer/Support/InternalNames.h
@@ -14,13 +14,23 @@
#include <cstdint>
#include <optional>
-static constexpr llvm::StringRef typeDescriptorSeparator = ".dt.";
-static constexpr llvm::StringRef componentInitSeparator = ".di.";
-static constexpr llvm::StringRef bindingTableSeparator = ".v.";
-static constexpr llvm::StringRef boxprocSuffix = "UnboxProc";
-
namespace fir {
+static constexpr llvm::StringRef kNameSeparator = ".";
+static constexpr llvm::StringRef kBoundsSeparator = ".b.";
+static constexpr llvm::StringRef kComponentSeparator = ".c.";
+static constexpr llvm::StringRef kComponentInitSeparator = ".di.";
+static constexpr llvm::StringRef kDataPtrInitSeparator = ".dp.";
+static constexpr llvm::StringRef kTypeDescriptorSeparator = ".dt.";
+static constexpr llvm::StringRef kKindParameterSeparator = ".kp.";
+static constexpr llvm::StringRef kLenKindSeparator = ".lpk.";
+static constexpr llvm::StringRef kLenParameterSeparator = ".lv.";
+static constexpr llvm::StringRef kNameStringSeparator = ".n.";
+static constexpr llvm::StringRef kProcPtrSeparator = ".p.";
+static constexpr llvm::StringRef kSpecialBindingSeparator = ".s.";
+static constexpr llvm::StringRef kBindingTableSeparator = ".v.";
+static constexpr llvm::StringRef boxprocSuffix = "UnboxProc";
+
/// Internal name mangling of identifiers
///
/// In order to generate symbolically referencable artifacts in a ModuleOp,
@@ -150,6 +160,9 @@ struct NameUniquer {
/// not a valid mangled derived type name.
static std::string getTypeDescriptorName(llvm::StringRef mangledTypeName);
+ static std::string
+ getTypeDescriptorAssemblyName(llvm::StringRef mangledTypeName);
+
/// Given a mangled derived type name, get the name of the related binding
/// table object. Returns an empty string if \p mangledTypeName is not a valid
/// mangled derived type name.
@@ -169,6 +182,8 @@ struct NameUniquer {
static llvm::StringRef
dropTypeConversionMarkers(llvm::StringRef mangledTypeName);
+ static std::string replaceSpecialSymbols(const std::string &name);
+
private:
static std::string intAsString(std::int64_t i);
static std::string doKind(std::int64_t kind);
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.h b/flang/include/flang/Optimizer/Transforms/Passes.h
index 96b0e9714b95af..6f98e3a25ec125 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.h
+++ b/flang/include/flang/Optimizer/Transforms/Passes.h
@@ -59,6 +59,7 @@ namespace fir {
#define GEN_PASS_DECL_VSCALEATTR
#define GEN_PASS_DECL_FUNCTIONATTR
#define GEN_PASS_DECL_CONSTANTARGUMENTGLOBALISATIONOPT
+#define GEN_PASS_DECL_COMPILERGENERATEDNAMESCONVERSION
#include "flang/Optimizer/Transforms/Passes.h.inc"
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td
index c703a62c03b7d9..a0211384667ed1 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.td
+++ b/flang/include/flang/Optimizer/Transforms/Passes.td
@@ -170,6 +170,24 @@ def ExternalNameConversion : Pass<"external-name-interop", "mlir::ModuleOp"> {
];
}
+def CompilerGeneratedNamesConversion : Pass<"compiler-generated-names",
+ "mlir::ModuleOp"> {
+ let summary = "Convert names of compiler generated globals";
+ let description = [{
+ Transforms names of compiler generated globals to avoid
+ characters that might be unsupported by some target toolchains.
+ All special symbols are replaced with a predefined 'X' character.
+ This is only done for uniqued names that are not externally facing.
+ The uniqued names always use '_Q' prefix, and the user entity names
+ are always lower cased, so using 'X' instead of the special symbols
+ will guarantee that the converted name will not conflict with the user
+ space. This pass does not affect the externally facing names,
+ because the expectation is that the compiler will not generate
+ externally facing names on its own, and these names cannot use
+ special symbols.
+ }];
+}
+
def MemRefDataFlowOpt : Pass<"fir-memref-dataflow-opt", "::mlir::func::FuncOp"> {
let summary =
"Perform store/load forwarding and potentially removing dead stores.";
diff --git a/flang/include/flang/Tools/CLOptions.inc b/flang/include/flang/Tools/CLOptions.inc
index 7df50449494631..57b90017d052e4 100644
--- a/flang/include/flang/Tools/CLOptions.inc
+++ b/flang/include/flang/Tools/CLOptions.inc
@@ -93,6 +93,8 @@ DisableOption(ExternalNameConversion, "external-name-interop",
"convert names with external convention");
EnableOption(ConstantArgumentGlobalisation, "constant-argument-globalisation",
"the local constant argument to global constant conversion");
+DisableOption(CompilerGeneratedNamesConversion, "compiler-generated-names",
+ "replace special symbols in compiler generated names");
using PassConstructor = std::unique_ptr<mlir::Pass>();
@@ -222,6 +224,8 @@ inline void addFIRToLLVMPass(
options.ignoreMissingTypeDescriptors = ignoreMissingTypeDescriptors;
options.applyTBAA = config.AliasAnalysis;
options.forceUnifiedTBAATree = useOldAliasTags;
+ options.typeDescriptorsRenamedForAssembly =
+ !disableCompilerGeneratedNamesConversion;
addPassConditionally(pm, disableFirToLlvmIr,
[&]() { return fir::createFIRToLLVMPass(options); });
// The dialect conversion framework may leave dead unrealized_conversion_cast
@@ -248,6 +252,11 @@ inline void addExternalNameConversionPass(
[&]() { return fir::createExternalNameConversion({appendUnderscore}); });
}
+inline void addCompilerGeneratedNamesConversionPass(mlir::PassManager &pm) {
+ addPassConditionally(pm, disableCompilerGeneratedNamesConversion,
+ [&]() { return fir::createCompilerGeneratedNamesConversion(); });
+}
+
// Use inliner extension point callback to register the default inliner pass.
inline void registerDefaultInlinerPass(MLIRToLLVMPassPipelineConfig &config) {
config.registerFIRInlinerCallback(
@@ -379,6 +388,7 @@ inline void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
fir::addCodeGenRewritePass(
pm, (config.DebugInfo != llvm::codegenoptions::NoDebugInfo));
fir::addTargetRewritePass(pm);
+ fir::addCompilerGeneratedNamesConversionPass(pm);
fir::addExternalNameConversionPass(pm, config.Underscoring);
fir::createDebugPasses(pm, config.DebugInfo, config.OptLevel, inputFilename);
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 1713cf98a8b961..e419b261252995 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -1201,7 +1201,9 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
mlir::Location loc,
fir::RecordType recType) const {
std::string name =
- fir::NameUniquer::getTypeDescriptorName(recType.getName());
+ this->options.typeDescriptorsRenamedForAssembly
+ ? fir::NameUniquer::getTypeDescriptorAssemblyName(recType.getName())
+ : fir::NameUniquer::getTypeDescriptorName(recType.getName());
mlir::Type llvmPtrTy = ::getLlvmPtrType(mod.getContext());
if (auto global = mod.template lookupSymbol<fir::GlobalOp>(name)) {
return rewriter.create<mlir::LLVM::AddressOfOp>(loc, llvmPtrTy,
@@ -2704,7 +2706,10 @@ struct TypeDescOpConversion : public fir::FIROpConversion<fir::TypeDescOp> {
auto recordType = mlir::dyn_cast<fir::RecordType>(inTy);
auto module = typeDescOp.getOperation()->getParentOfType<mlir::ModuleOp>();
std::string typeDescName =
- fir::NameUniquer::getTypeDescriptorName(recordType.getName());
+ this->options.typeDescriptorsRenamedForAssembly
+ ? fir::NameUniquer::getTypeDescriptorAssemblyName(
+ recordType.getName())
+ : fir::NameUniquer::getTypeDescriptorName(recordType.getName());
auto llvmPtrTy = ::getLlvmPtrType(typeDescOp.getContext());
if (auto global = module.lookupSymbol<mlir::LLVM::GlobalOp>(typeDescName)) {
rewriter.replaceOpWithNewOp<mlir::LLVM::AddressOfOp>(
@@ -3653,6 +3658,10 @@ class FIRToLLVMLowering
if (!forcedTargetFeatures.empty())
fir::setTargetFeatures(mod, forcedTargetFeatures);
+ if (typeDescriptorsRenamedForAssembly)
+ options.typeDescriptorsRenamedForAssembly =
+ typeDescriptorsRenamedForAssembly;
+
// Run dynamic pass pipeline for converting Math dialect
// operations into other dialects (llvm, func, etc.).
// Some conversions of Math operations cannot be done
diff --git a/flang/lib/Optimizer/Support/InternalNames.cpp b/flang/lib/Optimizer/Support/InternalNames.cpp
index b2e2cd38f48e60..58a5da5de79720 100644
--- a/flang/lib/Optimizer/Support/InternalNames.cpp
+++ b/flang/lib/Optimizer/Support/InternalNames.cpp
@@ -16,6 +16,7 @@
#include "mlir/IR/Diagnostics.h"
#include "llvm/Support/CommandLine.h"
#include <optional>
+#include <regex>
static llvm::cl::opt<std::string> mainEntryName(
"main-entry-name",
@@ -59,7 +60,11 @@ convertToStringRef(const std::optional<std::string> &from) {
static std::string readName(llvm::StringRef uniq, std::size_t &i,
std::size_t init, std::size_t end) {
- for (i = init; i < end && (uniq[i] < 'A' || uniq[i] > 'Z'); ++i) {
+ // Allow 'X' to be part of the mangled name, which
+ // can happen after the special symbols are replaced
+ // in the mangled names by CompilerGeneratedNamesConversionPass.
+ for (i = init; i < end && (uniq[i] < 'A' || uniq[i] > 'Z' || uniq[i] == 'X');
+ ++i) {
// do nothing
}
return uniq.substr(init, i - init).str();
@@ -348,7 +353,7 @@ mangleTypeDescriptorKinds(llvm::ArrayRef<std::int64_t> kinds) {
return "";
std::string result;
for (std::int64_t kind : kinds)
- result += "." + std::to_string(kind);
+ result += (fir::kNameSeparator + std::to_string(kind)).str();
return result;
}
@@ -373,12 +378,18 @@ static std::string getDerivedTypeObjectName(llvm::StringRef mangledTypeName,
std::string
fir::NameUniquer::getTypeDescriptorName(llvm::StringRef mangledTypeName) {
- return getDerivedTypeObjectName(mangledTypeName, typeDescriptorSeparator);
+ return getDerivedTypeObjectName(mangledTypeName,
+ fir::kTypeDescriptorSeparator);
+}
+
+std::string fir::NameUniquer::getTypeDescriptorAssemblyName(
+ llvm::StringRef mangledTypeName) {
+ return replaceSpecialSymbols(getTypeDescriptorName(mangledTypeName));
}
std::string fir::NameUniquer::getTypeDescriptorBindingTableName(
llvm::StringRef mangledTypeName) {
- return getDerivedTypeObjectName(mangledTypeName, bindingTableSeparator);
+ return getDerivedTypeObjectName(mangledTypeName, fir::kBindingTableSeparator);
}
std::string
@@ -386,13 +397,17 @@ fir::NameUniquer::getComponentInitName(llvm::StringRef mangledTypeName,
llvm::StringRef componentName) {
std::string prefix =
- getDerivedTypeObjectName(mangledTypeName, componentInitSeparator);
- return prefix + "." + componentName.str();
+ getDerivedTypeObjectName(mangledTypeName, fir::kComponentInitSeparator);
+ return (prefix + fir::kNameSeparator + componentName).str();
}
llvm::StringRef
fir::NameUniquer::dropTypeConversionMarkers(llvm::StringRef mangledTypeName) {
- if (mangledTypeName.ends_with(boxprocSuffix))
- return mangledTypeName.drop_back(boxprocSuffix.size());
+ if (mangledTypeName.ends_with(fir::boxprocSuffix))
+ return mangledTypeName.drop_back(fir::boxprocSuffix.size());
return mangledTypeName;
}
+
+std::string fir::NameUniquer::replaceSpecialSymbols(const std::string &name) {
+ return std::regex_replace(name, std::regex{"\\."}, "X");
+}
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index 3869633bd98e02..bf0a8d14d95df6 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -6,6 +6,7 @@ add_flang_library(FIRTransforms
AnnotateConstant.cpp
AssumedRankOpConversion.cpp
CharacterConversion.cpp
+ CompilerGeneratedNames.cpp
ConstantArgumentGlobalisation.cpp
ControlFlowConverter.cpp
CufOpConversion.cpp
diff --git a/flang/lib/Optimizer/Transforms/CompilerGeneratedNames.cpp b/flang/lib/Optimizer/Transforms/CompilerGeneratedNames.cpp
new file mode 100644
index 00000000000000..7f2cc41275e593
--- /dev/null
+++ b/flang/lib/Optimizer/Transforms/CompilerGeneratedNames.cpp
@@ -0,0 +1,80 @@
+//=== CompilerGeneratedNames.cpp - convert special symbols in global names ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang/Optimizer/Dialect/FIRDialect.h"
+#include "flang/Optimizer/Dialect/FIROps.h"
+#include "flang/Optimizer/Dialect/FIROpsSupport.h"
+#include "flang/Optimizer/Support/InternalNames.h"
+#include "flang/Optimizer/Transforms/Passes.h"
+#include "mlir/IR/Attributes.h"
+#include "mlir/IR/SymbolTable.h"
+#include "mlir/Pass/Pass.h"
+
+namespace fir {
+#define GEN_PASS_DEF_COMPILERGENERATEDNAMESCONVERSION
+#include "flang/Optimizer/Transforms/Passes.h.inc"
+} // namespace fir
+
+using namespace mlir;
+
+namespace {
+
+class CompilerGeneratedNamesConversionPass
+ : public fir::impl::CompilerGeneratedNamesConversionBase<
+ CompilerGeneratedNamesConversionPass> {
+public:
+ using CompilerGeneratedNamesConversionBase<
+ CompilerGeneratedNamesConversionPass>::
+ CompilerGeneratedNamesConversionBase;
+
+ mlir::ModuleOp getModule() { return getOperation(); }
+ void runOnOperation() override;
+};
+} // namespace
+
+void CompilerGeneratedNamesConversionPass::runOnOperation() {
+ auto op = getOperation();
+ auto *context = &getContext();
+
+ llvm::DenseMap<mlir::StringAttr, mlir::FlatSymbolRefAttr> remappings;
+ for (auto &funcOrGlobal : op->getRegion(0).front()) {
+ if (llvm::isa<mlir::func::FuncOp>(funcOrGlobal) ||
+ llvm::isa<fir::GlobalOp>(funcOrGlobal)) {
+ auto symName = funcOrGlobal.getAttrOfType<mlir::StringAttr>(
+ mlir::SymbolTable::getSymbolAttrName());
+ auto deconstructedName = fir::NameUniquer::deconstruct(symName);
+ if (deconstructedName.first != fir::NameUniquer::NameKind::NOT_UNIQUED &&
+ !fir::NameUniquer::isExternalFacingUniquedName(deconstructedName)) {
+ std::string newName =
+ fir::NameUniquer::replaceSpecialSymbols(symName.getValue().str());
+ if (newName != symName) {
+ auto newAttr = mlir::StringAttr::get(context, newName);
+ mlir::SymbolTable::setSymbolName(&funcOrGlobal, newAttr);
+ auto newSymRef = mlir::FlatSymbolRefAttr::get(newAttr);
+ remappings.try_emplace(symName, newSymRef);
+ }
+ }
+ }
+ }
+
+ if (remappings.empty())
+ return;
+
+ // Update all uses of the functions and globals that have been renamed.
+ op.walk([&remappings](mlir::Operation *nestedOp) {
+ llvm::SmallVector<std::pair<mlir::StringAttr, mlir::SymbolRefAttr>> updates;
+ for (const mlir::NamedAttribute &attr : nestedOp->getAttrDictionary())
+ if (auto symRef = llvm::dyn_cast<mlir::SymbolRefAttr>(attr.getValue()))
+ if (auto remap = remappings.find(symRef.getRootReference());
+ remap != remappings.end())
+ updates.emplace_back(std::pair<mlir::StringAttr, mlir::SymbolRefAttr>{
+ attr.getName(), mlir::SymbolRefAttr(remap->second)});
+ for (auto update : updates)
+ nestedOp->setAttr(update.first, update.second);
+ });
+}
diff --git a/flang/lib/Semantics/runtime-type-info.cpp b/flang/lib/Semantics/runtime-type-info.cpp
index 66909241966735..4d1308d84889f6 100644
--- a/flang/lib/Semantics/runtime-type-info.cpp
+++ b/flang/lib/Semantics/runtime-type-info.cpp
@@ -12,6 +12,7 @@
#include "flang/Evaluate/fold.h"
#include "flang/Evaluate/tools.h"
#include "flang/Evaluate/type.h"
+#include "flang/Optimizer/Support/InternalNames.h"
#include "flang/Semantics/scope.h"
#include "flang/Semantics/tools.h"
#include <functional>
@@ -377,9 +378,12 @@ static std::optional<std::string> GetSuffixIfTypeKindParameters(
if (pv->GetExplicit()) {
if (auto instantiatedValue{evaluate::ToInt64(*pv->GetExplicit())}) {
if (suffix.has_value()) {
- *suffix += "."s + std::to_string(*instantiatedValue);
+ *suffix +=
+ (fir::kNameSeparator + llvm::Twine(*instantiatedValue))
+ .str();
} else {
- suffix = "."s + std::to_string(*instantiatedValue);
+ suffix = (fir::kNameSeparator + llvm::Twine(*instantiatedValue))
+ .str();
}
}
}
@@ -448,7 +452,7 @@ const Symbol *RuntimeTableBuilder::DescribeType(Scope &dtScope) {
} else if (isPDTDefinitionWithKindParameters) {
return nullptr;
}
- std::string dtDescName{".dt."s + distinctName};
+ std::string dtDescName{(fir::kTypeDescriptorSeparator + distinctName).str()};
Scope *dtSymbolScope{const_cast<Scope *>(dtSymbol->scope())};
Scope &scope{
GetContainingNonDerivedScope(dtSymbolScope ? *dtSymbolScope : dtScope)};
@@ -518,11 +522,13 @@ const Symbol *RuntimeTableBuilder::DescribeType(Scope &dtScope) {
}
}
AddValue(dtValues, derivedTypeSchema_, "kindparameter"s,
- SaveNumericPointerTarget<Int8>(
- scope, SaveObjectName(".kp."s + distinctName), std::move(kinds)));
+ SaveNumericPointerTarget<Int8>(scope,
+ SaveObjectName((fir::kKindParameterSeparator + distinctName).str()),
+ std::move(kinds)));
AddValue(dtValues, derivedTypeSchema_, "lenparameterkind"s,
- SaveNumericPointerTarget<Int1>(
- scope, SaveObjectName(".lpk."s + distinctName), std::move(lenKinds)));
+ SaveNumericPointerTarget<Int1>(scope,
+ SaveObjectName((fir::kLenKindSeparator + distinctName).str()),
+ std::move(lenKinds)));
// Traverse the components of the derived type
if (!isPDTDefinitionWithKindParameters) {
std::vector<const Symbol *> dataComponentSymbols;
@@ -570,13 +576,15 @@ const Symbol *RuntimeTableBuilder::DescribeType(Scope &dtScope) {
dtScope, distinctName, parameters));
}
AddValue(dtValues, derivedTypeSchema_, "component"s,
- SaveDerivedPointerTarget(scope, SaveObjectName(".c."s + distinctName),
+ SaveDerivedPointerTarget(scope,
+ SaveObjectName((fir::kComponentSeparator + distinctName).str()),
std::move(dataComponents),
evaluate::ConstantSubscripts{
static_cast<evaluate::ConstantSubscript>(
dataComponents.size())}));
AddValue(dtValues, derivedTypeSchema_, "procptr"s,
- SaveDerivedPointerTarget(scope, SaveObjectName(".p."s + distinctName),
+ SaveDerivedPointerTarget(scope,
+ SaveObjectName((fir::kProcPtrSeparator + distinctName).str()),
std::move(procPtrComponents),
evaluate::ConstantSubscripts{
static_cast<evaluate::ConstantSubscript>(
@@ -587,7 +595,9 @@ const Symbol *RuntimeTableBuilder::DescribeType(Scope &dtScope) {
std::vector<evaluate::StructureConstructor> bindings{
DescribeBindings(dtScope, scope)};
AddValue(dtValues, derivedTypeSchema_, bindingDescCompName,
- SaveDerivedPointerTarget(scope, SaveObjectName(".v."s + distinctName),
+ SaveDerivedPointerTarget(scope,
+ SaveObjectName(
+ (fir::kBindingTableSeparator + distinctName).str()),
std::move(bindings),
evaluate::ConstantSubscripts{
static_cast<evaluate::ConstantSubscript>(bindings.size())}));
@@ -623,7 +633,9 @@ const Symbol *RuntimeTableBuilder::DescribeType(Scope &dtScope) {
sortedSpecials.emplace_back(std::move(pair.second));
}
AddValue(dtValues, derivedTypeSchema_, "special"s,
- SaveDerivedPointerTarget(scope, SaveObjectName(".s."s + distinctName),
+ SaveDerivedPointerTarget(scope,
+ SaveObjectName(
+ (fir::kSpecialBindingSeparator + distinctName).str()),
std::move(sortedSpecials),
evaluate::ConstantSubscripts{
static_cast<evaluate::ConstantSubscript>(specials.size())}));
@@ -731,9 +743,9 @@ SomeExpr RuntimeTableBuilder::SaveNameAsPointerTarget(
using AsciiExpr = evaluate::Expr<Ascii>;
object.set_init(evaluate::AsGenericExpr(AsciiExpr{name}));
Symbol &symbol{*scope
- .try_emplace(SaveObjectName(".n."s + name),
- Attrs{Attr::TARGET, Attr::SAVE}, std::move(object))
- .first->second};
+ .try_emplace(SaveObjectName((fir::kNameStringSeparator + name).str()),
+ Attrs{Attr::TARGET, Attr::SAVE}, std::move(object))
+ .first->second};
SetReadOnlyCompilerCreatedFlags(symbol);
return evaluate::AsGenericExpr(
AsciiExpr{evaluate::Designator<Ascii>{symbol}});
@@ -821,8 +833,9 @@ evaluate::StructureConstructor RuntimeTableBuilder::DescribeComponent(
if (!lenParams.empty()) {
AddValue(values, componentSchema_, "lenvalue"s,
SaveDerivedPointerTarget(scope,
- SaveObjectName(
- ".lv."s + distinctName + "."s + symbol.name().ToString()),
+ SaveObjectName((fir::kLenParameterSeparator + distinctName +
+ fir::kNameSeparator + symbol.name().ToString())
+ .str()),
std::move(lenParams),
evaluate::ConstantSubscripts{
static_cast<evaluate::ConstantSubscript>(lenParams.size())}));
@@ -845,8 +858,9 @@ evaluate::StructureConstructor RuntimeTableBuilder::DescribeComponent(
}
AddValue(values, componentSchema_, "bounds"s,
SaveDerivedPointerTarget(scope,
- SaveObjectName(
- ".b."s + distinctName + "."s + symbol.name().ToString()),
+ SaveObjectName((fir::kBoundsSeparator + distinctName +
+ fir::kNameSeparator + symbol.name().ToString())
+ .str()),
std::move(bounds), evaluate::ConstantSubscripts{2, rank}));
} else {
AddValue(
@@ -868,8 +882,9 @@ evaluate::StructureConstructor RuntimeTableBuilder::DescribeComponent(
if (hasDataInit) {
AddValue(values, componentSchema_, "initialization"s,
SaveObjectInit(scope,
- SaveObjectName(
- ".di."s + distinctName + "."s + symbol.name().ToString()),
+ SaveObjectName((fir::kComponentInitSeparator + distinctName +
+ fir::kNameSeparator + symbol.name().ToString())
+ .str()),
object));
}
}
@@ -918,8 +933,9 @@ bool RuntimeTableBuilder::InitializeDataPointer(
const ObjectEntityDetails &object, Scope &scope, Scope &dtScope,
const std::string &distinctName) {
if (object.init().has_value()) {
- SourceName ptrDtName{SaveObjectName(
- ".dp."s + distinctName + "."s + symbol.name().ToString())};
+ SourceName ptrDtName{SaveObjectName((fir::kDataPtrInitSeparator +
+ distinctName + fir::kNameSeparator + symbol.name().ToString())
+ .str())};
Symbol &ptrDtSym{
*scope.try_emplace(ptrDtName, Attrs{}, UnknownDetails{}).first->second};
SetReadOnlyCompilerCreatedFlags(ptrDtSym);
@@ -952,8 +968,9 @@ bool RuntimeTableBuilder::InitializeDataPointer(
Structure(ptrDtDeclType, std::move(ptrInitValues))));
AddValue(values, componentSchema_, "initialization"s,
SaveObjectInit(scope,
- SaveObjectName(
- ".di."s + distinctName + "."s + symbol.name().ToString()),
+ SaveObjectName((fir::kComponentInitSeparator + distinctName +
+ fir::kNameSeparator + symbol.name().ToString())
+ .str()),
ptrInitObj));
return true;
} else {
diff --git a/flang/test/Driver/mlir-debug-pass-pipeline.f90 b/flang/test/Driver/mlir-debug-pass-pipeline.f90
index 6e9846fa422e55..a6316ee7c83123 100644
--- a/flang/test/Driver/mlir-debug-pass-pipeline.f90
+++ b/flang/test/Driver/mlir-debug-pass-pipeline.f90
@@ -109,6 +109,7 @@
! ALL-NEXT: CodeGenRewrite
! ALL-NEXT: (S) 0 num-dce'd - Number of operations eliminated
! ALL-NEXT: TargetRewrite
+! ALL-NEXT: CompilerGeneratedNamesConversion
! ALL-NEXT: ExternalNameConversion
! DEBUG-NEXT: AddDebugInfo
! NO-DEBUG-NOT: AddDebugInfo
diff --git a/flang/test/Driver/mlir-pass-pipeline.f90 b/flang/test/Driver/mlir-pass-pipeline.f90
index db4551e93fe64c..2f35f928e99cfc 100644
--- a/flang/test/Driver/mlir-pass-pipeline.f90
+++ b/flang/test/Driver/mlir-pass-pipeline.f90
@@ -118,6 +118,7 @@
! ALL-NEXT: CodeGenRewrite
! ALL-NEXT: (S) 0 num-dce'd - Number of operations eliminated
! ALL-NEXT: TargetRewrite
+! ALL-NEXT: CompilerGeneratedNamesConversion
! ALL-NEXT: ExternalNameConversion
! ALL-NEXT: FIRToLLVMLowering
! ALL-NOT: LLVMIRLoweringPass
diff --git a/flang/test/Fir/basic-program.fir b/flang/test/Fir/basic-program.fir
index dda4f32872fef5..bca454c13ff9cc 100644
--- a/flang/test/Fir/basic-program.fir
+++ b/flang/test/Fir/basic-program.fir
@@ -118,6 +118,7 @@ func.func @_QQmain() {
// PASSES-NEXT: CodeGenRewrite
// PASSES-NEXT: (S) 0 num-dce'd - Number of operations eliminated
// PASSES-NEXT: TargetRewrite
+// PASSES-NEXT: CompilerGeneratedNamesConversion
// PASSES-NEXT: FIRToLLVMLowering
// PASSES-NEXT: ReconcileUnrealizedCasts
// PASSES-NEXT: LLVMIRLoweringPass
diff --git a/flang/test/Fir/convert-to-llvm.fir b/flang/test/Fir/convert-to-llvm.fir
index 194a11456f2569..a4e8170af036c9 100644
--- a/flang/test/Fir/convert-to-llvm.fir
+++ b/flang/test/Fir/convert-to-llvm.fir
@@ -1,7 +1,7 @@
// RUN: fir-opt --split-input-file --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" %s | FileCheck %s --check-prefixes=CHECK,CHECK-COMDAT,GENERIC
// RUN: fir-opt --split-input-file --fir-to-llvm-ir="target=aarch64-unknown-linux-gnu" %s | FileCheck %s --check-prefixes=CHECK,CHECK-COMDAT,GENERIC
// RUN: fir-opt --split-input-file --fir-to-llvm-ir="target=i386-unknown-linux-gnu" %s | FileCheck %s --check-prefixes=CHECK,CHECK-COMDAT,GENERIC
-// RUN: fir-opt --split-input-file --fir-to-llvm-ir="target=powerpc64le-unknown-linux-gn" %s | FileCheck %s --check-prefixes=CHECK,CHECK-COMDAT,GENERIC
+// RUN: fir-opt --split-input-file --fir-to-llvm-ir="target=powerpc64le-unknown-linux-gnu" %s | FileCheck %s --check-prefixes=CHECK,CHECK-COMDAT,GENERIC
// RUN: fir-opt --split-input-file --fir-to-llvm-ir="target=x86_64-pc-win32" %s | FileCheck %s --check-prefixes=CHECK,CHECK-COMDAT,GENERIC
// RUN: fir-opt --split-input-file --fir-to-llvm-ir="target=aarch64-apple-darwin" %s | FileCheck %s --check-prefixes=CHECK,CHECK-NO-COMDAT,GENERIC
// RUN: fir-opt --split-input-file --fir-to-llvm-ir="target=amdgcn-amd-amdhsa, datalayout=e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-P0" %s | FileCheck -check-prefixes=CHECK,AMDGPU %s
diff --git a/flang/test/Fir/convert-type-desc-to-llvm.fir b/flang/test/Fir/convert-type-desc-to-llvm.fir
new file mode 100644
index 00000000000000..251c95d9c84216
--- /dev/null
+++ b/flang/test/Fir/convert-type-desc-to-llvm.fir
@@ -0,0 +1,29 @@
+// RUN: fir-opt --split-input-file --compiler-generated-names --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu type-descriptors-renamed-for-assembly=true" %s | FileCheck %s --check-prefixes=CHECK,CHECK-COMDAT
+// RUN: fir-opt --split-input-file --compiler-generated-names --fir-to-llvm-ir="target=aarch64-unknown-linux-gnu type-descriptors-renamed-for-assembly=true" %s | FileCheck %s --check-prefixes=CHECK,CHECK-COMDAT
+// RUN: fir-opt --split-input-file --compiler-generated-names --fir-to-llvm-ir="target=i386-unknown-linux-gnu type-descriptors-renamed-for-assembly=true" %s | FileCheck %s --check-prefixes=CHECK,CHECK-COMDAT
+// RUN: fir-opt --split-input-file --compiler-generated-names --fir-to-llvm-ir="target=powerpc64le-unknown-linux-gnu type-descriptors-renamed-for-assembly=true" %s | FileCheck %s --check-prefixes=CHECK,CHECK-COMDAT
+// RUN: fir-opt --split-input-file --compiler-generated-names --fir-to-llvm-ir="target=x86_64-pc-win32 type-descriptors-renamed-for-assembly=true" %s | FileCheck %s --check-prefixes=CHECK,CHECK-COMDAT
+// RUN: fir-opt --split-input-file --compiler-generated-names --fir-to-llvm-ir="target=aarch64-apple-darwin type-descriptors-renamed-for-assembly=true" %s | FileCheck %s --check-prefixes=CHECK,CHECK-NO-COMDAT
+// RUN: fir-opt --split-input-file --compiler-generated-names --fir-to-llvm-ir="target=amdgcn-amd-amdhsa type-descriptors-renamed-for-assembly=1 datalayout=e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-P0" %s | FileCheck -check-prefixes=CHECK %s
+
+// Check descriptor for a derived type. Check that the f18Addendum flag is set
+// to 1 meaning the addendum is present (true) and the addendum values are
+// inserted.
+
+fir.global linkonce @_QMtest_dinitE.dt.tseq constant : i8
+
+func.func @embox1(%arg0: !fir.ref<!fir.type<_QMtest_dinitTtseq{i:i32}>>) {
+ %0 = fir.embox %arg0() : (!fir.ref<!fir.type<_QMtest_dinitTtseq{i:i32}>>) -> !fir.box<!fir.type<_QMtest_dinitTtseq{i:i32}>>
+ return
+}
+
+// CHECK-COMDAT: llvm.mlir.global linkonce constant @_QMtest_dinitEXdtXtseq() comdat(@__llvm_comdat::@_QMtest_dinitEXdtXtseq) {addr_space = 0 : i32} : i8
+// CHECK-NO-COMDAT: llvm.mlir.global linkonce constant @_QMtest_dinitEXdtXtseq() {addr_space = 0 : i32} : i8
+// CHECK-LABEL: llvm.func @embox1
+// CHECK: %[[TYPE_CODE:.*]] = llvm.mlir.constant(42 : i32) : i32
+// CHECK: %[[VERSION:.*]] = llvm.mlir.constant(20240719 : i32) : i32
+// CHECK: %{{.*}} = llvm.insertvalue %[[VERSION]], %{{.*}}[2] : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, ptr, array<1 x i64>)>
+// CHECK: %[[TYPE_CODE_I8:.*]] = llvm.trunc %[[TYPE_CODE]] : i32 to i8
+// CHECK: %{{.*}} = llvm.insertvalue %[[TYPE_CODE_I8]], %{{.*}}[4] : !llvm.struct<(ptr, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr, array<1 x i{{.*}}>)>
+// CHECK: %[[TDESC:.*]] = llvm.mlir.addressof @_QMtest_dinitEXdtXtseq : !llvm.ptr
+// CHECK: %{{.*}} = llvm.insertvalue %[[TDESC]], %{{.*}}[7] : !llvm.struct<(ptr, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr, array<1 x i{{.*}}>)>
diff --git a/flang/test/Fir/polymorphic.fir b/flang/test/Fir/polymorphic.fir
index a6b166367a4a1b..40204314e8df79 100644
--- a/flang/test/Fir/polymorphic.fir
+++ b/flang/test/Fir/polymorphic.fir
@@ -157,7 +157,7 @@ func.func @_QQmain() {
// CHECK-LABEL: define void @_QQmain(){{.*}}{
// CHECK: %[[CLASS_NONE:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }
// CHECK: %[[DESC:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }, i64 1
-// CHECK: store { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] } { ptr @_QMmod1Ea, i64 ptrtoint (ptr getelementptr (%_QMmod1TtK2, ptr null, i32 1) to i64), i32 20240719, i8 0, i8 42, i8 1, i8 1, ptr @_QMmod1E.dt.t.2, [1 x i64] zeroinitializer }, ptr %[[CLASS_NONE]], align 8
+// CHECK: store { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] } { ptr @_QMmod1Ea, i64 ptrtoint (ptr getelementptr (%_QMmod1TtK2, ptr null, i32 1) to i64), i32 20240719, i8 0, i8 42, i8 1, i8 1, ptr @_QMmod1EXdtXtX2, [1 x i64] zeroinitializer }, ptr %[[CLASS_NONE]], align 8
// CHECK: %[[LOAD:.*]] = load { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }, ptr %[[CLASS_NONE]]
// CHECK: store { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] } %[[LOAD]], ptr %[[DESC]]
// CHECK: call void @_QMmod1Psub1(ptr %[[DESC]])
@@ -197,4 +197,4 @@ func.func @_QQembox_input_type(%arg0 : !fir.ref<!fir.type<_QMmod1Tp2{v:!fir.arra
}
// CHECK-LABEL: define void @_QQembox_input_type
-// CHECK: %{{.*}} = insertvalue { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] } { ptr undef, i64 ptrtoint (ptr getelementptr (%_QMmod1Tp2, ptr null, i32 1) to i64), i32 20240719, i8 0, i8 42, i8 0, i8 1, ptr @_QMmod1E.dt.p2, [1 x i64] zeroinitializer }, ptr %{{.*}}, 0
+// CHECK: %{{.*}} = insertvalue { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] } { ptr undef, i64 ptrtoint (ptr getelementptr (%_QMmod1Tp2, ptr null, i32 1) to i64), i32 20240719, i8 0, i8 42, i8 0, i8 1, ptr @_QMmod1EXdtXp2, [1 x i64] zeroinitializer }, ptr %{{.*}}, 0
diff --git a/flang/test/Fir/type-descriptor.fir b/flang/test/Fir/type-descriptor.fir
index f0ebd8ddeee1e9..3b58a2f68251a7 100644
--- a/flang/test/Fir/type-descriptor.fir
+++ b/flang/test/Fir/type-descriptor.fir
@@ -14,7 +14,7 @@ fir.global internal @_QFfooEx : !fir.box<!fir.heap<!sometype>> {
}
// CHECK: @_QFfooEx = internal global { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }
// CHECK-SAME: { ptr null, i64 ptrtoint (ptr getelementptr (%_QFfooTsometype, ptr null, i32 1) to i64),
-// CHECK-SAME: i32 20240719, i8 0, i8 42, i8 2, i8 1, ptr @_QFfooE.dt.sometype, [1 x i64] zeroinitializer }
+// CHECK-SAME: i32 20240719, i8 0, i8 42, i8 2, i8 1, ptr @_QFfooEXdtXsometype, [1 x i64] zeroinitializer }
!some_pdt_type = !fir.type<_QFfooTsome_pdt_typeK42K43{num:i32,values:!fir.box<!fir.ptr<!fir.array<?x?xf32>>>}>
fir.global internal @_QFfooE.dt.some_pdt_type.42.43 constant : i8
@@ -26,4 +26,4 @@ fir.global internal @_QFfooEx2 : !fir.box<!fir.heap<!some_pdt_type>> {
}
// CHECK: @_QFfooEx2 = internal global { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }
// CHECK-SAME: { ptr null, i64 ptrtoint (ptr getelementptr (%_QFfooTsome_pdt_typeK42K43, ptr null, i32 1) to i64),
-// CHECK-SAME: i32 20240719, i8 0, i8 42, i8 2, i8 1, ptr @_QFfooE.dt.some_pdt_type.42.43, [1 x i64] zeroinitializer }
+// CHECK-SAME: i32 20240719, i8 0, i8 42, i8 2, i8 1, ptr @_QFfooEXdtXsome_pdt_typeX42X43, [1 x i64] zeroinitializer }
diff --git a/flang/test/Lower/allocatable-polymorphic.f90 b/flang/test/Lower/allocatable-polymorphic.f90
index 8fe06450d6119e..e23e38ffb4b013 100644
--- a/flang/test/Lower/allocatable-polymorphic.f90
+++ b/flang/test/Lower/allocatable-polymorphic.f90
@@ -591,16 +591,16 @@ program test_alloc
! LLVM-LABEL: define void @_QMpolyPtest_allocatable()
-! LLVM: %{{.*}} = call {} @_FortranAAllocatableInitDerivedForAllocate(ptr %{{.*}}, ptr @_QMpolyE.dt.p1, i32 0, i32 0)
+! LLVM: %{{.*}} = call {} @_FortranAAllocatableInitDerivedForAllocate(ptr %{{.*}}, ptr @_QMpolyEXdtXp1, i32 0, i32 0)
! LLVM: %{{.*}} = call i32 @_FortranAAllocatableAllocate(ptr %{{.*}}, i1 false, ptr null, ptr @_QQclX{{.*}}, i32 {{.*}})
-! LLVM: %{{.*}} = call {} @_FortranAAllocatableInitDerivedForAllocate(ptr %{{.*}}, ptr @_QMpolyE.dt.p1, i32 0, i32 0)
+! LLVM: %{{.*}} = call {} @_FortranAAllocatableInitDerivedForAllocate(ptr %{{.*}}, ptr @_QMpolyEXdtXp1, i32 0, i32 0)
! LLVM: %{{.*}} = call i32 @_FortranAAllocatableAllocate(ptr %{{.*}}, i1 false, ptr null, ptr @_QQclX{{.*}}, i32 {{.*}})
-! LLVM: %{{.*}} = call {} @_FortranAAllocatableInitDerivedForAllocate(ptr %{{.*}}, ptr @_QMpolyE.dt.p2, i32 0, i32 0)
+! LLVM: %{{.*}} = call {} @_FortranAAllocatableInitDerivedForAllocate(ptr %{{.*}}, ptr @_QMpolyEXdtXp2, i32 0, i32 0)
! LLVM: %{{.*}} = call i32 @_FortranAAllocatableAllocate(ptr %{{.*}}, i1 false, ptr null, ptr @_QQclX{{.*}}, i32 {{.*}})
-! LLVM: %{{.*}} = call {} @_FortranAAllocatableInitDerivedForAllocate(ptr %{{.*}}, ptr @_QMpolyE.dt.p1, i32 1, i32 0)
+! LLVM: %{{.*}} = call {} @_FortranAAllocatableInitDerivedForAllocate(ptr %{{.*}}, ptr @_QMpolyEXdtXp1, i32 1, i32 0)
! LLVM: %{{.*}} = call {} @_FortranAAllocatableSetBounds(ptr %{{.*}}, i32 0, i64 1, i64 10)
! LLVM: %{{.*}} = call i32 @_FortranAAllocatableAllocate(ptr %{{.*}}, i1 false, ptr null, ptr @_QQclX{{.*}}, i32 {{.*}})
-! LLVM: %{{.*}} = call {} @_FortranAAllocatableInitDerivedForAllocate(ptr %{{.*}}, ptr @_QMpolyE.dt.p2, i32 1, i32 0)
+! LLVM: %{{.*}} = call {} @_FortranAAllocatableInitDerivedForAllocate(ptr %{{.*}}, ptr @_QMpolyEXdtXp2, i32 1, i32 0)
! LLVM: %{{.*}} = call {} @_FortranAAllocatableSetBounds(ptr %{{.*}}, i32 0, i64 1, i64 20)
! LLVM: %{{.*}} = call i32 @_FortranAAllocatableAllocate(ptr %{{.*}}, i1 false, ptr null, ptr @_QQclX{{.*}}, i32 {{.*}})
! LLVM-COUNT-2: call void %{{.*}}()
@@ -685,9 +685,9 @@ program test_alloc
! allocatable.
! LLVM-LABEL: define void @_QMpolyPtest_deallocate()
-! LLVM: store { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] } { ptr null, i64 ptrtoint (ptr getelementptr (%_QMpolyTp1, ptr null, i32 1) to i64), i32 20240719, i8 0, i8 42, i8 2, i8 1, ptr @_QMpolyE.dt.p1, [1 x i64] zeroinitializer }, ptr %[[ALLOCA1:[0-9]*]]
+! LLVM: store { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] } { ptr null, i64 ptrtoint (ptr getelementptr (%_QMpolyTp1, ptr null, i32 1) to i64), i32 20240719, i8 0, i8 42, i8 2, i8 1, ptr @_QMpolyEXdtXp1, [1 x i64] zeroinitializer }, ptr %[[ALLOCA1:[0-9]*]]
! LLVM: %[[LOAD:.*]] = load { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }, ptr %[[ALLOCA1]]
! LLVM: store { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] } %[[LOAD]], ptr %[[ALLOCA2:[0-9]*]]
-! LLVM: %{{.*}} = call {} @_FortranAAllocatableInitDerivedForAllocate(ptr %[[ALLOCA2]], ptr @_QMpolyE.dt.p1, i32 0, i32 0)
+! LLVM: %{{.*}} = call {} @_FortranAAllocatableInitDerivedForAllocate(ptr %[[ALLOCA2]], ptr @_QMpolyEXdtXp1, i32 0, i32 0)
! LLVM: %{{.*}} = call i32 @_FortranAAllocatableAllocate(ptr %[[ALLOCA2]], i1 false, ptr null, ptr @_QQclX{{.*}}, i32 {{.*}})
! LLVM: %{{.*}} = call i32 @_FortranAAllocatableDeallocatePolymorphic(ptr %[[ALLOCA2]], ptr {{.*}}, i1 false, ptr null, ptr @_QQclX{{.*}}, i32 {{.*}})
diff --git a/flang/test/Lower/dense-array-any-rank.f90 b/flang/test/Lower/dense-array-any-rank.f90
index 437fdec2da10ec..129adf41de07ff 100644
--- a/flang/test/Lower/dense-array-any-rank.f90
+++ b/flang/test/Lower/dense-array-any-rank.f90
@@ -14,12 +14,12 @@ subroutine test()
! a1 array constructor
! CHECK-FIR: fir.global internal @_QQro.10xi4.{{.*}}(dense<[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]> : tensor<10xi32>) constant : !fir.array<10xi32>
-! CHECK-LLVMIR: @_QQro.10xi4.0 = internal constant [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]
+! CHECK-LLVMIR: @_QQroX10xi4X0 = internal constant [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]
! a2 array constructor
! CHECK-FIR: fir.global internal @_QQro.3x4xi4.{{.*}}(dense<{{\[\[11, 12, 13], \[21, 22, 23], \[31, 32, 33], \[41, 42, 43]]}}> : tensor<4x3xi32>) constant : !fir.array<3x4xi32>
-! CHECK-LLVMIR: @_QQro.3x4xi4.1 = internal constant [4 x [3 x i32]] {{\[\[3 x i32] \[i32 11, i32 12, i32 13], \[3 x i32] \[i32 21, i32 22, i32 23], \[3 x i32] \[i32 31, i32 32, i32 33], \[3 x i32] \[i32 41, i32 42, i32 43]]}}
+! CHECK-LLVMIR: @_QQroX3x4xi4X1 = internal constant [4 x [3 x i32]] {{\[\[3 x i32] \[i32 11, i32 12, i32 13], \[3 x i32] \[i32 21, i32 22, i32 23], \[3 x i32] \[i32 31, i32 32, i32 33], \[3 x i32] \[i32 41, i32 42, i32 43]]}}
! a3 array constructor
! CHECK-FIR: fir.global internal @_QQro.2x3x4xi4.{{.*}}(dense<{{\[\[\[111, 112], \[121, 122], \[131, 132]], \[\[211, 212], \[221, 222], \[231, 232]], \[\[311, 312], \[321, 322], \[331, 332]], \[\[411, 412], \[421, 422], \[431, 432]]]}}> : tensor<4x3x2xi32>) constant : !fir.array<2x3x4xi32>
-! CHECK-LLVMIR: @_QQro.2x3x4xi4.2 = internal constant [4 x [3 x [2 x i32]]] {{\[\[3 x \[2 x i32]] \[\[2 x i32] \[i32 111, i32 112], \[2 x i32] \[i32 121, i32 122], \[2 x i32] \[i32 131, i32 132]], \[3 x \[2 x i32]] \[\[2 x i32] \[i32 211, i32 212], \[2 x i32] \[i32 221, i32 222], \[2 x i32] \[i32 231, i32 232]], \[3 x \[2 x i32]] \[\[2 x i32] \[i32 311, i32 312], \[2 x i32] \[i32 321, i32 322], \[2 x i32] \[i32 331, i32 332]], \[3 x \[2 x i32]] \[\[2 x i32] \[i32 411, i32 412], \[2 x i32] \[i32 421, i32 422], \[2 x i32] \[i32 431, i32 432]]]}}
+! CHECK-LLVMIR: @_QQroX2x3x4xi4X2 = internal constant [4 x [3 x [2 x i32]]] {{\[\[3 x \[2 x i32]] \[\[2 x i32] \[i32 111, i32 112], \[2 x i32] \[i32 121, i32 122], \[2 x i32] \[i32 131, i32 132]], \[3 x \[2 x i32]] \[\[2 x i32] \[i32 211, i32 212], \[2 x i32] \[i32 221, i32 222], \[2 x i32] \[i32 231, i32 232]], \[3 x \[2 x i32]] \[\[2 x i32] \[i32 311, i32 312], \[2 x i32] \[i32 321, i32 322], \[2 x i32] \[i32 331, i32 332]], \[3 x \[2 x i32]] \[\[2 x i32] \[i32 411, i32 412], \[2 x i32] \[i32 421, i32 422], \[2 x i32] \[i32 431, i32 432]]]}}
>From 1a4eaf4a5ce13e5d69f343f3d6bdfab7f22bc59b Mon Sep 17 00:00:00 2001
From: Slava Zakharin <szakharin at nvidia.com>
Date: Mon, 19 Aug 2024 14:15:57 -0700
Subject: [PATCH 2/2] clang-format
---
flang/lib/Semantics/runtime-type-info.cpp | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/flang/lib/Semantics/runtime-type-info.cpp b/flang/lib/Semantics/runtime-type-info.cpp
index 4d1308d84889f6..9f3eb5fbe11a15 100644
--- a/flang/lib/Semantics/runtime-type-info.cpp
+++ b/flang/lib/Semantics/runtime-type-info.cpp
@@ -742,10 +742,12 @@ SomeExpr RuntimeTableBuilder::SaveNameAsPointerTarget(
using evaluate::Ascii;
using AsciiExpr = evaluate::Expr<Ascii>;
object.set_init(evaluate::AsGenericExpr(AsciiExpr{name}));
- Symbol &symbol{*scope
- .try_emplace(SaveObjectName((fir::kNameStringSeparator + name).str()),
- Attrs{Attr::TARGET, Attr::SAVE}, std::move(object))
- .first->second};
+ Symbol &symbol{
+ *scope
+ .try_emplace(
+ SaveObjectName((fir::kNameStringSeparator + name).str()),
+ Attrs{Attr::TARGET, Attr::SAVE}, std::move(object))
+ .first->second};
SetReadOnlyCompilerCreatedFlags(symbol);
return evaluate::AsGenericExpr(
AsciiExpr{evaluate::Designator<Ascii>{symbol}});
@@ -835,7 +837,7 @@ evaluate::StructureConstructor RuntimeTableBuilder::DescribeComponent(
SaveDerivedPointerTarget(scope,
SaveObjectName((fir::kLenParameterSeparator + distinctName +
fir::kNameSeparator + symbol.name().ToString())
- .str()),
+ .str()),
std::move(lenParams),
evaluate::ConstantSubscripts{
static_cast<evaluate::ConstantSubscript>(lenParams.size())}));
@@ -860,7 +862,7 @@ evaluate::StructureConstructor RuntimeTableBuilder::DescribeComponent(
SaveDerivedPointerTarget(scope,
SaveObjectName((fir::kBoundsSeparator + distinctName +
fir::kNameSeparator + symbol.name().ToString())
- .str()),
+ .str()),
std::move(bounds), evaluate::ConstantSubscripts{2, rank}));
} else {
AddValue(
@@ -884,7 +886,7 @@ evaluate::StructureConstructor RuntimeTableBuilder::DescribeComponent(
SaveObjectInit(scope,
SaveObjectName((fir::kComponentInitSeparator + distinctName +
fir::kNameSeparator + symbol.name().ToString())
- .str()),
+ .str()),
object));
}
}
@@ -935,7 +937,7 @@ bool RuntimeTableBuilder::InitializeDataPointer(
if (object.init().has_value()) {
SourceName ptrDtName{SaveObjectName((fir::kDataPtrInitSeparator +
distinctName + fir::kNameSeparator + symbol.name().ToString())
- .str())};
+ .str())};
Symbol &ptrDtSym{
*scope.try_emplace(ptrDtName, Attrs{}, UnknownDetails{}).first->second};
SetReadOnlyCompilerCreatedFlags(ptrDtSym);
@@ -970,7 +972,7 @@ bool RuntimeTableBuilder::InitializeDataPointer(
SaveObjectInit(scope,
SaveObjectName((fir::kComponentInitSeparator + distinctName +
fir::kNameSeparator + symbol.name().ToString())
- .str()),
+ .str()),
ptrInitObj));
return true;
} else {
More information about the flang-commits
mailing list