Mercurial > projects > ldc
annotate gen/passes/GarbageCollect2Stack.cpp @ 1297:8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
such are eligible for stack-allocation now.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Sun, 03 May 2009 18:01:45 +0200 |
parents | 0e79fb40c4d0 |
children | 7e303f9f16c7 |
rev | line source |
---|---|
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
1 //===- GarbageCollect2Stack - Optimize calls to the D garbage collector ---===// |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
2 // |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
3 // The LLVM D Compiler |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
4 // |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
5 // This file is distributed under the University of Illinois Open Source |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
6 // License. See LICENSE.TXT for details. |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
7 // |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
8 //===----------------------------------------------------------------------===// |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
9 // |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
10 // This file attempts to turn allocations on the garbage-collected heap into |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
11 // stack allocations. |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
12 // |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
13 //===----------------------------------------------------------------------===// |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
14 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
15 #include "gen/metadata.h" |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
16 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
17 // This pass doesn't work without metadata, so #ifdef it out entirely if the |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
18 // LLVM version in use doesn't support it. |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
19 #ifdef USE_METADATA |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
20 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
21 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
22 #define DEBUG_TYPE "dgc2stack" |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
23 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
24 #include "Passes.h" |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
25 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
26 #include "llvm/Pass.h" |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
27 #include "llvm/Module.h" |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
28 #include "llvm/Support/CallSite.h" |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
29 #include "llvm/Support/CommandLine.h" |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
30 #include "llvm/Support/IRBuilder.h" |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
31 #include "llvm/Analysis/CaptureTracking.h" |
1297
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
32 #include "llvm/Analysis/ValueTracking.h" |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
33 #include "llvm/Analysis/LoopInfo.h" |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
34 #include "llvm/Target/TargetData.h" |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
35 #include "llvm/ADT/StringMap.h" |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
36 #include "llvm/ADT/Statistic.h" |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
37 #include "llvm/Support/Compiler.h" |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
38 #include "llvm/Support/Debug.h" |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
39 using namespace llvm; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
40 |
1297
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
41 STATISTIC(NumGcToStack, "Number of calls promoted to constant-size allocas"); |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
42 STATISTIC(NumToDynSize, "Number of calls promoted to dynamically-sized allocas"); |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
43 STATISTIC(NumDeleted, "Number of GC calls deleted because the return value was unused"); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
44 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
45 //===----------------------------------------------------------------------===// |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
46 // GarbageCollect2Stack Pass Implementation |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
47 //===----------------------------------------------------------------------===// |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
48 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
49 namespace { |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
50 struct FunctionInfo { |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
51 unsigned TypeInfoArgNr; |
1297
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
52 int ArrSizeArgNr; |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
53 bool SafeToDelete; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
54 |
1297
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
55 FunctionInfo(unsigned typeInfoArgNr, int arrSizeArgNr, bool safeToDelete) |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
56 : TypeInfoArgNr(typeInfoArgNr), ArrSizeArgNr(arrSizeArgNr), |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
57 SafeToDelete(safeToDelete) {} |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
58 }; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
59 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
60 /// This pass replaces GC calls with alloca's |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
61 /// |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
62 class VISIBILITY_HIDDEN GarbageCollect2Stack : public FunctionPass { |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
63 StringMap<FunctionInfo*> KnownFunctions; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
64 Module* M; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
65 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
66 public: |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
67 static char ID; // Pass identification |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
68 GarbageCollect2Stack() : FunctionPass(&ID) {} |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
69 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
70 bool doInitialization(Module &M); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
71 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
72 bool runOnFunction(Function &F); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
73 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
74 virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
75 AU.addRequired<TargetData>(); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
76 AU.addRequired<LoopInfo>(); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
77 } |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
78 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
79 private: |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
80 const Type* getTypeFor(Value* typeinfo); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
81 }; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
82 char GarbageCollect2Stack::ID = 0; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
83 } // end anonymous namespace. |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
84 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
85 static RegisterPass<GarbageCollect2Stack> |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
86 X("dgc2stack", "Promote (GC'ed) heap allocations to stack"); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
87 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
88 // Public interface to the pass. |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
89 FunctionPass *createGarbageCollect2Stack() { |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
90 return new GarbageCollect2Stack(); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
91 } |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
92 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
93 bool GarbageCollect2Stack::doInitialization(Module &M) { |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
94 this->M = &M; |
1297
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
95 KnownFunctions["_d_allocmemoryT"] = new FunctionInfo(0, -1, true); |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
96 KnownFunctions["_d_newarrayvT"] = new FunctionInfo(0, 1, true); |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
97 } |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
98 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
99 /// runOnFunction - Top level algorithm. |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
100 /// |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
101 bool GarbageCollect2Stack::runOnFunction(Function &F) { |
1295
0e79fb40c4d0
Remove some overly verbose debug output
Frits van Bommel <fvbommel wxs.nl>
parents:
1291
diff
changeset
|
102 DEBUG(DOUT << "Running -dgc2stack on function " << F.getName() << '\n'); |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
103 |
1297
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
104 TargetData &TD = getAnalysis<TargetData>(); |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
105 const LoopInfo &LI = getAnalysis<LoopInfo>(); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
106 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
107 BasicBlock& Entry = F.getEntryBlock(); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
108 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
109 IRBuilder<> AllocaBuilder(&Entry, Entry.begin()); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
110 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
111 bool Changed = false; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
112 for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
113 // We don't yet have sufficient analysis to properly determine if |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
114 // allocations will be unreferenced when the loop returns to their |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
115 // allocation point, so we're playing it safe by ignoring allocations |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
116 // in loops. |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
117 // TODO: Analyze loops too... |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
118 if (LI.getLoopFor(BB)) { |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
119 continue; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
120 } |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
121 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
122 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) { |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
123 // Ignore non-calls. |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
124 Instruction* Inst = I++; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
125 CallSite CS = CallSite::get(Inst); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
126 if (!CS.getInstruction()) |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
127 continue; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
128 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
129 // Ignore indirect calls and calls to non-external functions. |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
130 Function *Callee = CS.getCalledFunction(); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
131 if (Callee == 0 || !Callee->isDeclaration() || |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
132 !(Callee->hasExternalLinkage() || Callee->hasDLLImportLinkage())) |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
133 continue; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
134 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
135 // Ignore unknown calls. |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
136 const char *CalleeName = Callee->getNameStart(); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
137 StringMap<FunctionInfo*>::iterator OMI = |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
138 KnownFunctions.find(CalleeName, CalleeName+Callee->getNameLen()); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
139 if (OMI == KnownFunctions.end()) continue; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
140 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
141 assert(isa<PointerType>(Inst->getType()) |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
142 && "GC function doesn't return a pointer?"); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
143 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
144 FunctionInfo* info = OMI->getValue(); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
145 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
146 if (Inst->use_empty() && info->SafeToDelete) { |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
147 Changed = true; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
148 NumDeleted++; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
149 Inst->eraseFromParent(); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
150 continue; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
151 } |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
152 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
153 DEBUG(DOUT << "GarbageCollect2Stack inspecting: " << *Inst); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
154 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
155 if (PointerMayBeCaptured(Inst, true)) { |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
156 continue; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
157 } |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
158 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
159 Value* TypeInfo = CS.getArgument(info->TypeInfoArgNr); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
160 const Type* Ty = getTypeFor(TypeInfo); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
161 if (!Ty) { |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
162 continue; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
163 } |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
164 |
1297
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
165 Value* arrSize = 0; |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
166 if (info->ArrSizeArgNr != -1) { |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
167 arrSize = CS.getArgument(info->ArrSizeArgNr); |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
168 const IntegerType* SizeType = |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
169 dyn_cast<IntegerType>(arrSize->getType()); |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
170 if (!SizeType) |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
171 continue; |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
172 unsigned bits = SizeType->getBitWidth(); |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
173 if (bits > 32) { |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
174 // The array size of an alloca must be an i32, so make sure |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
175 // the conversion is safe. |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
176 APInt Mask = APInt::getHighBitsSet(bits, bits - 32); |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
177 APInt KnownZero(bits, 0), KnownOne(bits, 0); |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
178 ComputeMaskedBits(arrSize, Mask, KnownZero, KnownOne, &TD); |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
179 if ((KnownZero & Mask) != Mask) |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
180 continue; |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
181 } |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
182 // Extract the element type from the array type. |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
183 const StructType* ArrTy = dyn_cast<StructType>(Ty); |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
184 assert(ArrTy && "Dynamic array type not a struct?"); |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
185 assert(isa<IntegerType>(ArrTy->getElementType(0))); |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
186 const PointerType* PtrTy = |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
187 cast<PointerType>(ArrTy->getElementType(1)); |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
188 Ty = PtrTy->getElementType(); |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
189 } |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
190 |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
191 // Let's alloca this! |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
192 Changed = true; |
1297
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
193 |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
194 IRBuilder<> Builder(BB, I); |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
195 |
1297
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
196 // If the allocation is of constant size it's best to put it in the |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
197 // entry block, so do so if we're not already there. |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
198 // For dynamically-sized allocations it's best to avoid the overhead |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
199 // of allocating them if possible, so leave those where they are. |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
200 // While we're at it, update statistics too. |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
201 if (!arrSize || isa<Constant>(arrSize)) { |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
202 if (&*BB != &Entry) |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
203 Builder = AllocaBuilder; |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
204 NumGcToStack++; |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
205 } else { |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
206 NumToDynSize++; |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
207 } |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
208 |
1297
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
209 // Convert array size to 32 bits if necessary |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
210 if (arrSize) |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
211 arrSize = Builder.CreateIntCast(arrSize, Type::Int32Ty, false); |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
212 |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
213 Value* newVal = Builder.CreateAlloca(Ty, arrSize, ".nongc_mem"); |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
214 |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
215 // Make sure the type is the same as it was before, and replace all |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
216 // uses of the runtime call with the alloca. |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
217 if (newVal->getType() != Inst->getType()) |
1297
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
218 newVal = Builder.CreateBitCast(newVal, Inst->getType()); |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
219 Inst->replaceAllUsesWith(newVal); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
220 |
1297
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
221 // If this was an invoke instruction, update the control flow. |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
222 if (InvokeInst* Invoke = dyn_cast<InvokeInst>(Inst)) { |
1297
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
223 // Notify the exception landing pad block that we won't be |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
224 // going there anymore. |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
225 Invoke->getUnwindDest()->removePredecessor(Invoke->getParent()); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
226 // Create a branch to the "normal" destination. |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
227 BranchInst::Create(Invoke->getNormalDest(), Invoke->getParent()); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
228 } |
1297
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
229 |
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
230 // Finally, remove the runtime call. |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
231 Inst->eraseFromParent(); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
232 } |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
233 } |
1297
8e8552601ecd
Stack promotion for _d_newarrayvT. Array literals, concatenations (a ~ b) and
Frits van Bommel <fvbommel wxs.nl>
parents:
1295
diff
changeset
|
234 |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
235 return Changed; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
236 } |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
237 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
238 const Type* GarbageCollect2Stack::getTypeFor(Value* typeinfo) { |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
239 GlobalVariable* ti_global = dyn_cast<GlobalVariable>(typeinfo->stripPointerCasts()); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
240 if (!ti_global) |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
241 return NULL; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
242 |
1291
875afb7a93b6
Factor out some constants into the header so producers and consumers of
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
243 std::string metaname = TD_PREFIX; |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
244 metaname.append(ti_global->getNameStart(), ti_global->getNameEnd()); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
245 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
246 GlobalVariable* global = M->getGlobalVariable(metaname); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
247 if (!global || !global->hasInitializer()) |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
248 return NULL; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
249 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
250 MDNode* node = dyn_cast<MDNode>(global->getInitializer()); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
251 if (!node) |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
252 return NULL; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
253 |
1291
875afb7a93b6
Factor out some constants into the header so producers and consumers of
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
254 if (node->getNumOperands() != TD_NumFields || |
875afb7a93b6
Factor out some constants into the header so producers and consumers of
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
255 node->getOperand(TD_Confirm)->stripPointerCasts() != ti_global) |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
256 return NULL; |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
257 |
1291
875afb7a93b6
Factor out some constants into the header so producers and consumers of
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
258 return node->getOperand(TD_Type)->getType(); |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
259 } |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
260 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
261 |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
diff
changeset
|
262 #endif //USE_METADATA |