# HG changeset patch # User Kelly Wilson # Date 1243580978 21600 # Node ID 3c880e2d80e75253e38fac3604cda7d9fa02e55c # Parent 9081d916df1d2d9918d01e00e8ec647b80d15cbc# Parent c6cc9cf12becbe48e75842a4be583bf787f059f6 merging diff -r 9081d916df1d -r 3c880e2d80e7 gen/complex.cpp --- a/gen/complex.cpp Fri May 29 01:08:39 2009 -0600 +++ b/gen/complex.cpp Fri May 29 01:09:38 2009 -0600 @@ -410,7 +410,7 @@ DValue* DtoCastComplex(Loc& loc, DValue* val, Type* _to) { Type* to = _to->toBasetype(); - Type* vty = val->getType(); + Type* vty = val->getType()->toBasetype(); if (to->iscomplex()) { if (vty->size() == to->size()) return val; @@ -438,17 +438,25 @@ DImValue* im = new DImValue(to, impart); return DtoCastFloat(loc, im, to); } - else if (to->isfloating()) { + else if (to->ty == Tbool) { + return new DImValue(_to, DtoComplexEquals(loc, TOKnotequal, val, DtoNullValue(vty))); + } + else if (to->isfloating() || to->isintegral()) { // FIXME: this loads both values, even when we only need one LLValue* v = val->getRVal(); LLValue* repart = gIR->ir->CreateExtractValue(v, 0, ".re_part"); - DImValue* re = new DImValue(to, repart); + Type *extractty; + if (vty->ty == Tcomplex32) { + extractty = Type::tfloat32; + } else if (vty->ty == Tcomplex64) { + extractty = Type::tfloat64; + } else if (vty->ty == Tcomplex80) { + extractty = Type::tfloat80; + } + DImValue* re = new DImValue(extractty, repart); return DtoCastFloat(loc, re, to); } - else if (to->ty == Tbool) { - return new DImValue(_to, DtoComplexEquals(loc, TOKnotequal, val, DtoNullValue(vty))); - } else - assert(0); + error(loc, "Don't know how to cast %s to %s", vty->toChars(), to->toChars()); } diff -r 9081d916df1d -r 3c880e2d80e7 gen/optimizer.cpp --- a/gen/optimizer.cpp Fri May 29 01:08:39 2009 -0600 +++ b/gen/optimizer.cpp Fri May 29 01:09:38 2009 -0600 @@ -119,6 +119,7 @@ addPass(pm, createInstructionCombiningPass()); addPass(pm, createCFGSimplificationPass()); addPass(pm, createPruneEHPass()); + addPass(pm, createFunctionAttrsPass()); #ifdef USE_METADATA if (!disableLangSpecificPasses && !disableGCToStack) diff -r 9081d916df1d -r 3c880e2d80e7 gen/passes/GarbageCollect2Stack.cpp --- a/gen/passes/GarbageCollect2Stack.cpp Fri May 29 01:08:39 2009 -0600 +++ b/gen/passes/GarbageCollect2Stack.cpp Fri May 29 01:09:38 2009 -0600 @@ -30,6 +30,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/IRBuilder.h" #include "llvm/Analysis/CaptureTracking.h" +#include "llvm/Analysis/CallGraph.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Target/TargetData.h" @@ -43,24 +44,40 @@ STATISTIC(NumToDynSize, "Number of calls promoted to dynamically-sized allocas"); STATISTIC(NumDeleted, "Number of GC calls deleted because the return value was unused"); + +namespace { + struct Analysis { + TargetData& TD; + const Module& M; + CallGraph* CG; + CallGraphNode* CGNode; + + const Type* getTypeFor(Value* typeinfo) const; + }; +} + //===----------------------------------------------------------------------===// // Helper functions //===----------------------------------------------------------------------===// -void EmitMemSet(IRBuilder<>& B, Value* Dst, Value* Val, Value* Len) { +void EmitMemSet(IRBuilder<>& B, Value* Dst, Value* Val, Value* Len, + const Analysis& A) { Dst = B.CreateBitCast(Dst, PointerType::getUnqual(Type::Int8Ty)); Module *M = B.GetInsertBlock()->getParent()->getParent(); const Type* Tys[1]; Tys[0] = Len->getType(); - Value *MemSet = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys, 1); + Function *MemSet = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys, 1); Value *Align = ConstantInt::get(Type::Int32Ty, 1); - B.CreateCall4(MemSet, Dst, Val, Len, Align); + CallSite CS = B.CreateCall4(MemSet, Dst, Val, Len, Align); + if (A.CGNode) + A.CGNode->addCalledFunction(CS, A.CG->getOrInsertFunction(MemSet)); } -static void EmitMemZero(IRBuilder<>& B, Value* Dst, Value* Len) { - EmitMemSet(B, Dst, ConstantInt::get(Type::Int8Ty, 0), Len); +static void EmitMemZero(IRBuilder<>& B, Value* Dst, Value* Len, + const Analysis& A) { + EmitMemSet(B, Dst, ConstantInt::get(Type::Int8Ty, 0), Len, A); } @@ -69,13 +86,6 @@ //===----------------------------------------------------------------------===// namespace { - struct Analysis { - TargetData& TD; - const Module& M; - - const Type* getTypeFor(Value* typeinfo) const; - }; - class FunctionInfo { protected: const Type* Ty; @@ -174,7 +184,7 @@ // Use the original B to put initialization at the // allocation site. Value* Size = B.CreateMul(TypeSize, arrSize); - EmitMemZero(B, alloca, Size); + EmitMemZero(B, alloca, Size, A); } return alloca; @@ -259,6 +269,7 @@ virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); AU.addRequired(); + AU.addPreserved(); } }; char GarbageCollect2Stack::ID = 0; @@ -284,8 +295,9 @@ KnownFunctions["_d_allocclass"] = &AllocClass; } -static void RemoveCall(Instruction* Inst) { - if (InvokeInst* Invoke = dyn_cast(Inst)) { +static void RemoveCall(CallSite CS, const Analysis& A) { + if (CS.isInvoke()) { + InvokeInst* Invoke = cast(CS.getInstruction()); // If this was an invoke instruction, we need to do some extra // work to preserve the control flow. @@ -296,7 +308,9 @@ BranchInst::Create(Invoke->getNormalDest(), Invoke->getParent()); } // Remove the runtime call. - Inst->eraseFromParent(); + if (A.CGNode) + A.CGNode->removeCallEdgeFor(CS); + CS.getInstruction()->eraseFromParent(); } /// runOnFunction - Top level algorithm. @@ -306,8 +320,10 @@ TargetData &TD = getAnalysis(); const LoopInfo &LI = getAnalysis(); + CallGraph* CG = getAnalysisIfAvailable(); + CallGraphNode* CGNode = CG ? (*CG)[&F] : NULL; - Analysis A = { TD, *M }; + Analysis A = { TD, *M, CG, CGNode }; BasicBlock& Entry = F.getEntryBlock(); @@ -351,7 +367,7 @@ if (Inst->use_empty() && info->SafeToDelete) { Changed = true; NumDeleted++; - RemoveCall(Inst); + RemoveCall(CS, A); continue; } @@ -374,7 +390,7 @@ newVal = Builder.CreateBitCast(newVal, Inst->getType()); Inst->replaceAllUsesWith(newVal); - RemoveCall(Inst); + RemoveCall(CS, A); } } diff -r 9081d916df1d -r 3c880e2d80e7 gen/tocall.cpp --- a/gen/tocall.cpp Fri May 29 01:08:39 2009 -0600 +++ b/gen/tocall.cpp Fri May 29 01:09:38 2009 -0600 @@ -416,7 +416,7 @@ } Logger::undent(); Logger::cout() << "Function type: " << tf->toChars() << '\n'; - Logger::cout() << "LLVM functype: " << *callable->getType() << '\n'; + //Logger::cout() << "LLVM functype: " << *callable->getType() << '\n'; } size_t n = Argument::dim(tf->parameters); diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/norun_debug1.d --- a/tests/mini/norun_debug1.d Fri May 29 01:08:39 2009 -0600 +++ b/tests/mini/norun_debug1.d Fri May 29 01:09:38 2009 -0600 @@ -2,7 +2,7 @@ void main() { - int* ptr; + int* ptr = cast(int*) 1; // all these should be inspectable int i = 1; diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/norun_debug10.d --- a/tests/mini/norun_debug10.d Fri May 29 01:08:39 2009 -0600 +++ b/tests/mini/norun_debug10.d Fri May 29 01:09:38 2009 -0600 @@ -16,6 +16,6 @@ void func(Vec2 v2, ref Vec2 rv2, char[] str, out int i, ref float f) { - int* fail; + int* fail = cast(int*) 1; *fail = 0; } diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/norun_debug12.d --- a/tests/mini/norun_debug12.d Fri May 29 01:08:39 2009 -0600 +++ b/tests/mini/norun_debug12.d Fri May 29 01:09:38 2009 -0600 @@ -19,6 +19,6 @@ scope c = new C; I i = c; - int* fail; + int* fail = cast(int*) 1; *fail = 0; } diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/norun_debug2.d --- a/tests/mini/norun_debug2.d Fri May 29 01:08:39 2009 -0600 +++ b/tests/mini/norun_debug2.d Fri May 29 01:09:38 2009 -0600 @@ -8,7 +8,7 @@ while (iter < 25) { if (rand() % 20 == 10) - *cast(int*)null = 0; + *cast(int*)1 = 0; ++iter; } assert(0); diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/norun_debug3.d --- a/tests/mini/norun_debug3.d Fri May 29 01:08:39 2009 -0600 +++ b/tests/mini/norun_debug3.d Fri May 29 01:09:38 2009 -0600 @@ -5,6 +5,6 @@ int i = 42; int* ip = &i; - int* fail; + int* fail = cast(int*) 1; *fail = 0; } diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/norun_debug4.d --- a/tests/mini/norun_debug4.d Fri May 29 01:08:39 2009 -0600 +++ b/tests/mini/norun_debug4.d Fri May 29 01:09:38 2009 -0600 @@ -6,6 +6,6 @@ wchar wc = 'w'; dchar dc = 'd'; - int* fail; + int* fail = cast(int*) 1; *fail = 32; } diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/norun_debug5.d --- a/tests/mini/norun_debug5.d Fri May 29 01:08:39 2009 -0600 +++ b/tests/mini/norun_debug5.d Fri May 29 01:09:38 2009 -0600 @@ -10,6 +10,6 @@ void func(int i, real r, real* p) { - int* fail; + int* fail = cast(int*) 1; *fail = 666; } diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/norun_debug6.d --- a/tests/mini/norun_debug6.d Fri May 29 01:08:39 2009 -0600 +++ b/tests/mini/norun_debug6.d Fri May 29 01:09:38 2009 -0600 @@ -4,6 +4,6 @@ { char[] str = "hello world :)"; - int* fail; + int* fail = cast(int*) 1; *fail = 32; } diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/norun_debug7.d --- a/tests/mini/norun_debug7.d Fri May 29 01:08:39 2009 -0600 +++ b/tests/mini/norun_debug7.d Fri May 29 01:09:38 2009 -0600 @@ -4,6 +4,6 @@ void main() { - int* fail; + int* fail = cast(int*) 1; *fail = 0; } diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/norun_debug8.d --- a/tests/mini/norun_debug8.d Fri May 29 01:08:39 2009 -0600 +++ b/tests/mini/norun_debug8.d Fri May 29 01:09:38 2009 -0600 @@ -26,6 +26,6 @@ foo.bar.y = 3.1415; foo.bar.foo = &foo; - int* fail; + int* fail = cast(int*) 1; *fail = 0; } diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/norun_debug9.d --- a/tests/mini/norun_debug9.d Fri May 29 01:08:39 2009 -0600 +++ b/tests/mini/norun_debug9.d Fri May 29 01:09:38 2009 -0600 @@ -6,7 +6,7 @@ void func() { - int* fail; + int* fail = cast(int*) 1; *fail = 0; } } diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/phobos/bug57.d --- a/tests/mini/phobos/bug57.d Fri May 29 01:08:39 2009 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -import std.stdio; -class Foo {} -void func3() -{ - Foo[1] test=[new Foo]; - writefln(test); -} -void main() { - func3(); -} diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/phobos/bug58.d --- a/tests/mini/phobos/bug58.d Fri May 29 01:08:39 2009 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -module bug58; -import std.stdio; -void main() -{ - int[16] arr = [1,16,2,15,3,14,4,13,5,12,6,11,7,10,8,9]; - writefln("arr = ",arr); - arr.sort; - writefln("arr.sort = ",arr); - assert(arr == [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); -} diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/phobos/bug66.d --- a/tests/mini/phobos/bug66.d Fri May 29 01:08:39 2009 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -module bug66; -import std.stdio; -class Scene { string name() { return "Scene"; } } -class Group : Scene { this () { } } -void main() { writefln((new Group).name); } diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/phobos/bug71.d --- a/tests/mini/phobos/bug71.d Fri May 29 01:08:39 2009 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -module bug71; - -void main() -{ - static TypeInfo skipCI(TypeInfo valti) - { - while (1) - { - if (valti.classinfo.name.length == 18 && - valti.classinfo.name[9..18] == "Invariant") - valti = (cast(TypeInfo_Invariant)valti).next; - else if (valti.classinfo.name.length == 14 && - valti.classinfo.name[9..14] == "Const") - valti = (cast(TypeInfo_Const)valti).next; - else - break; - } - return valti; - } -} \ No newline at end of file diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/phobos/bug79.d --- a/tests/mini/phobos/bug79.d Fri May 29 01:08:39 2009 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -module bug79; -import std.c.linux.linux; -void main() -{ - timespec ts; - ts.tv_nsec -= 1; - //auto t = ts.tv_nsec - 1; - //t -= 1; -} diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/phobos/imports2.d --- a/tests/mini/phobos/imports2.d Fri May 29 01:08:39 2009 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -module imports2; -import std.stdio; - -void main() { - writefln("Hello world!"[]); -} diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/phobos/stdiotest.d --- a/tests/mini/phobos/stdiotest.d Fri May 29 01:08:39 2009 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -module stdiotest; - -import std.stdio; - -T typed(T)(T x) -{ - return x; -} - -void main() -{ - /*char[] str = "hello"; - writefln(str); - - writefln("hello world");*/ - - char[] fmt = "%s"; - writefln(2.0f); - - /*{writefln(typed!(byte)(1));} - {writefln(typed!(short)(2));} - {writefln(typed!(int)(3));} - {writefln(typed!(long)(-4));} - {writefln(typed!(ulong)(5));} - {writefln("%f", typed!(float)(6));} - {writefln("%f", typed!(double)(7));} - {writefln("%f", typed!(real)(8));}*/ -} diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/phobos/stdiotest2.d --- a/tests/mini/phobos/stdiotest2.d Fri May 29 01:08:39 2009 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -module stdiotest2; -import std.stdio; -void main() -{ - int[4] v = [1,2,3,4]; - { - writefln("%s", v); - { - int[] dv = v; - {writefln("%s", dv);} - } - } - - { - writefln(v); - { - //int[] dv = v; - //{writefln(dv);} - } - } - //writefln(1,2,3,4.56,"hello",v); -} diff -r 9081d916df1d -r 3c880e2d80e7 tests/mini/phobos/strings2.d --- a/tests/mini/phobos/strings2.d Fri May 29 01:08:39 2009 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -module strings2; - -import std.string; -import std.stdio; - -void main() -{ - int i = 32; - auto str = format(i); - writefln(str); - - long l = 123123; - str = format(l); - writefln(str); -}