14
14
#include " llvm/ADT/APInt.h"
15
15
#include " llvm/ADT/StringMap.h"
16
16
#include " llvm/ADT/StringRef.h"
17
+ #include " llvm/IR/IntrinsicInst.h"
17
18
#include " llvm/IR/Module.h"
18
19
#include " llvm/IR/Operator.h"
19
20
@@ -175,11 +176,14 @@ PreservedAnalyses CompileTimePropertiesPass::run(Module &M,
175
176
: PreservedAnalyses::all ();
176
177
}
177
178
179
+ // Returns true if the transformation changed IntrInst.
178
180
bool CompileTimePropertiesPass::transformSYCLPropertiesAnnotation (
179
181
Module &M, IntrinsicInst *IntrInst,
180
- SmallVector <IntrinsicInst *, 4 > &RemovableAnnotations) {
182
+ SmallVectorImpl <IntrinsicInst *> &RemovableAnnotations) {
181
183
assert (IntrInst->getIntrinsicID () == Intrinsic::ptr_annotation &&
182
184
" Intrinsic is not a pointer annotation." );
185
+ assert (IntrInst->arg_size () == 5 &&
186
+ " Unexpected number of arguments in annotation intrinsic." );
183
187
184
188
// Get the global variable with the annotation string.
185
189
const GlobalVariable *AnnotStrArgGV = nullptr ;
@@ -238,7 +242,7 @@ bool CompileTimePropertiesPass::transformSYCLPropertiesAnnotation(
238
242
239
243
// If the new annotation string is empty there is no reason to keep it, so
240
244
// replace it with the first operand and mark it for removal.
241
- if (NewAnnotString == " " ) {
245
+ if (NewAnnotString. empty () ) {
242
246
IntrInst->replaceAllUsesWith (IntrInst->getOperand (0 ));
243
247
RemovableAnnotations.push_back (IntrInst);
244
248
return true ;
@@ -247,8 +251,8 @@ bool CompileTimePropertiesPass::transformSYCLPropertiesAnnotation(
247
251
// Either reuse a previously generated one or create a new global variable
248
252
// with the new annotation string.
249
253
GlobalVariable *NewAnnotStringGV = nullptr ;
250
- auto ExistingNewAnnotStringIt = NewAnnotationStrings .find (NewAnnotString);
251
- if (ExistingNewAnnotStringIt != NewAnnotationStrings .end ()) {
254
+ auto ExistingNewAnnotStringIt = ReusableAnnotStrings .find (NewAnnotString);
255
+ if (ExistingNewAnnotStringIt != ReusableAnnotStrings .end ()) {
252
256
NewAnnotStringGV = ExistingNewAnnotStringIt->second ;
253
257
} else {
254
258
Constant *NewAnnotStringData =
@@ -258,7 +262,7 @@ bool CompileTimePropertiesPass::transformSYCLPropertiesAnnotation(
258
262
NewAnnotStringData, " .str" );
259
263
NewAnnotStringGV->setSection (AnnotStrArgGV->getSection ());
260
264
NewAnnotStringGV->setUnnamedAddr (GlobalValue::UnnamedAddr::Global);
261
- NewAnnotationStrings .insert ({NewAnnotString, NewAnnotStringGV});
265
+ ReusableAnnotStrings .insert ({NewAnnotString, NewAnnotStringGV});
262
266
}
263
267
264
268
// Replace the annotation string with a bitcast of the new global variable.
0 commit comments