[polly] [Polly] Add vectorize metadata to loops identified as vectorizable by polly (PR #113994)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 30 05:33:56 PDT 2024


================
@@ -128,8 +128,25 @@ void ScopAnnotator::popLoop(bool IsParallel) {
   LoopAttrEnv.pop_back();
 }
 
+void addVectorizeMetadata(LLVMContext &Ctx, SmallVector<Metadata *, 3> *Args,
+                          bool EnableLoopVectorizer) {
+  MDString *PropName = MDString::get(Ctx, "llvm.loop.vectorize.enable");
+  ConstantInt *Value =
+      ConstantInt::get(Type::getInt1Ty(Ctx), EnableLoopVectorizer);
+  ValueAsMetadata *PropValue = ValueAsMetadata::get(Value);
+  Args->push_back(MDNode::get(Ctx, {PropName, PropValue}));
+}
+
+void addParallelMetadata(LLVMContext &Ctx, SmallVector<Metadata *, 3> *Args,
+                         llvm::SmallVector<llvm::MDNode *, 8> ParallelLoops) {
+  MDString *PropName = MDString::get(Ctx, "llvm.loop.parallel_accesses");
+  MDNode *AccGroup = ParallelLoops.back();
+  Args->push_back(MDNode::get(Ctx, {PropName, AccGroup}));
+}
+
 void ScopAnnotator::annotateLoopLatch(BranchInst *B, Loop *L, bool IsParallel,
-                                      bool IsLoopVectorizerDisabled) const {
+                                      bool setVectorizeMetadata,
----------------
Meinersbur wrote:

```suggestion
                                      bool SetVectorizeMetadata,
```

Could add a doxygen comment on what the parameters mean?

I am getting confused with the flag combinations. Since its terrnary logic, consider `std::optional<bool> EnableLoopVectorizer` where `std::nullopt` means no metadata set.

https://github.com/llvm/llvm-project/pull/113994


More information about the llvm-commits mailing list