llvm/llvm/lib/IR/ProfDataUtils.cpp

//===- ProfDataUtils.cpp - Utility functions for MD_prof Metadata ---------===//
//
// 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 utilities for working with Profiling Metadata.
//
//===----------------------------------------------------------------------===//

#include "llvm/IR/ProfDataUtils.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Twine.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/ProfDataUtils.h"
#include "llvm/Support/BranchProbability.h"
#include "llvm/Support/CommandLine.h"

usingnamespacellvm;

namespace {

// MD_prof nodes have the following layout
//
// In general:
// { String name,         Array of i32   }
//
// In terms of Types:
// { MDString,            [i32, i32, ...]}
//
// Concretely for Branch Weights
// { "branch_weights",    [i32 1, i32 10000]}
//
// We maintain some constants here to ensure that we access the branch weights
// correctly, and can change the behavior in the future if the layout changes

// the minimum number of operands for MD_prof nodes with branch weights
constexpr unsigned MinBWOps =;

// the minimum number of operands for MD_prof nodes with value profiles
constexpr unsigned MinVPOps =;

// We may want to add support for other MD_prof types, so provide an abstraction
// for checking the metadata type.
bool isTargetMD(const MDNode *ProfData, const char *Name, unsigned MinOps) {}

template <typename T,
          typename = typename std::enable_if<std::is_arithmetic_v<T>>>
static void extractFromBranchWeightMD(const MDNode *ProfileData,
                                      SmallVectorImpl<T> &Weights) {}

} // namespace

namespace llvm {

bool hasProfMD(const Instruction &I) {}

bool isBranchWeightMD(const MDNode *ProfileData) {}

bool isValueProfileMD(const MDNode *ProfileData) {}

bool hasBranchWeightMD(const Instruction &I) {}

bool hasCountTypeMD(const Instruction &I) {}

bool hasValidBranchWeightMD(const Instruction &I) {}

bool hasBranchWeightOrigin(const Instruction &I) {}

bool hasBranchWeightOrigin(const MDNode *ProfileData) {}

unsigned getBranchWeightOffset(const MDNode *ProfileData) {}

unsigned getNumBranchWeights(const MDNode &ProfileData) {}

MDNode *getBranchWeightMDNode(const Instruction &I) {}

MDNode *getValidBranchWeightMDNode(const Instruction &I) {}

void extractFromBranchWeightMD32(const MDNode *ProfileData,
                                 SmallVectorImpl<uint32_t> &Weights) {}

void extractFromBranchWeightMD64(const MDNode *ProfileData,
                                 SmallVectorImpl<uint64_t> &Weights) {}

bool extractBranchWeights(const MDNode *ProfileData,
                          SmallVectorImpl<uint32_t> &Weights) {}

bool extractBranchWeights(const Instruction &I,
                          SmallVectorImpl<uint32_t> &Weights) {}

bool extractBranchWeights(const Instruction &I, uint64_t &TrueVal,
                          uint64_t &FalseVal) {}

bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalVal) {}

bool extractProfTotalWeight(const Instruction &I, uint64_t &TotalVal) {}

void setBranchWeights(Instruction &I, ArrayRef<uint32_t> Weights,
                      bool IsExpected) {}

void scaleProfData(Instruction &I, uint64_t S, uint64_t T) {}

} // namespace llvm