Skip to content

Commit 4f6d330

Browse files
KorovinVladigcbot
authored andcommitted
Add restrictions for volatile variables
.
1 parent 5fb44b9 commit 4f6d330

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXVerify.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2023 Intel Corporation
3+
Copyright (C) 2023-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -27,20 +27,20 @@ void GenXVerify::getAnalysisUsage(AnalysisUsage &AU) const {
2727
AU.setPreservesAll();
2828
}
2929

30-
bool GenXVerify::ensure(const bool Cond, const Twine &Msg, const Instruction &I,
30+
bool GenXVerify::ensure(const bool Cond, const Twine &Msg, const Value &V,
3131
const IsFatal IsFatal_) {
3232
if (LLVM_LIKELY(Cond))
3333
return true;
3434
if (IsFatal_ == IsFatal::Yes || OptAllFatal || !OptQuietNonFatal)
35-
vc::diagnose(I.getContext(),
35+
vc::diagnose(V.getContext(),
3636
DbgPrefix + "[stage:" +
3737
OptStage.getParser().getOption(
3838
static_cast<int>(OptStage.getValue())) +
3939
"]" +
4040
(IsFatal_ == IsFatal::No
4141
? " (non-fatal, spec review required)"
4242
: ""),
43-
Msg, DS_Warning, vc::WarningName::Generic, &I);
43+
Msg, DS_Warning, vc::WarningName::Generic, &V);
4444
if (IsFatal_ == IsFatal::Yes || OptAllFatal) {
4545
IsBroken = true;
4646
if (OptTerminationPolicy == Terminate::OnFirstError)
@@ -55,15 +55,29 @@ bool GenXVerify::ensure(const bool Cond, const Twine &Msg, const Instruction &I,
5555

5656
bool GenXVerify::runOnModule(Module &M) {
5757
visit(M);
58+
if (Stage == GenXVerifyStage::PostIrAdaptors)
59+
for (const auto &GV : M.globals())
60+
visitGlobalVariable(GV);
5861
if (OptTerminationPolicy != Terminate::No && IsBroken)
5962
terminate();
6063
return false;
6164
}
6265

6366
void GenXVerify::visitGlobalVariable(const GlobalVariable &GV){
64-
// TODO: add genx_volatile-attributed values check here.
65-
// please make sure to run this check under a proper InvariantsSet to
66-
// trigger it only at appropriate pipeline stage(s).
67+
if (!GV.hasAttribute(genx::FunctionMD::GenXVolatile))
68+
return;
69+
ensure(GV.getAddressSpace() == vc::AddrSpace::Private,
70+
"a volatile variable must reside in private address space", GV);
71+
auto InvalidUser = llvm::find_if(GV.users(), [](const User *U) {
72+
const auto *I = dyn_cast<Instruction>(U);
73+
return !I || !(genx::isAVStore(I) || genx::isAVLoad(I));
74+
});
75+
if (InvalidUser == GV.user_end())
76+
return;
77+
ensure(false,
78+
"a volatile variable may only be used in genx.vload/genx.vstore "
79+
"intrinsics and volatile loads/stores instructions",
80+
**InvalidUser);
6781
};
6882

6983
void GenXVerify::visitCallInst(const CallInst &CI) {

IGC/VectorCompiler/lib/GenXCodeGen/GenXVerify.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2023 Intel Corporation
3+
Copyright (C) 2023-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -73,7 +73,7 @@ class GenXVerify : public ModulePass,
7373
enum class IsFatal { No = 0, Yes = 1 };
7474

7575
void verifyRegioning(const CallInst &, const unsigned);
76-
bool ensure(const bool Cond, const Twine &Msg, const Instruction &I,
76+
bool ensure(const bool Cond, const Twine &Msg, const Value &V,
7777
const IsFatal IsFatal_ = IsFatal::Yes);
7878
[[noreturn]] static void terminate();
7979

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2024 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; RUN: %opt %use_old_pass_manager% -GenXVerify -genx-verify-terminate=no \
10+
; RUN: -genx-verify-all-fatal=1 -march=genx64 -mtriple=spir64-unknown-unknown \
11+
; RUN: -mcpu=Gen9 -genx-verify-stage=post-ir-adaptors -S < %s 2>&1 | FileCheck \
12+
; RUN: --check-prefixes=CHECK %s
13+
14+
target datalayout = "e-p:64:64-p6:32:32-i64:64-n8:16:32:64"
15+
target triple = "genx64-unknown-unknown"
16+
17+
; CHECK: warning: {{.+}} <@SLMGV = addrspace(3) {{.+}}>: a volatile variable must reside in private address space
18+
@SLMGV = addrspace(3) global <2 x i8> undef #0
19+
20+
; CHECK: warning: {{.+}} @GV {{.+}} a volatile variable may only be used in genx.vload/genx.vstore intrinsics and volatile loads/stores instructions
21+
@GV = global <16 x i32> zeroinitializer, align 64 #1
22+
@ALIAS = global <16 x i32> addrspace(1)* addrspacecast (<16 x i32>* @GV to <16 x i32> addrspace(1)*)
23+
24+
@INVALID = global <16 x float> zeroinitializer, align 64 #2
25+
@VALID = global <16 x float> zeroinitializer, align 64 #3
26+
27+
define internal spir_func void @foo() {
28+
; CHECK: warning: {{.+}} %cst = {{.+}} a volatile variable may only be used in genx.vload/genx.vstore intrinsics and volatile loads/stores instructions
29+
%cst = addrspacecast <16 x float>* @INVALID to <16 x float> addrspace(4)*
30+
31+
; CHECK-NOT: warning
32+
%ld.ic = tail call <16 x float> @llvm.genx.vload.v16f32.p0v16f32(<16 x float>* @VALID)
33+
call void @llvm.genx.vstore.v16f32.p0v16f32(<16 x float> %ld.ic, <16 x float>* @VALID)
34+
%ld.inst = load volatile <16 x float>, <16 x float>* @VALID
35+
store volatile <16 x float> %ld.inst, <16 x float>* @VALID
36+
ret void
37+
}
38+
39+
declare <16 x float> @llvm.genx.vload.v16f32.p0v16f32(<16 x float>*)
40+
declare void @llvm.genx.vstore.v16f32.p0v16f32(<16 x float>, <16 x float>*)
41+
42+
attributes #0 = { "VCByteOffset"="0" "VCGlobalVariable" "VCVolatile" "genx_byte_offset"="0" "genx_volatile" }
43+
attributes #1 = { "VCByteOffset"="256" "VCGlobalVariable" "VCVolatile" "genx_byte_offset"="256" "genx_volatile" }
44+
attributes #2 = { "VCByteOffset"="512" "VCGlobalVariable" "VCVolatile" "genx_byte_offset"="512" "genx_volatile" }
45+
attributes #3 = { "VCByteOffset"="1024" "VCGlobalVariable" "VCVolatile" "genx_byte_offset"="1024" "genx_volatile" }

0 commit comments

Comments
 (0)