Skip to content

Commit 93c1654

Browse files
authored
Merge branch 'main' into support-x86-builtin-rotate
2 parents 1dbd13c + 258cb46 commit 93c1654

File tree

13 files changed

+420
-8
lines changed

13 files changed

+420
-8
lines changed

clang/include/clang/Tooling/Transformer/RangeSelector.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ RangeSelector enclose(RangeSelector Begin, RangeSelector End);
3737
/// Convenience version of \c range where end-points are bound nodes.
3838
RangeSelector encloseNodes(std::string BeginID, std::string EndID);
3939

40+
/// Selects the merge of the two ranges, i.e. from min(First.begin,
41+
/// Second.begin) to max(First.end, Second.end).
42+
RangeSelector merge(RangeSelector First, RangeSelector Second);
43+
4044
/// DEPRECATED. Use `enclose`.
4145
inline RangeSelector range(RangeSelector Begin, RangeSelector End) {
4246
return enclose(std::move(Begin), std::move(End));

clang/lib/Tooling/Transformer/Parsing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ getBinaryStringSelectors() {
108108
static const llvm::StringMap<RangeSelectorOp<RangeSelector, RangeSelector>> &
109109
getBinaryRangeSelectors() {
110110
static const llvm::StringMap<RangeSelectorOp<RangeSelector, RangeSelector>>
111-
M = {{"enclose", enclose}, {"between", between}};
111+
M = {{"enclose", enclose}, {"between", between}, {"merge", merge}};
112112
return M;
113113
}
114114

clang/lib/Tooling/Transformer/RangeSelector.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,63 @@ RangeSelector transformer::encloseNodes(std::string BeginID,
178178
return transformer::enclose(node(std::move(BeginID)), node(std::move(EndID)));
179179
}
180180

181+
RangeSelector transformer::merge(RangeSelector First, RangeSelector Second) {
182+
return [First,
183+
Second](const MatchResult &Result) -> Expected<CharSourceRange> {
184+
Expected<CharSourceRange> FirstRange = First(Result);
185+
if (!FirstRange)
186+
return FirstRange.takeError();
187+
Expected<CharSourceRange> SecondRange = Second(Result);
188+
if (!SecondRange)
189+
return SecondRange.takeError();
190+
191+
SourceLocation FirstB = FirstRange->getBegin();
192+
SourceLocation FirstE = FirstRange->getEnd();
193+
SourceLocation SecondB = SecondRange->getBegin();
194+
SourceLocation SecondE = SecondRange->getEnd();
195+
// Result begin loc is the minimum of the begin locs of the two ranges.
196+
SourceLocation B =
197+
Result.SourceManager->isBeforeInTranslationUnit(FirstB, SecondB)
198+
? FirstB
199+
: SecondB;
200+
if (FirstRange->isTokenRange() && SecondRange->isTokenRange()) {
201+
// Both ranges are token ranges. Just take the maximum of their end locs.
202+
SourceLocation E =
203+
Result.SourceManager->isBeforeInTranslationUnit(FirstE, SecondE)
204+
? SecondE
205+
: FirstE;
206+
return CharSourceRange::getTokenRange(B, E);
207+
}
208+
209+
if (FirstRange->isTokenRange()) {
210+
// The end of the first range is a token. Need to resolve the token to a
211+
// char range.
212+
FirstE = Lexer::getLocForEndOfToken(FirstE, /*Offset=*/0,
213+
*Result.SourceManager,
214+
Result.Context->getLangOpts());
215+
if (FirstE.isInvalid())
216+
return invalidArgumentError(
217+
"merge: can't resolve first token range to valid source range");
218+
}
219+
if (SecondRange->isTokenRange()) {
220+
// The end of the second range is a token. Need to resolve the token to a
221+
// char range.
222+
SecondE = Lexer::getLocForEndOfToken(SecondE, /*Offset=*/0,
223+
*Result.SourceManager,
224+
Result.Context->getLangOpts());
225+
if (SecondE.isInvalid())
226+
return invalidArgumentError(
227+
"merge: can't resolve second token range to valid source range");
228+
}
229+
// Result end loc is the maximum of the end locs of the two ranges.
230+
SourceLocation E =
231+
Result.SourceManager->isBeforeInTranslationUnit(FirstE, SecondE)
232+
? SecondE
233+
: FirstE;
234+
return CharSourceRange::getCharRange(B, E);
235+
};
236+
}
237+
181238
RangeSelector transformer::member(std::string ID) {
182239
return [ID](const MatchResult &Result) -> Expected<CharSourceRange> {
183240
Expected<DynTypedNode> Node = getNode(Result.Nodes, ID);

clang/unittests/Tooling/RangeSelectorTest.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,45 @@ TEST(RangeSelectorTest, EncloseOpGeneralParsed) {
327327
EXPECT_THAT_EXPECTED(select(*R, Match), HasValue("3, 7"));
328328
}
329329

330+
TEST(RangeSelectorTest, MergeOp) {
331+
StringRef Code = R"cc(
332+
int f(int x, int y, int z) { return 3; }
333+
int g() { return f(/* comment */ 3, 7 /* comment */, 9); }
334+
)cc";
335+
auto Matcher = callExpr(hasArgument(0, expr().bind("a0")),
336+
hasArgument(1, expr().bind("a1")),
337+
hasArgument(2, expr().bind("a2")));
338+
RangeSelector R = merge(node("a0"), node("a1"));
339+
TestMatch Match = matchCode(Code, Matcher);
340+
EXPECT_THAT_EXPECTED(select(R, Match), HasValue("3, 7"));
341+
// Test the merge of two non-contiguous and out-of-order token-ranges.
342+
R = merge(node("a2"), node("a0"));
343+
EXPECT_THAT_EXPECTED(select(R, Match), HasValue("3, 7 /* comment */, 9"));
344+
// Test the merge of a token-range (expr node) with a char-range (before).
345+
R = merge(node("a1"), before(node("a0")));
346+
EXPECT_THAT_EXPECTED(select(R, Match), HasValue("3, 7"));
347+
// Test the merge of two char-ranges.
348+
R = merge(before(node("a0")), before(node("a1")));
349+
EXPECT_THAT_EXPECTED(select(R, Match), HasValue("3, "));
350+
}
351+
352+
TEST(RangeSelectorTest, MergeOpParsed) {
353+
StringRef Code = R"cc(
354+
int f(int x, int y, int z) { return 3; }
355+
int g() { return f(/* comment */ 3, 7 /* comment */, 9); }
356+
)cc";
357+
auto Matcher = callExpr(hasArgument(0, expr().bind("a0")),
358+
hasArgument(1, expr().bind("a1")),
359+
hasArgument(2, expr().bind("a2")));
360+
auto R = parseRangeSelector(R"rs(merge(node("a0"), node("a1")))rs");
361+
ASSERT_THAT_EXPECTED(R, llvm::Succeeded());
362+
TestMatch Match = matchCode(Code, Matcher);
363+
EXPECT_THAT_EXPECTED(select(*R, Match), HasValue("3, 7"));
364+
R = parseRangeSelector(R"rs(merge(node("a2"), node("a1")))rs");
365+
ASSERT_THAT_EXPECTED(R, llvm::Succeeded());
366+
EXPECT_THAT_EXPECTED(select(*R, Match), HasValue("7 /* comment */, 9"));
367+
}
368+
330369
TEST(RangeSelectorTest, NodeOpStatement) {
331370
StringRef Code = "int f() { return 3; }";
332371
TestMatch Match = matchCode(Code, returnStmt().bind("id"));

libcxx/docs/Contributing.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ To do so, you will need to create a PR in the llvm-zorg repository and wait for
311311
merged. Once that change has been merged, an LLVM premerge maintainer (a Google employee)
312312
must use terraform to apply the change to the running GKE cluster.
313313

314+
.. note:: When you update the ``libcxx_runner_image``, also make sure to update the
315+
``libcxx/utils/ci/run-buildbot-container`` script to contain the new image.
316+
314317

315318
Monitoring premerge testing performance
316319
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

libcxx/src/include/from_chars_floating_point.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@
99
#ifndef _LIBCPP_SRC_INCLUDE_FROM_CHARS_FLOATING_POINT_H
1010
#define _LIBCPP_SRC_INCLUDE_FROM_CHARS_FLOATING_POINT_H
1111

12-
// These headers are in the shared LLVM-libc header library.
13-
#include "shared/fp_bits.h"
14-
#include "shared/str_to_float.h"
15-
#include "shared/str_to_integer.h"
16-
1712
#include <__assert>
1813
#include <__config>
1914
#include <cctype>
2015
#include <charconv>
2116
#include <concepts>
2217
#include <limits>
2318

19+
// Make sure we use libc++'s assertion machinery within the shared code we use
20+
// from LLVM libc.
21+
#define LIBC_ASSERT(cond) _LIBCPP_ASSERT((cond), _LIBCPP_TOSTRING(cond))
22+
23+
// These headers are in the shared LLVM-libc header library.
24+
#include "shared/fp_bits.h"
25+
#include "shared/str_to_float.h"
26+
#include "shared/str_to_integer.h"
27+
2428
// Included for the _Floating_type_traits class
2529
#include "to_chars_floating_point.h"
2630

libcxx/utils/ci/run-buildbot-container

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ if [[ ! -d "${MONOREPO_ROOT}/libcxx/utils/ci" ]]; then
2626
echo "Was unable to find the root of the LLVM monorepo; are you running from within the monorepo?"
2727
exit 1
2828
fi
29-
docker pull ghcr.io/llvm/libcxx-linux-builder:b060022103f551d8ca1dad84122ef73927c86512
30-
docker run -it --volume "${MONOREPO_ROOT}:/llvm" --workdir "/llvm" --cap-add=SYS_PTRACE ghcr.io/llvm/libcxx-linux-builder:b060022103f551d8ca1dad84122ef73927c86512 \
29+
docker pull ghcr.io/llvm/libcxx-linux-builder:d6b22a347f813cf4a9832627323a43074f57bbcf
30+
docker run -it --volume "${MONOREPO_ROOT}:/llvm" --workdir "/llvm" --cap-add=SYS_PTRACE ghcr.io/llvm/libcxx-linux-builder:d6b22a347f813cf4a9832627323a43074f57bbcf \
3131
bash -c 'git config --global --add safe.directory /llvm ; exec bash'

llvm/include/llvm/ProfileData/SampleProf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,7 @@ class ProfileSymbolList {
16581658
}
16591659

16601660
unsigned size() { return Syms.size(); }
1661+
void reserve(size_t Size) { Syms.reserve(Size); }
16611662

16621663
void setToCompress(bool TC) { ToCompress = TC; }
16631664
bool toCompress() { return ToCompress; }

llvm/lib/ProfileData/SampleProf.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "llvm/Support/ErrorHandling.h"
2323
#include "llvm/Support/LEB128.h"
2424
#include "llvm/Support/raw_ostream.h"
25+
#include <algorithm>
26+
#include <cstdint>
2527
#include <string>
2628
#include <system_error>
2729

@@ -398,6 +400,10 @@ LLVM_DUMP_METHOD void FunctionSamples::dump() const { print(dbgs(), 0); }
398400

399401
std::error_code ProfileSymbolList::read(const uint8_t *Data,
400402
uint64_t ListSize) {
403+
// Scan forward to see how many elements we expect.
404+
reserve(std::min<uint64_t>(ProfileSymbolListCutOff,
405+
std::count(Data, Data + ListSize, 0)));
406+
401407
const char *ListStart = reinterpret_cast<const char *>(Data);
402408
uint64_t Size = 0;
403409
uint64_t StrNum = 0;

mlir/include/mlir/Dialect/OpenACC/Transforms/Passes.td

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,20 @@ def ACCImplicitRoutine : Pass<"acc-implicit-routine", "mlir::ModuleOp"> {
136136
];
137137
}
138138

139+
def ACCLegalizeSerial : Pass<"acc-legalize-serial", "mlir::func::FuncOp"> {
140+
let summary = "Legalize OpenACC serial constructs";
141+
let description = [{
142+
This pass converts `acc.serial` constructs into `acc.parallel` constructs
143+
with `num_gangs(1)`, `num_workers(1)`, and `vector_length(1)`.
144+
145+
This transformation simplifies processing of acc regions by unifying the
146+
handling of serial and parallel constructs. Since an OpenACC serial region
147+
executes sequentially (like a parallel region with a single gang, worker,
148+
and vector), this conversion is semantically equivalent while enabling code
149+
reuse in later compilation stages.
150+
}];
151+
let dependentDialects = ["mlir::acc::OpenACCDialect",
152+
"mlir::arith::ArithDialect"];
153+
}
154+
139155
#endif // MLIR_DIALECT_OPENACC_TRANSFORMS_PASSES

0 commit comments

Comments
 (0)