Author: Orlando Cazalet-Hyams Date: 2025-04-08T08:44:10+01:00 New Revision: 308654608cb8bc5bbd5d4b3779cb7d92920dd6b7
URL: https://github.com/llvm/llvm-project/commit/308654608cb8bc5bbd5d4b3779cb7d92920dd6b7 DIFF: https://github.com/llvm/llvm-project/commit/308654608cb8bc5bbd5d4b3779cb7d92920dd6b7.diff LOG: [Clang][NFC] Move some static functions into CodeGenFunction (#134634) Patches in the Key Instructions (KeyInstr) stack need to access CGF in these functions. 2 CGF fields are passed to these functions already; at this point it felt natural to promote them to CGF methods. Added: Modified: clang/lib/CodeGen/CGDecl.cpp clang/lib/CodeGen/CodeGenFunction.h Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index eab1ebfb2369b..0af170a36f372 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -928,10 +928,9 @@ static bool canEmitInitWithFewStoresAfterBZero(llvm::Constant *Init, /// For inits that canEmitInitWithFewStoresAfterBZero returned true for, emit /// the scalar stores that would be required. -static void emitStoresForInitAfterBZero(CodeGenModule &CGM, - llvm::Constant *Init, Address Loc, - bool isVolatile, CGBuilderTy &Builder, - bool IsAutoInit) { +void CodeGenFunction::emitStoresForInitAfterBZero(llvm::Constant *Init, + Address Loc, bool isVolatile, + bool IsAutoInit) { assert(!Init->isNullValue() && !isa<llvm::UndefValue>(Init) && "called emitStoresForInitAfterBZero for zero or undef value."); @@ -952,8 +951,8 @@ static void emitStoresForInitAfterBZero(CodeGenModule &CGM, // If necessary, get a pointer to the element and emit it. if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt)) emitStoresForInitAfterBZero( - CGM, Elt, Builder.CreateConstInBoundsGEP2_32(Loc, 0, i), isVolatile, - Builder, IsAutoInit); + Elt, Builder.CreateConstInBoundsGEP2_32(Loc, 0, i), isVolatile, + IsAutoInit); } return; } @@ -966,9 +965,9 @@ static void emitStoresForInitAfterBZero(CodeGenModule &CGM, // If necessary, get a pointer to the element and emit it. if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt)) - emitStoresForInitAfterBZero(CGM, Elt, + emitStoresForInitAfterBZero(Elt, Builder.CreateConstInBoundsGEP2_32(Loc, 0, i), - isVolatile, Builder, IsAutoInit); + isVolatile, IsAutoInit); } } @@ -1169,10 +1168,10 @@ static Address createUnnamedGlobalForMemcpyFrom(CodeGenModule &CGM, return SrcPtr.withElementType(CGM.Int8Ty); } -static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D, - Address Loc, bool isVolatile, - CGBuilderTy &Builder, - llvm::Constant *constant, bool IsAutoInit) { +void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc, + bool isVolatile, + llvm::Constant *constant, + bool IsAutoInit) { auto *Ty = constant->getType(); uint64_t ConstantSize = CGM.getDataLayout().getTypeAllocSize(Ty); if (!ConstantSize) @@ -1201,8 +1200,7 @@ static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D, constant->isNullValue() || isa<llvm::UndefValue>(constant); if (!valueAlreadyCorrect) { Loc = Loc.withElementType(Ty); - emitStoresForInitAfterBZero(CGM, constant, Loc, isVolatile, Builder, - IsAutoInit); + emitStoresForInitAfterBZero(constant, Loc, isVolatile, IsAutoInit); } return; } @@ -1240,7 +1238,7 @@ static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D, CharUnits::fromQuantity(Layout->getElementOffset(i)); Address EltPtr = Builder.CreateConstInBoundsByteGEP( Loc.withElementType(CGM.Int8Ty), CurOff); - emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder, + emitStoresForConstant(D, EltPtr, isVolatile, constant->getAggregateElement(i), IsAutoInit); } return; @@ -1251,7 +1249,7 @@ static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D, for (unsigned i = 0; i != ATy->getNumElements(); i++) { Address EltPtr = Builder.CreateConstGEP( Loc.withElementType(ATy->getElementType()), i); - emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder, + emitStoresForConstant(D, EltPtr, isVolatile, constant->getAggregateElement(i), IsAutoInit); } return; @@ -1269,24 +1267,22 @@ static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D, I->addAnnotationMetadata("auto-init"); } -static void emitStoresForZeroInit(CodeGenModule &CGM, const VarDecl &D, - Address Loc, bool isVolatile, - CGBuilderTy &Builder) { +void CodeGenFunction::emitStoresForZeroInit(const VarDecl &D, Address Loc, + bool isVolatile) { llvm::Type *ElTy = Loc.getElementType(); llvm::Constant *constant = constWithPadding(CGM, IsPattern::No, llvm::Constant::getNullValue(ElTy)); - emitStoresForConstant(CGM, D, Loc, isVolatile, Builder, constant, + emitStoresForConstant(D, Loc, isVolatile, constant, /*IsAutoInit=*/true); } -static void emitStoresForPatternInit(CodeGenModule &CGM, const VarDecl &D, - Address Loc, bool isVolatile, - CGBuilderTy &Builder) { +void CodeGenFunction::emitStoresForPatternInit(const VarDecl &D, Address Loc, + bool isVolatile) { llvm::Type *ElTy = Loc.getElementType(); llvm::Constant *constant = constWithPadding( CGM, IsPattern::Yes, initializationPatternFor(CGM, ElTy)); assert(!isa<llvm::UndefValue>(constant)); - emitStoresForConstant(CGM, D, Loc, isVolatile, Builder, constant, + emitStoresForConstant(D, Loc, isVolatile, constant, /*IsAutoInit=*/true); } @@ -1829,7 +1825,7 @@ void CodeGenFunction::emitZeroOrPatternForAutoVarInit(QualType type, if (trivialAutoVarInitMaxSize > 0 && allocSize > trivialAutoVarInitMaxSize) return; - emitStoresForZeroInit(CGM, D, Loc, isVolatile, Builder); + emitStoresForZeroInit(D, Loc, isVolatile); break; case LangOptions::TrivialAutoVarInitKind::Pattern: if (CGM.stopAutoInit()) @@ -1837,7 +1833,7 @@ void CodeGenFunction::emitZeroOrPatternForAutoVarInit(QualType type, if (trivialAutoVarInitMaxSize > 0 && allocSize > trivialAutoVarInitMaxSize) return; - emitStoresForPatternInit(CGM, D, Loc, isVolatile, Builder); + emitStoresForPatternInit(D, Loc, isVolatile); break; } return; @@ -2052,8 +2048,8 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) { return EmitStoreThroughLValue(RValue::get(constant), lv, true); } - emitStoresForConstant(CGM, D, Loc.withElementType(CGM.Int8Ty), - type.isVolatileQualified(), Builder, constant, + emitStoresForConstant(D, Loc.withElementType(CGM.Int8Ty), + type.isVolatileQualified(), constant, /*IsAutoInit=*/false); } diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 34dee6df9dcfc..2b1062d6d307c 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -2800,6 +2800,17 @@ class CodeGenFunction : public CodeGenTypeCache { }; AllocaTracker *Allocas = nullptr; + /// CGDecl helper. + void emitStoresForConstant(const VarDecl &D, Address Loc, bool isVolatile, + llvm::Constant *constant, bool IsAutoInit); + /// CGDecl helper. + void emitStoresForZeroInit(const VarDecl &D, Address Loc, bool isVolatile); + /// CGDecl helper. + void emitStoresForPatternInit(const VarDecl &D, Address Loc, bool isVolatile); + /// CGDecl helper. + void emitStoresForInitAfterBZero(llvm::Constant *Init, Address Loc, + bool isVolatile, bool IsAutoInit); + public: // Captures all the allocas created during the scope of its RAII object. struct AllocaTrackerRAII { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits