diff --git a/flang/include/flang/Optimizer/Support/InternalNames.h b/flang/include/flang/Optimizer/Support/InternalNames.h --- a/flang/include/flang/Optimizer/Support/InternalNames.h +++ b/flang/include/flang/Optimizer/Support/InternalNames.h @@ -32,6 +32,7 @@ /// The sort of the unique name enum class NameKind { NOT_UNIQUED, + BLOCK_DATA_NAME, COMMON, CONSTANT, DERIVED_TYPE, @@ -63,6 +64,9 @@ /// Unique a common block name std::string doCommonBlock(llvm::StringRef name); + /// Unique a block data unit name + std::string doBlockData(llvm::StringRef name); + /// Unique a (global) constant name std::string doConstant(llvm::ArrayRef modules, llvm::Optional host, diff --git a/flang/lib/Optimizer/Support/InternalNames.cpp b/flang/lib/Optimizer/Support/InternalNames.cpp --- a/flang/lib/Optimizer/Support/InternalNames.cpp +++ b/flang/lib/Optimizer/Support/InternalNames.cpp @@ -7,6 +7,8 @@ //===----------------------------------------------------------------------===// #include "flang/Optimizer/Support/InternalNames.h" +#include "flang/Optimizer/Dialect/FIRType.h" +#include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Diagnostics.h" #include "llvm/Support/CommandLine.h" @@ -97,6 +99,11 @@ return result.append("B").append(toLower(name)); } +std::string fir::NameUniquer::doBlockData(llvm::StringRef name) { + std::string result = prefix(); + return result.append("L").append(toLower(name)); +} + std::string fir::NameUniquer::doConstant(llvm::ArrayRef modules, llvm::Optional host, @@ -237,6 +244,10 @@ name = readName(uniq, i, i + 1, end); } break; + case 'L': + nk = NameKind::BLOCK_DATA_NAME; + name = readName(uniq, i, i + 1, end); + break; case 'P': nk = NameKind::PROCEDURE; name = readName(uniq, i, i + 1, end); diff --git a/flang/unittests/Optimizer/InternalNamesTest.cpp b/flang/unittests/Optimizer/InternalNamesTest.cpp --- a/flang/unittests/Optimizer/InternalNamesTest.cpp +++ b/flang/unittests/Optimizer/InternalNamesTest.cpp @@ -46,6 +46,16 @@ << "Possible error: DeconstructedName mismatch"; } +TEST(InternalNamesTest, doBlockDataTest) { + NameUniquer obj; + std::string actual = obj.doBlockData("blockdatatest"); + std::string actualBlank = obj.doBlockData(""); + std::string expectedMangledName = "_QLblockdatatest"; + std::string expectedMangledNameBlank = "_QL"; + ASSERT_EQ(actual, expectedMangledName); + ASSERT_EQ(actualBlank, expectedMangledNameBlank); +} + TEST(InternalNamesTest, doCommonBlockTest) { NameUniquer obj; std::string actual = obj.doCommonBlock("hello");