1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00
llvm-mirror/lib/Transforms/Utils
Hongtao Yu db4396f62a [CSSPGO] IR intrinsic for pseudo-probe block instrumentation
This change introduces a new IR intrinsic named `llvm.pseudoprobe` for pseudo-probe block instrumentation. Please refer to https://reviews.llvm.org/D86193 for the whole story.

A pseudo probe is used to collect the execution count of the block where the probe is instrumented. This requires a pseudo probe to be persisting. The LLVM PGO instrumentation also instruments in similar places by placing a counter in the form of atomic read/write operations or runtime helper calls. While these operations are very persisting or optimization-resilient, in theory we can borrow the atomic read/write implementation from PGO counters and cut it off at the end of compilation with all the atomics converted into binary data. This was our initial design and we’ve seen promising sample correlation quality with it. However, the atomics approach has a couple issues:

1. IR Optimizations are blocked unexpectedly. Those atomic instructions are not going to be physically present in the binary code, but since they are on the IR till very end of compilation, they can still prevent certain IR optimizations and result in lower code quality.
2. The counter atomics may not be fully cleaned up from the code stream eventually.
3. Extra work is needed for re-targeting.

We choose to implement pseudo probes based on a special LLVM intrinsic, which is expected to have most of the semantics that comes with an atomic operation but does not block desired optimizations as much as possible. More specifically the semantics associated with the new intrinsic enforces a pseudo probe to be virtually executed exactly the same number of times before and after an IR optimization. The intrinsic also comes with certain flags that are carefully chosen so that the places they are probing are not going to be messed up by the optimizer while most of the IR optimizations still work. The core flags given to the special intrinsic is `IntrInaccessibleMemOnly`, which means the intrinsic accesses memory and does have a side effect so that it is not removable, but is does not access memory locations that are accessible by any original instructions. This way the intrinsic does not alias with any original instruction and thus it does not block optimizations as much as an atomic operation does. We also assign a function GUID and a block index to an intrinsic so that they are uniquely identified and not merged in order to achieve good correlation quality.

Let's now look at an example. Given the following LLVM IR:

```
define internal void @foo2(i32 %x, void (i32)* %f) !dbg !4 {
bb0:
  %cmp = icmp eq i32 %x, 0
   br i1 %cmp, label %bb1, label %bb2
bb1:
   br label %bb3
bb2:
   br label %bb3
bb3:
   ret void
}
```

The instrumented IR will look like below. Note that each `llvm.pseudoprobe` intrinsic call represents a pseudo probe at a block, of which the first parameter is the GUID of the probe’s owner function and the second parameter is the probe’s ID.

```
define internal void @foo2(i32 %x, void (i32)* %f) !dbg !4 {
bb0:
   %cmp = icmp eq i32 %x, 0
   call void @llvm.pseudoprobe(i64 837061429793323041, i64 1)
   br i1 %cmp, label %bb1, label %bb2
bb1:
   call void @llvm.pseudoprobe(i64 837061429793323041, i64 2)
   br label %bb3
bb2:
   call void @llvm.pseudoprobe(i64 837061429793323041, i64 3)
   br label %bb3
bb3:
   call void @llvm.pseudoprobe(i64 837061429793323041, i64 4)
   ret void
}

```

Reviewed By: wmi

Differential Revision: https://reviews.llvm.org/D86490
2020-11-20 10:39:24 -08:00
..
AddDiscriminators.cpp
AMDGPUEmitPrintf.cpp
ASanStackFrameLayout.cpp
AssumeBundleBuilder.cpp
BasicBlockUtils.cpp [Transforms] Use llvm::is_contained (NFC) 2020-11-18 20:42:22 -08:00
BreakCriticalEdges.cpp [Transforms] Use llvm::is_contained (NFC) 2020-11-18 20:42:22 -08:00
BuildLibCalls.cpp Make inferLibFuncAttributes() add SExt attribute on second arg to ldexp. 2020-11-10 18:32:15 +01:00
BypassSlowDivision.cpp
CallGraphUpdater.cpp
CallPromotionUtils.cpp
CanonicalizeAliases.cpp
CanonicalizeFreezeInLoops.cpp
CloneFunction.cpp [Transforms] Use pred_empty (NFC) 2020-11-16 22:09:14 -08:00
CloneModule.cpp
CMakeLists.txt Revert "clang-misexpect: Profile Guided Validation of Performance Annotations in LLVM" 2020-11-14 13:12:38 +03:00
CodeExtractor.cpp Revert "[IR] add fn attr for no_stack_protector; prevent inlining on mismatch" 2020-11-17 17:27:14 -08:00
CodeMoverUtils.cpp
CtorUtils.cpp
Debugify.cpp [Debugify] Skip debugifying on special/immutable passes 2020-11-16 20:39:46 -08:00
DemoteRegToStack.cpp
EntryExitInstrumenter.cpp [musttail] Unify musttail call preceding return checking 2020-11-03 11:39:27 -08:00
EscapeEnumerator.cpp [musttail] Unify musttail call preceding return checking 2020-11-03 11:39:27 -08:00
Evaluator.cpp [CSSPGO] IR intrinsic for pseudo-probe block instrumentation 2020-11-20 10:39:24 -08:00
FixIrreducible.cpp
FlattenCFG.cpp
FunctionComparator.cpp [MergeFunctions] fix function attribute comparison in FunctionComparator 2020-11-09 09:19:11 +00:00
FunctionImportUtils.cpp
GlobalStatus.cpp
GuardUtils.cpp
ImportedFunctionsInliningStatistics.cpp
InjectTLIMappings.cpp
InlineFunction.cpp [Inline] Fix incorrectly dropped noalias metadata 2020-11-18 21:22:50 +01:00
InstructionNamer.cpp Port -instnamer to NPM 2020-10-22 12:08:36 -07:00
IntegerDivision.cpp
LCSSA.cpp [LCSSA] Doc for special treatment of PHIs 2020-10-29 22:50:07 +02:00
LibCallsShrinkWrap.cpp
Local.cpp [Transforms] Use llvm::is_contained (NFC) 2020-11-18 20:42:22 -08:00
LoopPeel.cpp [NFC][SCEV] Refactor monotonic predicate checks to return enums instead of bools 2020-10-29 16:01:25 +07:00
LoopRotationUtils.cpp [Utils] Skip RemoveRedundantDbgInstrs in MergeBlockIntoPredecessor (PR47746) 2020-10-27 10:12:59 -07:00
LoopSimplify.cpp [Transforms] Use pred_empty (NFC) 2020-11-16 22:09:14 -08:00
LoopUnroll.cpp
LoopUnrollAndJam.cpp
LoopUnrollRuntime.cpp
LoopUtils.cpp [ARM] Don't aggressively unroll vector remainder loops 2020-11-10 17:01:31 +00:00
LoopVersioning.cpp [LoopVersioning] Form dedicated exits for versioned loop to preserve simplify form 2020-10-24 21:40:46 +08:00
LowerInvoke.cpp
LowerMemIntrinsics.cpp
LowerSwitch.cpp [Transforms] Use pred_empty (NFC) 2020-11-16 22:09:14 -08:00
MatrixUtils.cpp
Mem2Reg.cpp
MetaRenamer.cpp
ModuleUtils.cpp
NameAnonGlobals.cpp
PredicateInfo.cpp
PromoteMemoryToRegister.cpp [Mem2Reg] Use llvm::count instead of std::count (NFC) 2020-11-07 20:18:47 -08:00
SanitizerStats.cpp
ScalarEvolutionExpander.cpp Reland "[TTI] Add VecPred argument to getCmpSelInstrCost." 2020-11-02 15:39:29 +00:00
SimplifyCFG.cpp [CSSPGO] IR intrinsic for pseudo-probe block instrumentation 2020-11-20 10:39:24 -08:00
SimplifyIndVar.cpp [NFC] Remove comment (commited ahead of time by mistake) 2020-11-19 16:28:34 +07:00
SimplifyLibCalls.cpp
SizeOpts.cpp
SplitModule.cpp
SSAUpdater.cpp
SSAUpdaterBulk.cpp
StripGCRelocates.cpp
StripNonLineTableDebugInfo.cpp
SymbolRewriter.cpp
UnifyFunctionExitNodes.cpp
UnifyLoopExits.cpp
UniqueInternalLinkageNames.cpp Prepend "__uniq" to symbol names hash with -funique-internal-linkage-names. 2020-10-26 14:24:28 -07:00
Utils.cpp
ValueMapper.cpp Linker: Fix linking of byref types 2020-11-17 11:02:04 -05:00
VNCoercion.cpp [GVN] small improvements to comments 2020-11-03 13:21:48 -05:00