Mercurial > projects > ldc
annotate ir/irfunction.h @ 1592:91af6d05338c
Fix codegen for foreach with ref value being lowered to for.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sat, 07 Nov 2009 13:51:05 +0100 |
parents | e1e93343fc11 |
children |
rev | line source |
---|---|
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
584
diff
changeset
|
1 #ifndef LDC_IR_IRFUNCTION_H |
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
584
diff
changeset
|
2 #define LDC_IR_IRFUNCTION_H |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
3 |
1024
9167d492cbc2
Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
946
diff
changeset
|
4 #include "gen/llvm.h" |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
5 #include "ir/ir.h" |
319
e9c93739bc4c
[svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents:
309
diff
changeset
|
6 #include "ir/irlandingpad.h" |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
7 |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
8 #include <vector> |
355
d8357f7004ca
[svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents:
353
diff
changeset
|
9 #include <stack> |
d8357f7004ca
[svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents:
353
diff
changeset
|
10 #include <map> |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
11 |
1145
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
12 struct Statement; |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
13 struct EnclosingHandler; |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
14 |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
15 // scope statements that can be target of jumps |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
16 // includes loops, switch, case, labels |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
17 struct IRTargetScope |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
18 { |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
19 // generating statement |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
20 Statement* s; |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
21 |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
22 // the try of a TryFinally that encloses the loop |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
23 EnclosingHandler* enclosinghandler; |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
24 |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
25 llvm::BasicBlock* breakTarget; |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
26 llvm::BasicBlock* continueTarget; |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
27 |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
28 IRTargetScope(); |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
29 IRTargetScope(Statement* s, EnclosingHandler* enclosinghandler, llvm::BasicBlock* continueTarget, llvm::BasicBlock* breakTarget); |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
30 }; |
40caa8207b3e
Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
31 |
1508
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
32 struct FuncGen |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
33 { |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
34 FuncGen(); |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
35 |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
36 // pushes a unique label scope of the given name |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
37 void pushUniqueLabelScope(const char* name); |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
38 // pops a label scope |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
39 void popLabelScope(); |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
40 |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
41 // gets the string under which the label's BB |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
42 // is stored in the labelToBB map. |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
43 // essentially prefixes ident by the strings in labelScopes |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
44 std::string getScopedLabelName(const char* ident); |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
45 |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
46 // label to basic block lookup |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
47 typedef std::map<std::string, llvm::BasicBlock*> LabelToBBMap; |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
48 LabelToBBMap labelToBB; |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
49 |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
50 // loop blocks |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
51 typedef std::vector<IRTargetScope> TargetScopeVec; |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
52 TargetScopeVec targetScopes; |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
53 |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
54 // landing pads for try statements |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
55 IRLandingPad landingPadInfo; |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
56 llvm::BasicBlock* landingPad; |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
57 |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
58 private: |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
59 // prefix for labels and gotos |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
60 // used for allowing labels to be emitted twice |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
61 std::vector<std::string> labelScopes; |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
62 |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
63 // next unique id stack |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
64 std::stack<int> nextUnique; |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
65 }; |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
66 |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
67 // represents a function |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
68 struct IrFunction : IrBase |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
69 { |
1508
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
70 // constructor |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
71 IrFunction(FuncDeclaration* fd); |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
72 |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
73 // annotations |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
74 void setNeverInline(); |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
75 void setAlwaysInline(); |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
76 |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
77 llvm::Function* func; |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
78 llvm::Instruction* allocapoint; |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
79 FuncDeclaration* decl; |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
80 TypeFunction* type; |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
81 |
1508
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
82 FuncGen* gen; |
e1e93343fc11
Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents:
1412
diff
changeset
|
83 |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
84 bool queued; |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
85 bool defined; |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
355
diff
changeset
|
86 |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
355
diff
changeset
|
87 llvm::Value* retArg; // return in ptr arg |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
355
diff
changeset
|
88 llvm::Value* thisArg; // class/struct 'this' arg |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
355
diff
changeset
|
89 llvm::Value* nestArg; // nested function 'this' arg |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
355
diff
changeset
|
90 |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
355
diff
changeset
|
91 llvm::Value* nestedVar; // nested var alloca |
1216
033f18ec1371
Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents:
1212
diff
changeset
|
92 const llvm::StructType* frameType; // type of nested context (not for -nested-ctx=array) |
1223 | 93 // number of enclosing functions with variables accessed by nested functions |
94 // (-1 if neither this function nor any enclosing ones access variables from enclosing functions) | |
95 int depth; | |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
355
diff
changeset
|
96 |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
97 llvm::Value* _arguments; |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
98 llvm::Value* _argptr; |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
355
diff
changeset
|
99 |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
936
diff
changeset
|
100 llvm::DISubprogram diSubprogram; |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
101 }; |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
102 |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
diff
changeset
|
103 #endif |