From 4e499767a3586ba9ebab1cafaefb63e25f3d6af2 Mon Sep 17 00:00:00 2001 From: Nathan Lanza Date: Tue, 29 Oct 2024 20:14:30 -0400 Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?= =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.5 [skip ci] --- clang/include/clang/CIR/Dialect/IR/CIROps.td | 10 ++ clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 120 +++++++++++-------- 2 files changed, 78 insertions(+), 52 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index 3f04898605db..bf765f94e5f3 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -599,6 +599,12 @@ def LoadOp : CIR_Op<"load", [ $addr `:` qualified(type($addr)) `,` type($result) attr-dict }]; + let extraClassDeclaration = [{ + // TODO(CIR): The final interface here should include an argument for the + // SyncScope::ID. + void setAtomic(mlir::cir::MemOrder order); + }]; + // FIXME: add verifier. } @@ -2411,8 +2417,12 @@ def GlobalOp : CIR_Op<"global", bool hasAvailableExternallyLinkage() { return mlir::cir::isAvailableExternallyLinkage(getLinkage()); } + bool hasInternalLinkage() { + return mlir::cir::isInternalLinkage(getLinkage()); + } /// Whether the definition of this global may be replaced at link time. bool isWeakForLinker() { return cir::isWeakForLinker(getLinkage()); } + bool isDSOLocal() { return getDsolocal(); } }]; let skipDefaultBuilders = 1; diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index f9b883905b84..8468acacc3c8 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -49,6 +49,7 @@ using namespace mlir; #include "clang/CIR/Dialect/IR/CIROpsDialect.cpp.inc" #include "clang/CIR/Interfaces/ASTAttrInterfaces.h" #include "clang/CIR/Interfaces/CIROpInterfaces.h" +#include //===----------------------------------------------------------------------===// // CIR Dialect @@ -470,28 +471,28 @@ LogicalResult mlir::cir::CastOp::verify() { } switch (getKind()) { - case cir::CastKind::int_to_bool: { + case mlir::cir::CastKind::int_to_bool: { if (!mlir::isa(resType)) return emitOpError() << "requires !cir.bool type for result"; if (!mlir::isa(srcType)) return emitOpError() << "requires !cir.int type for source"; return success(); } - case cir::CastKind::ptr_to_bool: { + case mlir::cir::CastKind::ptr_to_bool: { if (!mlir::isa(resType)) return emitOpError() << "requires !cir.bool type for result"; if (!mlir::isa(srcType)) return emitOpError() << "requires !cir.ptr type for source"; return success(); } - case cir::CastKind::integral: { + case mlir::cir::CastKind::integral: { if (!mlir::isa(resType)) return emitOpError() << "requires !cir.int type for result"; if (!mlir::isa(srcType)) return emitOpError() << "requires !cir.int type for source"; return success(); } - case cir::CastKind::array_to_ptrdecay: { + case mlir::cir::CastKind::array_to_ptrdecay: { auto arrayPtrTy = mlir::dyn_cast(srcType); auto flatPtrTy = mlir::dyn_cast(resType); if (!arrayPtrTy || !flatPtrTy) @@ -512,7 +513,7 @@ LogicalResult mlir::cir::CastOp::verify() { << "requires same type for array element and pointee result"; return success(); } - case cir::CastKind::bitcast: { + case mlir::cir::CastKind::bitcast: { // Allow bitcast of structs for calling conventions. if (isa(srcType) || isa(resType)) return success(); @@ -537,62 +538,62 @@ LogicalResult mlir::cir::CastOp::verify() { << "requires !cir.ptr or !cir.vector type for source and result"; return success(); } - case cir::CastKind::floating: { + case mlir::cir::CastKind::floating: { if (!mlir::isa(srcType) || !mlir::isa(resType)) return emitOpError() << "requires !cir.float type for source and result"; return success(); } - case cir::CastKind::float_to_int: { + case mlir::cir::CastKind::float_to_int: { if (!mlir::isa(srcType)) return emitOpError() << "requires !cir.float type for source"; if (!mlir::dyn_cast(resType)) return emitOpError() << "requires !cir.int type for result"; return success(); } - case cir::CastKind::int_to_ptr: { + case mlir::cir::CastKind::int_to_ptr: { if (!mlir::dyn_cast(srcType)) return emitOpError() << "requires !cir.int type for source"; if (!mlir::dyn_cast(resType)) return emitOpError() << "requires !cir.ptr type for result"; return success(); } - case cir::CastKind::ptr_to_int: { + case mlir::cir::CastKind::ptr_to_int: { if (!mlir::dyn_cast(srcType)) return emitOpError() << "requires !cir.ptr type for source"; if (!mlir::dyn_cast(resType)) return emitOpError() << "requires !cir.int type for result"; return success(); } - case cir::CastKind::float_to_bool: { + case mlir::cir::CastKind::float_to_bool: { if (!mlir::isa(srcType)) return emitOpError() << "requires !cir.float type for source"; if (!mlir::isa(resType)) return emitOpError() << "requires !cir.bool type for result"; return success(); } - case cir::CastKind::bool_to_int: { + case mlir::cir::CastKind::bool_to_int: { if (!mlir::isa(srcType)) return emitOpError() << "requires !cir.bool type for source"; if (!mlir::isa(resType)) return emitOpError() << "requires !cir.int type for result"; return success(); } - case cir::CastKind::int_to_float: { + case mlir::cir::CastKind::int_to_float: { if (!mlir::isa(srcType)) return emitOpError() << "requires !cir.int type for source"; if (!mlir::isa(resType)) return emitOpError() << "requires !cir.float type for result"; return success(); } - case cir::CastKind::bool_to_float: { + case mlir::cir::CastKind::bool_to_float: { if (!mlir::isa(srcType)) return emitOpError() << "requires !cir.bool type for source"; if (!mlir::isa(resType)) return emitOpError() << "requires !cir.float type for result"; return success(); } - case cir::CastKind::address_space: { + case mlir::cir::CastKind::address_space: { auto srcPtrTy = mlir::dyn_cast(srcType); auto resPtrTy = mlir::dyn_cast(resType); if (!srcPtrTy || !resPtrTy) @@ -601,7 +602,7 @@ LogicalResult mlir::cir::CastOp::verify() { return emitOpError() << "requires two types differ in addrspace only"; return success(); } - case cir::CastKind::float_to_complex: { + case mlir::cir::CastKind::float_to_complex: { if (!mlir::isa(srcType)) return emitOpError() << "requires !cir.float type for source"; auto resComplexTy = mlir::dyn_cast(resType); @@ -611,7 +612,7 @@ LogicalResult mlir::cir::CastOp::verify() { return emitOpError() << "requires source type match result element type"; return success(); } - case cir::CastKind::int_to_complex: { + case mlir::cir::CastKind::int_to_complex: { if (!mlir::isa(srcType)) return emitOpError() << "requires !cir.int type for source"; auto resComplexTy = mlir::dyn_cast(resType); @@ -621,7 +622,7 @@ LogicalResult mlir::cir::CastOp::verify() { return emitOpError() << "requires source type match result element type"; return success(); } - case cir::CastKind::float_complex_to_real: { + case mlir::cir::CastKind::float_complex_to_real: { auto srcComplexTy = mlir::dyn_cast(srcType); if (!srcComplexTy) return emitOpError() << "requires !cir.complex type for source"; @@ -631,7 +632,7 @@ LogicalResult mlir::cir::CastOp::verify() { return emitOpError() << "requires source element type match result type"; return success(); } - case cir::CastKind::int_complex_to_real: { + case mlir::cir::CastKind::int_complex_to_real: { auto srcComplexTy = mlir::dyn_cast(srcType); if (!srcComplexTy) return emitOpError() << "requires !cir.complex type for source"; @@ -641,7 +642,7 @@ LogicalResult mlir::cir::CastOp::verify() { return emitOpError() << "requires source element type match result type"; return success(); } - case cir::CastKind::float_complex_to_bool: { + case mlir::cir::CastKind::float_complex_to_bool: { auto srcComplexTy = mlir::dyn_cast(srcType); if (!srcComplexTy || !mlir::isa(srcComplexTy.getElementTy())) @@ -651,7 +652,7 @@ LogicalResult mlir::cir::CastOp::verify() { return emitOpError() << "requires !cir.bool type for result"; return success(); } - case cir::CastKind::int_complex_to_bool: { + case mlir::cir::CastKind::int_complex_to_bool: { auto srcComplexTy = mlir::dyn_cast(srcType); if (!srcComplexTy || !mlir::isa(srcComplexTy.getElementTy())) @@ -661,7 +662,7 @@ LogicalResult mlir::cir::CastOp::verify() { return emitOpError() << "requires !cir.bool type for result"; return success(); } - case cir::CastKind::float_complex: { + case mlir::cir::CastKind::float_complex: { auto srcComplexTy = mlir::dyn_cast(srcType); if (!srcComplexTy || !mlir::isa(srcComplexTy.getElementTy())) @@ -674,7 +675,7 @@ LogicalResult mlir::cir::CastOp::verify() { << "requires !cir.complex type for result"; return success(); } - case cir::CastKind::float_complex_to_int_complex: { + case mlir::cir::CastKind::float_complex_to_int_complex: { auto srcComplexTy = mlir::dyn_cast(srcType); if (!srcComplexTy || !mlir::isa(srcComplexTy.getElementTy())) @@ -686,7 +687,7 @@ LogicalResult mlir::cir::CastOp::verify() { return emitOpError() << "requires !cir.complex type for result"; return success(); } - case cir::CastKind::int_complex: { + case mlir::cir::CastKind::int_complex: { auto srcComplexTy = mlir::dyn_cast(srcType); if (!srcComplexTy || !mlir::isa(srcComplexTy.getElementTy())) @@ -697,7 +698,7 @@ LogicalResult mlir::cir::CastOp::verify() { return emitOpError() << "requires !cir.complex type for result"; return success(); } - case cir::CastKind::int_complex_to_float_complex: { + case mlir::cir::CastKind::int_complex_to_float_complex: { auto srcComplexTy = mlir::dyn_cast(srcType); if (!srcComplexTy || !mlir::isa(srcComplexTy.getElementTy())) @@ -920,6 +921,18 @@ LogicalResult mlir::cir::ComplexImagPtrOp::verify() { return success(); } +//===----------------------------------------------------------------------===// +// LoadOp +//===----------------------------------------------------------------------===// + +// TODO(CIR): The final interface here should include an argument for the +// SyncScope::ID. +void mlir::cir::LoadOp::setAtomic(mlir::cir::MemOrder order) { + setMemOrder(order); + if (::cir::MissingFeatures::syncScopeID()) + llvm_unreachable("NYI"); +} + //===----------------------------------------------------------------------===// // VecCreateOp //===----------------------------------------------------------------------===// @@ -1030,11 +1043,11 @@ mlir::LogicalResult mlir::cir::ReturnOp::verify() { // Returns can be present in multiple different scopes, get the // wrapping function and start from there. auto *fnOp = getOperation()->getParentOp(); - while (!isa(fnOp)) + while (!isa(fnOp)) fnOp = fnOp->getParentOp(); // Make sure return types match function return type. - if (checkReturnAndFunction(*this, cast(fnOp)).failed()) + if (checkReturnAndFunction(*this, cast(fnOp)).failed()) return failure(); return success(); @@ -1940,8 +1953,8 @@ LogicalResult mlir::cir::GlobalOp::verify() { void mlir::cir::GlobalOp::build( OpBuilder &odsBuilder, OperationState &odsState, StringRef sym_name, - Type sym_type, bool isConstant, cir::GlobalLinkageKind linkage, - cir::AddressSpaceAttr addrSpace, + Type sym_type, bool isConstant, mlir::cir::GlobalLinkageKind linkage, + mlir::cir::AddressSpaceAttr addrSpace, function_ref ctorBuilder, function_ref dtorBuilder) { odsState.addAttribute(getSymNameAttrName(odsState.name), @@ -1953,7 +1966,7 @@ void mlir::cir::GlobalOp::build( odsBuilder.getUnitAttr()); ::mlir::cir::GlobalLinkageKindAttr linkageAttr = - cir::GlobalLinkageKindAttr::get(odsBuilder.getContext(), linkage); + mlir::cir::GlobalLinkageKindAttr::get(odsBuilder.getContext(), linkage); odsState.addAttribute(getLinkageAttrName(odsState.name), linkageAttr); if (addrSpace) @@ -2526,7 +2539,7 @@ void mlir::cir::FuncOp::print(OpAsmPrinter &p) { // getNumArguments hook not failing. LogicalResult mlir::cir::FuncOp::verifyType() { auto type = getFunctionType(); - if (!isa(type)) + if (!isa(type)) return emitOpError("requires '" + getFunctionTypeAttrName().str() + "' attribute of function type"); if (!getNoProto() && type.isVarArg() && type.getNumInputs() == 0) @@ -2549,19 +2562,20 @@ LogicalResult mlir::cir::FuncOp::verify() { if (getLinkage() == cir::GlobalLinkageKind::CommonLinkage) return emitOpError() << "functions cannot have '" << stringifyGlobalLinkageKind( - cir::GlobalLinkageKind::CommonLinkage) + mlir::cir::GlobalLinkageKind::CommonLinkage) << "' linkage"; if (isExternal()) { - if (getLinkage() != cir::GlobalLinkageKind::ExternalLinkage && - getLinkage() != cir::GlobalLinkageKind::ExternalWeakLinkage) - return emitOpError() << "external functions must have '" - << stringifyGlobalLinkageKind( - cir::GlobalLinkageKind::ExternalLinkage) - << "' or '" - << stringifyGlobalLinkageKind( - cir::GlobalLinkageKind::ExternalWeakLinkage) - << "' linkage"; + if (getLinkage() != mlir::cir::GlobalLinkageKind::ExternalLinkage && + getLinkage() != mlir::cir::GlobalLinkageKind::ExternalWeakLinkage) + return emitOpError() + << "external functions must have '" + << stringifyGlobalLinkageKind( + mlir::cir::GlobalLinkageKind::ExternalLinkage) + << "' or '" + << stringifyGlobalLinkageKind( + mlir::cir::GlobalLinkageKind::ExternalWeakLinkage) + << "' linkage"; return success(); } @@ -3057,11 +3071,11 @@ mlir::cir::TryCallOp::getSuccessorOperands(unsigned index) { LogicalResult mlir::cir::UnaryOp::verify() { switch (getKind()) { - case cir::UnaryOpKind::Inc: - case cir::UnaryOpKind::Dec: - case cir::UnaryOpKind::Plus: - case cir::UnaryOpKind::Minus: - case cir::UnaryOpKind::Not: + case mlir::cir::UnaryOpKind::Inc: + case mlir::cir::UnaryOpKind::Dec: + case mlir::cir::UnaryOpKind::Plus: + case mlir::cir::UnaryOpKind::Minus: + case mlir::cir::UnaryOpKind::Not: // Nothing to verify. return success(); } @@ -3078,8 +3092,9 @@ void mlir::cir::AwaitOp::build( function_ref readyBuilder, function_ref suspendBuilder, function_ref resumeBuilder) { - result.addAttribute(getKindAttrName(result.name), - cir::AwaitKindAttr::get(builder.getContext(), kind)); + result.addAttribute( + getKindAttrName(result.name), + mlir::cir::AwaitKindAttr::get(builder.getContext(), kind)); { OpBuilder::InsertionGuard guard(builder); Region *readyRegion = result.addRegion(); @@ -3191,7 +3206,7 @@ LogicalResult mlir::cir::ConstArrayAttr::verify( if (auto strAttr = mlir::dyn_cast(attr)) { mlir::cir::ArrayType at = mlir::cast(type); - auto intTy = mlir::dyn_cast(at.getEltType()); + auto intTy = mlir::dyn_cast(at.getEltType()); // TODO: add CIR type for char. if (!intTy || intTy.getWidth() != 8) { @@ -3308,8 +3323,9 @@ LogicalResult mlir::cir::ConstVectorAttr::verify( ::mlir::Type type, mlir::ArrayAttr arrayAttr) { if (!mlir::isa(type)) { - return emitError() - << "type of cir::ConstVectorAttr is not a cir::VectorType: " << type; + return emitError() << "type of mlir::cir::ConstVectorAttr is not a " + "mlir::cir::VectorType: " + << type; } auto vecType = mlir::cast(type); @@ -3499,8 +3515,8 @@ LogicalResult mlir::cir::CopyOp::verify() { //===----------------------------------------------------------------------===// LogicalResult mlir::cir::MemCpyOp::verify() { - auto voidPtr = - cir::PointerType::get(getContext(), cir::VoidType::get(getContext())); + auto voidPtr = mlir::cir::PointerType::get( + getContext(), mlir::cir::VoidType::get(getContext())); if (!getLenTy().isUnsigned()) return emitError() << "memcpy length must be an unsigned integer"; From 7c96bc41432f42f6d09777f021f681a2f3356ad3 Mon Sep 17 00:00:00 2001 From: Nathan Lanza Date: Tue, 29 Oct 2024 20:59:54 -0400 Subject: [PATCH 2/2] rename Created using spr 1.3.5 --- clang/lib/CIR/CodeGen/CIRGenCXX.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenCXX.cpp b/clang/lib/CIR/CodeGen/CIRGenCXX.cpp index d6edc78acd60..4d8174aaa3d1 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCXX.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCXX.cpp @@ -338,7 +338,7 @@ void CIRGenModule::buildCXXGlobalVarDeclInit(const VarDecl *varDecl, assert(varDecl && " Expected a global declaration!"); CIRGenFunction cgf{*this, builder, true}; - llvm::SaveAndRestore save(CurCGF, &cgf); + llvm::SaveAndRestore savedCGF(CurCGF, &cgf); CurCGF->CurFn = addr; CIRGenFunction::SourceLocRAIIObject fnLoc{cgf,