blob: 67ac95740e3e2b91fa859bf8c5e82df9cf1ca8ad [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/IR/Dominators.h"
28#include "llvm/IR/Function.h"
Derek Schuffad154c82016-03-28 17:05:30 +000029
Dan Gohman5ea74d52009-07-31 18:16:33 +000030using namespace llvm;
31
David Greene9b063df2010-04-02 23:17:14 +000032Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O,
33 const std::string &Banner) const {
34 return createMachineFunctionPrinterPass(O, Banner);
35}
36
Dan Gohman5ea74d52009-07-31 18:16:33 +000037bool MachineFunctionPass::runOnFunction(Function &F) {
38 // Do not codegen any 'available_externally' functions at all, they have
39 // definitions outside the translation unit.
Serge Pavloved5eb932017-01-15 10:23:18 +000040 if (F.hasAvailableExternallyLinkage())
Dan Gohman5ea74d52009-07-31 18:16:33 +000041 return false;
42
Matthias Braun733fe362016-08-24 01:52:46 +000043 MachineModuleInfo &MMI = getAnalysis<MachineModuleInfo>();
Matthias Braun7bda1952017-06-06 00:44:35 +000044 MachineFunction &MF = MMI.getOrCreateMachineFunction(F);
Matthias Braun733fe362016-08-24 01:52:46 +000045
Derek Schuffad154c82016-03-28 17:05:30 +000046 MachineFunctionProperties &MFProps = MF.getProperties();
47
Derek Schuff07636cd2016-03-29 20:28:20 +000048#ifndef NDEBUG
49 if (!MFProps.verifyRequiredProperties(RequiredProperties)) {
50 errs() << "MachineFunctionProperties required by " << getPassName()
51 << " pass are not met by function " << F.getName() << ".\n"
52 << "Required properties: ";
Matthias Brauna7d6fc92016-08-19 22:31:45 +000053 RequiredProperties.print(errs());
Derek Schuff07636cd2016-03-29 20:28:20 +000054 errs() << "\nCurrent properties: ";
55 MFProps.print(errs());
56 errs() << "\n";
57 llvm_unreachable("MachineFunctionProperties check failed");
58 }
59#endif
Derek Schuffad154c82016-03-28 17:05:30 +000060
61 bool RV = runOnMachineFunction(MF);
62
63 MFProps.set(SetProperties);
Quentin Colombetc437aa92016-08-26 22:09:08 +000064 MFProps.reset(ClearedProperties);
Derek Schuffad154c82016-03-28 17:05:30 +000065 return RV;
Dan Gohman5ea74d52009-07-31 18:16:33 +000066}
67
68void MachineFunctionPass::getAnalysisUsage(AnalysisUsage &AU) const {
Matthias Braun733fe362016-08-24 01:52:46 +000069 AU.addRequired<MachineModuleInfo>();
70 AU.addPreserved<MachineModuleInfo>();
Dan Gohman5ea74d52009-07-31 18:16:33 +000071
72 // MachineFunctionPass preserves all LLVM IR passes, but there's no
73 // high-level way to express this. Instead, just list a bunch of
Dan Gohman09984272009-10-08 17:00:02 +000074 // passes explicitly. This does not include setPreservesCFG,
75 // because CodeGen overloads that to mean preserving the MachineBasicBlock
76 // CFG in addition to the LLVM IR CFG.
Chandler Carruth7b560d42015-09-09 17:55:00 +000077 AU.addPreserved<BasicAAWrapperPass>();
Hongbin Zheng751337f2016-02-25 17:54:15 +000078 AU.addPreserved<DominanceFrontierWrapperPass>();
Chandler Carruthb81dfa62015-01-28 04:57:56 +000079 AU.addPreserved<DominatorTreeWrapperPass>();
Chandler Carruth7b560d42015-09-09 17:55:00 +000080 AU.addPreserved<AAResultsWrapperPass>();
81 AU.addPreserved<GlobalsAAWrapperPass>();
Dehao Chen1a444522016-07-16 22:51:33 +000082 AU.addPreserved<IVUsersWrapperPass>();
Chandler Carruthb81dfa62015-01-28 04:57:56 +000083 AU.addPreserved<LoopInfoWrapperPass>();
Chandler Carruth61440d22016-03-10 00:55:30 +000084 AU.addPreserved<MemoryDependenceWrapperPass>();
Chandler Carruth2f1fd162015-08-17 02:08:17 +000085 AU.addPreserved<ScalarEvolutionWrapperPass>();
Chandler Carruth7b560d42015-09-09 17:55:00 +000086 AU.addPreserved<SCEVAAWrapperPass>();
Dan Gohman5ea74d52009-07-31 18:16:33 +000087
88 FunctionPass::getAnalysisUsage(AU);
89}