@@ -714,6 +714,20 @@ static TableFiles processOneModule(std::unique_ptr<Module> M, bool IsEsimd,
714
714
if (!M)
715
715
return TblFiles;
716
716
717
+ // After linking device bitcode "llvm.used" holds references to the kernels
718
+ // that are defined in the device image. But after splitting device image into
719
+ // separate kernels we may end up with having references to kernel declaration
720
+ // originating from "llvm.used" in the IR that is passed to llvm-spirv tool,
721
+ // and these declarations cause an assertion in llvm-spirv. To workaround this
722
+ // issue remove "llvm.used" from the input module before performing any other
723
+ // actions.
724
+ bool IsLLVMUsedRemoved = false ;
725
+ if (GlobalVariable *GV = M->getGlobalVariable (" llvm.used" )) {
726
+ assert (GV->user_empty () && " unexpected llvm.used users" );
727
+ GV->eraseFromParent ();
728
+ IsLLVMUsedRemoved = true ;
729
+ }
730
+
717
731
if (IsEsimd && LowerEsimd)
718
732
LowerEsimdConstructs (*M);
719
733
@@ -773,7 +787,8 @@ static TableFiles processOneModule(std::unique_ptr<Module> M, bool IsEsimd,
773
787
// no spec constants and no splitting.
774
788
// We cannot reuse input module for ESIMD code since it was transformed.
775
789
bool CanReuseInputModule = !SpecConstsMet && (ResultModules.size () == 1 ) &&
776
- !SyclAndEsimdCode && !IsEsimd;
790
+ !SyclAndEsimdCode && !IsEsimd &&
791
+ !IsLLVMUsedRemoved;
777
792
string_vector Files =
778
793
CanReuseInputModule
779
794
? string_vector{InputFilename}
@@ -981,18 +996,6 @@ int main(int argc, char **argv) {
981
996
return 1 ;
982
997
}
983
998
984
- // After linking device bitcode "llvm.used" holds references to the kernels
985
- // that are defined in the device image. But after splitting device image into
986
- // separate kernels we may end up with having references to kernel declaration
987
- // originating from "llvm.used" in the IR that is passed to llvm-spirv tool,
988
- // and these declarations cause an assertion in llvm-spirv. To workaround this
989
- // issue remove "llvm.used" from the input module before performing any other
990
- // actions.
991
- if (GlobalVariable *GV = MPtr->getGlobalVariable (" llvm.used" )) {
992
- assert (GV->user_empty () && " unexpected llvm.used users" );
993
- GV->eraseFromParent ();
994
- }
995
-
996
999
if (OutputFilename.getNumOccurrences () == 0 )
997
1000
OutputFilename = (Twine (sys::path::stem (InputFilename)) + " .files" ).str ();
998
1001
0 commit comments