Skip to content

Commit

Permalink
Merged main:0a3cf7f4762e into amd-gfx:ab07f2cc37e7
Browse files Browse the repository at this point in the history
Local branch amd-gfx ab07f2c Merged main:4e0e79dd349a into amd-gfx:edf208676d23
Remote branch main 0a3cf7f AMDGPU/GlobalISel: Add baseline IR tests for fdiv
  • Loading branch information
Sw authored and Sw committed Jan 6, 2021
2 parents ab07f2c + 0a3cf7f commit 8b5343c
Show file tree
Hide file tree
Showing 45 changed files with 4,066 additions and 121 deletions.
4 changes: 2 additions & 2 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ def C : Flag<["-"], "C">, Flags<[CC1Option]>, Group<Preprocessor_Group>,
HelpText<"Include comments in preprocessed output">,
MarshallingInfoFlag<"PreprocessorOutputOpts.ShowComments">;
def D : JoinedOrSeparate<["-"], "D">, Group<Preprocessor_Group>,
Flags<[CC1Option]>, MetaVarName<"<macro>=<value>">,
Flags<[CC1Option, FlangOption, FC1Option]>, MetaVarName<"<macro>=<value>">,
HelpText<"Define <macro> to <value> (or 1 if <value> omitted)">;
def E : Flag<["-"], "E">, Flags<[NoXarchOption,CC1Option, FlangOption, FC1Option]>, Group<Action_Group>,
HelpText<"Only run the preprocessor">;
Expand Down Expand Up @@ -730,7 +730,7 @@ def Ttext : JoinedOrSeparate<["-"], "Ttext">, Group<T_Group>,
def T : JoinedOrSeparate<["-"], "T">, Group<T_Group>,
MetaVarName<"<script>">, HelpText<"Specify <script> as linker script">;
def U : JoinedOrSeparate<["-"], "U">, Group<Preprocessor_Group>,
Flags<[CC1Option]>, MetaVarName<"<macro>">, HelpText<"Undefine macro <macro>">;
Flags<[CC1Option, FlangOption, FC1Option]>, MetaVarName<"<macro>">, HelpText<"Undefine macro <macro>">;
def V : JoinedOrSeparate<["-"], "V">, Flags<[NoXarchOption, Unsupported]>;
def Wa_COMMA : CommaJoined<["-"], "Wa,">,
HelpText<"Pass the comma separated arguments in <arg> to the assembler">,
Expand Down
21 changes: 1 addition & 20 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6396,26 +6396,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
options::OPT_fno_cxx_static_destructors, true))
CmdArgs.push_back("-fno-c++-static-destructors");

if (Arg *A = Args.getLastArg(options::OPT_moutline,
options::OPT_mno_outline)) {
if (A->getOption().matches(options::OPT_moutline)) {
// We only support -moutline in AArch64 and ARM targets right now. If
// we're not compiling for these, emit a warning and ignore the flag.
// Otherwise, add the proper mllvm flags.
if (!(Triple.isARM() || Triple.isThumb() ||
Triple.getArch() == llvm::Triple::aarch64 ||
Triple.getArch() == llvm::Triple::aarch64_32)) {
D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName();
} else {
CmdArgs.push_back("-mllvm");
CmdArgs.push_back("-enable-machine-outliner");
}
} else {
// Disable all outlining behaviour.
CmdArgs.push_back("-mllvm");
CmdArgs.push_back("-enable-machine-outliner=never");
}
}
addMachineOutlinerArgs(D, Args, CmdArgs, Triple, /*IsLTO=*/false);

if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
options::OPT_mno_outline_atomics)) {
Expand Down
36 changes: 36 additions & 0 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,

// Handle remarks hotness/threshold related options.
renderRemarksHotnessOptions(Args, CmdArgs);

addMachineOutlinerArgs(D, Args, CmdArgs, ToolChain.getEffectiveTriple(),
/*IsLTO=*/true);
}

void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
Expand Down Expand Up @@ -1586,3 +1589,36 @@ unsigned tools::getOrCheckAMDGPUCodeObjectVersion(
}
return CodeObjVer;
}

void tools::addMachineOutlinerArgs(const Driver &D,
const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs,
const llvm::Triple &Triple, bool IsLTO) {
auto addArg = [&, IsLTO](const Twine &Arg) {
if (IsLTO) {
CmdArgs.push_back(Args.MakeArgString("-plugin-opt=" + Arg));
} else {
CmdArgs.push_back("-mllvm");
CmdArgs.push_back(Args.MakeArgString(Arg));
}
};

if (Arg *A = Args.getLastArg(options::OPT_moutline,
options::OPT_mno_outline)) {
if (A->getOption().matches(options::OPT_moutline)) {
// We only support -moutline in AArch64 and ARM targets right now. If
// we're not compiling for these, emit a warning and ignore the flag.
// Otherwise, add the proper mllvm flags.
if (!(Triple.isARM() || Triple.isThumb() ||
Triple.getArch() == llvm::Triple::aarch64 ||
Triple.getArch() == llvm::Triple::aarch64_32)) {
D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName();
} else {
addArg(Twine("-enable-machine-outliner"));
}
} else {
// Disable all outlining behaviour.
addArg(Twine("-enable-machine-outliner=never"));
}
}
}
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/CommonArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args,
unsigned getOrCheckAMDGPUCodeObjectVersion(const Driver &D,
const llvm::opt::ArgList &Args,
bool Diagnose = false);

void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs,
const llvm::Triple &Triple, bool IsLTO);
} // end namespace tools
} // end namespace driver
} // end namespace clang
Expand Down
14 changes: 13 additions & 1 deletion clang/lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ using namespace clang::driver::tools;
using namespace clang;
using namespace llvm::opt;

void Flang::AddPreprocessingOptions(const ArgList &Args,
ArgStringList &CmdArgs) const {
Args.AddAllArgs(CmdArgs, {options::OPT_D, options::OPT_U});
}

void Flang::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output, const InputInfoList &Inputs,
const ArgList &Args, const char *LinkingOutput) const {
Expand Down Expand Up @@ -63,14 +68,21 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
assert(false && "Unexpected action class for Flang tool.");
}

const InputInfo &Input = Inputs[0];
types::ID InputType = Input.getType();

// Add preprocessing options like -I, -D, etc. if we are using the
// preprocessor (i.e. skip when dealing with e.g. binary files).
if (types::getPreprocessedType(InputType) != types::TY_INVALID)
AddPreprocessingOptions(Args, CmdArgs);

if (Output.isFilename()) {
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
} else {
assert(Output.isNothing() && "Invalid output.");
}

const InputInfo &Input = Inputs[0];
assert(Input.isFilename() && "Invalid input.");
CmdArgs.push_back(Input.getFilename());

Expand Down
9 changes: 9 additions & 0 deletions clang/lib/Driver/ToolChains/Flang.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ namespace tools {

/// Flang compiler tool.
class LLVM_LIBRARY_VISIBILITY Flang : public Tool {
private:
/// Extract preprocessing options from the driver arguments and add them to
/// the preprocessor command arguments.
///
/// \param [in] Args The list of input driver arguments
/// \param [out] CmdArgs The list of output command arguments
void AddPreprocessingOptions(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const;

public:
Flang(const ToolChain &TC);
~Flang() override;
Expand Down
14 changes: 13 additions & 1 deletion clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8200,9 +8200,21 @@ ExprResult InitializationSequence::Perform(Sema &S,
if (S.CheckExceptionSpecCompatibility(CurInit.get(), DestType))
return ExprError();

QualType MTETy = Step->Type;

// When this is an incomplete array type (such as when this is
// initializing an array of unknown bounds from an init list), use THAT
// type instead so that we propogate the array bounds.
if (MTETy->isIncompleteArrayType() &&
!CurInit.get()->getType()->isIncompleteArrayType() &&
S.Context.hasSameType(
MTETy->getPointeeOrArrayElementType(),
CurInit.get()->getType()->getPointeeOrArrayElementType()))
MTETy = CurInit.get()->getType();

// Materialize the temporary into memory.
MaterializeTemporaryExpr *MTE = S.CreateMaterializeTemporaryExpr(
Step->Type, CurInit.get(), Entity.getType()->isLValueReferenceType());
MTETy, CurInit.get(), Entity.getType()->isLValueReferenceType());
CurInit = MTE;

// If we're extending this temporary to automatic storage duration -- we
Expand Down
26 changes: 26 additions & 0 deletions clang/test/AST/pr47636.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %clang_cc1 -fsyntax-only %s -ast-dump | FileCheck %s

int(&&intu_rvref)[] {1,2,3,4};
// CHECK: VarDecl 0x[[GLOB_ADDR:[0-9a-f]+]] {{.*}} intu_rvref 'int (&&)[4]' listinit
// CHECK-NEXT: ExprWithCleanups {{.*}} 'int [4]' xvalue
// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'int [4]' xvalue extended by Var 0x[[GLOB_ADDR]] 'intu_rvref' 'int (&&)[4]'
// CHECK-NEXT: InitListExpr {{.*}} 'int [4]'

// CHECK: FunctionDecl {{.*}} static_const
void static_const() {
static const int(&&intu_rvref)[] {1,2,3,4};
// CHECK: VarDecl 0x[[STATIC_ADDR:[0-9a-f]+]] {{.*}} intu_rvref 'const int (&&)[4]' static listinit
// CHECK-NEXT: ExprWithCleanups {{.*}} 'const int [4]' xvalue
// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'const int [4]' xvalue extended by Var 0x[[STATIC_ADDR]] 'intu_rvref' 'const int (&&)[4]'
// CHECK-NEXT: InitListExpr {{.*}} 'const int [4]'
}

// CHECK: FunctionDecl {{.*}} const_expr
constexpr int const_expr() {
int(&&intu_rvref)[]{1, 2, 3, 4};
// CHECK: VarDecl 0x[[CE_ADDR:[0-9a-f]+]] {{.*}} intu_rvref 'int (&&)[4]' listinit
// CHECK-NEXT: ExprWithCleanups {{.*}} 'int [4]' xvalue
// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'int [4]' xvalue extended by Var 0x[[CE_ADDR]] 'intu_rvref' 'int (&&)[4]'
// CHECK-NEXT: InitListExpr {{.*}} 'int [4]'
return intu_rvref[0];
}
12 changes: 12 additions & 0 deletions clang/test/CodeGenCXX/pr47636.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ void foo() {
// CHECK: @_ZZ3foovE10intu_rvref = internal constant [4 x i32]* @_ZGRZ3foovE10intu_rvref_
// CHECK: @_ZGRZ3foovE10intu_rvref_ = internal constant [4 x i32] [i32 1, i32 2, i32 3, i32 4]
}

// Example given on review, ensure this doesn't crash as well.
constexpr int f() {
// CHECK: i32 @_Z1fv()
int(&&intu_rvref)[]{1, 2, 3, 4};
// CHECK: %{{.*}} = alloca [4 x i32]*
return intu_rvref[2];
}

void use_f() {
int i = f();
}
9 changes: 9 additions & 0 deletions clang/test/Driver/arm-machine-outliner.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// REQUIRES: arm-registered-target
// RUN: %clang -target armv7-linux-gnueabihf -moutline -c %s -### 2>&1 | FileCheck %s -check-prefix=ON
// ON: "-mllvm" "-enable-machine-outliner"
// RUN: %clang -target armv7-linux-gnueabihf -flto -moutline %s -### 2>&1 | FileCheck %s -check-prefix=ON-LTO
// ON-LTO: "-plugin-opt=-enable-machine-outliner"
// RUN: %clang -target armv7-linux-gnueabihf -moutline -mno-outline -c %s -### 2>&1 | FileCheck %s -check-prefix=OFF
// OFF: "-mllvm" "-enable-machine-outliner=never"
// RUN: %clang -target armv7-linux-gnueabihf -flto -moutline -mno-outline %s -### 2>&1 | FileCheck %s -check-prefix=OFF-LTO
// OFF-LTO: "-plugin-opt=-enable-machine-outliner=never"
8 changes: 8 additions & 0 deletions flang/include/flang/Frontend/CompilerInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "flang/Frontend/CompilerInvocation.h"
#include "flang/Frontend/FrontendAction.h"
#include "flang/Frontend/PreprocessorOptions.h"
#include "flang/Parser/parsing.h"
#include "flang/Parser/provenance.h"
#include "flang/Semantics/semantics.h"
Expand Down Expand Up @@ -135,6 +136,13 @@ class CompilerInstance {
return invocation_->frontendOpts();
}

PreprocessorOptions &preprocessorOpts() {
return invocation_->preprocessorOpts();
}
const PreprocessorOptions &preprocessorOpts() const {
return invocation_->preprocessorOpts();
}

/// }
/// @name Diagnostics Engine
/// {
Expand Down
13 changes: 13 additions & 0 deletions flang/include/flang/Frontend/CompilerInvocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#define LLVM_FLANG_FRONTEND_COMPILERINVOCATION_H

#include "flang/Frontend/FrontendOptions.h"
#include "flang/Frontend/PreprocessorOptions.h"
#include "flang/Parser/parsing.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "llvm/Option/ArgList.h"
#include <memory>

namespace Fortran::frontend {

Expand All @@ -27,6 +29,8 @@ class CompilerInvocationBase {
public:
/// Options controlling the diagnostic engine.
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagnosticOpts_;
/// Options for the preprocessor.
std::shared_ptr<Fortran::frontend::PreprocessorOptions> preprocessorOpts_;

CompilerInvocationBase();
CompilerInvocationBase(const CompilerInvocationBase &x);
Expand All @@ -38,6 +42,11 @@ class CompilerInvocationBase {
const clang::DiagnosticOptions &GetDiagnosticOpts() const {
return *diagnosticOpts_.get();
}

PreprocessorOptions &preprocessorOpts() { return *preprocessorOpts_; }
const PreprocessorOptions &preprocessorOpts() const {
return *preprocessorOpts_;
}
};

class CompilerInvocation : public CompilerInvocationBase {
Expand Down Expand Up @@ -74,6 +83,10 @@ class CompilerInvocation : public CompilerInvocationBase {
// need to extend frontendOpts_ first. Next, we need to add the corresponding
// compiler driver options in libclangDriver.
void SetDefaultFortranOpts();

/// Set the Fortran options to user-specified values.
/// These values are found in the preprocessor options.
void setFortranOpts();
};

} // end namespace Fortran::frontend
Expand Down
42 changes: 42 additions & 0 deletions flang/include/flang/Frontend/PreprocessorOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//===- PreprocessorOptions.h ------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file contains the declaration of the PreprocessorOptions class, which
/// is the class for all preprocessor options.
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_FLANG_PREPROCESSOROPTIONS_H
#define LLVM_FLANG_PREPROCESSOROPTIONS_H

#include "llvm/ADT/StringRef.h"

namespace Fortran::frontend {

/// This class is used for passing the various options used
/// in preprocessor initialization to the parser options.
class PreprocessorOptions {
public:
std::vector<std::pair<std::string, /*isUndef*/ bool>> macros;

public:
PreprocessorOptions() {}

void addMacroDef(llvm::StringRef name) {
macros.emplace_back(std::string(name), false);
}

void addMacroUndef(llvm::StringRef name) {
macros.emplace_back(std::string(name), true);
}
};

} // namespace Fortran::frontend

#endif // LLVM_FLANG_PREPROCESSOROPTIONS_H
2 changes: 2 additions & 0 deletions flang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ bool CompilerInstance::ExecuteAction(FrontendAction &act) {
// TODO: Instead of defaults we should be setting these options based on the
// user input.
this->invocation().SetDefaultFortranOpts();
// Set the fortran options to user-based input.
this->invocation().setFortranOpts();

// Connect Input to a CompileInstance
for (const FrontendInputFile &fif : frontendOpts().inputs_) {
Expand Down
Loading

0 comments on commit 8b5343c

Please sign in to comment.