blob: 2265676ff8b1445836263891339abd025a8f1ba5 [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"
Matthias Braun733fe362016-08-24 01:52:46 +000025#include "llvm/CodeGen/MachineModuleInfo.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
Matthias Braun733fe362016-08-24 01:52:46 +000044 MachineModuleInfo &MMI = getAnalysis<MachineModuleInfo>();
45 MachineFunction &MF = MMI.getMachineFunction(F);
46
Derek Schuffad154c82016-03-28 17:05:30 +000047 MachineFunctionProperties &MFProps = MF.getProperties();
48
Derek Schuff07636cd2016-03-29 20:28:20 +000049#ifndef NDEBUG
50 if (!MFProps.verifyRequiredProperties(RequiredProperties)) {
51 errs() << "MachineFunctionProperties required by " << getPassName()
52 << " pass are not met by function " << F.getName() << ".\n"
53 << "Required properties: ";
Matthias Brauna7d6fc92016-08-19 22:31:45 +000054 RequiredProperties.print(errs());
Derek Schuff07636cd2016-03-29 20:28:20 +000055 errs() << "\nCurrent properties: ";
56 MFProps.print(errs());
57 errs() << "\n";
58 llvm_unreachable("MachineFunctionProperties check failed");
59 }
60#endif
Derek Schuffad154c82016-03-28 17:05:30 +000061
62 bool RV = runOnMachineFunction(MF);
63
64 MFProps.set(SetProperties);
Quentin Colombetc437aa92016-08-26 22:09:08 +000065 MFProps.reset(ClearedProperties);
Derek Schuffad154c82016-03-28 17:05:30 +000066 return RV;
Dan Gohman5ea74d52009-07-31 18:16:33 +000067}
68
69void MachineFunctionPass::getAnalysisUsage(AnalysisUsage &AU) const {
Matthias Braun733fe362016-08-24 01:52:46 +000070 AU.addRequired<MachineModuleInfo>();
71 AU.addPreserved<MachineModuleInfo>();
Dan Gohman5ea74d52009-07-31 18:16:33 +000072
73 // MachineFunctionPass preserves all LLVM IR passes, but there's no
74 // high-level way to express this. Instead, just list a bunch of
Dan Gohman09984272009-10-08 17:00:02 +000075 // passes explicitly. This does not include setPreservesCFG,
76 // because CodeGen overloads that to mean preserving the MachineBasicBlock
77 // CFG in addition to the LLVM IR CFG.
Chandler Carruth7b560d42015-09-09 17:55:00 +000078 AU.addPreserved<BasicAAWrapperPass>();
Hongbin Zheng751337f2016-02-25 17:54:15 +000079 AU.addPreserved<DominanceFrontierWrapperPass>();
Chandler Carruthb81dfa62015-01-28 04:57:56 +000080 AU.addPreserved<DominatorTreeWrapperPass>();
Chandler Carruth7b560d42015-09-09 17:55:00 +000081 AU.addPreserved<AAResultsWrapperPass>();
82 AU.addPreserved<GlobalsAAWrapperPass>();
Dehao Chen1a444522016-07-16 22:51:33 +000083 AU.addPreserved<IVUsersWrapperPass>();
Chandler Carruthb81dfa62015-01-28 04:57:56 +000084 AU.addPreserved<LoopInfoWrapperPass>();
Chandler Carruth61440d22016-03-10 00:55:30 +000085 AU.addPreserved<MemoryDependenceWrapperPass>();
Chandler Carruth2f1fd162015-08-17 02:08:17 +000086 AU.addPreserved<ScalarEvolutionWrapperPass>();
Chandler Carruth7b560d42015-09-09 17:55:00 +000087 AU.addPreserved<SCEVAAWrapperPass>();
Chandler Carruthb81dfa62015-01-28 04:57:56 +000088 AU.addPreserved<StackProtector>();
Dan Gohman5ea74d52009-07-31 18:16:33 +000089
90 FunctionPass::getAnalysisUsage(AU);
91}