[clang] 2cfb027 - [CodeGen][NFC] Add a helper function that returns the addresses of
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 15 15:59:29 PDT 2020
Author: Akira Hatanaka
Date: 2020-06-15T15:59:16-07:00
New Revision: 2cfb027369e6e297c2dee70e56ec384afe883ec3
URL: https://github.com/llvm/llvm-project/commit/2cfb027369e6e297c2dee70e56ec384afe883ec3
DIFF: https://github.com/llvm/llvm-project/commit/2cfb027369e6e297c2dee70e56ec384afe883ec3.diff
LOG: [CodeGen][NFC] Add a helper function that returns the addresses of
parameters of non-trivial C struct special functions
This removes the need to pass std::array of Addresses to getFunction,
which were overwritten in the function.
Added:
Modified:
clang/lib/CodeGen/CGNonTrivialStruct.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGNonTrivialStruct.cpp b/clang/lib/CodeGen/CGNonTrivialStruct.cpp
index 4a2c3b290382..73188c48e885 100644
--- a/clang/lib/CodeGen/CGNonTrivialStruct.cpp
+++ b/clang/lib/CodeGen/CGNonTrivialStruct.cpp
@@ -321,6 +321,16 @@ static const CGFunctionInfo &getFunctionInfo(CodeGenModule &CGM,
return CGM.getTypes().arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Args);
}
+template <size_t N, size_t... Ints>
+static std::array<Address, N> getParamAddrs(std::index_sequence<Ints...> IntSeq,
+ std::array<CharUnits, N> Alignments,
+ FunctionArgList Args,
+ CodeGenFunction *CGF) {
+ return std::array<Address, N>{
+ Address(CGF->Builder.CreateLoad(CGF->GetAddrOfLocalVar(Args[Ints])),
+ Alignments[Ints])...};
+}
+
// Template classes that are used as bases for classes that emit special
// functions.
template <class Derived> struct GenFuncBase {
@@ -428,9 +438,9 @@ template <class Derived> struct GenFuncBase {
}
template <size_t N>
- llvm::Function *
- getFunction(StringRef FuncName, QualType QT, std::array<Address, N> Addrs,
- std::array<CharUnits, N> Alignments, CodeGenModule &CGM) {
+ llvm::Function *getFunction(StringRef FuncName, QualType QT,
+ std::array<CharUnits, N> Alignments,
+ CodeGenModule &CGM) {
// If the special function already exists in the module, return it.
if (llvm::Function *F = CGM.getModule().getFunction(FuncName)) {
bool WrongType = false;
@@ -470,12 +480,8 @@ template <class Derived> struct GenFuncBase {
CodeGenFunction NewCGF(CGM);
setCGF(&NewCGF);
CGF->StartFunction(FD, Ctx.VoidTy, F, FI, Args);
-
- for (unsigned I = 0; I < N; ++I) {
- llvm::Value *V = CGF->Builder.CreateLoad(CGF->GetAddrOfLocalVar(Args[I]));
- Addrs[I] = Address(V, Alignments[I]);
- }
-
+ std::array<Address, N> Addrs =
+ getParamAddrs<N>(std::make_index_sequence<N>{}, Alignments, Args, CGF);
asDerived().visitStructFields(QT, CharUnits::Zero(), Addrs);
CGF->FinishFunction();
return F;
@@ -495,7 +501,7 @@ template <class Derived> struct GenFuncBase {
}
if (llvm::Function *F =
- getFunction(FuncName, QT, Addrs, Alignments, CallerCGF.CGM))
+ getFunction(FuncName, QT, Alignments, CallerCGF.CGM))
CallerCGF.EmitNounwindRuntimeCall(F, Ptrs);
}
@@ -833,17 +839,6 @@ static void callSpecialFunction(G &&Gen, StringRef FuncName, QualType QT,
Gen.callFunc(FuncName, QT, Addrs, CGF);
}
-template <size_t N> static std::array<Address, N> createNullAddressArray();
-
-template <> std::array<Address, 1> createNullAddressArray() {
- return std::array<Address, 1>({{Address(nullptr, CharUnits::Zero())}});
-}
-
-template <> std::array<Address, 2> createNullAddressArray() {
- return std::array<Address, 2>({{Address(nullptr, CharUnits::Zero()),
- Address(nullptr, CharUnits::Zero())}});
-}
-
template <class G, size_t N>
static llvm::Function *
getSpecialFunction(G &&Gen, StringRef FuncName, QualType QT, bool IsVolatile,
@@ -852,8 +847,7 @@ getSpecialFunction(G &&Gen, StringRef FuncName, QualType QT, bool IsVolatile,
// The following call requires an array of addresses as arguments, but doesn't
// actually use them (it overwrites them with the addresses of the arguments
// of the created function).
- return Gen.getFunction(FuncName, QT, createNullAddressArray<N>(), Alignments,
- CGM);
+ return Gen.getFunction(FuncName, QT, Alignments, CGM);
}
// Functions to emit calls to the special functions of a non-trivial C struct.
More information about the cfe-commits
mailing list