Skip to content

Commit 645ffaa

Browse files
committed
Apply feedback
1 parent 0b07a4a commit 645ffaa

File tree

4 files changed

+54
-27
lines changed

4 files changed

+54
-27
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4057,32 +4057,36 @@ def CIR_ExpectOp : CIR_Op<"expect", [
40574057
//===----------------------------------------------------------------------===//
40584058

40594059
def CIR_PrefetchOp : CIR_Op<"prefetch"> {
4060-
let summary = "prefetch operation";
4060+
let summary = "Prefetch operation";
40614061
let description = [{
4062-
The `cir.prefetch` op prefetches data from the memmory address.
4062+
The `cir.prefetch` operation is a hint to the code generator to insert a
4063+
prefetch instruction if supported; otherwise, it is a noop. Prefetches
4064+
have no effect on the behavior of the program but can change its
4065+
performance characteristics.
40634066

40644067
```mlir
40654068
cir.prefetch(%0 : !cir.ptr<!void>) locality(1) write
40664069
```
40674070

4068-
This opcode has the three attributes:
4069-
1. The $locality is a temporal locality specifier
4070-
ranging from (0) - no locality, to (3) - extremely local keep in cache.
4071-
2. The $isWrite is the specifier determining if the prefetch is prepaired
4072-
for a 'read' or 'write'.
4073-
If $isWrite doesn't specified it means that prefetch is prepared for 'read'.
4071+
$locality is a temporal locality specifier ranging from (0) - no locality,
4072+
to (3) - extremely local, keep in cache. If $locality is not present, the
4073+
default value is 3.
4074+
4075+
$isWrite specifies whether the prefetch is for a 'read' or 'write'. If
4076+
$isWrite is not specified, it means that prefetch is prepared for 'read'.
40744077
}];
40754078

40764079
let arguments = (ins CIR_VoidPtrType:$addr,
4077-
ConfinedAttr<I32Attr, [IntMinValue<0>, IntMaxValue<3>]>:$locality,
4080+
DefaultValuedAttr<ConfinedAttr<I32Attr, [IntMinValue<0>, IntMaxValue<3>]>,
4081+
"3">:$locality,
40784082
UnitAttr:$isWrite);
40794083

40804084
let assemblyFormat = [{
4081-
`(` $addr `:` qualified(type($addr)) `)`
4082-
`locality``(` $locality `)`
40834085
(`write` $isWrite^) : (`read`)?
4086+
`locality` `(` $locality `)`
4087+
$addr `:` qualified(type($addr))
40844088
attr-dict
4085-
}];
4089+
}];
40864090
}
40874091

40884092
//===----------------------------------------------------------------------===//

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
467467
if (e->getNumArgs() > 1)
468468
isWrite = evaluateOperandAsInt(e->getArg(1));
469469

470-
int locality = 0;
470+
int locality = 3;
471471
if (e->getNumArgs() > 2)
472472
locality = evaluateOperandAsInt(e->getArg(2));
473473

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ mlir::LogicalResult CIRToLLVMPrefetchOpLowering::matchAndRewrite(
15121512
mlir::ConversionPatternRewriter &rewriter) const {
15131513
rewriter.replaceOpWithNewOp<mlir::LLVM::Prefetch>(
15141514
op, adaptor.getAddr(), adaptor.getIsWrite(), adaptor.getLocality(),
1515-
/*DataCache*/ 1);
1515+
/*DataCache=*/1);
15161516
return mlir::success();
15171517
}
15181518

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
11
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-cir %s -o - | FileCheck %s -check-prefix=CIR
22
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o - | FileCheck %s -check-prefix=LLVM
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s -check-prefix=OGCG
34

45
void foo(void *a) {
5-
__builtin_prefetch(a, 1, 1);
6+
__builtin_prefetch(a); // rw=0, locality=3
7+
__builtin_prefetch(a, 0); // rw=0, locality=3
8+
__builtin_prefetch(a, 1); // rw=1, locality=3
9+
__builtin_prefetch(a, 1, 1); // rw=1, locality=1
610
}
711

8-
// CIR: cir.func dso_local @foo(%arg0: !cir.ptr<!void> loc({{.*}}))
9-
// CIR: [[PTR_ALLOC:%.*]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["a", init] {alignment = 8 : i64}
10-
// CIR: cir.store %arg0, [[PTR_ALLOC]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>
11-
// CIR: [[PTR:%.*]] = cir.load{{.*}} [[PTR_ALLOC]] : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void>
12-
// CIR: cir.prefetch([[PTR]] : !cir.ptr<!void>) locality(1) write
13-
// CIR: cir.return
12+
// CIR-LABEL: cir.func dso_local @foo(
13+
// CIR: %[[ALLOCA:.*]] = cir.alloca !cir.ptr<!void>
14+
// CIR: cir.store %arg0, %[[ALLOCA]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>
15+
// CIR: %[[P1:.*]] = cir.load{{.*}} %[[ALLOCA]] : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void>
16+
// CIR: cir.prefetch read locality(3) %[[P1]] : !cir.ptr<!void>
17+
// CIR: %[[P2:.*]] = cir.load{{.*}} %[[ALLOCA]] : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void>
18+
// CIR: cir.prefetch read locality(3) %[[P2]] : !cir.ptr<!void>
19+
// CIR: %[[P3:.*]] = cir.load{{.*}} %[[ALLOCA]] : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void>
20+
// CIR: cir.prefetch write locality(3) %[[P3]] : !cir.ptr<!void>
21+
// CIR: %[[P4:.*]] = cir.load{{.*}} %[[ALLOCA]] : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void>
22+
// CIR: cir.prefetch write locality(1) %[[P4]] : !cir.ptr<!void>
23+
// CIR: cir.return
1424

15-
// LLVM: define dso_local void @foo(ptr [[ARG0:%.*]])
16-
// LLVM: [[PTR_ALLOC:%.*]] = alloca ptr, i64 1
17-
// LLVM: store ptr [[ARG0]], ptr [[PTR_ALLOC]]
18-
// LLVM: [[PTR:%.*]] = load ptr, ptr [[PTR_ALLOC]]
19-
// LLVM: call void @llvm.prefetch.p0(ptr [[PTR]], i32 1, i32 1, i32 1)
20-
// LLVM: ret void
25+
// LLVM-LABEL: define dso_local void @foo(
26+
// LLVM: [[ALLOCA:%.*]] = alloca ptr, i64 1
27+
// LLVM: store ptr {{.*}}, ptr [[ALLOCA]]
28+
// LLVM: [[LP1:%.*]] = load ptr, ptr [[ALLOCA]]
29+
// LLVM: call void @llvm.prefetch.p0(ptr [[LP1]], i32 0, i32 3, i32 1)
30+
// LLVM: [[LP2:%.*]] = load ptr, ptr [[ALLOCA]]
31+
// LLVM: call void @llvm.prefetch.p0(ptr [[LP2]], i32 0, i32 3, i32 1)
32+
// LLVM: [[LP3:%.*]] = load ptr, ptr [[ALLOCA]]
33+
// LLVM: call void @llvm.prefetch.p0(ptr [[LP3]], i32 1, i32 3, i32 1)
34+
// LLVM: [[LP4:%.*]] = load ptr, ptr [[ALLOCA]]
35+
// LLVM: call void @llvm.prefetch.p0(ptr [[LP4]], i32 1, i32 1, i32 1)
36+
// LLVM: ret void
37+
38+
// OGCG-LABEL: define dso_local void @foo(ptr
39+
// OGCG: call void @llvm.prefetch.p0(ptr {{.*}}, i32 0, i32 3, i32 1)
40+
// OGCG: call void @llvm.prefetch.p0(ptr {{.*}}, i32 0, i32 3, i32 1)
41+
// OGCG: call void @llvm.prefetch.p0(ptr {{.*}}, i32 1, i32 3, i32 1)
42+
// OGCG: call void @llvm.prefetch.p0(ptr {{.*}}, i32 1, i32 1, i32 1)
43+
// OGCG: ret void

0 commit comments

Comments
 (0)