annotate gen/irstate.h @ 945:03d7c4aac654

SWITCHED TO LLVM 2.5 ! Applied patch from ticket #129 to compile against latest LLVM. Thanks Frits van Bommel. Fixed implicit return by asm block at the end of a function on x86-32. Other architectures will produce an error at the moment. Adding support for new targets is fairly simple. Fixed return calling convention for complex numbers, ST and ST(1) were switched around. Added some testcases. I've run a dstress test and there are no regressions. However, the runtime does not seem to compile with symbolic debug information. -O3 -release -inline works well and is what I used for the dstress run. Tango does not compile, a small workaround is needed in tango.io.digest.Digest.Digest.hexDigest. See ticket #206 .
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sun, 08 Feb 2009 05:26:54 +0100
parents 545f54041d91
children 1714836f2c0b
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: 632
diff changeset
1 #ifndef LDC_GEN_IRSTATE_H
eef8ac26c66c Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents: 632
diff changeset
2 #define LDC_GEN_IRSTATE_H
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
4 #include <vector>
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
5 #include <deque>
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
6 #include <list>
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
7 #include <sstream>
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
8
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
9 #include "root.h"
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 108
diff changeset
10 #include "aggregate.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
11
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: 116
diff changeset
12 #include "ir/irfunction.h"
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: 116
diff changeset
13 #include "ir/irstruct.h"
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: 116
diff changeset
14 #include "ir/irvar.h"
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: 116
diff changeset
15
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
16 // global ir state for current module
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
17 struct IRState;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
18 extern IRState* gIR;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 54
diff changeset
19 extern const llvm::TargetData* gTargetData;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
20
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
21 struct TypeFunction;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
22 struct TypeStruct;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
23 struct ClassDeclaration;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
24 struct FuncDeclaration;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
25 struct Module;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
26 struct TypeStruct;
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 108
diff changeset
27 struct BaseClass;
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 664
diff changeset
28 struct AnonDeclaration;
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
29 struct EnclosingHandler;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
30
156
ccd07d9f2ce9 [svn r172] moving all IR state previously stored in Dsymbol into IrDsymbol and a Dsymbol->IrDsymbol map
ChristianK
parents: 155
diff changeset
31 struct IrModule;
ccd07d9f2ce9 [svn r172] moving all IR state previously stored in Dsymbol into IrDsymbol and a Dsymbol->IrDsymbol map
ChristianK
parents: 155
diff changeset
32
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
33 // represents a scope
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
34 struct IRScope
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
35 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
36 llvm::BasicBlock* begin;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
37 llvm::BasicBlock* end;
493
017ca8645a1f Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents: 477
diff changeset
38 IRBuilder<> builder;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
39
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
40 IRScope();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
41 IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
42 };
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
43
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 136
diff changeset
44 // scope for loops
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 136
diff changeset
45 struct IRLoopScope : IRScope
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 136
diff changeset
46 {
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 136
diff changeset
47 // generating statement
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 136
diff changeset
48 Statement* s;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 136
diff changeset
49 // the try of a TryFinally that encloses the loop
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
50 EnclosingHandler* enclosinghandler;
311
9967a3270837 [svn r332] Fix codegen for continue within switch.
ChristianK
parents: 309
diff changeset
51 // if it is a switch, we are a possible target for break
9967a3270837 [svn r332] Fix codegen for continue within switch.
ChristianK
parents: 309
diff changeset
52 // but not for continue
9967a3270837 [svn r332] Fix codegen for continue within switch.
ChristianK
parents: 309
diff changeset
53 bool isSwitch;
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 136
diff changeset
54
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 136
diff changeset
55 IRLoopScope();
311
9967a3270837 [svn r332] Fix codegen for continue within switch.
ChristianK
parents: 309
diff changeset
56 IRLoopScope(Statement* s, EnclosingHandler* enclosinghandler, llvm::BasicBlock* b, llvm::BasicBlock* e, bool isSwitch = false);
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 136
diff changeset
57 };
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 136
diff changeset
58
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
59 struct IRBuilderHelper
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
60 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
61 IRState* state;
493
017ca8645a1f Make llvmdc work with llvm 2.4svn revision 54614. Breaks compatibility with llvm 2.3.
Christian Kamm <kamm incasoftware de>
parents: 477
diff changeset
62 IRBuilder<>* operator->();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
63 };
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
64
232
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 213
diff changeset
65 struct IRAsmStmt
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 213
diff changeset
66 {
477
253f234eb80c Make sure to initialize isBranchToLabel to zero.
Christian Kamm <kamm incasoftware de>
parents: 447
diff changeset
67 IRAsmStmt()
253f234eb80c Make sure to initialize isBranchToLabel to zero.
Christian Kamm <kamm incasoftware de>
parents: 447
diff changeset
68 : isBranchToLabel(NULL) {}
253f234eb80c Make sure to initialize isBranchToLabel to zero.
Christian Kamm <kamm incasoftware de>
parents: 447
diff changeset
69
232
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 213
diff changeset
70 std::string code;
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 213
diff changeset
71 std::string out_c;
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 213
diff changeset
72 std::string in_c;
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 213
diff changeset
73 std::vector<LLValue*> out;
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 213
diff changeset
74 std::vector<LLValue*> in;
299
df8a7b8d5929 [svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents: 252
diff changeset
75
302
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 299
diff changeset
76 // if this is nonzero, it contains the target label
305
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 302
diff changeset
77 Identifier* isBranchToLabel;
232
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 213
diff changeset
78 };
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 213
diff changeset
79
233
76ee1bbe487e [svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents: 232
diff changeset
80 struct IRAsmBlock
76ee1bbe487e [svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents: 232
diff changeset
81 {
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
82 std::deque<IRAsmStmt*> s;
233
76ee1bbe487e [svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents: 232
diff changeset
83 std::set<std::string> clobs;
299
df8a7b8d5929 [svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents: 252
diff changeset
84
df8a7b8d5929 [svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents: 252
diff changeset
85 // stores the labels within the asm block
df8a7b8d5929 [svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents: 252
diff changeset
86 std::vector<Identifier*> internalLabels;
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
87
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
88 AsmBlockStatement* asmBlock;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
89 const LLType* retty;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
90 unsigned retn;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
91
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
92 IRAsmBlock(AsmBlockStatement* b) : asmBlock(b), retty(NULL), retn(0) {}
233
76ee1bbe487e [svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents: 232
diff changeset
93 };
76ee1bbe487e [svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents: 232
diff changeset
94
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
95 // llvm::CallInst and llvm::InvokeInst don't share a common base
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
96 // but share common functionality. to avoid duplicating code for
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
97 // adjusting these common properties these structs are made
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
98 struct CallOrInvoke
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
99 {
632
df196c8dea26 Updated to latest LLVM trunk, function notes have been removed and merged with parameter attributes, which have been renamed to just attributes. Nothing seems to have broke!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 493
diff changeset
100 virtual void setAttributes(const llvm::AttrListPtr& Attrs) = 0;
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
101 virtual void setCallingConv(unsigned CC) = 0;
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
102 virtual llvm::Instruction* get() = 0;
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
103 };
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
104
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
105 struct CallOrInvoke_Call : public CallOrInvoke
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
106 {
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
107 llvm::CallInst* inst;
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
108 CallOrInvoke_Call(llvm::CallInst* call) : inst(call) {}
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
109
632
df196c8dea26 Updated to latest LLVM trunk, function notes have been removed and merged with parameter attributes, which have been renamed to just attributes. Nothing seems to have broke!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 493
diff changeset
110 virtual void setAttributes(const llvm::AttrListPtr& Attrs)
df196c8dea26 Updated to latest LLVM trunk, function notes have been removed and merged with parameter attributes, which have been renamed to just attributes. Nothing seems to have broke!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 493
diff changeset
111 { inst->setAttributes(Attrs); }
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
112 virtual void setCallingConv(unsigned CC)
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
113 { inst->setCallingConv(CC); }
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
114 virtual llvm::Instruction* get()
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
115 { return inst; }
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
116 };
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
117
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
118 struct CallOrInvoke_Invoke : public CallOrInvoke
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
119 {
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
120 llvm::InvokeInst* inst;
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
121 CallOrInvoke_Invoke(llvm::InvokeInst* invoke) : inst(invoke) {}
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
122
632
df196c8dea26 Updated to latest LLVM trunk, function notes have been removed and merged with parameter attributes, which have been renamed to just attributes. Nothing seems to have broke!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 493
diff changeset
123 virtual void setAttributes(const llvm::AttrListPtr& Attrs)
df196c8dea26 Updated to latest LLVM trunk, function notes have been removed and merged with parameter attributes, which have been renamed to just attributes. Nothing seems to have broke!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 493
diff changeset
124 { inst->setAttributes(Attrs); }
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
125 virtual void setCallingConv(unsigned CC)
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
126 { inst->setCallingConv(CC); }
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
127 virtual llvm::Instruction* get()
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
128 { return inst; }
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
129 };
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
130
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
131 // represents the module
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
132 struct IRState
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
133 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
134 IRState();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
135
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
136 // module
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
137 Module* dmodule;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
138 llvm::Module* module;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
139
161
3a891cfcd249 [svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents: 157
diff changeset
140 // interface info type, used in DtoInterfaceInfoType
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
141 const LLStructType* interfaceInfoType;
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
142 const LLStructType* mutexType;
323
0d52412d5b1a [svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents: 319
diff changeset
143 const LLStructType* moduleRefType;
161
3a891cfcd249 [svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents: 157
diff changeset
144
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
145 // functions
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: 116
diff changeset
146 typedef std::vector<IrFunction*> FunctionVector;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
147 FunctionVector functions;
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: 116
diff changeset
148 IrFunction* func();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
149
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
150 llvm::Function* topfunc();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
151 TypeFunction* topfunctype();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
152 llvm::Instruction* topallocapoint();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
153
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
154 // structs
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: 116
diff changeset
155 typedef std::vector<IrStruct*> StructVector;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
156 StructVector structs;
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: 116
diff changeset
157 IrStruct* topstruct();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
158
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
159 // D main function
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
160 bool emitMain;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
161 llvm::Function* mainFunc;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
162
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
163 // basic block scopes
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
164 std::vector<IRScope> scopes;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
165 IRScope& scope();
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 103
diff changeset
166 llvm::BasicBlock* scopebb();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
167 llvm::BasicBlock* scopeend();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
168 bool scopereturned();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
169
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
170 // create a call or invoke, depending on the landing pad info
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
171 // the template function is defined further down in this file
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
172 template <typename InputIterator>
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
173 CallOrInvoke* CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name="");
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
174 CallOrInvoke* CreateCallOrInvoke(LLValue* Callee, const char* Name="");
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
175 CallOrInvoke* CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name="");
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
176 CallOrInvoke* CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name="");
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
177 CallOrInvoke* CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name="");
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
178 CallOrInvoke* CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, LLValue* Arg4, const char* Name="");
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
179
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
180 // loop blocks
145
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 136
diff changeset
181 typedef std::vector<IRLoopScope> LoopScopeVec;
8f704cb9969b [svn r150] fixes #16 and #17, implements GotoCaseStatement
ChristianK
parents: 136
diff changeset
182 LoopScopeVec loopbbs;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
183
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
184 // this holds the array being indexed or sliced so $ will work
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
185 // might be a better way but it works. problem is I only get a
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
186 // VarDeclaration for __dollar, but I can't see how to get the
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
187 // array pointer from this :(
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 82
diff changeset
188 std::vector<DValue*> arrays;
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 6
diff changeset
189
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
190 // builder helper
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 31
diff changeset
191 IRBuilderHelper ir;
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 94
diff changeset
192
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
193 typedef std::list<Dsymbol*> DsymbolList;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
194 // dsymbols that need to be resolved
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
195 DsymbolList resolveList;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
196 // dsymbols that need to be declared
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
197 DsymbolList declareList;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
198 // dsymbols that need constant initializers constructed
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
199 DsymbolList constInitList;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
200 // dsymbols that need definitions
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
201 DsymbolList defineList;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
202
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
203 // static ctors/dtors/unittests
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
204 typedef std::vector<FuncDeclaration*> FuncDeclVector;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
205 FuncDeclVector ctors;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
206 FuncDeclVector dtors;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
207 FuncDeclVector unitTests;
232
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 213
diff changeset
208
092468448d25 [svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents: 213
diff changeset
209 // for inline asm
233
76ee1bbe487e [svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents: 232
diff changeset
210 IRAsmBlock* asmBlock;
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
211 std::ostringstream nakedAsm;
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
212
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
213 // 'used' array solely for keeping a reference to globals
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
214 std::vector<LLConstant*> usedArray;
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 233
diff changeset
215
252
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
216 // dwarf dbg stuff
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
217 LLGlobalVariable* dwarfCUs;
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
218 LLGlobalVariable* dwarfSPs;
e3355ce5444b [svn r269] Fixed dwarf debug info for structs.
lindquist
parents: 250
diff changeset
219 LLGlobalVariable* dwarfGVs;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
220 };
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
221
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
222 template <typename InputIterator>
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
223 CallOrInvoke* IRState::CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name)
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
224 {
319
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
225 llvm::BasicBlock* pad;
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
226 if(pad = func()->landingPad.get())
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
227 {
447
f7259fa1349c Fixed problem with invoking intrinsics, which llvm doesn't allow.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 334
diff changeset
228 // intrinsics don't support invoking
f7259fa1349c Fixed problem with invoking intrinsics, which llvm doesn't allow.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 334
diff changeset
229 LLFunction* funcval = llvm::dyn_cast<LLFunction>(Callee);
f7259fa1349c Fixed problem with invoking intrinsics, which llvm doesn't allow.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 334
diff changeset
230 if (funcval && funcval->isIntrinsic())
f7259fa1349c Fixed problem with invoking intrinsics, which llvm doesn't allow.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 334
diff changeset
231 {
f7259fa1349c Fixed problem with invoking intrinsics, which llvm doesn't allow.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 334
diff changeset
232 return new CallOrInvoke_Call(ir->CreateCall(Callee, ArgBegin, ArgEnd, Name));
f7259fa1349c Fixed problem with invoking intrinsics, which llvm doesn't allow.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 334
diff changeset
233 }
f7259fa1349c Fixed problem with invoking intrinsics, which llvm doesn't allow.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 334
diff changeset
234
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
235 llvm::BasicBlock* postinvoke = llvm::BasicBlock::Create("postinvoke", topfunc(), scopeend());
319
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
236 llvm::InvokeInst* invoke = ir->CreateInvoke(Callee, postinvoke, pad, ArgBegin, ArgEnd, Name);
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
237 scope() = IRScope(postinvoke, scopeend());
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
238 return new CallOrInvoke_Invoke(invoke);
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
239 }
319
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
240 else
e9c93739bc4c [svn r340] Rework exception handling to work with nested tryfinally and trycatch.
ChristianK
parents: 315
diff changeset
241 return new CallOrInvoke_Call(ir->CreateCall(Callee, ArgBegin, ArgEnd, Name));
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
242 }
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 314
diff changeset
243
664
eef8ac26c66c Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents: 632
diff changeset
244 #endif // LDC_GEN_IRSTATE_H