comparison lib/IR/Pass.cpp @ 148:63bd29f05246

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 19:46:37 +0900
parents c2174574ed3a
children
comparison
equal deleted inserted replaced
146:3fc4d5c3e21e 148:63bd29f05246
1 //===- Pass.cpp - LLVM Pass Infrastructure Implementation -----------------===// 1 //===- Pass.cpp - LLVM Pass Infrastructure Implementation -----------------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // 4 // See https://llvm.org/LICENSE.txt for license information.
5 // This file is distributed under the University of Illinois Open Source 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 // License. See LICENSE.TXT for details.
7 // 6 //
8 //===----------------------------------------------------------------------===// 7 //===----------------------------------------------------------------------===//
9 // 8 //
10 // This file implements the LLVM Pass infrastructure. It is primarily 9 // This file implements the LLVM Pass infrastructure. It is primarily
11 // responsible with ensuring that passes are executed and batched together 10 // responsible with ensuring that passes are executed and batched together
12 // optimally. 11 // optimally.
13 // 12 //
14 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
15 14
16 #include "llvm/Pass.h" 15 #include "llvm/Pass.h"
16 #include "llvm/Config/llvm-config.h"
17 #include "llvm/IR/Attributes.h" 17 #include "llvm/IR/Attributes.h"
18 #include "llvm/IR/BasicBlock.h" 18 #include "llvm/IR/BasicBlock.h"
19 #include "llvm/IR/Function.h" 19 #include "llvm/IR/Function.h"
20 #include "llvm/IR/IRPrintingPasses.h" 20 #include "llvm/IR/IRPrintingPasses.h"
21 #include "llvm/IR/LLVMContext.h" 21 #include "llvm/IR/LLVMContext.h"
53 53
54 PassManagerType ModulePass::getPotentialPassManagerType() const { 54 PassManagerType ModulePass::getPotentialPassManagerType() const {
55 return PMT_ModulePassManager; 55 return PMT_ModulePassManager;
56 } 56 }
57 57
58 static std::string getDescription(const Module &M) {
59 return "module (" + M.getName().str() + ")";
60 }
61
58 bool ModulePass::skipModule(Module &M) const { 62 bool ModulePass::skipModule(Module &M) const {
59 return !M.getContext().getOptBisect().shouldRunPass(this, M); 63 OptPassGate &Gate = M.getContext().getOptPassGate();
64 return Gate.isEnabled() && !Gate.shouldRunPass(this, getDescription(M));
60 } 65 }
61 66
62 bool Pass::mustPreserveAnalysisID(char &AID) const { 67 bool Pass::mustPreserveAnalysisID(char &AID) const {
63 return Resolver->getAnalysisIfAvailable(&AID, true) != nullptr; 68 return Resolver->getAnalysisIfAvailable(&AID, true) != nullptr;
64 } 69 }
152 157
153 PassManagerType FunctionPass::getPotentialPassManagerType() const { 158 PassManagerType FunctionPass::getPotentialPassManagerType() const {
154 return PMT_FunctionPassManager; 159 return PMT_FunctionPassManager;
155 } 160 }
156 161
162 static std::string getDescription(const Function &F) {
163 return "function (" + F.getName().str() + ")";
164 }
165
157 bool FunctionPass::skipFunction(const Function &F) const { 166 bool FunctionPass::skipFunction(const Function &F) const {
158 if (!F.getContext().getOptBisect().shouldRunPass(this, F)) 167 OptPassGate &Gate = F.getContext().getOptPassGate();
168 if (Gate.isEnabled() && !Gate.shouldRunPass(this, getDescription(F)))
159 return true; 169 return true;
160 170
161 if (F.hasFnAttribute(Attribute::OptimizeNone)) { 171 if (F.hasOptNone()) {
162 DEBUG(dbgs() << "Skipping pass '" << getPassName() << "' on function " 172 LLVM_DEBUG(dbgs() << "Skipping pass '" << getPassName() << "' on function "
163 << F.getName() << "\n"); 173 << F.getName() << "\n");
164 return true; 174 return true;
165 } 175 }
166 return false; 176 return false;
167 } 177 }
168 178
181 } 191 }
182 192
183 bool BasicBlockPass::doFinalization(Function &) { 193 bool BasicBlockPass::doFinalization(Function &) {
184 // By default, don't do anything. 194 // By default, don't do anything.
185 return false; 195 return false;
196 }
197
198 static std::string getDescription(const BasicBlock &BB) {
199 return "basic block (" + BB.getName().str() + ") in function (" +
200 BB.getParent()->getName().str() + ")";
186 } 201 }
187 202
188 bool BasicBlockPass::skipBasicBlock(const BasicBlock &BB) const { 203 bool BasicBlockPass::skipBasicBlock(const BasicBlock &BB) const {
189 const Function *F = BB.getParent(); 204 const Function *F = BB.getParent();
190 if (!F) 205 if (!F)
191 return false; 206 return false;
192 if (!F->getContext().getOptBisect().shouldRunPass(this, BB)) 207 OptPassGate &Gate = F->getContext().getOptPassGate();
208 if (Gate.isEnabled() && !Gate.shouldRunPass(this, getDescription(BB)))
193 return true; 209 return true;
194 if (F->hasFnAttribute(Attribute::OptimizeNone)) { 210 if (F->hasOptNone()) {
195 // Report this only once per function. 211 // Report this only once per function.
196 if (&BB == &F->getEntryBlock()) 212 if (&BB == &F->getEntryBlock())
197 DEBUG(dbgs() << "Skipping pass '" << getPassName() 213 LLVM_DEBUG(dbgs() << "Skipping pass '" << getPassName()
198 << "' on function " << F->getName() << "\n"); 214 << "' on function " << F->getName() << "\n");
199 return true; 215 return true;
200 } 216 }
201 return false; 217 return false;
202 } 218 }
203 219