[all-commits] [llvm/llvm-project] fb047e: [mlir][llvm] Type consistency transformations

Théo Degioanni via All-commits all-commits at lists.llvm.org
Mon Jul 3 02:14:10 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: fb047e4ae1b2a17ed068d560f94cc8e9fd94d0e6
      https://github.com/llvm/llvm-project/commit/fb047e4ae1b2a17ed068d560f94cc8e9fd94d0e6
  Author: Théo Degioanni <theo.degioanni at nextsilicon.com>
  Date:   2023-07-03 (Mon, 03 Jul 2023)

  Changed paths:
    M mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td
    M mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
    M mlir/include/mlir/Dialect/LLVMIR/Transforms/Passes.h
    M mlir/include/mlir/Dialect/LLVMIR/Transforms/Passes.td
    A mlir/include/mlir/Dialect/LLVMIR/Transforms/TypeConsistency.h
    M mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
    M mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp
    M mlir/lib/Dialect/LLVMIR/Transforms/CMakeLists.txt
    A mlir/lib/Dialect/LLVMIR/Transforms/TypeConsistency.cpp
    A mlir/test/Dialect/LLVMIR/type-consistency.mlir

  Log Message:
  -----------
  [mlir][llvm] Type consistency transformations

This revision introduces new rewrites to improve the type consistency of
a program expressed in the LLVM dialect.

Type consistency means that a given opaque pointer is consistently used
assuming the same pointee type, in a best effort basis. The introduced
rewrites modify the program to improve type consistency while preserving
the same semantics. This is useful for two main reasons:

- Transformation passes in the LLVM dialect like SROA or Mem2Reg can
  analyse code better if type information and structure is used in a
  consistent manner. Opaque pointers make this difficult to enforce, but
  type consistency improvements increase the amount of occurences where
  reasonable analysis can pick up on transformable patterns.
- While LLVM IR is not particularly picky about inconsistent type uses,
  it may be of interest to lift LLVM IR into higher level dialects.
  Having more instances of consistent type information would help
  lifting into dialects that do care about consistent types.

In order to detect cases of inconsistent uses, operations returning an
LLVMPointer can implement the GetResultPtrElementType interface, which
allows getting a hint of which type the provided pointer should see its
pointee as, if such hint is available. The provided rewrites will then
use this hint to attempt to modify operations using the pointers so they
use the hinted type when dealing with the pointer.

Two transformations have been implemented in this revision:

- When a load/store uses a struct ptr directly to write to the first
  element of the struct, introduce a GEP to the first element so the
  type structure is preserved.
- When a GEP statically indexes in a pointer with a base type
  inconsistent with the hint, try to find indices using the hint as a
  base type that would result in the same offset, and replace the GEP
  with this indexing.

More transformations are possible and I hope this is only a beginning
for this simplification effort.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D153973




More information about the All-commits mailing list