Skip to content

Commit dce6d61

Browse files
committed
Address first round of comments
1 parent feff135 commit dce6d61

File tree

8 files changed

+49
-11
lines changed

8 files changed

+49
-11
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,38 @@ def CIR_VTableAttr : CIR_Attr<"VTable", "vtable", [TypedAttrInterface]> {
606606
//===----------------------------------------------------------------------===//
607607

608608
def CIR_AddressSpaceAttr : CIR_EnumAttr<CIR_AddressSpace, "address_space"> {
609+
let summary = "Attribute representing memory address spaces";
610+
let description = [{
611+
Represents different memory address spaces for pointer types.
612+
Address spaces distinguish between different types of memory regions,
613+
such as global, local, or constant memory.
614+
615+
The `value` parameter is an extensible enum, which encodes target address
616+
space as an offset to the last language address space. For that reason, the
617+
attribute is implemented as custom AddressSpaceAttr, which provides custom
618+
printer and parser for the `value` parameter.
619+
620+
CIR supports two categories:
621+
- Language address spaces: Predefined spaces like `offload_global`,
622+
`offload_constant`, `offload_private` for offload programming models
623+
- Target address spaces: Numeric spaces `target<N>` for target-specific
624+
memory regions, where N is the address space number
625+
626+
Examples:
627+
```mlir
628+
// Default address space (implicit)
629+
!cir.ptr<!s32i>
630+
631+
// Language-defined offload address spaces
632+
!cir.ptr<!s32i, addrspace(offload_global)>
633+
!cir.ptr<!s32i, addrspace(offload_constant)>
634+
!cir.ptr<!s32i, addrspace(offload_private)>
635+
636+
// Target-specific numeric address spaces
637+
!cir.ptr<!s32i, addrspace(target<1>)>
638+
!cir.ptr<!s32i, addrspace(target<10>)>
639+
```
640+
}];
609641
let builders = [
610642
AttrBuilder<(ins "clang::LangAS":$langAS), [{
611643
return $_get($_ctxt, cir::toCIRAddressSpace(langAS));

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ def CIR_AddressSpace : CIR_I32EnumAttr<
4949
The `address_space` attribute is used to represent address spaces for
5050
pointer types in CIR. It provides a unified model on top of `clang::LangAS`
5151
and simplifies the representation of address spaces.
52-
53-
The `value` parameter is an extensible enum, which encodes target address
54-
space as an offset to the last language address space. For that reason, the
55-
attribute is implemented as custom AddressSpaceAttr, which provides custom
56-
printer and parser for the `value` parameter.
5752
}];
5853

5954
let genSpecializedAttr = 0;

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2052,7 +2052,6 @@ mlir::Value CIRGenFunction::emitAlloca(StringRef name, mlir::Type ty,
20522052
// CIR uses its own alloca address space rather than follow the target data
20532053
// layout like original CodeGen. The data layout awareness should be done in
20542054
// the lowering pass instead.
2055-
assert(!cir::MissingFeatures::addressSpace());
20562055
cir::PointerType localVarPtrTy =
20572056
builder.getPointerTo(ty, getCIRAllocaAddressSpace());
20582057
mlir::IntegerAttr alignIntAttr = cgm.getSize(alignment);

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
7676
SInt128Ty = cir::IntType::get(&getMLIRContext(), 128, /*isSigned=*/true);
7777
UInt8Ty = cir::IntType::get(&getMLIRContext(), 8, /*isSigned=*/false);
7878
UInt8PtrTy = cir::PointerType::get(UInt8Ty);
79+
cirAllocaAddressSpace = getTargetCIRGenInfo().getCIRAllocaAddressSpace();
7980
UInt16Ty = cir::IntType::get(&getMLIRContext(), 16, /*isSigned=*/false);
8081
UInt32Ty = cir::IntType::get(&getMLIRContext(), 32, /*isSigned=*/false);
8182
UInt64Ty = cir::IntType::get(&getMLIRContext(), 64, /*isSigned=*/false);

clang/lib/CIR/CodeGen/TargetInfo.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ bool isEmptyFieldForLayout(const ASTContext &context, const FieldDecl *fd);
3232
/// if the [[no_unique_address]] attribute would have made them empty.
3333
bool isEmptyRecordForLayout(const ASTContext &context, QualType t);
3434

35-
class CIRGenFunction;
36-
3735
class TargetCIRGenInfo {
3836
std::unique_ptr<ABIInfo> info;
3937

@@ -45,6 +43,11 @@ class TargetCIRGenInfo {
4543
/// Returns ABI info helper for the target.
4644
const ABIInfo &getABIInfo() const { return *info; }
4745

46+
/// Get the CIR address space for alloca.
47+
virtual cir::AddressSpace getCIRAllocaAddressSpace() const {
48+
return cir::AddressSpace::Default;
49+
}
50+
4851
/// Determine whether a call to an unprototyped functions under
4952
/// the given calling convention should use the variadic
5053
/// convention or the non-variadic convention.

clang/lib/CIR/Dialect/IR/CIRTypes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,13 +852,13 @@ mlir::ParseResult parseAddressSpaceValue(mlir::AsmParser &p,
852852
if (mlir::failed(result))
853853
return p.emitError(loc, "expected address space keyword");
854854

855-
// Address space is either a target address space or a regular one.
855+
// Address space is either a target address space or a language-specific one.
856856
// - If it is a target address space, we expect a value to follow in the form
857857
// of `<value>`, where value is an integer that represents the target address
858858
// space value. This value is kept in the address space enum as an offset
859859
// from the maximum address space value, which is defined in
860860
// `cir::getMaxEnumValForAddressSpace()`. This allows us to use
861-
// the same enum for both regular and target address spaces.
861+
// the same enum for both language-specific and target address spaces.
862862
// - Otherwise, we just use the parsed value.
863863
if (cir::isTargetAddressSpace(result.value())) {
864864
if (p.parseLess())

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2313,7 +2313,7 @@ getTargetAddrSpaceFromCIRAddrSpace(cir::AddressSpace addrSpace) {
23132313
if (cir::isTargetAddressSpace(addrSpace))
23142314
return cir::getTargetAddressSpaceValue(addrSpace);
23152315

2316-
llvm_unreachable("CIR AS map is not available");
2316+
llvm_unreachable("CIR target lowering is NYI");
23172317
}
23182318

23192319
static void prepareTypeConverter(mlir::LLVMTypeConverter &converter,

clang/test/CIR/address-space.c renamed to clang/test/CIR/CodeGen/address-space.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,29 @@
22
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
33
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll
44
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
5+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
6+
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
57

8+
// Test address space 1
69
// CIR: cir.func dso_local {{@.*foo.*}}(%arg0: !cir.ptr<!s32i, addrspace(target<1>)>
710
// LLVM: define dso_local void @foo(ptr addrspace(1) %0)
11+
// OGCG: define dso_local void @foo(ptr addrspace(1) noundef %arg)
812
void foo(int __attribute__((address_space(1))) *arg) {
913
return;
1014
}
1115

16+
// Test explicit address space 0 (should be same as default)
1217
// CIR: cir.func dso_local {{@.*bar.*}}(%arg0: !cir.ptr<!s32i, addrspace(target<0>)>
1318
// LLVM: define dso_local void @bar(ptr %0)
19+
// OGCG: define dso_local void @bar(ptr noundef %arg)
1420
void bar(int __attribute__((address_space(0))) *arg) {
1521
return;
1622
}
1723

24+
// Test default address space (no attribute)
1825
// CIR: cir.func dso_local {{@.*baz.*}}(%arg0: !cir.ptr<!s32i>
1926
// LLVM: define dso_local void @baz(ptr %0)
27+
// OGCG: define dso_local void @baz(ptr noundef %arg)
2028
void baz(int *arg) {
2129
return;
2230
}

0 commit comments

Comments
 (0)