27
27
28
28
#include " llvm/SYCLLowerIR/SYCLPropagateAspectsUsage.h"
29
29
30
+ #include " llvm/ADT/STLExtras.h"
30
31
#include " llvm/ADT/SetVector.h"
31
32
#include " llvm/ADT/SmallPtrSet.h"
32
33
#include " llvm/ADT/SmallSet.h"
@@ -58,20 +59,18 @@ TypeToAspectsMapTy getTypesThatUseAspectsFromMetadata(const Module &M) {
58
59
return Result;
59
60
60
61
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" );
65
65
66
- const auto *TypeName = cast<MDString>(N. getOperand (0 ));
66
+ const auto *TypeName = cast<MDString>(N-> getOperand (0 ));
67
67
const Type *T = StructType::getTypeByName (C, TypeName->getString ());
68
68
assert (T &&
69
69
" invalid type referenced by intel_types_that_use_aspect metadata" );
70
70
71
71
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 ();
72
+ for (const MDOperand &Op : drop_begin (N->operands ())) {
73
+ const Constant *C = cast<ConstantAsMetadata>(Op)->getValue ();
75
74
Aspects.insert (cast<ConstantInt>(C)->getSExtValue ());
76
75
}
77
76
}
@@ -89,16 +88,15 @@ AspectValueToNameMapTy getAspectsFromMetadata(const Module &M) {
89
88
if (!Node)
90
89
return Result;
91
90
92
- for (const auto OperandIt : Node->operands ()) {
93
- const MDNode &N = *OperandIt;
94
- assert (N.getNumOperands () == 2 &&
91
+ for (const MDNode *N : Node->operands ()) {
92
+ assert (N->getNumOperands () == 2 &&
95
93
" Each operand of sycl_aspects must be a pair." );
96
94
97
95
// The aspect's name is the first operand.
98
- const auto *AspectName = cast<MDString>(N. getOperand (0 ));
96
+ const auto *AspectName = cast<MDString>(N-> getOperand (0 ));
99
97
100
98
// The aspect's integral value is the second operand.
101
- const auto *AspectCAM = cast<ConstantAsMetadata>(N. getOperand (1 ));
99
+ const auto *AspectCAM = cast<ConstantAsMetadata>(N-> getOperand (1 ));
102
100
const Constant *AspectC = AspectCAM->getValue ();
103
101
104
102
Result[AspectName->getString ()] =
@@ -119,6 +117,7 @@ void propagateAspectsThroughTypes(const TypesEdgesTy &Edges, const Type *Start,
119
117
const AspectsSetTy &AspectsToPropagate = Aspects[Start];
120
118
SmallSetVector<const Type *, 16 > TypesToPropagate;
121
119
TypesToPropagate.insert (Start);
120
+ // The TypesToPropagate is being updated inside the loop, so no range-for.
122
121
for (size_t I = 0 ; I < TypesToPropagate.size (); ++I) {
123
122
const Type *T = TypesToPropagate[I];
124
123
Aspects[T].insert (AspectsToPropagate.begin (), AspectsToPropagate.end ());
@@ -240,12 +239,10 @@ using FunctionToAspectsMapTy = DenseMap<Function *, AspectsSetTy>;
240
239
using CallGraphTy = DenseMap<Function *, SmallPtrSet<Function *, 8 >>;
241
240
242
241
void createUsedAspectsMetadataForFunctions (FunctionToAspectsMapTy &Map) {
243
- for (auto &It : Map) {
244
- AspectsSetTy &Aspects = It.second ;
242
+ for (auto &[F, Aspects] : Map) {
245
243
if (Aspects.empty ())
246
244
continue ;
247
245
248
- Function *F = It.first ;
249
246
LLVMContext &C = F->getContext ();
250
247
251
248
SmallVector<Metadata *, 16 > AspectsMetadata;
@@ -312,9 +309,8 @@ void processFunction(Function &F, FunctionToAspectsMapTy &FunctionToAspects,
312
309
if (F.hasMetadata (" sycl_used_aspects" )) {
313
310
const MDNode *MD = F.getMetadata (" sycl_used_aspects" );
314
311
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 ();
312
+ for (const MDOperand &Op : MD->operands ()) {
313
+ Constant *C = cast<ConstantAsMetadata>(Op.get ())->getValue ();
318
314
Aspects.insert (cast<ConstantInt>(C)->getSExtValue ());
319
315
}
320
316
FunctionToAspects[&F].insert (Aspects.begin (), Aspects.end ());
0 commit comments