Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into bitfield-assignment…
Browse files Browse the repository at this point in the history
…-operator
  • Loading branch information
gitoleg committed Dec 20, 2024
2 parents f3f87d3 + 232db8c commit d67a728
Show file tree
Hide file tree
Showing 31 changed files with 975 additions and 281 deletions.
6 changes: 3 additions & 3 deletions clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
/*alignment=*/intAttr,
/*mem_order=*/
cir::MemOrderAttr{},
/*tbaa=*/mlir::ArrayAttr{});
/*tbaa=*/cir::TBAAAttr{});
}

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

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

cir::MemCpyOp createMemCpy(mlir::Location loc, mlir::Value dst,
Expand Down
8 changes: 4 additions & 4 deletions clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ include "clang/CIR/Interfaces/ASTAttrInterfaces.td"
// CIR Attrs
//===----------------------------------------------------------------------===//

class CIR_Attr<string name, string attrMnemonic, list<Trait> traits = []>
: AttrDef<CIR_Dialect, name, traits> {
class CIR_Attr<string name, string attrMnemonic, list<Trait> traits = [],
string baseCppClass = "::mlir::Attribute">
: AttrDef<CIR_Dialect, name, traits, baseCppClass> {
let mnemonic = attrMnemonic;
}

Expand Down Expand Up @@ -1294,8 +1295,7 @@ def GlobalAnnotationValuesAttr : CIR_Attr<"GlobalAnnotationValues",
let genVerifyDecl = 1;
}

def CIR_TBAAAttr : CIR_Attr<"TBAA", "tbaa", []> {
}
include "clang/CIR/Dialect/IR/CIRTBAAAttrs.td"

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

Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def LoadOp : CIR_Op<"load", [
UnitAttr:$is_volatile,
OptionalAttr<I64Attr>:$alignment,
OptionalAttr<MemOrder>:$mem_order,
OptionalAttr<ArrayAttr>:$tbaa
OptionalAttr<CIR_AnyTBAAAttr>:$tbaa
);
let results = (outs CIR_AnyType:$result);

Expand Down Expand Up @@ -657,7 +657,7 @@ def StoreOp : CIR_Op<"store", [
UnitAttr:$is_volatile,
OptionalAttr<I64Attr>:$alignment,
OptionalAttr<MemOrder>:$mem_order,
OptionalAttr<ArrayAttr>:$tbaa);
OptionalAttr<CIR_AnyTBAAAttr>:$tbaa);

let assemblyFormat = [{
(`volatile` $is_volatile^)?
Expand Down Expand Up @@ -4068,7 +4068,7 @@ def CopyOp : CIR_Op<"copy",
let arguments = (ins Arg<CIR_PointerType, "", [MemWrite]>:$dst,
Arg<CIR_PointerType, "", [MemRead]>:$src,
UnitAttr:$is_volatile,
OptionalAttr<ArrayAttr>:$tbaa);
OptionalAttr<CIR_TBAAAttr>:$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 Down
38 changes: 38 additions & 0 deletions clang/include/clang/CIR/Dialect/IR/CIRTBAAAttrs.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
// TBAAAttr
//===----------------------------------------------------------------------===//

def CIR_TBAAAttr : CIR_Attr<"TBAA", "tbaa", []> {
let summary = "CIR dialect TBAA base attribute";
}

//===----------------------------------------------------------------------===//
// TBAAScalarAttr
//===----------------------------------------------------------------------===//

def CIR_TBAAScalarAttr : CIR_Attr<"TBAAScalar", "tbaa_scalar", [], "TBAAAttr"> {
let summary = "Describes a scalar type in TBAA with an identifier.";

let parameters = (ins CIR_AnyScalarType : $type);

let description = [{
Define a TBAA attribute.

Example:
```mlir
// CIR_TBAAScalarAttr
#tbaa_scalar = #cir.tbaa_scalar<type = !s32i>
#tbaa_scalar1 = #cir.tbaa_scalar<type = !u32i>
```

See the following link for more details:
https://llvm.org/docs/LangRef.html#tbaa-metadata
}];

let assemblyFormat = "`<` struct(params) `>`";
}

def CIR_AnyTBAAAttr : AnyAttrOf<[
CIR_TBAAAttr,
CIR_TBAAScalarAttr
]>;
43 changes: 40 additions & 3 deletions clang/include/clang/CIR/Dialect/IR/CIRTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ include "mlir/Interfaces/DataLayoutInterfaces.td"
include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/EnumAttr.td"

// Specify the TBAA name of CIR_type
class TBAALoweringInfo {
string tbaaName = "";
}

//===----------------------------------------------------------------------===//
// CIR Types
//===----------------------------------------------------------------------===//

class CIR_Type<string name, string typeMnemonic, list<Trait> traits = [],
string baseCppClass = "::mlir::Type">
: TypeDef<CIR_Dialect, name, traits, baseCppClass> {
: TypeDef<CIR_Dialect, name, traits, baseCppClass>, TBAALoweringInfo {
let mnemonic = typeMnemonic;
}

Expand Down Expand Up @@ -74,6 +79,28 @@ def CIR_IntType : CIR_Type<"Int", "int",
static bool isValidPrimitiveIntBitwidth(unsigned width) {
return width == 8 || width == 16 || width == 32 || width == 64;
}

llvm::StringRef getTBAATypeName() const {
switch (getWidth()) {
case 1:
case 8: {
return "omnipotent char";
}
case 16: {
return "short";
}
case 32: {
return "int";
}
case 64: {
return "long";
}
default: {
llvm::errs() << "unknown type: " << *this << "\n";
return "unknown";
}
}
}
}];
let genVerifyDecl = 1;
}
Expand Down Expand Up @@ -140,6 +167,7 @@ class CIR_FloatType<string name, string mnemonic>
]> {}

def CIR_Single : CIR_FloatType<"Single", "float"> {
let tbaaName = "float";
let summary = "CIR single-precision float type";
let description = [{
Floating-point type that represents the `float` type in C/C++. Its
Expand All @@ -148,6 +176,7 @@ def CIR_Single : CIR_FloatType<"Single", "float"> {
}

def CIR_Double : CIR_FloatType<"Double", "double"> {
let tbaaName = "double";
let summary = "CIR double-precision float type";
let description = [{
Floating-point type that represents the `double` type in C/C++. Its
Expand Down Expand Up @@ -184,6 +213,7 @@ def CIR_FP128 : CIR_FloatType<"FP128", "f128"> {
}

def CIR_LongDouble : CIR_FloatType<"LongDouble", "long_double"> {
let tbaaName = "long double";
let summary = "CIR extended-precision float type";
let description = [{
Floating-point type that represents the `long double` type in C/C++.
Expand Down Expand Up @@ -241,7 +271,7 @@ def CIR_ComplexType : CIR_Type<"Complex", "complex",

def CIR_PointerType : CIR_Type<"Pointer", "ptr",
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {

let tbaaName = "any pointer";
let summary = "CIR pointer type";
let description = [{
`CIR.ptr` is a type returned by any op generating a pointer in C++.
Expand Down Expand Up @@ -317,7 +347,7 @@ def CIR_DataMemberType : CIR_Type<"DataMember", "data_member",
def CIR_BoolType :
CIR_Type<"Bool", "bool",
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {

let tbaaName = "bool";
let summary = "CIR bool type";
let description = [{
`cir.bool` represent's C++ bool type.
Expand Down Expand Up @@ -609,4 +639,11 @@ def CIR_AnyType : AnyTypeOf<[
CIR_ComplexType
]>;

def CIR_AnyScalarType : AnyTypeOf<[
CIR_IntType, CIR_PointerType, CIR_DataMemberType, CIR_MethodType,
CIR_BoolType, CIR_ArrayType, CIR_VectorType, CIR_FuncType, CIR_VoidType,
CIR_ExceptionType, CIR_AnyFloat, CIR_FP16, CIR_BFloat16,
CIR_ComplexType
]>;

#endif // MLIR_CIR_DIALECT_CIR_TYPES
4 changes: 4 additions & 0 deletions clang/include/clang/CIR/Dialect/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ add_public_tablegen_target(MLIRCIREnumsGen)
clang_tablegen(CIRBuiltinsLowering.inc -gen-cir-builtins-lowering
SOURCE CIROps.td
TARGET CIRBuiltinsLowering)

clang_tablegen(CIRTBAANameLowering.inc -gen-cir-tbaa-name-lowering
SOURCE CIRTypes.td
TARGET CIRTBAANameLowering)
7 changes: 6 additions & 1 deletion clang/include/clang/CIR/MissingFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ 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 tbaaStruct() { return false; }
static bool tbaaTagForStruct() { return false; }
static bool tbaaVTablePtr() { return false; }
static bool tbaaIncompleteType() { return false; }
static bool tbaaMergeTBAAInfo() { return false; }
static bool tbaaMayAlias() { return false; }
static bool cleanups() { return false; }
static bool emitNullabilityCheck() { return false; }
static bool ptrAuth() { return false; }
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 @@ -839,7 +839,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{}, /*tbaa=*/mlir::ArrayAttr{});
/*mem_order=*/cir::MemOrderAttr{}, /*tbaa=*/cir::TBAAAttr{});
}

mlir::Value createAlignedLoad(mlir::Location loc, mlir::Type ty,
Expand Down
26 changes: 15 additions & 11 deletions clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2679,19 +2679,16 @@ static mlir::Value emitCommonNeonSISDBuiltinExpr(
return emitNeonCall(builder, {argTy}, ops, "aarch64.neon.uaddlv", resultTy,
loc);
case NEON::BI__builtin_neon_vaddv_f32:
llvm_unreachable(" neon_vaddv_f32 NYI ");
case NEON::BI__builtin_neon_vaddv_s32:
llvm_unreachable(" neon_vaddv_s32 NYI ");
case NEON::BI__builtin_neon_vaddv_u32:
llvm_unreachable(" neon_vaddv_u32 NYI ");
case NEON::BI__builtin_neon_vaddvq_f32:
llvm_unreachable(" neon_vaddvq_f32 NYI ");
case NEON::BI__builtin_neon_vaddvq_f64:
llvm_unreachable(" neon_vaddvq_f64 NYI ");
return emitNeonCall(builder, {argTy}, ops, "aarch64.neon.faddv", resultTy,
loc);
case NEON::BI__builtin_neon_vaddv_s32:
case NEON::BI__builtin_neon_vaddvq_s32:
llvm_unreachable(" neon_vaddvq_s32 NYI ");
case NEON::BI__builtin_neon_vaddvq_s64:
llvm_unreachable(" neon_vaddvq_s64 NYI ");
return emitNeonCall(builder, {argTy}, ops, "aarch64.neon.saddv", resultTy,
loc);
case NEON::BI__builtin_neon_vaddv_u32:
case NEON::BI__builtin_neon_vaddvq_u32:
case NEON::BI__builtin_neon_vaddvq_u64:
return emitNeonCall(builder, {argTy}, ops, "aarch64.neon.uaddv", resultTy,
Expand Down Expand Up @@ -3924,8 +3921,15 @@ CIRGenFunction::emitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
getLoc(E->getExprLoc()));
}
case NEON::BI__builtin_neon_vmax_v:
case NEON::BI__builtin_neon_vmaxq_v:
llvm_unreachable("NEON::BI__builtin_neon_vmaxq_v NYI");
case NEON::BI__builtin_neon_vmaxq_v: {
mlir::Location loc = getLoc(E->getExprLoc());
Ops[0] = builder.createBitcast(Ops[0], ty);
Ops[1] = builder.createBitcast(Ops[1], ty);
if (cir::isFPOrFPVectorTy(ty)) {
return builder.create<cir::FMaximumOp>(loc, Ops[0], Ops[1]);
}
return builder.create<cir::BinOp>(loc, cir::BinOpKind::Max, Ops[0], Ops[1]);
}
case NEON::BI__builtin_neon_vmaxh_f16: {
llvm_unreachable("NEON::BI__builtin_neon_vmaxh_f16 NYI");
}
Expand Down
Loading

0 comments on commit d67a728

Please sign in to comment.