[MemProf] Fix off-by-one in the function clone numbers of UnassignedC… (#234032)
The loop recording the calls in function clones which did not get their
own clone of a callsite node (UnassignedCallClones) incremented the
clone number before checking it, recording the calls of function clone k
under clone number k+1. A function clone was therefore skipped whenever
k+1 was the clone number of a clone of the callsite node, leaving its
call to the original callee instead of following the original node's
callee assignment, and the calls of a function clone which did have its
own clone of the node could be recorded (under the next number) and
later redirected to the original node's callee. Use the clone number of
the function clone being examined.
The new test has a function F with two clones, where F.memprof.1 has no
clone of the F->G callsite node while F.memprof.2 does (clone number 2):
F.memprof.1's call to G was skipped and kept calling the original G
rather than the cold clone the original node is assigned to.
[OpenMP] Fix context selector matching and scoring
OMPContext computes some context selector scores differently from the
OpenMP 5.2 rules in "Matching and Scoring Context Selectors", and
crashes on some selectors. Fix the following; each can change which
variant is selected:
- Device weights. kind, arch, and isa are worth 2^l, 2^(l+1), and
2^(l+2), where l is the depth of the construct context. OMPContext
used the candidate's own construct selector count, so inside two
nested parallel regions kind(cpu) was worth 1 instead of 4 and lost
to vendor(score(2): llvm).
- Scores per selector. A score belongs to a trait selector, but it was
added once per property, so vendor(score(10): llvm, amd) counted 20.
Scores now add once, using arbitrary-width arithmetic instead of
wrapping 64-bit sums.
- Repeated constructs. When a construct selector can match several
enclosing constructs, the highest-valued complete match counts.
construct={parallel} inside three nested parallel regions now adds 2^2
[29 lines not shown]
[libc] Use sigmask utils in linux thread_exit (#234185)
Use signals::block_all() instead of manually filling a sigset_t with
0xff and calling rt_sigprocmask. Also drop the now unused includes and
build dependencies.
Assisted-by: Gemini
[CIR][OpenMP] Add support for 'distribute parallel for' with 'target teams'
Adds support for handling the full '[target] teams distribute parallel for'.
Introduces setting the omp.composite attibute for the 'distribute parallel for'
composite construct.
Assisted-by: Cursor / Claude Sonnet 5 High
[CIR][OpenMP] Add initial support for distribute
This patch adds initial support for the OpenMP 'distribute' directive. Basic
code generation for the standalone and combined cases is introduced. Support
for clauses will be added in the future. The composite 'teams distribute
parallel for' form will be added in a subsequent patch.
Assisted-by: Cursor / Claude Sonnet 5 High
[CIR][OpenMP] Add support for omp teams
This patch adds support for the OpenMP 'teams' directive, both standalone
and as the combined `target teams` construct. isCombinableLeaf now also
recognizes teams, so an explicitly-nested `target` + `teams` pair gets
the same omp.combined marking as the combined case.
Assisted-by: Cursor / Claude Sonnet 5 High
[CIR][OpenMP] Add support for host_eval so that SPMD kernels can be used
This patch adds support for host_eval so that SPMD kernels and in the future
num_threads and other clauses can be implemented correctly.
Assisted-by: Cursor / Claude Sonnet 5 High
[CIR][OpenMP] Add support for the OpenMP 'for' directive
This patch adds support for wsloop in ClangIR: the `for` directive and its
combined forms `parallel for` and `target parallel for`. This is lowered to an
omp.wsloop + omp.loop_nest, nested utilizing the existing queue-based
decomposition.
Assisted-by: Cursor / Claude Sonnet 5 High
[libc] Enable baremetal Armv7-M pre-merge tests
The tests are run using QEMU system emulation on AArch64 GitHub runners.
No strong reason to use AArch64 instead of x86_64 as it is via emulation
anyway. But AArch64 runners are cheaper, so that might prove beneficial.
[libc] Application and testing support in baremetal Armv7-M CMake cache file
This patch adds support for linking and running applications, including
tests, targeting baremetal Armv7-M to the corresponding CMake cache
file.
The cache file takes into consideration if compiler-rt is enabled or
not. If it is, then linking applications is possible, and the relevant
CMake variables are set to enable test runs. If not, then only the libc
build is possible and enabled.
Particular libc configuration options, memory mappings, and QEMU options
are based on what Arm Toolchain for Embedded uses in its fully working
downstream testing.
[libc] Add qemu-system-arm to libc Dockerfile for Arm baremetal testing
This patch adds `qemu-system-arm` to the packages installed into the
Docker image so that we can run Arm baremetal tests.
It is only installed on the AArch64 platforms because we intend to run
the tests on AArch64 GitHub runners. Therefore there is no need to
install on x86_64.
fix: [CIR] Check only the converted pointer's address space
Limit opaque pointer conversion to its own address space and diagnose unsupported pointee types where their layout is required. Emit type-specific errors for failed pointer conversions.
Validate pointee memory conversion before deriving copy sizes, alignments, or pointer-difference strides from CIR layout. Keep deeper pointee types opaque when their layouts are not needed.
Assisted-by: Codex / GPT-6
[CIR] Reject language address spaces in DirectToLLVM pointer conversion
Reject unlowered language address spaces in pointer types when bypassing TargetLowering. Guard pointer-producing lowerings, including generated patterns, so failed conversions report legalization failures instead of silently selecting address space zero or constructing invalid LLVM operations.
Assisted-by: Codex / GPT-6
[flang] Add -f[no-]version-loops-for-trip-count and enable it at -O3 (2/2) (#231207)
Stacked on #231205.
Wire `LoopTripCountVersioning` into the default pipeline behind a new
flag, mirroring `-fversion-loops-for-stride`:
- `-f[no-]version-loops-for-trip-count` in the `flang` driver and
`-fc1`, on by default at `-O3` and above.
- `CompilerInvocation` records the flag in `CodeGenOptions`, which feeds
`MLIRToLLVMPassPipelineConfig::LoopTripCountVersioning`; `Pipelines.cpp`
adds the pass when that is set. `tco` sets it directly at `-O3`.
- The pass runs right after `LoopVersioning`, before CSE, so the guard's
`arith.cmpi` is shared when several loops version on the same bound.
- `-mmlir -loop-tripcount-versioning-max-section-extent=N` (hidden) sets
the pass option for experiments; 0 disables.
- Release note under New Compiler Flags.
Tests:
[10 lines not shown]
[flang] Add pass to version innermost loops on a likely constant trip count (1/2) (#231205)
Add `LoopTripCountVersioning`, a FIR pass that versions an innermost
`fir.do_loop` whose trip count is a runtime value likely to equal a
compile-time constant N:
```
if (ub == N) { same loop with ub := N }
else { original loop }
```
Both arms are the original loop with only the bound changed, so the
transformation is legal wherever the runtime check is uniform across the
threads executing the loop. Device code is excluded: on a GPU the check
could differ between threads and send them to different copies of a
convergent operation such as a barrier. The fast arm has a constant trip
count, which LLVM can fully unroll, or at least vectorize without a
minimum-iteration check and remainder loop. A heuristic is used to
decide where the rewrite is worthwhile.
[36 lines not shown]
[CIR] Propagate initializer type adjustment failures
Reject initializers whose active members have no LLVM representation, including when an enclosing union's storage type is convertible. Propagate recursive adjustment failures before querying data layout or constructing LLVM operations.
Assisted-by: Codex / GPT-6
[OpenMP] Fix construct context at TARGET and repeated-construct subsets (#233480)
OMPContext has two bugs in how construct selectors are matched. Both can
select the wrong variant:
- The construct context should start at the innermost enclosing TARGET,
but Clang and Flang add every enclosing construct. Inside a TARGET
region nested in a PARALLEL, construct={parallel} matched the outer
PARALLEL. OMPContext::addTrait now drops the constructs recorded before
a target trait.
- A selector that only repeats a construct, such as construct={parallel
do, parallel} over construct={parallel do}, adds no property.
isStrictSubset required fewer properties, so a score tie between the two
fell back to clause order. A shorter ordered construct sequence now also
makes a strict subset. If the shorter selector has a user condition, or
an ISA name the longer one lacks, the tie still falls back to clause
order, since different conditions or ISA names share one property.
The ordered-subsequence check advanced the wrong iterator, so it
[7 lines not shown]
[CIR] Add llvm-strings to check-clang dependencies (#234257)
Build `llvm-strings` for `check-clang` when CIR is enabled. The CIR
bytecode tests use this tool, but only `check-clang-cir` declares the
dependency, so clean builds running `check-clang` can fail with command
not found.
Assisted-by: Codex / GPT-6
[libc++][pstl][NFC] Sort the forward declarations in backend_fwd.h (#233477)
This file has grown quite a lot and is expected to continue growing.
Make it easier to maintain by organising the forward declarations in a
strict lexicographical order.
[libc] Implement ether_ntoa and ether_ntoa_r (#233876)
This adds <net/ethernet.h> (with struct ether_addr) and
<netinet/ether.h> (with ether_ntoa, ether_ntoa_r).
A few implementation notes:
- following glibc and musl (and the linux man page), octets < 0x10 are
formatted without a leading zero. This differs from some BSD
implementations.
- like inet_ntoa (but unlike GLIBC), ether_ntoa uses a thread-local
static buffer
Assisted-by: Gemini
[CIR] Fix uninitialized value which caused MSAN failure (#234274)
This failure showed up in the build bots now that we're enabled by
default. We ended up accessing an invalid index while doing label
lowering ops.
[CIR][OpenMP] Add support for 'distribute parallel for' with 'target teams'
Adds support for handling the full '[target] teams distribute parallel for'.
Introduces setting the omp.composite attibute for the 'distribute parallel for'
composite construct.
Assisted-by: Cursor / Claude Sonnet 5 High
[libc] Fix gcc build for popen (#234041)
There were gcc failures after #232846 added popen/pclose. This PR fixes
them. Specifically gcc 12 didn't like the custom `delete` and was
confused by `MSAN_UNPOISON` expanding to nothing.
Assisted-by: Automated tooling, human reviewed.