From e40c8a2b26d1e2f9b7a216b3f1e5537f77b07a31 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Tue, 11 Aug 2015 23:09:45 +0000 Subject: PseudoSourceValue: Replace global manager with a manager in a machine function. This commit removes the global manager variable which is responsible for storing and allocating pseudo source values and instead it introduces a new manager class named 'PseudoSourceValueManager'. Machine functions now own an instance of the pseudo source value manager class. This commit also modifies the 'get...' methods in the 'MachinePointerInfo' class to construct pseudo source values using the instance of the pseudo source value manager object from the machine function. This commit updates calls to the 'get...' methods from the 'MachinePointerInfo' class in a lot of different files because those calls now need to pass in a reference to a machine function to those methods. This change will make it easier to serialize pseudo source values as it will enable me to transform the mips specific MipsCallEntry PseudoSourceValue subclass into two target independent subclasses. Reviewers: Akira Hatanaka llvm-svn: 244693 --- llvm/lib/CodeGen/PseudoSourceValue.cpp | 74 +++++++++++++--------------------- 1 file changed, 27 insertions(+), 47 deletions(-) (limited to 'llvm/lib/CodeGen/PseudoSourceValue.cpp') diff --git a/llvm/lib/CodeGen/PseudoSourceValue.cpp b/llvm/lib/CodeGen/PseudoSourceValue.cpp index 612293555e6..79b09ee990e 100644 --- a/llvm/lib/CodeGen/PseudoSourceValue.cpp +++ b/llvm/lib/CodeGen/PseudoSourceValue.cpp @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/STLExtras.h" #include "llvm/CodeGen/PseudoSourceValue.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/IR/DerivedTypes.h" @@ -22,44 +23,6 @@ #include using namespace llvm; -namespace { -struct PSVGlobalsTy { - // PseudoSourceValues are immutable so don't need locking. - const PseudoSourceValue StackPSV, GOTPSV, JumpTablePSV, ConstantPoolPSV; - sys::Mutex Lock; // Guards FSValues, but not the values inside it. - std::map FSValues; - - PSVGlobalsTy() - : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT), - JumpTablePSV(PseudoSourceValue::JumpTable), - ConstantPoolPSV(PseudoSourceValue::ConstantPool) {} - ~PSVGlobalsTy() { - for (std::map::iterator - I = FSValues.begin(), - E = FSValues.end(); - I != E; ++I) { - delete I->second; - } - } -}; - -static ManagedStatic PSVGlobals; - -} // anonymous namespace - -const PseudoSourceValue *PseudoSourceValue::getStack() { - return &PSVGlobals->StackPSV; -} -const PseudoSourceValue *PseudoSourceValue::getGOT() { - return &PSVGlobals->GOTPSV; -} -const PseudoSourceValue *PseudoSourceValue::getJumpTable() { - return &PSVGlobals->JumpTablePSV; -} -const PseudoSourceValue *PseudoSourceValue::getConstantPool() { - return &PSVGlobals->ConstantPoolPSV; -} - static const char *const PSVNames[] = { "Stack", "GOT", "JumpTable", "ConstantPool", "FixedStack", "MipsCallEntry"}; @@ -71,15 +34,6 @@ void PseudoSourceValue::printCustom(raw_ostream &O) const { O << PSVNames[Kind]; } -const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) { - PSVGlobalsTy &PG = *PSVGlobals; - sys::ScopedLock locked(PG.Lock); - const PseudoSourceValue *&V = PG.FSValues[FI]; - if (!V) - V = new FixedStackPseudoSourceValue(FI); - return V; -} - bool PseudoSourceValue::isConstant(const MachineFrameInfo *) const { if (isStack()) return false; @@ -121,3 +75,29 @@ bool FixedStackPseudoSourceValue::mayAlias(const MachineFrameInfo *MFI) const { void FixedStackPseudoSourceValue::printCustom(raw_ostream &OS) const { OS << "FixedStack" << FI; } + +PseudoSourceValueManager::PseudoSourceValueManager() + : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT), + JumpTablePSV(PseudoSourceValue::JumpTable), + ConstantPoolPSV(PseudoSourceValue::ConstantPool) {} + +const PseudoSourceValue *PseudoSourceValueManager::getStack() { + return &StackPSV; +} + +const PseudoSourceValue *PseudoSourceValueManager::getGOT() { return &GOTPSV; } + +const PseudoSourceValue *PseudoSourceValueManager::getConstantPool() { + return &ConstantPoolPSV; +} + +const PseudoSourceValue *PseudoSourceValueManager::getJumpTable() { + return &JumpTablePSV; +} + +const PseudoSourceValue *PseudoSourceValueManager::getFixedStack(int FI) { + std::unique_ptr &V = FSValues[FI]; + if (!V) + V = llvm::make_unique(FI); + return V.get(); +} -- cgit v1.2.3