LLVM  3.7.0
PseudoSourceValue.cpp
Go to the documentation of this file.
1 //===-- llvm/CodeGen/PseudoSourceValue.cpp ----------------------*- C++ -*-===//
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 implements the PseudoSourceValue class.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 #include "llvm/IR/DerivedTypes.h"
17 #include "llvm/IR/LLVMContext.h"
20 #include "llvm/Support/Mutex.h"
22 #include <map>
23 using namespace llvm;
24 
25 namespace {
26 struct PSVGlobalsTy {
27  // PseudoSourceValues are immutable so don't need locking.
28  const PseudoSourceValue PSVs[4];
29  sys::Mutex Lock; // Guards FSValues, but not the values inside it.
30  std::map<int, const PseudoSourceValue *> FSValues;
31 
32  PSVGlobalsTy() : PSVs() {}
33  ~PSVGlobalsTy() {
34  for (std::map<int, const PseudoSourceValue *>::iterator
35  I = FSValues.begin(), E = FSValues.end(); I != E; ++I) {
36  delete I->second;
37  }
38  }
39 };
40 
41 static ManagedStatic<PSVGlobalsTy> PSVGlobals;
42 
43 } // anonymous namespace
44 
46 { return &PSVGlobals->PSVs[0]; }
48 { return &PSVGlobals->PSVs[1]; }
50 { return &PSVGlobals->PSVs[2]; }
52 { return &PSVGlobals->PSVs[3]; }
53 
54 static const char *const PSVNames[] = {
55  "Stack",
56  "GOT",
57  "JumpTable",
58  "ConstantPool"
59 };
60 
61 PseudoSourceValue::PseudoSourceValue(bool isFixed) : isFixed(isFixed) {}
62 
64 
65 void PseudoSourceValue::printCustom(raw_ostream &O) const {
66  O << PSVNames[this - PSVGlobals->PSVs];
67 }
68 
70  PSVGlobalsTy &PG = *PSVGlobals;
71  sys::ScopedLock locked(PG.Lock);
72  const PseudoSourceValue *&V = PG.FSValues[FI];
73  if (!V)
74  V = new FixedStackPseudoSourceValue(FI);
75  return V;
76 }
77 
79  if (this == getStack())
80  return false;
81  if (this == getGOT() ||
82  this == getConstantPool() ||
83  this == getJumpTable())
84  return true;
85  llvm_unreachable("Unknown PseudoSourceValue!");
86 }
87 
89  if (this == getStack() ||
90  this == getGOT() ||
91  this == getConstantPool() ||
92  this == getJumpTable())
93  return false;
94  llvm_unreachable("Unknown PseudoSourceValue!");
95 }
96 
98  if (this == getGOT() ||
99  this == getConstantPool() ||
100  this == getJumpTable())
101  return false;
102  return true;
103 }
104 
106  return MFI && MFI->isImmutableObjectIndex(FI);
107 }
108 
110  if (!MFI)
111  return true;
112  return MFI->isAliasedObjectIndex(FI);
113 }
114 
116  if (!MFI)
117  return true;
118  // Spill slots will not alias any LLVM IR value.
119  return !MFI->isSpillSlotObjectIndex(FI);
120 }
121 
123  OS << "FixedStack" << FI;
124 }
static const PseudoSourceValue * getConstantPool()
A pseudo source value referencing the constant pool.
static sys::Mutex Lock
static const PseudoSourceValue * getJumpTable()
A pseudo source value referencing a jump table.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
static const PseudoSourceValue * getFixedStack(int FI)
A pseudo source value referencing a fixed stack frame entry, e.g., a spill slot.
bool isImmutableObjectIndex(int ObjectIdx) const
isImmutableObjectIndex - Returns true if the specified index corresponds to an immutable object...
bool isConstant(const MachineFrameInfo *MFI) const override
isConstant - Test whether the memory pointed to by this PseudoSourceValue has a constant value...
bool mayAlias(const MachineFrameInfo *) const override
mayAlias - Return true if the memory pointed to by this PseudoSourceValue can ever alias an LLVM IR V...
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
virtual bool mayAlias(const MachineFrameInfo *) const
mayAlias - Return true if the memory pointed to by this PseudoSourceValue can ever alias an LLVM IR V...
bool isAliasedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to an object that might be pointed to by an LLVM IR v...
virtual bool isConstant(const MachineFrameInfo *) const
isConstant - Test whether the memory pointed to by this PseudoSourceValue has a constant value...
static const PseudoSourceValue * getGOT()
A pseudo source value referencing the global offset table (or something the like).
static const PseudoSourceValue * getStack()
A pseudo source value referencing the area below the stack frame of a function, e.g., the argument space.
PseudoSourceValue - Special value supplied for machine level alias analysis.
#define I(x, y, z)
Definition: MD5.cpp:54
static const char *const PSVNames[]
bool isAliased(const MachineFrameInfo *MFI) const override
isAliased - Test whether the memory pointed to by this PseudoSourceValue may also be pointed to by an...
void printCustom(raw_ostream &OS) const override
printCustom - Implement printing for PseudoSourceValue.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:61
FixedStackPseudoSourceValue - A specialized PseudoSourceValue for holding FixedStack values...
PseudoSourceValue(bool isFixed=false)
virtual bool isAliased(const MachineFrameInfo *) const
isAliased - Test whether the memory pointed to by this PseudoSourceValue may also be pointed to by an...