diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/libs/llvm12/lib/IR/PseudoProbe.cpp | |
parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) | |
download | ydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/llvm12/lib/IR/PseudoProbe.cpp')
-rw-r--r-- | contrib/libs/llvm12/lib/IR/PseudoProbe.cpp | 198 |
1 files changed, 99 insertions, 99 deletions
diff --git a/contrib/libs/llvm12/lib/IR/PseudoProbe.cpp b/contrib/libs/llvm12/lib/IR/PseudoProbe.cpp index 24f38b8888..80d2963938 100644 --- a/contrib/libs/llvm12/lib/IR/PseudoProbe.cpp +++ b/contrib/libs/llvm12/lib/IR/PseudoProbe.cpp @@ -1,99 +1,99 @@ -//===- PseudoProbe.cpp - Pseudo Probe Helpers -----------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file implements the helpers to manipulate pseudo probe IR intrinsic -// calls. -// -//===----------------------------------------------------------------------===// - -#include "llvm/IR/PseudoProbe.h" -#include "llvm/IR/DebugInfoMetadata.h" -#include "llvm/IR/IRBuilder.h" -#include "llvm/IR/Instruction.h" - -using namespace llvm; - -namespace llvm { - -Optional<PseudoProbe> extractProbeFromDiscriminator(const Instruction &Inst) { - assert(isa<CallBase>(&Inst) && !isa<IntrinsicInst>(&Inst) && - "Only call instructions should have pseudo probe encodes as their " - "Dwarf discriminators"); - if (const DebugLoc &DLoc = Inst.getDebugLoc()) { - const DILocation *DIL = DLoc; - auto Discriminator = DIL->getDiscriminator(); - if (DILocation::isPseudoProbeDiscriminator(Discriminator)) { - PseudoProbe Probe; - Probe.Id = - PseudoProbeDwarfDiscriminator::extractProbeIndex(Discriminator); - Probe.Type = - PseudoProbeDwarfDiscriminator::extractProbeType(Discriminator); - Probe.Attr = - PseudoProbeDwarfDiscriminator::extractProbeAttributes(Discriminator); - Probe.Factor = - PseudoProbeDwarfDiscriminator::extractProbeFactor(Discriminator) / - (float)PseudoProbeDwarfDiscriminator::FullDistributionFactor; - return Probe; - } - } - return None; -} - -Optional<PseudoProbe> extractProbe(const Instruction &Inst) { - if (const auto *II = dyn_cast<PseudoProbeInst>(&Inst)) { - PseudoProbe Probe; - Probe.Id = II->getIndex()->getZExtValue(); - Probe.Type = (uint32_t)PseudoProbeType::Block; - Probe.Attr = II->getAttributes()->getZExtValue(); - Probe.Factor = II->getFactor()->getZExtValue() / - (float)PseudoProbeFullDistributionFactor; - return Probe; - } - - if (isa<CallBase>(&Inst) && !isa<IntrinsicInst>(&Inst)) - return extractProbeFromDiscriminator(Inst); - - return None; -} - -void setProbeDistributionFactor(Instruction &Inst, float Factor) { - assert(Factor >= 0 && Factor <= 1 && - "Distribution factor must be in [0, 1.0]"); - if (auto *II = dyn_cast<PseudoProbeInst>(&Inst)) { - IRBuilder<> Builder(&Inst); - uint64_t IntFactor = PseudoProbeFullDistributionFactor; - if (Factor < 1) - IntFactor *= Factor; - auto OrigFactor = II->getFactor()->getZExtValue(); - if (IntFactor != OrigFactor) - II->replaceUsesOfWith(II->getFactor(), Builder.getInt64(IntFactor)); - } else if (isa<CallBase>(&Inst) && !isa<IntrinsicInst>(&Inst)) { - if (const DebugLoc &DLoc = Inst.getDebugLoc()) { - const DILocation *DIL = DLoc; - auto Discriminator = DIL->getDiscriminator(); - if (DILocation::isPseudoProbeDiscriminator(Discriminator)) { - auto Index = - PseudoProbeDwarfDiscriminator::extractProbeIndex(Discriminator); - auto Type = - PseudoProbeDwarfDiscriminator::extractProbeType(Discriminator); - auto Attr = PseudoProbeDwarfDiscriminator::extractProbeAttributes( - Discriminator); - // Round small factors to 0 to avoid over-counting. - uint32_t IntFactor = - PseudoProbeDwarfDiscriminator::FullDistributionFactor; - if (Factor < 1) - IntFactor *= Factor; - uint32_t V = PseudoProbeDwarfDiscriminator::packProbeData( - Index, Type, Attr, IntFactor); - DIL = DIL->cloneWithDiscriminator(V); - Inst.setDebugLoc(DIL); - } - } - } -} -} // namespace llvm +//===- PseudoProbe.cpp - Pseudo Probe Helpers -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements the helpers to manipulate pseudo probe IR intrinsic +// calls. +// +//===----------------------------------------------------------------------===// + +#include "llvm/IR/PseudoProbe.h" +#include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/Instruction.h" + +using namespace llvm; + +namespace llvm { + +Optional<PseudoProbe> extractProbeFromDiscriminator(const Instruction &Inst) { + assert(isa<CallBase>(&Inst) && !isa<IntrinsicInst>(&Inst) && + "Only call instructions should have pseudo probe encodes as their " + "Dwarf discriminators"); + if (const DebugLoc &DLoc = Inst.getDebugLoc()) { + const DILocation *DIL = DLoc; + auto Discriminator = DIL->getDiscriminator(); + if (DILocation::isPseudoProbeDiscriminator(Discriminator)) { + PseudoProbe Probe; + Probe.Id = + PseudoProbeDwarfDiscriminator::extractProbeIndex(Discriminator); + Probe.Type = + PseudoProbeDwarfDiscriminator::extractProbeType(Discriminator); + Probe.Attr = + PseudoProbeDwarfDiscriminator::extractProbeAttributes(Discriminator); + Probe.Factor = + PseudoProbeDwarfDiscriminator::extractProbeFactor(Discriminator) / + (float)PseudoProbeDwarfDiscriminator::FullDistributionFactor; + return Probe; + } + } + return None; +} + +Optional<PseudoProbe> extractProbe(const Instruction &Inst) { + if (const auto *II = dyn_cast<PseudoProbeInst>(&Inst)) { + PseudoProbe Probe; + Probe.Id = II->getIndex()->getZExtValue(); + Probe.Type = (uint32_t)PseudoProbeType::Block; + Probe.Attr = II->getAttributes()->getZExtValue(); + Probe.Factor = II->getFactor()->getZExtValue() / + (float)PseudoProbeFullDistributionFactor; + return Probe; + } + + if (isa<CallBase>(&Inst) && !isa<IntrinsicInst>(&Inst)) + return extractProbeFromDiscriminator(Inst); + + return None; +} + +void setProbeDistributionFactor(Instruction &Inst, float Factor) { + assert(Factor >= 0 && Factor <= 1 && + "Distribution factor must be in [0, 1.0]"); + if (auto *II = dyn_cast<PseudoProbeInst>(&Inst)) { + IRBuilder<> Builder(&Inst); + uint64_t IntFactor = PseudoProbeFullDistributionFactor; + if (Factor < 1) + IntFactor *= Factor; + auto OrigFactor = II->getFactor()->getZExtValue(); + if (IntFactor != OrigFactor) + II->replaceUsesOfWith(II->getFactor(), Builder.getInt64(IntFactor)); + } else if (isa<CallBase>(&Inst) && !isa<IntrinsicInst>(&Inst)) { + if (const DebugLoc &DLoc = Inst.getDebugLoc()) { + const DILocation *DIL = DLoc; + auto Discriminator = DIL->getDiscriminator(); + if (DILocation::isPseudoProbeDiscriminator(Discriminator)) { + auto Index = + PseudoProbeDwarfDiscriminator::extractProbeIndex(Discriminator); + auto Type = + PseudoProbeDwarfDiscriminator::extractProbeType(Discriminator); + auto Attr = PseudoProbeDwarfDiscriminator::extractProbeAttributes( + Discriminator); + // Round small factors to 0 to avoid over-counting. + uint32_t IntFactor = + PseudoProbeDwarfDiscriminator::FullDistributionFactor; + if (Factor < 1) + IntFactor *= Factor; + uint32_t V = PseudoProbeDwarfDiscriminator::packProbeData( + Index, Type, Attr, IntFactor); + DIL = DIL->cloneWithDiscriminator(V); + Inst.setDebugLoc(DIL); + } + } + } +} +} // namespace llvm |