Skip to content

Commit 2d5a287

Browse files
authored
[CIR] Make UndefAttr use AttrBuilderWithInferredContext (#1577)
1 parent 099c13c commit 2d5a287

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,13 @@ def UndefAttr : CIR_Attr<"Undef", "undef", [TypedAttrInterface]> {
246246
}];
247247

248248
let parameters = (ins AttributeSelfTypeParameter<"">:$type);
249+
250+
let builders = [
251+
AttrBuilderWithInferredContext<(ins "mlir::Type":$type), [{
252+
return $_get(type.getContext(), type);
253+
}]>
254+
];
255+
249256
let assemblyFormat = [{}];
250257
}
251258

clang/lib/CIR/CodeGen/CIRGenExprConst.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ mlir::Attribute ConstantAggregateBuilder::buildFrom(
353353
ConstantAggregateBuilderUtils Utils(CGM);
354354

355355
if (Elems.empty())
356-
return cir::UndefAttr::get(CGM.getBuilder().getContext(), DesiredTy);
356+
return cir::UndefAttr::get(DesiredTy);
357357

358358
auto Offset = [&](size_t I) { return Offsets[I] - StartOffset; };
359359

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *d,
14131413
d->getType()->isCUDADeviceBuiltinTextureType());
14141414
if (getLangOpts().CUDA &&
14151415
(isCudaSharedVar || isCudaShadowVar || isCudaDeviceShadowVar))
1416-
init = UndefAttr::get(&getMLIRContext(), convertType(d->getType()));
1416+
init = cir::UndefAttr::get(convertType(d->getType()));
14171417
else if (d->hasAttr<LoaderUninitializedAttr>())
14181418
assert(0 && "not implemented");
14191419
else if (!initExpr) {

clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ llvm::SmallVector<MemorySlot> cir::AllocaOp::getPromotableSlots() {
4343

4444
Value cir::AllocaOp::getDefaultValue(const MemorySlot &slot,
4545
OpBuilder &builder) {
46-
return builder.create<cir::ConstantOp>(
47-
getLoc(), slot.elemType, builder.getAttr<cir::UndefAttr>(slot.elemType));
46+
return builder.create<cir::ConstantOp>(getLoc(), slot.elemType,
47+
cir::UndefAttr::get(slot.elemType));
4848
}
4949

5050
void cir::AllocaOp::handleBlockArgument(const MemorySlot &slot,

0 commit comments

Comments
 (0)