[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 6 12:14:31 PST 2023


================
@@ -788,6 +797,17 @@ void LoopInfoStack::push(BasicBlock *Header, clang::ASTContext &Ctx,
     }
   }
 
+  // Identify loop attribute 'code_align' from Attrs.
+  // For attribute code_align:
+  // n - 'llvm.loop.align i32 n' metadata will be emitted.
+  for (const auto *A : Attrs) {
+    if (const auto *CodeAlign = dyn_cast<CodeAlignAttr>(A)) {
+      const auto *CE = cast<ConstantExpr>(CodeAlign->getAlignment());
+      llvm::APSInt ArgVal = CE->getResultAsAPSInt();
+      setCodeAlign(ArgVal.getSExtValue());
+    }
+  }
----------------
smanna12 wrote:



I have updated codegen change to fix the build issue below:
```
if (const auto *CodeAlign = getSpecificAttr<const CodeAlignAttr>(Attrs)) {
   const auto *CE = cast<ConstantExpr>(CodeAlign->getAlignment());
   llvm::APSInt ArgVal = CE->getResultAsAPSInt();
   setCodeAlign(ArgVal.getSExtValue());
```
.../include/clang/AST/AttrIterator.h: In instantiation of ‘SpecificAttr* clang::specific_attr_iterator<SpecificAttr, Container>::operator*() const [with SpecificAttr = clang::CodeAlignAttr; Container = llvm::ArrayRef<const clang::Attr*>; clang::specific_attr_iterator<SpecificAttr, Container>::reference = clang::CodeAlignAttr*]’:
.../include/clang/AST/AttrIterator.h:120:12:   required from ‘SpecificAttr* clang::getSpecificAttr(const Container&) [with SpecificAttr = clang::CodeAlignAttr; Container = llvm::ArrayRef<const clang::Attr*>]’
.../lib/CodeGen/CGLoopInfo.cpp:803:67:   required from here
/.../include/clang/AST/AttrIterator.h:67:30: error: invalid conversion from ‘llvm::CastInfo<clang::CodeAlignAttr, const clang::Attr*, void>::CastReturnType {aka const clang::CodeAlignAttr*}’ to ‘clang::specific_attr_iterator<clang::CodeAlignAttr, llvm::ArrayRef<const clang::Attr*> >::reference {aka clang::CodeAlignAttr*}’ [-fpermissive]
     return cast<SpecificAttr>(*Current);


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


More information about the cfe-commits mailing list