Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/MaxEW707/llvm-project into …
Browse files Browse the repository at this point in the history
…mew/intrin0-clangcl
  • Loading branch information
MaxEW707 committed Dec 24, 2023
2 parents cb7aa9a + d8ddcae commit 71c0966
Show file tree
Hide file tree
Showing 135 changed files with 1,872 additions and 1,018 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) {
if (!AlgDecl)
return;

if (Unordered && AlgDecl->getName().find("bound") != llvm::StringRef::npos)
if (Unordered && AlgDecl->getName().contains("bound"))
return;

const auto *AlgParam = Result.Nodes.getNodeAs<Expr>("AlgParam");
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/APINotes/APINotesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ APINotesManager::loadAPINotes(StringRef Buffer) {

bool APINotesManager::loadAPINotes(const DirectoryEntry *HeaderDir,
FileEntryRef APINotesFile) {
assert(Readers.find(HeaderDir) == Readers.end());
assert(!Readers.contains(HeaderDir));
if (auto Reader = loadAPINotes(APINotesFile)) {
Readers[HeaderDir] = Reader.release();
return false;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
<< PluginFN << toString(PassPlugin.takeError());
}
}
for (auto PassCallback : CodeGenOpts.PassBuilderCallbacks)
for (const auto &PassCallback : CodeGenOpts.PassBuilderCallbacks)
PassCallback(PB);
#define HANDLE_EXTENSION(Ext) \
get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Format/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_clang_library(clangFormat
IntegerLiteralSeparatorFixer.cpp
MacroCallReconstructor.cpp
MacroExpander.cpp
MatchFilePath.cpp
NamespaceEndCommentsFixer.cpp
ObjCPropertyAttributeOrderFixer.cpp
QualifierAlignmentFixer.cpp
Expand Down
20 changes: 9 additions & 11 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,17 +583,15 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
return true;
}

// If the return type spans multiple lines, wrap before the function name.
if (((Current.is(TT_FunctionDeclarationName) &&
!State.Line->ReturnTypeWrapped &&
// Don't break before a C# function when no break after return type.
(!Style.isCSharp() ||
Style.AlwaysBreakAfterReturnType != FormatStyle::RTBS_None) &&
// Don't always break between a JavaScript `function` and the function
// name.
!Style.isJavaScript()) ||
(Current.is(tok::kw_operator) && Previous.isNot(tok::coloncolon))) &&
Previous.isNot(tok::kw_template) && CurrentState.BreakBeforeParameter) {
if (Current.is(TT_FunctionDeclarationName) &&
!State.Line->ReturnTypeWrapped &&
// Don't break before a C# function when no break after return type.
(!Style.isCSharp() ||
Style.AlwaysBreakAfterReturnType != FormatStyle::RTBS_None) &&
// Don't always break between a JavaScript `function` and the function
// name.
!Style.isJavaScript() && Previous.isNot(tok::kw_template) &&
CurrentState.BreakBeforeParameter) {
return true;
}

Expand Down
122 changes: 122 additions & 0 deletions clang/lib/Format/MatchFilePath.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//===--- MatchFilePath.cpp - Match file path with pattern -------*- 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 implements the functionality of matching a file path name to
/// a pattern, similar to the POSIX fnmatch() function.
///
//===----------------------------------------------------------------------===//

#include "MatchFilePath.h"

using namespace llvm;

namespace clang {
namespace format {

// Check whether `FilePath` matches `Pattern` based on POSIX (1003.1-2008)
// 2.13.1, 2.13.2, and Rule 1 of 2.13.3.
bool matchFilePath(StringRef Pattern, StringRef FilePath) {
assert(!Pattern.empty());
assert(!FilePath.empty());

// No match if `Pattern` ends with a non-meta character not equal to the last
// character of `FilePath`.
if (const auto C = Pattern.back(); !strchr("?*]", C) && C != FilePath.back())
return false;

constexpr auto Separator = '/';
const auto EOP = Pattern.size(); // End of `Pattern`.
const auto End = FilePath.size(); // End of `FilePath`.
unsigned I = 0; // Index to `Pattern`.

for (unsigned J = 0; J < End; ++J) {
if (I == EOP)
return false;

switch (const auto F = FilePath[J]; Pattern[I]) {
case '\\':
if (++I == EOP || F != Pattern[I])
return false;
break;
case '?':
if (F == Separator)
return false;
break;
case '*': {
while (++I < EOP && Pattern[I] == '*') { // Skip consecutive stars.
}
const auto K = FilePath.find(Separator, J); // Index of next `Separator`.
const bool NoMoreSeparatorsInFilePath = K == StringRef::npos;
if (I == EOP) // `Pattern` ends with a star.
return NoMoreSeparatorsInFilePath;
// `Pattern` ends with a lone backslash.
if (Pattern[I] == '\\' && ++I == EOP)
return false;
// The star is followed by a (possibly escaped) `Separator`.
if (Pattern[I] == Separator) {
if (NoMoreSeparatorsInFilePath)
return false;
J = K; // Skip to next `Separator` in `FilePath`.
break;
}
// Recurse.
for (auto Pat = Pattern.substr(I); J < End && FilePath[J] != Separator;
++J) {
if (matchFilePath(Pat, FilePath.substr(J)))
return true;
}
return false;
}
case '[':
// Skip e.g. `[!]`.
if (I + 3 < EOP || (I + 3 == EOP && Pattern[I + 1] != '!')) {
// Skip unpaired `[`, brackets containing slashes, and `[]`.
if (const auto K = Pattern.find_first_of("]/", I + 1);
K != StringRef::npos && Pattern[K] == ']' && K > I + 1) {
if (F == Separator)
return false;
++I; // After the `[`.
bool Negated = false;
if (Pattern[I] == '!') {
Negated = true;
++I; // After the `!`.
}
bool Match = false;
do {
if (I + 2 < K && Pattern[I + 1] == '-') {
Match = Pattern[I] <= F && F <= Pattern[I + 2];
I += 3; // After the range, e.g. `A-Z`.
} else {
Match = F == Pattern[I++];
}
} while (!Match && I < K);
if (Negated ? Match : !Match)
return false;
I = K + 1; // After the `]`.
continue;
}
}
[[fallthrough]]; // Match `[` literally.
default:
if (F != Pattern[I])
return false;
}

++I;
}

// Match trailing stars with null strings.
while (I < EOP && Pattern[I] == '*')
++I;

return I == EOP;
}

} // namespace format
} // namespace clang
22 changes: 22 additions & 0 deletions clang/lib/Format/MatchFilePath.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===--- MatchFilePath.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
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_LIB_FORMAT_MATCHFILEPATH_H
#define LLVM_CLANG_LIB_FORMAT_MATCHFILEPATH_H

#include "llvm/ADT/StringRef.h"

namespace clang {
namespace format {

bool matchFilePath(llvm::StringRef Pattern, llvm::StringRef FilePath);

} // end namespace format
} // end namespace clang

#endif
3 changes: 2 additions & 1 deletion clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3403,7 +3403,8 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current,
continue;
}
if (Tok->is(tok::kw_const) || Tok->isSimpleTypeSpecifier() ||
Tok->isOneOf(TT_PointerOrReference, TT_StartOfName, tok::ellipsis)) {
Tok->isOneOf(TT_PointerOrReference, TT_StartOfName, tok::ellipsis,
TT_TypeName)) {
return true;
}
if (Tok->isOneOf(tok::l_brace, TT_ObjCMethodExpr) || Tok->Tok.isLiteral())
Expand Down
24 changes: 20 additions & 4 deletions clang/lib/Headers/riscv_bitmanip.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ __riscv_ctz_32(uint32_t __x) {

static __inline__ unsigned __attribute__((__always_inline__, __nodebug__))
__riscv_cpop_32(uint32_t __x) {
return __builtin_riscv_cpop_32(__x);
return __builtin_popcount(__x);
}

#if __riscv_xlen == 64
Expand All @@ -55,7 +55,7 @@ __riscv_ctz_64(uint64_t __x) {

static __inline__ unsigned __attribute__((__always_inline__, __nodebug__))
__riscv_cpop_64(uint64_t __x) {
return __builtin_riscv_cpop_64(__x);
return __builtin_popcountll(__x);
}
#endif
#endif // defined(__riscv_zbb)
Expand Down Expand Up @@ -120,7 +120,23 @@ __riscv_zip_32(uint32_t __x) {
#endif
#endif // defined(__riscv_zbkb)

#if defined(__riscv_zbkc)
#if defined(__riscv_zbc)
#if __riscv_xlen == 32
static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
__riscv_clmulr_32(uint32_t __x, uint32_t __y) {
return __builtin_riscv_clmulr_32(__x, __y);
}
#endif

#if __riscv_xlen == 64
static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
__riscv_clmulr_64(uint64_t __x, uint64_t __y) {
return __builtin_riscv_clmulr_64(__x, __y);
}
#endif
#endif // defined(__riscv_zbc)

#if defined(__riscv_zbkc) || defined(__riscv_zbc)
static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
__riscv_clmul_32(uint32_t __x, uint32_t __y) {
return __builtin_riscv_clmul_32(__x, __y);
Expand All @@ -144,7 +160,7 @@ __riscv_clmulh_64(uint64_t __x, uint64_t __y) {
return __builtin_riscv_clmulh_64(__x, __y);
}
#endif
#endif // defined(__riscv_zbkc)
#endif // defined(__riscv_zbkc) || defined(__riscv_zbc)

#if defined(__riscv_zbkx)
#if __riscv_xlen == 32
Expand Down
8 changes: 0 additions & 8 deletions clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5512,14 +5512,6 @@ static void TryOrBuildParenListInitialization(
} else if (auto *RT = Entity.getType()->getAs<RecordType>()) {
bool IsUnion = RT->isUnionType();
const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
if (RD->isInvalidDecl()) {
// Exit early to avoid confusion when processing members.
// We do the same for braced list initialization in
// `CheckStructUnionTypes`.
Sequence.SetFailed(
clang::InitializationSequence::FK_ParenthesizedListInitFailed);
return;
}

if (!IsUnion) {
for (const CXXBaseSpecifier &Base : RD->bases()) {
Expand Down
60 changes: 44 additions & 16 deletions clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// RUN: -disable-O0-optnone | opt -S -passes=mem2reg \
// RUN: | FileCheck %s -check-prefix=RV64ZBB

#include <riscv_bitmanip.h>

// RV32ZBB-LABEL: @orc_b_32(
// RV32ZBB-NEXT: entry:
// RV32ZBB-NEXT: [[TMP0:%.*]] = call i32 @llvm.riscv.orc.b.i32(i32 [[A:%.*]])
Expand All @@ -16,8 +18,8 @@
// RV64ZBB-NEXT: [[TMP0:%.*]] = call i32 @llvm.riscv.orc.b.i32(i32 [[A:%.*]])
// RV64ZBB-NEXT: ret i32 [[TMP0]]
//
unsigned int orc_b_32(unsigned int a) {
return __builtin_riscv_orc_b_32(a);
uint32_t orc_b_32(uint32_t a) {
return __riscv_orc_b_32(a);
}

#if __riscv_xlen == 64
Expand All @@ -26,8 +28,8 @@ unsigned int orc_b_32(unsigned int a) {
// RV64ZBB-NEXT: [[TMP0:%.*]] = call i64 @llvm.riscv.orc.b.i64(i64 [[A:%.*]])
// RV64ZBB-NEXT: ret i64 [[TMP0]]
//
unsigned long orc_b_64(unsigned long a) {
return __builtin_riscv_orc_b_64(a);
uint64_t orc_b_64(uint64_t a) {
return __riscv_orc_b_64(a);
}
#endif

Expand All @@ -41,19 +43,19 @@ unsigned long orc_b_64(unsigned long a) {
// RV64ZBB-NEXT: [[TMP0:%.*]] = call i32 @llvm.ctlz.i32(i32 [[A:%.*]], i1 false)
// RV64ZBB-NEXT: ret i32 [[TMP0]]
//
unsigned int clz_32(unsigned int a) {
return __builtin_riscv_clz_32(a);
unsigned int clz_32(uint32_t a) {
return __riscv_clz_32(a);
}

#if __riscv_xlen == 64
// RV64ZBB-LABEL: @clz_64(
// RV64ZBB-NEXT: entry:
// RV64ZBB-NEXT: [[TMP0:%.*]] = call i64 @llvm.ctlz.i64(i64 [[A:%.*]], i1 false)
// RV64ZBB-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i32
// RV64ZBB-NEXT: ret i32 [[CAST]]
// RV64ZBB-NEXT: [[CAST_I:%.*]] = trunc i64 [[TMP0]] to i32
// RV64ZBB-NEXT: ret i32 [[CAST_I]]
//
unsigned int clz_64(unsigned long a) {
return __builtin_riscv_clz_64(a);
unsigned int clz_64(uint64_t a) {
return __riscv_clz_64(a);
}
#endif

Expand All @@ -67,18 +69,44 @@ unsigned int clz_64(unsigned long a) {
// RV64ZBB-NEXT: [[TMP0:%.*]] = call i32 @llvm.cttz.i32(i32 [[A:%.*]], i1 false)
// RV64ZBB-NEXT: ret i32 [[TMP0]]
//
unsigned int ctz_32(unsigned int a) {
return __builtin_riscv_ctz_32(a);
unsigned int ctz_32(uint32_t a) {
return __riscv_ctz_32(a);
}

#if __riscv_xlen == 64
// RV64ZBB-LABEL: @ctz_64(
// RV64ZBB-NEXT: entry:
// RV64ZBB-NEXT: [[TMP0:%.*]] = call i64 @llvm.cttz.i64(i64 [[A:%.*]], i1 false)
// RV64ZBB-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i32
// RV64ZBB-NEXT: ret i32 [[CAST]]
// RV64ZBB-NEXT: [[CAST_I:%.*]] = trunc i64 [[TMP0]] to i32
// RV64ZBB-NEXT: ret i32 [[CAST_I]]
//
unsigned int ctz_64(uint64_t a) {
return __riscv_ctz_64(a);
}
#endif

// RV32ZBB-LABEL: @cpop_32(
// RV32ZBB-NEXT: entry:
// RV32ZBB-NEXT: [[TMP0:%.*]] = call i32 @llvm.ctpop.i32(i32 [[A:%.*]])
// RV32ZBB-NEXT: ret i32 [[TMP0]]
//
// RV64ZBB-LABEL: @cpop_32(
// RV64ZBB-NEXT: entry:
// RV64ZBB-NEXT: [[TMP0:%.*]] = call i32 @llvm.ctpop.i32(i32 [[A:%.*]])
// RV64ZBB-NEXT: ret i32 [[TMP0]]
//
unsigned int cpop_32(uint32_t a) {
return __riscv_cpop_32(a);
}

#if __riscv_xlen == 64
// RV64ZBB-LABEL: @cpop_64(
// RV64ZBB-NEXT: entry:
// RV64ZBB-NEXT: [[TMP0:%.*]] = call i64 @llvm.ctpop.i64(i64 [[A:%.*]])
// RV64ZBB-NEXT: [[CAST_I:%.*]] = trunc i64 [[TMP0]] to i32
// RV64ZBB-NEXT: ret i32 [[CAST_I]]
//
unsigned int ctz_64(unsigned long a) {
return __builtin_riscv_ctz_64(a);
unsigned int cpop_64(uint64_t a) {
return __riscv_cpop_64(a);
}
#endif
Loading

0 comments on commit 71c0966

Please sign in to comment.