Skip to content

[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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 24 additions & 28 deletions clang/lib/CodeGen/CGDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");

Expand All @@ -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;
}
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -1829,15 +1825,15 @@ 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())
return;
if (trivialAutoVarInitMaxSize > 0 &&
allocSize > trivialAutoVarInitMaxSize)
return;
emitStoresForPatternInit(CGM, D, Loc, isVolatile, Builder);
emitStoresForPatternInit(D, Loc, isVolatile);
break;
}
return;
Expand Down Expand Up @@ -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);
}

Expand Down
11 changes: 11 additions & 0 deletions clang/lib/CodeGen/CodeGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading