This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP][OMPIRBuilder]Move SIMD alignment calculation to LLVM Frontend
ClosedPublic

Authored by domada on Jan 17 2023, 3:00 AM.

Details

Summary

Currently default simd alignment is defined by Clang specific TargetInfo class. This class cannot be reused for LLVM Flang. That's why default simd alignment calculation has been moved to OMPIRBuilder which is common for Flang and Clang.

Previous attempt: https://reviews.llvm.org/D138496 was wrong because the default alignment depended on the number of built LLVM targets.

If we wanted to calculate the default alignment for PPC and we hadn't specified PPC LLVM target to build, then we would get 0 as the alignment because OMPIRBuilder couldn't create PPCTargetMachine object and it returned 0 as the default value. If PPC LLVM target had been built earlier, then OMPIRBuilder could have created PPCTargetMachine object and it would have returned 128.

Diff Detail

Event Timeline

domada created this revision.Jan 17 2023, 3:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 17 2023, 3:00 AM
domada requested review of this revision.Jan 17 2023, 3:00 AM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald Transcript
jsjodin accepted this revision.Jan 23 2023, 9:58 AM

This looks good to me. Have @jdoerfert approve as well.

This revision is now accepted and ready to land.Jan 23 2023, 9:58 AM
This revision was landed with ongoing or failed builds.Jan 26 2023, 1:18 PM
This revision was automatically updated to reflect the committed changes.

Hi @domada, these changes break compilation of clang, with such build error:

FAILED: tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTContext.cpp.o 
<clang invocation>
In file included from /llvm-project/clang/lib/AST/ASTContext.cpp:81:
In file included from /llvm-project/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:17:
In file included from /llvm-project/llvm/include/llvm/Analysis/MemorySSAUpdater.h:37:
In file included from /llvm-project/llvm/include/llvm/Analysis/MemorySSA.h:93:
In file included from /llvm-project/llvm/include/llvm/Analysis/AliasAnalysis.h:44:
In file included from /llvm-project/llvm/include/llvm/IR/PassManager.h:45:
In file included from /llvm-project/llvm/include/llvm/IR/Function.h:25:
In file included from /llvm-project/llvm/include/llvm/IR/Argument.h:17:
/llvm-project/llvm/include/llvm/IR/Attributes.h:90:14: fatal error: 'llvm/IR/Attributes.inc' file not found

Reproduction steps:

  1. Configure to build clang using ninja:
cmake -G Ninja /path/to/llvm-project/llvm \
  -DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64" \
  -DCMAKE_BUILD_TYPE:STRING=Release \
  -DLLVM_ENABLE_PROJECTS="clang"
  1. Build ASTContext.cpp.o with a clean build directory.
ninja clean && ninja tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTContext.cpp.o

Are you able to take a look? 🙏

I've reverted this change from main branch, let me know if there's anything I can do to help with addressing the build issue.

domada updated this revision to Diff 495609.Feb 7 2023, 12:58 PM
domada added a reviewer: akyrtzi.

Added changes in clang/lib/AST/CMakeLists.txt to address build issue reported by @akyrtzi .

I modified CMakeLists.txt so that it requires generation of missing Attributes.inc.

@akyrtzi Please let me know if it solves your issue

domada reopened this revision.Feb 7 2023, 12:59 PM
This revision is now accepted and ready to land.Feb 7 2023, 12:59 PM
domada updated this revision to Diff 495627.Feb 7 2023, 1:10 PM

Patch rebased

Added changes in clang/lib/AST/CMakeLists.txt to address build issue reported by @akyrtzi .

I modified CMakeLists.txt so that it requires generation of missing Attributes.inc.

@akyrtzi Please let me know if it solves your issue

This fixes the build issue 👍, thank you!

@akyrtzi Thank you for your feedback. Can I land the patch?

For AArch64 the default alignment is 0? I would have expected 128.

domada added a comment.Feb 8 2023, 8:10 AM

For AArch64 the default alignment is 0? I would have expected 128.

The refactored function TargetInfo::getSimdDefaultAlign is used only for calculation of default alignment for #pragma omp simd aligned(A). If user does not specify any alignment in OpenMP simd pragma, then we will assume that the alignment of A is equal to 128 for PPC, WebAssembly or for some X86 targets and we insert proper assumptions into LLVM IR (please refer to: clang test for more details. For other targets like AArch64 we don't insert any assumptions into LLVM IR code.

I just refactored the code and I return the same values as previous function.

@akyrtzi Thank you for your feedback. Can I land the patch?

Fine be me.

This revision was automatically updated to reflect the committed changes.