Skip to content

Commit 533e322

Browse files
committed
Apply 2nd round of suggestions
1 parent b5180ef commit 533e322

File tree

10 files changed

+23
-33
lines changed

10 files changed

+23
-33
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,14 @@ def CIR_VTableAttr : CIR_Attr<"VTable", "vtable", [TypedAttrInterface]> {
607607

608608
def CIR_TargetAddressSpaceAttr : CIR_Attr< "TargetAddressSpace",
609609
"target_address_space"> {
610-
let summary = "Attribute representing a target-specific numeric address space";
610+
let summary = "Represents a target-specific numeric address space";
611611
let description = [{
612-
Represents a target-specific numeric address space for pointer types.
612+
The TargetAddressSpaceAttr represents a target-specific numeric address space,
613+
corresponding to the LLVM IR `addressspace` qualifier and the clang
614+
`address_space` attribute.
615+
616+
A value of zero represents the default address space. The semantics of non-zero
617+
address spaces are target-specific.
613618

614619
Example:
615620
```mlir

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ bool isValidFundamentalIntWidth(unsigned width);
3838
/// void, or abstract types.
3939
bool isSized(mlir::Type ty);
4040

41-
//===----------------------------------------------------------------------===//
42-
// AddressSpace helpers
43-
//===----------------------------------------------------------------------===//
44-
45-
/// Returns the integer value of a CIR address space for LLVM.
46-
unsigned getTargetAddrSpaceFromAttr(cir::TargetAddressSpaceAttr attr);
47-
4841
} // namespace cir
4942

5043
//===----------------------------------------------------------------------===//

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,6 @@ def CIR_PointerType : CIR_Type<"Pointer", "ptr", [
238238
records, arrays, vectors, functions, and other pointers. It can also point
239239
to incomplete types, such as incomplete records.
240240

241-
Note: Data-member pointers and method pointers are represented by
242-
`!cir.data_member` and `!cir.method` types, respectively not by
243-
`!cir.ptr` type.
244-
245241
Examples:
246242

247243
```mlir
@@ -256,8 +252,7 @@ def CIR_PointerType : CIR_Type<"Pointer", "ptr", [
256252
let parameters = (ins
257253
"mlir::Type":$pointee,
258254
OptionalParameter<
259-
"cir::TargetAddressSpaceAttr"
260-
>:$addrSpace
255+
"cir::TargetAddressSpaceAttr">:$addrSpace
261256
);
262257

263258
let skipDefaultBuilders = 1;

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,7 @@ mlir::Value CIRGenFunction::emitAlloca(StringRef name, mlir::Type ty,
20532053
// layout like original CodeGen. The data layout awareness should be done in
20542054
// the lowering pass instead.
20552055
cir::PointerType localVarPtrTy =
2056-
builder.getPointerTo(ty, getASTAllocaAddressSpace());
2056+
builder.getPointerTo(ty, getCIRAllocaAddressSpace());
20572057
mlir::IntegerAttr alignIntAttr = cgm.getSize(alignment);
20582058

20592059
mlir::Value addr;

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +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-
ASTAllocaAddressSpace = getTargetCIRGenInfo().getASTAllocaAddressSpace();
79+
cirAllocaAddressSpace = getTargetCIRGenInfo().getCIRAllocaAddressSpace();
8080
UInt16Ty = cir::IntType::get(&getMLIRContext(), 16, /*isSigned=*/false);
8181
UInt32Ty = cir::IntType::get(&getMLIRContext(), 32, /*isSigned=*/false);
8282
UInt64Ty = cir::IntType::get(&getMLIRContext(), 64, /*isSigned=*/false);

clang/lib/CIR/CodeGen/CIRGenTypeCache.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct CIRGenTypeCache {
7474
/// The alignment of size_t.
7575
unsigned char SizeAlignInBytes;
7676

77-
LangAS ASTAllocaAddressSpace;
77+
cir::TargetAddressSpaceAttr cirAllocaAddressSpace;
7878

7979
clang::CharUnits getSizeAlign() const {
8080
return clang::CharUnits::fromQuantity(SizeAlignInBytes);
@@ -84,7 +84,9 @@ struct CIRGenTypeCache {
8484
return clang::CharUnits::fromQuantity(PointerAlignInBytes);
8585
}
8686

87-
LangAS getASTAllocaAddressSpace() const { return ASTAllocaAddressSpace; }
87+
cir::TargetAddressSpaceAttr getCIRAllocaAddressSpace() const {
88+
return cirAllocaAddressSpace;
89+
}
8890
};
8991

9092
} // namespace clang::CIRGen

clang/lib/CIR/CodeGen/TargetInfo.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ class TargetCIRGenInfo {
4444
/// Returns ABI info helper for the target.
4545
const ABIInfo &getABIInfo() const { return *info; }
4646

47-
/// Get the AST address space for alloca.
48-
virtual LangAS getASTAllocaAddressSpace() const { return LangAS::Default; }
47+
/// Get the address space for alloca.
48+
virtual cir::TargetAddressSpaceAttr getCIRAllocaAddressSpace() const {
49+
return nullptr;
50+
}
4951

5052
/// Determine whether a call to an unprototyped functions under
5153
/// the given calling convention should use the variadic

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -805,13 +805,6 @@ mlir::LogicalResult cir::VectorType::verify(
805805
// TargetAddressSpace definitions
806806
//===----------------------------------------------------------------------===//
807807

808-
// Convert from TargetAddressSpaceAttr to the actual integer address space.
809-
unsigned cir::getTargetAddrSpaceFromAttr(cir::TargetAddressSpaceAttr attr) {
810-
if (!attr)
811-
return 0; // Default address space is 0 in LLVM.
812-
return attr.getValue().getUInt();
813-
}
814-
815808
mlir::ParseResult parseTargetAddressSpace(mlir::AsmParser &p,
816809
cir::TargetAddressSpaceAttr &attr) {
817810
if (failed(p.parseKeyword("target_address_space")))
@@ -820,7 +813,7 @@ mlir::ParseResult parseTargetAddressSpace(mlir::AsmParser &p,
820813
if (failed(p.parseLParen()))
821814
return mlir::failure();
822815

823-
int64_t targetValue;
816+
int32_t targetValue;
824817
if (failed(p.parseInteger(targetValue)))
825818
return p.emitError(p.getCurrentLocation(),
826819
"expected integer address space value");
@@ -830,9 +823,8 @@ mlir::ParseResult parseTargetAddressSpace(mlir::AsmParser &p,
830823
"expected ')' after address space value");
831824

832825
mlir::MLIRContext *context = p.getBuilder().getContext();
833-
auto intTy = mlir::IntegerType::get(context, 32);
834826
attr = cir::TargetAddressSpaceAttr::get(
835-
context, mlir::IntegerAttr::get(intTy, targetValue));
827+
context, p.getBuilder().getUI32IntegerAttr(targetValue));
836828
return mlir::success();
837829
}
838830

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2309,7 +2309,8 @@ mlir::LogicalResult CIRToLLVMSelectOpLowering::matchAndRewrite(
23092309
static void prepareTypeConverter(mlir::LLVMTypeConverter &converter,
23102310
mlir::DataLayout &dataLayout) {
23112311
converter.addConversion([&](cir::PointerType type) -> mlir::Type {
2312-
unsigned addrSpace = cir::getTargetAddrSpaceFromAttr(type.getAddrSpace());
2312+
unsigned addrSpace =
2313+
type.getAddrSpace() ? type.getAddrSpace().getValue().getUInt() : 0;
23132314
return mlir::LLVM::LLVMPointerType::get(type.getContext(), addrSpace);
23142315
});
23152316
converter.addConversion([&](cir::VPtrType type) -> mlir::Type {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ void bar(int __attribute__((address_space(0))) *arg) {
2727
// OGCG: define dso_local void @baz(ptr noundef %arg)
2828
void baz(int *arg) {
2929
return;
30-
}
30+
}

0 commit comments

Comments
 (0)