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
28 changes: 28 additions & 0 deletions clang/include/clang/CIR/Dialect/IR/CIRAttrConstraints.td
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,32 @@ def CIR_AnyIntOrFloatAttr : AnyAttrOf<[CIR_AnyIntAttr, CIR_AnyFPAttr],
def CIR_IntArrayAttr : TypedArrayAttrBase<CIR_AnyIntAttr,
"integer array attribute">;

//===----------------------------------------------------------------------===//
// TBAAAttr constraints
//===----------------------------------------------------------------------===//

def CIR_TBAAConstraint
: CIR_AttrConstraint<"::cir::TBAAAttr", "base attribute for TBAA">;
def CIR_TBAAOmnipotentCharConstraint
: CIR_AttrConstraint<"::cir::TBAAOmnipotentCharAttr", "Omnipotent char type">;
def CIR_TBAAVTablePointerConstraint
: CIR_AttrConstraint<"::cir::TBAAVTablePointerAttr", "VTable pointer type">;
def CIR_TBAAScalarConstraint
: CIR_AttrConstraint<"::cir::TBAAScalarAttr", "Scalar type with identifier">;
def CIR_TBAAStructConstraint
: CIR_AttrConstraint<"::cir::TBAAStructAttr", "Struct type">;
def CIR_TBAATagConstraint
: CIR_AttrConstraint<"::cir::TBAATagAttr", "Member of a TBAA struct type">;

def CIR_AnyTBAAAttr : AnyAttrOf<[
CIR_TBAAConstraint,
CIR_TBAAOmnipotentCharConstraint,
CIR_TBAAVTablePointerConstraint,
CIR_TBAAScalarConstraint,
CIR_TBAAStructConstraint,
CIR_TBAATagConstraint
]> {
string cppType = "::mlir::Attribute";
}

#endif // CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD
2 changes: 1 addition & 1 deletion clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -4556,7 +4556,7 @@ def CIR_CopyOp : CIR_Op<"copy",[
let arguments = (ins Arg<CIR_PointerType, "", [MemWrite]>:$dst,
Arg<CIR_PointerType, "", [MemRead]>:$src,
UnitAttr:$is_volatile,
OptionalAttr<CIR_TBAAAttr>:$tbaa);
OptionalAttr<CIR_AnyTBAAAttr>:$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
16 changes: 4 additions & 12 deletions clang/include/clang/CIR/Dialect/IR/CIRTBAAAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef CLANG_CIR_DIALECT_IR_CIRTBAAATTRS_TD
#define CLANG_CIR_DIALECT_IR_CIRTBAAATTRS_TD

include "clang/CIR/Dialect/IR/CIRAttrConstraints.td"
include "clang/CIR/Dialect/IR/CIRTypes.td"

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -91,8 +92,8 @@ def CIR_TBAAScalarAttr : CIR_TBAAAttrCase< "TBAAScalar", "tbaa_scalar"> {
}

def CIR_TBAATagAttr : CIR_TBAAAttrCase<"TBAATag", "tbaa_tag"> {
let parameters = (ins CIR_TBAAAttr
: $base, CIR_TBAAAttr
let parameters = (ins CIR_AnyTBAAAttr
: $base, CIR_AnyTBAAAttr
: $access, "int64_t"
: $offset);

Expand All @@ -101,7 +102,7 @@ def CIR_TBAATagAttr : CIR_TBAAAttrCase<"TBAATag", "tbaa_tag"> {

def CIR_TBAAMemberAttr : CIR_Attr<"TBAAMember", "tbaa_member"> {
let summary = "Attribute representing a member of a TBAA structured type.";
let parameters = (ins "TBAAAttr":$type_desc,
let parameters = (ins CIR_AnyTBAAAttr:$type_desc,
"int64_t":$offset);
let description = [{
Define a TBAA struct attribute.
Expand Down Expand Up @@ -170,13 +171,4 @@ def CIR_TBAAStructAttr : CIR_TBAAAttrCase<"TBAAStruct", "tbaa_struct"> {
let assemblyFormat = "`<` struct(params) `>`";
}

def CIR_AnyTBAAAttr : AnyAttrOf<[
CIR_TBAAAttr,
CIR_TBAAOmnipotentCharAttr,
CIR_TBAAVTablePointerAttr,
CIR_TBAAScalarAttr,
CIR_TBAAStructAttr,
CIR_TBAATagAttr
]>;

#endif // CLANG_CIR_DIALECT_IR_CIRTBAAATTRS_TD
28 changes: 28 additions & 0 deletions clang/test/CIR/IR/invalid.cir
Original file line number Diff line number Diff line change
Expand Up @@ -1630,3 +1630,31 @@ cir.func @invalidConditionTerminator (%arg0 : !cir.bool) -> !cir.void {
}
cir.return
}

// -----

!s16i = !cir.int<s, 16>
!s32i = !cir.int<s, 32>
#fn_attr = #cir<extra({nothrow = #cir.nothrow, uwtable = #cir.uwtable<async>})>
!rec_S = !cir.record<struct "S" {!s16i} #cir.record.decl.ast>
#tbaa_scalar = #cir.tbaa_scalar<id = "short", type = !s16i>
// expected-error @below {{invalid kind of attribute specified}}
// expected-error @below {{failed to parse CIR_TBAAStructAttr parameter 'members'}}
#tbaa_struct = #cir.tbaa_struct<id = "S", members = {#cir.uwtable<async>}>
#tbaa_tag = #cir.tbaa_tag<base = #tbaa_struct, access = #tbaa_scalar, offset = 0>
cir.global external dso_local @glob = #cir.zero : !rec_S {alignment = 2 : i64}
cir.func dso_local @main() -> !s32i extra(#fn_attr) {
%0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"] {alignment = 4 : i64}
%1 = cir.const #cir.int<0> : !s32i
%2 = cir.cast(integral, %1 : !s32i), !s16i
%3 = cir.get_global @glob : !cir.ptr<!rec_S>
%4 = cir.get_member %3[0] {name = "i"} : !cir.ptr<!rec_S> -> !cir.ptr<!s16i>
cir.store align(2) %2, %4 : !s16i, !cir.ptr<!s16i> tbaa(#tbaa_tag)
%5 = cir.get_global @glob : !cir.ptr<!rec_S>
%6 = cir.get_member %5[0] {name = "i"} : !cir.ptr<!rec_S> -> !cir.ptr<!s16i>
%7 = cir.load align(2) %6 : !cir.ptr<!s16i>, !s16i tbaa(#tbaa_tag)
%8 = cir.cast(integral, %7 : !s16i), !s32i
cir.store %8, %0 : !s32i, !cir.ptr<!s32i>
%9 = cir.load %0 : !cir.ptr<!s32i>, !s32i
cir.return %9 : !s32i
}
28 changes: 28 additions & 0 deletions clang/test/CIR/IR/tbaa-parse.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: cir-opt %s -o - | FileCheck %s

!s16i = !cir.int<s, 16>
!s32i = !cir.int<s, 32>
#fn_attr = #cir<extra({nothrow = #cir.nothrow, uwtable = #cir.uwtable<async>})>
!rec_S = !cir.record<struct "S" {!s16i} #cir.record.decl.ast>
// CHECK: #tbaa_scalar = #cir.tbaa_scalar<id = "short", type = !s16i>
// CHECK: #tbaa_struct = #cir.tbaa_struct<id = "S", members = {<#tbaa_scalar, 0>}>
// CHECK: #tbaa_tag = #cir.tbaa_tag<base = #tbaa_struct, access = #tbaa_scalar, offset = 0>
#tbaa_scalar = #cir.tbaa_scalar<id = "short", type = !s16i>
#tbaa_struct = #cir.tbaa_struct<id = "S", members = {<#tbaa_scalar, 0>}>
#tbaa_tag = #cir.tbaa_tag<base = #tbaa_struct, access = #tbaa_scalar, offset = 0>
cir.global external dso_local @glob = #cir.zero : !rec_S {alignment = 2 : i64}
cir.func dso_local @main() -> !s32i extra(#fn_attr) {
%0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"] {alignment = 4 : i64}
%1 = cir.const #cir.int<0> : !s32i
%2 = cir.cast(integral, %1 : !s32i), !s16i
%3 = cir.get_global @glob : !cir.ptr<!rec_S>
%4 = cir.get_member %3[0] {name = "i"} : !cir.ptr<!rec_S> -> !cir.ptr<!s16i>
cir.store align(2) %2, %4 : !s16i, !cir.ptr<!s16i> tbaa(#tbaa_tag)
%5 = cir.get_global @glob : !cir.ptr<!rec_S>
%6 = cir.get_member %5[0] {name = "i"} : !cir.ptr<!rec_S> -> !cir.ptr<!s16i>
%7 = cir.load align(2) %6 : !cir.ptr<!s16i>, !s16i tbaa(#tbaa_tag)
%8 = cir.cast(integral, %7 : !s16i), !s32i
cir.store %8, %0 : !s32i, !cir.ptr<!s32i>
%9 = cir.load %0 : !cir.ptr<!s32i>, !s32i
cir.return %9 : !s32i
}
Loading