Skip to content

Commit a7a33f3

Browse files
[SYCL][NFCI] Clean up CompileTimePropertiesPass source (#8448)
This commit makes the following clean up actions in llvm/lib/SYCLLowerIR/CompileTimePropertiesPass.cpp: * Adjust variable naming to be in line with the style guide. * Add reference to select auto loop variables. * Remove unused variables. * Use cast rather than dyn_cast in case where the casted pointer should always be the corresponding type. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 74bf195 commit a7a33f3

File tree

1 file changed

+28
-37
lines changed

1 file changed

+28
-37
lines changed

llvm/lib/SYCLLowerIR/CompileTimePropertiesPass.cpp

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,6 @@ PreservedAnalyses CompileTimePropertiesPass::run(Module &M,
418418

419419
void CompileTimePropertiesPass::parseAlignmentAndApply(
420420
Module &M, IntrinsicInst *IntrInst) {
421-
LLVMContext &Ctx = M.getContext();
422-
unsigned MDKindID = Ctx.getMDKindID(SPIRV_DECOR_MD_KIND);
423-
424421
// Get the global variable with the annotation string.
425422
const GlobalVariable *AnnotStrArgGV = nullptr;
426423
const Value *IntrAnnotStringArg = IntrInst->getArgOperand(1);
@@ -435,54 +432,48 @@ void CompileTimePropertiesPass::parseAlignmentAndApply(
435432
return;
436433

437434
// parse properties string to decoration-value pairs
438-
auto properties = parseSYCLPropertiesString(M, IntrInst);
435+
auto Properties = parseSYCLPropertiesString(M, IntrInst);
439436

440-
SmallVector<Value *, 8> userList;
441-
SmallVector<Instruction *, 4> instList;
437+
SmallVector<Value *, 8> UserList;
438+
SmallVector<Instruction *, 4> InstList;
442439
// check if used by a load or store instructions
443-
for (auto val : IntrInst->users()) {
440+
for (auto Val : IntrInst->users()) {
444441
// if castInst, push successors
445-
if (auto cast = dyn_cast<CastInst>(val)) {
446-
for (auto successor : cast->users())
447-
userList.push_back(successor);
442+
if (auto CInst = dyn_cast<CastInst>(Val)) {
443+
for (auto Successor : CInst->users())
444+
UserList.push_back(Successor);
448445
} else {
449-
userList.push_back(val);
446+
UserList.push_back(Val);
450447
}
451448
}
452449

453-
for (auto &value : userList) {
454-
if (isa<LoadInst>(value) || isa<StoreInst>(value))
455-
instList.push_back(cast<Instruction>(value));
450+
for (auto &Value : UserList) {
451+
if (isa<LoadInst>(Value) || isa<StoreInst>(Value))
452+
InstList.push_back(cast<Instruction>(Value));
456453
}
457454

458-
for (auto property : properties) {
459-
// get decorcode code
460-
auto DecorIt = SpirvDecorMap.find(*property.first);
461-
if (DecorIt == SpirvDecorMap.end())
462-
continue;
463-
464-
uint32_t DecorCode = DecorIt->second.Code;
465-
auto DecorStr = property.first->str();
466-
auto DecorValue = property.second;
467-
uint32_t attr_val;
455+
for (auto &Property : Properties) {
456+
auto DecorStr = Property.first->str();
457+
auto DecorValue = Property.second;
458+
uint32_t AttrVal;
468459

469460
if (DecorStr == "sycl-alignment") {
470461
assert(DecorValue && "sycl-alignment attribute is missing");
471462

472-
bool DecorValueIntConvFailed = DecorValue->getAsInteger(0, attr_val);
463+
bool DecorValueIntConvFailed = DecorValue->getAsInteger(0, AttrVal);
473464

474465
std::ignore = DecorValueIntConvFailed;
475466
assert(!DecorValueIntConvFailed &&
476467
"sycl-alignment attribute is not an integer");
477-
assert(llvm::isPowerOf2_64(attr_val) &&
468+
assert(llvm::isPowerOf2_64(AttrVal) &&
478469
"sycl-alignment attribute is not a power of 2");
479470

480471
// apply alignment attributes to load/store
481-
for (auto inst : instList) {
482-
if (auto loadinst = dyn_cast<LoadInst>(inst))
483-
loadinst->setAlignment(Align(attr_val));
484-
else if (auto storeinst = dyn_cast<StoreInst>(inst))
485-
storeinst->setAlignment(Align(attr_val));
472+
for (auto Inst : InstList) {
473+
if (auto LInst = dyn_cast<LoadInst>(Inst))
474+
LInst->setAlignment(Align(AttrVal));
475+
else if (auto SInst = dyn_cast<StoreInst>(Inst))
476+
SInst->setAlignment(Align(AttrVal));
486477
}
487478
}
488479
}
@@ -517,9 +508,9 @@ bool CompileTimePropertiesPass::transformSYCLPropertiesAnnotation(
517508

518509
// Read the annotation values and create the new annotation string.
519510
std::string NewAnnotString = "";
520-
auto properties = parseSYCLPropertiesString(M, IntrInst);
521-
for (auto property : properties) {
522-
auto DecorIt = SpirvDecorMap.find(*property.first);
511+
auto Properties = parseSYCLPropertiesString(M, IntrInst);
512+
for (auto &Property : Properties) {
513+
auto DecorIt = SpirvDecorMap.find(*Property.first);
523514
if (DecorIt == SpirvDecorMap.end())
524515
continue;
525516
uint32_t DecorCode = DecorIt->second.Code;
@@ -529,8 +520,8 @@ bool CompileTimePropertiesPass::transformSYCLPropertiesAnnotation(
529520
// string values are handled correctly. Note that " around values are
530521
// always valid, even if the decoration parameters are not strings.
531522
NewAnnotString += "{" + std::to_string(DecorCode);
532-
if (property.second)
533-
NewAnnotString += ":\"" + property.second->str() + "\"";
523+
if (Property.second)
524+
NewAnnotString += ":\"" + Property.second->str() + "\"";
534525
NewAnnotString += "}";
535526
}
536527

@@ -568,7 +559,7 @@ bool CompileTimePropertiesPass::transformSYCLPropertiesAnnotation(
568559
// The values are not in the annotation string, so we can remove the original
569560
// annotation value.
570561
PointerType *Arg4PtrTy =
571-
dyn_cast<PointerType>(IntrInst->getArgOperand(4)->getType());
562+
cast<PointerType>(IntrInst->getArgOperand(4)->getType());
572563
IntrInst->setArgOperand(4, ConstantPointerNull::get(Arg4PtrTy));
573564
return true;
574565
}

0 commit comments

Comments
 (0)