Skip to content

Conversation

fabianmcg
Copy link
Contributor

This patch changes the behavior of convert-to-llvm{dynamic=true} so that the nearest DataLayout is used to configure LowerToLLVMOptions and LLVMTypeConverter.

Example:

module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<index, 16>>} {
  func.func private @test_16bit_index(%arg0: index) -> index
}
// mlir-opt --convert-to-llvm="dynamic=true"
module attributes {dlti.dl_spec = #dlti.dl_spec<index = 16 : i64>} {
  llvm.func @test_16bit_index(i16) -> i16 attributes {sym_visibility = "private"}
}

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This patch fixes the handling of index bitwidth in the dynamic case of the convert-to-llvm pass by ensuring the nearest DataLayout is used to configure LowerToLLVMOptions and LLVMTypeConverter. This enables proper type conversion of index types based on the data layout specification.

  • Updates the DynamicConvertToLLVM implementation to use DataLayout-aware LowerToLLVMOptions
  • Adds test coverage for various index bitwidths (16, 32, 64) with dynamic conversion

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
mlir/lib/Conversion/ConvertToLLVM/ConvertToLLVMPass.cpp Updated to extract DataLayout and create LowerToLLVMOptions with proper index bitwidth configuration
mlir/test/Conversion/FuncToLLVM/func-to-llvm-datalayout.mlir Added comprehensive test cases verifying correct index type conversion for different bitwidths

@fabianmcg fabianmcg requested a review from zero9178 September 3, 2025 10:54
Copy link
Member

@zero9178 zero9178 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me as if the same logic is required in the static driver as well. Would it make sense to run the test with both "dynamic=true" and false?

Approving otherwise, feel free to defer to the future if youd like :)

@fabianmcg
Copy link
Contributor Author

fabianmcg commented Sep 3, 2025

This fix doesn't work for the static case as the TypeConverter is created at pass initialization, which doesn't know on which op is being run on, so it's not possible to get the DataLayout to configure the converter.

@fabianmcg fabianmcg merged commit 298764a into llvm:main Sep 3, 2025
10 checks passed
@zero9178
Copy link
Member

zero9178 commented Sep 3, 2025

This fix doesn't work for the static case as the TypeConverter is created at pass initialization, which doesn't know on which op is being run on, so it's not possible to get the DataLayout to configure the converter.

Is it necessary in the static case for it be performed at pass initialization though?

@fabianmcg
Copy link
Contributor Author

fabianmcg commented Sep 3, 2025

Is it necessary in the static case for it be performed at pass initialization though?

It was a performance constraint, that's also why the dynamic version was introduced. However, if I recall correctly @joker-eph we discussed the possibility to remove the static version, right?

@joker-eph
Copy link
Collaborator

Right!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants