Skip to content

Commit

Permalink
merge main into amd-staging (llvm#842)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronlieb authored Feb 26, 2025
2 parents f876d2b + a52579f commit 345a308
Show file tree
Hide file tree
Showing 216 changed files with 6,884 additions and 4,892 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ jobs:
# 2-3 hours to build on macOS, much slower than on Linux.
# The long build time causes the release build to time out on x86_64,
# so we need to disable flang there.
target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_PROJECTS='clang;lld;lldb;clang-tools-extra;bolt;polly;mlir'"
target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_PROJECTS='clang;lld;lldb;clang-tools-extra;polly;mlir'"
fi
target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_ARCHS=$arches -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_BUILTIN_ARCHS=$arches"
fi
Expand Down
5 changes: 3 additions & 2 deletions bolt/lib/Core/BinaryFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "bolt/Core/DynoStats.h"
#include "bolt/Core/HashUtilities.h"
#include "bolt/Core/MCPlusBuilder.h"
#include "bolt/Utils/CommandLineOpts.h"
#include "bolt/Utils/NameResolver.h"
#include "bolt/Utils/NameShortener.h"
#include "bolt/Utils/Utils.h"
Expand Down Expand Up @@ -1753,8 +1754,8 @@ void BinaryFunction::postProcessEntryPoints() {
// In non-relocation mode there's potentially an external undetectable
// reference to the entry point and hence we cannot move this entry
// point. Optimizing without moving could be difficult.
// In BAT mode, register any known entry points for CFG construction.
if (!BC.HasRelocations && !BC.HasBATSection)
// In aggregation, register any known entry points for CFG construction.
if (!BC.HasRelocations && !opts::AggregateOnly)
setSimple(false);

const uint32_t Offset = KV.first;
Expand Down
5 changes: 3 additions & 2 deletions bolt/lib/Profile/DataAggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,10 @@ bool DataAggregator::doTrace(const LBREntry &First, const LBREntry &Second,
ParentFunc = FromFunc;
ParentFunc->SampleCountInBytes += Count * (Second.From - First.To);

const uint64_t FuncAddress = FromFunc->getAddress();
std::optional<BoltAddressTranslation::FallthroughListTy> FTs =
BAT ? BAT->getFallthroughsInTrace(FromFunc->getAddress(), First.To,
Second.From)
BAT && BAT->isBATFunction(FuncAddress)
? BAT->getFallthroughsInTrace(FuncAddress, First.To, Second.From)
: getFallthroughsInTrace(*FromFunc, First, Second, Count);
if (!FTs) {
LLVM_DEBUG(
Expand Down
5 changes: 5 additions & 0 deletions bolt/test/X86/bolt-address-translation-yaml.test
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ YAML-BAT-CHECK-NEXT: - bid: 0
YAML-BAT-CHECK-NEXT: insns: 26
YAML-BAT-CHECK-NEXT: hash: 0xA900AE79CFD40000
YAML-BAT-CHECK-NEXT: succ: [ { bid: 3, cnt: 0 }, { bid: 1, cnt: 0 } ]
# Check fallthroughs in non-BAT function
YAML-BAT-CHECK-NEXT: - bid: 27
YAML-BAT-CHECK-NEXT: insns: 3
YAML-BAT-CHECK-NEXT: hash: 0x30A1EBA77A903F0
YAML-BAT-CHECK-NEXT: succ: [ { bid: 28, cnt: 1 } ]
# Calls from no-BAT to BAT function
YAML-BAT-CHECK: - bid: 28
YAML-BAT-CHECK-NEXT: insns: 13
Expand Down
24 changes: 24 additions & 0 deletions bolt/test/X86/entry-point-fallthru.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Checks that fallthroughs spanning entry points are accepted in aggregation
## mode.

# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
# RUN: ld.lld %t.o -o %t
# RUN: link_fdata %s %t %t.preagg PREAGG
# RUN: perf2bolt %t -p %t.preagg --pa -o %t.fdata | FileCheck %s
# CHECK: traces mismatching disassembled function contents: 0

.globl main
main:
.cfi_startproc
vmovaps %zmm31,%zmm3

next:
add $0x4,%r9
add $0x40,%r10
dec %r14
Ljmp:
jne main
# PREAGG: T #Ljmp# #main# #Ljmp# 1
ret
.cfi_endproc
.size main,.-main
1 change: 1 addition & 0 deletions clang/Maintainers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Clang static analyzer
| Balázs Benics
| benicsbalazs\@gmail.com (email), steakhal (Phabricator), steakhal (GitHub)
| balazs.benics\@sonarsource.com (email), balazs-benics-sonarsource (GitHub)
Compiler options
~~~~~~~~~~~~~~~~
Expand Down
17 changes: 16 additions & 1 deletion clang/cmake/caches/Release.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ endfunction()
# cache file to CMake via -C. e.g.
#
# cmake -D LLVM_RELEASE_ENABLE_PGO=ON -C Release.cmake

set (DEFAULT_PROJECTS "clang;lld;lldb;clang-tools-extra;polly;mlir;flang")
# bolt only supports ELF, so only enable it for Linux.
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
list(APPEND DEFAULT_PROJECTS "bolt")
endif()

set (DEFAULT_RUNTIMES "compiler-rt;libcxx")
if (NOT WIN32)
list(APPEND DEFAULT_RUNTIMES "libcxxabi" "libunwind")
endif()
set(LLVM_RELEASE_ENABLE_LTO THIN CACHE STRING "")
set(LLVM_RELEASE_ENABLE_PGO ON CACHE BOOL "")
set(LLVM_RELEASE_ENABLE_RUNTIMES ${DEFAULT_RUNTIMES} CACHE STRING "")
set(LLVM_RELEASE_ENABLE_PROJECTS "clang;lld;lldb;clang-tools-extra;bolt;polly;mlir;flang" CACHE STRING "")
set(LLVM_RELEASE_ENABLE_PROJECTS ${DEFAULT_PROJECTS} CACHE STRING "")
# Note we don't need to add install here, since it is one of the pre-defined
# steps.
set(LLVM_RELEASE_FINAL_STAGE_TARGETS "clang;package;check-all;check-llvm;check-clang" CACHE STRING "")
Expand Down Expand Up @@ -118,13 +125,21 @@ if(NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -static-libgcc")
endif()

# Set flags for bolt
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -Wl,--emit-relocs,-znow")
endif()

set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)
set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)
set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)

# Final Stage Config (stage2)
set_final_stage_var(LLVM_ENABLE_RUNTIMES "${LLVM_RELEASE_ENABLE_RUNTIMES}" STRING)
set_final_stage_var(LLVM_ENABLE_PROJECTS "${LLVM_RELEASE_ENABLE_PROJECTS}" STRING)
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
set_final_stage_var(CLANG_BOLT "INSTRUMENT" STRING)
endif()
set_final_stage_var(CPACK_GENERATOR "TXZ" STRING)
set_final_stage_var(CPACK_ARCHIVE_THREADS "0" STRING)

Expand Down
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ Removed Compiler Flags

Attribute Changes in Clang
--------------------------
Adding [[clang::unsafe_buffer_usage]] attribute to a method definition now turns off all -Wunsafe-buffer-usage
related warnings within the method body.

- The ``no_sanitize`` attribute now accepts both ``gnu`` and ``clang`` names.
- Clang now diagnoses use of declaration attributes on void parameters. (#GH108819)
Expand Down
14 changes: 14 additions & 0 deletions clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#define LLVM_CLANG_CIR_DIALECT_BUILDER_CIRBASEBUILDER_H

#include "clang/CIR/Dialect/IR/CIRAttrs.h"
#include "clang/CIR/Dialect/IR/CIRDialect.h"
#include "clang/CIR/Dialect/IR/CIRTypes.h"

#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinTypes.h"
Expand All @@ -23,6 +25,14 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
CIRBaseBuilderTy(mlir::MLIRContext &mlirContext)
: mlir::OpBuilder(&mlirContext) {}

cir::ConstantOp getBool(bool state, mlir::Location loc) {
return create<cir::ConstantOp>(loc, getBoolTy(), getCIRBoolAttr(state));
}
cir::ConstantOp getFalse(mlir::Location loc) { return getBool(false, loc); }
cir::ConstantOp getTrue(mlir::Location loc) { return getBool(true, loc); }

cir::BoolType getBoolTy() { return cir::BoolType::get(getContext()); }

cir::PointerType getPointerTo(mlir::Type ty) {
return cir::PointerType::get(getContext(), ty);
}
Expand All @@ -31,6 +41,10 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
return getPointerTo(cir::VoidType::get(getContext()));
}

cir::BoolAttr getCIRBoolAttr(bool state) {
return cir::BoolAttr::get(getContext(), getBoolTy(), state);
}

mlir::TypedAttr getConstPtrAttr(mlir::Type type, int64_t value) {
auto valueAttr = mlir::IntegerAttr::get(
mlir::IntegerType::get(type.getContext(), 64), value);
Expand Down
19 changes: 19 additions & 0 deletions clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ class CIRUnitAttr<string name, string attrMnemonic, list<Trait> traits = []>
let isOptional = 1;
}

//===----------------------------------------------------------------------===//
// BoolAttr
//===----------------------------------------------------------------------===//

def CIR_BoolAttr : CIR_Attr<"Bool", "bool", [TypedAttrInterface]> {
let summary = "Represent true/false for !cir.bool types";
let description = [{
The BoolAttr represents a 'true' or 'false' value.
}];

let parameters = (ins AttributeSelfTypeParameter<
"", "cir::BoolType">:$type,
"bool":$value);

let assemblyFormat = [{
`<` $value `>`
}];
}

//===----------------------------------------------------------------------===//
// IntegerAttr
//===----------------------------------------------------------------------===//
Expand Down
17 changes: 16 additions & 1 deletion clang/include/clang/CIR/Dialect/IR/CIRTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,20 @@ def CIR_PointerType : CIR_Type<"Pointer", "ptr",
}];
}

//===----------------------------------------------------------------------===//
// BoolType
//===----------------------------------------------------------------------===//

def CIR_BoolType :
CIR_Type<"Bool", "bool",
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {

let summary = "CIR bool type";
let description = [{
`cir.bool` represents C++ bool type.
}];
}

//===----------------------------------------------------------------------===//
// FuncType
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -355,7 +369,8 @@ def VoidPtr : Type<
//===----------------------------------------------------------------------===//

def CIR_AnyType : AnyTypeOf<[
CIR_VoidType, CIR_IntType, CIR_AnyFloat, CIR_PointerType, CIR_FuncType
CIR_VoidType, CIR_BoolType, CIR_IntType, CIR_AnyFloat, CIR_PointerType,
CIR_FuncType
]>;

#endif // MLIR_CIR_DIALECT_CIR_TYPES
2 changes: 2 additions & 0 deletions clang/lib/Basic/Targets/SPIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ class LLVM_LIBRARY_VISIBILITY SPIRV64AMDGCNTargetInfo final
HasLegalHalfType = true;
HasFloat16 = true;
HalfArgsAndReturns = true;

MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
}

bool hasBFloat16Type() const override { return true; }
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
cgf.getLoc(e->getExprLoc()), type,
builder.getAttr<cir::IntAttr>(type, e->getValue()));
}

mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
mlir::Type type = cgf.convertType(e->getType());
return builder.create<cir::ConstantOp>(
cgf.getLoc(e->getExprLoc()), type,
builder.getCIRBoolAttr(e->getValue()));
}
};
} // namespace

Expand Down
6 changes: 5 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd,
if (APValue *value = initDecl->evaluateValue()) {
switch (value->getKind()) {
case APValue::Int: {
initializer = builder.getAttr<cir::IntAttr>(type, value->getInt());
if (mlir::isa<cir::BoolType>(type))
initializer =
builder.getCIRBoolAttr(value->getInt().getZExtValue());
else
initializer = builder.getAttr<cir::IntAttr>(type, value->getInt());
break;
}
case APValue::Float: {
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
resultType = cgm.VoidTy;
break;

// bool
case BuiltinType::Bool:
resultType = cir::BoolType::get(&getMLIRContext());
break;

// Signed integral types.
case BuiltinType::Char_S:
case BuiltinType::Int:
Expand Down
25 changes: 25 additions & 0 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ using namespace cir;
//===----------------------------------------------------------------------===//
// CIR Dialect
//===----------------------------------------------------------------------===//
namespace {
struct CIROpAsmDialectInterface : public OpAsmDialectInterface {
using OpAsmDialectInterface::OpAsmDialectInterface;

AliasResult getAlias(Type type, raw_ostream &os) const final {
return AliasResult::NoAlias;
}

AliasResult getAlias(Attribute attr, raw_ostream &os) const final {
if (auto boolAttr = mlir::dyn_cast<cir::BoolAttr>(attr)) {
os << (boolAttr.getValue() ? "true" : "false");
return AliasResult::FinalAlias;
}
return AliasResult::NoAlias;
}
};
} // namespace

void cir::CIRDialect::initialize() {
registerTypes();
Expand All @@ -33,6 +50,7 @@ void cir::CIRDialect::initialize() {
#define GET_OP_LIST
#include "clang/CIR/Dialect/IR/CIROps.cpp.inc"
>();
addInterfaces<CIROpAsmDialectInterface>();
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -112,6 +130,13 @@ static LogicalResult checkConstantTypes(mlir::Operation *op, mlir::Type opType,
return success();
}

if (mlir::isa<cir::BoolAttr>(attrType)) {
if (!mlir::isa<cir::BoolType>(opType))
return op->emitOpError("result type (")
<< opType << ") must be '!cir.bool' for '" << attrType << "'";
return success();
}

if (mlir::isa<cir::IntAttr, cir::FPAttr>(attrType)) {
auto at = cast<TypedAttr>(attrType);
if (at.getType() != opType) {
Expand Down
22 changes: 22 additions & 0 deletions clang/lib/CIR/Dialect/IR/CIRTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,28 @@ llvm::ArrayRef<mlir::Type> FuncType::getReturnTypes() const {

bool FuncType::isVoid() const { return mlir::isa<VoidType>(getReturnType()); }

//===----------------------------------------------------------------------===//
// BoolType
//===----------------------------------------------------------------------===//

llvm::TypeSize
BoolType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
return llvm::TypeSize::getFixed(8);
}

uint64_t
BoolType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
return 1;
}

uint64_t
BoolType::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
return 1;
}

//===----------------------------------------------------------------------===//
// PointerType Definitions
//===----------------------------------------------------------------------===//
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Sema/AnalysisBasedWarnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2566,6 +2566,9 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(

// The Callback function that performs analyses:
auto CallAnalyzers = [&](const Decl *Node) -> void {
if (Node->hasAttr<UnsafeBufferUsageAttr>())
return;

// Perform unsafe buffer usage analysis:
if (!Diags.isIgnored(diag::warn_unsafe_buffer_operation,
Node->getBeginLoc()) ||
Expand Down
9 changes: 5 additions & 4 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7390,10 +7390,11 @@ bool DecomposePrintfHandler::GetSpecifiers(
const char *Str = Data.data();
llvm::SmallBitVector BV;
UncoveredArgHandler UA;
const Expr *PrintfArgs[] = {FSL->getFormatString()};
DecomposePrintfHandler H(S, FSL, FSL->getFormatString(), Type, 0, 0, IsObjC,
Str, Sema::FAPK_Elsewhere, {FSL->getFormatString()},
0, InFunctionCall, Sema::VariadicDoesNotApply, BV,
UA, Args);
Str, Sema::FAPK_Elsewhere, PrintfArgs, 0,
InFunctionCall, Sema::VariadicDoesNotApply, BV, UA,
Args);

if (!analyze_format_string::ParsePrintfString(
H, Str, Str + Data.size(), S.getLangOpts(), S.Context.getTargetInfo(),
Expand All @@ -7402,7 +7403,7 @@ bool DecomposePrintfHandler::GetSpecifiers(
if (H.HadError)
return false;

std::sort(
std::stable_sort(
Args.begin(), Args.end(),
[](const EquatableFormatArgument &A, const EquatableFormatArgument &B) {
return A.getPosition() < B.getPosition();
Expand Down
6 changes: 6 additions & 0 deletions clang/test/CIR/func-simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ unsigned long long ullfunc() { return 42ull; }
// CHECK: %0 = cir.const #cir.int<42> : !cir.int<u, 64>
// CHECK: cir.return %0 : !cir.int<u, 64>
// CHECK: }

bool boolfunc() { return true; }
// CHECK: cir.func @boolfunc() -> !cir.bool {
// CHECK: %0 = cir.const #true
// CHECK: cir.return %0 : !cir.bool
// CHECK: }
Loading

0 comments on commit 345a308

Please sign in to comment.