1ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman//===-- MachineFunctionPass.cpp -------------------------------------------===// 2ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman// 3ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman// The LLVM Compiler Infrastructure 4ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman// 5ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman// This file is distributed under the University of Illinois Open Source 6ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman// License. See LICENSE.TXT for details. 7ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman// 8ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman//===----------------------------------------------------------------------===// 9ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman// 10ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman// This file contains the definitions of the MachineFunctionPass members. 11ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman// 12ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman//===----------------------------------------------------------------------===// 13ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman 140b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Function.h" 15ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman#include "llvm/Analysis/AliasAnalysis.h" 16ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman#include "llvm/CodeGen/MachineFunctionAnalysis.h" 17ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman#include "llvm/CodeGen/MachineFunctionPass.h" 185c8aa950fe3484b6e115647328c196f8be64f9edDavid Greene#include "llvm/CodeGen/Passes.h" 19ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohmanusing namespace llvm; 20ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman 215c8aa950fe3484b6e115647328c196f8be64f9edDavid GreenePass *MachineFunctionPass::createPrinterPass(raw_ostream &O, 225c8aa950fe3484b6e115647328c196f8be64f9edDavid Greene const std::string &Banner) const { 235c8aa950fe3484b6e115647328c196f8be64f9edDavid Greene return createMachineFunctionPrinterPass(O, Banner); 245c8aa950fe3484b6e115647328c196f8be64f9edDavid Greene} 255c8aa950fe3484b6e115647328c196f8be64f9edDavid Greene 26ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohmanbool MachineFunctionPass::runOnFunction(Function &F) { 27ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman // Do not codegen any 'available_externally' functions at all, they have 28ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman // definitions outside the translation unit. 29ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman if (F.hasAvailableExternallyLinkage()) 30ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman return false; 31ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman 32ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman MachineFunction &MF = getAnalysis<MachineFunctionAnalysis>().getMF(); 33ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman return runOnMachineFunction(MF); 34ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman} 35ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman 36ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohmanvoid MachineFunctionPass::getAnalysisUsage(AnalysisUsage &AU) const { 37ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman AU.addRequired<MachineFunctionAnalysis>(); 38ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman AU.addPreserved<MachineFunctionAnalysis>(); 39ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman 40ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman // MachineFunctionPass preserves all LLVM IR passes, but there's no 41ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman // high-level way to express this. Instead, just list a bunch of 428a261e44f71a433b7d9af373c3e3dfa6fea67146Dan Gohman // passes explicitly. This does not include setPreservesCFG, 438a261e44f71a433b7d9af373c3e3dfa6fea67146Dan Gohman // because CodeGen overloads that to mean preserving the MachineBasicBlock 448a261e44f71a433b7d9af373c3e3dfa6fea67146Dan Gohman // CFG in addition to the LLVM IR CFG. 45ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman AU.addPreserved<AliasAnalysis>(); 468a261e44f71a433b7d9af373c3e3dfa6fea67146Dan Gohman AU.addPreserved("scalar-evolution"); 478a261e44f71a433b7d9af373c3e3dfa6fea67146Dan Gohman AU.addPreserved("iv-users"); 488a261e44f71a433b7d9af373c3e3dfa6fea67146Dan Gohman AU.addPreserved("memdep"); 498a261e44f71a433b7d9af373c3e3dfa6fea67146Dan Gohman AU.addPreserved("live-values"); 508a261e44f71a433b7d9af373c3e3dfa6fea67146Dan Gohman AU.addPreserved("domtree"); 518a261e44f71a433b7d9af373c3e3dfa6fea67146Dan Gohman AU.addPreserved("domfrontier"); 528a261e44f71a433b7d9af373c3e3dfa6fea67146Dan Gohman AU.addPreserved("loops"); 538a261e44f71a433b7d9af373c3e3dfa6fea67146Dan Gohman AU.addPreserved("lda"); 5436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines AU.addPreserved("stack-protector"); 55ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman 56ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman FunctionPass::getAnalysisUsage(AU); 57ad2afc2a421a0e41603d5eee412d4d8c77e9bc1cDan Gohman} 58