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
The next level applied frontend-specified alignment to the alloca and
returned an address, but left the value in the alloca address space (2):
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):
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
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
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.