blob: 3c10005b2d177f33bfb08d7631173a4f0a904482 [file] [log] [blame]
Dan Gohmanad2afc22009-07-31 18:16:33 +00001//===-- MachineFunctionAnalysis.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 MachineFunctionAnalysis members.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/CodeGen/MachineFunctionAnalysis.h"
Nicolas Geoffray7a5a3f72010-10-31 20:38:38 +000015#include "llvm/CodeGen/GCMetadata.h"
Dan Gohmanad2afc22009-07-31 18:16:33 +000016#include "llvm/CodeGen/MachineFunction.h"
Chris Lattner11d53c12010-03-13 20:55:24 +000017#include "llvm/CodeGen/MachineModuleInfo.h"
Dan Gohmanad2afc22009-07-31 18:16:33 +000018using namespace llvm;
19
20// Register this pass with PassInfo directly to avoid having to define
21// a default constructor.
22static PassInfo
23X("Machine Function Analysis", "machine-function-analysis",
Owen Anderson90c579d2010-08-06 18:33:48 +000024 &MachineFunctionAnalysis::ID, 0,
Dan Gohmanad2afc22009-07-31 18:16:33 +000025 /*CFGOnly=*/false, /*is_analysis=*/true);
26
27char MachineFunctionAnalysis::ID = 0;
28
Dan Gohman28a4c782009-11-09 18:18:49 +000029MachineFunctionAnalysis::MachineFunctionAnalysis(const TargetMachine &tm,
Dan Gohmanad2afc22009-07-31 18:16:33 +000030 CodeGenOpt::Level OL) :
Owen Anderson90c579d2010-08-06 18:33:48 +000031 FunctionPass(ID), TM(tm), OptLevel(OL), MF(0) {
Dan Gohmanad2afc22009-07-31 18:16:33 +000032}
33
Dan Gohmanf9408332009-08-01 04:19:43 +000034MachineFunctionAnalysis::~MachineFunctionAnalysis() {
Chris Lattnerf5e16132009-10-12 04:22:44 +000035 releaseMemory();
Dan Gohmanf9408332009-08-01 04:19:43 +000036 assert(!MF && "MachineFunctionAnalysis left initialized!");
37}
38
Chris Lattner421ccd92010-04-06 00:51:52 +000039void MachineFunctionAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
40 AU.setPreservesAll();
41 AU.addRequired<MachineModuleInfo>();
42}
43
44bool MachineFunctionAnalysis::doInitialization(Module &M) {
45 MachineModuleInfo *MMI = getAnalysisIfAvailable<MachineModuleInfo>();
46 assert(MMI && "MMI not around yet??");
47 MMI->setModule(&M);
Dan Gohman9f23dee2010-04-17 16:29:15 +000048 NextFnNum = 0;
49 return false;
Chris Lattner421ccd92010-04-06 00:51:52 +000050}
51
52
Dan Gohmanad2afc22009-07-31 18:16:33 +000053bool MachineFunctionAnalysis::runOnFunction(Function &F) {
54 assert(!MF && "MachineFunctionAnalysis already initialized!");
Chris Lattner11d53c12010-03-13 20:55:24 +000055 MF = new MachineFunction(&F, TM, NextFnNum++,
Nicolas Geoffray7a5a3f72010-10-31 20:38:38 +000056 getAnalysis<MachineModuleInfo>(),
57 getAnalysisIfAvailable<GCModuleInfo>());
Dan Gohmanad2afc22009-07-31 18:16:33 +000058 return false;
59}
60
61void MachineFunctionAnalysis::releaseMemory() {
62 delete MF;
63 MF = 0;
64}