//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/STLExtras.h"
#include "llvm/CodeGen/PseudoSourceValue.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include <map>
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<int, const PseudoSourceValue *> FSValues;
-
- PSVGlobalsTy()
- : StackPSV(PseudoSourceValue::Stack), GOTPSV(PseudoSourceValue::GOT),
- JumpTablePSV(PseudoSourceValue::JumpTable),
- ConstantPoolPSV(PseudoSourceValue::ConstantPool) {}
- ~PSVGlobalsTy() {
- for (std::map<int, const PseudoSourceValue *>::iterator
- I = FSValues.begin(),
- E = FSValues.end();
- I != E; ++I) {
- delete I->second;
- }
- }
-};
-
-static ManagedStatic<PSVGlobalsTy> 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"};
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;
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<FixedStackPseudoSourceValue> &V = FSValues[FI];
+ if (!V)
+ V = llvm::make_unique<FixedStackPseudoSourceValue>(FI);
+ return V.get();
+}