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
71 changes: 38 additions & 33 deletions clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {

mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ,
const llvm::APInt &val) {
return create<cir::ConstantOp>(loc, cir::IntAttr::get(typ, val));
return cir::ConstantOp::create(*this, loc, cir::IntAttr::get(typ, val));
}

cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr) {
return create<cir::ConstantOp>(loc, attr);
return cir::ConstantOp::create(*this, loc, attr);
}

cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty,
Expand Down Expand Up @@ -119,7 +119,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
}

cir::ConstantOp getBool(bool state, mlir::Location loc) {
return create<cir::ConstantOp>(loc, getCIRBoolAttr(state));
return cir::ConstantOp::create(*this, loc, getCIRBoolAttr(state));
}
cir::ConstantOp getFalse(mlir::Location loc) { return getBool(false, loc); }
cir::ConstantOp getTrue(mlir::Location loc) { return getBool(true, loc); }
Expand All @@ -144,17 +144,20 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
mlir::Value createComplexCreate(mlir::Location loc, mlir::Value real,
mlir::Value imag) {
auto resultComplexTy = cir::ComplexType::get(real.getType());
return create<cir::ComplexCreateOp>(loc, resultComplexTy, real, imag);
return cir::ComplexCreateOp::create(*this, loc, resultComplexTy, real,
imag);
}

mlir::Value createComplexReal(mlir::Location loc, mlir::Value operand) {
auto operandTy = mlir::cast<cir::ComplexType>(operand.getType());
return create<cir::ComplexRealOp>(loc, operandTy.getElementType(), operand);
return cir::ComplexRealOp::create(*this, loc, operandTy.getElementType(),
operand);
}

mlir::Value createComplexImag(mlir::Location loc, mlir::Value operand) {
auto operandTy = mlir::cast<cir::ComplexType>(operand.getType());
return create<cir::ComplexImagOp>(loc, operandTy.getElementType(), operand);
return cir::ComplexImagOp::create(*this, loc, operandTy.getElementType(),
operand);
}

cir::LoadOp createLoad(mlir::Location loc, mlir::Value ptr,
Expand All @@ -171,7 +174,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
}

mlir::Value createNot(mlir::Value value) {
return create<cir::UnaryOp>(value.getLoc(), value.getType(),
return cir::UnaryOp::create(*this, value.getLoc(), value.getType(),
cir::UnaryOpKind::Not, value);
}

Expand All @@ -180,15 +183,15 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
mlir::Location loc,
llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> condBuilder,
llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> bodyBuilder) {
return create<cir::DoWhileOp>(loc, condBuilder, bodyBuilder);
return cir::DoWhileOp::create(*this, loc, condBuilder, bodyBuilder);
}

/// Create a while operation.
cir::WhileOp createWhile(
mlir::Location loc,
llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> condBuilder,
llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> bodyBuilder) {
return create<cir::WhileOp>(loc, condBuilder, bodyBuilder);
return cir::WhileOp::create(*this, loc, condBuilder, bodyBuilder);
}

/// Create a for operation.
Expand All @@ -197,22 +200,23 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> condBuilder,
llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> bodyBuilder,
llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> stepBuilder) {
return create<cir::ForOp>(loc, condBuilder, bodyBuilder, stepBuilder);
return cir::ForOp::create(*this, loc, condBuilder, bodyBuilder,
stepBuilder);
}

/// Create a break operation.
cir::BreakOp createBreak(mlir::Location loc) {
return create<cir::BreakOp>(loc);
return cir::BreakOp::create(*this, loc);
}

/// Create a continue operation.
cir::ContinueOp createContinue(mlir::Location loc) {
return create<cir::ContinueOp>(loc);
return cir::ContinueOp::create(*this, loc);
}

mlir::Value createUnaryOp(mlir::Location loc, cir::UnaryOpKind kind,
mlir::Value operand) {
return create<cir::UnaryOp>(loc, kind, operand);
return cir::UnaryOp::create(*this, loc, kind, operand);
}

mlir::TypedAttr getConstPtrAttr(mlir::Type type, int64_t value) {
Expand All @@ -222,7 +226,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType,
mlir::Type type, llvm::StringRef name,
mlir::IntegerAttr alignment) {
return create<cir::AllocaOp>(loc, addrType, type, name, alignment);
return cir::AllocaOp::create(*this, loc, addrType, type, name, alignment);
}

/// Get constant address of a global variable as an MLIR attribute.
Expand All @@ -235,8 +239,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {

mlir::Value createGetGlobal(mlir::Location loc, cir::GlobalOp global) {
assert(!cir::MissingFeatures::addressSpace());
return create<cir::GetGlobalOp>(loc, getPointerTo(global.getSymType()),
global.getSymName());
return cir::GetGlobalOp::create(
*this, loc, getPointerTo(global.getSymType()), global.getSymName());
}

mlir::Value createGetGlobal(cir::GlobalOp global) {
Expand All @@ -263,7 +267,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
cir::GetMemberOp createGetMember(mlir::Location loc, mlir::Type resultTy,
mlir::Value base, llvm::StringRef name,
unsigned index) {
return create<cir::GetMemberOp>(loc, resultTy, base, name, index);
return cir::GetMemberOp::create(*this, loc, resultTy, base, name, index);
}

mlir::Value createDummyValue(mlir::Location loc, mlir::Type type,
Expand All @@ -276,7 +280,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {

cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base,
mlir::Value stride) {
return create<cir::PtrStrideOp>(loc, base.getType(), base, stride);
return cir::PtrStrideOp::create(*this, loc, base.getType(), base, stride);
}

//===--------------------------------------------------------------------===//
Expand All @@ -286,7 +290,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee,
mlir::Type returnType, mlir::ValueRange operands,
llvm::ArrayRef<mlir::NamedAttribute> attrs = {}) {
auto op = create<cir::CallOp>(loc, callee, returnType, operands);
auto op = cir::CallOp::create(*this, loc, callee, returnType, operands);
op->setAttrs(attrs);
return op;
}
Expand Down Expand Up @@ -317,7 +321,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
mlir::Value src, mlir::Type newTy) {
if (newTy == src.getType())
return src;
return create<cir::CastOp>(loc, newTy, kind, src);
return cir::CastOp::create(*this, loc, newTy, kind, src);
}

mlir::Value createCast(cir::CastKind kind, mlir::Value src,
Expand Down Expand Up @@ -367,7 +371,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {

mlir::Value createBinop(mlir::Location loc, mlir::Value lhs,
cir::BinOpKind kind, mlir::Value rhs) {
return create<cir::BinOp>(loc, lhs.getType(), kind, lhs, rhs);
return cir::BinOp::create(*this, loc, lhs.getType(), kind, lhs, rhs);
}

mlir::Value createLowBitsSet(mlir::Location loc, unsigned size,
Expand All @@ -389,8 +393,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
mlir::Value trueValue, mlir::Value falseValue) {
assert(trueValue.getType() == falseValue.getType() &&
"trueValue and falseValue should have the same type");
return create<cir::SelectOp>(loc, trueValue.getType(), condition, trueValue,
falseValue);
return cir::SelectOp::create(*this, loc, trueValue.getType(), condition,
trueValue, falseValue);
}

mlir::Value createLogicalAnd(mlir::Location loc, mlir::Value lhs,
Expand All @@ -405,8 +409,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {

mlir::Value createMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
OverflowBehavior ob = OverflowBehavior::None) {
auto op =
create<cir::BinOp>(loc, lhs.getType(), cir::BinOpKind::Mul, lhs, rhs);
auto op = cir::BinOp::create(*this, loc, lhs.getType(), cir::BinOpKind::Mul,
lhs, rhs);
op.setNoUnsignedWrap(
llvm::to_underlying(ob & OverflowBehavior::NoUnsignedWrap));
op.setNoSignedWrap(
Expand All @@ -424,8 +428,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {

mlir::Value createSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
OverflowBehavior ob = OverflowBehavior::Saturated) {
auto op =
create<cir::BinOp>(loc, lhs.getType(), cir::BinOpKind::Sub, lhs, rhs);
auto op = cir::BinOp::create(*this, loc, lhs.getType(), cir::BinOpKind::Sub,
lhs, rhs);
op.setNoUnsignedWrap(
llvm::to_underlying(ob & OverflowBehavior::NoUnsignedWrap));
op.setNoSignedWrap(
Expand All @@ -446,8 +450,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {

mlir::Value createAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
OverflowBehavior ob = OverflowBehavior::None) {
auto op =
create<cir::BinOp>(loc, lhs.getType(), cir::BinOpKind::Add, lhs, rhs);
auto op = cir::BinOp::create(*this, loc, lhs.getType(), cir::BinOpKind::Add,
lhs, rhs);
op.setNoUnsignedWrap(
llvm::to_underlying(ob & OverflowBehavior::NoUnsignedWrap));
op.setNoSignedWrap(
Expand All @@ -468,7 +472,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {

cir::CmpOp createCompare(mlir::Location loc, cir::CmpOpKind kind,
mlir::Value lhs, mlir::Value rhs) {
return create<cir::CmpOp>(loc, getBoolTy(), kind, lhs, rhs);
return cir::CmpOp::create(*this, loc, getBoolTy(), kind, lhs, rhs);
}

mlir::Value createIsNaN(mlir::Location loc, mlir::Value operand) {
Expand All @@ -477,7 +481,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {

mlir::Value createShift(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
bool isShiftLeft) {
return create<cir::ShiftOp>(loc, lhs.getType(), lhs, rhs, isShiftLeft);
return cir::ShiftOp::create(*this, loc, lhs.getType(), lhs, rhs,
isShiftLeft);
}

mlir::Value createShift(mlir::Location loc, mlir::Value lhs,
Expand Down Expand Up @@ -555,12 +560,12 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {

/// Create a loop condition.
cir::ConditionOp createCondition(mlir::Value condition) {
return create<cir::ConditionOp>(condition.getLoc(), condition);
return cir::ConditionOp::create(*this, condition.getLoc(), condition);
}

/// Create a yield operation.
cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value = {}) {
return create<cir::YieldOp>(loc, value);
return cir::YieldOp::create(*this, loc, value);
}
};

Expand Down
37 changes: 19 additions & 18 deletions clang/lib/CIR/CodeGen/CIRGenBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
// Creates constant nullptr for pointer type ty.
cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc) {
assert(!cir::MissingFeatures::targetCodeGenInfoGetNullPointer());
return create<cir::ConstantOp>(loc, getConstPtrAttr(ty, 0));
return cir::ConstantOp::create(*this, loc, getConstPtrAttr(ty, 0));
}

mlir::Value createNeg(mlir::Value value) {
Expand All @@ -300,7 +300,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
// Source is a unsigned integer: first cast it to signed.
if (intTy.isUnsigned())
value = createIntCast(value, getSIntNTy(intTy.getWidth()));
return create<cir::UnaryOp>(value.getLoc(), value.getType(),
return cir::UnaryOp::create(*this, value.getLoc(), value.getType(),
cir::UnaryOpKind::Minus, value);
}

Expand All @@ -312,38 +312,38 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
mlir::Value createFloatingCast(mlir::Value v, mlir::Type destType) {
assert(!cir::MissingFeatures::fpConstraints());

return create<cir::CastOp>(v.getLoc(), destType, cir::CastKind::floating,
v);
return cir::CastOp::create(*this, v.getLoc(), destType,
cir::CastKind::floating, v);
}

mlir::Value createFSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
assert(!cir::MissingFeatures::metaDataNode());
assert(!cir::MissingFeatures::fpConstraints());
assert(!cir::MissingFeatures::fastMathFlags());

return create<cir::BinOp>(loc, cir::BinOpKind::Sub, lhs, rhs);
return cir::BinOp::create(*this, loc, cir::BinOpKind::Sub, lhs, rhs);
}

mlir::Value createFAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
assert(!cir::MissingFeatures::metaDataNode());
assert(!cir::MissingFeatures::fpConstraints());
assert(!cir::MissingFeatures::fastMathFlags());

return create<cir::BinOp>(loc, cir::BinOpKind::Add, lhs, rhs);
return cir::BinOp::create(*this, loc, cir::BinOpKind::Add, lhs, rhs);
}
mlir::Value createFMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
assert(!cir::MissingFeatures::metaDataNode());
assert(!cir::MissingFeatures::fpConstraints());
assert(!cir::MissingFeatures::fastMathFlags());

return create<cir::BinOp>(loc, cir::BinOpKind::Mul, lhs, rhs);
return cir::BinOp::create(*this, loc, cir::BinOpKind::Mul, lhs, rhs);
}
mlir::Value createFDiv(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
assert(!cir::MissingFeatures::metaDataNode());
assert(!cir::MissingFeatures::fpConstraints());
assert(!cir::MissingFeatures::fastMathFlags());

return create<cir::BinOp>(loc, cir::BinOpKind::Div, lhs, rhs);
return cir::BinOp::create(*this, loc, cir::BinOpKind::Div, lhs, rhs);
}

Address createBaseClassAddr(mlir::Location loc, Address addr,
Expand All @@ -353,8 +353,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
return addr;

auto ptrTy = getPointerTo(destType);
auto baseAddr = create<cir::BaseClassAddrOp>(
loc, ptrTy, addr.getPointer(), mlir::APInt(64, offset), assumeNotNull);
auto baseAddr =
cir::BaseClassAddrOp::create(*this, loc, ptrTy, addr.getPointer(),
mlir::APInt(64, offset), assumeNotNull);
return Address(baseAddr, destType, addr.getAlignment());
}

Expand Down Expand Up @@ -393,8 +394,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
mlir::Value createComplexRealPtr(mlir::Location loc, mlir::Value value) {
auto srcPtrTy = mlir::cast<cir::PointerType>(value.getType());
auto srcComplexTy = mlir::cast<cir::ComplexType>(srcPtrTy.getPointee());
return create<cir::ComplexRealPtrOp>(
loc, getPointerTo(srcComplexTy.getElementType()), value);
return cir::ComplexRealPtrOp::create(
*this, loc, getPointerTo(srcComplexTy.getElementType()), value);
}

Address createComplexRealPtr(mlir::Location loc, Address addr) {
Expand All @@ -408,8 +409,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
mlir::Value createComplexImagPtr(mlir::Location loc, mlir::Value value) {
auto srcPtrTy = mlir::cast<cir::PointerType>(value.getType());
auto srcComplexTy = mlir::cast<cir::ComplexType>(srcPtrTy.getPointee());
return create<cir::ComplexImagPtrOp>(
loc, getPointerTo(srcComplexTy.getElementType()), value);
return cir::ComplexImagPtrOp::create(
*this, loc, getPointerTo(srcComplexTy.getElementType()), value);
}

Address createComplexImagPtr(mlir::Location loc, Address addr) {
Expand Down Expand Up @@ -467,9 +468,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
useVolatile ? cir::IntType::get(storageType.getContext(),
info.volatileStorageSize, info.isSigned)
: storageType;
return create<cir::SetBitfieldOp>(
loc, resultType, dstAddr.getPointer(), storageType, src, info.name,
info.size, offset, info.isSigned, isLvalueVolatile,
return cir::SetBitfieldOp::create(
*this, loc, resultType, dstAddr.getPointer(), storageType, src,
info.name, info.size, offset, info.isSigned, isLvalueVolatile,
dstAddr.getAlignment().getAsAlign().value());
}

Expand All @@ -485,7 +486,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
useVolatile ? cir::IntType::get(storageType.getContext(),
info.volatileStorageSize, info.isSigned)
: storageType;
return create<cir::GetBitfieldOp>(loc, resultType, addr.getPointer(),
return cir::GetBitfieldOp::create(*this, loc, resultType, addr.getPointer(),
storageType, info.name, info.size, offset,
info.isSigned, isLvalueVolatile,
addr.getAlignment().getAsAlign().value());
Expand Down