| 1 | //===- MachineUniformityAnalysis.h ---------------------------*- 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 | /// \file |
| 10 | /// \brief Machine IR instance of the generic uniformity analysis |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CODEGEN_MACHINEUNIFORMITYANALYSIS_H |
| 15 | #define LLVM_CODEGEN_MACHINEUNIFORMITYANALYSIS_H |
| 16 | |
| 17 | #include "llvm/ADT/GenericUniformityInfo.h" |
| 18 | #include "llvm/CodeGen/MachineCycleAnalysis.h" |
| 19 | #include "llvm/CodeGen/MachineDominators.h" |
| 20 | #include "llvm/CodeGen/MachinePassManager.h" |
| 21 | #include "llvm/CodeGen/MachineSSAContext.h" |
| 22 | |
| 23 | namespace llvm { |
| 24 | |
| 25 | extern template class GenericUniformityInfo<MachineSSAContext>; |
| 26 | using MachineUniformityInfo = GenericUniformityInfo<MachineSSAContext>; |
| 27 | |
| 28 | /// \brief Compute uniformity information for a Machine IR function. |
| 29 | /// |
| 30 | /// If \p HasBranchDivergence is false, produces a dummy result which assumes |
| 31 | /// everything is uniform. |
| 32 | MachineUniformityInfo computeMachineUniformityInfo( |
| 33 | MachineFunction &F, const MachineCycleInfo &cycleInfo, |
| 34 | const MachineDominatorTree &domTree, bool HasBranchDivergence); |
| 35 | |
| 36 | /// Legacy analysis pass which computes a \ref MachineUniformityInfo. |
| 37 | class MachineUniformityAnalysisPass : public MachineFunctionPass { |
| 38 | MachineUniformityInfo UI; |
| 39 | |
| 40 | public: |
| 41 | static char ID; |
| 42 | |
| 43 | MachineUniformityAnalysisPass(); |
| 44 | |
| 45 | MachineUniformityInfo &getUniformityInfo() { return UI; } |
| 46 | const MachineUniformityInfo &getUniformityInfo() const { return UI; } |
| 47 | |
| 48 | bool runOnMachineFunction(MachineFunction &F) override; |
| 49 | void getAnalysisUsage(AnalysisUsage &AU) const override; |
| 50 | void print(raw_ostream &OS, const Module *M = nullptr) const override; |
| 51 | |
| 52 | // TODO: verify analysis |
| 53 | }; |
| 54 | |
| 55 | class MachineUniformityAnalysis |
| 56 | : public AnalysisInfoMixin<MachineUniformityAnalysis> { |
| 57 | friend AnalysisInfoMixin<MachineUniformityAnalysis>; |
| 58 | static AnalysisKey Key; |
| 59 | |
| 60 | public: |
| 61 | using Result = MachineUniformityInfo; |
| 62 | Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM); |
| 63 | }; |
| 64 | |
| 65 | class MachineUniformityPrinterPass |
| 66 | : public PassInfoMixin<MachineUniformityAnalysis> { |
| 67 | raw_ostream &OS; |
| 68 | |
| 69 | public: |
| 70 | explicit MachineUniformityPrinterPass(raw_ostream &OS) : OS(OS) {} |
| 71 | PreservedAnalyses run(MachineFunction &MF, |
| 72 | MachineFunctionAnalysisManager &MFAM); |
| 73 | static bool isRequired() { return true; } |
| 74 | }; |
| 75 | |
| 76 | } // namespace llvm |
| 77 | |
| 78 | #endif // LLVM_CODEGEN_MACHINEUNIFORMITYANALYSIS_H |
| 79 |