annotate ir/irfunction.h @ 1168:ab186e535e72

A different fix to #218 and DMD2682 that does not lead to constant folding regressions. Fixes run/const_15, run/c/const_16_B. The price is removing the lvalueness of struct literals. If it turns out too much code depends on this behavior or we don't want to break with DMD, we could keep struct literals as lvalues and instead convert struct literals used as expression initializers into struct initializers.
author Christian Kamm <kamm incasoftware de>
date Sun, 29 Mar 2009 11:43:45 +0200
parents 40caa8207b3e
children 8699c450a1a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
32 // 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
33 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
34 {
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
35 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
36 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
37 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
38 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
39
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
40 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
41 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
42
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
43 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
44 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
45 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
46
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
47 llvm::Value* nestedVar; // nested var alloca
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
48
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
49 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
50 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
51
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 936
diff changeset
52 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
53
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
54 // pushes a unique label scope of the given name
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
55 void pushUniqueLabelScope(const char* name);
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
56 // pops a label scope
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
57 void popLabelScope();
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
58
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
59 // gets the string under which the label's BB
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
60 // is stored in the labelToBB map.
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
61 // essentially prefixes ident by the strings in labelScopes
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
62 std::string getScopedLabelName(const char* ident);
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
63
353
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 319
diff changeset
64 // label to basic block lookup
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 319
diff changeset
65 typedef std::map<std::string, llvm::BasicBlock*> LabelToBBMap;
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 319
diff changeset
66 LabelToBBMap labelToBB;
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 319
diff changeset
67
319
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 309
diff changeset
68 // landing pads for try statements
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 309
diff changeset
69 IRLandingPad landingPad;
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 309
diff changeset
70
1145
40caa8207b3e Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1051
diff changeset
71 // loop blocks
40caa8207b3e Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1051
diff changeset
72 typedef std::vector<IRTargetScope> TargetScopeVec;
40caa8207b3e Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1051
diff changeset
73 TargetScopeVec targetScopes;
40caa8207b3e Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1051
diff changeset
74
40caa8207b3e Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1051
diff changeset
75 // constructor
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
76 IrFunction(FuncDeclaration* fd);
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
77
584
c7d7e2282ba3 Make sure functions containing inline asm are never inlined to avoid
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
78 // annotations
c7d7e2282ba3 Make sure functions containing inline asm are never inlined to avoid
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
79 void setNeverInline();
c7d7e2282ba3 Make sure functions containing inline asm are never inlined to avoid
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
80 void setAlwaysInline();
c7d7e2282ba3 Make sure functions containing inline asm are never inlined to avoid
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
81
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
82 private:
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
83 // prefix for labels and gotos
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
84 // used for allowing labels to be emitted twice
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
85 std::vector<std::string> labelScopes;
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
86
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
87 // next unique id 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
88 std::stack<int> nextUnique;
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
89 };
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
90
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
91 #endif