annotate gen/naked.cpp @ 1650:40bd4a0d4870

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.
author Tomas Lindquist Olsen
date Wed, 19 May 2010 12:42:32 +0200
parents 8d086d552909
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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:
diff changeset
1 #include "gen/llvm.h"
1152
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
2 #include "llvm/InlineAsm.h"
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:
diff changeset
3
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:
diff changeset
4 #include "expression.h"
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:
diff changeset
5 #include "statement.h"
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:
diff changeset
6 #include "declaration.h"
1152
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
7 #include "template.h"
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:
diff changeset
8
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:
diff changeset
9 #include <cassert>
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:
diff changeset
10
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:
diff changeset
11 #include "gen/logger.h"
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:
diff changeset
12 #include "gen/irstate.h"
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:
diff changeset
13 #include "gen/llvmhelpers.h"
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
14 #include "gen/tollvm.h"
1152
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
15 #include "gen/dvalue.h"
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:
diff changeset
16
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:
diff changeset
17 //////////////////////////////////////////////////////////////////////////////////////////
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:
diff changeset
18
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:
diff changeset
19 void Statement::toNakedIR(IRState *p)
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:
diff changeset
20 {
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:
diff changeset
21 error("not allowed in naked function");
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:
diff changeset
22 }
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:
diff changeset
23
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:
diff changeset
24 //////////////////////////////////////////////////////////////////////////////////////////
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:
diff changeset
25
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:
diff changeset
26 void CompoundStatement::toNakedIR(IRState *p)
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:
diff changeset
27 {
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:
diff changeset
28 Logger::println("CompoundStatement::toNakedIR(): %s", loc.toChars());
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:
diff changeset
29 LOG_SCOPE;
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:
diff changeset
30
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:
diff changeset
31 if (statements)
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:
diff changeset
32 for (unsigned i = 0; i < statements->dim; i++)
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:
diff changeset
33 {
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:
diff changeset
34 Statement* s = (Statement*)statements->data[i];
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:
diff changeset
35 if (s) s->toNakedIR(p);
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:
diff changeset
36 }
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:
diff changeset
37 }
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:
diff changeset
38
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:
diff changeset
39 //////////////////////////////////////////////////////////////////////////////////////////
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:
diff changeset
40
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:
diff changeset
41 void ExpStatement::toNakedIR(IRState *p)
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:
diff changeset
42 {
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:
diff changeset
43 Logger::println("ExpStatement::toNakedIR(): %s", loc.toChars());
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:
diff changeset
44 LOG_SCOPE;
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:
diff changeset
45
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:
diff changeset
46 // only expstmt supported in declarations
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:
diff changeset
47 if (exp->op != TOKdeclaration)
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:
diff changeset
48 {
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:
diff changeset
49 Statement::toNakedIR(p);
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:
diff changeset
50 return;
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:
diff changeset
51 }
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:
diff changeset
52
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:
diff changeset
53 DeclarationExp* d = (DeclarationExp*)exp;
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:
diff changeset
54 VarDeclaration* vd = d->declaration->isVarDeclaration();
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:
diff changeset
55 FuncDeclaration* fd = d->declaration->isFuncDeclaration();
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:
diff changeset
56 EnumDeclaration* ed = d->declaration->isEnumDeclaration();
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:
diff changeset
57
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:
diff changeset
58 // and only static variable/function declaration
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:
diff changeset
59 // no locals or nested stuffies!
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:
diff changeset
60 if (!vd && !fd && !ed)
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:
diff changeset
61 {
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:
diff changeset
62 Statement::toNakedIR(p);
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:
diff changeset
63 return;
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:
diff changeset
64 }
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:
diff changeset
65 else if (vd && !vd->isDataseg())
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:
diff changeset
66 {
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:
diff changeset
67 error("non-static variable '%s' not allowed in naked function", vd->toChars());
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:
diff changeset
68 return;
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:
diff changeset
69 }
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:
diff changeset
70 else if (fd && !fd->isStatic())
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:
diff changeset
71 {
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:
diff changeset
72 error("non-static nested function '%s' not allowed in naked function", fd->toChars());
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:
diff changeset
73 return;
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:
diff changeset
74 }
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:
diff changeset
75 // enum decls should always be safe
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:
diff changeset
76
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:
diff changeset
77 // make sure the symbols gets processed
1147
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1047
diff changeset
78 d->declaration->codegen(Type::sir);
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:
diff changeset
79 }
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:
diff changeset
80
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:
diff changeset
81 //////////////////////////////////////////////////////////////////////////////////////////
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:
diff changeset
82
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:
diff changeset
83 void LabelStatement::toNakedIR(IRState *p)
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:
diff changeset
84 {
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:
diff changeset
85 Logger::println("LabelStatement::toNakedIR(): %s", loc.toChars());
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:
diff changeset
86 LOG_SCOPE;
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:
diff changeset
87
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:
diff changeset
88 p->nakedAsm << p->func()->decl->mangle() << "_" << ident->toChars() << ":";
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:
diff changeset
89
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:
diff changeset
90 if (statement)
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:
diff changeset
91 statement->toNakedIR(p);
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:
diff changeset
92 }
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:
diff changeset
93
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:
diff changeset
94 //////////////////////////////////////////////////////////////////////////////////////////
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:
diff changeset
95
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:
diff changeset
96 void DtoDefineNakedFunction(FuncDeclaration* fd)
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:
diff changeset
97 {
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:
diff changeset
98 Logger::println("DtoDefineNakedFunction(%s)", fd->mangle());
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:
diff changeset
99 LOG_SCOPE;
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:
diff changeset
100
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:
diff changeset
101 assert(fd->ir.irFunc);
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:
diff changeset
102 gIR->functions.push_back(fd->ir.irFunc);
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:
diff changeset
103
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:
diff changeset
104 // we need to do special processing on the body, since we only want
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:
diff changeset
105 // to allow actual inline asm blocks to reach the final asm output
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:
diff changeset
106
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:
diff changeset
107 std::ostringstream& asmstr = gIR->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:
diff changeset
108
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:
diff changeset
109 // build function header
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:
diff changeset
110
923
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
111 // FIXME: could we perhaps use llvm asmwriter to give us these details ?
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:
diff changeset
112
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:
diff changeset
113 const char* mangle = fd->mangle();
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:
diff changeset
114 std::ostringstream tmpstr;
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:
diff changeset
115
923
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
116 // osx is different
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
117 // also mangling has an extra underscore prefixed
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
118 if (global.params.os == OSMacOSX)
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:
diff changeset
119 {
923
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
120 std::string section = "text";
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
121 bool weak = false;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
122 if (DtoIsTemplateInstance(fd))
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
123 {
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
124 tmpstr << "section\t__TEXT,__textcoal_nt,coalesced,pure_instructions";
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
125 section = tmpstr.str();
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
126 weak = true;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
127 }
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
128 asmstr << "\t." << section << std::endl;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
129 asmstr << "\t.align\t4,0x90" << std::endl;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
130 asmstr << "\t.globl\t_" << mangle << std::endl;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
131 if (weak)
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
132 {
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
133 asmstr << "\t.weak_definition\t_" << mangle << std::endl;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
134 }
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
135 asmstr << "_" << mangle << ":" << std::endl;
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:
diff changeset
136 }
923
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
137 // this works on linux x86 32 and 64 bit
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
138 // assume it works everywhere else as well for now
1181
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
139 // this needed a slight modification for Win
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
140 else
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
141 {
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
142 const char* linkage = "globl";
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
143 std::string section = "text";
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
144 if (DtoIsTemplateInstance(fd))
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
145 {
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
146 linkage = "weak";
1190
ea7b8b6c96c0 Some more fixups for mingw -- missing underscores
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1182
diff changeset
147 tmpstr << "section\t.gnu.linkonce.t.";
ea7b8b6c96c0 Some more fixups for mingw -- missing underscores
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1182
diff changeset
148 if (global.params.os != OSWindows)
ea7b8b6c96c0 Some more fixups for mingw -- missing underscores
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1182
diff changeset
149 {
ea7b8b6c96c0 Some more fixups for mingw -- missing underscores
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1182
diff changeset
150 tmpstr << mangle << ",\"ax\",@progbits";
ea7b8b6c96c0 Some more fixups for mingw -- missing underscores
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1182
diff changeset
151 } else
ea7b8b6c96c0 Some more fixups for mingw -- missing underscores
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1182
diff changeset
152 {
ea7b8b6c96c0 Some more fixups for mingw -- missing underscores
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1182
diff changeset
153 tmpstr << "_" << mangle << ",\"ax\"";
ea7b8b6c96c0 Some more fixups for mingw -- missing underscores
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1182
diff changeset
154 }
1181
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
155 section = tmpstr.str();
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
156 }
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
157 asmstr << "\t." << section << std::endl;
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
158 asmstr << "\t.align\t16" << std::endl;
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
159
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
160 if (global.params.os == OSWindows)
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
161 {
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
162 std::string def = "def";
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
163 std::string endef = "endef";
1190
ea7b8b6c96c0 Some more fixups for mingw -- missing underscores
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1182
diff changeset
164 asmstr << "\t." << def << "\t_" << mangle << ";";
1181
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
165 // hard code these two numbers for now since gas ignores .scl and llvm
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
166 // is defaulting to .type 32 for everything I have seen
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
167 asmstr << "\t.scl 2; .type 32;\t" << "." << endef << std::endl;
1190
ea7b8b6c96c0 Some more fixups for mingw -- missing underscores
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1182
diff changeset
168 asmstr << "_";
1181
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
169 } else
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
170 {
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
171 asmstr << "\t." << linkage << "\t" << mangle << std::endl;
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
172 asmstr << "\t.type\t" << mangle << ",@function" << std::endl;
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
173 }
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
174
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
175 asmstr << mangle << ":" << std::endl;
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
176
204197eb9eb5 Fix up some naked asm output for mingw32
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1154
diff changeset
177 }
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:
diff changeset
178
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:
diff changeset
179 // emit body
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:
diff changeset
180 fd->fbody->toNakedIR(gIR);
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:
diff changeset
181
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:
diff changeset
182 // emit size after body
1182
5e8f7ad442ba Fix one more naked asm output problem for mingw32 and remove some
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1181
diff changeset
183 // llvm does this on linux, but not on osx or Win
5e8f7ad442ba Fix one more naked asm output problem for mingw32 and remove some
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1181
diff changeset
184 if (global.params.os != OSMacOSX && global.params.os != OSWindows)
923
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
185 {
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
186 asmstr << "\t.size\t" << mangle << ", .-" << mangle << std::endl << std::endl;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
187 }
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:
diff changeset
188
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:
diff changeset
189 gIR->module->appendModuleInlineAsm(asmstr.str());
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:
diff changeset
190 asmstr.str("");
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:
diff changeset
191
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:
diff changeset
192 gIR->functions.pop_back();
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:
diff changeset
193 }
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
194
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
195 //////////////////////////////////////////////////////////////////////////////////////////
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
196
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
197 void emitABIReturnAsmStmt(IRAsmBlock* asmblock, Loc loc, FuncDeclaration* fdecl)
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
198 {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
199 Logger::println("emitABIReturnAsmStmt(%s)", fdecl->mangle());
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
200 LOG_SCOPE;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
201
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
202 IRAsmStmt* as = new IRAsmStmt;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
203
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
204 const LLType* llretTy = DtoType(fdecl->type->nextOf());
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
205 asmblock->retty = llretTy;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
206 asmblock->retn = 1;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
207
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1020
diff changeset
208 // FIXME: This should probably be handled by the TargetABI somehow.
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1020
diff changeset
209 // It should be able to do this for a greater variety of types.
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1020
diff changeset
210
959
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
211 // x86
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
212 if (global.params.cpu == ARCHx86)
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
213 {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
214 LINK l = fdecl->linkage;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
215 assert((l == LINKd || l == LINKc || l == LINKwindows) && "invalid linkage for asm implicit return");
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
216
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
217 Type* rt = fdecl->type->nextOf()->toBasetype();
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
218 if (rt->isintegral() || rt->ty == Tpointer || rt->ty == Tclass || rt->ty == Taarray)
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
219 {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
220 if (rt->size() == 8) {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
221 as->out_c = "=A,";
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
222 } else {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
223 as->out_c = "={ax},";
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
224 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
225 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
226 else if (rt->isfloating())
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
227 {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
228 if (rt->iscomplex()) {
1018
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1002
diff changeset
229 if (fdecl->linkage == LINKd) {
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1002
diff changeset
230 // extern(D) always returns on the FPU stack
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1002
diff changeset
231 as->out_c = "={st},={st(1)},";
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1002
diff changeset
232 asmblock->retn = 2;
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1002
diff changeset
233 } else if (rt->ty == Tcomplex32) {
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1002
diff changeset
234 // extern(C) cfloat is return as i64
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1002
diff changeset
235 as->out_c = "=A,";
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1350
diff changeset
236 asmblock->retty = LLType::getInt64Ty(gIR->context());
1018
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1002
diff changeset
237 } else {
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1002
diff changeset
238 // cdouble and creal extern(C) are returned in pointer
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1002
diff changeset
239 // don't add anything!
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1350
diff changeset
240 asmblock->retty = LLType::getVoidTy(gIR->context());
1020
474d7dd54d43 Remember to set asm type back to void and n=0 when rewriting to sret asm return.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
241 asmblock->retn = 0;
1018
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1002
diff changeset
242 return;
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1002
diff changeset
243 }
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
244 } else {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
245 as->out_c = "={st},";
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
246 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
247 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
248 else if (rt->ty == Tarray || rt->ty == Tdelegate)
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
249 {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
250 as->out_c = "={ax},={dx},";
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
251 asmblock->retn = 2;
954
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
252 #if 0
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
253 // this is to show how to allocate a temporary for the return value
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
254 // in case the appropriate multi register constraint isn't supported.
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
255 // this way abi return from inline asm can still be emulated.
988
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 959
diff changeset
256 // note that "$<<out0>>" etc in the asm will translate to the correct
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 959
diff changeset
257 // numbered output when the asm block in finalized
954
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
258
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
259 // generate asm
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
260 as->out_c = "=*m,=*m,";
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1190
diff changeset
261 LLValue* tmp = DtoRawAlloca(llretTy, 0, ".tmp_asm_ret");
954
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
262 as->out.push_back( tmp );
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
263 as->out.push_back( DtoGEPi(tmp, 0,1) );
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
264 as->code = "movd %eax, $<<out0>>" "\n\t" "mov %edx, $<<out1>>";
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
265
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
266 // fix asmblock
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
267 asmblock->retn = 0;
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
268 asmblock->retemu = true;
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
269 asmblock->asmBlock->abiret = tmp;
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
270
988
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 959
diff changeset
271 // add "ret" stmt at the end of the block
954
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
272 asmblock->s.push_back(as);
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
273
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
274 // done, we don't want anything pushed in the front of the block
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
275 return;
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
276 #endif
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
277 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
278 else
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
279 {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
280 error(loc, "unimplemented return type '%s' for implicit abi return", rt->toChars());
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
281 fatal();
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
282 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
283 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
284
959
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
285 // x86_64
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
286 else if (global.params.cpu == ARCHx86_64)
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
287 {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
288 LINK l = fdecl->linkage;
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
289 /* TODO: Check if this works with extern(Windows), completely untested.
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
290 * In particular, returning cdouble may not work with
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
291 * extern(Windows) since according to X86CallingConv.td it
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
292 * doesn't allow XMM1 to be used.
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
293 * (So is extern(C), but that should be fine as the calling convention
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
294 * is identical to that of extern(D))
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
295 */
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
296 assert((l == LINKd || l == LINKc || l == LINKwindows) && "invalid linkage for asm implicit return");
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
297
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
298 Type* rt = fdecl->type->nextOf()->toBasetype();
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
299 if (rt->isintegral() || rt->ty == Tpointer || rt->ty == Tclass || rt->ty == Taarray)
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
300 {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
301 as->out_c = "={ax},";
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
302 }
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
303 else if (rt->isfloating())
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
304 {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
305 if (rt == Type::tcomplex80) {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
306 // On x87 stack, re=st, im=st(1)
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
307 as->out_c = "={st},={st(1)},";
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
308 asmblock->retn = 2;
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
309 } else if (rt == Type::tfloat80 || rt == Type::timaginary80) {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
310 // On x87 stack
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
311 as->out_c = "={st},";
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
312 } else if (l != LINKd && rt == Type::tcomplex32) {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
313 // LLVM and GCC disagree on how to return {float, float}.
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
314 // For compatibility, use the GCC/LLVM-GCC way for extern(C/Windows)
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
315 // extern(C) cfloat -> %xmm0 (extract two floats)
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
316 as->out_c = "={xmm0},";
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1350
diff changeset
317 asmblock->retty = LLType::getDoubleTy(gIR->context());
959
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
318 } else if (rt->iscomplex()) {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
319 // cdouble and extern(D) cfloat -> re=%xmm0, im=%xmm1
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
320 as->out_c = "={xmm0},={xmm1},";
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
321 asmblock->retn = 2;
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
322 } else {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
323 // Plain float/double/ifloat/idouble
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
324 as->out_c = "={xmm0},";
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
325 }
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
326 }
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
327 else if (rt->ty == Tarray || rt->ty == Tdelegate)
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
328 {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
329 as->out_c = "={ax},={dx},";
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
330 asmblock->retn = 2;
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
331 }
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
332 else
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
333 {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
334 error(loc, "unimplemented return type '%s' for implicit abi return", rt->toChars());
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
335 fatal();
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
336 }
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
337 }
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
338
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
339 // unsupported
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
340 else
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
341 {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
342 error(loc, "this target (%s) does not implement inline asm falling off the end of the function", global.params.targetTriple);
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
343 fatal();
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
344 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
345
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
346 // return values always go in the front
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
347 asmblock->s.push_front(as);
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
348 }
1152
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
349
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
350 //////////////////////////////////////////////////////////////////////////////////////////
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
351
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
352 // sort of kinda related to naked ...
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
353
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
354 DValue * DtoInlineAsmExpr(Loc loc, FuncDeclaration * fd, Expressions * arguments)
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
355 {
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
356 Logger::println("DtoInlineAsmExpr @ %s", loc.toChars());
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
357 LOG_SCOPE;
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
358
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
359 TemplateInstance* ti = fd->toParent()->isTemplateInstance();
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
360 assert(ti && "invalid inline __asm expr");
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
361
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
362 assert(arguments->dim >= 2 && "invalid __asm call");
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
363
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
364 // get code param
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
365 Expression* e = (Expression*)arguments->data[0];
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
366 Logger::println("code exp: %s", e->toChars());
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
367 StringExp* se = (StringExp*)e;
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
368 if (e->op != TOKstring || se->sz != 1)
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
369 {
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
370 e->error("__asm code argument is not a char[] string literal");
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
371 fatal();
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
372 }
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
373 std::string code((char*)se->string, se->len);
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
374
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
375 // get constraints param
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
376 e = (Expression*)arguments->data[1];
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
377 Logger::println("constraint exp: %s", e->toChars());
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
378 se = (StringExp*)e;
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
379 if (e->op != TOKstring || se->sz != 1)
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
380 {
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
381 e->error("__asm constraints argument is not a char[] string literal");
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
382 fatal();
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
383 }
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
384 std::string constraints((char*)se->string, se->len);
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
385
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
386 // build runtime arguments
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
387 size_t n = arguments->dim;
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
388
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
389 LLSmallVector<llvm::Value*, 8> args;
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
390 args.reserve(n-2);
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
391 std::vector<const llvm::Type*> argtypes;
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
392 argtypes.reserve(n-2);
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
393
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
394 for (size_t i = 2; i < n; i++)
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
395 {
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
396 e = (Expression*)arguments->data[i];
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
397 args.push_back(e->toElem(gIR)->getRVal());
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
398 argtypes.push_back(args.back()->getType());
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
399 }
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
400
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
401 // build asm function type
1154
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
402 Type* type = fd->type->nextOf()->toBasetype();
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
403 const llvm::Type* ret_type = DtoType(type);
1153
4454126b4345 Added support for single D type register return from __asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1152
diff changeset
404 llvm::FunctionType* FT = llvm::FunctionType::get(ret_type, argtypes, false);
1152
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
405
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
406 // build asm call
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
407 bool sideeffect = true;
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
408 llvm::InlineAsm* ia = llvm::InlineAsm::get(FT, code, constraints, sideeffect);
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
409
1154
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
410 llvm::Value* rv = gIR->ir->CreateCall(ia, args.begin(), args.end(), "");
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
411
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
412 // work around missing tuple support for users of the return value
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
413 if (type->ty == Tstruct)
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
414 {
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
415 // make a copy
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1190
diff changeset
416 llvm::Value* mem = DtoAlloca(type, ".__asm_tuple_ret");
1154
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
417
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
418 TypeStruct* ts = (TypeStruct*)type;
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
419 size_t n = ts->sym->fields.dim;
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
420 for (size_t i = 0; i < n; i++)
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
421 {
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
422 llvm::Value* v = gIR->ir->CreateExtractValue(rv, i, "");
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
423 llvm::Value* gep = DtoGEPi(mem, 0, i);
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
424 DtoStore(v, gep);
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
425 }
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
426
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
427 return new DVarValue(fd->type->nextOf(), mem);
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
428 }
1152
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
429
1153
4454126b4345 Added support for single D type register return from __asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1152
diff changeset
430 // return call as im value
1154
9279a9dc6df3 Added support for tuple return with __asmtuple!(int,int) etc.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1153
diff changeset
431 return new DImValue(fd->type->nextOf(), rv);
1152
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
432 }
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
433
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
434
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
435
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
436
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
437
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
438
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
439
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
440
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
441
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
442
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
443