Skip to content
Merged
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
12 changes: 4 additions & 8 deletions clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,21 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {

cir::BoolAttr getFalseAttr() { return getCIRBoolAttr(false); }

mlir::TypedAttr getZeroAttr(mlir::Type t) {
return cir::ZeroAttr::get(getContext(), t);
}

mlir::TypedAttr getZeroInitAttr(mlir::Type ty) {
if (mlir::isa<cir::IntType>(ty))
return cir::IntAttr::get(ty, 0);
if (cir::isAnyFloatingPointType(ty))
return cir::FPAttr::getZero(ty);
if (auto complexType = mlir::dyn_cast<cir::ComplexType>(ty))
return getZeroAttr(complexType);
return cir::ZeroAttr::get(complexType);
if (auto arrTy = mlir::dyn_cast<cir::ArrayType>(ty))
return getZeroAttr(arrTy);
return cir::ZeroAttr::get(arrTy);
if (auto vecTy = mlir::dyn_cast<cir::VectorType>(ty))
return getZeroAttr(vecTy);
return cir::ZeroAttr::get(vecTy);
if (auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty))
return getConstNullPtrAttr(ptrTy);
if (auto RecordTy = mlir::dyn_cast<cir::RecordType>(ty))
return getZeroAttr(RecordTy);
return cir::ZeroAttr::get(RecordTy);
if (auto methodTy = mlir::dyn_cast<cir::MethodType>(ty))
return getNullMethodAttr(methodTy);
if (mlir::isa<cir::BoolType>(ty)) {
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ def ZeroAttr : CIR_Attr<"Zero", "zero", [TypedAttrInterface]> {
}];

let parameters = (ins AttributeSelfTypeParameter<"">:$type);

let builders = [
AttrBuilderWithInferredContext<(ins "mlir::Type":$type), [{
return $_get(type.getContext(), type);
}]>
];

let assemblyFormat = [{}];
}

Expand Down
6 changes: 3 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
// a #cir.const_array.
if (lastNonZeroPos == llvm::StringRef::npos) {
auto arrayTy = cir::ArrayType::get(eltTy, finalSize);
return getZeroAttr(arrayTy);
return cir::ZeroAttr::get(arrayTy);
}
// We will use trailing zeros only if there are more than one zero
// at the end
Expand Down Expand Up @@ -214,7 +214,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {

// Return zero or anonymous constant record.
if (isZero)
return cir::ZeroAttr::get(getContext(), recordTy);
return cir::ZeroAttr::get(recordTy);
return cir::ConstRecordAttr::get(recordTy, arrayAttr);
}

Expand Down Expand Up @@ -602,7 +602,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
assert((mlir::isa<cir::RecordType>(ty) || mlir::isa<cir::ArrayType>(ty) ||
mlir::isa<cir::VectorType>(ty)) &&
"NYI for other types");
return create<cir::ConstantOp>(loc, ty, getZeroAttr(ty));
return create<cir::ConstantOp>(loc, ty, cir::ZeroAttr::get(ty));
}

//
Expand Down
7 changes: 3 additions & 4 deletions clang/lib/CIR/CodeGen/CIRGenExprConst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ static mlir::TypedAttr computePadding(CIRGenModule &CGM, CharUnits size) {
auto arSize = size.getQuantity();
auto &bld = CGM.getBuilder();
if (size > CharUnits::One()) {
SmallVector<mlir::Attribute, 4> elts(arSize, bld.getZeroAttr(eltTy));
SmallVector<mlir::Attribute, 4> elts(arSize, cir::ZeroAttr::get(eltTy));
return bld.getConstArray(mlir::ArrayAttr::get(bld.getContext(), elts),
cir::ArrayType::get(eltTy, arSize));
} else {
return cir::ZeroAttr::get(bld.getContext(), eltTy);
return cir::ZeroAttr::get(eltTy);
}
}

Expand Down Expand Up @@ -1726,8 +1726,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &D) {
// assignments and whatnots). Since this is for globals shouldn't
// be a problem for the near future.
if (CD->isTrivial() && CD->isDefaultConstructor())
return cir::ZeroAttr::get(CGM.getBuilder().getContext(),
CGM.convertType(D.getType()));
return cir::ZeroAttr::get(CGM.convertType(D.getType()));
}
}
InConstantContext = D.hasConstantInitialization();
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ class CIRGenFunction : public CIRGenTypeCache {
bool isReference() const { return ValueAndIsReference.getInt(); }
LValue getReferenceLValue(CIRGenFunction &CGF, Expr *refExpr) const {
assert(isReference());
// create<cir::ConstantOp>(loc, ty, getZeroAttr(ty));
// create<cir::ConstantOp>(loc, ty, cir::ZeroAttr::get(ty));
// CGF.getBuilder().const
// return CGF.MakeNaturalAlignAddrLValue(ValueAndIsReference.getPointer(),
// refExpr->getType());
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ CIRGenModule::getConstantArrayFromStringLiteral(const StringLiteral *e) {
// If the string is full of null bytes, emit a #cir.zero instead.
if (std::all_of(elementValues.begin(), elementValues.end(),
[](uint32_t x) { return x == 0; }))
return builder.getZeroAttr(arrayTy);
return cir::ZeroAttr::get(arrayTy);

// Otherwise emit a constant array holding the characters.
SmallVector<mlir::Attribute, 32> elements;
Expand Down
Loading