Skip to content

Port Classic Flang to LLVM 20.1.2 #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 60 commits into
base: release_20x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
fb3f4e4
Port Classic Flang to LLVM 15
schweitzpgi Aug 21, 2019
c742b6f
[ClassicFlang][Driver] Coexist with LLVM Flang
bryanpkc May 2, 2022
c08dc5e
Support for DWARF 4/5 and fix of issues related to -gdwarf-X options …
alokkrsharma Sep 20, 2020
7f29058
Reduce downstream delta
bryanpkc Oct 12, 2020
ac06000
Allow full path to flang1 and flang2 in classic flang tests.
michalpasztamobica Mar 17, 2021
ddc4404
[DebugInfo] Support of `-gpubnames` in Driver
SouraVX Apr 16, 2021
5956703
[Driver] Support macOS
isuruf Aug 6, 2021
d8ed767
[DebugInfo]: Remove dangerous dead function (-Wreturn-stack-address)
nextsilicon-itay-bookstein Sep 22, 2021
284775b
[driver] Add -emit-flang-llvm option
RichBarton-Arm Jan 26, 2022
797def3
[driver] Add regression test
RichBarton-Arm Feb 1, 2022
66a39e7
[driver] Add infrastructure for testing the flang-driver in lit
RichBarton-Arm Nov 15, 2021
efe38d0
[LoopVectorize] Revert Classic Flang patch causing AArch64 test failure
bryanpkc Apr 25, 2022
451fb20
[driver] Pass LLVM target_features to flang
RichBarton-Arm Nov 12, 2021
141720f
[flang-driver] Uniquify the target_features string
RichBarton-Arm Nov 18, 2021
fd33775
[driver] Pass msve-vector-bits to flang as vscale range
pawosm-arm Jan 21, 2022
66c872d
[Driver][Test] Add more variants to test/Driver/emit-flang-attrs.f90
pwisniewskimobica Jan 13, 2022
233fea2
Fix classic flang version screen
RichBarton-Arm Mar 22, 2022
a2117ec
Canonicalize some ENABLE_CLASSIC_FLANG
RichBarton-Arm Mar 18, 2022
cf4b2c1
[NFC] Add missing ENABLE_CLASSIC_FLANG guard.
RichBarton-Arm Mar 18, 2022
de121e6
Fix flang driver preprocessor issue
RichBarton-Arm May 3, 2022
78cb191
classic flang: enable IEEE by default (and sort Lower/Common inconsis…
pawosm-arm Jul 15, 2022
fb2df47
Changes to flang's fp-contract behaviour
kiranchandramohan May 8, 2018
03c1408
[Driver] Remove the "-lompstub" in the driver
PeixinQiao Aug 8, 2022
ce537af
[Driver] Pass Classic Flang libraries to the linker correctly
bryanpkc Sep 10, 2022
d9c5175
[OpenMP] Exclude a test that fails on smaller GitHub runners
bryanpkc Sep 8, 2022
6909dee
[AsmPrinter] Delete dead code; NFC
bryanpkc Nov 3, 2022
144a0a2
[driver] Allow -msve-vector-bits=<n>+ syntax to mean no maximum vscale
LittleMeepo Nov 2, 2022
0a0e78b
Changes for reassoc attributes
kiranchandramohan Jan 21, 2020
7166c24
[llvm] Provide separate veclib mapping of PGMATH functions for AArch64
pawosm-arm Aug 1, 2022
76ce456
Delete libpgmath veclib definitions for sincos
gbaraldi Nov 30, 2022
df999d3
Add platform independent build script for LLVM (release_15x)
tdusnoki Nov 30, 2022
e4f32d0
win: Fix the build with verbose options
kaadam Jan 26, 2023
8d6e1a3
win: Don't install llvm by default
kaadam Jan 24, 2023
da16f15
[Driver][ClassicFlang] Add options -fno-automatic and -f(no-)implicit…
PeixinQiao Mar 3, 2023
dee15fa
[Driver] Don't use Classic Flang tools for LLVM IR input
bryanpkc Feb 28, 2023
3ecb4f3
Added Windows support to 'classic-flang.f95' driver test
kaadam Jan 4, 2023
d22a89e
script: update llvm build script
kaadam Mar 16, 2023
79c77f2
[build] Specify LLVM_MAIN_SRC_DIR when running build-flang.sh
bryanpkc Jul 3, 2023
27370f5
Pass Flang libraries to MSVC linker correctly
isuruf Oct 21, 2021
c5aa14c
Add Flang include directory to MSVC toolchain
kaadam Jul 12, 2023
d2a98c7
[Driver] Fix flang driver preprocessor issue
bryanpkc Sep 15, 2023
51625ba
[ClassicFlang] Update LLVM version number passed to the frontend
bryanpkc Feb 19, 2025
d629433
[ClassicFlang] Adapt header include paths
bryanpkc Oct 5, 2023
3994d1e
[Driver] Update test to not expect -rpath for -lomp
bryanpkc Oct 5, 2023
1253080
[VecLib] Update test case to match new vectorizer behaviour
bryanpkc Oct 5, 2023
42115e7
[Driver] Handle -Mnomain and -fno-fortran-main correctly
bryanpkc Oct 21, 2023
41c61f5
[OpenMP] Exclude affinity tests that fail on GitHub runners
bryanpkc Jan 3, 2024
1d903c5
[TLI] Adapt libpgmath function mappings for LLVM 18
bryanpkc Mar 20, 2024
f881975
[libomptarget] Exclude omp3d_x tests that fail on GitHub runners
bryanpkc Apr 3, 2024
998ca6f
[Driver] Make supported Clang options visible to Classic Flang
bryanpkc Apr 3, 2024
04f4c90
[Driver] Update FileCheck patterns for AArch64 target features
bryanpkc Apr 3, 2024
c529513
[Driver] Allow Classic Flang driver to accept more Clang options
bryanpkc Jul 11, 2024
7aa40d9
Fix for issue 1440 (#180) (#187)
shivaramaarao Aug 7, 2024
16c9e69
Fix for Issue #1413 (cherry-pick #179 to release_18x) (#185)
shivaramaarao Aug 13, 2024
8328b7e
[Driver] Update FileCheck patterns for AArch64 target features
bryanpkc Sep 26, 2024
c1386f3
Partially revert "[flang][OpenMP] Compile proper `omp_lib.mod` from t…
bryanpkc Oct 16, 2024
72c7d13
[Driver] Enable Classic Flang cross-compilation, e.g. from X86 to AAr…
bryanpkc Oct 21, 2024
d037c2d
[build] Modify build script to support a cross-compiling toolchain
bryanpkc Nov 2, 2024
9f13cf8
Revert "[flang][Driver] Support -print-supported-cpus and associated …
bryanpkc Feb 19, 2025
f45eb31
[Driver] Make linker command generation compatible with LLVM Flang
bryanpkc Apr 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/flang-arm64-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Build and install libpgmath & flang
run: |
cd ${{ env.build_path }}/flang
./build-flang.sh -t ${{ matrix.target }} -p ${{ env.install_prefix }} -n $(nproc)
./build-flang.sh -t ${{ matrix.target }} -p ${{ env.install_prefix }} -n $(nproc) -l ${{ env.build_path }}/classic-flang-llvm-project/llvm

- name: Copy llvm-lit
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/flang-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Build and install libpgmath & flang
run: |
cd ../../flang
./build-flang.sh -t ${{ matrix.target }} -p ${{ env.install_prefix }} -n $(nproc) -c -s
./build-flang.sh -t ${{ matrix.target }} -p ${{ env.install_prefix }} -n $(nproc) -c -s -l $(realpath ../classic-flang-llvm-project/classic-flang-llvm-project/llvm)

- name: Copy llvm-lit
run: |
Expand Down
81 changes: 60 additions & 21 deletions build-llvm-project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
TARGET="X86"
BUILD_TYPE="Release"
INSTALL_PREFIX="/usr/local"
CROSS_TARGETS=""
NPROC=1
USE_CCACHE="0"
DO_INSTALL="0"
USE_SUDO="0"
C_COMPILER_PATH="/usr/bin/gcc"
CXX_COMPILER_PATH="/usr/bin/g++"
LLVM_ENABLE_PROJECTS="clang;openmp"
LLVM_EXTRA_PROJECTS=""
EXTRA_CMAKE_OPTS=""
VERBOSE=""

Expand All @@ -19,56 +20,50 @@ set -e # Exit script on first error.
function print_usage {
echo "Usage: ./build-llvm-project.sh [options]";
echo "";
echo "Build and install classic-flang-llvm-project.";
echo "Build and install classic-flang-llvm-project (including clang, lld, and openmp).";
echo "Run this script in a directory with project sources.";
echo "Example:";
echo " $ git clone https://github.com/flang-compiler/classic-flang-llvm-project";
echo " $ cd classic-flang-llvm-project";
echo " $ .github/workflows/build-llvm-project.sh -t X86 -p /install/prefix/ \\";
echo " $ -a /usr/bin/gcc-10 -b /usr/bin/g++-10 -i -s";
echo " $ ./build-llvm-project.sh -t X86 -p /opt/classic-flang/ -i -s";
echo "";
echo "Options:";
echo " -t Target to build for (X86, AArch64, PowerPC). Default: X86";
echo " -d Set the CMake build type. Default: Release";
echo " -p Install prefix. Default: /usr/local";
echo " -X Cross-compile OpenMP for given list of target triples. Default: none";
echo " -n Number of parallel jobs. Default: 1";
echo " -c Use ccache. Default: 0 - do not use ccache";
echo " -i Install the build. Default 0 - just build, do not install";
echo " -s Use sudo to install. Default: 0 - do not use sudo";
echo " -a C compiler path. Default: /usr/bin/gcc";
echo " -b C++ compiler path. Default: /usr/bin/g++";
echo " -e List of the LLVM sub-projects to build. Default: clang;openmp";
echo " -e List of additional LLVM sub-projects to build. Default: none";
echo " -x Extra CMake options. Default: ''";
echo " -v Enable verbose output";
}

while getopts "t:d:p:n:cisa:b:e:x:v?" opt; do
while getopts "t:d:p:X:n:cisa:b:e:x:v?" opt; do
case "$opt" in
t) TARGET=$OPTARG;;
d) BUILD_TYPE=$OPTARG;;
p) INSTALL_PREFIX=$OPTARG;;
X) CROSS_TARGETS=$OPTARG;;
n) NPROC=$OPTARG;;
c) USE_CCACHE="1";;
i) DO_INSTALL="1";;
s) USE_SUDO="1";;
a) C_COMPILER_PATH=$OPTARG;;
b) CXX_COMPILER_PATH=$OPTARG;;
e) LLVM_ENABLE_PROJECTS=$OPTARG;;
e) LLVM_EXTRA_PROJECTS=$OPTARG;;
x) EXTRA_CMAKE_OPTS="$OPTARG";;
v) VERBOSE="1";;
?) print_usage; exit 0;;
esac
done

CMAKE_OPTIONS="-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_C_COMPILER=$C_COMPILER_PATH \
-DCMAKE_CXX_COMPILER=$CXX_COMPILER_PATH \
-DLLVM_TARGETS_TO_BUILD=$TARGET \
-DLLVM_ENABLE_CLASSIC_FLANG=ON \
-DFLANG_BUILD_NEW_DRIVER=OFF"
# Warning: the -DLLVM_ENABLE_PROJECTS option is specified with cmake
# to avoid issues with nested quotation marks
-DCMAKE_BUILD_TYPE=$BUILD_TYPE"

if [ $USE_CCACHE == "1" ]; then
echo "Build using ccache"
Expand All @@ -77,16 +72,19 @@ if [ $USE_CCACHE == "1" ]; then
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache"
fi

if [ -n "$EXTRA_CMAKE_OPTS" ]; then
CMAKE_OPTIONS="$CMAKE_OPTIONS $EXTRA_CMAKE_OPTS"
fi

# Build and install
# Build and install.
mkdir -p build && cd build
if [ -n "$VERBOSE" ]; then
set -x
fi
cmake $CMAKE_OPTIONS -DLLVM_ENABLE_PROJECTS=$LLVM_ENABLE_PROJECTS ../llvm
cmake $CMAKE_OPTIONS \
-DCMAKE_C_COMPILER=$C_COMPILER_PATH \
-DCMAKE_CXX_COMPILER=$CXX_COMPILER_PATH \
-DLLVM_ENABLE_CLASSIC_FLANG=ON \
-DLLVM_ENABLE_PROJECTS="clang;lld;openmp;$LLVM_EXTRA_PROJECTS" \
-DLLVM_TARGETS_TO_BUILD="$TARGET" \
$EXTRA_CMAKE_OPTS \
../llvm
set +x
make -j$NPROC VERBOSE=$VERBOSE
if [ $DO_INSTALL == "1" ]; then
Expand All @@ -100,3 +98,44 @@ if [ $DO_INSTALL == "1" ]; then
fi
cd ..

# Cross-compile OpenMP libraries if requested.
IFS=';' read -ra CROSS_TARGET_LIST <<< "$CROSS_TARGETS"
for T in ${CROSS_TARGET_LIST[@]}; do
mkdir -p "build/openmp-$T"
pushd "build/openmp-$T"
CMAKE_OPTIONS="$CMAKE_OPTIONS \
-DCMAKE_AR=$INSTALL_PREFIX/bin/llvm-ar \
-DCMAKE_ASM_COMPILER=$INSTALL_PREFIX/bin/clang \
-DCMAKE_ASM_COMPILER_TARGET=$T \
-DCMAKE_C_COMPILER=$INSTALL_PREFIX/bin/clang \
-DCMAKE_C_COMPILER_TARGET=$T \
-DCMAKE_CXX_COMPILER=$INSTALL_PREFIX/bin/clang++ \
-DCMAKE_CXX_COMPILER_TARGET=$T \
-DCMAKE_RANLIB=$INSTALL_PREFIX/bin/llvm-ranlib \
-DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld"
if [ -n "$VERBOSE" ]; then
set -x
fi
cmake $CMAKE_OPTIONS \
-DLLVM_DEFAULT_TARGET_TRIPLE=$T \
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON \
-DLLVM_ENABLE_RUNTIMES="openmp" \
-DLIBOMP_OMPT_SUPPORT=OFF \
-DOPENMP_ENABLE_LIBOMPTARGET=OFF \
-DOPENMP_ENABLE_OMPT_TOOLS=OFF \
-DOPENMP_LLVM_TOOLS_DIR=$PWD/../bin \
$EXTRA_CMAKE_OPTS \
../../runtimes
set +x
make -j$NPROC VERBOSE=$VERBOSE
if [ $DO_INSTALL -eq 1 ]; then
if [ $USE_SUDO -eq 1 ]; then
echo "Install with sudo"
sudo make install
else
echo "Install without sudo"
make install
fi
fi
popd
done
5 changes: 5 additions & 0 deletions clang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
endif()
endif()

option(LLVM_ENABLE_CLASSIC_FLANG "Build support for classic Flang instead of the new built-in Flang" OFF)
if(LLVM_ENABLE_CLASSIC_FLANG)
add_definitions( -DENABLE_CLASSIC_FLANG )
endif()

option(CLANG_BUILD_TOOLS
"Build the Clang tools. If OFF, just generate build targets." ON)

Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ def err_drv_invalid_linker_name : Error<
"invalid linker name in argument '%0'">;
def err_drv_invalid_rtlib_name : Error<
"invalid runtime library name in argument '%0'">;
def err_drv_invalid_allocatable_mode : Error<
"invalid semantic mode for assignments to allocatables in argument '%0'">;
def err_drv_unsupported_fixed_line_length : Error<
"unsupported fixed-format line length in argument '%0'">;
def err_drv_unsupported_rtlib_for_platform : Error<
"unsupported runtime library '%0' for platform '%1'">;
def err_drv_invalid_unwindlib_name : Error<
Expand Down Expand Up @@ -384,6 +388,8 @@ def err_drv_small_columns : Error<
def warn_drv_fraw_string_literals_in_cxx11 : Warning<
"ignoring '-f%select{no-|}0raw-string-literals', which is only valid for C and C++ standards before C++11">,
InGroup<UnusedCommandLineArgument>;
def err_drv_clang_unsupported_minfo_arg : Error<
"'%0' option does not support '%1' value">;

def err_drv_invalid_malign_branch_EQ : Error<
"invalid argument '%0' to -malign-branch=; each element must be one of: %1">;
Expand Down
5 changes: 3 additions & 2 deletions clang/include/clang/Basic/MacroBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ class MacroBuilder {
raw_ostream &Out;
public:
MacroBuilder(raw_ostream &Output) : Out(Output) {}
virtual ~MacroBuilder() {}

/// Append a \#define line for macro of the form "\#define Name Value\n".
/// If DeprecationMsg is provided, also append a pragma to deprecate the
/// defined macro.
void defineMacro(const Twine &Name, const Twine &Value = "1",
Twine DeprecationMsg = "") {
virtual void defineMacro(const Twine &Name, const Twine &Value = "1",
Twine DeprecationMsg = "") {
Out << "#define " << Name << ' ' << Value << '\n';
if (!DeprecationMsg.isTriviallyEmpty())
Out << "#pragma clang deprecated(" << Name << ", \"" << DeprecationMsg
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/Sanitizers.def
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ SANITIZER_GROUP("bounds", Bounds, ArrayBounds | LocalBounds)
// Scudo hardened allocator
SANITIZER("scudo", Scudo)

// Fortran contiguous pointer checks
SANITIZER("discontiguous", Discontiguous)

// Magic group, containing all sanitizers. For example, "-fno-sanitize=all"
// can be used to disable all the sanitizers.
SANITIZER_GROUP("all", All, ~SanitizerMask())
Expand Down
6 changes: 5 additions & 1 deletion clang/include/clang/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
set(LLVM_TARGET_DEFINITIONS Options.td)
tablegen(LLVM Options.inc -gen-opt-parser-defs)
if(LLVM_ENABLE_CLASSIC_FLANG)
tablegen(LLVM Options.inc -DENABLE_CLASSIC_FLANG -gen-opt-parser-defs)
else()
tablegen(LLVM Options.inc -gen-opt-parser-defs)
endif()
add_public_tablegen_target(ClangDriverOptions)
Loading
Loading