[all-commits] [llvm/llvm-project] 80f881: [LLVM] Add InsertPosition union-type to remove ove...

Stephen Tozer via All-commits all-commits at lists.llvm.org
Thu Jun 20 02:28:17 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 80f881485accb020345ee7e1c4c3151ec55ce590
      https://github.com/llvm/llvm-project/commit/80f881485accb020345ee7e1c4c3151ec55ce590
  Author: Stephen Tozer <stephen.tozer at sony.com>
  Date:   2024-06-20 (Thu, 20 Jun 2024)

  Changed paths:
    M clang/lib/CodeGen/CGBuilder.h
    M clang/lib/CodeGen/CGExpr.cpp
    M clang/lib/CodeGen/CodeGenFunction.cpp
    M clang/lib/CodeGen/CodeGenFunction.h
    M llvm/include/llvm/IR/IRBuilder.h
    M llvm/include/llvm/IR/InstrTypes.h
    M llvm/include/llvm/IR/Instruction.h
    M llvm/include/llvm/IR/Instructions.h
    M llvm/lib/IR/Instruction.cpp
    M llvm/lib/IR/Instructions.cpp
    M llvm/lib/Transforms/Scalar/SROA.cpp
    M polly/include/polly/CodeGen/IRBuilder.h

  Log Message:
  -----------
  [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (#94226)

This patch simplifies instruction creation by replacing all overloads of
instruction constructors/Create methods that are identical other than
the Instruction *InsertBefore/BasicBlock *InsertAtEnd/BasicBlock::iterator
InsertBefore argument with a single version that takes an InsertPosition
argument. The InsertPosition class can be implicitly constructed from
any of the above, internally converting them to the appropriate
BasicBlock::iterator value which can then be used to insert the
instruction (or to not insert it if an invalid iterator is passed).

The upshot of this is that code will be deduplicated, and all callsites
will switch to calling the new unified version without any changes
needed to make the compiler happy. There is at least one exception to
this; the construction of InsertPosition is a user-defined conversion,
so any caller that was already relying on a different user-defined
conversion won't work. In all of LLVM and Clang this happens exactly
once: at clang/lib/CodeGen/CGExpr.cpp:123 we try to construct an alloca
with an AssertingVH<Instruction> argument, which must now be cast to an
Instruction* by using `&*`. If this is more common elsewhere, it could
be fixed by adding an appropriate constructor to InsertPosition.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list