Initialize HasPOPCNT.
[oota-llvm.git] / lib / CodeGen / MachineFunctionAnalysis.cpp
1 //===-- 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"
15 #include "llvm/CodeGen/GCMetadata.h"
16 #include "llvm/CodeGen/MachineFunction.h"
17 #include "llvm/CodeGen/MachineModuleInfo.h"
18 using namespace llvm;
19
20 // Register this pass with PassInfo directly to avoid having to define
21 // a default constructor.
22 static PassInfo
23 X("Machine Function Analysis", "machine-function-analysis",
24    &MachineFunctionAnalysis::ID, 0,
25   /*CFGOnly=*/false, /*is_analysis=*/true);
26
27 char MachineFunctionAnalysis::ID = 0;
28
29 MachineFunctionAnalysis::MachineFunctionAnalysis(const TargetMachine &tm,
30                                                  CodeGenOpt::Level OL) :
31   FunctionPass(ID), TM(tm), OptLevel(OL), MF(0) {
32 }
33
34 MachineFunctionAnalysis::~MachineFunctionAnalysis() {
35   releaseMemory();
36   assert(!MF && "MachineFunctionAnalysis left initialized!");
37 }
38
39 void MachineFunctionAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
40   AU.setPreservesAll();
41   AU.addRequired<MachineModuleInfo>();
42 }
43
44 bool MachineFunctionAnalysis::doInitialization(Module &M) {
45   MachineModuleInfo *MMI = getAnalysisIfAvailable<MachineModuleInfo>();
46   assert(MMI && "MMI not around yet??");
47   MMI->setModule(&M);
48   NextFnNum = 0;
49   return false;
50 }
51
52
53 bool MachineFunctionAnalysis::runOnFunction(Function &F) {
54   assert(!MF && "MachineFunctionAnalysis already initialized!");
55   MF = new MachineFunction(&F, TM, NextFnNum++,
56                            getAnalysis<MachineModuleInfo>(),
57                            getAnalysisIfAvailable<GCModuleInfo>());
58   return false;
59 }
60
61 void MachineFunctionAnalysis::releaseMemory() {
62   delete MF;
63   MF = 0;
64 }