Skip to content
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

Port Classic Flang to LLVM 19.1.0 #193

Merged
merged 56 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
39464e2
Port Classic Flang to LLVM 15
schweitzpgi Aug 21, 2019
bac1470
[ClassicFlang][Driver] Coexist with LLVM Flang
bryanpkc May 2, 2022
6b855d9
Support for DWARF 4/5 and fix of issues related to -gdwarf-X options …
alokkrsharma Sep 20, 2020
28527b9
Reduce downstream delta
bryanpkc Oct 12, 2020
05ee8fa
Allow full path to flang1 and flang2 in classic flang tests.
michalpasztamobica Mar 17, 2021
400c6be
[DebugInfo] Support of `-gpubnames` in Driver
SouraVX Apr 16, 2021
2aa83f4
[Driver] Support macOS
isuruf Aug 6, 2021
25e66cd
[DebugInfo]: Remove dangerous dead function (-Wreturn-stack-address)
nextsilicon-itay-bookstein Sep 22, 2021
c6fbd79
[ClassicFlang][Driver] Fix warnings
nextsilicon-itay-bookstein Sep 22, 2021
8a95179
[driver] Add -emit-flang-llvm option
RichBarton-Arm Jan 26, 2022
56b271f
[driver] Add regression test
RichBarton-Arm Feb 1, 2022
bbe6446
[driver] Add infrastructure for testing the flang-driver in lit
RichBarton-Arm Nov 15, 2021
8b4a2da
[LoopVectorize] Revert Classic Flang patch causing AArch64 test failure
bryanpkc Apr 25, 2022
1cb9823
[driver] Pass LLVM target_features to flang
RichBarton-Arm Nov 12, 2021
da5f236
[flang-driver] Uniquify the target_features string
RichBarton-Arm Nov 18, 2021
a9da4c8
[driver] Pass msve-vector-bits to flang as vscale range
pawosm-arm Jan 21, 2022
27a17b3
[Driver][Test] Add more variants to test/Driver/emit-flang-attrs.f90
pwisniewskimobica Jan 13, 2022
89df5f2
Fix classic flang version screen
RichBarton-Arm Mar 22, 2022
9a38a9d
Canonicalize some ENABLE_CLASSIC_FLANG
RichBarton-Arm Mar 18, 2022
a335571
[NFC] Add missing ENABLE_CLASSIC_FLANG guard.
RichBarton-Arm Mar 18, 2022
11357b9
Fix flang driver preprocessor issue
RichBarton-Arm May 3, 2022
09fb92f
classic flang: enable IEEE by default (and sort Lower/Common inconsis…
pawosm-arm Jul 15, 2022
4a6a8a6
Changes to flang's fp-contract behaviour
kiranchandramohan May 8, 2018
e1d04a8
[Driver] Remove the "-lompstub" in the driver
PeixinQiao Aug 8, 2022
c7c9bdc
[Driver] Pass Classic Flang libraries to the linker correctly
bryanpkc Sep 10, 2022
c0ba9fe
[OpenMP] Exclude a test that fails on smaller GitHub runners
bryanpkc Sep 8, 2022
8c69c98
[AsmPrinter] Delete dead code; NFC
bryanpkc Nov 3, 2022
ae16010
[driver] Allow -msve-vector-bits=<n>+ syntax to mean no maximum vscale
LittleMeepo Nov 2, 2022
e14c7b7
Changes for reassoc attributes
kiranchandramohan Jan 21, 2020
8a0515b
[llvm] Provide separate veclib mapping of PGMATH functions for AArch64
pawosm-arm Aug 1, 2022
b92308a
Delete libpgmath veclib definitions for sincos
gbaraldi Nov 30, 2022
12fbbac
Add platform independent build script for LLVM (release_15x)
tdusnoki Nov 30, 2022
80d3670
win: Fix the build with verbose options
kaadam Jan 26, 2023
c842304
win: Don't install llvm by default
kaadam Jan 24, 2023
5f65560
[Driver][ClassicFlang] Add options -fno-automatic and -f(no-)implicit…
PeixinQiao Mar 3, 2023
89ac07d
[Driver] Don't use Classic Flang tools for LLVM IR input
bryanpkc Feb 28, 2023
19f1cef
Added Windows support to 'classic-flang.f95' driver test
kaadam Jan 4, 2023
39b9283
script: update llvm build script
kaadam Mar 16, 2023
91a556f
[build] Specify LLVM_MAIN_SRC_DIR when running build-flang.sh
bryanpkc Jul 3, 2023
1a0df61
Pass Flang libraries to MSVC linker correctly
isuruf Oct 21, 2021
ea5b2c0
Add Flang include directory to MSVC toolchain
kaadam Jul 12, 2023
faf15a6
[Driver] Fix flang driver preprocessor issue
bryanpkc Sep 15, 2023
25cfb17
[ClassicFlang] Update LLVM version number passed to the frontend
bryanpkc Oct 5, 2023
08d4a2f
[ClassicFlang] Adapt header include paths
bryanpkc Oct 5, 2023
6cec149
[Driver] Update test to not expect -rpath for -lomp
bryanpkc Oct 5, 2023
1b6fff9
[VecLib] Update test case to match new vectorizer behaviour
bryanpkc Oct 5, 2023
7e8d2e4
[Driver] Handle -Mnomain and -fno-fortran-main correctly
bryanpkc Oct 21, 2023
54980d1
[OpenMP] Exclude affinity tests that fail on GitHub runners
bryanpkc Jan 3, 2024
87db98f
[TLI] Adapt libpgmath function mappings for LLVM 18
bryanpkc Mar 20, 2024
da28ece
[libomptarget] Exclude omp3d_x tests that fail on GitHub runners
bryanpkc Apr 3, 2024
96820f0
[Driver] Make supported Clang options visible to Classic Flang
bryanpkc Apr 3, 2024
4917f42
[Driver] Update FileCheck patterns for AArch64 target features
bryanpkc Apr 3, 2024
36b2fa6
[Driver] Allow Classic Flang driver to accept more Clang options
bryanpkc Jul 11, 2024
7703ec1
Fix for issue 1440 (#180) (#187)
shivaramaarao Aug 7, 2024
b75f256
Fix for Issue #1413 (cherry-pick #179 to release_18x) (#185)
shivaramaarao Aug 13, 2024
31c269c
[Driver] Update FileCheck patterns for AArch64 target features
bryanpkc Sep 26, 2024
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
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 @@ -152,6 +152,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 @@ -380,6 +384,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
3 changes: 2 additions & 1 deletion clang/include/clang/Basic/MacroBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ 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".
void defineMacro(const Twine &Name, const Twine &Value = "1") {
virtual void defineMacro(const Twine &Name, const Twine &Value = "1") {
Out << "#define " << Name << ' ' << Value << '\n';
}

Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/Sanitizers.def
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ SANITIZER("signed-integer-overflow", SignedIntegerOverflow)
SANITIZER("unreachable", Unreachable)
SANITIZER("vla-bound", VLABound)
SANITIZER("vptr", Vptr)
// fortran contiguous pointer checks
SANITIZER("discontiguous", Discontiguous)

// IntegerSanitizer
SANITIZER("unsigned-integer-overflow", UnsignedIntegerOverflow)
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)
277 changes: 276 additions & 1 deletion clang/include/clang/Driver/Options.td

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions clang/include/clang/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,16 @@ class ToolChain {
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;

#ifdef ENABLE_CLASSIC_FLANG
/// \brief Add the flang arguments for system include paths.
///
/// This routine is responsible for adding the -stdinc argument to
/// include headers and module files from standard system header directories.
virtual void
AddFlangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &Flang1Args) const { }
#endif

/// Add options that need to be passed to cc1 for this target.
virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
Expand Down Expand Up @@ -780,6 +790,13 @@ class ToolChain {
virtual void AddHIPRuntimeLibArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const {}

#ifdef ENABLE_CLASSIC_FLANG
/// AddFortranStdlibLibArgs - Add the system specific linker arguments to use
/// for the given Fortran runtime library type.
virtual void AddFortranStdlibLibArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const;
#endif

/// Return sanitizers which are available in this toolchain.
virtual SanitizerMask getSupportedSanitizers() const;

Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/Driver/Types.def
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,15 @@ TYPE("c++-module-cpp-output", PP_CXXModule, INVALID, "iim", phases
TYPE("ada", Ada, INVALID, nullptr, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("assembler", PP_Asm, INVALID, "s", phases::Assemble, phases::Link)
TYPE("assembler-with-cpp", Asm, PP_Asm, "S", phases::Preprocess, phases::Assemble, phases::Link)
#ifdef ENABLE_CLASSIC_FLANG
TYPE("f77", PP_F_FixedForm, INVALID, "f", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("f77-cpp-input", F_FixedForm, PP_F_FixedForm, "F", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("f95", PP_F_FreeForm, INVALID, "f95", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("f95-cpp-input", F_FreeForm, PP_F_FreeForm, "F95", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
#else
TYPE("f95", PP_Fortran, INVALID, "i", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("f95-cpp-input", Fortran, PP_Fortran, nullptr, phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
#endif
TYPE("java", Java, INVALID, nullptr, phases::Compile, phases::Backend, phases::Assemble, phases::Link)

// LLVM IR/LTO types. We define separate types for IR and LTO because LTO
Expand Down
8 changes: 8 additions & 0 deletions clang/include/clang/Driver/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ namespace types {
/// isOpenCL - Is this an "OpenCL" input.
bool isOpenCL(ID Id);

#ifdef ENABLE_CLASSIC_FLANG
/// isFreeFormFortran -- is it a free form layout Fortran input
bool isFreeFormFortran(ID Id);

/// isFixedFormFortran -- is it a fixed form layout Fortran input
bool isFixedFormFortran(ID Id);
#endif

/// isHLSL - Is this an HLSL input.
bool isHLSL(ID Id);

Expand Down
32 changes: 32 additions & 0 deletions clang/include/clang/Frontend/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
#include "clang/Basic/LLVM.h"
#include "clang/Driver/OptionUtils.h"
#include "clang/Frontend/DependencyOutputOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
Expand All @@ -31,6 +33,12 @@
#include <utility>
#include <vector>

namespace llvm {

class StringRef;

} // namespace llvm

namespace clang {

class ASTReader;
Expand All @@ -39,6 +47,7 @@ class CompilerInvocation;
class DiagnosticsEngine;
class ExternalSemaSource;
class FrontendOptions;
class MacroBuilder;
class PCHContainerReader;
class Preprocessor;
class PreprocessorOptions;
Expand All @@ -56,6 +65,29 @@ void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts,
void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
const PreprocessorOutputOptions &Opts);

/// DefineTypeSize - Emit a macro to the predefines buffer that declares a macro
/// named MacroName with the max value for a type with width 'TypeWidth' a
/// signedness of 'isSigned' and with a value suffix of 'ValSuffix' (e.g. LL).
template<typename T>
static void DefineTypeSize(const Twine &MacroName, unsigned TypeWidth,
StringRef ValSuffix, bool isSigned,
T &Builder) {
static_assert(std::is_base_of<MacroBuilder, T>::value, "Illegal T value");
llvm::APInt MaxVal = isSigned ? llvm::APInt::getSignedMaxValue(TypeWidth)
: llvm::APInt::getMaxValue(TypeWidth);
Builder.defineMacro(MacroName, toString(MaxVal, 10, isSigned) + ValSuffix);
}

/// DefineTypeSize - An overloaded helper that uses TargetInfo to determine
/// the width, suffix, and signedness of the given type
template<typename T>
static void DefineTypeSize(const Twine &MacroName, TargetInfo::IntType Ty,
const TargetInfo &TI, T &Builder) {
static_assert(std::is_base_of<MacroBuilder, T>::value, "Illegal T value");
DefineTypeSize(MacroName, TI.getTypeWidth(Ty), TI.getTypeConstantSuffix(Ty),
TI.isTypeSigned(Ty), Builder);
}

/// An interface for collecting the dependencies of a compilation. Users should
/// use \c attachToPreprocessor and \c attachToASTReader to get all of the
/// dependencies.
Expand Down
14 changes: 10 additions & 4 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,11 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
raw_pwrite_stream &OS,
raw_pwrite_stream *DwoOS) {
// Add LibraryInfo.
std::unique_ptr<TargetLibraryInfoImpl> TLII(
llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
bool TargetHasAVX512 =
std::find(TargetOpts.Features.begin(), TargetOpts.Features.end(),
"+avx512f") != TargetOpts.Features.end();
std::unique_ptr<TargetLibraryInfoImpl> TLII(llvm::driver::createTLII(
TargetTriple, CodeGenOpts.getVecLib(), TargetHasAVX512));
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));

// Normal mode, emit a .s or .o file by running the code generator. Note,
Expand Down Expand Up @@ -930,8 +933,11 @@ void EmitAssemblyHelper::RunOptimizationPipeline(

// Register the target library analysis directly and give it a customized
// preset TLI.
std::unique_ptr<TargetLibraryInfoImpl> TLII(
llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
bool TargetHasAVX512 =
std::find(TargetOpts.Features.begin(), TargetOpts.Features.end(),
"+avx512f") != TargetOpts.Features.end();
std::unique_ptr<TargetLibraryInfoImpl> TLII(llvm::driver::createTLII(
TargetTriple, CodeGenOpts.getVecLib(), TargetHasAVX512));
FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });

// Register all the basic analyses with the managers.
Expand Down
10 changes: 6 additions & 4 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4156,7 +4156,8 @@ CGDebugInfo::getGlobalVariableForwardDeclaration(const VarDecl *VD) {
auto Align = getDeclAlignIfRequired(VD, CGM.getContext());
auto *GV = DBuilder.createTempGlobalVariableFwdDecl(
DContext, Name, LinkageName, Unit, Line, getOrCreateType(T, Unit),
!VD->isExternallyVisible(), nullptr, TemplateParameters, Align);
!VD->isExternallyVisible(), nullptr, TemplateParameters,
llvm::DINode::FlagZero, Align);
FwdDeclReplaceMap.emplace_back(
std::piecewise_construct,
std::make_tuple(cast<VarDecl>(VD->getCanonicalDecl())),
Expand Down Expand Up @@ -5676,7 +5677,7 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
Var->hasLocalLinkage(), true,
Expr.empty() ? nullptr : DBuilder.createExpression(Expr),
getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
Align, Annotations);
llvm::DINode::FlagZero, Align, Annotations);
Var->addDebugInfo(GVE);
}
DeclCache[D->getCanonicalDecl()].reset(GVE);
Expand Down Expand Up @@ -5755,7 +5756,7 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {
GV.reset(DBuilder.createGlobalVariableExpression(
DContext, Name, StringRef(), Unit, getLineNumber(VD->getLocation()), Ty,
true, true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),
TemplateParameters, Align));
TemplateParameters, llvm::DINode::FlagZero, Align));
}

void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
Expand All @@ -5773,7 +5774,8 @@ void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
llvm::DIGlobalVariableExpression *GVE =
DBuilder.createGlobalVariableExpression(
DContext, Name, StringRef(), Unit, getLineNumber(D->getLocation()),
Ty, false, false, nullptr, nullptr, nullptr, Align);
Ty, false, false, nullptr, nullptr, nullptr, llvm::DINode::FlagZero,
Align);
Var->addDebugInfo(GVE);
}

Expand Down
8 changes: 7 additions & 1 deletion clang/lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ if(WIN32)
set(system_libs version)
endif()

if(LLVM_ENABLE_CLASSIC_FLANG)
set(TOOLCHAINS_FLANG_CPP ToolChains/ClassicFlang.cpp)
else()
set(TOOLCHAINS_FLANG_CPP ToolChains/Flang.cpp)
endif()

add_clang_library(clangDriver
Action.cpp
Compilation.cpp
Expand Down Expand Up @@ -53,7 +59,7 @@ add_clang_library(clangDriver
ToolChains/Cuda.cpp
ToolChains/Darwin.cpp
ToolChains/DragonFly.cpp
ToolChains/Flang.cpp
${TOOLCHAINS_FLANG_CPP}
ToolChains/FreeBSD.cpp
ToolChains/Fuchsia.cpp
ToolChains/Gnu.cpp
Expand Down
Loading
Loading