3199 Commits

Author SHA1 Message Date
Daniel Kiss
45726c1a3a
[LLVM] Make sanitizers respect the disable_santizer_instrumentation attribute. (#91732)
`disable_sanitizer_instrumetation` is attached to functions that shall
not be instrumented e.g. ifunc resolver because those run before
everything is initialised.
Some sanitizer already handles this attribute, this patch adds it to
DataFLow and Coverage too.
2024-05-15 08:40:16 +02:00
Nikita Popov
71fbbb69d6 [IR] Move GlobalValue::getGUID() out of line (NFC)
Avoid including MD5.h in a core IR header.
2024-05-15 10:49:25 +09:00
Mircea Trofin
96568f3539
[llvm][ctx_profile] Add instrumentation lowering (#90821)
This adds the instrumentation lowering pass.

(Tracking Issue: #89287, RFC referenced there)
2024-05-08 16:49:08 -07:00
Florian Mayer
2a4f1f4a8f
Document FP relative offsets (#91031) 2024-05-07 12:23:00 -07:00
Kazu Hirata
677dddebae
[Transforms] Use StringRef::operator== instead of StringRef::equals (NFC) (#91072)
I'm planning to remove StringRef::equals in favor of
StringRef::operator==.

- StringRef::operator==/!= outnumber StringRef::equals by a factor of
  31 under llvm/ in terms of their usage.

- The elimination of StringRef::equals brings StringRef closer to
  std::string_view, which has operator== but not equals.

- S == "foo" is more readable than S.equals("foo"), especially for
  !Long.Expression.equals("str") vs Long.Expression != "str".
2024-05-04 12:33:12 -07:00
Vitaly Buka
a441645f80
[tsan] Don't crash on vscale (#91018)
Co-authored-by: Heejin Ahn <aheejin@gmail.com>
2024-05-03 16:29:26 -07:00
Teresa Johnson
e5cbe8fd9c
[MemProf] Optionally match profiles on to manually hinted hot/cold new (#91027)
While we don't currently rewrite the hints on manually hot/cold hinted
allocations, enable optionally matching profiles onto those allocations
as a first step to being able to do this.

By explicitly checking whether the library function is in the list of
operator new also fixes one limitation of the prior call to isNewLikeFn.
Some operator new calls (those that specify nothrow) are considered
Malloc-like because they may return null. We want to be able to match
and rewrite these. Therefore the new test uses a nothrow variant to test
the fix for this as well.
2024-05-03 16:18:04 -07:00
Youngsuk Kim
bcdbd0bf50 [llvm][DataFlowSanitizer] Don't pass vector by value (NFC)
Closes #89201
2024-05-03 05:58:40 -05:00
Vitaly Buka
3016c0636f
[NFCI][msan] Use IntPtr for vscales origin for consistency (#90920) 2024-05-02 17:23:57 -07:00
Vitaly Buka
83fdcf234f
[msan] Fix vscale alloca poisoning (#90912) 2024-05-02 16:44:10 -07:00
Mircea Trofin
c2d892668b
[llvm][ctx_profile] Add instrumentation (#90136)
This adds instrumenting callsites to PGOInstrumentation, *if* contextual profiling is requested. The latter also enables inserting counters in the entry basic block and disables value profiling (the latter is a point in time change)

This change adds the skeleton of the contextual profiling lowering pass, just so we can introduce the flag controlling that and the API to check that. The actual lowering pass will be introduced in a subsequent patch.

(Tracking Issue: #89287, RFC referenced there)
2024-05-01 14:47:49 -07:00
Vitaly Buka
a2be1b8d03
[msan] Don't modify CFG iterating it (#90691)
In rare cases `SplitBlockAndInsertSimpleForLoop` in `paintOrigin`
crashes outsize iterators.

Somehow existing `SplitBlockAndInsertIfThen` do not invalidate
iterators.
2024-05-01 14:47:00 -07:00
Vitaly Buka
8cf0f9ab2f
[msan] Add conservative handling of vscale params (#90167)
Msan uses `__msan_param_tls` to pass shadow of
arguments. Position of arguments is expected to be
available during compile time, if size of the
argument is know. This is not true for vscale.

As work around we require that vscale parameters
are always initialized, then we don't need to pass
shadow.

Ret val should work out of the box as we don't
need to know size compile time.
2024-04-26 15:26:57 -07:00
Florian Mayer
022dc6bab5
[NFC] [HWASan] factor out debug record annotation (#90252)
This will also be used by stack MTE
2024-04-26 13:11:12 -07:00
Vitaly Buka
21b84928f9
[msan] Don't crash in CreateShadowCast on vscale (#90126)
Code expects `VectorOrPrimitiveTypeSizeInBits` compile time value,
which is not available for vscale.
    
In trivial case of the same type we need to do nothing.
2024-04-25 21:29:24 -07:00
Thurston Dang
744d469500
[hwasan] Optimize outlined memaccess for fixed shadow on Aarch64 (#88544)
The HWASan transform currently always uses x20 to pass the shadow base to hwasan_check_memaccess_shortgranules, even if the shadow base is a constant known at compile time (e.g., for Fuchsia, KHWASan, or via -hwasan-mapping-offset).  This patch uses the fixed shadow variant of the hwasan_check_memaccess_shortgranules intrinsic (introduced in 365bddf634), allowing the shadow base to be materialized inside the memaccess callee.

We currently only support this optimization for AArch64; it is a no-op on other platforms due to lack of support for lowering the intrinsic.

Note: when a binary is instrumented with -hwasan-mapping-offset, it is necessary to specify HWASAN_OPTIONS=fixed_shadow_base=... (see ea991a11b2a3d2bfa545adbefb71cd17e8970a43) at runtime to ensure the shadow is mapped appropriately.
2024-04-24 10:38:12 -07:00
Vitaly Buka
4f4ebee10e
[msan] Eliminate non-deterministic behavior in the pass (#89831)
Almost NFC, instrumentation is as correct as it was before.

We need InstrumentationList grouped by origin instruction,
so we used stable_sort. However these objects already grouped
because we never interleave sequences of `insertShadowCheck`
of different instrunction.

Pointer sort has artifact that it was deppendent on allocator behavior,
so we could inserted checks in a different order.

There is no test, as I failed to reproduce this with `opt`. My guess
is that for reproducer we need to increase fragmentation in the
allocator.
2024-04-23 16:19:47 -07:00
Vitaly Buka
1d14034873 [NFC][msan] Add DebugInstrumentInstruction DEBUG_COUNTER 2024-04-23 11:20:50 -07:00
Vitaly Buka
06cc1754f8 [NFC][msan] Fix typo in comment 2024-04-23 11:20:50 -07:00
Ellis Hoag
abfb4915e1
[NFC][InstrProf] Increment valid profile stat in populateCoverage (#89660)
We increment `NumOfCSPGOFunc` and `NumOfPGOFunc` in
`PGOUseFunc::readCounters()` already. We should do the same in
`PGOUseFunc::populateCoverage`.


83bc7b5771/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (L1331)
2024-04-23 11:51:24 -05:00
Kazu Hirata
d674f45d51
[Transforms] Remove extraneous ArrayRef (NFC) (#89535)
We don't need to create these instances of ArrayRef because
ConstantDataVector::get takes ArrayRef, and ArrayRef can be implicitly
constructed from C arrays.
2024-04-21 08:21:23 -07:00
Vitaly Buka
6fedc18c9c [NFC][SanCov] Re-format long line 2024-04-19 19:16:35 -07:00
Vitaly Buka
30257dd4ae [NFC][SanCov] Move Module and analysis callbacks into ModuleSanitizerCoverage class
Avoid passing them around.
2024-04-19 18:55:59 -07:00
Vitaly Buka
b0fe4d4ac3 [NFCI][SanCov] Remove redundant copt<> defaults 2024-04-19 18:45:54 -07:00
Vitaly Buka
905f34eeca [NFCI][SanCov] Remove unused default arguments 2024-04-19 18:34:45 -07:00
Vitaly Buka
91c2e9c2d9 [NFC][SanCov] Pass DomTrees as const references
They are not optional.
2024-04-19 18:26:55 -07:00
Vitaly Buka
c4a799b056 [NFC][hwasan] Use DEBUG_TYPE instead of "hwasan" 2024-04-19 17:43:10 -07:00
Vitaly Buka
c60aa430dc
[NFCI][sanitizers][metadata] Exctract create{Unlikely,Likely}BranchWeights (#89464)
We have a lot of repeated code with random constants.
Particular values are not important, the one just needs to be
bigger then another.

UR_NONTAKEN_WEIGHT is selected as it's the most common one.
2024-04-19 17:03:23 -07:00
Vitaly Buka
f3587d4106
[sancov] Apply branch weights when checking counters (#89458)
It reduces instrumentation overhead by ~50%.
2024-04-19 17:01:18 -07:00
Harald van Dijk
60de56c743
[ValueTracking] Restore isKnownNonZero parameter order. (#88873)
Prior to #85863, the required parameters of llvm::isKnownNonZero were
Value and DataLayout. After, they are Value, Depth, and SimplifyQuery,
where SimplifyQuery is implicitly constructible from DataLayout. The
change to move Depth before SimplifyQuery needed callers to be updated
unnecessarily, and as commented in #85863, we actually want Depth to be
after SimplifyQuery anyway so that it can be defaulted and the caller
does not need to specify it.
2024-04-16 15:21:09 +01:00
Yingwei Zheng
e0a628715a
[ValueTracking] Convert isKnownNonZero to use SimplifyQuery (#85863)
This patch converts `isKnownNonZero` to use SimplifyQuery. Then we can
use the context information from `DomCondCache`.

Fixes https://github.com/llvm/llvm-project/issues/85823.
Alive2: https://alive2.llvm.org/ce/z/QUvHVj
2024-04-12 23:47:20 +08:00
Mingming Liu
08e210c6af
[NFC][IndirectCallProm] Refactor function-based conditional devirtualization and indirect call value profile update into one helper function (#80762)
* The motivation is to move indirect callee profile update inside the
function-based speculative indirect-call promotion, so that there are
fewer diffs the vtable-based transformation and profile update is
implemented in a follow-up patch.
* The Parent patch is https://github.com/llvm/llvm-project/pull/79381
2024-04-11 13:28:20 -07:00
Vitaly Buka
9c4aca2b2e
[HWASAN] Emit optimization remarks (#88332)
Similar to #88304

SelHWAsan is optimization. We may want to diagnose compiler decisions.
Remarks is the tool for that https://llvm.org/docs/Remarks.html.
2024-04-11 11:13:12 -07:00
Vitaly Buka
d927d1867f
[UBSAN] Emit optimization remarks (#88304) 2024-04-10 16:30:42 -07:00
Evgenii Stepanov
e72c949c15
[msan] Overflow intrinsics. (#88210) 2024-04-10 09:12:25 -07:00
Vitaly Buka
0646344062
[HWASAN][UBSAN] Reverse random logic (#88070)
It feels more intuitive to make higher P to keep more checks.
2024-04-08 17:23:47 -07:00
Evgenii Stepanov
5bc87dac75 Revert "Overflow and saturating intrinsics (#88068)"
This reverts commit 118a5d8236d8a483dd401fa35c8b1fcd058eacc1.
2024-04-08 17:02:21 -07:00
Evgenii Stepanov
118a5d8236
Overflow and saturating intrinsics (#88068) 2024-04-08 16:33:45 -07:00
Vitaly Buka
49f0b536fd
[UBSAN] Rename remove-traps to lower-allow-check (#84853) 2024-04-04 21:29:46 -07:00
Vitaly Buka
a9d93873f8
[clang][ubsan] Switch UBSAN optimization to llvm.allow.{runtime,ubsan}.check() (#84858)
Intrinsic introduced with #84850. Intrinsics improves performance
by 3% comparing to removing traps (on
"test-suite/MultiSource/Benchmarks" with PGO+ThinLTO).

The pass will be renamed with #84853.

RFC:
https://discourse.llvm.org/t/rfc-add-llvm-experimental-hot-intrinsic-or-llvm-hot/77641
2024-04-04 17:40:02 -07:00
Vitaly Buka
aa6ba23235 [UBSAN] Remove invalid assert added with #87709 2024-04-04 14:52:31 -07:00
Vitaly Buka
18380c522a
[UBSAN][HWASAN] Remove redundant flags (#87709)
Presense of `cutoff-hot` or `random-skip-rate`
should be enough to trigger optimization.
2024-04-04 14:32:30 -07:00
Vitaly Buka
e628581aaa
[NFC][HWASAN][UBSAN] Remove cl:init from few opts (#87692)
They are supposed to be used with `getNumOccurrences`.
2024-04-04 14:30:04 -07:00
Vitaly Buka
03f54725c3
[HWASAN][UBSAN] Don't use default profile-summary-cutoff-hot (#87691)
Default cutoff is not usefull here. Decision to
enable or not sanitizer causes more significant
performance impact, than a typical optimizations
which rely on `profile-summary-cutoff-hot`.
2024-04-04 14:25:53 -07:00
Vitaly Buka
9a0ae08104
[NFC][HWASAN] Simplify selectiveInstrumentationShouldSkip (#87670) 2024-04-04 12:21:50 -07:00
Mingming Liu
1351d17826
[InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (#66825)
(The profile format change is split into a standalone change into https://github.com/llvm/llvm-project/pull/81691)

* For InstrFDO value profiling, implement instrumentation and lowering for virtual table address.
* This is controlled by `-enable-vtable-value-profiling` and off by default.
* When the option is on, raw profiles will carry serialized `VTableProfData` structs and compressed vtables as payloads.
 
* Implement profile reader and writer support 
  * Raw profile reader is used by `llvm-profdata` but not compiler. Raw profile reader will construct InstrProfSymtab with symbol names, and map profiled runtime address to vtable symbols.
  * Indexed profile reader is used by `llvm-profdata` and compiler. When initialized, the reader stores a pointer to the beginning of in-memory compressed vtable names and the length of string. When used in `llvm-profdata`, reader decompress the string to show symbols of a profiled site. When used in compiler, string decompression doesn't
happen since IR is used to construct InstrProfSymtab.
  * Indexed profile writer collects the list of vtable names, and stores that to index profiles.
  * Text profile reader and writer support are added but mostly follow the implementation for indirect-call value type.
* `llvm-profdata show -show-vtables <args> <profile>` is implemented.

rfc in
https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600#pick-instrumentation-points-and-instrument-runtime-types-7
2024-04-01 08:52:35 -07:00
Florian Mayer
39e8137467
[NFC] [HWASan] add example for ring buffer wrap (#87029)
Also another move comment to correct place.
2024-03-28 18:23:48 -07:00
Vitaly Buka
70e8cf0c31
[HWASAN] Don't instrument loads from global if globals are not tagged (#86774) 2024-03-27 13:43:18 -07:00
Vitaly Buka
453a63caeb
[NFC][HWASAN] Promote InstrumentGlobals to member (#86773) 2024-03-27 13:38:21 -07:00
Florian Mayer
880eb339ca
[NFC] [HWASan] make getAndroidSlotPtr function generic (#86200)
This is so we can use a different slot for stack MTE.
2024-03-26 13:46:08 -07:00