Skip to content

Commit

Permalink
Merge branch 'main' into new-goto-pass
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardosolopes authored May 7, 2024
2 parents 4f4f32a + 7655c70 commit 9561911
Show file tree
Hide file tree
Showing 161 changed files with 3,507 additions and 871 deletions.
37 changes: 35 additions & 2 deletions clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
return ::mlir::cir::VoidType::get(getContext());
}

mlir::cir::IntType getUIntNTy(int N) {
return mlir::cir::IntType::get(getContext(), N, false);
}

mlir::cir::IntType getSIntNTy(int N) {
return mlir::cir::IntType::get(getContext(), N, true);
}

mlir::cir::PointerType getPointerTo(mlir::Type ty,
unsigned addressSpace = 0) {
assert(!addressSpace && "address space is NYI");
Expand All @@ -76,6 +84,18 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
return getPointerTo(::mlir::cir::VoidType::get(getContext()), addressSpace);
}

mlir::Value createLoad(mlir::Location loc, mlir::Value ptr) {
return create<mlir::cir::LoadOp>(loc, ptr, /*isDeref=*/false,
/*is_volatile=*/false,
/*mem_order=*/mlir::cir::MemOrderAttr{});
}

mlir::Value createAlignedLoad(mlir::Location loc, mlir::Value ptr,
uint64_t alignment) {
// TODO(cir): implement aligned load in CIRBaseBuilder.
return createLoad(loc, ptr);
}

mlir::Value createNot(mlir::Value value) {
return create<mlir::cir::UnaryOp>(value.getLoc(), value.getType(),
mlir::cir::UnaryOpKind::Not, value);
Expand Down Expand Up @@ -205,6 +225,19 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
return createSub(lhs, rhs, false, true);
}

struct BinOpOverflowResults {
mlir::Value result;
mlir::Value overflow;
};

BinOpOverflowResults createBinOpOverflowOp(mlir::Location loc,
mlir::cir::IntType resultTy,
mlir::cir::BinOpOverflowKind kind,
mlir::Value lhs, mlir::Value rhs) {
auto op = create<mlir::cir::BinOpOverflowOp>(loc, resultTy, kind, lhs, rhs);
return {op.getResult(), op.getOverflow()};
}

//===--------------------------------------------------------------------===//
// Cast/Conversion Operators
//===--------------------------------------------------------------------===//
Expand Down Expand Up @@ -328,8 +361,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
}

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

// Creates constant nullptr for pointer type ty.
Expand Down
15 changes: 12 additions & 3 deletions clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,29 @@ def FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {

def ConstPtrAttr : CIR_Attr<"ConstPtr", "ptr", [TypedAttrInterface]> {
let summary = "Holds a constant pointer value";
let parameters = (ins AttributeSelfTypeParameter<"">:$type, "uint64_t":$value);
let parameters = (ins
AttributeSelfTypeParameter<"", "::mlir::cir::PointerType">:$type,
"uint64_t":$value);
let description = [{
A pointer attribute is a literal attribute that represents an integral
value of a pointer type.
}];
let builders = [
AttrBuilderWithInferredContext<(ins "Type":$type, "uint64_t":$value), [{
return $_get(type.getContext(), type, value);
return $_get(type.getContext(), type.cast<mlir::cir::PointerType>(), value);
}]>,
AttrBuilder<(ins "Type":$type,
"uint64_t":$value), [{
return $_get($_ctxt, type.cast<mlir::cir::PointerType>(), value);
}]>,
];
let extraClassDeclaration = [{
bool isNullValue() const { return getValue() == 0; }
}];
let hasCustomAssemblyFormat = 1;

let assemblyFormat = [{
`<` custom<ConstPtr>($value) `>`
}];
}

//===----------------------------------------------------------------------===//
Expand Down
Loading

0 comments on commit 9561911

Please sign in to comment.