Skip to content

Commit

Permalink
Merged master:49a4f3f7d88 into amd-gfx:9c1698c4caf
Browse files Browse the repository at this point in the history
Local branch amd-gfx 9c1698c Merged master:bb7fb6d7b2f into amd-gfx:9d914d750a0
Remote branch master 49a4f3f [AArch64][GlobalISel] Add a post-legalizer combiner with a very simple combine.
  • Loading branch information
Sw authored and Sw committed May 22, 2020
2 parents 9c1698c + 49a4f3f commit 92039d2
Show file tree
Hide file tree
Showing 36 changed files with 669 additions and 110 deletions.
5 changes: 5 additions & 0 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,11 @@ def FallThrough : StmtAttr {
let Documentation = [FallthroughDocs];
}

def NoMerge : StmtAttr {
let Spellings = [Clang<"nomerge">];
let Documentation = [NoMergeDocs];
}

def FastCall : DeclOrTypeAttr {
let Spellings = [GCC<"fastcall">, Keyword<"__fastcall">,
Keyword<"_fastcall">];
Expand Down
14 changes: 14 additions & 0 deletions clang/include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,20 @@ that appears to be capable of returning to its caller.
}];
}

def NoMergeDocs : Documentation {
let Category = DocCatFunction;
let Content = [{
If a statement is marked ``nomerge`` and contains call experessions, those call
expressions inside the statement will not be merged during optimization. This
attribute can be used to prevent the optimizer from obscuring the source
location of certain calls. For example, it will prevent tail merging otherwise
identical code sequences that raise an exception or terminate the program. Tail
merging normally reduces the precision of source location information, making
stack traces less useful for debugging. This attribute gives the user control
over the tradeoff between code size and debug information precision.
}];
}

def AssertCapabilityDocs : Documentation {
let Category = DocCatFunction;
let Heading = "assert_capability, assert_shared_capability";
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -2762,6 +2762,10 @@ def warn_auto_var_is_id : Warning<
InGroup<DiagGroup<"auto-var-id">>;

// Attributes
def warn_nomerge_attribute_ignored_in_stmt: Warning<
"%0 attribute is ignored because there exists no call expression inside the "
"statement">,
InGroup<IgnoredAttributes>;
def err_nsobject_attribute : Error<
"'NSObject' attribute is for pointer types only">;
def err_attributes_are_not_compatible : Error<
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4822,6 +4822,12 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
Attrs.addAttribute(getLLVMContext(), llvm::AttributeList::FunctionIndex,
llvm::Attribute::StrictFP);

// Add call-site nomerge attribute if exists.
if (InNoMergeAttributedStmt)
Attrs =
Attrs.addAttribute(getLLVMContext(), llvm::AttributeList::FunctionIndex,
llvm::Attribute::NoMerge);

// Apply some call-site-specific attributes.
// TODO: work this into building the attribute set.

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CGException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
// In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
// case of throw with types, we ignore it and print a warning for now.
// TODO Correctly handle exception specification in wasm
if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
if (CGM.getLangOpts().WasmExceptions) {
if (EST == EST_DynamicNone)
EHStack.pushTerminate();
else
Expand Down Expand Up @@ -560,7 +560,7 @@ void CodeGenFunction::EmitEndEHSpec(const Decl *D) {
// In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
// case of throw with types, we ignore it and print a warning for now.
// TODO Correctly handle exception specification in wasm
if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly) {
if (CGM.getLangOpts().WasmExceptions) {
if (EST == EST_DynamicNone)
EHStack.popTerminate();
return;
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/CodeGen/CGStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/Support/SaveAndRestore.h"

using namespace clang;
using namespace CodeGen;
Expand Down Expand Up @@ -608,6 +609,13 @@ void CodeGenFunction::EmitLabelStmt(const LabelStmt &S) {
}

void CodeGenFunction::EmitAttributedStmt(const AttributedStmt &S) {
bool nomerge = false;
for (const auto *A : S.getAttrs())
if (A->getKind() == attr::NoMerge) {
nomerge = true;
break;
}
SaveAndRestore<bool> save_nomerge(InNoMergeAttributedStmt, nomerge);
EmitStmt(S.getSubStmt(), S.getAttrs());
}

Expand Down
3 changes: 3 additions & 0 deletions clang/lib/CodeGen/CodeGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,9 @@ class CodeGenFunction : public CodeGenTypeCache {
/// region.
bool IsInPreservedAIRegion = false;

/// True if the current statement has nomerge attribute.
bool InNoMergeAttributedStmt = false;

const CodeGen::CGBlockInfo *BlockInfo = nullptr;
llvm::Value *BlockPointer = nullptr;

Expand Down
41 changes: 41 additions & 0 deletions clang/lib/Sema/SemaStmtAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
//===----------------------------------------------------------------------===//

#include "clang/AST/EvaluatedExprVisitor.h"
#include "clang/Sema/SemaInternal.h"
#include "clang/AST/ASTContext.h"
#include "clang/Basic/SourceManager.h"
Expand Down Expand Up @@ -170,6 +171,44 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
return LoopHintAttr::CreateImplicit(S.Context, Option, State, ValueExpr, A);
}

namespace {
class CallExprFinder : public ConstEvaluatedExprVisitor<CallExprFinder> {
bool FoundCallExpr = false;

public:
typedef ConstEvaluatedExprVisitor<CallExprFinder> Inherited;

CallExprFinder(Sema &S, const Stmt *St) : Inherited(S.Context) { Visit(St); }

bool foundCallExpr() { return FoundCallExpr; }

void VisitCallExpr(const CallExpr *E) { FoundCallExpr = true; }

void Visit(const Stmt *St) {
if (!St)
return;
ConstEvaluatedExprVisitor<CallExprFinder>::Visit(St);
}
};
} // namespace

static Attr *handleNoMergeAttr(Sema &S, Stmt *St, const ParsedAttr &A,
SourceRange Range) {
NoMergeAttr NMA(S.Context, A);
if (S.CheckAttrNoArgs(A))
return nullptr;

CallExprFinder CEF(S, St);

if (!CEF.foundCallExpr()) {
S.Diag(St->getBeginLoc(), diag::warn_nomerge_attribute_ignored_in_stmt)
<< NMA.getSpelling();
return nullptr;
}

return ::new (S.Context) NoMergeAttr(S.Context, A);
}

static void
CheckForIncompatibleAttributes(Sema &S,
const SmallVectorImpl<const Attr *> &Attrs) {
Expand Down Expand Up @@ -335,6 +374,8 @@ static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
return handleOpenCLUnrollHint(S, St, A, Range);
case ParsedAttr::AT_Suppress:
return handleSuppressAttr(S, St, A, Range);
case ParsedAttr::AT_NoMerge:
return handleNoMergeAttr(S, St, A, Range);
default:
// if we're here, then we parsed a known attribute, but didn't recognize
// it as a statement attribute => it is declaration attribute
Expand Down
26 changes: 26 additions & 0 deletions clang/test/CodeGen/attr-nomerge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %clang_cc1 -S -emit-llvm %s -triple x86_64-unknown-linux-gnu -o - | FileCheck %s

bool bar();
void f(bool, bool);

void foo(int i) {
[[clang::nomerge]] bar();
[[clang::nomerge]] (i = 4, bar());
[[clang::nomerge]] (void)(bar());
[[clang::nomerge]] f(bar(), bar());
[[clang::nomerge]] [] { bar(); bar(); }(); // nomerge only applies to the anonymous function call
[[clang::nomerge]] for (bar(); bar(); bar()) {}
bar();
}
// CHECK: call zeroext i1 @_Z3barv() #[[NOMERGEATTR:[0-9]+]]
// CHECK: call zeroext i1 @_Z3barv() #[[NOMERGEATTR]]
// CHECK: call zeroext i1 @_Z3barv() #[[NOMERGEATTR]]
// CHECK: call zeroext i1 @_Z3barv() #[[NOMERGEATTR]]
// CHECK: call zeroext i1 @_Z3barv() #[[NOMERGEATTR]]
// CHECK: call void @_Z1fbb({{.*}}) #[[NOMERGEATTR]]
// CHECK: call void @"_ZZ3fooiENK3$_0clEv"(%class.anon* %ref.tmp) #[[NOMERGEATTR]]
// CHECK: call zeroext i1 @_Z3barv() #[[NOMERGEATTR]]
// CHECK: call zeroext i1 @_Z3barv() #[[NOMERGEATTR]]
// CHECK: call zeroext i1 @_Z3barv() #[[NOMERGEATTR]]
// CHECK: call zeroext i1 @_Z3barv()
// CHECK: attributes #[[NOMERGEATTR]] = { nomerge }
11 changes: 6 additions & 5 deletions clang/test/CodeGenCXX/wasm-eh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,17 +393,18 @@ void test8() {
// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-DEFAULT
// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -Wwasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-ON
// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -fwasm-exceptions -target-feature +exception-handling -Wno-wasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-OFF
// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=NOT-WASM-EH

// Wasm ignores dynamic exception specifications with types at the moment. This
// is controlled by -Wwasm-exception-spec, which is on by default. This warning
// can be suppressed with -Wno-wasm-exception-spec.
// Checks if a warning message is correctly printed or not printed depending on
// the options.
// Wasm EH ignores dynamic exception specifications with types at the moment.
// This is controlled by -Wwasm-exception-spec, which is on by default. This
// warning can be suppressed with -Wno-wasm-exception-spec. Checks if a warning
// message is correctly printed or not printed depending on the options.
void test9() throw(int) {
}
// WARNING-DEFAULT: warning: dynamic exception specifications with types are currently ignored in wasm
// WARNING-ON: warning: dynamic exception specifications with types are currently ignored in wasm
// WARNING-OFF-NOT: warning: dynamic exception specifications with types are currently ignored in wasm
// NOT-WASM-EH-NOT: warning: dynamic exception specifications with types are currently ignored in wasm

// Wasm curremtly treats 'throw()' in the same way as 'noexept'. Check if the
// same warning message is printed as if when a 'noexcept' function throws.
Expand Down
17 changes: 17 additions & 0 deletions clang/test/Sema/attr-nomerge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %clang_cc1 -verify -fsyntax-only %s

void bar();

void foo() {
[[clang::nomerge]] bar();
[[clang::nomerge(1, 2)]] bar(); // expected-error {{'nomerge' attribute takes no arguments}}
int x;
[[clang::nomerge]] x = 10; // expected-warning {{nomerge attribute is ignored because there exists no call expression inside the statement}}

[[clang::nomerge]] label: bar(); // expected-error {{'nomerge' attribute cannot be applied to a declaration}}

}

int f();

[[clang::nomerge]] static int i = f(); // expected-error {{'nomerge' attribute cannot be applied to a declaration}}
21 changes: 21 additions & 0 deletions libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ string(TOLOWER ${LIBC_TARGET_OS} LIBC_TARGET_OS)

set(LIBC_TARGET_MACHINE ${CMAKE_SYSTEM_PROCESSOR})

# Check --print-resource-dir to find the compiler resource dir if this flag
# is supported by the compiler.
execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND ${CMAKE_CXX_COMPILER} --print-resource-dir
RESULT_VARIABLE COMMAND_RETURN_CODE
OUTPUT_VARIABLE COMPILER_RESOURCE_DIR
)
# Retrieve the host compiler's resource dir.
if(COMMAND_RETURN_CODE EQUAL 0)
set(COMPILER_RESOURCE_DIR
"${COMPILER_RESOURCE_DIR}" CACHE PATH "path to compiler resource dir"
)
message(STATUS "Set COMPILER_RESOURCE_DIR to
${COMPILER_RESOURCE_DIR} using --print-resource-dir")
else()
set(COMPILER_RESOURCE_DIR OFF)
message(STATUS "COMPILER_RESOURCE_DIR not set
--print-resource-dir not supported by host compiler")
endif()

option(LLVM_LIBC_ENABLE_LINTING "Enables linting of libc source files" ON)
if(LLVM_LIBC_ENABLE_LINTING)
if("clang-tools-extra" IN_LIST LLVM_ENABLE_PROJECTS
Expand Down
2 changes: 1 addition & 1 deletion libc/cmake/modules/LLVMLibCHeaderRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function(add_gen_header target_name)
${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td

WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${in_file} ${fq_data_files} ${td_includes}
DEPENDS ${in_file} ${fq_data_files} ${td_includes}
${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td libc-hdrgen
)

Expand Down
34 changes: 26 additions & 8 deletions libc/cmake/modules/LLVMLibCObjectRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,30 @@ function(add_entrypoint_object target_name)
)

if(LLVM_LIBC_ENABLE_LINTING)
set(lint_timestamp "${CMAKE_CURRENT_BINARY_DIR}/.${target_name}.__lint_timestamp__")

# We only want a second invocation of clang-tidy to run
# restrict-system-libc-headers if the compiler-resource-dir was set in
# order to prevent false-positives due to a mismatch between the host
# compiler and the compiled clang-tidy.
if(COMPILER_RESOURCE_DIR)
# We run restrict-system-libc-headers with --system-headers to prevent
# transitive inclusion through compler provided headers.
set(restrict_system_headers_check_invocation
COMMAND $<TARGET_FILE:clang-tidy> --system-headers
--checks="-*,llvmlibc-restrict-system-libc-headers"
# We explicitly set the resource dir here to match the
# resource dir of the host compiler.
"--extra-arg=-resource-dir=${COMPILER_RESOURCE_DIR}"
--quiet
-p ${PROJECT_BINARY_DIR}
${ADD_ENTRYPOINT_OBJ_SRCS}
)
else()
set(restrict_system_headers_check_invocation
COMMAND ${CMAKE_COMMAND} -E echo "Header file check skipped")
endif()

set(lint_timestamp "${CMAKE_CURRENT_BINARY_DIR}/.${target_name}.__lint_timestamp__")
add_custom_command(
OUTPUT ${lint_timestamp}
# --quiet is used to surpress warning statistics from clang-tidy like:
Expand All @@ -222,13 +244,9 @@ function(add_entrypoint_object target_name)
# Path to directory containing compile_commands.json
-p ${PROJECT_BINARY_DIR}
${ADD_ENTRYPOINT_OBJ_SRCS}
# We run restrict-system-libc-headers with --system-headers to prevent
# transitive inclusion through compler provided headers.
COMMAND $<TARGET_FILE:clang-tidy> --system-headers
--checks="-*,llvmlibc-restrict-system-libc-headers"
--quiet
-p ${PROJECT_BINARY_DIR}
${ADD_ENTRYPOINT_OBJ_SRCS}
# See above: this might be a second invocation of clang-tidy depending on
# the conditions above.
${restrict_system_headers_check_invocation}
# We have two options for running commands, add_custom_command and
# add_custom_target. We don't want to run the linter unless source files
# have changed. add_custom_target explicitly runs everytime therefore we
Expand Down
3 changes: 2 additions & 1 deletion lldb/include/lldb/lldb-enumerations.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ enum ExpressionResults {
eExpressionHitBreakpoint,
eExpressionTimedOut,
eExpressionResultUnavailable,
eExpressionStoppedForDebug
eExpressionStoppedForDebug,
eExpressionThreadVanished
};

enum SearchDepth {
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Expression/FunctionCaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ lldb::ExpressionResults FunctionCaller::ExecuteFunction(
if (return_value != lldb::eExpressionCompleted) {
LLDB_LOGF(log,
"== [FunctionCaller::ExecuteFunction] Execution of \"%s\" "
"completed abnormally ==",
m_name.c_str());
"completed abnormally: %s ==",
m_name.c_str(),
Process::ExecutionResultAsCString(return_value));
} else {
LLDB_LOGF(log,
"== [FunctionCaller::ExecuteFunction] Execution of \"%s\" "
Expand Down
12 changes: 12 additions & 0 deletions lldb/source/Expression/LLVMUserExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager,
return lldb::eExpressionSetupError;
}

// Store away the thread ID for error reporting, in case it exits
// during execution:
lldb::tid_t expr_thread_id = exe_ctx.GetThreadRef().GetID();

Address wrapper_address(m_jit_start_addr);

std::vector<lldb::addr_t> args;
Expand Down Expand Up @@ -223,6 +227,14 @@ LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager,
"Use \"thread return -x\" to return to the state before expression "
"evaluation.");
return execution_result;
} else if (execution_result == lldb::eExpressionThreadVanished) {
diagnostic_manager.Printf(
eDiagnosticSeverityError,
"Couldn't complete execution; the thread "
"on which the expression was being run: 0x%" PRIx64
" exited during its execution.",
expr_thread_id);
return execution_result;
} else if (execution_result != lldb::eExpressionCompleted) {
diagnostic_manager.Printf(
eDiagnosticSeverityError, "Couldn't execute function; result was %s",
Expand Down
Loading

0 comments on commit 92039d2

Please sign in to comment.