-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[Clang][NFC] Move some static functions into CodeGenFunction #134634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang][NFC] Move some static functions into CodeGenFunction #134634
Conversation
The next patch in the stack needs 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.
@llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-clang Author: Orlando Cazalet-Hyams (OCHyams) ChangesThe next patch in the stack needs to access CGF in these functions. 2 Full diff: https://github.com/llvm/llvm-project/pull/134634.diff 2 Files Affected:
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 96d217b0a13cc..6aa9f3fa27c87 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;
@@ -2053,8 +2049,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 0c0019fbea5ea..d8b1c4e4efb77 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -2838,6 +2838,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 {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.
Thanks for the review. Landed in 3086546 (sorry for the additional noise, I'm still getting to grips with Graphite, plus this patch isn't actually dependant on its parent in the stack). |
…4634) 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.
…4634) 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.
The next patch in the stack needs 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.