1f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===- llvm/PassAnalysisSupport.h - Analysis Pass Support code --*- C++ -*-===// 2f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// 3f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// The LLVM Compiler Infrastructure 4f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// 5f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// This file is distributed under the University of Illinois Open Source 6f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// License. See LICENSE.TXT for details. 7f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// 8f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===// 9f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// 10f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// This file defines stuff that is used to define and "use" Analysis Passes. 11f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// This file is automatically #included by Pass.h, so: 12f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// 13f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// NO .CPP FILES SHOULD INCLUDE THIS FILE DIRECTLY 14f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// 15f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// Instead, #include Pass.h 16f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// 17f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===// 18f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 19f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#ifndef LLVM_PASSANALYSISSUPPORT_H 20f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#define LLVM_PASSANALYSISSUPPORT_H 21f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 22f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/ADT/SmallVector.h" 23f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/Pass.h" 24f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <vector> 25f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 26f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotnamespace llvm { 27f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass StringRef; 28f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 29f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===// 30f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// Represent the analysis usage information of a pass. This tracks analyses 31f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// that the pass REQUIRES (must be available when the pass runs), REQUIRES 32f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// TRANSITIVE (must be available throughout the lifetime of the pass), and 33f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// analyses that the pass PRESERVES (the pass does not invalidate the results 34f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// of these analyses). This information is provided by a pass to the Pass 35f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// infrastructure through the getAnalysisUsage virtual function. 36f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// 37f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass AnalysisUsage { 38f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic: 39f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot typedef SmallVectorImpl<AnalysisID> VectorType; 40f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 41f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate: 42f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Sets of analyses required and preserved by a pass 43f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // TODO: It's not clear that SmallVector is an appropriate data structure for 44f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // this usecase. The sizes were picked to minimize wasted space, but are 45f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // otherwise fairly meaningless. 46f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot SmallVector<AnalysisID, 8> Required; 47f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot SmallVector<AnalysisID, 2> RequiredTransitive; 48f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot SmallVector<AnalysisID, 2> Preserved; 49f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot SmallVector<AnalysisID, 0> Used; 50f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool PreservesAll; 51f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 52f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic: 53f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisUsage() : PreservesAll(false) {} 54f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 55f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot ///@{ 56f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Add the specified ID to the required set of the usage info for a pass. 57f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisUsage &addRequiredID(const void *ID); 58f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisUsage &addRequiredID(char &ID); 59f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot template<class PassClass> 60f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisUsage &addRequired() { 61f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return addRequiredID(PassClass::ID); 62f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 63f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 64f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisUsage &addRequiredTransitiveID(char &ID); 65f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot template<class PassClass> 66f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisUsage &addRequiredTransitive() { 67f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return addRequiredTransitiveID(PassClass::ID); 68f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 69f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot ///@} 70f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 71f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot ///@{ 72f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Add the specified ID to the set of analyses preserved by this pass. 73f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisUsage &addPreservedID(const void *ID) { 74f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Preserved.push_back(ID); 75f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return *this; 76f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 77f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisUsage &addPreservedID(char &ID) { 78f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Preserved.push_back(&ID); 79f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return *this; 80f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 81f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Add the specified Pass class to the set of analyses preserved by this pass. 82f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot template<class PassClass> 83f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisUsage &addPreserved() { 84f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Preserved.push_back(&PassClass::ID); 85f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return *this; 86f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 87f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot ///@} 88f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 89f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot ///@{ 90f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Add the specified ID to the set of analyses used by this pass if they are 91f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// available.. 92f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisUsage &addUsedIfAvailableID(const void *ID) { 93f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Used.push_back(ID); 94f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return *this; 95f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 96f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisUsage &addUsedIfAvailableID(char &ID) { 97f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Used.push_back(&ID); 98f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return *this; 99f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 100f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Add the specified Pass class to the set of analyses used by this pass. 101f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot template<class PassClass> 102f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisUsage &addUsedIfAvailable() { 103f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Used.push_back(&PassClass::ID); 104f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return *this; 105f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 106f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot ///@} 107f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 108f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Add the Pass with the specified argument string to the set of analyses 109f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// preserved by this pass. If no such Pass exists, do nothing. This can be 110f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// useful when a pass is trivially preserved, but may not be linked in. Be 111f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// careful about spelling! 112f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisUsage &addPreserved(StringRef Arg); 113f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 114f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Set by analyses that do not transform their input at all 115f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setPreservesAll() { PreservesAll = true; } 116f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 117f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Determine whether a pass said it does not transform its input at all 118f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot bool getPreservesAll() const { return PreservesAll; } 119f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 120f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// This function should be called by the pass, iff they do not: 121f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 122f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 1. Add or remove basic blocks from the function 123f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 2. Modify terminator instructions in any way. 124f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 125f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// This function annotates the AnalysisUsage info object to say that analyses 126f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// that only depend on the CFG are preserved by this pass. 127f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// 128f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void setPreservesCFG(); 129f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 130f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const VectorType &getRequiredSet() const { return Required; } 131f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const VectorType &getRequiredTransitiveSet() const { 132f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return RequiredTransitive; 133f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 134f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const VectorType &getPreservedSet() const { return Preserved; } 135f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const VectorType &getUsedSet() const { return Used; } 136f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}; 137f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 138f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===// 139f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// AnalysisResolver - Simple interface used by Pass objects to pull all 140f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// analysis information out of pass manager that is responsible to manage 141f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// the pass. 142f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// 143f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass PMDataManager; 144f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass AnalysisResolver { 145f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate: 146f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisResolver() = delete; 147f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 148f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic: 149f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot explicit AnalysisResolver(PMDataManager &P) : PM(P) { } 150f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 151f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot inline PMDataManager &getPMDataManager() { return PM; } 152f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 153f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Find pass that is implementing PI. 154f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Pass *findImplPass(AnalysisID PI) { 155f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Pass *ResultPass = nullptr; 156f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot for (const auto &AnalysisImpl : AnalysisImpls) { 157f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot if (AnalysisImpl.first == PI) { 158f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot ResultPass = AnalysisImpl.second; 159f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot break; 160f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 161f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 162f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return ResultPass; 163f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 164f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 165f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Find pass that is implementing PI. Initialize pass for Function F. 166f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Pass *findImplPass(Pass *P, AnalysisID PI, Function &F); 167f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 168f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void addAnalysisImplsPair(AnalysisID PI, Pass *P) { 169f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot if (findImplPass(PI) == P) 170f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return; 171f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot std::pair<AnalysisID, Pass*> pir = std::make_pair(PI,P); 172f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisImpls.push_back(pir); 173f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 174f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 175f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Clear cache that is used to connect a pass to the the analysis (PassInfo). 176f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot void clearAnalysisImpls() { 177f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot AnalysisImpls.clear(); 178f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot } 179f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 180f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// Return analysis result or null if it doesn't exist. 181f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Pass *getAnalysisIfAvailable(AnalysisID ID, bool Direction) const; 182f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 183f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate: 184f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// This keeps track of which passes implements the interfaces that are 185f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// required by the current pass (to implement getAnalysis()). 186f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot std::vector<std::pair<AnalysisID, Pass*> > AnalysisImpls; 187f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 188f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot /// PassManager that is used to resolve analysis info 189f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot PMDataManager &PM; 190f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}; 191f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 192f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to 193f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// get analysis information that might be around, for example to update it. 194f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// This is different than getAnalysis in that it can fail (if the analysis 195f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// results haven't been computed), so should only be used if you can handle 196f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// the case when the analysis is not available. This method is often used by 197f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// transformation APIs to update analysis results for a pass automatically as 198f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// the transform is performed. 199f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// 200f3014761c955345d6e05491608e73228d014afbandroid-build-team Robottemplate<typename AnalysisType> 201f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotAnalysisType *Pass::getAnalysisIfAvailable() const { 202f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot assert(Resolver && "Pass not resident in a PassManager object!"); 203f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 204f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot const void *PI = &AnalysisType::ID; 205f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 206f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Pass *ResultPass = Resolver->getAnalysisIfAvailable(PI, true); 207f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot if (!ResultPass) return nullptr; 208f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 209f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // Because the AnalysisType may not be a subclass of pass (for 210f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // AnalysisGroups), we use getAdjustedAnalysisPointer here to potentially 211f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // adjust the return pointer (because the class may multiply inherit, once 212f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // from pass, once from AnalysisType). 213f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return (AnalysisType*)ResultPass->getAdjustedAnalysisPointer(PI); 214f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot} 215f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 216f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// getAnalysis<AnalysisType>() - This function is used by subclasses to get 217f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// to the analysis information that they claim to use by overriding the 218f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// getAnalysisUsage function. 219f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// 220f3014761c955345d6e05491608e73228d014afbandroid-build-team Robottemplate<typename AnalysisType> 221f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotAnalysisType &Pass::getAnalysis() const { 222f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot assert(Resolver && "Pass has not been inserted into a PassManager object!"); 223f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return getAnalysisID<AnalysisType>(&AnalysisType::ID); 224f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot} 225f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 226f3014761c955345d6e05491608e73228d014afbandroid-build-team Robottemplate<typename AnalysisType> 227f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotAnalysisType &Pass::getAnalysisID(AnalysisID PI) const { 228f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot assert(PI && "getAnalysis for unregistered pass!"); 229f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot assert(Resolver&&"Pass has not been inserted into a PassManager object!"); 230f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // PI *must* appear in AnalysisImpls. Because the number of passes used 231f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // should be a small number, we just do a linear search over a (dense) 232f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // vector. 233f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Pass *ResultPass = Resolver->findImplPass(PI); 234f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot assert (ResultPass && 235f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot "getAnalysis*() called on an analysis that was not " 236f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot "'required' by pass!"); 237f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 238f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // Because the AnalysisType may not be a subclass of pass (for 239f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // AnalysisGroups), we use getAdjustedAnalysisPointer here to potentially 240f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // adjust the return pointer (because the class may multiply inherit, once 241f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // from pass, once from AnalysisType). 242f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return *(AnalysisType*)ResultPass->getAdjustedAnalysisPointer(PI); 243f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot} 244f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 245f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// getAnalysis<AnalysisType>() - This function is used by subclasses to get 246f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// to the analysis information that they claim to use by overriding the 247f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// getAnalysisUsage function. 248f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// 249f3014761c955345d6e05491608e73228d014afbandroid-build-team Robottemplate<typename AnalysisType> 250f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotAnalysisType &Pass::getAnalysis(Function &F) { 251f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot assert(Resolver &&"Pass has not been inserted into a PassManager object!"); 252f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 253f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return getAnalysisID<AnalysisType>(&AnalysisType::ID, F); 254f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot} 255f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 256f3014761c955345d6e05491608e73228d014afbandroid-build-team Robottemplate<typename AnalysisType> 257f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotAnalysisType &Pass::getAnalysisID(AnalysisID PI, Function &F) { 258f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot assert(PI && "getAnalysis for unregistered pass!"); 259f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot assert(Resolver && "Pass has not been inserted into a PassManager object!"); 260f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // PI *must* appear in AnalysisImpls. Because the number of passes used 261f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // should be a small number, we just do a linear search over a (dense) 262f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // vector. 263f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Pass *ResultPass = Resolver->findImplPass(this, PI, F); 264f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot assert(ResultPass && "Unable to find requested analysis info"); 265f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 266f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // Because the AnalysisType may not be a subclass of pass (for 267f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // AnalysisGroups), we use getAdjustedAnalysisPointer here to potentially 268f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // adjust the return pointer (because the class may multiply inherit, once 269f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot // from pass, once from AnalysisType). 270f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot return *(AnalysisType*)ResultPass->getAdjustedAnalysisPointer(PI); 271f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot} 272f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 273f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot} // End llvm namespace 274f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot 275f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#endif 276