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,20 +59,18 @@ 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 ();
72+ for (const MDOperand &Op : drop_begin (N->operands ())) {
73+ const Constant *C = cast<ConstantAsMetadata>(Op)->getValue ();
7574 Aspects.insert (cast<ConstantInt>(C)->getSExtValue ());
7675 }
7776 }
@@ -89,16 +88,15 @@ AspectValueToNameMapTy getAspectsFromMetadata(const Module &M) {
8988 if (!Node)
9089 return Result;
9190
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 &&
9593 " Each operand of sycl_aspects must be a pair." );
9694
9795 // 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 ));
9997
10098 // 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 ));
102100 const Constant *AspectC = AspectCAM->getValue ();
103101
104102 Result[AspectName->getString ()] =
@@ -119,6 +117,7 @@ void propagateAspectsThroughTypes(const TypesEdgesTy &Edges, const Type *Start,
119117 const AspectsSetTy &AspectsToPropagate = Aspects[Start];
120118 SmallSetVector<const Type *, 16 > TypesToPropagate;
121119 TypesToPropagate.insert (Start);
120+ // The TypesToPropagate is being updated inside the loop, so no range-for.
122121 for (size_t I = 0 ; I < TypesToPropagate.size (); ++I) {
123122 const Type *T = TypesToPropagate[I];
124123 Aspects[T].insert (AspectsToPropagate.begin (), AspectsToPropagate.end ());
@@ -240,12 +239,10 @@ using FunctionToAspectsMapTy = DenseMap<Function *, AspectsSetTy>;
240239using CallGraphTy = DenseMap<Function *, SmallPtrSet<Function *, 8 >>;
241240
242241void createUsedAspectsMetadataForFunctions (FunctionToAspectsMapTy &Map) {
243- for (auto &It : Map) {
244- AspectsSetTy &Aspects = It.second ;
242+ for (auto &[F, Aspects] : Map) {
245243 if (Aspects.empty ())
246244 continue ;
247245
248- Function *F = It.first ;
249246 LLVMContext &C = F->getContext ();
250247
251248 SmallVector<Metadata *, 16 > AspectsMetadata;
@@ -312,9 +309,8 @@ void processFunction(Function &F, FunctionToAspectsMapTy &FunctionToAspects,
312309 if (F.hasMetadata (" sycl_used_aspects" )) {
313310 const MDNode *MD = F.getMetadata (" sycl_used_aspects" );
314311 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 ();
318314 Aspects.insert (cast<ConstantInt>(C)->getSExtValue ());
319315 }
320316 FunctionToAspects[&F].insert (Aspects.begin (), Aspects.end ());
0 commit comments