Skip to content

Commit 8ca95dd

Browse files
committed
[CIR] Add default alignment to createStore
1 parent 5a75305 commit 8ca95dd

File tree

7 files changed

+24
-34
lines changed

7 files changed

+24
-34
lines changed

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,14 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
351351

352352
cir::StoreOp createStore(mlir::Location loc, mlir::Value val, mlir::Value dst,
353353
bool _volatile = false,
354-
::mlir::IntegerAttr align = {},
354+
uint64_t alignment = {},
355355
cir::MemOrderAttr order = {}) {
356356
if (mlir::cast<cir::PointerType>(dst.getType()).getPointee() !=
357357
val.getType())
358358
dst = createPtrBitcast(dst, val.getType());
359-
return create<cir::StoreOp>(loc, val, dst, _volatile, align, order,
359+
const mlir::IntegerAttr alignmentAttr = mlir::IntegerAttr::get(
360+
mlir::IntegerType::get(dst.getContext(), 64), alignment);
361+
return create<cir::StoreOp>(loc, val, dst, _volatile, alignmentAttr, order,
360362
/*tbaa=*/cir::TBAAAttr{});
361363
}
362364

clang/lib/CIR/CodeGen/CIRGenAtomic.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,7 @@ static void emitAtomicOp(CIRGenFunction &CGF, AtomicExpr *E, Address Dest,
618618
auto loadVal1 = builder.createLoad(loc, Val1);
619619
// FIXME(cir): add scope information.
620620
assert(!cir::MissingFeatures::syncScopeID());
621-
builder.createStore(loc, loadVal1, Ptr, E->isVolatile(),
622-
/*alignment=*/mlir::IntegerAttr{}, orderAttr);
621+
builder.createStore(loc, loadVal1, Ptr, E->isVolatile(), orderAttr);
623622
return;
624623
}
625624

clang/lib/CIR/CodeGen/CIRGenBuilder.h

+12-18
Original file line numberDiff line numberDiff line change
@@ -895,10 +895,19 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
895895

896896
cir::StoreOp createStore(mlir::Location loc, mlir::Value val, Address dst,
897897
bool _volatile = false,
898-
::mlir::IntegerAttr align = {},
899898
cir::MemOrderAttr order = {}) {
900-
return CIRBaseBuilderTy::createStore(loc, val, dst.getPointer(), _volatile,
901-
align, order);
899+
return createAlignedStore(loc, val, dst.getPointer(), dst.getAlignment(),
900+
_volatile, order);
901+
}
902+
903+
cir::StoreOp
904+
createAlignedStore(mlir::Location loc, mlir::Value val, mlir::Value dst,
905+
clang::CharUnits align,
906+
bool _volatile = false, cir::MemOrderAttr order = {}) {
907+
llvm::MaybeAlign mayAlign = align.getAsAlign();
908+
uint64_t alignment = mayAlign ? mayAlign->value() : 0;
909+
return CIRBaseBuilderTy::createStore(loc, val, dst, _volatile, alignment,
910+
order);
902911
}
903912

904913
cir::StoreOp createFlagStore(mlir::Location loc, bool val, mlir::Value dst) {
@@ -934,21 +943,6 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
934943
return createVecShuffle(loc, vec1, vec1, mask);
935944
}
936945

937-
cir::StoreOp
938-
createAlignedStore(mlir::Location loc, mlir::Value val, mlir::Value dst,
939-
clang::CharUnits align = clang::CharUnits::One(),
940-
bool _volatile = false, cir::MemOrderAttr order = {}) {
941-
llvm::MaybeAlign mayAlign = align.getAsAlign();
942-
mlir::IntegerAttr alignAttr;
943-
if (mayAlign) {
944-
uint64_t alignment = mayAlign ? mayAlign->value() : 0;
945-
alignAttr = mlir::IntegerAttr::get(
946-
mlir::IntegerType::get(dst.getContext(), 64), alignment);
947-
}
948-
return CIRBaseBuilderTy::createStore(loc, val, dst, _volatile, alignAttr,
949-
order);
950-
}
951-
952946
// Convert byte offset to sequence of high-level indices suitable for
953947
// GlobalViewAttr. Ideally we shouldn't deal with low-level offsets at all
954948
// but currently some parts of Clang AST, which we don't want to touch just

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ void CIRGenFunction::StartFunction(GlobalDecl gd, QualType retTy,
12961296
// Location of the store to the param storage tracked as beginning of
12971297
// the function body.
12981298
auto fnBodyBegin = getLoc(fd->getBody()->getBeginLoc());
1299-
builder.CIRBaseBuilderTy::createStore(fnBodyBegin, paramVal, addr);
1299+
builder.createStore(fnBodyBegin, paramVal, address);
13001300
}
13011301
assert(builder.getInsertionBlock() && "Should be valid");
13021302

clang/lib/CIR/CodeGen/CIRGenFunction.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -2031,12 +2031,7 @@ class CIRGenFunction : public CIRGenTypeCache {
20312031
{
20322032
mlir::OpBuilder::InsertionGuard guard(builder);
20332033
builder.restoreInsertionPoint(OutermostConditional->getInsertPoint());
2034-
builder.createStore(
2035-
value.getLoc(), value, addr,
2036-
/*volatile*/ false,
2037-
mlir::IntegerAttr::get(
2038-
mlir::IntegerType::get(value.getContext(), 64),
2039-
(uint64_t)addr.getAlignment().getAsAlign().value()));
2034+
builder.createStore(value.getLoc(), value, addr);
20402035
}
20412036
}
20422037

clang/test/CIR/CodeGen/OpenCL/addrspace-alloca.cl

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ kernel void func(local int *p) {
2323
// LLVM-NEXT: %[[#ALLOCA_PTR:]] = alloca ptr, i64 1, align 8
2424

2525
// Store of the argument `p`
26-
// CIR-NEXT: cir.store %arg0, %[[#ALLOCA_P]] : !cir.ptr<!s32i, addrspace(offload_local)>, !cir.ptr<!cir.ptr<!s32i, addrspace(offload_local)>, addrspace(offload_private)>
26+
// CIR-NEXT: cir.store align(8) %arg0, %[[#ALLOCA_P]] : !cir.ptr<!s32i, addrspace(offload_local)>, !cir.ptr<!cir.ptr<!s32i, addrspace(offload_local)>, addrspace(offload_private)>
2727
// LLVM-NEXT: store ptr addrspace(3) %{{[0-9]+}}, ptr %[[#ALLOCA_P]], align 8
2828

2929
ptr = &x;
30-
// CIR-NEXT: cir.store %[[#ALLOCA_X]], %[[#ALLOCA_PTR]] : !cir.ptr<!s32i, addrspace(offload_private)>, !cir.ptr<!cir.ptr<!s32i, addrspace(offload_private)>, addrspace(offload_private)>
31-
// LLVM-NEXT: store ptr %[[#ALLOCA_X]], ptr %[[#ALLOCA_PTR]]
30+
// CIR-NEXT: cir.store align(8) %[[#ALLOCA_X]], %[[#ALLOCA_PTR]] : !cir.ptr<!s32i, addrspace(offload_private)>, !cir.ptr<!cir.ptr<!s32i, addrspace(offload_private)>, addrspace(offload_private)>
31+
// LLVM-NEXT: store ptr %[[#ALLOCA_X]], ptr %[[#ALLOCA_PTR]], align 8
3232

3333
return;
3434
}

clang/test/CIR/CodeGen/OpenCL/str_literals.cl

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ __constant char *__constant y = "hello world";
1717
// LLVM: addrspace(2) constant{{.*}}"f\00"
1818

1919
void f() {
20-
// CIR: cir.store %{{.*}}, %{{.*}} : !cir.ptr<!s8i, addrspace(offload_constant)>, !cir.ptr<!cir.ptr<!s8i, addrspace(offload_constant)>, addrspace(offload_private)>
21-
// LLVM: store ptr addrspace(2) {{.*}}, ptr
20+
// CIR: cir.store align(8) %{{.*}}, %{{.*}} : !cir.ptr<!s8i, addrspace(offload_constant)>, !cir.ptr<!cir.ptr<!s8i, addrspace(offload_constant)>, addrspace(offload_private)>
21+
// LLVM: store ptr addrspace(2) {{.*}}, ptr {{.*}} align 8
2222
constant const char *f3 = __func__;
2323
}

0 commit comments

Comments
 (0)