[PATCH] D108464: [clang][CodeGen] Refactor CreateTempAlloca function nest. NFC.

Andy Wingo via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 20 06:01:34 PDT 2021


wingo created this revision.
wingo added a reviewer: rjmccall.
Herald added subscribers: lxfind, sunfish, dschuff.
wingo requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1, aheejin.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

It used to be that there were three layers to create temp alloca
instructions in CodeGenFunction.  The lowest level was named
CreateTempAlloca and returned an LLVM instruction (1):

  llvm::AllocaInst* CreateTempAlloca(llvm::Type *Ty);

(Leaving off the name argument and array size from the prototype, for
brevity.)

The next level applied frontend-specified alignment to the alloca and
returned an address, but left the value in the alloca address space (2):

  Address
  CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits Align);

Finally the normal function returns an Address, but also makes sure that
the result is in LangAS::Default (3):

  Address
  CreateTempAlloca(QualType Ty, CharUnits Align);

This is a bit confusing since functions (1) and (3) share a name but
have different behavior, and function (2) has a funny name.
Furthermore, the implementation of function (2) actually calls
function (1), making it seem to the reader like there is a loop in the
call graph.

This patch refactors to remove function (1) and replace code that uses
it with calls to function (2), returning an Address instead of an IR
instruction.  This also removes some places in which the frontend wasn't
specifying the alignment of its allocas.

This patch also changes function (2) to explicitly take an address space
argument, which should generally be the alloca address space.  There is
usually one target-specified alloca address space, but in the future,
the WebAssembly target may alloca variables in multiple address spaces.
The function name is changed from CreateTempAllocaWithoutCast to
CreateTempAllocaInAS, indicating that the result is left in the given
AS.

Finally, we also replace uses of the somewhat-deprecated
CreateDefaultAlignTempAlloca with CreateTempAllocaInAS, passing the
result of calling the new CodeGenFunction::PreferredAlignmentForIRType
method as the alignnment.

As a result of this patch, a number of llvm::Value* variables are
changed to be Address instead.  This allows a more simplified codegen,
as the IR builder doesn't need to take an additional alignment argument.

Depends on D108459 <https://reviews.llvm.org/D108459>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108464

Files:
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGCleanup.cpp
  clang/lib/CodeGen/CGCoroutine.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGGPUBuiltin.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108464.367775.patch
Type: text/x-patch
Size: 40553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210820/11cff1f3/attachment-0001.bin>


More information about the cfe-commits mailing list