Skip to content

Commit

Permalink
use mlir::IntegerType as the type for the #cir.ptr.
Browse files Browse the repository at this point in the history
  • Loading branch information
Laity000 committed May 16, 2024
1 parent 2d41c96 commit 6403290
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,9 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
}

mlir::TypedAttr getConstPtrAttr(mlir::Type t, int64_t v) {
auto val = mlir::IntegerAttr::get(mlir::IntegerType::get(t.getContext(), 64), v);
return mlir::cir::ConstPtrAttr::get(getContext(),
t.cast<mlir::cir::PointerType>(), v);
t.cast<mlir::cir::PointerType>(), val);
}

// Creates constant nullptr for pointer type ty.
Expand Down
10 changes: 4 additions & 6 deletions clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,12 @@ def ConstPtrAttr : CIR_Attr<"ConstPtr", "ptr", [TypedAttrInterface]> {
value of a pointer type.
}];
let builders = [
AttrBuilderWithInferredContext<(ins "Type":$type, "int64_t":$value), [{
auto val = mlir::IntegerAttr::get(mlir::IntegerType::get(type.getContext(), 64), value);
return $_get(type.getContext(), type.cast<mlir::cir::PointerType>(), val);
AttrBuilderWithInferredContext<(ins "Type":$type, "mlir::IntegerAttr":$value), [{
return $_get(type.getContext(), type.cast<mlir::cir::PointerType>(), value);
}]>,
AttrBuilder<(ins "Type":$type,
"int64_t":$value), [{
auto val = mlir::IntegerAttr::get(mlir::IntegerType::get(type.getContext(), 64), value);
return $_get($_ctxt, type.cast<mlir::cir::PointerType>(), val);
"mlir::IntegerAttr":$value), [{
return $_get($_ctxt, type.cast<mlir::cir::PointerType>(), value);
}]>,
];
let extraClassDeclaration = [{
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {

mlir::TypedAttr getConstNullPtrAttr(mlir::Type t) {
assert(t.isa<mlir::cir::PointerType>() && "expected cir.ptr");
return mlir::cir::ConstPtrAttr::get(getContext(), t, 0);
return getConstPtrAttr(t, 0);
}

mlir::Attribute getString(llvm::StringRef str, mlir::Type eltTy,
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenVTables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ void CIRGenVTables::GenerateClassData(const CXXRecordDecl *RD) {
static void AddPointerLayoutOffset(CIRGenModule &CGM,
ConstantArrayBuilder &builder,
CharUnits offset) {
builder.add(mlir::cir::ConstPtrAttr::get(CGM.getBuilder().getContext(),
CGM.getBuilder().getUInt8PtrTy(),
offset.getQuantity()));
builder.add(CGM.getBuilder().getConstPtrAttr(CGM.getBuilder().getUInt8PtrTy(),
offset.getQuantity()));
}

static void AddRelativeLayoutOffset(CIRGenModule &CGM,
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/CIR/CodeGen/ConstantInitBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ class ConstantAggregateBuilderBase {

/// Add a pointer of a specific type.
void addPointer(mlir::cir::PointerType ptrTy, uint64_t value) {
add(mlir::cir::ConstPtrAttr::get(ptrTy.getContext(), ptrTy, value));
auto val = mlir::IntegerAttr::get(mlir::IntegerType::get(ptrTy.getContext(), 64), value);
add(mlir::cir::ConstPtrAttr::get(ptrTy.getContext(), ptrTy, val));
}

/// Add a bitcast of a value to a specific type.
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,12 @@ class CIRCastOpLowering : public mlir::OpConversionPattern<mlir::cir::CastOp> {
return mlir::success();
}
case mlir::cir::CastKind::ptr_to_bool: {
auto zero =
mlir::IntegerAttr::get(mlir::IntegerType::get(getContext(), 64), 0);
auto null = rewriter.create<mlir::cir::ConstantOp>(
src.getLoc(), castOp.getSrc().getType(),
mlir::cir::ConstPtrAttr::get(getContext(), castOp.getSrc().getType(),
0));
zero));
rewriter.replaceOpWithNewOp<mlir::cir::CmpOp>(
castOp, mlir::cir::BoolType::get(getContext()),
mlir::cir::CmpOpKind::ne, castOp.getSrc(), null);
Expand Down

0 comments on commit 6403290

Please sign in to comment.