Skip to content

Commit 98e190f

Browse files
author
z1.cciauto
committed
merge main into amd-staging
2 parents 1ff501d + 48d0ef1 commit 98e190f

File tree

202 files changed

+9206
-3064
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+9206
-3064
lines changed

bolt/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ if (BOLT_ENABLE_RUNTIME)
163163
add_llvm_install_targets(install-bolt_rt
164164
DEPENDS bolt_rt bolt
165165
COMPONENT bolt)
166-
set(LIBBOLT_RT_INSTR "${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins/lib/libbolt_rt_instr.a")
167-
set(LIBBOLT_RT_HUGIFY "${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins/lib/libbolt_rt_hugify.a")
166+
set(LIBBOLT_RT_INSTR "${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins/lib${LLVM_LIBDIR_SUFFIX}/libbolt_rt_instr.a")
167+
set(LIBBOLT_RT_HUGIFY "${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins/lib${LLVM_LIBDIR_SUFFIX}/libbolt_rt_hugify.a")
168168
endif()
169169

170170
find_program(GNU_LD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.bfd ld.bfd DOC "GNU ld")

bolt/lib/Passes/Inliner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,13 @@ Inliner::inlineCall(BinaryBasicBlock &CallerBB,
310310
if (MIB.isPseudo(Inst))
311311
continue;
312312

313-
MIB.stripAnnotations(Inst, /*KeepTC=*/BC.isX86());
313+
MIB.stripAnnotations(Inst, /*KeepTC=*/BC.isX86() || BC.isAArch64());
314314

315315
// Fix branch target. Strictly speaking, we don't have to do this as
316316
// targets of direct branches will be fixed later and don't matter
317317
// in the CFG state. However, disassembly may look misleading, and
318318
// hence we do the fixing.
319-
if (MIB.isBranch(Inst)) {
319+
if (MIB.isBranch(Inst) && !MIB.isTailCall(Inst)) {
320320
assert(!MIB.isIndirectBranch(Inst) &&
321321
"unexpected indirect branch in callee");
322322
const BinaryBasicBlock *TargetBB =

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,36 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
133133
public:
134134
using MCPlusBuilder::MCPlusBuilder;
135135

136+
MCPhysReg getStackPointer() const override { return AArch64::SP; }
137+
138+
bool isPush(const MCInst &Inst) const override { return false; }
139+
140+
bool isPop(const MCInst &Inst) const override { return false; }
141+
142+
void createCall(MCInst &Inst, const MCSymbol *Target,
143+
MCContext *Ctx) override {
144+
createDirectCall(Inst, Target, Ctx, false);
145+
}
146+
147+
bool convertTailCallToCall(MCInst &Inst) override {
148+
int NewOpcode;
149+
switch (Inst.getOpcode()) {
150+
default:
151+
return false;
152+
case AArch64::B:
153+
NewOpcode = AArch64::BL;
154+
break;
155+
case AArch64::BR:
156+
NewOpcode = AArch64::BLR;
157+
break;
158+
}
159+
160+
Inst.setOpcode(NewOpcode);
161+
removeAnnotation(Inst, MCPlus::MCAnnotation::kTailCall);
162+
clearOffset(Inst);
163+
return true;
164+
}
165+
136166
bool equals(const MCTargetExpr &A, const MCTargetExpr &B,
137167
CompFuncTy Comp) const override {
138168
const auto &AArch64ExprA = cast<AArch64MCExpr>(A);

bolt/runtime/CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ add_library(bolt_rt_instr STATIC
1616
instr.cpp
1717
${CMAKE_CURRENT_BINARY_DIR}/config.h
1818
)
19-
set_target_properties(bolt_rt_instr PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
19+
set_target_properties(bolt_rt_instr PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "lib${LLVM_LIBDIR_SUFFIX}")
2020
add_library(bolt_rt_hugify STATIC
2121
hugify.cpp
2222
${CMAKE_CURRENT_BINARY_DIR}/config.h
2323
)
24-
set_target_properties(bolt_rt_hugify PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
24+
set_target_properties(bolt_rt_hugify PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "lib${LLVM_LIBDIR_SUFFIX}")
2525

2626
if(NOT BOLT_BUILT_STANDALONE)
2727
add_custom_command(TARGET bolt_rt_instr POST_BUILD
28-
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/lib/libbolt_rt_instr.a" "${LLVM_LIBRARY_DIR}")
28+
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/libbolt_rt_instr.a" "${LLVM_LIBRARY_DIR}")
2929
add_custom_command(TARGET bolt_rt_hugify POST_BUILD
30-
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/lib/libbolt_rt_hugify.a" "${LLVM_LIBRARY_DIR}")
30+
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/libbolt_rt_hugify.a" "${LLVM_LIBRARY_DIR}")
3131
endif()
3232

3333
set(BOLT_RT_FLAGS
@@ -53,23 +53,23 @@ target_include_directories(bolt_rt_instr PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
5353
target_compile_options(bolt_rt_hugify PRIVATE ${BOLT_RT_FLAGS})
5454
target_include_directories(bolt_rt_hugify PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
5555

56-
install(TARGETS bolt_rt_instr DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
57-
install(TARGETS bolt_rt_hugify DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
56+
install(TARGETS bolt_rt_instr DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")
57+
install(TARGETS bolt_rt_hugify DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")
5858

5959
if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" AND CMAKE_SYSTEM_NAME STREQUAL "Darwin")
6060
add_library(bolt_rt_instr_osx STATIC
6161
instr.cpp
6262
${CMAKE_CURRENT_BINARY_DIR}/config.h
6363
)
64-
set_target_properties(bolt_rt_instr_osx PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
64+
set_target_properties(bolt_rt_instr_osx PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "lib${LLVM_LIBDIR_SUFFIX}")
6565
target_include_directories(bolt_rt_instr_osx PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
6666
target_compile_options(bolt_rt_instr_osx PRIVATE
6767
-target x86_64-apple-darwin19.6.0
6868
${BOLT_RT_FLAGS})
69-
install(TARGETS bolt_rt_instr_osx DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
69+
install(TARGETS bolt_rt_instr_osx DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")
7070

7171
if(NOT BOLT_BUILT_STANDALONE)
7272
add_custom_command(TARGET bolt_rt_instr_osx POST_BUILD
73-
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/lib/libbolt_rt_instr_osx.a" "${LLVM_LIBRARY_DIR}")
73+
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/libbolt_rt_instr_osx.a" "${LLVM_LIBRARY_DIR}")
7474
endif()
7575
endif()
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## This test checks that inline is properly handled by BOLT on aarch64.
2+
3+
# REQUIRES: system-linux
4+
5+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
6+
# RUN: %clang %cflags -O0 %t.o -o %t.exe -Wl,-q
7+
# RUN: llvm-bolt --inline-small-functions --print-inline --print-only=_Z3barP1A \
8+
# RUN: %t.exe -o %t.bolt | FileCheck %s
9+
10+
# CHECK: BOLT-INFO: inlined 0 calls at 1 call sites in 2 iteration(s). Change in binary size: 4 bytes.
11+
# CHECK: Binary Function "_Z3barP1A" after inlining {
12+
# CHECK-NOT: bl _Z3fooP1A
13+
# CHECK: ldr x8, [x0]
14+
# CHECK-NEXT: ldr w0, [x8]
15+
16+
.text
17+
.globl _Z3fooP1A
18+
.type _Z3fooP1A,@function
19+
_Z3fooP1A:
20+
ldr x8, [x0]
21+
ldr w0, [x8]
22+
ret
23+
.size _Z3fooP1A, .-_Z3fooP1A
24+
25+
.globl _Z3barP1A
26+
.type _Z3barP1A,@function
27+
_Z3barP1A:
28+
stp x29, x30, [sp, #-16]!
29+
mov x29, sp
30+
bl _Z3fooP1A
31+
mul w0, w0, w0
32+
ldp x29, x30, [sp], #16
33+
ret
34+
.size _Z3barP1A, .-_Z3barP1A
35+
36+
.globl main
37+
.p2align 2
38+
.type main,@function
39+
main:
40+
mov w0, wzr
41+
ret
42+
.size main, .-main
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## This test checks that inline is properly handled by BOLT on aarch64.
2+
3+
# REQUIRES: system-linux
4+
5+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
6+
# RUN: %clang %cflags -O0 %t.o -o %t.exe -Wl,-q
7+
# RUN: llvm-bolt --inline-small-functions --print-inline --print-only=test \
8+
# RUN: %t.exe -o %t.bolt | FileCheck %s
9+
10+
#CHECK: BOLT-INFO: inlined 0 calls at 1 call sites in 2 iteration(s). Change in binary size: 4 bytes.
11+
#CHECK: Binary Function "test" after inlining {
12+
#CHECK-NOT: bl indirect
13+
#CHECK: add w0, w1, w0
14+
#CHECK-NEXT: blr x2
15+
16+
.text
17+
.globl indirect
18+
.type indirect,@function
19+
indirect:
20+
add w0, w1, w0
21+
br x2
22+
.size indirect, .-indirect
23+
24+
.globl test
25+
.type test,@function
26+
test:
27+
stp x29, x30, [sp, #-32]!
28+
stp x20, x19, [sp, #16]
29+
mov x29, sp
30+
mov w19, w1
31+
mov w20, w0
32+
bl indirect
33+
add w8, w19, w20
34+
cmp w0, #0
35+
csinc w0, w8, wzr, eq
36+
ldp x20, x19, [sp, #16]
37+
ldp x29, x30, [sp], #32
38+
ret
39+
.size test, .-test
40+
41+
.globl main
42+
.type main,@function
43+
main:
44+
mov w0, wzr
45+
ret
46+
.size main, .-main
47+
48+

bolt/test/lit.local.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
host_linux_triple = config.target_triple.split("-")[0] + "-unknown-linux-gnu"
2-
common_linker_flags = "-fuse-ld=lld -Wl,--unresolved-symbols=ignore-all -pie"
2+
common_linker_flags = "-fuse-ld=lld -Wl,--unresolved-symbols=ignore-all -Wl,--build-id=none -pie"
33
flags = f"--target={host_linux_triple} -fPIE {common_linker_flags}"
44

55
config.substitutions.insert(0, ("%cflags", f"%cflags {flags}"))

clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
#include "RawStringLiteralCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
#include "clang/Basic/LangOptions.h"
13+
#include "clang/Basic/SourceManager.h"
1214
#include "clang/Lex/Lexer.h"
15+
#include "llvm/ADT/StringRef.h"
16+
#include <optional>
1317

1418
using namespace clang::ast_matchers;
1519

@@ -66,20 +70,6 @@ bool containsDelimiter(StringRef Bytes, const std::string &Delimiter) {
6670
: (")" + Delimiter + R"(")")) != StringRef::npos;
6771
}
6872

69-
std::string asRawStringLiteral(const StringLiteral *Literal,
70-
const std::string &DelimiterStem) {
71-
const StringRef Bytes = Literal->getBytes();
72-
std::string Delimiter;
73-
for (int I = 0; containsDelimiter(Bytes, Delimiter); ++I) {
74-
Delimiter = (I == 0) ? DelimiterStem : DelimiterStem + std::to_string(I);
75-
}
76-
77-
if (Delimiter.empty())
78-
return (R"(R"()" + Bytes + R"lit()")lit").str();
79-
80-
return (R"(R")" + Delimiter + "(" + Bytes + ")" + Delimiter + R"(")").str();
81-
}
82-
8373
} // namespace
8474

8575
RawStringLiteralCheck::RawStringLiteralCheck(StringRef Name,
@@ -119,30 +109,73 @@ void RawStringLiteralCheck::registerMatchers(MatchFinder *Finder) {
119109
stringLiteral(unless(hasParent(predefinedExpr()))).bind("lit"), this);
120110
}
121111

112+
static std::optional<StringRef>
113+
createUserDefinedSuffix(const StringLiteral *Literal, const SourceManager &SM,
114+
const LangOptions &LangOpts) {
115+
const CharSourceRange TokenRange =
116+
CharSourceRange::getTokenRange(Literal->getSourceRange());
117+
Token T;
118+
if (Lexer::getRawToken(Literal->getBeginLoc(), T, SM, LangOpts))
119+
return std::nullopt;
120+
const CharSourceRange CharRange =
121+
Lexer::makeFileCharRange(TokenRange, SM, LangOpts);
122+
if (T.hasUDSuffix()) {
123+
StringRef Text = Lexer::getSourceText(CharRange, SM, LangOpts);
124+
const size_t UDSuffixPos = Text.find_last_of('"');
125+
if (UDSuffixPos == StringRef::npos)
126+
return std::nullopt;
127+
return Text.slice(UDSuffixPos + 1, Text.size());
128+
}
129+
return std::nullopt;
130+
}
131+
132+
static std::string createRawStringLiteral(const StringLiteral *Literal,
133+
const std::string &DelimiterStem,
134+
const SourceManager &SM,
135+
const LangOptions &LangOpts) {
136+
const StringRef Bytes = Literal->getBytes();
137+
std::string Delimiter;
138+
for (int I = 0; containsDelimiter(Bytes, Delimiter); ++I) {
139+
Delimiter = (I == 0) ? DelimiterStem : DelimiterStem + std::to_string(I);
140+
}
141+
142+
std::optional<StringRef> UserDefinedSuffix =
143+
createUserDefinedSuffix(Literal, SM, LangOpts);
144+
145+
if (Delimiter.empty())
146+
return (R"(R"()" + Bytes + R"lit()")lit" + UserDefinedSuffix.value_or(""))
147+
.str();
148+
149+
return (R"(R")" + Delimiter + "(" + Bytes + ")" + Delimiter + R"(")" +
150+
UserDefinedSuffix.value_or(""))
151+
.str();
152+
}
153+
154+
static bool compareStringLength(StringRef Replacement,
155+
const StringLiteral *Literal,
156+
const SourceManager &SM,
157+
const LangOptions &LangOpts) {
158+
return Replacement.size() <=
159+
Lexer::MeasureTokenLength(Literal->getBeginLoc(), SM, LangOpts);
160+
}
161+
122162
void RawStringLiteralCheck::check(const MatchFinder::MatchResult &Result) {
123163
const auto *Literal = Result.Nodes.getNodeAs<StringLiteral>("lit");
124164
if (Literal->getBeginLoc().isMacroID())
125165
return;
126-
166+
const SourceManager &SM = *Result.SourceManager;
167+
const LangOptions &LangOpts = getLangOpts();
127168
if (containsEscapedCharacters(Result, Literal, DisallowedChars)) {
128-
std::string Replacement = asRawStringLiteral(Literal, DelimiterStem);
169+
const std::string Replacement =
170+
createRawStringLiteral(Literal, DelimiterStem, SM, LangOpts);
129171
if (ReplaceShorterLiterals ||
130-
Replacement.length() <=
131-
Lexer::MeasureTokenLength(Literal->getBeginLoc(),
132-
*Result.SourceManager, getLangOpts()))
133-
replaceWithRawStringLiteral(Result, Literal, Replacement);
172+
compareStringLength(Replacement, Literal, SM, LangOpts)) {
173+
diag(Literal->getBeginLoc(),
174+
"escaped string literal can be written as a raw string literal")
175+
<< FixItHint::CreateReplacement(Literal->getSourceRange(),
176+
Replacement);
177+
}
134178
}
135179
}
136180

137-
void RawStringLiteralCheck::replaceWithRawStringLiteral(
138-
const MatchFinder::MatchResult &Result, const StringLiteral *Literal,
139-
StringRef Replacement) {
140-
CharSourceRange CharRange = Lexer::makeFileCharRange(
141-
CharSourceRange::getTokenRange(Literal->getSourceRange()),
142-
*Result.SourceManager, getLangOpts());
143-
diag(Literal->getBeginLoc(),
144-
"escaped string literal can be written as a raw string literal")
145-
<< FixItHint::CreateReplacement(CharRange, Replacement);
146-
}
147-
148181
} // namespace clang::tidy::modernize

clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ class RawStringLiteralCheck : public ClangTidyCheck {
3333
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
3434

3535
private:
36-
void replaceWithRawStringLiteral(
37-
const ast_matchers::MatchFinder::MatchResult &Result,
38-
const StringLiteral *Literal, StringRef Replacement);
39-
4036
std::string DelimiterStem;
4137
CharsBitSet DisallowedChars;
4238
const bool ReplaceShorterLiterals;

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ Changes in existing checks
321321
a false positive when only an implicit conversion happened inside an
322322
initializer list.
323323

324+
- Improved :doc:`modernize-raw-string-literal
325+
<clang-tidy/checks/modernize/raw-string-literal>` check to fix incorrect
326+
fix-it when the string contains a user-defined suffix.
327+
324328
- Improved :doc:`modernize-use-designated-initializers
325329
<clang-tidy/checks/modernize/use-designated-initializers>` check to fix a
326330
crash when a class is declared but not defined.

0 commit comments

Comments
 (0)