Skip to content

Commit

Permalink
Merged main:7dc3575ef2dc into amd-gfx:b2004a9a0490
Browse files Browse the repository at this point in the history
Local branch amd-gfx b2004a9 Merged main:214387c2c694 into amd-gfx:47fd8032da63
Remote branch main 7dc3575 [llvm] Remove redundant return and continue statements (NFC)
  • Loading branch information
Sw authored and Sw committed Jan 15, 2021
2 parents b2004a9 + 7dc3575 commit 33090e8
Show file tree
Hide file tree
Showing 58 changed files with 301 additions and 88 deletions.
10 changes: 6 additions & 4 deletions clang/include/clang/Tooling/Transformer/RewriteRule.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,12 @@ ASTEdit addInclude(RangeSelector Target, StringRef Header,
IncludeFormat Format = IncludeFormat::Quoted);

/// Adds an include directive for the given header to the file associated with
/// `RootID`.
/// `RootID`. If `RootID` matches inside a macro expansion, will add the
/// directive to the file in which the macro was expanded (as opposed to the
/// file in which the macro is defined).
inline ASTEdit addInclude(StringRef Header,
IncludeFormat Format = IncludeFormat::Quoted) {
return addInclude(node(RootID), Header, Format);
return addInclude(expansion(node(RootID)), Header, Format);
}

// FIXME: If `Metadata` returns an `llvm::Expected<T>` the `AnyGenerator` will
Expand Down Expand Up @@ -312,8 +314,8 @@ inline RewriteRule makeRule(ast_matchers::internal::DynTypedMatcher M,
/// \code
/// auto R = makeRule(callExpr(callee(functionDecl(hasName("foo")))),
/// changeTo(cat("bar()")));
/// AddInclude(R, "path/to/bar_header.h");
/// AddInclude(R, "vector", IncludeFormat::Angled);
/// addInclude(R, "path/to/bar_header.h");
/// addInclude(R, "vector", IncludeFormat::Angled);
/// \endcode
void addInclude(RewriteRule &Rule, llvm::StringRef Header,
IncludeFormat Format = IncludeFormat::Quoted);
Expand Down
7 changes: 6 additions & 1 deletion clang/lib/Tooling/Transformer/RewriteRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ translateEdits(const MatchResult &Result, ArrayRef<ASTEdit> ASTEdits) {
llvm::Optional<CharSourceRange> EditRange =
tooling::getRangeForEdit(*Range, *Result.Context);
// FIXME: let user specify whether to treat this case as an error or ignore
// it as is currently done.
// it as is currently done. This behavior is problematic in that it hides
// failures from bad ranges. Also, the behavior here differs from
// `flatten`. Here, we abort (without error), whereas flatten, if it hits an
// empty list, does not abort. As a result, `editList({A,B})` is not
// equivalent to `flatten(edit(A), edit(B))`. The former will abort if `A`
// produces a bad range, whereas the latter will simply ignore A.
if (!EditRange)
return SmallVector<Edit, 0>();
auto Replacement = E.Replacement->eval(Result);
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.memchr
libc.src.string.memcmp
libc.src.string.memcpy
libc.src.string.memmove
libc.src.string.memset
libc.src.string.memrchr
libc.src.string.strcat
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.memchr
libc.src.string.memcmp
libc.src.string.memcpy
libc.src.string.memmove
libc.src.string.memrchr
libc.src.string.memset
libc.src.string.strcat
Expand Down
12 changes: 12 additions & 0 deletions libc/src/string/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ add_entrypoint_object(
memcmp.h
)

add_entrypoint_object(
memmove
SRCS
memmove.cpp
HDRS
memmove.h
DEPENDS
libc.include.unistd
libc.src.stdlib.abs_utils
libc.src.string.memcpy
)

add_entrypoint_object(
strchr
SRCS
Expand Down
61 changes: 61 additions & 0 deletions libc/src/string/memmove.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//===-- Implementation of memmove -----------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "src/string/memmove.h"
#include "src/__support/common.h"
#include "src/stdlib/abs_utils.h"
#include "src/string/memcpy.h"
#include <stddef.h> // size_t, ptrdiff_t
#include <unistd.h> // ssize_t

namespace __llvm_libc {

// src_m and dest_m might be the beginning or end.
static inline void move_byte(unsigned char *dest_m, const unsigned char *src_m,
size_t count, ssize_t direction) {
for (ssize_t offset = 0; count; --count, offset += direction)
dest_m[offset] = src_m[offset];
}

LLVM_LIBC_FUNCTION(void *, memmove,
(void *dest, const void *src, size_t count)) {
unsigned char *dest_c = reinterpret_cast<unsigned char *>(dest);
const unsigned char *src_c = reinterpret_cast<const unsigned char *>(src);

// If the distance between src_c and dest_c is equal to or greater
// than count (integer_abs(src_c - dest_c) >= count), they would not overlap.
// e.g. greater equal overlapping
// [12345678] [12345678] [12345678]
// src_c: [_ab_____] [_ab_____] [_ab_____]
// dest_c:[_____yz_] [___yz___] [__yz____]

// Use memcpy if src_c and dest_c do not overlap.
if (__llvm_libc::integer_abs(src_c - dest_c) >= static_cast<ptrdiff_t>(count))
return __llvm_libc::memcpy(dest_c, src_c, count);

// Overlap cases.
// If dest_c starts before src_c (dest_c < src_c), copy forward(pointer add 1)
// from beginning to end.
// If dest_c starts after src_c (dest_c > src_c), copy backward(pointer add
// -1) from end to beginning.
// If dest_c and src_c start at the same address (dest_c == src_c),
// just return dest.
// e.g. forward backward
// *--> <--*
// src_c : [___abcde_] [_abcde___]
// dest_c: [_abc--___] [___--cde_]

// TODO: Optimize `move_byte(...)` function.
if (dest_c < src_c)
move_byte(dest_c, src_c, count, /*pointer add*/ 1);
if (dest_c > src_c)
move_byte(dest_c + count - 1, src_c + count - 1, count, /*pointer add*/ -1);
return dest;
}

} // namespace __llvm_libc
20 changes: 20 additions & 0 deletions libc/src/string/memmove.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for memmove -----------------------*- 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_LIBC_SRC_STRING_MEMMOVE_H
#define LLVM_LIBC_SRC_STRING_MEMMOVE_H

#include <stddef.h> // size_t

namespace __llvm_libc {

void *memmove(void *dest, const void *src, size_t count);

} // namespace __llvm_libc

#endif // LLVM_LIBC_SRC_STRING_MEMMOVE_H
11 changes: 11 additions & 0 deletions libc/test/src/string/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ add_libc_unittest(
libc.src.string.memcmp
)

add_libc_unittest(
memmove_test
SUITE
libc_string_unittests
SRCS
memmove_test.cpp
DEPENDS
libc.src.string.memcmp
libc.src.string.memmove
)

add_libc_unittest(
strchr_test
SUITE
Expand Down
70 changes: 70 additions & 0 deletions libc/test/src/string/memmove_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//===-- Unittests for memmove ---------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "src/string/memcmp.h"
#include "src/string/memmove.h"
#include "utils/CPP/ArrayRef.h"
#include "utils/UnitTest/Test.h"

class MemmoveTest : public __llvm_libc::testing::Test {
public:
void check_memmove(void *dest, const void *src, size_t count, const void *str,
const __llvm_libc::cpp::ArrayRef<unsigned char> expected) {
void *result = __llvm_libc::memmove(dest, src, count);
// Making sure the pointer returned is same with dest.
EXPECT_EQ(result, dest);
// expected is designed according to str.
// dest and src might be part of str.
// Making sure the str is same with expected.
EXPECT_EQ(__llvm_libc::memcmp(str, expected.data(), expected.size()), 0);
}
};

TEST_F(MemmoveTest, MoveZeroByte) {
unsigned char dest[] = {'a', 'b'};
const unsigned char src[] = {'y', 'z'};
const unsigned char expected[] = {'a', 'b'};
check_memmove(dest, src, 0, dest, expected);
}

TEST_F(MemmoveTest, OverlapThatDestAndSrcPointToSameAddress) {
unsigned char str[] = {'a', 'b'};
const unsigned char expected[] = {'a', 'b'};
check_memmove(str, str, 1, str, expected);
}

TEST_F(MemmoveTest, OverlapThatDestStartsBeforeSrc) {
// Set boundary at beginning and end for not overstepping when
// copy forward or backward.
unsigned char str[] = {'z', 'a', 'b', 'c', 'z'};
const unsigned char expected[] = {'z', 'b', 'c', 'c', 'z'};
// dest is &str[1].
check_memmove(&str[1], &str[2], 2, str, expected);
}

TEST_F(MemmoveTest, OverlapThatDestStartsAfterSrc) {
unsigned char str[] = {'z', 'a', 'b', 'c', 'z'};
const unsigned char expected[] = {'z', 'a', 'a', 'b', 'z'};
check_memmove(&str[2], &str[1], 2, str, expected);
}

// e.g. dest follow src.
// str: [abcdefghij]
// [__src_____]
// [_____dest_]
TEST_F(MemmoveTest, SrcFollowDest) {
unsigned char str[] = {'z', 'a', 'b', 'z'};
const unsigned char expected[] = {'z', 'b', 'b', 'z'};
check_memmove(&str[1], &str[2], 1, str, expected);
}

TEST_F(MemmoveTest, DestFollowSrc) {
unsigned char str[] = {'z', 'a', 'b', 'z'};
const unsigned char expected[] = {'z', 'a', 'a', 'z'};
check_memmove(&str[2], &str[1], 1, str, expected);
}
1 change: 0 additions & 1 deletion llvm/include/llvm/CodeGen/LiveRegUnits.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class LiveRegUnits {
UsedRegUnits.addReg(Reg);
}
}
return;
}

/// Initialize and clear the set.
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Config/llvm-config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/* Indicate that this is LLVM compiled from the amd-gfx branch. */
#define LLVM_HAVE_BRANCH_AMD_GFX
#define LLVM_MAIN_REVISION 377082
#define LLVM_MAIN_REVISION 377088

/* Define if LLVM_ENABLE_DUMP is enabled */
#cmakedefine LLVM_ENABLE_DUMP
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/LazyCallGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ LazyCallGraph::RefSCC::switchInternalEdgeToRef(Node &SourceN, Node &TargetN) {
PendingSCCStack.clear();
while (!DFSStack.empty())
OldSCC.Nodes.push_back(DFSStack.pop_back_val().first);
for (Node &N : make_range(OldSCC.begin() + OldSize, OldSCC.end())) {
for (Node &N : drop_begin(OldSCC, OldSize)) {
N.DFSNumber = N.LowLink = -1;
G->SCCMap[&N] = &OldSCC;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static void addVCallToSet(DevirtCallSite Call, GlobalValue::GUID Guid,
SetVector<FunctionSummary::ConstVCall> &ConstVCalls) {
std::vector<uint64_t> Args;
// Start from the second argument to skip the "this" pointer.
for (auto &Arg : make_range(Call.CB.arg_begin() + 1, Call.CB.arg_end())) {
for (auto &Arg : drop_begin(Call.CB.args(), 1)) {
auto *CI = dyn_cast<ConstantInt>(Arg);
if (!CI || CI->getBitWidth() > 64) {
VCalls.insert({Guid, Call.Offset});
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Analysis/VFABIDemangling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ bool verifyAllVectorsHaveSameWidth(FunctionType *Signature) {

assert(VecTys.size() > 1 && "Invalid number of elements.");
const ElementCount EC = VecTys[0]->getElementCount();
return llvm::all_of(
llvm::make_range(VecTys.begin() + 1, VecTys.end()),
[&EC](VectorType *VTy) { return (EC == VTy->getElementCount()); });
return llvm::all_of(llvm::drop_begin(VecTys, 1), [&EC](VectorType *VTy) {
return (EC == VTy->getElementCount());
});
}

#endif // NDEBUG
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void DbgValueHistoryMap::trimLocationRanges(
if (ReferenceCount[i] <= 0 && HistoryMapEntries[i].isClobber())
ToRemove.push_back(i);

std::sort(ToRemove.begin(), ToRemove.end());
llvm::sort(ToRemove);

// Build an offset map so we can update the EndIndex of the remaining
// entries.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/CodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ bool CodeGenPrepare::eliminateFallThrough(Function &F) {
// Use a temporary array to avoid iterator being invalidated when
// deleting blocks.
SmallVector<WeakTrackingVH, 16> Blocks;
for (auto &Block : llvm::make_range(std::next(F.begin()), F.end()))
for (auto &Block : llvm::drop_begin(F, 1))
Blocks.push_back(&Block);

SmallSet<WeakTrackingVH, 16> Preds;
Expand Down Expand Up @@ -747,7 +747,7 @@ bool CodeGenPrepare::eliminateMostlyEmptyBlocks(Function &F) {
// as we remove them.
// Note that this intentionally skips the entry block.
SmallVector<WeakTrackingVH, 16> Blocks;
for (auto &Block : llvm::make_range(std::next(F.begin()), F.end()))
for (auto &Block : llvm::drop_begin(F, 1))
Blocks.push_back(&Block);

for (auto &Block : Blocks) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class FrameIndexesCache {
void sortRegisters(SmallVectorImpl<Register> &Regs) {
if (!FixupSCSExtendSlotSize)
return;
llvm::sort(Regs.begin(), Regs.end(), [&](Register &A, Register &B) {
llvm::sort(Regs, [&](Register &A, Register &B) {
return getRegisterSize(TRI, A) > getRegisterSize(TRI, B);
});
}
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2282,7 +2282,7 @@ InstrRefBasedLDV::mlocJoin(MachineBasicBlock &MBB,
auto Cmp = [&](const MachineBasicBlock *A, const MachineBasicBlock *B) {
return BBToOrder.find(A)->second < BBToOrder.find(B)->second;
};
llvm::sort(BlockOrders.begin(), BlockOrders.end(), Cmp);
llvm::sort(BlockOrders, Cmp);

// Skip entry block.
if (BlockOrders.size() == 0)
Expand Down Expand Up @@ -2649,7 +2649,7 @@ std::tuple<bool, bool> InstrRefBasedLDV::vlocJoin(
return BBToOrder[A] < BBToOrder[B];
};

llvm::sort(BlockOrders.begin(), BlockOrders.end(), Cmp);
llvm::sort(BlockOrders, Cmp);

unsigned CurBlockRPONum = BBToOrder[&MBB];

Expand Down Expand Up @@ -2991,7 +2991,7 @@ void InstrRefBasedLDV::vlocDataflow(
for (auto *MBB : BlocksToExplore)
BlockOrders.push_back(const_cast<MachineBasicBlock *>(MBB));

llvm::sort(BlockOrders.begin(), BlockOrders.end(), Cmp);
llvm::sort(BlockOrders, Cmp);
unsigned NumBlocks = BlockOrders.size();

// Allocate some vectors for storing the live ins and live outs. Large.
Expand Down Expand Up @@ -3170,7 +3170,7 @@ void InstrRefBasedLDV::emitLocations(
// in the middle.
for (auto &P : TTracker->Transfers) {
// Sort them according to appearance order.
llvm::sort(P.Insts.begin(), P.Insts.end(), OrderDbgValues);
llvm::sort(P.Insts, OrderDbgValues);
// Insert either before or after the designated point...
if (P.MBB) {
MachineBasicBlock &MBB = *P.MBB;
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/CodeGen/MachinePipeliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,6 @@ void SwingSchedulerDAG::checkNodeSets(NodeSetType &NodeSets) {
}
NodeSets.clear();
LLVM_DEBUG(dbgs() << "Clear recurrence node-sets\n");
return;
}

/// Add the nodes that do not belong to a recurrence set into groups
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/RDFLiveness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ NodeList Liveness::getAllReachingDefs(RegisterRef RefRR,
TmpBB.push_back(Bucket.first);
if (Bucket.second.size() > 2)
GetOrder(*Bucket.first);
llvm::sort(Bucket.second.begin(), Bucket.second.end(), Precedes);
llvm::sort(Bucket.second, Precedes);
}

// Sort the blocks with respect to dominance.
llvm::sort(TmpBB.begin(), TmpBB.end(),
llvm::sort(TmpBB,
[this](auto A, auto B) { return MDT.properlyDominates(A, B); });

std::vector<NodeId> TmpInst;
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/RegAllocFast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1157,8 +1157,7 @@ void RegAllocFast::allocateInstruction(MachineInstr &MI) {
}
}

llvm::sort(DefOperandIndexes.begin(), DefOperandIndexes.end(),
[&](uint16_t I0, uint16_t I1) {
llvm::sort(DefOperandIndexes, [&](uint16_t I0, uint16_t I1) {
const MachineOperand &MO0 = MI.getOperand(I0);
const MachineOperand &MO1 = MI.getOperand(I1);
Register Reg0 = MO0.getReg();
Expand Down
Loading

0 comments on commit 33090e8

Please sign in to comment.