Skip to content

Commit 58310a1

Browse files
committed
[CIR] Remove saturated types; add _BitInt types
This is a follow-up commit to "Integral types; simple global variables" Remove the saturated integral types from the type conversion code, since I am not confident that they are implemented correctly. They are part of fixed-point support, which has not yet been implemented in ClangIR. Add _BitInt types to the type conversion code, and add test cases for them. Improve the documentation for FuncOp, GlobalOp, and IntType.
1 parent 3f911a4 commit 58310a1

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ class CIR_Op<string mnemonic, list<Trait> traits = []> :
8686
def GlobalOp : CIR_Op<"global"> {
8787
let summary = "Declare or define a global variable";
8888
let description = [{
89-
... lots of text to be added later ...
89+
The `cir.global` operation declares or defines a named global variable.
90+
91+
The backing memory for the variable is allocated statically and is
92+
described by the type of the variable.
9093
}];
9194

9295
let arguments = (ins SymbolNameAttr:$sym_name, TypeAttr:$sym_type);
@@ -112,7 +115,8 @@ def GlobalOp : CIR_Op<"global"> {
112115
def FuncOp : CIR_Op<"func"> {
113116
let summary = "Declare or define a function";
114117
let description = [{
115-
... lots of text to be added later ...
118+
THe `cir.func` operation defines a function, similar to the `mlir::FuncOp`
119+
built-in.
116120
}];
117121

118122
let arguments = (ins SymbolNameAttr:$sym_name);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def CIR_IntType : CIR_Type<"Int", "int",
3535
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {
3636
let summary = "Integer type with arbitrary precision up to a fixed limit";
3737
let description = [{
38-
CIR type that represents integer types with arbitrary precision.
38+
CIR type that represents integer types with arbitrary precision, including
39+
standard integral types such as `int` and `long`, extended integral types
40+
such as `__int128`, and arbitrary width types such as `_BitInt(n)`.
3941

4042
Those integer types that are directly available in C/C++ standard are called
4143
primitive integer types. Said types are: `signed char`, `short`, `int`,

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ void CIRGenModule::emitGlobal(clang::GlobalDecl gd) {
6767
return;
6868
}
6969
} else {
70-
const auto *vd = cast<VarDecl>(global);
71-
assert(vd->isFileVarDecl() && "Cannot emit local var decl as global");
70+
assert(cast<VarDecl>(global)->isFileVarDecl() &&
71+
"Cannot emit local var decl as global");
7272
}
7373

7474
// TODO(CIR): Defer emitting some global definitions until later

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
3636
case BuiltinType::ShortAccum:
3737
case BuiltinType::ShortFract:
3838
case BuiltinType::WChar_S:
39-
// Saturated signed types.
40-
case BuiltinType::SatAccum:
41-
case BuiltinType::SatFract:
42-
case BuiltinType::SatLongAccum:
43-
case BuiltinType::SatLongFract:
44-
case BuiltinType::SatShortAccum:
45-
case BuiltinType::SatShortFract:
4639
resultType = cir::IntType::get(cgm.getBuilder().getContext(),
4740
context.getTypeSize(ty),
4841
/*isSigned=*/true);
@@ -65,13 +58,6 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
6558
case BuiltinType::UShortAccum:
6659
case BuiltinType::UShortFract:
6760
case BuiltinType::WChar_U:
68-
// Saturated unsigned types.
69-
case BuiltinType::SatUAccum:
70-
case BuiltinType::SatUFract:
71-
case BuiltinType::SatULongAccum:
72-
case BuiltinType::SatULongFract:
73-
case BuiltinType::SatUShortAccum:
74-
case BuiltinType::SatUShortFract:
7561
resultType = cir::IntType::get(cgm.getBuilder().getContext(),
7662
context.getTypeSize(ty),
7763
/*isSigned=*/false);
@@ -84,6 +70,13 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
8470
}
8571
break;
8672
}
73+
case Type::BitInt: {
74+
const auto *bitIntTy = cast<BitIntType>(type);
75+
resultType =
76+
cir::IntType::get(cgm.getBuilder().getContext(), bitIntTy->getNumBits(),
77+
bitIntTy->isSigned());
78+
break;
79+
}
8780
default:
8881
cgm.errorNYI(SourceLocation(), "processing of type", type);
8982
resultType =

clang/test/CIR/global-var-simple.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,9 @@ char16_t c16;
5151

5252
char32_t c32;
5353
// CHECK: cir.global @c32 : !cir.int<u, 32>
54+
55+
_BitInt(20) sb20;
56+
// CHECK: cir.global @sb20 : !cir.int<s, 20>
57+
58+
unsigned _BitInt(48) ub48;
59+
// CHECK: cir.global @ub48 : !cir.int<u, 48>

0 commit comments

Comments
 (0)