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/Analysis/ProfileSummaryInfo.h" 21 #include "llvm/CodeGen/MachineBasicBlock.h" 22 #include "llvm/CodeGen/MachineBlockFrequencyInfo.h" 23 #include "llvm/CodeGen/MachineBranchProbabilityInfo.h" 24 #include "llvm/CodeGen/MachineDominators.h" 25 #include "llvm/CodeGen/MachineFunction.h" 26 #include "llvm/CodeGen/MachineFunctionPass.h" 27 #include "llvm/CodeGen/MachineInstr.h" 28 #include "llvm/CodeGen/MachineLoopInfo.h" 29 #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h" 30 #include "llvm/CodeGen/MachinePostDominators.h" 31 #include "llvm/CodeGen/Passes.h" 32 #include "llvm/IR/DebugInfoMetadata.h" 33 #include "llvm/IR/Function.h" 34 #include "llvm/IR/Module.h" 35 #include "llvm/InitializePasses.h" 36 #include "llvm/ProfileData/InstrProf.h" 37 #include "llvm/ProfileData/SampleProf.h" 38 #include "llvm/ProfileData/SampleProfReader.h" 39 40 #include <cassert> 41 42 namespace llvm { 43 44 class MIRAddFSDiscriminators : public MachineFunctionPass { 45 MachineFunction *MF; 46 unsigned LowBit; 47 unsigned HighBit; 48 49 public: 50 static char ID; 51 /// FS bits that will be used in this pass (numbers are 0 based and 52 /// inclusive). 53 MIRAddFSDiscriminators(unsigned LowBit = 0, unsigned HighBit = 0) MachineFunctionPass(ID)54 : MachineFunctionPass(ID), LowBit(LowBit), HighBit(HighBit) { 55 assert(LowBit < HighBit && "HighBit needs to be greater than Lowbit"); 56 } 57 58 /// getNumFSBBs() - Return the number of machine BBs that have FS samples. 59 unsigned getNumFSBBs(); 60 61 /// getNumFSSamples() - Return the number of samples that have flow sensitive 62 /// values. 63 uint64_t getNumFSSamples(); 64 65 /// getMachineFunction - Return the current machine function. getMachineFunction()66 const MachineFunction *getMachineFunction() const { return MF; } 67 68 private: 69 bool runOnMachineFunction(MachineFunction &) override; 70 }; 71 72 } // namespace llvm 73 74 #endif // LLVM_CODEGEN_MIRFSDISCRIMINATOR_H 75