llvm.org GIT mirror llvm / b84822f
make MachineFunction keep track of its ID and make MachineFunctionAnalysis dole them out, instead of having AsmPrinter do both. Have the AsmPrinter::SetupMachineFunction method set the 'AsmPrinter::MF' variable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94509 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
7 changed file(s) with 28 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
1818 #include "llvm/CodeGen/MachineFunctionPass.h"
1919 #include "llvm/Support/DebugLoc.h"
2020 #include "llvm/Target/TargetMachine.h"
21 #include "llvm/ADT/DenseMap.h"
2221
2322 namespace llvm {
2423 class BlockAddress;
6160 class AsmPrinter : public MachineFunctionPass {
6261 static char ID;
6362
64 /// FunctionNumber - This provides a unique ID for each function emitted in
65 /// this translation unit. It is autoincremented by SetupMachineFunction,
66 /// and can be accessed with getFunctionNumber() and
67 /// IncrementFunctionNumber().
68 ///
69 unsigned FunctionNumber;
70
7163 // GCMetadataPrinters - The garbage collection metadata printer table.
7264 typedef DenseMap gcp_map_type;
7365 typedef gcp_map_type::iterator gcp_iterator;
167159
168160 /// getFunctionNumber - Return a unique ID for the current function.
169161 ///
170 unsigned getFunctionNumber() const { return FunctionNumber; }
162 unsigned getFunctionNumber() const;
171163
172164 protected:
173165 /// getAnalysisUsage - Record analysis usage.
217209 /// SetupMachineFunction - This should be called when a new MachineFunction
218210 /// is being processed from runOnMachineFunction.
219211 void SetupMachineFunction(MachineFunction &MF);
220
221 /// IncrementFunctionNumber - Increase Function Number. AsmPrinters should
222 /// not normally call this, as the counter is automatically bumped by
223 /// SetupMachineFunction.
224 void IncrementFunctionNumber() { FunctionNumber++; }
225212
226213 /// EmitConstantPool - Print to the current output stream assembly
227214 /// representations of the constants in the constant pool MCP. This is
111111 // Tracks debug locations.
112112 DebugLocTracker DebugLocInfo;
113113
114 /// FunctionNumber - This provides a unique ID for each function emitted in
115 /// this translation unit.
116 ///
117 unsigned FunctionNumber;
118
114119 // The alignment of the function.
115120 unsigned Alignment;
116121
118123 void operator=(const MachineFunction&); // intentionally unimplemented
119124
120125 public:
121 MachineFunction(Function *Fn, const TargetMachine &TM);
126 MachineFunction(Function *Fn, const TargetMachine &TM, unsigned FunctionNum);
122127 ~MachineFunction();
123128
124129 /// getFunction - Return the LLVM function that this machine code represents
125130 ///
126131 Function *getFunction() const { return Fn; }
127132
133 /// getFunctionNumber - Return a unique ID for the current function.
134 ///
135 unsigned getFunctionNumber() const { return FunctionNumber; }
136
128137 /// getTarget - Return the target machine this machine code is compiled with
129138 ///
130139 const TargetMachine &getTarget() const { return Target; }
2727 const TargetMachine &TM;
2828 CodeGenOpt::Level OptLevel;
2929 MachineFunction *MF;
30
30 unsigned NextFnNum;
3131 public:
3232 static char ID;
3333 explicit MachineFunctionAnalysis(const TargetMachine &tm,
3838 CodeGenOpt::Level getOptLevel() const { return OptLevel; }
3939
4040 private:
41 virtual bool doInitialization(Module &) { NextFnNum = 1; return false; }
4142 virtual bool runOnFunction(Function &F);
4243 virtual void releaseMemory();
4344 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
6363 char AsmPrinter::ID = 0;
6464 AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
6565 const MCAsmInfo *T, bool VDef)
66 : MachineFunctionPass(&ID), FunctionNumber(0), O(o),
66 : MachineFunctionPass(&ID), O(o),
6767 TM(tm), MAI(T), TRI(tm.getRegisterInfo()),
6868
6969 OutContext(*new MCContext()),
8484
8585 delete &OutStreamer;
8686 delete &OutContext;
87 }
88
89 /// getFunctionNumber - Return a unique ID for the current function.
90 ///
91 unsigned AsmPrinter::getFunctionNumber() const {
92 return MF->getFunctionNumber();
8793 }
8894
8995 TargetLoweringObjectFile &AsmPrinter::getObjFileLowering() const {
358364 }
359365
360366 void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
367 this->MF = &MF;
361368 // Get the function symbol.
362369 CurrentFnSym = GetGlobalValueSymbol(MF.getFunction());
363 IncrementFunctionNumber();
364370
365371 if (VerboseAsm)
366372 LI = &getAnalysis();
6969 return new Printer(OS, Banner);
7070 }
7171
72 //===---------------------------------------------------------------------===//
72 //===----------------------------------------------------------------------===//
7373 // MachineFunction implementation
74 //===---------------------------------------------------------------------===//
74 //===----------------------------------------------------------------------===//
7575
7676 // Out of line virtual method.
7777 MachineFunctionInfo::~MachineFunctionInfo() {}
8080 MBB->getParent()->DeleteMachineBasicBlock(MBB);
8181 }
8282
83 MachineFunction::MachineFunction(Function *F,
84 const TargetMachine &TM)
83 MachineFunction::MachineFunction(Function *F, const TargetMachine &TM,
84 unsigned FunctionNum)
8585 : Fn(F), Target(TM) {
8686 if (TM.getRegisterInfo())
8787 RegInfo = new (Allocator.Allocate())
9494 ConstantPool = new (Allocator.Allocate())
9595 MachineConstantPool(TM.getTargetData());
9696 Alignment = TM.getTargetLowering()->getFunctionAlignment(F);
97
97 FunctionNumber = FunctionNum;
9898 JumpTableInfo = 0;
9999 }
100100
3535
3636 bool MachineFunctionAnalysis::runOnFunction(Function &F) {
3737 assert(!MF && "MachineFunctionAnalysis already initialized!");
38 MF = new MachineFunction(&F, TM);
38 MF = new MachineFunction(&F, TM, NextFnNum++);
3939 return false;
4040 }
4141
920920 FunctionType::get(llvm::Type::getVoidTy(getGlobalContext()), false);
921921 DummyF = Function::Create(FTy, GlobalValue::InternalLinkage);
922922 DummyTD = new TargetData("");
923 DummyMF = new MachineFunction(DummyF, TM);
923 DummyMF = new MachineFunction(DummyF, TM, 0);
924924 DummyMBB = DummyMF->CreateMachineBasicBlock();
925925
926926 InstrEmitter = new MCSingleInstructionCodeEmitter();