forked from OSchip/llvm-project
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. llvm-svn: 94509
This commit is contained in:
parent
f8f8ba8a47
commit
6715952c25
|
@ -19,7 +19,6 @@
|
||||||
#include "llvm/CodeGen/MachineFunctionPass.h"
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
||||||
#include "llvm/Support/DebugLoc.h"
|
#include "llvm/Support/DebugLoc.h"
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
#include "llvm/ADT/DenseMap.h"
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class BlockAddress;
|
class BlockAddress;
|
||||||
|
@ -62,13 +61,6 @@ namespace llvm {
|
||||||
class AsmPrinter : public MachineFunctionPass {
|
class AsmPrinter : public MachineFunctionPass {
|
||||||
static char ID;
|
static char ID;
|
||||||
|
|
||||||
/// FunctionNumber - This provides a unique ID for each function emitted in
|
|
||||||
/// this translation unit. It is autoincremented by SetupMachineFunction,
|
|
||||||
/// and can be accessed with getFunctionNumber() and
|
|
||||||
/// IncrementFunctionNumber().
|
|
||||||
///
|
|
||||||
unsigned FunctionNumber;
|
|
||||||
|
|
||||||
// GCMetadataPrinters - The garbage collection metadata printer table.
|
// GCMetadataPrinters - The garbage collection metadata printer table.
|
||||||
typedef DenseMap<GCStrategy*,GCMetadataPrinter*> gcp_map_type;
|
typedef DenseMap<GCStrategy*,GCMetadataPrinter*> gcp_map_type;
|
||||||
typedef gcp_map_type::iterator gcp_iterator;
|
typedef gcp_map_type::iterator gcp_iterator;
|
||||||
|
@ -168,7 +160,7 @@ namespace llvm {
|
||||||
|
|
||||||
/// getFunctionNumber - Return a unique ID for the current function.
|
/// getFunctionNumber - Return a unique ID for the current function.
|
||||||
///
|
///
|
||||||
unsigned getFunctionNumber() const { return FunctionNumber; }
|
unsigned getFunctionNumber() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// getAnalysisUsage - Record analysis usage.
|
/// getAnalysisUsage - Record analysis usage.
|
||||||
|
@ -219,11 +211,6 @@ namespace llvm {
|
||||||
/// is being processed from runOnMachineFunction.
|
/// is being processed from runOnMachineFunction.
|
||||||
void SetupMachineFunction(MachineFunction &MF);
|
void SetupMachineFunction(MachineFunction &MF);
|
||||||
|
|
||||||
/// IncrementFunctionNumber - Increase Function Number. AsmPrinters should
|
|
||||||
/// not normally call this, as the counter is automatically bumped by
|
|
||||||
/// SetupMachineFunction.
|
|
||||||
void IncrementFunctionNumber() { FunctionNumber++; }
|
|
||||||
|
|
||||||
/// EmitConstantPool - Print to the current output stream assembly
|
/// EmitConstantPool - Print to the current output stream assembly
|
||||||
/// representations of the constants in the constant pool MCP. This is
|
/// representations of the constants in the constant pool MCP. This is
|
||||||
/// used to print out constants which have been "spilled to memory" by
|
/// used to print out constants which have been "spilled to memory" by
|
||||||
|
|
|
@ -112,6 +112,11 @@ class MachineFunction {
|
||||||
// Tracks debug locations.
|
// Tracks debug locations.
|
||||||
DebugLocTracker DebugLocInfo;
|
DebugLocTracker DebugLocInfo;
|
||||||
|
|
||||||
|
/// FunctionNumber - This provides a unique ID for each function emitted in
|
||||||
|
/// this translation unit.
|
||||||
|
///
|
||||||
|
unsigned FunctionNumber;
|
||||||
|
|
||||||
// The alignment of the function.
|
// The alignment of the function.
|
||||||
unsigned Alignment;
|
unsigned Alignment;
|
||||||
|
|
||||||
|
@ -119,13 +124,17 @@ class MachineFunction {
|
||||||
void operator=(const MachineFunction&); // intentionally unimplemented
|
void operator=(const MachineFunction&); // intentionally unimplemented
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MachineFunction(Function *Fn, const TargetMachine &TM);
|
MachineFunction(Function *Fn, const TargetMachine &TM, unsigned FunctionNum);
|
||||||
~MachineFunction();
|
~MachineFunction();
|
||||||
|
|
||||||
/// getFunction - Return the LLVM function that this machine code represents
|
/// getFunction - Return the LLVM function that this machine code represents
|
||||||
///
|
///
|
||||||
Function *getFunction() const { return Fn; }
|
Function *getFunction() const { return Fn; }
|
||||||
|
|
||||||
|
/// getFunctionNumber - Return a unique ID for the current function.
|
||||||
|
///
|
||||||
|
unsigned getFunctionNumber() const { return FunctionNumber; }
|
||||||
|
|
||||||
/// getTarget - Return the target machine this machine code is compiled with
|
/// getTarget - Return the target machine this machine code is compiled with
|
||||||
///
|
///
|
||||||
const TargetMachine &getTarget() const { return Target; }
|
const TargetMachine &getTarget() const { return Target; }
|
||||||
|
|
|
@ -28,7 +28,7 @@ private:
|
||||||
const TargetMachine &TM;
|
const TargetMachine &TM;
|
||||||
CodeGenOpt::Level OptLevel;
|
CodeGenOpt::Level OptLevel;
|
||||||
MachineFunction *MF;
|
MachineFunction *MF;
|
||||||
|
unsigned NextFnNum;
|
||||||
public:
|
public:
|
||||||
static char ID;
|
static char ID;
|
||||||
explicit MachineFunctionAnalysis(const TargetMachine &tm,
|
explicit MachineFunctionAnalysis(const TargetMachine &tm,
|
||||||
|
@ -39,6 +39,7 @@ public:
|
||||||
CodeGenOpt::Level getOptLevel() const { return OptLevel; }
|
CodeGenOpt::Level getOptLevel() const { return OptLevel; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual bool doInitialization(Module &) { NextFnNum = 1; return false; }
|
||||||
virtual bool runOnFunction(Function &F);
|
virtual bool runOnFunction(Function &F);
|
||||||
virtual void releaseMemory();
|
virtual void releaseMemory();
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
||||||
|
|
|
@ -64,7 +64,7 @@ static bool getVerboseAsm(bool VDef) {
|
||||||
char AsmPrinter::ID = 0;
|
char AsmPrinter::ID = 0;
|
||||||
AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
|
AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
|
||||||
const MCAsmInfo *T, bool VDef)
|
const MCAsmInfo *T, bool VDef)
|
||||||
: MachineFunctionPass(&ID), FunctionNumber(0), O(o),
|
: MachineFunctionPass(&ID), O(o),
|
||||||
TM(tm), MAI(T), TRI(tm.getRegisterInfo()),
|
TM(tm), MAI(T), TRI(tm.getRegisterInfo()),
|
||||||
|
|
||||||
OutContext(*new MCContext()),
|
OutContext(*new MCContext()),
|
||||||
|
@ -87,6 +87,12 @@ AsmPrinter::~AsmPrinter() {
|
||||||
delete &OutContext;
|
delete &OutContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// getFunctionNumber - Return a unique ID for the current function.
|
||||||
|
///
|
||||||
|
unsigned AsmPrinter::getFunctionNumber() const {
|
||||||
|
return MF->getFunctionNumber();
|
||||||
|
}
|
||||||
|
|
||||||
TargetLoweringObjectFile &AsmPrinter::getObjFileLowering() const {
|
TargetLoweringObjectFile &AsmPrinter::getObjFileLowering() const {
|
||||||
return TM.getTargetLowering()->getObjFileLowering();
|
return TM.getTargetLowering()->getObjFileLowering();
|
||||||
}
|
}
|
||||||
|
@ -359,9 +365,9 @@ bool AsmPrinter::doFinalization(Module &M) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
|
void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
|
||||||
|
this->MF = &MF;
|
||||||
// Get the function symbol.
|
// Get the function symbol.
|
||||||
CurrentFnSym = GetGlobalValueSymbol(MF.getFunction());
|
CurrentFnSym = GetGlobalValueSymbol(MF.getFunction());
|
||||||
IncrementFunctionNumber();
|
|
||||||
|
|
||||||
if (VerboseAsm)
|
if (VerboseAsm)
|
||||||
LI = &getAnalysis<MachineLoopInfo>();
|
LI = &getAnalysis<MachineLoopInfo>();
|
||||||
|
|
|
@ -70,9 +70,9 @@ FunctionPass *llvm::createMachineFunctionPrinterPass(raw_ostream &OS,
|
||||||
return new Printer(OS, Banner);
|
return new Printer(OS, Banner);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===---------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// MachineFunction implementation
|
// MachineFunction implementation
|
||||||
//===---------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
// Out of line virtual method.
|
// Out of line virtual method.
|
||||||
MachineFunctionInfo::~MachineFunctionInfo() {}
|
MachineFunctionInfo::~MachineFunctionInfo() {}
|
||||||
|
@ -81,8 +81,8 @@ void ilist_traits<MachineBasicBlock>::deleteNode(MachineBasicBlock *MBB) {
|
||||||
MBB->getParent()->DeleteMachineBasicBlock(MBB);
|
MBB->getParent()->DeleteMachineBasicBlock(MBB);
|
||||||
}
|
}
|
||||||
|
|
||||||
MachineFunction::MachineFunction(Function *F,
|
MachineFunction::MachineFunction(Function *F, const TargetMachine &TM,
|
||||||
const TargetMachine &TM)
|
unsigned FunctionNum)
|
||||||
: Fn(F), Target(TM) {
|
: Fn(F), Target(TM) {
|
||||||
if (TM.getRegisterInfo())
|
if (TM.getRegisterInfo())
|
||||||
RegInfo = new (Allocator.Allocate<MachineRegisterInfo>())
|
RegInfo = new (Allocator.Allocate<MachineRegisterInfo>())
|
||||||
|
@ -95,7 +95,7 @@ MachineFunction::MachineFunction(Function *F,
|
||||||
ConstantPool = new (Allocator.Allocate<MachineConstantPool>())
|
ConstantPool = new (Allocator.Allocate<MachineConstantPool>())
|
||||||
MachineConstantPool(TM.getTargetData());
|
MachineConstantPool(TM.getTargetData());
|
||||||
Alignment = TM.getTargetLowering()->getFunctionAlignment(F);
|
Alignment = TM.getTargetLowering()->getFunctionAlignment(F);
|
||||||
|
FunctionNumber = FunctionNum;
|
||||||
JumpTableInfo = 0;
|
JumpTableInfo = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ MachineFunctionAnalysis::~MachineFunctionAnalysis() {
|
||||||
|
|
||||||
bool MachineFunctionAnalysis::runOnFunction(Function &F) {
|
bool MachineFunctionAnalysis::runOnFunction(Function &F) {
|
||||||
assert(!MF && "MachineFunctionAnalysis already initialized!");
|
assert(!MF && "MachineFunctionAnalysis already initialized!");
|
||||||
MF = new MachineFunction(&F, TM);
|
MF = new MachineFunction(&F, TM, NextFnNum++);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -921,7 +921,7 @@ public:
|
||||||
FunctionType::get(llvm::Type::getVoidTy(getGlobalContext()), false);
|
FunctionType::get(llvm::Type::getVoidTy(getGlobalContext()), false);
|
||||||
DummyF = Function::Create(FTy, GlobalValue::InternalLinkage);
|
DummyF = Function::Create(FTy, GlobalValue::InternalLinkage);
|
||||||
DummyTD = new TargetData("");
|
DummyTD = new TargetData("");
|
||||||
DummyMF = new MachineFunction(DummyF, TM);
|
DummyMF = new MachineFunction(DummyF, TM, 0);
|
||||||
DummyMBB = DummyMF->CreateMachineBasicBlock();
|
DummyMBB = DummyMF->CreateMachineBasicBlock();
|
||||||
|
|
||||||
InstrEmitter = new MCSingleInstructionCodeEmitter();
|
InstrEmitter = new MCSingleInstructionCodeEmitter();
|
||||||
|
|
Loading…
Reference in New Issue