Skip to content

Commit

Permalink
Merge branch 'llvm:main' into m1Mac
Browse files Browse the repository at this point in the history
  • Loading branch information
ghehg authored Nov 22, 2024
2 parents ac960bb + dbd3e03 commit 3b3af1e
Show file tree
Hide file tree
Showing 52 changed files with 2,000 additions and 907 deletions.
12 changes: 8 additions & 4 deletions clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
llvm_unreachable("Zero initializer for given type is NYI");
}

mlir::Value createLoad(mlir::Location loc, mlir::Value ptr,
cir::LoadOp createLoad(mlir::Location loc, mlir::Value ptr,
bool isVolatile = false, uint64_t alignment = 0) {
mlir::IntegerAttr intAttr;
if (alignment)
Expand All @@ -167,7 +167,9 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {

return create<cir::LoadOp>(loc, ptr, /*isDeref=*/false, isVolatile,
/*alignment=*/intAttr,
/*mem_order=*/cir::MemOrderAttr{});
/*mem_order=*/
cir::MemOrderAttr{},
/*tbaa=*/mlir::ArrayAttr{});
}

mlir::Value createAlignedLoad(mlir::Location loc, mlir::Value ptr,
Expand Down Expand Up @@ -353,7 +355,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
if (mlir::cast<cir::PointerType>(dst.getType()).getPointee() !=
val.getType())
dst = createPtrBitcast(dst, val.getType());
return create<cir::StoreOp>(loc, val, dst, _volatile, align, order);
return create<cir::StoreOp>(loc, val, dst, _volatile, align, order,
/*tbaa=*/mlir::ArrayAttr{});
}

mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType,
Expand Down Expand Up @@ -400,7 +403,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
/// Create a copy with inferred length.
cir::CopyOp createCopy(mlir::Value dst, mlir::Value src,
bool isVolatile = false) {
return create<cir::CopyOp>(dst.getLoc(), dst, src, isVolatile);
return create<cir::CopyOp>(dst.getLoc(), dst, src, isVolatile,
/*tbaa=*/mlir::ArrayAttr{});
}

cir::MemCpyOp createMemCpy(mlir::Location loc, mlir::Value dst,
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,9 @@ def GlobalAnnotationValuesAttr : CIR_Attr<"GlobalAnnotationValues",
let genVerifyDecl = 1;
}

def CIR_TBAAAttr : CIR_Attr<"TBAA", "tbaa", []> {
}

include "clang/CIR/Dialect/IR/CIROpenCLAttrs.td"

#endif // MLIR_CIR_DIALECT_CIR_ATTRS
49 changes: 43 additions & 6 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ def LoadOp : CIR_Op<"load", [
[MemRead]>:$addr, UnitAttr:$isDeref,
UnitAttr:$is_volatile,
OptionalAttr<I64Attr>:$alignment,
OptionalAttr<MemOrder>:$mem_order
OptionalAttr<MemOrder>:$mem_order,
OptionalAttr<ArrayAttr>:$tbaa
);
let results = (outs CIR_AnyType:$result);

Expand All @@ -597,6 +598,7 @@ def LoadOp : CIR_Op<"load", [
(`align` `(` $alignment^ `)`)?
(`atomic` `(` $mem_order^ `)`)?
$addr `:` qualified(type($addr)) `,` type($result) attr-dict
(`tbaa` `(` $tbaa^ `)`)?
}];

let extraClassDeclaration = [{
Expand Down Expand Up @@ -654,13 +656,15 @@ def StoreOp : CIR_Op<"store", [
[MemWrite]>:$addr,
UnitAttr:$is_volatile,
OptionalAttr<I64Attr>:$alignment,
OptionalAttr<MemOrder>:$mem_order);
OptionalAttr<MemOrder>:$mem_order,
OptionalAttr<ArrayAttr>:$tbaa);

let assemblyFormat = [{
(`volatile` $is_volatile^)?
(`align` `(` $alignment^ `)`)?
(`atomic` `(` $mem_order^ `)`)?
$value `,` $addr attr-dict `:` type($value) `,` qualified(type($addr))
(`tbaa` `(` $tbaa^ `)`)?
}];

let extraClassDeclaration = [{
Expand Down Expand Up @@ -1268,8 +1272,7 @@ def CmpOp : CIR_Op<"cmp", [Pure, SameTypeOperands]> {
```
}];

// TODO: get more accurate than CIR_AnyType
let results = (outs CIR_AnyType:$result);
let results = (outs CIR_BoolType:$result);
let arguments = (ins Arg<CmpOpKind, "cmp kind">:$kind,
CIR_AnyType:$lhs, CIR_AnyType:$rhs);

Expand Down Expand Up @@ -3981,7 +3984,8 @@ def CopyOp : CIR_Op<"copy",
DeclareOpInterfaceMethods<PromotableMemOpInterface>]> {
let arguments = (ins Arg<CIR_PointerType, "", [MemWrite]>:$dst,
Arg<CIR_PointerType, "", [MemRead]>:$src,
UnitAttr:$is_volatile);
UnitAttr:$is_volatile,
OptionalAttr<ArrayAttr>:$tbaa);
let summary = "Copies contents from a CIR pointer to another";
let description = [{
Given two CIR pointers, `src` and `dst`, `cir.copy` will copy the memory
Expand All @@ -4000,7 +4004,9 @@ def CopyOp : CIR_Op<"copy",
}];

let assemblyFormat = [{$src `to` $dst (`volatile` $is_volatile^)?
attr-dict `:` qualified(type($dst)) }];
attr-dict `:` qualified(type($dst))
(`tbaa` `(` $tbaa^ `)`)?
}];
let hasVerifier = 1;

let extraClassDeclaration = [{
Expand Down Expand Up @@ -4148,6 +4154,37 @@ def MemSetOp : CIR_Op<"libc.memset"> {
let hasVerifier = 0;
}

//===----------------------------------------------------------------------===//
// MemSetInlineOp
//===----------------------------------------------------------------------===//

def MemSetInlineOp : CIR_Op<"memset_inline"> {
let arguments = (ins Arg<VoidPtr, "", [MemWrite]>:$dst,
SInt32:$val,
I64Attr:$len);
let summary = "Fill a block of memory with constant length without calling"
"any external function";
let description = [{
Given the CIR pointer, `dst`, `cir.memset_inline` will set the first `len`
bytes of the memory pointed by `dst` to the specified `val`.

The `len` argument must be a constant integer argument specifying the number
of bytes to fill.

Examples:

```mlir
// Set 2 bytes from a struct to 0
cir.memset_inline 2 bytes from %struct set to %zero : !cir.ptr<!void>, !s32i
```
}];

let assemblyFormat = [{
$len `bytes` `from` $dst `set` `to` $val attr-dict
`:` qualified(type($dst)) `,` type($val)
}];
let hasVerifier = 0;
}
//===----------------------------------------------------------------------===//
// MemChrOp
//===----------------------------------------------------------------------===//
Expand Down
4 changes: 1 addition & 3 deletions clang/include/clang/CIR/MissingFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct MissingFeatures {
// sanitizer related type check features
static bool emitTypeCheck() { return false; }
static bool tbaa() { return false; }
static bool tbaa_struct() { return false; }
static bool cleanups() { return false; }
static bool emitNullabilityCheck() { return false; }
static bool ptrAuth() { return false; }
Expand Down Expand Up @@ -403,9 +404,6 @@ struct MissingFeatures {
// specs. We should make it always present.
static bool makeTripleAlwaysPresent() { return false; }

// This Itanium bit is currently being skipped in cir.
static bool itaniumRecordLayoutBuilderFinishLayout() { return false; }

static bool mustProgress() { return false; }

static bool skipTempCopy() { return false; }
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenAtomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ static void emitAtomicOp(CIRGenFunction &CGF, AtomicExpr *E, Address Dest,
case AtomicExpr::AO__atomic_load:
case AtomicExpr::AO__scoped_atomic_load_n:
case AtomicExpr::AO__scoped_atomic_load: {
auto *load = builder.createLoad(loc, Ptr).getDefiningOp();
auto load = builder.createLoad(loc, Ptr);
// FIXME(cir): add scope information.
assert(!cir::MissingFeatures::syncScopeID());
load->setAttr("mem_order", orderAttr);
Expand Down Expand Up @@ -1462,8 +1462,7 @@ void CIRGenFunction::emitAtomicStore(RValue rvalue, LValue dest,
if (IsVolatile)
store.setIsVolatile(true);

// DecorateInstructionWithTBAA
assert(!cir::MissingFeatures::tbaa());
CGM.decorateOperationWithTBAA(store, dest.getTBAAInfo());
return;
}

Expand Down
11 changes: 9 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,13 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
return create<cir::MemSetOp>(loc, dst, val, len);
}

cir::MemSetInlineOp createMemSetInline(mlir::Location loc, mlir::Value dst,
mlir::Value val,
mlir::IntegerAttr len) {
val = createIntCast(val, cir::IntType::get(getContext(), 32, true));
return create<cir::MemSetInlineOp>(loc, dst, val, len);
}

mlir::Value createNeg(mlir::Value value) {

if (auto intTy = mlir::dyn_cast<cir::IntType>(value.getType())) {
Expand Down Expand Up @@ -825,7 +832,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
addr.getAlignment());
}

mlir::Value createLoad(mlir::Location loc, Address addr,
cir::LoadOp createLoad(mlir::Location loc, Address addr,
bool isVolatile = false) {
auto ptrTy = mlir::dyn_cast<cir::PointerType>(addr.getPointer().getType());
if (addr.getElementType() != ptrTy.getPointee())
Expand All @@ -835,7 +842,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
return create<cir::LoadOp>(
loc, addr.getElementType(), addr.getPointer(), /*isDeref=*/false,
/*is_volatile=*/isVolatile, /*alignment=*/mlir::IntegerAttr{},
/*mem_order=*/cir::MemOrderAttr{});
/*mem_order=*/cir::MemOrderAttr{}, /*tbaa=*/mlir::ArrayAttr{});
}

mlir::Value createAlignedLoad(mlir::Location loc, mlir::Type ty,
Expand Down
16 changes: 14 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1554,8 +1554,20 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
return RValue::get(Dest.getPointer());
}

case Builtin::BI__builtin_memset_inline:
llvm_unreachable("BI__builtin_memset_inline NYI");
case Builtin::BI__builtin_memset_inline: {
Address Dest = emitPointerWithAlignment(E->getArg(0));
mlir::Value ByteVal = emitScalarExpr(E->getArg(1));
uint64_t size =
E->getArg(2)->EvaluateKnownConstInt(getContext()).getZExtValue();
emitNonNullArgCheck(RValue::get(Dest.getPointer()), E->getArg(0)->getType(),
E->getArg(0)->getExprLoc(), FD, 0);
builder.createMemSetInline(
getLoc(E->getSourceRange()), Dest.getPointer(), ByteVal,
mlir::IntegerAttr::get(mlir::IntegerType::get(builder.getContext(), 64),
size));
// __builtin_memset_inline has no return value
return RValue::get(nullptr);
}
case Builtin::BI__builtin___memset_chk: {
// fold __builtin_memset_chk(x, y, cst1, cst2) to memset iff cst1<=cst2.
llvm::APSInt size;
Expand Down
16 changes: 12 additions & 4 deletions clang/lib/CIR/CodeGen/CIRGenClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,14 @@ void CIRGenFunction::initializeVTablePointer(mlir::Location loc,
assert(!cir::MissingFeatures::addressSpace());
VTableField = builder.createElementBitCast(loc, VTableField,
VTableAddressPoint.getType());
builder.createStore(loc, VTableAddressPoint, VTableField);
assert(!cir::MissingFeatures::tbaa());
auto storeOp = builder.createStore(loc, VTableAddressPoint, VTableField);
TBAAAccessInfo TBAAInfo =
CGM.getTBAAVTablePtrAccessInfo(VTableAddressPoint.getType());
CGM.decorateOperationWithTBAA(storeOp, TBAAInfo);
if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
CGM.getCodeGenOpts().StrictVTablePointers) {
assert(!cir::MissingFeatures::createInvariantGroup());
}
}

void CIRGenFunction::initializeVTablePointers(mlir::Location loc,
Expand Down Expand Up @@ -1659,14 +1665,16 @@ mlir::Value CIRGenFunction::getVTablePtr(mlir::Location Loc, Address This,

Address CIRGenFunction::emitCXXMemberDataPointerAddress(
const Expr *E, Address base, mlir::Value memberPtr,
const MemberPointerType *memberPtrType, LValueBaseInfo *baseInfo) {
const MemberPointerType *memberPtrType, LValueBaseInfo *baseInfo,
TBAAAccessInfo *tbaaInfo) {
assert(!cir::MissingFeatures::cxxABI());

auto op = builder.createGetIndirectMember(getLoc(E->getSourceRange()),
base.getPointer(), memberPtr);

QualType memberType = memberPtrType->getPointeeType();
CharUnits memberAlign = CGM.getNaturalTypeAlignment(memberType, baseInfo);
CharUnits memberAlign =
CGM.getNaturalTypeAlignment(memberType, baseInfo, tbaaInfo);
memberAlign = CGM.getDynamicOffsetAlignment(
base.getAlignment(), memberPtrType->getClass()->getAsCXXRecordDecl(),
memberAlign);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void CIRGenFunction::emitAutoVarInit(const AutoVarEmission &emission) {
// its removal/optimization to the CIR lowering.
if (!constant || isa<CXXTemporaryObjectExpr>(Init)) {
initializeWhatIsTechnicallyUninitialized(Loc);
LValue lv = LValue::makeAddr(Loc, type, AlignmentSource::Decl);
LValue lv = makeAddrLValue(Loc, type, AlignmentSource::Decl);
emitExprAsInit(Init, &D, lv);
// In case lv has uses it means we indeed initialized something
// out of it while trying to build the expression, mark it as such.
Expand Down
Loading

0 comments on commit 3b3af1e

Please sign in to comment.