blob: f6cb36e1a2060c8e543af92b3faf3d9b7afeaa22 [file] [log] [blame]
Dan Gohman5ea74d52009-07-31 18:16:33 +00001//===-- MachineFunctionPass.cpp -------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the definitions of the MachineFunctionPass members.
11//
12//===----------------------------------------------------------------------===//
13
Dan Gohman5ea74d52009-07-31 18:16:33 +000014#include "llvm/CodeGen/MachineFunctionPass.h"
Chandler Carruthb81dfa62015-01-28 04:57:56 +000015#include "llvm/Analysis/AliasAnalysis.h"
Chandler Carruth7b560d42015-09-09 17:55:00 +000016#include "llvm/Analysis/BasicAliasAnalysis.h"
Chandler Carruthb81dfa62015-01-28 04:57:56 +000017#include "llvm/Analysis/DominanceFrontier.h"
Chandler Carruth7b560d42015-09-09 17:55:00 +000018#include "llvm/Analysis/GlobalsModRef.h"
Chandler Carruthb81dfa62015-01-28 04:57:56 +000019#include "llvm/Analysis/IVUsers.h"
20#include "llvm/Analysis/LoopInfo.h"
Chandler Carruthb81dfa62015-01-28 04:57:56 +000021#include "llvm/Analysis/MemoryDependenceAnalysis.h"
22#include "llvm/Analysis/ScalarEvolution.h"
Chandler Carruth7b560d42015-09-09 17:55:00 +000023#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
Derek Schuffad154c82016-03-28 17:05:30 +000024#include "llvm/CodeGen/MachineFunction.h"
Chandler Carruthb81dfa62015-01-28 04:57:56 +000025#include "llvm/CodeGen/MachineFunctionAnalysis.h"
David Greene9b063df2010-04-02 23:17:14 +000026#include "llvm/CodeGen/Passes.h"
Chandler Carruthb81dfa62015-01-28 04:57:56 +000027#include "llvm/CodeGen/StackProtector.h"
28#include "llvm/IR/Dominators.h"
29#include "llvm/IR/Function.h"
Derek Schuffad154c82016-03-28 17:05:30 +000030
Dan Gohman5ea74d52009-07-31 18:16:33 +000031using namespace llvm;
32
David Greene9b063df2010-04-02 23:17:14 +000033Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O,
34 const std::string &Banner) const {
35 return createMachineFunctionPrinterPass(O, Banner);
36}
37
Dan Gohman5ea74d52009-07-31 18:16:33 +000038bool MachineFunctionPass::runOnFunction(Function &F) {
39 // Do not codegen any 'available_externally' functions at all, they have
40 // definitions outside the translation unit.
41 if (F.hasAvailableExternallyLinkage())
42 return false;
43
44 MachineFunction &MF = getAnalysis<MachineFunctionAnalysis>().getMF();
Derek Schuffad154c82016-03-28 17:05:30 +000045 MachineFunctionProperties &MFProps = MF.getProperties();
46
Derek Schuff07636cd2016-03-29 20:28:20 +000047#ifndef NDEBUG
48 if (!MFProps.verifyRequiredProperties(RequiredProperties)) {
49 errs() << "MachineFunctionProperties required by " << getPassName()
50 << " pass are not met by function " << F.getName() << ".\n"
51 << "Required properties: ";
52 RequiredProperties.print(errs());
53 errs() << "\nCurrent properties: ";
54 MFProps.print(errs());
55 errs() << "\n";
56 llvm_unreachable("MachineFunctionProperties check failed");
57 }
58#endif
Derek Schuffad154c82016-03-28 17:05:30 +000059
60 bool RV = runOnMachineFunction(MF);
61
62 MFProps.set(SetProperties);
63 MFProps.clear(ClearedProperties);
64 return RV;
Dan Gohman5ea74d52009-07-31 18:16:33 +000065}
66
67void MachineFunctionPass::getAnalysisUsage(AnalysisUsage &AU) const {
68 AU.addRequired<MachineFunctionAnalysis>();
69 AU.addPreserved<MachineFunctionAnalysis>();
70
71 // MachineFunctionPass preserves all LLVM IR passes, but there's no
72 // high-level way to express this. Instead, just list a bunch of
Dan Gohman09984272009-10-08 17:00:02 +000073 // passes explicitly. This does not include setPreservesCFG,
74 // because CodeGen overloads that to mean preserving the MachineBasicBlock
75 // CFG in addition to the LLVM IR CFG.
Chandler Carruth7b560d42015-09-09 17:55:00 +000076 AU.addPreserved<BasicAAWrapperPass>();
Hongbin Zheng751337f2016-02-25 17:54:15 +000077 AU.addPreserved<DominanceFrontierWrapperPass>();
Chandler Carruthb81dfa62015-01-28 04:57:56 +000078 AU.addPreserved<DominatorTreeWrapperPass>();
Chandler Carruth7b560d42015-09-09 17:55:00 +000079 AU.addPreserved<AAResultsWrapperPass>();
80 AU.addPreserved<GlobalsAAWrapperPass>();
Chandler Carruthb81dfa62015-01-28 04:57:56 +000081 AU.addPreserved<IVUsers>();
82 AU.addPreserved<LoopInfoWrapperPass>();
Chandler Carruth61440d22016-03-10 00:55:30 +000083 AU.addPreserved<MemoryDependenceWrapperPass>();
Chandler Carruth2f1fd162015-08-17 02:08:17 +000084 AU.addPreserved<ScalarEvolutionWrapperPass>();
Chandler Carruth7b560d42015-09-09 17:55:00 +000085 AU.addPreserved<SCEVAAWrapperPass>();
Chandler Carruthb81dfa62015-01-28 04:57:56 +000086 AU.addPreserved<StackProtector>();
Dan Gohman5ea74d52009-07-31 18:16:33 +000087
88 FunctionPass::getAnalysisUsage(AU);
89}