Skip to content

Commit a685c84

Browse files
committed
Apply suggestions
Signed-off-by: Steffen Larsen <[email protected]>
1 parent a172c3a commit a685c84

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

llvm/tools/sycl-post-link/CompileTimePropertiesPass.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "llvm/ADT/APInt.h"
1515
#include "llvm/ADT/StringMap.h"
1616
#include "llvm/ADT/StringRef.h"
17+
#include "llvm/IR/IntrinsicInst.h"
1718
#include "llvm/IR/Module.h"
1819
#include "llvm/IR/Operator.h"
1920

@@ -175,11 +176,14 @@ PreservedAnalyses CompileTimePropertiesPass::run(Module &M,
175176
: PreservedAnalyses::all();
176177
}
177178

179+
// Returns true if the transformation changed IntrInst.
178180
bool CompileTimePropertiesPass::transformSYCLPropertiesAnnotation(
179181
Module &M, IntrinsicInst *IntrInst,
180-
SmallVector<IntrinsicInst *, 4> &RemovableAnnotations) {
182+
SmallVectorImpl<IntrinsicInst *> &RemovableAnnotations) {
181183
assert(IntrInst->getIntrinsicID() == Intrinsic::ptr_annotation &&
182184
"Intrinsic is not a pointer annotation.");
185+
assert(IntrInst->arg_size() == 5 &&
186+
"Unexpected number of arguments in annotation intrinsic.");
183187

184188
// Get the global variable with the annotation string.
185189
const GlobalVariable *AnnotStrArgGV = nullptr;
@@ -238,7 +242,7 @@ bool CompileTimePropertiesPass::transformSYCLPropertiesAnnotation(
238242

239243
// If the new annotation string is empty there is no reason to keep it, so
240244
// replace it with the first operand and mark it for removal.
241-
if (NewAnnotString == "") {
245+
if (NewAnnotString.empty()) {
242246
IntrInst->replaceAllUsesWith(IntrInst->getOperand(0));
243247
RemovableAnnotations.push_back(IntrInst);
244248
return true;
@@ -247,8 +251,8 @@ bool CompileTimePropertiesPass::transformSYCLPropertiesAnnotation(
247251
// Either reuse a previously generated one or create a new global variable
248252
// with the new annotation string.
249253
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()) {
252256
NewAnnotStringGV = ExistingNewAnnotStringIt->second;
253257
} else {
254258
Constant *NewAnnotStringData =
@@ -258,7 +262,7 @@ bool CompileTimePropertiesPass::transformSYCLPropertiesAnnotation(
258262
NewAnnotStringData, ".str");
259263
NewAnnotStringGV->setSection(AnnotStrArgGV->getSection());
260264
NewAnnotStringGV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
261-
NewAnnotationStrings.insert({NewAnnotString, NewAnnotStringGV});
265+
ReusableAnnotStrings.insert({NewAnnotString, NewAnnotStringGV});
262266
}
263267

264268
// Replace the annotation string with a bitcast of the new global variable.

llvm/tools/sycl-post-link/CompileTimePropertiesPass.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@
1414

1515
#pragma once
1616

17-
#include "llvm/IR/IntrinsicInst.h"
1817
#include "llvm/IR/PassManager.h"
1918

2019
#include <cassert>
20+
#include <string>
2121
#include <unordered_map>
2222

2323
namespace llvm {
2424

25+
// Forward declaration.
26+
class IntrinsicInst;
27+
2528
class CompileTimePropertiesPass
2629
: public PassInfoMixin<CompileTimePropertiesPass> {
2730
public:
@@ -35,12 +38,12 @@ class CompileTimePropertiesPass
3538
// the SPIR-V translator.
3639
bool transformSYCLPropertiesAnnotation(
3740
Module &M, IntrinsicInst *IntrInst,
38-
SmallVector<IntrinsicInst *, 4> &RemovableAnnotations);
41+
SmallVectorImpl<IntrinsicInst *> &RemovableAnnotations);
3942

4043
// Map for keeping track of global variables generated for annotation strings.
4144
// This allows reuse for annotations with the same generated annotation
4245
// strings.
43-
std::unordered_map<std::string, GlobalVariable *> NewAnnotationStrings;
46+
std::unordered_map<std::string, GlobalVariable *> ReusableAnnotStrings;
4447
};
4548

4649
namespace detail {

0 commit comments

Comments
 (0)