Skip to content

Commit

Permalink
Merged master:a6a42df506c into amd-gfx:652d2b7e64f
Browse files Browse the repository at this point in the history
Local branch amd-gfx 652d2b7 Merged master:07239c736a5 into amd-gfx:5df6a2a9b9a
Remote branch master a6a42df [Sema] Fix -Wunused-variable in CreateBuiltinMatrixSubscriptExpr (NFC).
  • Loading branch information
Sw authored and Sw committed Jun 2, 2020
2 parents 652d2b7 + a6a42df commit 446d3a5
Show file tree
Hide file tree
Showing 86 changed files with 2,177 additions and 2,081 deletions.
4 changes: 4 additions & 0 deletions clang/docs/ClangCommandLineReference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,10 @@ Restrict code to those available for App Extensions

.. option:: -fautolink, -fno-autolink

.. option:: -fbasic-block-sections=labels, -fbasic-block-sections=all, -fbasic-block-sections=list=<arg>, -fbasic-block-sections=none

Generate labels for each basic block or place each basic block or a subset of basic blocks in its own section.

.. option:: -fblocks, -fno-blocks

Enable the 'blocks' language feature
Expand Down
38 changes: 38 additions & 0 deletions clang/docs/UsersManual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,44 @@ are listed below.
$ cd $P/bar && clang -c -funique-internal-linkage-names name_conflict.c
$ cd $P && clang foo/name_conflict.o && bar/name_conflict.o
**-fbasic-block-sections=[labels, all, list=<arg>, none]**

Controls whether Clang emits a label for each basic block. Further, with
values "all" and "list=arg", each basic block or a subset of basic blocks
can be placed in its own unique section.

With the ``list=<arg>`` option, a file containing the subset of basic blocks
that need to placed in unique sections can be specified. The format of the
file is as follows. For example, ``list=spec.txt`` where ``spec.txt`` is the
following:

::

!foo
!!2
!_Z3barv

will place the machine basic block with ``id 2`` in function ``foo`` in a
unique section. It will also place all basic blocks of functions ``bar``
in unique sections.

Further, section clusters can also be specified using the ``list=<arg>``
option. For example, ``list=spec.txt`` where ``spec.txt`` contains:

::

!foo
!!1 !!3 !!5
!!2 !!4 !!6

will create two unique sections for function ``foo`` with the first
containing the odd numbered basic blocks and the second containing the
even numbered basic blocks.

Basic block sections allow the linker to reorder basic blocks and enables
link-time optimizations like whole program inter-procedural basic block
reordering.

Profile Guided Optimization
---------------------------

Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ CODEGENOPT(CXXCtorDtorAliases, 1, 0) ///< Emit complete ctors/dtors as linker
///< aliases to base ctors when possible.
CODEGENOPT(DataSections , 1, 0) ///< Set when -fdata-sections is enabled.
CODEGENOPT(UniqueSectionNames, 1, 1) ///< Set for -funique-section-names.
CODEGENOPT(UniqueBasicBlockSectionNames, 1, 1) ///< Set for -funique-basic-block-section-names,
///< Produce unique section names with
///< basic block sections.
ENUM_CODEGENOPT(FramePointer, FramePointerKind, 2, FramePointerKind::None) /// frame-pointer: all,non-leaf,none

CODEGENOPT(DisableFree , 1, 0) ///< Don't free memory.
Expand Down
16 changes: 16 additions & 0 deletions clang/include/clang/Basic/CodeGenOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ class CodeGenOptions : public CodeGenOptionsBase {
Embed_Marker // Embed a marker as a placeholder for bitcode.
};

// This field stores one of the allowed values for the option
// -fbasic-block-sections=. The allowed values with this option are:
// {"labels", "all", "list=<file>", "none"}.
//
// "labels": Only generate basic block symbols (labels) for all basic
// blocks, do not generate unique sections for basic blocks.
// Use the machine basic block id in the symbol name to
// associate profile info from virtual address to machine
// basic block.
// "all" : Generate basic block sections for all basic blocks.
// "list=<file>": Generate basic block sections for a subset of basic blocks.
// The functions and the machine basic block ids are specified
// in the file.
// "none": Disable sections/labels for basic blocks.
std::string BBSections;

enum class FramePointerKind {
None, // Omit all frame pointers.
NonLeaf, // Keep non-leaf frame pointers.
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticFrontendKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def warn_fe_concepts_ts_flag : Warning<
"-fconcepts-ts is deprecated - use '-std=c++20' for Concepts support">,
InGroup<Deprecated>;

def err_fe_unable_to_load_basic_block_sections_file : Error<
"unable to load basic block sections function list: '%0'">;

def warn_fe_serialized_diag_merge_failure : Warning<
"unable to merge a subprocess's serialized diagnostics">,
InGroup<SerializedDiagnostics>;
Expand Down
11 changes: 11 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,11 @@ def ffunction_sections : Flag<["-"], "ffunction-sections">, Group<f_Group>,
Flags<[CC1Option]>,
HelpText<"Place each function in its own section">;
def fno_function_sections : Flag<["-"], "fno-function-sections">, Group<f_Group>;
def fbasic_block_sections_EQ : Joined<["-"], "fbasic-block-sections=">, Group<f_Group>,
Flags<[CC1Option, CC1AsOption]>,
HelpText<"Place each function's basic blocks in unique sections (ELF Only) : all | labels | none | list=<file>">,
DocBrief<[{Generate labels for each basic block or place each basic block or a subset of basic blocks in its own section.}]>,
Values<"all,labels,none,list=">;
def fdata_sections : Flag <["-"], "fdata-sections">, Group<f_Group>,
Flags<[CC1Option]>, HelpText<"Place each data in its own section">;
def fno_data_sections : Flag <["-"], "fno-data-sections">, Group<f_Group>;
Expand All @@ -2002,6 +2007,12 @@ def funique_section_names : Flag <["-"], "funique-section-names">,
def fno_unique_section_names : Flag <["-"], "fno-unique-section-names">,
Group<f_Group>, Flags<[CC1Option]>;

def funique_basic_block_section_names : Flag <["-"], "funique-basic-block-section-names">,
Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Use unique names for basic block sections (ELF Only)">;
def fno_unique_basic_block_section_names : Flag <["-"], "fno-unique-basic-block-section-names">,
Group<f_Group>;

def funique_internal_linkage_names : Flag <["-"], "funique-internal-linkage-names">,
Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Uniqueify Internal Linkage Symbol Names by appending the MD5 hash of the module path">;
Expand Down
47 changes: 33 additions & 14 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ static CodeGenFileType getCodeGenFileType(BackendAction Action) {
}
}

static void initTargetOptions(llvm::TargetOptions &Options,
static void initTargetOptions(DiagnosticsEngine &Diags,
llvm::TargetOptions &Options,
const CodeGenOptions &CodeGenOpts,
const clang::TargetOptions &TargetOpts,
const LangOptions &LangOpts,
Expand Down Expand Up @@ -488,9 +489,30 @@ static void initTargetOptions(llvm::TargetOptions &Options,
Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
Options.UnsafeFPMath = LangOpts.UnsafeFPMath;
Options.StackAlignmentOverride = CodeGenOpts.StackAlignment;

Options.BBSections =
llvm::StringSwitch<llvm::BasicBlockSection>(CodeGenOpts.BBSections)
.Case("all", llvm::BasicBlockSection::All)
.Case("labels", llvm::BasicBlockSection::Labels)
.StartsWith("list=", llvm::BasicBlockSection::List)
.Case("none", llvm::BasicBlockSection::None)
.Default(llvm::BasicBlockSection::None);

if (Options.BBSections == llvm::BasicBlockSection::List) {
ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
MemoryBuffer::getFile(CodeGenOpts.BBSections.substr(5));
if (!MBOrErr)
Diags.Report(diag::err_fe_unable_to_load_basic_block_sections_file)
<< MBOrErr.getError().message();
else
Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
}

Options.FunctionSections = CodeGenOpts.FunctionSections;
Options.DataSections = CodeGenOpts.DataSections;
Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
Options.UniqueBasicBlockSectionNames =
CodeGenOpts.UniqueBasicBlockSectionNames;
Options.TLSSize = CodeGenOpts.TLSSize;
Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
Options.ExplicitEmulatedTLS = CodeGenOpts.ExplicitEmulatedTLS;
Expand Down Expand Up @@ -802,7 +824,7 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
CodeGenOpt::Level OptLevel = getCGOptLevel(CodeGenOpts);

llvm::TargetOptions Options;
initTargetOptions(Options, CodeGenOpts, TargetOpts, LangOpts, HSOpts);
initTargetOptions(Diags, Options, CodeGenOpts, TargetOpts, LangOpts, HSOpts);
TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr,
Options, RM, CM, OptLevel));
}
Expand Down Expand Up @@ -1480,15 +1502,12 @@ BitcodeModule *clang::FindThinLTOModule(MutableArrayRef<BitcodeModule> BMs) {
return nullptr;
}

static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
const HeaderSearchOptions &HeaderOpts,
const CodeGenOptions &CGOpts,
const clang::TargetOptions &TOpts,
const LangOptions &LOpts,
std::unique_ptr<raw_pwrite_stream> OS,
std::string SampleProfile,
std::string ProfileRemapping,
BackendAction Action) {
static void runThinLTOBackend(
DiagnosticsEngine &Diags, ModuleSummaryIndex *CombinedIndex, Module *M,
const HeaderSearchOptions &HeaderOpts, const CodeGenOptions &CGOpts,
const clang::TargetOptions &TOpts, const LangOptions &LOpts,
std::unique_ptr<raw_pwrite_stream> OS, std::string SampleProfile,
std::string ProfileRemapping, BackendAction Action) {
StringMap<DenseMap<GlobalValue::GUID, GlobalValueSummary *>>
ModuleToDefinedGVSummaries;
CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
Expand Down Expand Up @@ -1558,7 +1577,7 @@ static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
Conf.RelocModel = CGOpts.RelocationModel;
Conf.CGOptLevel = getCGOptLevel(CGOpts);
Conf.OptLevel = CGOpts.OptimizationLevel;
initTargetOptions(Conf.Options, CGOpts, TOpts, LOpts, HeaderOpts);
initTargetOptions(Diags, Conf.Options, CGOpts, TOpts, LOpts, HeaderOpts);
Conf.SampleProfile = std::move(SampleProfile);
Conf.PTO.LoopUnrolling = CGOpts.UnrollLoops;
// For historical reasons, loop interleaving is set to mirror setting for loop
Expand Down Expand Up @@ -1648,8 +1667,8 @@ void clang::EmitBackendOutput(DiagnosticsEngine &Diags,
// of an error).
if (CombinedIndex) {
if (!CombinedIndex->skipModuleByDistributedBackend()) {
runThinLTOBackend(CombinedIndex.get(), M, HeaderOpts, CGOpts, TOpts,
LOpts, std::move(OS), CGOpts.SampleProfileFile,
runThinLTOBackend(Diags, CombinedIndex.get(), M, HeaderOpts, CGOpts,
TOpts, LOpts, std::move(OS), CGOpts.SampleProfileFile,
CGOpts.ProfileRemappingFile, Action);
return;
}
Expand Down
17 changes: 17 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4205,10 +4205,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
options::OPT_fno_function_sections,
options::OPT_fdata_sections,
options::OPT_fno_data_sections,
options::OPT_fbasic_block_sections_EQ,
options::OPT_funique_internal_linkage_names,
options::OPT_fno_unique_internal_linkage_names,
options::OPT_funique_section_names,
options::OPT_fno_unique_section_names,
options::OPT_funique_basic_block_section_names,
options::OPT_fno_unique_basic_block_section_names,
options::OPT_mrestrict_it,
options::OPT_mno_restrict_it,
options::OPT_mstackrealign,
Expand Down Expand Up @@ -4826,6 +4829,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-ffunction-sections");
}

if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_sections_EQ)) {
StringRef Val = A->getValue();
if (Val != "all" && Val != "labels" && Val != "none" &&
!(Val.startswith("list=") && llvm::sys::fs::exists(Val.substr(5))))
D.Diag(diag::err_drv_invalid_value)
<< A->getAsString(Args) << A->getValue();
else
A->render(Args, CmdArgs);
}

if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
UseSeparateSections)) {
CmdArgs.push_back("-fdata-sections");
Expand All @@ -4839,6 +4852,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
options::OPT_fno_unique_internal_linkage_names, false))
CmdArgs.push_back("-funique-internal-linkage-names");

if (Args.hasFlag(options::OPT_funique_basic_block_section_names,
options::OPT_fno_unique_basic_block_section_names, false))
CmdArgs.push_back("-funique-basic-block-section-names");

Args.AddLastArg(CmdArgs, options::OPT_finstrument_functions,
options::OPT_finstrument_functions_after_inlining,
options::OPT_finstrument_function_entry_bare);
Expand Down
11 changes: 10 additions & 1 deletion clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,10 +937,19 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Opts.TrapFuncName = std::string(Args.getLastArgValue(OPT_ftrap_function_EQ));
Opts.UseInitArray = !Args.hasArg(OPT_fno_use_init_array);

Opts.FunctionSections = Args.hasArg(OPT_ffunction_sections);
Opts.BBSections =
std::string(Args.getLastArgValue(OPT_fbasic_block_sections_EQ, "none"));

// Basic Block Sections implies Function Sections.
Opts.FunctionSections =
Args.hasArg(OPT_ffunction_sections) ||
(Opts.BBSections != "none" && Opts.BBSections != "labels");

Opts.DataSections = Args.hasArg(OPT_fdata_sections);
Opts.StackSizeSection = Args.hasArg(OPT_fstack_size_section);
Opts.UniqueSectionNames = !Args.hasArg(OPT_fno_unique_section_names);
Opts.UniqueBasicBlockSectionNames =
Args.hasArg(OPT_funique_basic_block_section_names);
Opts.UniqueInternalLinkageNames =
Args.hasArg(OPT_funique_internal_linkage_names);

Expand Down
1 change: 1 addition & 0 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4737,6 +4737,7 @@ ExprResult Sema::CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx,
bool ConversionOk = tryConvertToTy(*this, Context.getSizeType(), &ConvExpr);
assert(ConversionOk &&
"should be able to convert any integer type to size type");
(void)ConversionOk;
return ConvExpr.get();
};

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ void InitListChecker::CheckReferenceType(const InitializedEntity &Entity,

expr = Result.getAs<Expr>();
// FIXME: Why are we updating the syntactic init list?
if (!VerifyOnly)
if (!VerifyOnly && expr)
IList->setInit(Index, expr);

if (hadError)
Expand Down
11 changes: 11 additions & 0 deletions clang/test/AST/ast-dump-recovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,14 @@ void InitializerForAuto() {
// Verified that the generated call operator is invalid.
// CHECK: |-CXXMethodDecl {{.*}} invalid operator() 'auto () const -> auto'
using Escape = decltype([] { return undef(); }());

// CHECK: VarDecl {{.*}} NoCrashOnInvalidInitList
// CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>' contains-errors lvalue
// CHECK-NEXT: `-InitListExpr
// CHECK-NEXT: `-DesignatedInitExpr {{.*}} 'void'
// CHECK-NEXT: `-CXXNullPtrLiteralExpr {{.*}} 'nullptr_t'
struct {
int& abc;
} NoCrashOnInvalidInitList = {
.abc = nullptr,
};
1 change: 1 addition & 0 deletions clang/test/CodeGen/Inputs/basic-block-sections.funcnames
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!world
47 changes: 47 additions & 0 deletions clang/test/CodeGen/basic-block-sections.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// REQUIRES: x86-registered-target

// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -o - < %s | FileCheck %s --check-prefix=PLAIN
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasic-block-sections=all -fbasic-block-sections=none -o - < %s | FileCheck %s --check-prefix=PLAIN

// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasic-block-sections=labels -o - < %s | FileCheck %s --check-prefix=BB_LABELS
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasic-block-sections=all -o - < %s | FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_ALL
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasic-block-sections=list=%S/Inputs/basic-block-sections.funcnames -o - < %s | FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_LIST
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasic-block-sections=all -funique-basic-block-section-names -o - < %s | FileCheck %s --check-prefix=UNIQUE

int world(int a) {
if (a > 10)
return 10;
else if (a > 5)
return 5;
else
return 0;
}

int another(int a) {
if (a > 10)
return 20;
return 0;
}

// PLAIN-NOT: section
// PLAIN: world:
//
// BB_LABELS-NOT: section
// BB_LABELS: world:
// BB_LABELS: a.BB.world:
// BB_LABELS: aa.BB.world:
// BB_LABELS: a.BB.another:
//
// BB_WORLD: .section .text.world,"ax",@progbits{{$}}
// BB_WORLD: world:
// BB_WORLD: .section .text.world,"ax",@progbits,unique
// BB_WORLD: world.1:
// BB_WORLD: .section .text.another,"ax",@progbits
// BB_ALL: .section .text.another,"ax",@progbits,unique
// BB_ALL: another.1:
// BB_LIST-NOT: .section .text.another,"ax",@progbits,unique
// BB_LIST: another:
// BB_LIST-NOT: another.1:
//
// UNIQUE: .section .text.world.world.1,
// UNIQUE: .section .text.another.another.1,
9 changes: 9 additions & 0 deletions clang/test/Driver/fbasic-block-sections.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %clang -### -fbasic-block-sections=none %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-NONE %s
// RUN: %clang -### -fbasic-block-sections=all %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-ALL %s
// RUN: %clang -### -fbasic-block-sections=list=%s %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-LIST %s
// RUN: %clang -### -fbasic-block-sections=labels %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-LABELS %s
//
// CHECK-OPT-NONE: "-fbasic-block-sections=none"
// CHECK-OPT-ALL: "-fbasic-block-sections=all"
// CHECK-OPT-LIST: "-fbasic-block-sections={{[^ ]*}}fbasic-block-sections.c"
// CHECK-OPT-LABELS: "-fbasic-block-sections=labels"
4 changes: 4 additions & 0 deletions clang/test/Driver/funique-basic-block-section-names.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// RUN: %clang -### -funique-basic-block-section-names %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
// RUN: %clang -### -funique-basic-block-section-names -fno-unique-basic-block-section-names %s -S 2>&1 | FileCheck -check-prefix=CHECK-NOOPT %s
// CHECK-OPT: "-funique-basic-block-section-names"
// CHECK-NOOPT-NOT: "-funique-basic-block-section-names"
1 change: 1 addition & 0 deletions clang/unittests/Tooling/Syntax/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ clang_target_link_libraries(SyntaxTests
clangFrontend
clangLex
clangSerialization
clangTesting
clangTooling
clangToolingCore
clangToolingSyntax
Expand Down
Loading

0 comments on commit 446d3a5

Please sign in to comment.