Index: flang/include/flang/Optimizer/Support/InternalNames.h =================================================================== --- flang/include/flang/Optimizer/Support/InternalNames.h +++ 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, Index: flang/lib/Optimizer/Support/InternalNames.cpp =================================================================== --- flang/lib/Optimizer/Support/InternalNames.cpp +++ flang/lib/Optimizer/Support/InternalNames.cpp @@ -7,7 +7,9 @@ //===----------------------------------------------------------------------===// #include "flang/Optimizer/Support/InternalNames.h" +#include "flang/Optimizer/Dialect/FIRType.h" #include "mlir/IR/Diagnostics.h" +#include "mlir/IR/BuiltinTypes.h" #include "llvm/Support/CommandLine.h" static llvm::cl::opt mainEntryName( @@ -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); Index: flang/unittests/Optimizer/InternalNamesTest.cpp =================================================================== --- flang/unittests/Optimizer/InternalNamesTest.cpp +++ 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");