Skip to content

Commit cdd1946

Browse files
[NFC][SYCL] Minor stylistic changes in SYCLPropagateAspectsUsage.cpp
1 parent 65baee7 commit cdd1946

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

llvm/lib/SYCLLowerIR/SYCLPropagateAspectsUsage.cpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "llvm/SYCLLowerIR/SYCLPropagateAspectsUsage.h"
2929

30+
#include "llvm/ADT/STLExtras.h"
3031
#include "llvm/ADT/SetVector.h"
3132
#include "llvm/ADT/SmallPtrSet.h"
3233
#include "llvm/ADT/SmallSet.h"
@@ -58,22 +59,19 @@ TypeToAspectsMapTy getTypesThatUseAspectsFromMetadata(const Module &M) {
5859
return Result;
5960

6061
LLVMContext &C = M.getContext();
61-
for (const auto OperandIt : Node->operands()) {
62-
const MDNode &N = *OperandIt;
63-
assert(N.getNumOperands() > 1 && "intel_types_that_use_aspect metadata "
64-
"shouldn't contain empty metadata nodes");
62+
for (const MDNode *N : Node->operands()) {
63+
assert(N->getNumOperands() > 1 && "intel_types_that_use_aspect metadata "
64+
"shouldn't contain empty metadata nodes");
6565

66-
const auto *TypeName = cast<MDString>(N.getOperand(0));
66+
const auto *TypeName = cast<MDString>(N->getOperand(0));
6767
const Type *T = StructType::getTypeByName(C, TypeName->getString());
6868
assert(T &&
6969
"invalid type referenced by intel_types_that_use_aspect metadata");
7070

7171
AspectsSetTy &Aspects = Result[T];
72-
for (size_t I = 1; I != N.getNumOperands(); ++I) {
73-
const auto *CAM = cast<ConstantAsMetadata>(N.getOperand(I));
74-
const Constant *C = CAM->getValue();
75-
Aspects.insert(cast<ConstantInt>(C)->getSExtValue());
76-
}
72+
for (const MDOperand &Op : drop_begin(N->operands()))
73+
Aspects.insert(cast<ConstantInt>(cast<ConstantAsMetadata>(Op)->getValue())
74+
->getSExtValue());
7775
}
7876

7977
return Result;
@@ -89,16 +87,15 @@ AspectValueToNameMapTy getAspectsFromMetadata(const Module &M) {
8987
if (!Node)
9088
return Result;
9189

92-
for (const auto OperandIt : Node->operands()) {
93-
const MDNode &N = *OperandIt;
94-
assert(N.getNumOperands() == 2 &&
90+
for (const MDNode *N : Node->operands()) {
91+
assert(N->getNumOperands() == 2 &&
9592
"Each operand of sycl_aspects must be a pair.");
9693

9794
// The aspect's name is the first operand.
98-
const auto *AspectName = cast<MDString>(N.getOperand(0));
95+
const auto *AspectName = cast<MDString>(N->getOperand(0));
9996

10097
// The aspect's integral value is the second operand.
101-
const auto *AspectCAM = cast<ConstantAsMetadata>(N.getOperand(1));
98+
const auto *AspectCAM = cast<ConstantAsMetadata>(N->getOperand(1));
10299
const Constant *AspectC = AspectCAM->getValue();
103100

104101
Result[AspectName->getString()] =
@@ -119,8 +116,7 @@ void propagateAspectsThroughTypes(const TypesEdgesTy &Edges, const Type *Start,
119116
const AspectsSetTy &AspectsToPropagate = Aspects[Start];
120117
SmallSetVector<const Type *, 16> TypesToPropagate;
121118
TypesToPropagate.insert(Start);
122-
for (size_t I = 0; I < TypesToPropagate.size(); ++I) {
123-
const Type *T = TypesToPropagate[I];
119+
for (const Type *T : TypesToPropagate) {
124120
Aspects[T].insert(AspectsToPropagate.begin(), AspectsToPropagate.end());
125121
const auto It = Edges.find(T);
126122
if (It != Edges.end())
@@ -240,12 +236,10 @@ using FunctionToAspectsMapTy = DenseMap<Function *, AspectsSetTy>;
240236
using CallGraphTy = DenseMap<Function *, SmallPtrSet<Function *, 8>>;
241237

242238
void createUsedAspectsMetadataForFunctions(FunctionToAspectsMapTy &Map) {
243-
for (auto &It : Map) {
244-
AspectsSetTy &Aspects = It.second;
239+
for (auto &[F, Aspects] : Map) {
245240
if (Aspects.empty())
246241
continue;
247242

248-
Function *F = It.first;
249243
LLVMContext &C = F->getContext();
250244

251245
SmallVector<Metadata *, 16> AspectsMetadata;
@@ -312,9 +306,8 @@ void processFunction(Function &F, FunctionToAspectsMapTy &FunctionToAspects,
312306
if (F.hasMetadata("sycl_used_aspects")) {
313307
const MDNode *MD = F.getMetadata("sycl_used_aspects");
314308
AspectsSetTy Aspects;
315-
for (size_t I = 0, E = MD->getNumOperands(); I < E; ++I) {
316-
Constant *C =
317-
cast<ConstantAsMetadata>(MD->getOperand(I).get())->getValue();
309+
for (const MDOperand &Op : MD->operands()) {
310+
Constant *C = cast<ConstantAsMetadata>(Op.get())->getValue();
318311
Aspects.insert(cast<ConstantInt>(C)->getSExtValue());
319312
}
320313
FunctionToAspects[&F].insert(Aspects.begin(), Aspects.end());

0 commit comments

Comments
 (0)