annotate gen/nested.cpp @ 1210:3d4581761b4c

Add some alignment info where LLVM might otherwise be more pessimistic. In particular, %.nest_arg is always aligned even though it's bitcast from i8*. Pointers in vtables are also guaranteed to be stored at aligned addresses.
author Frits van Bommel <fvbommel wxs.nl>
date Sun, 12 Apr 2009 21:56:43 +0200
parents 8699c450a1a0
children df2227fdc860
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
1 #include "gen/nested.h"
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
2
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
3 #include "gen/dvalue.h"
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
4 #include "gen/irstate.h"
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
5 #include "gen/llvmhelpers.h"
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
6 #include "gen/logger.h"
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
7 #include "gen/tollvm.h"
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
8
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
9 #include "llvm/Support/CommandLine.h"
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
10 namespace cl = llvm::cl;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
11
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
12 /// What the context pointer for a nested function looks like
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
13 enum NestedCtxType {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
14 /// Context is void*[] of pointers to variables.
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
15 /// Variables from higher levels are at the front.
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
16 NCArray,
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
17
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
18 /// Context is a struct containing variables belonging to the parent function.
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
19 /// If the parent function itself has a parent function, one of the members is
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
20 /// a pointer to its context. (linked-list style)
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
21 // FIXME: implement
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
22 // TODO: Functions without any variables accessed by nested functions, but
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
23 // with a parent whose variables are accessed, can use the parent's
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
24 // context.
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
25 // NOTE: This is what DMD seems to do.
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
26 NCStruct,
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
27
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
28 /// Context is a list of pointers to structs. Each function with variables
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
29 /// accessed by nested functions puts them in a struct, and appends a
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
30 /// pointer to that struct to it's local copy of the list.
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
31 NCHybrid
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
32 };
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
33
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
34 static cl::opt<NestedCtxType> nestedCtx("nested-ctx",
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
35 cl::desc("How to construct a nested function's context:"),
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
36 cl::ZeroOrMore,
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
37 cl::values(
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
38 clEnumValN(NCArray, "array", "Array of pointers to variables (including multi-level)"),
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
39 //clEnumValN(NCStruct, "struct", "Struct of variables (with multi-level via linked list)"),
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
40 clEnumValN(NCHybrid, "hybrid", "List of pointers to structs of variables, one per level."),
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
41 clEnumValEnd),
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
42 cl::init(NCHybrid));
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
43
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
44
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
45 /****************************************************************************************/
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
46 /*////////////////////////////////////////////////////////////////////////////////////////
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
47 // NESTED VARIABLE HELPERS
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
48 ////////////////////////////////////////////////////////////////////////////////////////*/
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
49
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
50 static FuncDeclaration* getParentFunc(Dsymbol* sym) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
51 Dsymbol* parent = sym->parent;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
52 assert(parent);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
53 while (parent && !parent->isFuncDeclaration())
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
54 parent = parent->parent;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
55
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
56 return (parent ? parent->isFuncDeclaration() : NULL);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
57 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
58
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
59 DValue* DtoNestedVariable(Loc loc, Type* astype, VarDeclaration* vd)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
60 {
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
61 Logger::println("DtoNestedVariable for %s @ %s", vd->toChars(), loc.toChars());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
62 LOG_SCOPE;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
63
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
64 ////////////////////////////////////
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
65 // Locate context value
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
66
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
67 Dsymbol* vdparent = vd->toParent2();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
68 assert(vdparent);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
69
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
70 IrFunction* irfunc = gIR->func();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
71
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
72 // is the nested variable in this scope?
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
73 if (vdparent == irfunc->decl)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
74 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
75 LLValue* val = vd->ir.getIrValue();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
76 return new DVarValue(astype, vd, val);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
77 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
78
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
79 // get the nested context
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
80 LLValue* ctx = 0;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
81 if (irfunc->decl->isMember2())
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
82 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
83 ClassDeclaration* cd = irfunc->decl->isMember2()->isClassDeclaration();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
84 LLValue* val = DtoLoad(irfunc->thisArg);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
85 ctx = DtoLoad(DtoGEPi(val, 0,cd->vthis->ir.irField->index, ".vthis"));
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
86 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
87 else
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
88 ctx = irfunc->nestArg;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
89 assert(ctx);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
90
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
91 assert(vd->ir.irLocal);
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
92
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
93 ////////////////////////////////////
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
94 // Extract variable from nested context
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
95
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
96 if (nestedCtx == NCArray) {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
97 LLValue* val = DtoBitCast(ctx, getPtrToType(getVoidPtrType()));
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
98 val = DtoGEPi1(val, vd->ir.irLocal->nestedIndex);
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
99 val = DtoAlignedLoad(val);
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
100 assert(vd->ir.irLocal->value);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
101 val = DtoBitCast(val, vd->ir.irLocal->value->getType(), vd->toChars());
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
102 return new DVarValue(astype, vd, val);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
103 }
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
104 else if (nestedCtx == NCHybrid) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
105 FuncDeclaration *parentfunc = getParentFunc(vd);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
106 assert(parentfunc && "No parent function for nested variable?");
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
107
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
108 LLValue* val = DtoBitCast(ctx, LLPointerType::getUnqual(parentfunc->ir.irFunc->framesType));
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
109 val = DtoGEPi(val, 0, vd->ir.irLocal->nestedDepth);
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
110 val = DtoAlignedLoad(val, (std::string(".frame.") + parentfunc->toChars()).c_str());
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
111 val = DtoGEPi(val, 0, vd->ir.irLocal->nestedIndex, vd->toChars());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
112 if (vd->ir.irLocal->byref)
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
113 val = DtoAlignedLoad(val);
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
114 return new DVarValue(astype, vd, val);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
115 }
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
116 else {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
117 assert(0 && "Not implemented yet");
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
118 }
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
119 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
120
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
121 void DtoNestedInit(VarDeclaration* vd)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
122 {
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
123 Logger::println("DtoNestedInit for %s", vd->toChars());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
124 LOG_SCOPE
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
125
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
126 LLValue* nestedVar = gIR->func()->decl->ir.irFunc->nestedVar;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
127
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
128 if (nestedCtx == NCArray) {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
129 // alloca as usual if no value already
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
130 if (!vd->ir.irLocal->value)
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
131 vd->ir.irLocal->value = DtoAlloca(DtoType(vd->type), vd->toChars());
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
132
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
133 // store the address into the nested vars array
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
134 assert(vd->ir.irLocal->nestedIndex >= 0);
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
135 LLValue* gep = DtoGEPi(nestedVar, 0, vd->ir.irLocal->nestedIndex);
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
136
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
137 assert(isaPointer(vd->ir.irLocal->value));
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
138 LLValue* val = DtoBitCast(vd->ir.irLocal->value, getVoidPtrType());
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
139
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
140 DtoAlignedStore(val, gep);
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
141 }
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
142 else if (nestedCtx == NCHybrid) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
143 assert(vd->ir.irLocal->value && "Nested variable without storage?");
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
144 if (!vd->isParameter() && (vd->isRef() || vd->isOut())) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
145 Logger::println("Initializing non-parameter byref value");
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
146 LLValue* framep = DtoGEPi(nestedVar, 0, vd->ir.irLocal->nestedDepth);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
147
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
148 FuncDeclaration *parentfunc = getParentFunc(vd);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
149 assert(parentfunc && "No parent function for nested variable?");
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
150 LLValue* frame = DtoAlignedLoad(framep, (std::string(".frame.") + parentfunc->toChars()).c_str());
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
151
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
152 LLValue* slot = DtoGEPi(frame, 0, vd->ir.irLocal->nestedIndex);
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
153 DtoAlignedStore(vd->ir.irLocal->value, slot);
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
154 } else {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
155 // Already initialized in DtoCreateNestedContext
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
156 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
157 }
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
158 else {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
159 assert(0 && "Not implemented yet");
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
160 }
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
161 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
162
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
163 LLValue* DtoNestedContext(Loc loc, Dsymbol* sym)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
164 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
165 Logger::println("DtoNestedContext for %s", sym->toPrettyChars());
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
166 LOG_SCOPE;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
167
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
168 IrFunction* irfunc = gIR->func();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
169
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
170 // if this func has its own vars that are accessed by nested funcs
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
171 // use its own context
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
172 if (irfunc->nestedVar)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
173 return irfunc->nestedVar;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
174 // otherwise, it may have gotten a context from the caller
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
175 else if (irfunc->nestArg)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
176 return irfunc->nestArg;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
177 // or just have a this argument
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
178 else if (irfunc->thisArg)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
179 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
180 ClassDeclaration* cd = irfunc->decl->isMember2()->isClassDeclaration();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
181 if (!cd || !cd->vthis)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
182 return getNullPtr(getVoidPtrType());
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
183 LLValue* val = DtoLoad(irfunc->thisArg);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
184 return DtoLoad(DtoGEPi(val, 0,cd->vthis->ir.irField->index, ".vthis"));
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
185 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
186 else
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
187 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
188 return getNullPtr(getVoidPtrType());
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
189 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
190 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
191
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
192 void DtoCreateNestedContext(FuncDeclaration* fd) {
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
193 Logger::println("DtoCreateNestedContext for %s", fd->toChars());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
194 LOG_SCOPE
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
195
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
196 if (nestedCtx == NCArray) {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
197 // construct nested variables array
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
198 if (!fd->nestedVars.empty())
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
199 {
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
200 Logger::println("has nested frame");
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
201 // start with adding all enclosing parent frames until a static parent is reached
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
202 int nparelems = 0;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
203 if (!fd->isStatic())
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
204 {
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
205 Dsymbol* par = fd->toParent2();
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
206 while (par)
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
207 {
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
208 if (FuncDeclaration* parfd = par->isFuncDeclaration())
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
209 {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
210 nparelems += parfd->nestedVars.size();
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
211 // stop at first static
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
212 if (parfd->isStatic())
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
213 break;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
214 }
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
215 else if (ClassDeclaration* parcd = par->isClassDeclaration())
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
216 {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
217 // nothing needed
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
218 }
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
219 else
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
220 {
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
221 break;
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
222 }
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
223
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
224 par = par->toParent2();
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
225 }
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
226 }
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
227 int nelems = fd->nestedVars.size() + nparelems;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
228
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
229 // make array type for nested vars
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
230 const LLType* nestedVarsTy = LLArrayType::get(getVoidPtrType(), nelems);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
231
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
232 // alloca it
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
233 LLValue* nestedVars = DtoAlloca(nestedVarsTy, ".nested_vars");
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
234
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
235 IrFunction* irfunction = fd->ir.irFunc;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
236
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
237 // copy parent frame into beginning
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
238 if (nparelems)
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
239 {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
240 LLValue* src = irfunction->nestArg;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
241 if (!src)
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
242 {
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
243 assert(irfunction->thisArg);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
244 assert(fd->isMember2());
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
245 LLValue* thisval = DtoLoad(irfunction->thisArg);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
246 ClassDeclaration* cd = fd->isMember2()->isClassDeclaration();
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
247 assert(cd);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
248 assert(cd->vthis);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
249 src = DtoLoad(DtoGEPi(thisval, 0,cd->vthis->ir.irField->index, ".vthis"));
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
250 }
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
251 DtoMemCpy(nestedVars, src, DtoConstSize_t(nparelems*PTRSIZE),
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
252 getABITypeAlign(getVoidPtrType()));
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
253 }
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
254
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
255 // store in IrFunction
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
256 irfunction->nestedVar = nestedVars;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
257
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
258 // go through all nested vars and assign indices
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
259 int idx = nparelems;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
260 for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i)
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
261 {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
262 VarDeclaration* vd = *i;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
263 if (!vd->ir.irLocal)
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
264 vd->ir.irLocal = new IrLocal(vd);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
265
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
266 if (vd->isParameter())
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
267 {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
268 Logger::println("nested param: %s", vd->toChars());
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
269 LLValue* gep = DtoGEPi(nestedVars, 0, idx);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
270 LLValue* val = DtoBitCast(vd->ir.irLocal->value, getVoidPtrType());
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
271 DtoAlignedStore(val, gep);
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
272 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
273 else
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
274 {
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
275 Logger::println("nested var: %s", vd->toChars());
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
276 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
277
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
278 vd->ir.irLocal->nestedIndex = idx++;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
279 }
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
280 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
281 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
282 else if (nestedCtx == NCHybrid) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
283 // construct nested variables array
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
284 if (!fd->nestedVars.empty())
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
285 {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
286 Logger::println("has nested frame");
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
287 // start with adding all enclosing parent frames until a static parent is reached
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
288 typedef std::vector<const LLType*> TypeVec;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
289 TypeVec frametypes;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
290 if (!fd->isStatic()) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
291 Dsymbol* par = fd->toParent2();
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
292 while (par) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
293 if (FuncDeclaration* parfd = par->isFuncDeclaration()) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
294 // skip functions without nested parameters
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
295 if (!parfd->nestedVars.empty()) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
296 // Copy the types of parent function frames.
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
297 const LLStructType* parft = parfd->ir.irFunc->framesType;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
298 frametypes.insert(frametypes.begin(), parft->element_begin(), parft->element_end());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
299 break; // That's all the info needed.
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
300 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
301 } else if (ClassDeclaration* parcd = par->isClassDeclaration()) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
302 // skip
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
303 } else {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
304 break;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
305 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
306 par = par->toParent2();
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
307 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
308 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
309 unsigned depth = frametypes.size();
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
310
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
311 // Construct a struct for the direct nested variables of this function, and update their indices to match.
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
312 // TODO: optimize ordering for minimal space usage?
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
313 TypeVec types;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
314 for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i)
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
315 {
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
316 VarDeclaration* vd = *i;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
317 if (!vd->ir.irLocal)
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
318 vd->ir.irLocal = new IrLocal(vd);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
319
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
320 vd->ir.irLocal->nestedDepth = depth;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
321 vd->ir.irLocal->nestedIndex = types.size();
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
322 if (vd->isParameter()) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
323 // Parameters already have storage associated with them (to handle byref etc.),
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
324 // so handle specially for now by storing a pointer instead of a value.
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
325 assert(vd->ir.irLocal->value);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
326 // FIXME: don't do this for normal parameters?
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
327 types.push_back(vd->ir.irLocal->value->getType());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
328 } else if (vd->isRef() || vd->isOut()) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
329 // Foreach variables can also be by reference, for instance.
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
330 types.push_back(DtoType(vd->type->pointerTo()));
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
331 } else {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
332 types.push_back(DtoType(vd->type));
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
333 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
334 if (Logger::enabled()) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
335 Logger::println("Nested var: %s", vd->toChars());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
336 Logger::cout() << "of type: " << *types.back() << '\n';
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
337 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
338 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
339 // Append current frame type to frame type list
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
340 const LLType* frameType = LLStructType::get(types);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
341 frametypes.push_back(LLPointerType::getUnqual(frameType));
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
342
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
343 // make struct type for nested frame list
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
344 const LLStructType* nestedVarsTy = LLStructType::get(frametypes);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
345
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
346 // Store type in IrFunction
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
347 IrFunction* irfunction = fd->ir.irFunc;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
348 irfunction->framesType = nestedVarsTy;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
349
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
350 // alloca it
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
351 // FIXME: For D2, this should be a gc_malloc (or similar) call, not alloca
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
352 LLValue* nestedVars = DtoAlloca(nestedVarsTy, ".frame_list");
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
353
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
354 // copy parent frames into beginning
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
355 if (depth != 0)
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
356 {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
357 LLValue* src = irfunction->nestArg;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
358 if (!src)
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
359 {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
360 assert(irfunction->thisArg);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
361 assert(fd->isMember2());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
362 LLValue* thisval = DtoLoad(irfunction->thisArg);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
363 ClassDeclaration* cd = fd->isMember2()->isClassDeclaration();
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
364 assert(cd);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
365 assert(cd->vthis);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
366 Logger::println("Indexing to 'this'");
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
367 src = DtoLoad(DtoGEPi(thisval, 0, cd->vthis->ir.irField->index, ".vthis"));
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
368 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
369 src = DtoBitCast(src, getVoidPtrType());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
370 LLValue* dst = DtoBitCast(nestedVars, getVoidPtrType());
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
371 DtoMemCpy(dst, src, DtoConstSize_t(depth * PTRSIZE),
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
372 getABITypeAlign(getVoidPtrType()));
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
373 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
374
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
375 // Create frame for current function and append to frames list
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
376 LLValue* frame = DtoAlloca(frameType, ".frame");
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
377 // store current frame in list
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
378 DtoAlignedStore(frame, DtoGEPi(nestedVars, 0, depth));
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
379
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
380 // store context in IrFunction
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
381 irfunction->nestedVar = nestedVars;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
382
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
383 // go through all nested vars and assign addresses where possible.
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
384 for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i)
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
385 {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
386 VarDeclaration* vd = *i;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
387
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
388 LLValue* gep = DtoGEPi(frame, 0, vd->ir.irLocal->nestedIndex, vd->toChars());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
389 if (vd->isParameter()) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
390 Logger::println("nested param: %s", vd->toChars());
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
391 DtoAlignedStore(vd->ir.irLocal->value, gep);
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
392 vd->ir.irLocal->byref = true;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
393 } else if (vd->isRef() || vd->isOut()) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
394 // This slot is initialized in DtoNestedInit, to handle things like byref foreach variables
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
395 // which move around in memory.
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
396 vd->ir.irLocal->byref = true;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
397 } else {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
398 Logger::println("nested var: %s", vd->toChars());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
399 if (vd->ir.irLocal->value)
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
400 Logger::cout() << "Pre-existing value: " << *vd->ir.irLocal->value << '\n';
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
401 assert(!vd->ir.irLocal->value);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
402 vd->ir.irLocal->value = gep;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
403 vd->ir.irLocal->byref = false;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
404 }
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
405 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
406 }
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
407 }
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
408 else {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
409 assert(0 && "Not implemented yet");
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
410 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
411 }