Skip to content

Commit 869f703

Browse files
authored
Improve LLVM annotations translation to SPIR-V (#1191)
https://reviews.llvm.org/D88645 introduces additional parameter to var/ptr/global annotation instruction, which can be set by clang::annotation attribute that has variadic constant expression argument. Right now we can't translate it properly and an extension is being discussed, but yet we need a W/A for this. As a W/A the current patch makes this argument (in case if it is const int) be translatable as a string put in UserSemantic decorations, so the IL flow is looking like this: Annotation in source-code: [[clang::annotate("custom", 30, 60)]] int *Var; LLVM IR before: @.str = private unnamed_addr constant [7 x i8] c"custom\00" @.args = private unnamed_addr constant { i32, i32 } { i32 30, i32 60 } // ... call void @llvm.var.annotation(i8* ..., i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* ... , i32 ..., i8* bitcast ({ i32, i32 }* @.args to i8*)) // ... SPIR-V: Decorate %GEP% UserSemantic "custom: 30, 60" LLVM IR after: @3 = private unnamed_addr constant [15 x i8] c"custom: 30, 60\00" // ... call void @llvm.var.annotation(i8* ..., i8* getelementptr inbounds ( [15 x i8], [15 x i8]* @3, i32 0, i32 0), i8* ..., i32 ..., i8* undef) // ... As you see the annotation remains to be a string after the translation. It's done so because we wouldn't be able to distinguish [[clang::annotate("custom", 30, 60)]] from [[clang::annotate("custom, 30, 60")]] as they both would result in the same UserSemantic decoration. Also this patch brings a bit of refactoring of add Intel FPGA decoration functions, since their infrustructure can (and should) be reused here, solving an issue of incorrect allowed FPGA memory SPIR-V extensions processing. TODO: 1. Replace this W/A with an extension, when it's ready; 2. Global annotation instruction isn't handled properly yet, its handling requires even more refactoring, which I plan to do, when the extension is ready. Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent 89b319e commit 869f703

File tree

2 files changed

+229
-119
lines changed

2 files changed

+229
-119
lines changed

0 commit comments

Comments
 (0)