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,22 +59,19 @@ 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 ();
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 ());
77
75
}
78
76
79
77
return Result;
@@ -89,16 +87,15 @@ AspectValueToNameMapTy getAspectsFromMetadata(const Module &M) {
89
87
if (!Node)
90
88
return Result;
91
89
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 &&
95
92
" Each operand of sycl_aspects must be a pair." );
96
93
97
94
// 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 ));
99
96
100
97
// 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 ));
102
99
const Constant *AspectC = AspectCAM->getValue ();
103
100
104
101
Result[AspectName->getString ()] =
@@ -119,8 +116,7 @@ void propagateAspectsThroughTypes(const TypesEdgesTy &Edges, const Type *Start,
119
116
const AspectsSetTy &AspectsToPropagate = Aspects[Start];
120
117
SmallSetVector<const Type *, 16 > TypesToPropagate;
121
118
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) {
124
120
Aspects[T].insert (AspectsToPropagate.begin (), AspectsToPropagate.end ());
125
121
const auto It = Edges.find (T);
126
122
if (It != Edges.end ())
@@ -240,12 +236,10 @@ using FunctionToAspectsMapTy = DenseMap<Function *, AspectsSetTy>;
240
236
using CallGraphTy = DenseMap<Function *, SmallPtrSet<Function *, 8 >>;
241
237
242
238
void createUsedAspectsMetadataForFunctions (FunctionToAspectsMapTy &Map) {
243
- for (auto &It : Map) {
244
- AspectsSetTy &Aspects = It.second ;
239
+ for (auto &[F, Aspects] : Map) {
245
240
if (Aspects.empty ())
246
241
continue ;
247
242
248
- Function *F = It.first ;
249
243
LLVMContext &C = F->getContext ();
250
244
251
245
SmallVector<Metadata *, 16 > AspectsMetadata;
@@ -312,9 +306,8 @@ void processFunction(Function &F, FunctionToAspectsMapTy &FunctionToAspects,
312
306
if (F.hasMetadata (" sycl_used_aspects" )) {
313
307
const MDNode *MD = F.getMetadata (" sycl_used_aspects" );
314
308
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 ();
318
311
Aspects.insert (cast<ConstantInt>(C)->getSExtValue ());
319
312
}
320
313
FunctionToAspects[&F].insert (Aspects.begin (), Aspects.end ());
0 commit comments