blob: bd0b11a8cb56b2d24c4f61d07184defd8e1466ec [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
47 assert(MFProps.verifyRequiredProperties(RequiredProperties) &&
48 "Properties required by the pass are not met by the function");
49
50 bool RV = runOnMachineFunction(MF);
51
52 MFProps.set(SetProperties);
53 MFProps.clear(ClearedProperties);
54 return RV;
Dan Gohman5ea74d52009-07-31 18:16:33 +000055}
56
57void MachineFunctionPass::getAnalysisUsage(AnalysisUsage &AU) const {
58 AU.addRequired<MachineFunctionAnalysis>();
59 AU.addPreserved<MachineFunctionAnalysis>();
60
61 // MachineFunctionPass preserves all LLVM IR passes, but there's no
62 // high-level way to express this. Instead, just list a bunch of
Dan Gohman09984272009-10-08 17:00:02 +000063 // passes explicitly. This does not include setPreservesCFG,
64 // because CodeGen overloads that to mean preserving the MachineBasicBlock
65 // CFG in addition to the LLVM IR CFG.
Chandler Carruth7b560d42015-09-09 17:55:00 +000066 AU.addPreserved<BasicAAWrapperPass>();
Hongbin Zheng751337f2016-02-25 17:54:15 +000067 AU.addPreserved<DominanceFrontierWrapperPass>();
Chandler Carruthb81dfa62015-01-28 04:57:56 +000068 AU.addPreserved<DominatorTreeWrapperPass>();
Chandler Carruth7b560d42015-09-09 17:55:00 +000069 AU.addPreserved<AAResultsWrapperPass>();
70 AU.addPreserved<GlobalsAAWrapperPass>();
Chandler Carruthb81dfa62015-01-28 04:57:56 +000071 AU.addPreserved<IVUsers>();
72 AU.addPreserved<LoopInfoWrapperPass>();
Chandler Carruth61440d22016-03-10 00:55:30 +000073 AU.addPreserved<MemoryDependenceWrapperPass>();
Chandler Carruth2f1fd162015-08-17 02:08:17 +000074 AU.addPreserved<ScalarEvolutionWrapperPass>();
Chandler Carruth7b560d42015-09-09 17:55:00 +000075 AU.addPreserved<SCEVAAWrapperPass>();
Chandler Carruthb81dfa62015-01-28 04:57:56 +000076 AU.addPreserved<StackProtector>();
Dan Gohman5ea74d52009-07-31 18:16:33 +000077
78 FunctionPass::getAnalysisUsage(AU);
79}