Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

root/gen/llvmhelpers.h

Revision 1650:40bd4a0d4870, 5.9 kB (checked in by Tomas Lindquist Olsen, 2 years ago)

Update to work with LLVM 2.7.

Removed use of dyn_cast, llvm no compiles
without exceptions and rtti by
default. We do need exceptions for the libconfig stuff, but rtti isn't
necessary (anymore).

Debug info needs to be rewritten, as in LLVM 2.7 the format has
completely changed. To have something to look at while rewriting, the
old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means
that you have to define this to compile at the moment.

Updated tango 0.99.9 patch to include updated EH runtime code, which is
needed for LLVM 2.7 as well.

Line 
1 #ifndef LDC_GEN_LLVMHELPERS_H
2 #define LDC_GEN_LLVMHELPERS_H
3
4 #include "gen/llvm.h"
5 #include "gen/dvalue.h"
6
7 #include "statement.h"
8 #include "mtype.h"
9
10 // this is used for tracking try-finally, synchronized and volatile scopes
11 struct EnclosingHandler
12 {
13     virtual void emitCode(IRState* p) = 0;
14 };
15 struct EnclosingTryFinally : EnclosingHandler
16 {
17     TryFinallyStatement* tf;
18     llvm::BasicBlock* landingPad;
19     void emitCode(IRState* p);
20     EnclosingTryFinally(TryFinallyStatement* _tf, llvm::BasicBlock* _pad)
21     : tf(_tf), landingPad(_pad) {}
22 };
23 struct EnclosingVolatile : EnclosingHandler
24 {
25     VolatileStatement* v;
26     void emitCode(IRState* p);
27     EnclosingVolatile(VolatileStatement* _tf) : v(_tf) {}
28 };
29 struct EnclosingSynchro : EnclosingHandler
30 {
31     SynchronizedStatement* s;
32     void emitCode(IRState* p);
33     EnclosingSynchro(SynchronizedStatement* _tf) : s(_tf) {}
34 };
35
36
37 // dynamic memory helpers
38 LLValue* DtoNew(Type* newtype);
39 void DtoDeleteMemory(LLValue* ptr);
40 void DtoDeleteClass(LLValue* inst);
41 void DtoDeleteInterface(LLValue* inst);
42 void DtoDeleteArray(DValue* arr);
43
44 // emit an alloca
45 llvm::AllocaInst* DtoAlloca(Type* type, const char* name = "");
46 llvm::AllocaInst* DtoArrayAlloca(Type* type, unsigned arraysize, const char* name = "");
47 llvm::AllocaInst* DtoRawAlloca(const llvm::Type* lltype, size_t alignment, const char* name = "");
48
49 // assertion generator
50 void DtoAssert(Module* M, Loc loc, DValue* msg);
51
52 // return the LabelStatement from the current function with the given identifier or NULL if not found
53 LabelStatement* DtoLabelStatement(Identifier* ident);
54
55 /// emits goto to LabelStatement with the target identifier
56 /// the sourceFinally is only used for error checking
57 void DtoGoto(Loc loc, Identifier* target, TryFinallyStatement* sourceFinally);
58
59 // Generates IR for enclosing handlers between the current state and
60 // the scope created by the 'target' statement.
61 void DtoEnclosingHandlers(Loc loc, Statement* target);
62
63 /// Enters a critical section.
64 void DtoEnterCritical(LLValue* g);
65 /// leaves a critical section.
66 void DtoLeaveCritical(LLValue* g);
67
68 /// Enters a monitor lock.
69 void DtoEnterMonitor(LLValue* v);
70 /// Leaves a monitor lock.
71 void DtoLeaveMonitor(LLValue* v);
72
73 // basic operations
74 void DtoAssign(Loc& loc, DValue* lhs, DValue* rhs);
75
76 /// Create a null DValue.
77 DValue* DtoNullValue(Type* t);
78
79 // casts
80 DValue* DtoCastInt(Loc& loc, DValue* val, Type* to);
81 DValue* DtoCastPtr(Loc& loc, DValue* val, Type* to);
82 DValue* DtoCastFloat(Loc& loc, DValue* val, Type* to);
83 DValue* DtoCastDelegate(Loc& loc, DValue* val, Type* to);
84 DValue* DtoCast(Loc& loc, DValue* val, Type* to);
85
86 // return the same val as passed in, modified to the target type, if possible, otherwise returns a new DValue
87 DValue* DtoPaintType(Loc& loc, DValue* val, Type* to);
88
89 // is template instance check, returns module where instantiated
90 TemplateInstance* DtoIsTemplateInstance(Dsymbol* s);
91
92 /// Generate code for the symbol.
93 /// Dispatches as appropriate.
94 void DtoResolveDsymbol(Dsymbol* dsym);
95
96 /// Generates the constant initializer for a global variable.
97 void DtoConstInitGlobal(VarDeclaration* vd);
98
99 // declaration inside a declarationexp
100 DValue* DtoDeclarationExp(Dsymbol* declaration);
101 LLValue* DtoRawVarDeclaration(VarDeclaration* var, LLValue* addr = 0);
102
103 // initializer helpers
104 LLConstant* DtoConstInitializer(Loc loc, Type* type, Initializer* init);
105 LLConstant* DtoConstExpInit(Loc loc, Type* t, Expression* exp);
106 DValue* DtoInitializer(LLValue* target, Initializer* init);
107
108 // annotation generator
109 void DtoAnnotation(const char* str);
110
111 // getting typeinfo of type, base=true casts to object.TypeInfo
112 LLConstant* DtoTypeInfoOf(Type* ty, bool base=true);
113
114 // binary operations
115 DValue* DtoBinAdd(DValue* lhs, DValue* rhs);
116 DValue* DtoBinSub(DValue* lhs, DValue* rhs);
117 // these binops need an explicit result type to handling
118 // to give 'ifloat op float' and 'float op ifloat' the correct type
119 DValue* DtoBinMul(Type* resulttype, DValue* lhs, DValue* rhs);
120 DValue* DtoBinDiv(Type* resulttype, DValue* lhs, DValue* rhs);
121 DValue* DtoBinRem(Type* resulttype, DValue* lhs, DValue* rhs);
122 LLValue* DtoBinNumericEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op);
123
124 // target stuff
125 void findDefaultTarget();
126
127 /// Fixup an overloaded intrinsic name string.
128 void DtoOverloadedIntrinsicName(TemplateInstance* ti, TemplateDeclaration* td, std::string& name);
129
130 /// Returns true if the symbol should be defined in the current module, not just declared.
131 bool mustDefineSymbol(Dsymbol* s);
132
133 /// Returns true if the symbol needs template linkage, or just external.
134 bool needsTemplateLinkage(Dsymbol* s);
135
136 /// Returns true if there is any unaligned type inside the aggregate.
137 bool hasUnalignedFields(Type* t);
138
139 ///
140 DValue* DtoInlineAsmExpr(Loc loc, FuncDeclaration* fd, Expressions* arguments);
141
142 /// Create the IrModule if necessary and returns it.
143 IrModule* getIrModule(Module* M);
144
145 /// Update an offset to make sure it follows both the D and LLVM alignments.
146 /// Returns the offset rounded up to the closest safely aligned offset.
147 size_t realignOffset(size_t offset, Type* type);
148
149 /// Returns the llvm::Value of the passed DValue, making sure that it is an
150 /// lvalue (has a memory address), so it can be passed to the D runtime
151 /// functions without problems.
152 LLValue* makeLValue(Loc& loc, DValue* value);
153
154 ////////////////////////////////////////////
155 // gen/tocall.cpp stuff below
156 ////////////////////////////////////////////
157
158 /// convert DMD calling conv to LLVM
159 llvm::CallingConv::ID DtoCallingConv(Loc loc, LINK l);
160
161 ///
162 TypeFunction* DtoTypeFunction(DValue* fnval);
163
164 ///
165 DValue* DtoVaArg(Loc& loc, Type* type, Expression* valistArg);
166
167 ///
168 LLValue* DtoCallableValue(DValue* fn);
169
170 ///
171 const LLFunctionType* DtoExtractFunctionType(const LLType* type);
172
173 ///
174 void DtoBuildDVarArgList(std::vector<LLValue*>& args, llvm::AttrListPtr& palist, TypeFunction* tf, Expressions* arguments, size_t argidx);
175
176 ///
177 DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions* arguments);
178
179 Type* stripModifiers(Type* type);
180
181 #endif
Note: See TracBrowser for help on using the browser.
Copyright © 2008, LDC Development Team.