From 2cce0771b08e107667ffd59693fcc31e731e243e Mon Sep 17 00:00:00 2001 From: Magnus Sjalander Date: Sat, 12 Sep 2026 21:26:02 +0200 Subject: [PATCH 1/2] MLIR: Handle linkage for LambdaNode --- jlm/mlir/RvsdgRoundtripTests.cpp | 2 ++ jlm/mlir/frontend/MlirToJlmConverter.cpp | 16 ++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/jlm/mlir/RvsdgRoundtripTests.cpp b/jlm/mlir/RvsdgRoundtripTests.cpp index 7c9429e4e..82fa0c64e 100644 --- a/jlm/mlir/RvsdgRoundtripTests.cpp +++ b/jlm/mlir/RvsdgRoundtripTests.cpp @@ -683,6 +683,8 @@ ROUNDTRIP_TEST(TestVariadicFunctionTest1, ::jlm::llvm::VariadicFunctionTest1) ROUNDTRIP_TEST(TestVariadicFunctionTest2, ::jlm::llvm::VariadicFunctionTest2) ROUNDTRIP_TEST(TestGamma, ::jlm::llvm::GammaTest) ROUNDTRIP_TEST(TestImport, ::jlm::llvm::ImportTest) +ROUNDTRIP_TEST(TestEscapingLocalFunction, ::jlm::llvm::EscapingLocalFunctionTest) +ROUNDTRIP_TEST(TestLambdaCallArgumentMismatch, ::jlm::llvm::LambdaCallArgumentMismatch) // NAllocaNodesTest is parameterized by the number of allocas, so it cannot use the // default-constructing ROUNDTRIP_TEST macro. diff --git a/jlm/mlir/frontend/MlirToJlmConverter.cpp b/jlm/mlir/frontend/MlirToJlmConverter.cpp index 912a37c16..8d25ffc36 100644 --- a/jlm/mlir/frontend/MlirToJlmConverter.cpp +++ b/jlm/mlir/frontend/MlirToJlmConverter.cpp @@ -1213,14 +1213,18 @@ MlirToJlmConverter::ConvertLambda( } auto functionType = rvsdg::FunctionType::Create(std::move(argumentTypes), std::move(resultTypes)); - // FIXME - // The linkage should be part of the MLIR attributes so it can be extracted here + // Get the linkage attribute from the MLIR LambdaNode + auto linkage = llvm::Linkage::externalLinkage; // Default to external linkage + auto linkageAttribute = mlirOperation.getAttr(::llvm::StringRef("linkage")); + if (linkageAttribute != nullptr) + { + auto linkageStr = ::mlir::cast<::mlir::StringAttr>(linkageAttribute); + linkage = llvm::linkageFromString(linkageStr.str()); + } + auto rvsdgLambda = rvsdg::LambdaNode::Create( rvsdgRegion, - llvm::LlvmLambdaOperation::Create( - functionType, - functionName.getValue().str(), - llvm::Linkage::externalLinkage)); + llvm::LlvmLambdaOperation::Create(functionType, functionName.getValue().str(), linkage)); for (auto input : inputs) { From 19489ff2326a71e2b77cd87d2088341c82f0b394 Mon Sep 17 00:00:00 2001 From: Magnus Sjalander Date: Wed, 16 Sep 2026 16:19:48 +0200 Subject: [PATCH 2/2] Always require linkage --- jlm/mlir/frontend/MlirToJlmConverter.cpp | 9 +++---- jlm/mlir/frontend/MlirToJlmConverterTests.cpp | 25 ++++++++++++++++++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/jlm/mlir/frontend/MlirToJlmConverter.cpp b/jlm/mlir/frontend/MlirToJlmConverter.cpp index 936a671c9..b183abf0d 100644 --- a/jlm/mlir/frontend/MlirToJlmConverter.cpp +++ b/jlm/mlir/frontend/MlirToJlmConverter.cpp @@ -1224,13 +1224,10 @@ MlirToJlmConverter::ConvertLambda( auto functionType = rvsdg::FunctionType::Create(std::move(argumentTypes), std::move(resultTypes)); // Get the linkage attribute from the MLIR LambdaNode - auto linkage = llvm::Linkage::externalLinkage; // Default to external linkage auto linkageAttribute = mlirOperation.getAttr(::llvm::StringRef("linkage")); - if (linkageAttribute != nullptr) - { - auto linkageStr = ::mlir::cast<::mlir::StringAttr>(linkageAttribute); - linkage = llvm::linkageFromString(linkageStr.str()); - } + JLM_ASSERT(linkageAttribute != nullptr); + auto linkageStr = ::mlir::cast<::mlir::StringAttr>(linkageAttribute); + auto linkage = llvm::linkageFromString(linkageStr.str()); auto rvsdgLambda = rvsdg::LambdaNode::Create( rvsdgRegion, diff --git a/jlm/mlir/frontend/MlirToJlmConverterTests.cpp b/jlm/mlir/frontend/MlirToJlmConverterTests.cpp index 0d603b8cd..b4885a045 100644 --- a/jlm/mlir/frontend/MlirToJlmConverterTests.cpp +++ b/jlm/mlir/frontend/MlirToJlmConverterTests.cpp @@ -57,6 +57,10 @@ TEST(MlirToJlmConverterTests, TestLambda) auto attributeValue = Builder_->getStringAttr("test"); auto symbolName = Builder_->getNamedAttr(attributeName, attributeValue); attributes.push_back(symbolName); + auto linkageName = Builder_->getStringAttr("linkage"); + auto linkageValue = Builder_->getStringAttr("external_linkage"); + auto linkage = Builder_->getNamedAttr(linkageName, linkageValue); + attributes.push_back(linkage); ::llvm::ArrayRef<::mlir::NamedAttribute> attributesRef(attributes); // Add inputs to the function @@ -185,6 +189,10 @@ TEST(MlirToJlmConverterTests, TestDivOperation) auto attributeValue = Builder_->getStringAttr("test"); auto symbolName = Builder_->getNamedAttr(attributeName, attributeValue); attributes.push_back(symbolName); + auto linkageName = Builder_->getStringAttr("linkage"); + auto linkageValue = Builder_->getStringAttr("external_linkage"); + auto linkage = Builder_->getNamedAttr(linkageName, linkageValue); + attributes.push_back(linkage); ::llvm::ArrayRef<::mlir::NamedAttribute> attributesRef(attributes); // Add inputs to the function @@ -377,6 +385,10 @@ TEST(MlirToJlmConverterTests, TestCompZeroExt) auto attributeValue = Builder_->getStringAttr("test"); auto symbolName = Builder_->getNamedAttr(attributeName, attributeValue); attributes.push_back(symbolName); + auto linkageName = Builder_->getStringAttr("linkage"); + auto linkageValue = Builder_->getStringAttr("external_linkage"); + auto linkage = Builder_->getNamedAttr(linkageName, linkageValue); + attributes.push_back(linkage); ::llvm::ArrayRef<::mlir::NamedAttribute> attributesRef(attributes); // Add inputs to the function @@ -601,6 +613,10 @@ TEST(MlirToJlmConverterTests, TestMatchOp) auto attributeValue = Builder_->getStringAttr("test"); auto symbolName = Builder_->getNamedAttr(attributeName, attributeValue); attributes.push_back(symbolName); + auto linkageName = Builder_->getStringAttr("linkage"); + auto linkageValue = Builder_->getStringAttr("external_linkage"); + auto linkage = Builder_->getNamedAttr(linkageName, linkageValue); + attributes.push_back(linkage); ::llvm::ArrayRef<::mlir::NamedAttribute> attributesRef(attributes); // Add inputs to the function @@ -773,6 +789,10 @@ TEST(MlirToJlmConverterTests, TestGammaOp) auto attributeValue = Builder_->getStringAttr("test"); auto symbolName = Builder_->getNamedAttr(attributeName, attributeValue); attributes.push_back(symbolName); + auto linkageName = Builder_->getStringAttr("linkage"); + auto linkageValue = Builder_->getStringAttr("external_linkage"); + auto linkage = Builder_->getNamedAttr(linkageName, linkageValue); + attributes.push_back(linkage); ::llvm::ArrayRef<::mlir::NamedAttribute> attributesRef(attributes); // Add inputs to the function @@ -925,6 +945,9 @@ TEST(MlirToJlmConverterTests, TestThetaOp) auto attributeName = Builder_->getStringAttr("sym_name"); auto attributeValue = Builder_->getStringAttr("test"); auto symbolName = Builder_->getNamedAttr(attributeName, attributeValue); + auto linkageName = Builder_->getStringAttr("linkage"); + auto linkageValue = Builder_->getStringAttr("external_linkage"); + auto linkage = Builder_->getNamedAttr(linkageName, linkageValue); auto iotype = Builder_->getType(); auto memtype = Builder_->getType(); @@ -937,7 +960,7 @@ TEST(MlirToJlmConverterTests, TestThetaOp) ::mlir::TypeRange({ iotype, memtype }), ::mlir::TypeRange({ iotype, memtype })), ::llvm::SmallVector(), - ::llvm::ArrayRef<::mlir::NamedAttribute>({ symbolName })); + ::llvm::ArrayRef<::mlir::NamedAttribute>({ symbolName, linkage })); omegaBlock->push_back(lambda); auto & lambdaRegion = lambda.getRegion(); auto * lambdaBlock = new mlir::Block;