[all-commits] [llvm/llvm-project] e7749d: [misexpect] Re-implement MisExpect Diagnostics

Paul Kirth via All-commits all-commits at lists.llvm.org
Thu Mar 17 16:48:04 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e7749d4713a5ec886011ceb0fc821c6723061724
      https://github.com/llvm/llvm-project/commit/e7749d4713a5ec886011ceb0fc821c6723061724
  Author: Paul Kirth <paulkirth at google.com>
  Date:   2022-03-17 (Thu, 17 Mar 2022)

  Changed paths:
    A clang/docs/MisExpect.rst
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/CodeGenOptions.def
    M clang/include/clang/Basic/CodeGenOptions.h
    M clang/include/clang/Basic/DiagnosticDriverKinds.td
    M clang/include/clang/Basic/DiagnosticFrontendKinds.td
    M clang/include/clang/Basic/DiagnosticGroups.td
    M clang/include/clang/Driver/Options.td
    M clang/lib/CodeGen/BackendUtil.cpp
    M clang/lib/CodeGen/CodeGenAction.cpp
    M clang/lib/Frontend/CompilerInvocation.cpp
    A clang/test/Profile/Inputs/misexpect-branch-nonconst-expect-arg.proftext
    A clang/test/Profile/Inputs/misexpect-branch.proftext
    A clang/test/Profile/Inputs/misexpect-switch-default-only.proftext
    A clang/test/Profile/Inputs/misexpect-switch-default.proftext
    A clang/test/Profile/Inputs/misexpect-switch-nonconst.proftext
    A clang/test/Profile/Inputs/misexpect-switch.proftext
    A clang/test/Profile/misexpect-branch-cold.c
    A clang/test/Profile/misexpect-branch-nonconst-expected-val.c
    A clang/test/Profile/misexpect-branch-unpredictable.c
    A clang/test/Profile/misexpect-branch.c
    A clang/test/Profile/misexpect-switch-default.c
    A clang/test/Profile/misexpect-switch-nonconst.c
    A clang/test/Profile/misexpect-switch-only-default-case.c
    A clang/test/Profile/misexpect-switch.c
    A llvm/docs/MisExpect.rst
    M llvm/include/llvm/IR/DiagnosticInfo.h
    M llvm/include/llvm/IR/LLVMContext.h
    M llvm/include/llvm/Target/TargetOptions.h
    A llvm/include/llvm/Transforms/Utils/MisExpect.h
    M llvm/lib/IR/DiagnosticInfo.cpp
    M llvm/lib/IR/LLVMContext.cpp
    M llvm/lib/IR/LLVMContextImpl.h
    M llvm/lib/Transforms/IPO/SampleProfile.cpp
    M llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
    M llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
    M llvm/lib/Transforms/Utils/CMakeLists.txt
    A llvm/lib/Transforms/Utils/MisExpect.cpp
    A llvm/test/Transforms/PGOProfile/Inputs/misexpect-branch-correct.proftext
    A llvm/test/Transforms/PGOProfile/Inputs/misexpect-branch-threshold.proftext
    A llvm/test/Transforms/PGOProfile/Inputs/misexpect-branch.proftext
    A llvm/test/Transforms/PGOProfile/Inputs/misexpect-switch-correct.proftext
    A llvm/test/Transforms/PGOProfile/Inputs/misexpect-switch.proftext
    A llvm/test/Transforms/PGOProfile/misexpect-branch-correct.ll
    A llvm/test/Transforms/PGOProfile/misexpect-branch-stripped.ll
    A llvm/test/Transforms/PGOProfile/misexpect-branch-unpredictable.ll
    A llvm/test/Transforms/PGOProfile/misexpect-branch.ll
    A llvm/test/Transforms/PGOProfile/misexpect-switch-default.ll
    A llvm/test/Transforms/PGOProfile/misexpect-switch.ll

  Log Message:
  -----------
  [misexpect] Re-implement MisExpect Diagnostics

Reimplements MisExpect diagnostics from D66324 to reconstruct its
original checking methodology only using MD_prof branch_weights
metadata.

New checks rely on 2 invariants:

1) For frontend instrumentation, MD_prof branch_weights will always be
   populated before llvm.expect intrinsics are lowered.

2) for IR and sample profiling, llvm.expect intrinsics will always be
   lowered before branch_weights are populated from the IR profiles.

These invariants allow the checking to assume how the existing branch
weights are populated depending on the profiling method used, and emit
the correct diagnostics. If these invariants are ever invalidated, the
MisExpect related checks would need to be updated, potentially by
re-introducing MD_misexpect metadata, and ensuring it always will be
transformed the same way as branch_weights in other optimization passes.

Frontend based profiling is now enabled without using LLVM Args, by
introducing a new CodeGen option, and checking if the -Wmisexpect flag
has been passed on the command line.

Differential Revision: https://reviews.llvm.org/D115907




More information about the All-commits mailing list