1 //===----- MIRFSDiscriminator.h: MIR FS Discriminator Support --0-- c++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file contains the supporting functions for adding Machine level IR 10 // Flow Sensitive discriminators to the instruction debug information. With 11 // this, a cloned machine instruction in a different MachineBasicBlock will 12 // have its own discriminator value. This is done in a MIRAddFSDiscriminators 13 // pass. 14 // 15 //===----------------------------------------------------------------------===// 16 17 #ifndef LLVM_CODEGEN_MIRFSDISCRIMINATOR_H 18 #define LLVM_CODEGEN_MIRFSDISCRIMINATOR_H 19 20 #include "llvm/ADT/StringRef.h" 21 #include "llvm/CodeGen/MachineFunction.h" 22 #include "llvm/CodeGen/MachineFunctionPass.h" 23 #include "llvm/Support/Discriminator.h" 24 25 #include <cassert> 26 #include <cstdint> 27 28 namespace llvm { 29 class MachineFunction; 30 31 using namespace sampleprof; 32 class MIRAddFSDiscriminators : public MachineFunctionPass { 33 MachineFunction *MF = nullptr; 34 FSDiscriminatorPass Pass; 35 unsigned LowBit; 36 unsigned HighBit; 37 38 public: 39 static char ID; 40 /// PassNum is the sequence number this pass is called, start from 1. 41 MIRAddFSDiscriminators(FSDiscriminatorPass P = FSDiscriminatorPass::Pass1) 42 : MachineFunctionPass(ID), Pass(P) { 43 LowBit = getFSPassBitBegin(P); 44 HighBit = getFSPassBitEnd(P); 45 assert(LowBit < HighBit && "HighBit needs to be greater than Lowbit"); 46 } 47 48 StringRef getPassName() const override { 49 return "Add FS discriminators in MIR"; 50 } 51 52 /// getNumFSBBs() - Return the number of machine BBs that have FS samples. 53 unsigned getNumFSBBs(); 54 55 /// getNumFSSamples() - Return the number of samples that have flow sensitive 56 /// values. 57 uint64_t getNumFSSamples(); 58 59 /// getMachineFunction - Return the current machine function. 60 const MachineFunction *getMachineFunction() const { return MF; } 61 62 private: 63 bool runOnMachineFunction(MachineFunction &) override; 64 }; 65 66 } // namespace llvm 67 68 #endif // LLVM_CODEGEN_MIRFSDISCRIMINATOR_H 69