Skip to content

Commit 319e93c

Browse files
committed
Change signature of EmitAutoVarInit to not take variable, store state
inside AutoVarEmission instead.
1 parent 478331c commit 319e93c

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ bool CIRGenFunction::isTrivialInitializer(const Expr *init) {
7777
}
7878

7979
void CIRGenFunction::emitAutoVarInit(
80-
const CIRGenFunction::AutoVarEmission &emission, bool allocatedSeparately) {
80+
const CIRGenFunction::AutoVarEmission &emission) {
8181
assert(emission.Variable && "emission was not valid!");
8282

8383
// If this was emitted as a global constant, we're done.
@@ -154,16 +154,19 @@ void CIRGenFunction::emitAutoVarInit(
154154
initializeWhatIsTechnicallyUninitialized(addr);
155155
LValue lv = makeAddrLValue(addr, type, AlignmentSource::Decl);
156156
emitExprAsInit(init, &d, lv);
157-
// In case lv has uses it means we indeed initialized something
158-
// out of it while trying to build the expression, mark it as such.
159-
mlir::Value val = lv.getAddress().getPointer();
160-
assert(val && "Should have an address");
161-
auto allocaOp = val.getDefiningOp<cir::AllocaOp>();
162-
assert((allocatedSeparately || allocaOp) &&
163-
"Address should come straight out of the alloca");
164-
165-
if (allocaOp && !allocaOp.use_empty())
166-
allocaOp.setInitAttr(mlir::UnitAttr::get(&getMLIRContext()));
157+
158+
if (!emission.wasEmittedAsOffloadClause()) {
159+
// In case lv has uses it means we indeed initialized something
160+
// out of it while trying to build the expression, mark it as such.
161+
mlir::Value val = lv.getAddress().getPointer();
162+
assert(val && "Should have an address");
163+
auto allocaOp = val.getDefiningOp<cir::AllocaOp>();
164+
assert(allocaOp && "Address should come straight out of the alloca");
165+
166+
if (!allocaOp.use_empty())
167+
allocaOp.setInitAttr(mlir::UnitAttr::get(&getMLIRContext()));
168+
}
169+
167170
return;
168171
}
169172

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ class CIRGenFunction : public CIRGenTypeCache {
470470
/// escaping block.
471471
bool IsEscapingByRef = false;
472472

473+
/// True if the variable was emitted as an offload recipe, and thus doesn't
474+
/// have the same sort of alloca initialization.
475+
bool EmittedAsOffload = false;
476+
473477
mlir::Value NRVOFlag{};
474478

475479
struct Invalid {};
@@ -482,6 +486,8 @@ class CIRGenFunction : public CIRGenTypeCache {
482486

483487
bool wasEmittedAsGlobal() const { return !Addr.isValid(); }
484488

489+
bool wasEmittedAsOffloadClause() const { return EmittedAsOffload; }
490+
485491
/// Returns the raw, allocated address, which is not necessarily
486492
/// the address of the object itself. It is casted to default
487493
/// address space for address space agnostic languages.
@@ -978,8 +984,7 @@ class CIRGenFunction : public CIRGenTypeCache {
978984
/// emission is not directly an alloca), the allocatedSeparately parameter can
979985
/// be used to suppress the assertions. However, this should only be used in
980986
/// extreme cases, as it doesn't properly reflect the language/AST.
981-
void emitAutoVarInit(const AutoVarEmission &emission,
982-
bool allocatedSeparately = false);
987+
void emitAutoVarInit(const AutoVarEmission &emission);
983988
void emitAutoVarTypeCleanup(const AutoVarEmission &emission,
984989
clang::QualType::DestructionKind dtorKind);
985990

clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,13 @@ class OpenACCClauseCIREmitter final
407407
// that instead of the variable in the other block.
408408
tempDeclEmission.setAllocatedAddress(
409409
Address{toArg, elementTy, cgf.getContext().getDeclAlign(varRecipe)});
410+
tempDeclEmission.EmittedAsOffload = true;
410411

411412
cgf.setAddrOfLocalVar(
412413
temporary,
413414
Address{fromArg, elementTy, cgf.getContext().getDeclAlign(varRecipe)});
414415

415-
cgf.emitAutoVarInit(tempDeclEmission, /*allocatedSeparately=*/true);
416+
cgf.emitAutoVarInit(tempDeclEmission);
416417
mlir::acc::YieldOp::create(builder, locEnd);
417418
}
418419

0 commit comments

Comments
 (0)