Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:32

0001 //===----- MIRFSDiscriminator.h: MIR FS Discriminator Support --0-- c++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file contains the supporting functions for adding Machine level IR
0010 // Flow Sensitive discriminators to the instruction debug information. With
0011 // this, a cloned machine instruction in a different MachineBasicBlock will
0012 // have its own discriminator value. This is done in a MIRAddFSDiscriminators
0013 // pass.
0014 //
0015 //===----------------------------------------------------------------------===//
0016 
0017 #ifndef LLVM_CODEGEN_MIRFSDISCRIMINATOR_H
0018 #define LLVM_CODEGEN_MIRFSDISCRIMINATOR_H
0019 
0020 #include "llvm/ADT/StringRef.h"
0021 #include "llvm/CodeGen/MachineFunction.h"
0022 #include "llvm/CodeGen/MachineFunctionPass.h"
0023 #include "llvm/Support/Discriminator.h"
0024 
0025 #include <cassert>
0026 #include <cstdint>
0027 
0028 namespace llvm {
0029 class MachineFunction;
0030 
0031 using namespace sampleprof;
0032 class MIRAddFSDiscriminators : public MachineFunctionPass {
0033   MachineFunction *MF = nullptr;
0034   FSDiscriminatorPass Pass;
0035   unsigned LowBit;
0036   unsigned HighBit;
0037 
0038 public:
0039   static char ID;
0040   /// PassNum is the sequence number this pass is called, start from 1.
0041   MIRAddFSDiscriminators(FSDiscriminatorPass P = FSDiscriminatorPass::Pass1)
0042       : MachineFunctionPass(ID), Pass(P) {
0043     LowBit = getFSPassBitBegin(P);
0044     HighBit = getFSPassBitEnd(P);
0045     assert(LowBit < HighBit && "HighBit needs to be greater than Lowbit");
0046   }
0047 
0048   StringRef getPassName() const override {
0049     return "Add FS discriminators in MIR";
0050   }
0051 
0052   /// getNumFSBBs() - Return the number of machine BBs that have FS samples.
0053   unsigned getNumFSBBs();
0054 
0055   /// getNumFSSamples() - Return the number of samples that have flow sensitive
0056   /// values.
0057   uint64_t getNumFSSamples();
0058 
0059   /// getMachineFunction - Return the current machine function.
0060   const MachineFunction *getMachineFunction() const { return MF; }
0061 
0062 private:
0063   bool runOnMachineFunction(MachineFunction &) override;
0064 };
0065 
0066 } // namespace llvm
0067 
0068 #endif // LLVM_CODEGEN_MIRFSDISCRIMINATOR_H