LLVM  4.0.0
ARMConstantPoolValue.cpp
Go to the documentation of this file.
1 //===-- ARMConstantPoolValue.cpp - ARM constantpool value -----------------===//
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 ARM specific constantpool value class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "ARMConstantPoolValue.h"
15 #include "llvm/ADT/FoldingSet.h"
17 #include "llvm/IR/Constant.h"
18 #include "llvm/IR/Constants.h"
19 #include "llvm/IR/GlobalValue.h"
20 #include "llvm/IR/Type.h"
22 #include <cstdlib>
23 using namespace llvm;
24 
25 //===----------------------------------------------------------------------===//
26 // ARMConstantPoolValue
27 //===----------------------------------------------------------------------===//
28 
30  ARMCP::ARMCPKind kind,
31  unsigned char PCAdj,
32  ARMCP::ARMCPModifier modifier,
33  bool addCurrentAddress)
34  : MachineConstantPoolValue(Ty), LabelId(id), Kind(kind),
35  PCAdjust(PCAdj), Modifier(modifier),
36  AddCurrentAddress(addCurrentAddress) {}
37 
39  ARMCP::ARMCPKind kind,
40  unsigned char PCAdj,
41  ARMCP::ARMCPModifier modifier,
42  bool addCurrentAddress)
43  : MachineConstantPoolValue((Type*)Type::getInt32Ty(C)),
44  LabelId(id), Kind(kind), PCAdjust(PCAdj), Modifier(modifier),
45  AddCurrentAddress(addCurrentAddress) {}
46 
48 
50  switch (Modifier) {
51  // FIXME: Are these case sensitive? It'd be nice to lower-case all the
52  // strings if that's legal.
53  case ARMCP::no_modifier:
54  return "none";
55  case ARMCP::TLSGD:
56  return "tlsgd";
57  case ARMCP::GOT_PREL:
58  return "GOT_PREL";
59  case ARMCP::GOTTPOFF:
60  return "gottpoff";
61  case ARMCP::TPOFF:
62  return "tpoff";
63  case ARMCP::SBREL:
64  return "SBREL";
65  case ARMCP::SECREL:
66  return "secrel32";
67  }
68  llvm_unreachable("Unknown modifier!");
69 }
70 
72  unsigned Alignment) {
73  llvm_unreachable("Shouldn't be calling this directly!");
74 }
75 
76 void
78  ID.AddInteger(LabelId);
79  ID.AddInteger(PCAdjust);
80 }
81 
82 bool
84  if (ACPV->Kind == Kind &&
85  ACPV->PCAdjust == PCAdjust &&
86  ACPV->Modifier == Modifier &&
87  ACPV->LabelId == LabelId &&
88  ACPV->AddCurrentAddress == AddCurrentAddress) {
89  // Two PC relative constpool entries containing the same GV address or
90  // external symbols. FIXME: What about blockaddress?
91  if (Kind == ARMCP::CPValue || Kind == ARMCP::CPExtSymbol)
92  return true;
93  }
94  return false;
95 }
96 
98  errs() << " " << *this;
99 }
100 
102  if (Modifier) O << "(" << getModifierText() << ")";
103  if (PCAdjust != 0) {
104  O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
105  if (AddCurrentAddress) O << "-.";
106  O << ")";
107  }
108 }
109 
110 //===----------------------------------------------------------------------===//
111 // ARMConstantPoolConstant
112 //===----------------------------------------------------------------------===//
113 
114 ARMConstantPoolConstant::ARMConstantPoolConstant(Type *Ty,
115  const Constant *C,
116  unsigned ID,
118  unsigned char PCAdj,
119  ARMCP::ARMCPModifier Modifier,
120  bool AddCurrentAddress)
121  : ARMConstantPoolValue(Ty, ID, Kind, PCAdj, Modifier, AddCurrentAddress),
122  CVal(C) {}
123 
124 ARMConstantPoolConstant::ARMConstantPoolConstant(const Constant *C,
125  unsigned ID,
127  unsigned char PCAdj,
128  ARMCP::ARMCPModifier Modifier,
129  bool AddCurrentAddress)
130  : ARMConstantPoolValue((Type*)C->getType(), ID, Kind, PCAdj, Modifier,
131  AddCurrentAddress),
132  CVal(C) {}
133 
134 ARMConstantPoolConstant::ARMConstantPoolConstant(const GlobalVariable *GV,
135  const Constant *C)
136  : ARMConstantPoolValue((Type *)C->getType(), 0, ARMCP::CPPromotedGlobal, 0,
137  ARMCP::no_modifier, false),
138  CVal(C), GVar(GV) {}
139 
142  return new ARMConstantPoolConstant(C, ID, ARMCP::CPValue, 0,
143  ARMCP::no_modifier, false);
144 }
145 
148  const Constant *Initializer) {
149  return new ARMConstantPoolConstant(GVar, Initializer);
150 }
151 
154  ARMCP::ARMCPModifier Modifier) {
156  GV, 0, ARMCP::CPValue, 0,
157  Modifier, false);
158 }
159 
162  ARMCP::ARMCPKind Kind, unsigned char PCAdj) {
163  return new ARMConstantPoolConstant(C, ID, Kind, PCAdj,
164  ARMCP::no_modifier, false);
165 }
166 
169  ARMCP::ARMCPKind Kind, unsigned char PCAdj,
170  ARMCP::ARMCPModifier Modifier,
171  bool AddCurrentAddress) {
172  return new ARMConstantPoolConstant(C, ID, Kind, PCAdj, Modifier,
173  AddCurrentAddress);
174 }
175 
177  return dyn_cast_or_null<GlobalValue>(CVal);
178 }
179 
181  return dyn_cast_or_null<BlockAddress>(CVal);
182 }
183 
185  unsigned Alignment) {
186  return getExistingMachineCPValueImpl<ARMConstantPoolConstant>(CP, Alignment);
187 }
188 
191  return ACPC && ACPC->CVal == CVal && ARMConstantPoolValue::hasSameValue(ACPV);
192 }
193 
195  ID.AddPointer(CVal);
197 }
198 
200  O << CVal->getName();
202 }
203 
204 //===----------------------------------------------------------------------===//
205 // ARMConstantPoolSymbol
206 //===----------------------------------------------------------------------===//
207 
208 ARMConstantPoolSymbol::ARMConstantPoolSymbol(LLVMContext &C, StringRef s,
209  unsigned id, unsigned char PCAdj,
210  ARMCP::ARMCPModifier Modifier,
211  bool AddCurrentAddress)
212  : ARMConstantPoolValue(C, id, ARMCP::CPExtSymbol, PCAdj, Modifier,
213  AddCurrentAddress),
214  S(s) {}
215 
217  StringRef s, unsigned ID,
218  unsigned char PCAdj) {
219  return new ARMConstantPoolSymbol(C, s, ID, PCAdj, ARMCP::no_modifier, false);
220 }
221 
223  unsigned Alignment) {
224  return getExistingMachineCPValueImpl<ARMConstantPoolSymbol>(CP, Alignment);
225 }
226 
229  return ACPS && ACPS->S == S && ARMConstantPoolValue::hasSameValue(ACPV);
230 }
231 
233  ID.AddString(S);
235 }
236 
238  O << S;
240 }
241 
242 //===----------------------------------------------------------------------===//
243 // ARMConstantPoolMBB
244 //===----------------------------------------------------------------------===//
245 
246 ARMConstantPoolMBB::ARMConstantPoolMBB(LLVMContext &C,
247  const MachineBasicBlock *mbb,
248  unsigned id, unsigned char PCAdj,
249  ARMCP::ARMCPModifier Modifier,
250  bool AddCurrentAddress)
251  : ARMConstantPoolValue(C, id, ARMCP::CPMachineBasicBlock, PCAdj,
252  Modifier, AddCurrentAddress),
253  MBB(mbb) {}
254 
256  const MachineBasicBlock *mbb,
257  unsigned ID,
258  unsigned char PCAdj) {
259  return new ARMConstantPoolMBB(C, mbb, ID, PCAdj, ARMCP::no_modifier, false);
260 }
261 
263  unsigned Alignment) {
264  return getExistingMachineCPValueImpl<ARMConstantPoolMBB>(CP, Alignment);
265 }
266 
268  const ARMConstantPoolMBB *ACPMBB = dyn_cast<ARMConstantPoolMBB>(ACPV);
269  return ACPMBB && ACPMBB->MBB == MBB &&
271 }
272 
274  ID.AddPointer(MBB);
276 }
277 
279  O << "BB#" << MBB->getNumber();
281 }
void AddPointer(const void *Ptr)
Add* - Add various data types to Bit data.
Definition: FoldingSet.cpp:52
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static ARMConstantPoolSymbol * Create(LLVMContext &C, StringRef s, unsigned ID, unsigned char PCAdj)
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:450
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) override
ARMConstantPoolValue - ARM specific constantpool value.
Global Offset Table, Thread Pointer Offset.
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:905
Global Offset Table, PC Relative.
Thread Pointer Offset.
void print(raw_ostream &O) const override
print - Implement operator<<
const GlobalValue * getGV() const
ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind, unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, bool AddCurrentAddress)
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:191
The address of a basic block.
Definition: Constants.h:822
int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) override
void AddInteger(signed I)
Definition: FoldingSet.cpp:61
void print(raw_ostream &O) const override
print - Implement operator<<
const BlockAddress * getBlockAddress() const
MachineBasicBlock * MBB
int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) override
Function Alias Analysis false
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
bool hasSameValue(ARMConstantPoolValue *ACPV) override
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:316
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
This is an important base class in LLVM.
Definition: Constant.h:42
This file contains the declarations for the subclasses of Constant, which represent the different fla...
virtual bool hasSameValue(ARMConstantPoolValue *ACPV)
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
bool hasSameValue(ARMConstantPoolValue *ACPV) override
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
Thread Local Storage (General Dynamic Mode)
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:654
Abstract base class for all machine specific constantpool value subclasses.
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
static ARMConstantPoolMBB * Create(LLVMContext &C, const MachineBasicBlock *mbb, unsigned ID, unsigned char PCAdj)
void print(raw_ostream &O) const override
print - Implement operator<<
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
ARMConstantPoolConstant - ARM-specific constant pool values for Constants, Functions, and BlockAddresses.
ARMConstantPoolSymbol - ARM-specific constantpool values for external symbols.
bool hasSameValue(ARMConstantPoolValue *ACPV) override
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
ARMConstantPoolMBB - ARM-specific constantpool value of a machine basic block.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
void print(raw_ostream &O) const override
print - Implement operator<<
Section Relative (Windows TLS)
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:169
void AddString(StringRef String)
Definition: FoldingSet.cpp:87
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:287
const unsigned Kind
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) override
static ARMConstantPoolConstant * Create(const Constant *C, unsigned ID)