From baldrick at free.fr Mon Feb 16 04:27:40 2009 From: baldrick at free.fr (Duncan Sands) Date: Mon, 16 Feb 2009 11:27:40 +0100 Subject: [llvm-commits] make utils/GenLibDeps.pl ignore 'D' lines from nm In-Reply-To: <4998A27E.1090905@mxc.ca> References: <4997D42C.9060900@mxc.ca> <200902151004.12829.baldrick@free.fr> <4998A27E.1090905@mxc.ca> Message-ID: <200902161127.41418.baldrick@free.fr> Hi Nick, > > How about just ignoring __dso_handle? This might be enough to work > > around the gold bug. I don't much like the idea of ignoring all 'D' > > symbols (externally visible globals with initial value). > > That works for me. I've attached the patch, let me know if it works for > you and I'll commit it! thanks for doing this. On my system I also have to ignore '__stack_chk_fail_local'. Revised patch attached. Ciao, Duncan. -------------- next part -------------- A non-text attachment was scrubbed... Name: gold.diff Type: text/x-patch Size: 1311 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090216/977a0842/attachment.bin From dpatel at apple.com Mon Feb 16 13:18:01 2009 From: dpatel at apple.com (Devang Patel) Date: Mon, 16 Feb 2009 19:18:01 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64648 - /llvm-gcc-4.2/trunk/gcc/cp/name-lookup.c Message-ID: <200902161918.n1GJI1Kw013607@zion.cs.uiuc.edu> Author: dpatel Date: Mon Feb 16 13:18:00 2009 New Revision: 64648 URL: http://llvm.org/viewvc/llvm-project?rev=64648&view=rev Log: A patch was added in gcc-4.2 to copy TYPE_DECL as the new type's typedef name if the type is anonymous. This patch is not required in llvm-gcc. The difference is due to the way gcc and llvm-gcc walks gcc trees to emit debug info. Modified: llvm-gcc-4.2/trunk/gcc/cp/name-lookup.c Modified: llvm-gcc-4.2/trunk/gcc/cp/name-lookup.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/cp/name-lookup.c?rev=64648&r1=64647&r2=64648&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/cp/name-lookup.c (original) +++ llvm-gcc-4.2/trunk/gcc/cp/name-lookup.c Mon Feb 16 13:18:00 2009 @@ -817,7 +817,12 @@ /* Make sure to do the copying if the type was anonymous */ else if (type != error_mark_node && ((TYPE_NAME (type) != x) +#ifdef ENABLE_LLVM + /* llvm-gcc does not need a copy if the type was anonymous. */ + ) +#else || (TYPE_LANG_SPECIFIC (type) && TYPE_WAS_ANONYMOUS (type))) +#endif /* APPLE LOCAL end radar 6007135, typedef of anonymous struct */ /* We don't want to copy the type when all we're doing is making a TYPE_DECL for the purposes of From dpatel at apple.com Mon Feb 16 13:24:30 2009 From: dpatel at apple.com (Devang Patel) Date: Mon, 16 Feb 2009 19:24:30 -0000 Subject: [llvm-commits] [llvm] r64649 - /llvm/trunk/test/FrontendC++/2009-02-16-AnonTypedef-Dbg.cpp Message-ID: <200902161924.n1GJOUAX013915@zion.cs.uiuc.edu> Author: dpatel Date: Mon Feb 16 13:24:29 2009 New Revision: 64649 URL: http://llvm.org/viewvc/llvm-project?rev=64649&view=rev Log: Test case for llvm-gcc rev. 64648. Added: llvm/trunk/test/FrontendC++/2009-02-16-AnonTypedef-Dbg.cpp Added: llvm/trunk/test/FrontendC++/2009-02-16-AnonTypedef-Dbg.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FrontendC%2B%2B/2009-02-16-AnonTypedef-Dbg.cpp?rev=64649&view=auto ============================================================================== --- llvm/trunk/test/FrontendC++/2009-02-16-AnonTypedef-Dbg.cpp (added) +++ llvm/trunk/test/FrontendC++/2009-02-16-AnonTypedef-Dbg.cpp Mon Feb 16 13:24:29 2009 @@ -0,0 +1,5 @@ +// Test on debug info to make sure that anon typedef info is emitted. +// RUN: %llvmgcc -S --emit-llvm -x c++ -g %s -o - | grep composite +typedef struct { int a; long b; } foo; +foo x; + From kremenek at apple.com Mon Feb 16 13:31:23 2009 From: kremenek at apple.com (Ted Kremenek) Date: Mon, 16 Feb 2009 19:31:23 -0000 Subject: [llvm-commits] [llvm] r64655 - /llvm/tags/checker/checker-0.157/ Message-ID: <200902161931.n1GJVNGW014342@zion.cs.uiuc.edu> Author: kremenek Date: Mon Feb 16 13:31:23 2009 New Revision: 64655 URL: http://llvm.org/viewvc/llvm-project?rev=64655&view=rev Log: Tagging checker-0.157. Added: llvm/tags/checker/checker-0.157/ - copied from r64654, llvm/trunk/ From isanbard at gmail.com Mon Feb 16 13:38:38 2009 From: isanbard at gmail.com (Bill Wendling) Date: Mon, 16 Feb 2009 19:38:38 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64659 - /llvm-gcc-4.2/branches/Apple/Dib/gcc/cp/name-lookup.c Message-ID: <200902161938.n1GJccSm014816@zion.cs.uiuc.edu> Author: void Date: Mon Feb 16 13:38:38 2009 New Revision: 64659 URL: http://llvm.org/viewvc/llvm-project?rev=64659&view=rev Log: --- Merging (from foreign repository) r64648 into '.': U gcc/cp/name-lookup.c A patch was added in gcc-4.2 to copy TYPE_DECL as the new type's typedef name if the type is anonymous. This patch is not required in llvm-gcc. The difference is due to the way gcc and llvm-gcc walks gcc trees to emit debug info. Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/cp/name-lookup.c Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/cp/name-lookup.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/cp/name-lookup.c?rev=64659&r1=64658&r2=64659&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/cp/name-lookup.c (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/cp/name-lookup.c Mon Feb 16 13:38:38 2009 @@ -817,7 +817,12 @@ /* Make sure to do the copying if the type was anonymous */ else if (type != error_mark_node && ((TYPE_NAME (type) != x) +#ifdef ENABLE_LLVM + /* llvm-gcc does not need a copy if the type was anonymous. */ + ) +#else || (TYPE_LANG_SPECIFIC (type) && TYPE_WAS_ANONYMOUS (type))) +#endif /* APPLE LOCAL end radar 6007135, typedef of anonymous struct */ /* We don't want to copy the type when all we're doing is making a TYPE_DECL for the purposes of From isanbard at gmail.com Mon Feb 16 13:41:47 2009 From: isanbard at gmail.com (Bill Wendling) Date: Mon, 16 Feb 2009 19:41:47 -0000 Subject: [llvm-commits] [llvm] r64661 - /llvm/branches/Apple/Dib/lib/CodeGen/VirtRegMap.cpp Message-ID: <200902161941.n1GJflQT015001@zion.cs.uiuc.edu> Author: void Date: Mon Feb 16 13:41:47 2009 New Revision: 64661 URL: http://llvm.org/viewvc/llvm-project?rev=64661&view=rev Log: Fix comment. Modified: llvm/branches/Apple/Dib/lib/CodeGen/VirtRegMap.cpp Modified: llvm/branches/Apple/Dib/lib/CodeGen/VirtRegMap.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/VirtRegMap.cpp?rev=64661&r1=64660&r2=64661&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/CodeGen/VirtRegMap.cpp (original) +++ llvm/branches/Apple/Dib/lib/CodeGen/VirtRegMap.cpp Mon Feb 16 13:41:47 2009 @@ -1278,7 +1278,7 @@ } /// rewriteMBB - Keep track of which spills are available even after the -/// register allocator is done with them. If possible, avid reloading vregs. +/// register allocator is done with them. If possible, avoid reloading vregs. void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM, AvailableSpills &Spills) { DOUT << "\n**** Local spiller rewriting MBB '" From isanbard at gmail.com Mon Feb 16 13:42:22 2009 From: isanbard at gmail.com (Bill Wendling) Date: Mon, 16 Feb 2009 19:42:22 -0000 Subject: [llvm-commits] [llvm] r64662 - /llvm/branches/Apple/Dib/test/FrontendC++/2009-02-16-AnonTypedef-Dbg.cpp Message-ID: <200902161942.n1GJgM44015085@zion.cs.uiuc.edu> Author: void Date: Mon Feb 16 13:42:22 2009 New Revision: 64662 URL: http://llvm.org/viewvc/llvm-project?rev=64662&view=rev Log: Merge r64649 into Dib: Test case for llvm-gcc rev. 64648. Added: llvm/branches/Apple/Dib/test/FrontendC++/2009-02-16-AnonTypedef-Dbg.cpp Added: llvm/branches/Apple/Dib/test/FrontendC++/2009-02-16-AnonTypedef-Dbg.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/FrontendC%2B%2B/2009-02-16-AnonTypedef-Dbg.cpp?rev=64662&view=auto ============================================================================== --- llvm/branches/Apple/Dib/test/FrontendC++/2009-02-16-AnonTypedef-Dbg.cpp (added) +++ llvm/branches/Apple/Dib/test/FrontendC++/2009-02-16-AnonTypedef-Dbg.cpp Mon Feb 16 13:42:22 2009 @@ -0,0 +1,5 @@ +// Test on debug info to make sure that anon typedef info is emitted. +// RUN: %llvmgcc -S --emit-llvm -x c++ -g %s -o - | grep composite +typedef struct { int a; long b; } foo; +foo x; + From kremenek at apple.com Mon Feb 16 16:39:08 2009 From: kremenek at apple.com (Ted Kremenek) Date: Mon, 16 Feb 2009 22:39:08 -0000 Subject: [llvm-commits] [llvm] r64687 - /llvm/trunk/include/llvm/ADT/APSInt.h Message-ID: <200902162239.n1GMd82N022052@zion.cs.uiuc.edu> Author: kremenek Date: Mon Feb 16 16:39:08 2009 New Revision: 64687 URL: http://llvm.org/viewvc/llvm-project?rev=64687&view=rev Log: Fix bug where APSInt::operator-- incremented instead of decremented. Modified: llvm/trunk/include/llvm/ADT/APSInt.h Modified: llvm/trunk/include/llvm/ADT/APSInt.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APSInt.h?rev=64687&r1=64686&r2=64687&view=diff ============================================================================== --- llvm/trunk/include/llvm/ADT/APSInt.h (original) +++ llvm/trunk/include/llvm/ADT/APSInt.h Mon Feb 16 16:39:08 2009 @@ -150,7 +150,7 @@ return *this; } APSInt& operator--() { - static_cast(*this)++; + static_cast(*this)--; return *this; } APSInt operator++(int) { From daniel at zuster.org Mon Feb 16 16:57:04 2009 From: daniel at zuster.org (Daniel Dunbar) Date: Mon, 16 Feb 2009 22:57:04 -0000 Subject: [llvm-commits] [llvm] r64691 - /llvm/trunk/include/llvm/Support/MathExtras.h Message-ID: <200902162257.n1GMv4QM022917@zion.cs.uiuc.edu> Author: ddunbar Date: Mon Feb 16 16:57:04 2009 New Revision: 64691 URL: http://llvm.org/viewvc/llvm-project?rev=64691&view=rev Log: Add llvm::RoundUpToAlignment. - No functionality change. Modified: llvm/trunk/include/llvm/Support/MathExtras.h Modified: llvm/trunk/include/llvm/Support/MathExtras.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MathExtras.h?rev=64691&r1=64690&r2=64691&view=diff ============================================================================== --- llvm/trunk/include/llvm/Support/MathExtras.h (original) +++ llvm/trunk/include/llvm/Support/MathExtras.h Mon Feb 16 16:57:04 2009 @@ -412,6 +412,18 @@ A |= (A >> 32); return A + 1; } + +/// RoundUpToAlignment - Returns the next integer (mod 2**64) that is +/// greater than or equal to \arg Value and is a multiple of \arg +/// Align. Align must be non-zero. +/// +/// Examples: +/// RoundUpToAlignment(5, 8) = 8 +/// RoundUpToAlignment(17, 8) = 24 +/// RoundUpToAlignment(~0LL, 8) = 0 +inline uint64_t RoundUpToAlignment(uint64_t Value, uint64_t Align) { + return ((Value + Align - 1) / Align) * Align; +} } // End llvm namespace From gohman at apple.com Mon Feb 16 17:02:21 2009 From: gohman at apple.com (Dan Gohman) Date: Mon, 16 Feb 2009 23:02:21 -0000 Subject: [llvm-commits] [llvm] r64693 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/enforce-known-alignment.ll Message-ID: <200902162302.n1GN2LK7023114@zion.cs.uiuc.edu> Author: djg Date: Mon Feb 16 17:02:21 2009 New Revision: 64693 URL: http://llvm.org/viewvc/llvm-project?rev=64693&view=rev Log: Fix EnforceKnownAlignment so that it doesn't ever reduce the alignment of an alloca or global variable. Added: llvm/trunk/test/Transforms/InstCombine/enforce-known-alignment.ll Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=64693&r1=64692&r2=64693&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Mon Feb 16 17:02:21 2009 @@ -9237,15 +9237,23 @@ // If there is a large requested alignment and we can, bump up the alignment // of the global. if (!GV->isDeclaration()) { - GV->setAlignment(PrefAlign); - Align = PrefAlign; + if (GV->getAlignment() >= PrefAlign) + Align = GV->getAlignment(); + else { + GV->setAlignment(PrefAlign); + Align = PrefAlign; + } } } else if (AllocationInst *AI = dyn_cast(V)) { // If there is a requested alignment and if this is an alloca, round up. We // don't do this for malloc, because some systems can't respect the request. if (isa(AI)) { - AI->setAlignment(PrefAlign); - Align = PrefAlign; + if (AI->getAlignment() >= PrefAlign) + Align = AI->getAlignment(); + else { + AI->setAlignment(PrefAlign); + Align = PrefAlign; + } } } Added: llvm/trunk/test/Transforms/InstCombine/enforce-known-alignment.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/enforce-known-alignment.ll?rev=64693&view=auto ============================================================================== --- llvm/trunk/test/Transforms/InstCombine/enforce-known-alignment.ll (added) +++ llvm/trunk/test/Transforms/InstCombine/enforce-known-alignment.ll Mon Feb 16 17:02:21 2009 @@ -0,0 +1,18 @@ +; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep alloca | grep {align 16} +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" +target triple = "i386-apple-darwin9.6" + +define void @foo(<{ { [4 x i32] }, i32, i32, i32, i8, i8, i8, i8, i8, [3 x i8], { i8, i8, i8, i8, [4 x i32], [4 x i32], [4 x i32], i8, i8, i8, i8, i8, i8 }*, <{ i8, i8, i8, i8, i8, i8, [2 x i8], i32, [4 x i8], <{ [16 x { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } }], i8, [15 x i8] }>, { i8, i8, [16 x i8], [4 x i8], [16 x i8], [4 x i8] }, [2 x i8], i32, i32, i32, i32, i32, i32, i32, i32, [2 x [16 x [3 x i32]]], [2 x [16 x [3 x i32]]], [2 x [16 x [16 x [3 x i32]]]], [1 x i32] }>*, <{ <{ { [16 x i16] }, { [256 x i16] } }>, <{ { [64 x i16] }, { [64 x i16] }, { [8 x i16] } }> }>*, i8*, { [2 x { { i32 } }], [2 x i8], i8, [2 x i32], i32, i32, i32 }*, { [2 x { { i32 } }], [2 x i8], i8, [2 x i32], i32, i32, i32 }*, { [2 x { { i32 } }], [2 x i8], i8, [2 x i32], i32, i32, i32 }*, i32, i32, i32, i32, i32, i32, { [34 x <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*]! , [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{ { <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i3! 2, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, i32, i! 8*, i32, i32, i32, i32, i16*, i16, i16, i16, i16, float, i8*, i32*, i32, i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32, i16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i32, i32, i32, double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>*], [34 x <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i3! 2, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{ { <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i32, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, ! i32, i8*, i32, i32, i32, i32, i16*, i16, i16, i16, i16, float,! i8*, i3 2*, i32, i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32, i16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i32, i32, i32, double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>*], [34 x i32], [34 x i32], [2 x i32], [2 x i32], <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32! , i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{ { <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i32, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, i32, i8*, i32, i! 32, i32, i32, i16*, i16, i16, i16, i16, float, i8*, i32*, i32,! i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32, i16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i32, i32, i32, double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>* }*, i32**, opaque*, [5 x <{ i32, [7 x i32], <{ { [16 x i8] } }>, <{ { [16 x i8] } }>, i8, [15 x i8], <{ { [16 x i8] }, [4 x i8], [4 x i8], [2 x i32] }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, { i8, i8, i8, i8, i8, i8, i8, [16 x i8], i8, i8, i64, [2 x [16 x [! 2 x i16]]], [2 x [16 x i8]], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, i32 }, [16 x i32] }>*], <{ i32, [7 x i32], <{ { [16 x i8] } }>, <{ { [16 x i8] } }>, i8, [15 x i8], <{ { [16 x i8] }, [4 x i8], [4 x i8], [2 x i32] }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, { i8, i8, i8, i8, i8, i8, i8, [16 x i8], i8, i8, i64, [2 x [16 x [2 x i16]]], [2 x [16 x i8]], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, i32 }, [16 x i32] }>*, i8, i8, i8, i8, i8, [3 x i8], i8*, i8*, i8*, <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [! 21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{ { <{ { ! { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i32, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, i32, i8*, i32, i32, i32, i32, i16*, i16, i16, i16, i16, float, i8*, i32*, i32, i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32, i! 16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i32, i32, i32, double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>*, [2 x <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{ { *, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i32, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, i32, i8*, i32, i32, i32, i32, i16*, i16, i16, i16, i16, float, i8*, i32*, i32, i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32, i16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, {! i32, i32, i32, double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>**], [2 x i32], [2 x i32], [33 x i8]*, [41 x i8]*, <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{ { <{ { { [2 x { { ! i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { ! [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i32, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, i32, i8*, i32, i32, i32, i32, i16*, i16, i16, i16, i16, float, i8*, i32*, i32, i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32, i16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i32, i32, i32,! double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>*, { <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, i32, i32, i32, i32, i32*, { { i32, i32 }, i8, i8, i8, i8, [17 x <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32],! [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{ { <{ ! { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i32, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, i32, i8*, i32, i32, i32, i32, i16*, i16, i16, i16, i16, float, i8*, i32*, i32, i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32,! i16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i32, i32, i32, double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>*], [17 x <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{! { <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, ! i8 } } } >*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i32, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, i32, i8*, i32, i32, i32, i32, i16*, i16, i16, i16, i16, float, i8*, i32*, i32, i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32, i16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i! 8, { i32, i32, i32, double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>*] }*, i32, opaque*, i16*, <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>*, i8*, i8*, i8*, i8*, i8*, { [16 x i8], [16 x i8] }*, opaque*, i8*, i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i! 8 }*, double, [16 x { i32, i32, i32, { i16* }, { [1 x i16*], [! 2 x i16* ], [2 x i16*], [4 x i16*], [8 x i16*], [8 x i16*], [16 x i16*] }, i32, [64 x { { { i32 } }, i8 }], { i16* }, [64 x { [1 x i16*], [2 x i16*], [2 x i16*], [4 x i16*], [8 x i16*], [8 x i16*], [16 x i16*] }], { i16* }, { i16* }, i32, [20 x { { i8, { { i16 } }, { { i32 } } }, i32, { { i32 } } }] }], [16 x { i32, i32, i32, { i16* }, { [1 x i16*], [2 x i16*], [2 x i16*], [4 x i16*], [8 x i16*], [8 x i16*], [16 x i16*] }, i32, [64 x { { { i32 } }, i8 }], { i16* }, [64 x { [1 x i16*], [2 x i16*], [2 x i16*], [4 x i16*], [8 x i16*], [8 x i16*], [16 x i16*] }], { i16* }, { i16* }, i32, [20 x { { i8, { { i16 } }, { { i32 } } }, i32, { { i32 } } }] }], { i8* }, { i8* }, i8, i8, [6 x [16 x i8]], [2 x [64 x i8]], [6 x [16 x i8]], [2 x [64 x i8]], [2 x i8], { i8* }, { i8* }, <{ i8, [15 x i8], [4 x <{ [16 x i8], <{ i8 }>, [3 x i8], i32, i32, [4 x i8], { [256 x i8] }, { [256 x i16] }, { [256 x i16] }, <{ <{ { [16 x i16] }, { [256 x i16] } }>, <{ { [64 x i16] }, { [64 x i16] }, { [8 x i16] } }! > }> }>] }>*, <{ i8, [15 x i8], [2 x <{ i8, <{ i8 }>, i8, i8, i32, i32, [4 x i8], { [128 x i8] }, { [128 x i16] }, { [128 x i16] }, <{ { [64 x i16] }, { [64 x i16] }, { [8 x i16] } }> }>] }>*, { i32, i32, i32, double }, { i32, i32, i32, double }, <{ [16 x i8], <{ i8 }>, [3 x i8], i32, i32, [4 x i8], { [256 x i8] }, { [256 x i16] }, { [256 x i16] }, <{ <{ { [16 x i16] }, { [256 x i16] } }>, <{ { [64 x i16] }, { [64 x i16] }, { [8 x i16] } }> }> }>*, <{ i8, <{ i8 }>, i8, i8, i32, i32, [4 x i8], { [128 x i8] }, { [128 x i16] }, { [128 x i16] }, <{ { [64 x i16] }, { [64 x i16] }, { [8 x i16] } }> }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, i32, i32, i32, i32, i32, i32, i32 }>*) { + %2 = alloca [3 x <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>], align 16 ; <[3 x <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>]*> [#uses=1] + %3 = getelementptr [3 x <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>]* %2, i32 0, i32 0 ; <<{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*> [#uses=1] + %4 = getelementptr <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* %3, i32 0, i32 0 ; <{ { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } }*> [#uses=1] + %5 = getelementptr { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } }* %4, i32 0, i32 0 ; <{ [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 }*> [#uses=1] + %6 = bitcast { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 }* %5 to { [8 x i16] }* ; <{ [8 x i16] }*> [#uses=1] + %7 = getelementptr { [8 x i16] }* %6, i32 0, i32 0 ; <[8 x i16]*> [#uses=1] + %8 = getelementptr [8 x i16]* %7, i32 0, i32 0 ; [#uses=1] + store i16 0, i16* %8, align 16 + call void @bar(i16* %8) + ret void +} + +declare void @bar(i16*) From gohman at apple.com Mon Feb 16 17:14:14 2009 From: gohman at apple.com (Dan Gohman) Date: Mon, 16 Feb 2009 23:14:14 -0000 Subject: [llvm-commits] [llvm] r64694 - /llvm/trunk/lib/Target/TargetData.cpp Message-ID: <200902162314.n1GNEERO023971@zion.cs.uiuc.edu> Author: djg Date: Mon Feb 16 17:14:14 2009 New Revision: 64694 URL: http://llvm.org/viewvc/llvm-project?rev=64694&view=rev Log: Delete trailing whitespace. Modified: llvm/trunk/lib/Target/TargetData.cpp Modified: llvm/trunk/lib/Target/TargetData.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetData.cpp?rev=64694&r1=64693&r2=64694&view=diff ============================================================================== --- llvm/trunk/lib/Target/TargetData.cpp (original) +++ llvm/trunk/lib/Target/TargetData.cpp Mon Feb 16 17:14:14 2009 @@ -302,14 +302,14 @@ BestMatchIdx = LargestInt; } else { assert(AlignType == VECTOR_ALIGN && "Unknown alignment type!"); - + // If we didn't find a vector size that is smaller or equal to this type, // then we will end up scalarizing this to its element type. Just return // the alignment of the element. return getAlignment(cast(Ty)->getElementType(), ABIInfo); - } + } } - + // Since we got a "best match" index, just return it. return ABIInfo ? Alignments[BestMatchIdx].ABIAlign : Alignments[BestMatchIdx].PrefAlign; @@ -475,12 +475,12 @@ : getPointerPrefAlignment()); case Type::ArrayTyID: return getAlignment(cast(Ty)->getElementType(), abi_or_pref); - + case Type::StructTyID: { // Packed structure types always have an ABI alignment of one. if (cast(Ty)->isPacked() && abi_or_pref) return 1; - + // Get the layout annotation... which is lazily created on demand. const StructLayout *Layout = getStructLayout(cast(Ty)); unsigned Align = getAlignmentInfo(AGGREGATE_ALIGN, 0, abi_or_pref, Ty); From kremenek at apple.com Mon Feb 16 17:18:21 2009 From: kremenek at apple.com (Ted Kremenek) Date: Mon, 16 Feb 2009 23:18:21 -0000 Subject: [llvm-commits] [llvm] r64695 - /llvm/tags/checker/checker-0.157/ Message-ID: <200902162318.n1GNILbI024147@zion.cs.uiuc.edu> Author: kremenek Date: Mon Feb 16 17:18:21 2009 New Revision: 64695 URL: http://llvm.org/viewvc/llvm-project?rev=64695&view=rev Log: Removing checker-0.157. Removed: llvm/tags/checker/checker-0.157/ From kremenek at apple.com Mon Feb 16 17:19:04 2009 From: kremenek at apple.com (Ted Kremenek) Date: Mon, 16 Feb 2009 23:19:04 -0000 Subject: [llvm-commits] [llvm] r64697 - /llvm/tags/checker/checker-0.157/ Message-ID: <200902162319.n1GNJ4jG024206@zion.cs.uiuc.edu> Author: kremenek Date: Mon Feb 16 17:19:04 2009 New Revision: 64697 URL: http://llvm.org/viewvc/llvm-project?rev=64697&view=rev Log: Tagging checker-0.157. Added: llvm/tags/checker/checker-0.157/ - copied from r64696, llvm/trunk/ From gohman at apple.com Mon Feb 16 18:10:53 2009 From: gohman at apple.com (Dan Gohman) Date: Tue, 17 Feb 2009 00:10:53 -0000 Subject: [llvm-commits] [llvm] r64702 - /llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Message-ID: <200902170010.n1H0Ar6u025999@zion.cs.uiuc.edu> Author: djg Date: Mon Feb 16 18:10:53 2009 New Revision: 64702 URL: http://llvm.org/viewvc/llvm-project?rev=64702&view=rev Log: Simplify; fix some 80-column violations. Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=64702&r1=64701&r2=64702&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Mon Feb 16 18:10:53 2009 @@ -705,8 +705,9 @@ // variable. while (!IndVars.empty()) { PHINode *PN = IndVars.back().first; - Value *NewVal = Rewriter.expandCodeFor(IndVars.back().second, InsertPt); - DOUT << "INDVARS: Rewrote IV '" << *IndVars.back().second << "' " << *PN + SCEVAddRecExpr *AR = cast(IndVars.back().second); + Value *NewVal = Rewriter.expandCodeFor(AR, InsertPt); + DOUT << "INDVARS: Rewrote IV '" << *AR << "' " << *PN << " into = " << *NewVal << "\n"; NewVal->takeName(PN); @@ -718,9 +719,9 @@ UI != UE; ++UI) { if (isa(UI) && NoSignedWrap) { SCEVHandle ExtendedStart = - SE->getSignExtendExpr(cast(IndVars.back().second)->getStart(), LargestType); + SE->getSignExtendExpr(AR->getStart(), LargestType); SCEVHandle ExtendedStep = - SE->getSignExtendExpr(cast(IndVars.back().second)->getStepRecurrence(*SE), LargestType); + SE->getSignExtendExpr(AR->getStepRecurrence(*SE), LargestType); SCEVHandle ExtendedAddRec = SE->getAddRecExpr(ExtendedStart, ExtendedStep, L); if (LargestType != UI->getType()) @@ -732,9 +733,9 @@ } if (isa(UI) && NoUnsignedWrap) { SCEVHandle ExtendedStart = - SE->getZeroExtendExpr(cast(IndVars.back().second)->getStart(), LargestType); + SE->getZeroExtendExpr(AR->getStart(), LargestType); SCEVHandle ExtendedStep = - SE->getZeroExtendExpr(cast(IndVars.back().second)->getStepRecurrence(*SE), LargestType); + SE->getZeroExtendExpr(AR->getStepRecurrence(*SE), LargestType); SCEVHandle ExtendedAddRec = SE->getAddRecExpr(ExtendedStart, ExtendedStep, L); if (LargestType != UI->getType()) From evan.cheng at apple.com Mon Feb 16 18:13:06 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 17 Feb 2009 00:13:06 -0000 Subject: [llvm-commits] [llvm] r64703 - in /llvm/trunk: include/llvm/Analysis/ScalarEvolution.h include/llvm/Analysis/ScalarEvolutionExpressions.h lib/Analysis/ScalarEvolution.cpp lib/Transforms/Scalar/LoopStrengthReduce.cpp test/Transforms/LoopStrengthReduce/pr3399.ll Message-ID: <200902170013.n1H0D729026081@zion.cs.uiuc.edu> Author: evancheng Date: Mon Feb 16 18:13:06 2009 New Revision: 64703 URL: http://llvm.org/viewvc/llvm-project?rev=64703&view=rev Log: Strengthen the "non-constant stride must dominate loop preheader" check. Added: llvm/trunk/test/Transforms/LoopStrengthReduce/pr3399.ll Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolution.h llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h llvm/trunk/lib/Analysis/ScalarEvolution.cpp llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolution.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolution.h?rev=64703&r1=64702&r2=64703&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/ScalarEvolution.h (original) +++ llvm/trunk/include/llvm/Analysis/ScalarEvolution.h Mon Feb 16 18:13:06 2009 @@ -89,6 +89,10 @@ const SCEVHandle &Conc, ScalarEvolution &SE) const = 0; + /// dominates - Return true if elements that makes up this SCEV dominates + /// the specified basic block. + virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const = 0; + /// print - Print out the internal representation of this scalar to the /// specified stream. This should really only be used for debugging /// purposes. @@ -124,6 +128,10 @@ const SCEVHandle &Conc, ScalarEvolution &SE) const; + virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const { + return true; + } + /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const SCEVCouldNotCompute *S) { return true; } static bool classof(const SCEV *S); Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h?rev=64703&r1=64702&r2=64703&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h (original) +++ llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h Mon Feb 16 18:13:06 2009 @@ -20,6 +20,7 @@ class ConstantInt; class ConstantRange; class APInt; + class DominatorTree; enum SCEVTypes { // These should be ordered in terms of increasing complexity to make the @@ -58,6 +59,10 @@ return this; } + bool dominates(BasicBlock *BB, DominatorTree *DT) const { + return true; + } + virtual void print(std::ostream &OS) const; void print(std::ostream *OS) const { if (OS) print(*OS); } @@ -100,6 +105,8 @@ return SE.getTruncateExpr(H, Ty); } + virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const; + virtual void print(std::ostream &OS) const; void print(std::ostream *OS) const { if (OS) print(*OS); } @@ -142,6 +149,8 @@ return SE.getZeroExtendExpr(H, Ty); } + bool dominates(BasicBlock *BB, DominatorTree *DT) const; + virtual void print(std::ostream &OS) const; void print(std::ostream *OS) const { if (OS) print(*OS); } @@ -184,6 +193,8 @@ return SE.getSignExtendExpr(H, Ty); } + bool dominates(BasicBlock *BB, DominatorTree *DT) const; + virtual void print(std::ostream &OS) const; void print(std::ostream *OS) const { if (OS) print(*OS); } @@ -250,6 +261,8 @@ const SCEVHandle &Conc, ScalarEvolution &SE) const; + bool dominates(BasicBlock *BB, DominatorTree *DT) const; + virtual const char *getOperationStr() const = 0; virtual const Type *getType() const { return getOperand(0)->getType(); } @@ -343,6 +356,7 @@ return SE.getUDivExpr(L, R); } + bool dominates(BasicBlock *BB, DominatorTree *DT) const; virtual const Type *getType() const; @@ -437,6 +451,8 @@ const SCEVHandle &Conc, ScalarEvolution &SE) const; + bool dominates(BasicBlock *BB, DominatorTree *DT) const; + virtual void print(std::ostream &OS) const; void print(std::ostream *OS) const { if (OS) print(*OS); } @@ -518,6 +534,8 @@ return this; } + bool dominates(BasicBlock *BB, DominatorTree *DT) const; + virtual const Type *getType() const; virtual void print(std::ostream &OS) const; Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=64703&r1=64702&r2=64703&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original) +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Mon Feb 16 18:13:06 2009 @@ -66,6 +66,7 @@ #include "llvm/GlobalVariable.h" #include "llvm/Instructions.h" #include "llvm/Analysis/ConstantFolding.h" +#include "llvm/Analysis/Dominators.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Assembly/Writer.h" #include "llvm/Transforms/Scalar.h" @@ -205,6 +206,10 @@ SCEVTruncates->erase(std::make_pair(Op, Ty)); } +bool SCEVTruncateExpr::dominates(BasicBlock *BB, DominatorTree *DT) const { + return Op->dominates(BB, DT); +} + void SCEVTruncateExpr::print(std::ostream &OS) const { OS << "(truncate " << *Op << " to " << *Ty << ")"; } @@ -227,6 +232,10 @@ SCEVZeroExtends->erase(std::make_pair(Op, Ty)); } +bool SCEVZeroExtendExpr::dominates(BasicBlock *BB, DominatorTree *DT) const { + return Op->dominates(BB, DT); +} + void SCEVZeroExtendExpr::print(std::ostream &OS) const { OS << "(zeroextend " << *Op << " to " << *Ty << ")"; } @@ -249,6 +258,10 @@ SCEVSignExtends->erase(std::make_pair(Op, Ty)); } +bool SCEVSignExtendExpr::dominates(BasicBlock *BB, DominatorTree *DT) const { + return Op->dominates(BB, DT); +} + void SCEVSignExtendExpr::print(std::ostream &OS) const { OS << "(signextend " << *Op << " to " << *Ty << ")"; } @@ -306,6 +319,14 @@ return this; } +bool SCEVCommutativeExpr::dominates(BasicBlock *BB, DominatorTree *DT) const { + for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { + if (!getOperand(i)->dominates(BB, DT)) + return false; + } + return true; +} + // SCEVUDivs - Only allow the creation of one SCEVUDivExpr for any particular // input. Don't use a SCEVHandle here, or else the object will never be @@ -317,6 +338,10 @@ SCEVUDivs->erase(std::make_pair(LHS, RHS)); } +bool SCEVUDivExpr::dominates(BasicBlock *BB, DominatorTree *DT) const { + return LHS->dominates(BB, DT) && RHS->dominates(BB, DT); +} + void SCEVUDivExpr::print(std::ostream &OS) const { OS << "(" << *LHS << " /u " << *RHS << ")"; } @@ -337,6 +362,15 @@ Operands.end()))); } +bool SCEVAddRecExpr::dominates(BasicBlock *BB, DominatorTree *DT) const { + for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { + if (!getOperand(i)->dominates(BB, DT)) + return false; + } + return true; +} + + SCEVHandle SCEVAddRecExpr:: replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym, const SCEVHandle &Conc, @@ -391,6 +425,12 @@ return true; } +bool SCEVUnknown::dominates(BasicBlock *BB, DominatorTree *DT) const { + if (Instruction *I = dyn_cast(getValue())) + return DT->dominates(I->getParent(), BB); + return true; +} + const Type *SCEVUnknown::getType() const { return V->getType(); } Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=64703&r1=64702&r2=64703&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Mon Feb 16 18:13:06 2009 @@ -438,16 +438,11 @@ Start = SE->getAddExpr(Start, AddRec->getOperand(0)); if (!isa(AddRec->getOperand(1))) { - // If stride is an instruction, make sure it dominates the loop header. + // If stride is an instruction, make sure it dominates the loop preheader. // Otherwise we could end up with a use before def situation. - if (SCEVUnknown *SU = dyn_cast(AddRec->getOperand(1))) { - if (Instruction *I = dyn_cast(SU->getValue())) { - BasicBlock *StrideBB = I->getParent(); - BasicBlock *Preheader = L->getLoopPreheader(); - if (!DT->dominates(StrideBB, Preheader)) - return false; - } - } + BasicBlock *Preheader = L->getLoopPreheader(); + if (!AddRec->getOperand(1)->dominates(Preheader, DT)) + return false; DOUT << "[" << L->getHeader()->getName() << "] Variable stride: " << *AddRec << "\n"; Added: llvm/trunk/test/Transforms/LoopStrengthReduce/pr3399.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopStrengthReduce/pr3399.ll?rev=64703&view=auto ============================================================================== --- llvm/trunk/test/Transforms/LoopStrengthReduce/pr3399.ll (added) +++ llvm/trunk/test/Transforms/LoopStrengthReduce/pr3399.ll Mon Feb 16 18:13:06 2009 @@ -0,0 +1,32 @@ +; RUN: llvm-as < %s | opt -loop-reduce | llvm-dis +; PR3399 + + at g_53 = external global i32 ; [#uses=1] + +define i32 @foo() nounwind { +bb5.thread: + br label %bb + +bb: ; preds = %bb5, %bb5.thread + %indvar = phi i32 [ 0, %bb5.thread ], [ %indvar.next, %bb5 ] ; [#uses=2] + br i1 false, label %bb5, label %bb1 + +bb1: ; preds = %bb + %l_2.0.reg2mem.0 = sub i32 0, %indvar ; [#uses=1] + %0 = volatile load i32* @g_53, align 4 ; [#uses=1] + %1 = trunc i32 %l_2.0.reg2mem.0 to i16 ; [#uses=1] + %2 = trunc i32 %0 to i16 ; [#uses=1] + %3 = mul i16 %2, %1 ; [#uses=1] + %4 = icmp eq i16 %3, 0 ; [#uses=1] + br i1 %4, label %bb7, label %bb2 + +bb2: ; preds = %bb2, %bb1 + br label %bb2 + +bb5: ; preds = %bb + %indvar.next = add i32 %indvar, 1 ; [#uses=1] + br label %bb + +bb7: ; preds = %bb1 + ret i32 1 +} From dpatel at apple.com Mon Feb 16 18:13:57 2009 From: dpatel at apple.com (Devang Patel) Date: Tue, 17 Feb 2009 00:13:57 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64704 - /llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Message-ID: <200902170013.n1H0DvZY026123@zion.cs.uiuc.edu> Author: dpatel Date: Mon Feb 16 18:13:56 2009 New Revision: 64704 URL: http://llvm.org/viewvc/llvm-project?rev=64704&view=rev Log: Use appropriate constructor and destructor names in debug info entry. Modified: llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Modified: llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp?rev=64704&r1=64703&r2=64704&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Mon Feb 16 18:13:56 2009 @@ -221,12 +221,13 @@ BasicBlock *CurBB) { // Gather location information. expanded_location Loc = GetNodeLocation(FnDecl, false); - const char *FnName = GetNodeName(FnDecl); const char *LinkageName = getLinkageName(FnDecl); DISubprogram SP = DebugFactory.CreateSubprogram(findRegion(FnDecl), - FnName, FnName, LinkageName, + lang_hooks.dwarf_name(FnDecl, 0), + lang_hooks.dwarf_name(FnDecl, 0), + LinkageName, getOrCreateCompileUnit(Loc.file), CurLineNo, getOrCreateType(TREE_TYPE(FnDecl)), Fn->hasInternalLinkage(), @@ -588,7 +589,7 @@ Member = TREE_CHAIN(Member)) { // Should we skip. if (DECL_P(Member) && DECL_IGNORED_P(Member)) continue; - + if (TREE_CODE(Member) == FIELD_DECL) { if (DECL_FIELD_OFFSET(Member) == 0 || @@ -631,11 +632,12 @@ Member = TREE_CHAIN(Member)) { if (DECL_ABSTRACT_ORIGIN (Member)) continue; - + if (DECL_ARTIFICIAL (Member)) continue; + // Get the location of the member. expanded_location MemLoc = GetNodeLocation(Member, false); - const char *MemberName = GetNodeName(Member); + const char *MemberName = lang_hooks.dwarf_name(Member, 0); const char *LinkageName = getLinkageName(Member); DIType SPTy = getOrCreateType(TREE_TYPE(Member)); DISubprogram SP = From dpatel at apple.com Mon Feb 16 18:15:08 2009 From: dpatel at apple.com (Devang Patel) Date: Tue, 17 Feb 2009 00:15:08 -0000 Subject: [llvm-commits] [llvm] r64705 - /llvm/trunk/test/FrontendC++/2009-02-16-CtorNames-dbg.cpp Message-ID: <200902170015.n1H0F8at026195@zion.cs.uiuc.edu> Author: dpatel Date: Mon Feb 16 18:15:08 2009 New Revision: 64705 URL: http://llvm.org/viewvc/llvm-project?rev=64705&view=rev Log: Testcase for rev. 64704 Added: llvm/trunk/test/FrontendC++/2009-02-16-CtorNames-dbg.cpp Added: llvm/trunk/test/FrontendC++/2009-02-16-CtorNames-dbg.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FrontendC%2B%2B/2009-02-16-CtorNames-dbg.cpp?rev=64705&view=auto ============================================================================== --- llvm/trunk/test/FrontendC++/2009-02-16-CtorNames-dbg.cpp (added) +++ llvm/trunk/test/FrontendC++/2009-02-16-CtorNames-dbg.cpp Mon Feb 16 18:15:08 2009 @@ -0,0 +1,12 @@ +// RUN: %llvmgcc -S -g --emit-llvm %s -o - | grep "\~A" +// RUN: %llvmgcc -S -g --emit-llvm %s -o - | not grep comp_ctor +// RUN: %llvmgcc -S -g --emit-llvm %s -o - | not grep comp_dtor +class A { + int i; +public: + A() { i = 0; } + ~A() { i = 42; } +}; + +A a; + From clattner at apple.com Mon Feb 16 18:24:45 2009 From: clattner at apple.com (Chris Lattner) Date: Mon, 16 Feb 2009 16:24:45 -0800 Subject: [llvm-commits] [llvm] r64693 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/enforce-known-alignment.ll In-Reply-To: <200902162302.n1GN2LK7023114@zion.cs.uiuc.edu> References: <200902162302.n1GN2LK7023114@zion.cs.uiuc.edu> Message-ID: <6B846213-287D-428A-88C6-1E37205080ED@apple.com> On Feb 16, 2009, at 3:02 PM, Dan Gohman wrote: > Author: djg > Date: Mon Feb 16 17:02:21 2009 > New Revision: 64693 > > URL: http://llvm.org/viewvc/llvm-project?rev=64693&view=rev > Log: > Fix EnforceKnownAlignment so that it doesn't ever reduce the alignment > of an alloca or global variable. Thanks! Can you please reduce the testcase to something that doesn't use the crazy types? -Chris From isanbard at gmail.com Mon Feb 16 19:01:29 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 01:01:29 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64713 - in /llvm-gcc-4.2/trunk/gcc: config/darwin.h llvm-backend.cpp llvm-debug.cpp Message-ID: <200902170101.n1H11Uaf027943@zion.cs.uiuc.edu> Author: void Date: Mon Feb 16 19:01:29 2009 New Revision: 64713 URL: http://llvm.org/viewvc/llvm-project?rev=64713&view=rev Log: Reapply r63639: Enable debug info at -O1+. However, for now, do not emit variable and line number info at -O1+. Modified: llvm-gcc-4.2/trunk/gcc/config/darwin.h llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Modified: llvm-gcc-4.2/trunk/gcc/config/darwin.h URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/darwin.h?rev=64713&r1=64712&r2=64713&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/config/darwin.h (original) +++ llvm-gcc-4.2/trunk/gcc/config/darwin.h Mon Feb 16 19:01:29 2009 @@ -340,7 +340,6 @@ specifying the handling of options understood by generic Unix linkers, and for positional arguments like libraries. */ /* APPLE LOCAL begin mainline */ -#ifdef ENABLE_LLVM #define LINK_COMMAND_SPEC "\ %{!fdump=*:%{!fsyntax-only:%{!precomp:%{!c:%{!M:%{!MM:%{!E:%{!S:\ %(linker) %l %X %{d} %{s} %{t} %{Z} %{u*} \ @@ -359,29 +358,7 @@ %{!fdump=*:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ "/* APPLE LOCAL end mainline 4.3 2006-10-31 4370146 */"\ %{.c|.cc|.C|.cpp|.cp|.c++|.cxx|.CPP|.m|.mm: \ - %{!O: %{!O1: %{!O2: %{!O3: %{!O4: %{!Os: \ -"/* LLVM LOCAL do not use dsymutil with -O1 or higher */"\ - %{g*:%{!gstabs*:%{!g0: dsymutil %{o*:%*}%{!o:a.out}}}}}}}}}}}}}}}}}}" -#else -#define LINK_COMMAND_SPEC "\ -%{!fdump=*:%{!fsyntax-only:%{!precomp:%{!c:%{!M:%{!MM:%{!E:%{!S:\ - %(linker) %l %X %{d} %{s} %{t} %{Z} %{u*} \ - %{A} %{e*} %{m} %{r} %{x} \ - %{o*}%{!o:-o a.out} \ - %{!A:%{!nostdlib:%{!nostartfiles:%S}}} \ - %{L*} %{fopenmp:%:include(libgomp.spec)%(link_gomp)} \ -"/* APPLE LOCAL add fcreate-profile */"\ - %(link_libgcc) %o %{fprofile-arcs|fprofile-generate|fcreate-profile|coverage:-lgcov} \ -"/* APPLE LOCAL nested functions 4357979 */"\ - %{fnested-functions: -allow_stack_execute} \ - %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %G %L}} \ -"/* APPLE LOCAL begin mainline 4.3 2006-10-31 4370146 */"\ - %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} %{F*} }}}}}}}}\n\ -%{!fdump=*:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ -"/* APPLE LOCAL end mainline 4.3 2006-10-31 4370146 */"\ - %{.c|.cc|.C|.cpp|.cp|.c++|.cxx|.CPP|.m|.mm: \ %{g*:%{!gstabs*:%{!g0: dsymutil %{o*:%*}%{!o:a.out}}}}}}}}}}}}" -#endif /* APPLE LOCAL end mainline */ #ifdef TARGET_SYSTEM_ROOT Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=64713&r1=64712&r2=64713&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Mon Feb 16 19:01:29 2009 @@ -250,7 +250,7 @@ // FIXME - Do not disable debug info while writing pch. if (!flag_pch_file && - !optimize && debug_info_level > DINFO_LEVEL_NONE) + debug_info_level > DINFO_LEVEL_NONE) TheDebugInfo = new DebugInfo(TheModule); } @@ -287,8 +287,7 @@ delete MB; // FIXME - Do not disable debug info while writing pch. - if (!flag_pch_file && - !optimize && debug_info_level > DINFO_LEVEL_NONE) + if (!flag_pch_file && debug_info_level > DINFO_LEVEL_NONE) TheDebugInfo = new DebugInfo(TheModule); if (!TheModule) { Modified: llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp?rev=64713&r1=64712&r2=64713&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Mon Feb 16 19:01:29 2009 @@ -299,6 +299,11 @@ /// region - "llvm.dbg.declare." void DebugInfo::EmitDeclare(tree decl, unsigned Tag, const char *Name, tree type, Value *AI, BasicBlock *CurBB) { + + // Do not emit variable declaration info, for now. + if (optimize) + return; + // Ignore compiler generated temporaries. if (DECL_IGNORED_P(decl)) return; @@ -320,6 +325,11 @@ /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of /// source line - "llvm.dbg.stoppoint." void DebugInfo::EmitStopPoint(Function *Fn, BasicBlock *CurBB) { + + // Do not emit line number info, for now. + if (optimize) + return; + // Don't bother if things are the same as last time. if (PrevLineNo == CurLineNo && PrevBB == CurBB && From isanbard at gmail.com Mon Feb 16 19:02:43 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 01:02:43 -0000 Subject: [llvm-commits] [llvm] r64714 - in /llvm/branches/Apple/Dib: include/llvm/CodeGen/DebugLoc.h lib/CodeGen/SelectionDAG/LegalizeDAG.cpp lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Message-ID: <200902170102.n1H12hNd027993@zion.cs.uiuc.edu> Author: void Date: Mon Feb 16 19:02:43 2009 New Revision: 64714 URL: http://llvm.org/viewvc/llvm-project?rev=64714&view=rev Log: Enable debug location generation at -Os. This goes with the reapplication of the r63639 patch. Modified: llvm/branches/Apple/Dib/include/llvm/CodeGen/DebugLoc.h llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Modified: llvm/branches/Apple/Dib/include/llvm/CodeGen/DebugLoc.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/CodeGen/DebugLoc.h?rev=64714&r1=64713&r2=64714&view=diff ============================================================================== --- llvm/branches/Apple/Dib/include/llvm/CodeGen/DebugLoc.h (original) +++ llvm/branches/Apple/Dib/include/llvm/CodeGen/DebugLoc.h Mon Feb 16 19:02:43 2009 @@ -37,17 +37,14 @@ public: DebugLoc() : Idx(~0U) {} // Defaults to invalid. - static DebugLoc getUnknownLoc() { DebugLoc L; L.Idx = 0; return L; } + static DebugLoc getUnknownLoc() { DebugLoc L; L.Idx = ~0U; return L; } static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; } unsigned getIndex() const { return Idx; } - /// isInvalid - Return true if the DebugLoc is invalid. - bool isInvalid() const { return Idx == ~0U; } - /// isUnknown - Return true if there is no debug info for the SDNode / /// MachineInstr. - bool isUnknown() const { return Idx == 0; } + bool isUnknown() const { return Idx == ~0U; } bool operator==(const DebugLoc &DL) const { return Idx == DL.Idx; } bool operator!=(const DebugLoc &DL) const { return !(*this == DL); } Modified: llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=64714&r1=64713&r2=64714&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (original) +++ llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Mon Feb 16 19:02:43 2009 @@ -28,6 +28,7 @@ #include "llvm/CallingConv.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" +#include "llvm/Function.h" #include "llvm/GlobalVariable.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" @@ -1289,17 +1290,23 @@ unsigned Line = DSP->getLine(); unsigned Col = DSP->getColumn(); - - // A bit self-referential to have DebugLoc on Debug_Loc nodes, but - // it won't hurt anything. - if (useDEBUG_LOC) { - SDValue Ops[] = { Tmp1, DAG.getConstant(Line, MVT::i32), + + const Function *F = DAG.getMachineFunction().getFunction(); + + if (!F->hasFnAttr(Attribute::OptimizeForSize)) { + // A bit self-referential to have DebugLoc on Debug_Loc nodes, but it + // won't hurt anything. + if (useDEBUG_LOC) { + SDValue Ops[] = { Tmp1, DAG.getConstant(Line, MVT::i32), DAG.getConstant(Col, MVT::i32), DAG.getConstant(SrcFile, MVT::i32) }; - Result = DAG.getNode(ISD::DEBUG_LOC, dl, MVT::Other, Ops, 4); + Result = DAG.getNode(ISD::DEBUG_LOC, dl, MVT::Other, Ops, 4); + } else { + unsigned ID = DW->RecordSourceLine(Line, Col, SrcFile); + Result = DAG.getLabel(ISD::DBG_LABEL, dl, Tmp1, ID); + } } else { - unsigned ID = DW->RecordSourceLine(Line, Col, SrcFile); - Result = DAG.getLabel(ISD::DBG_LABEL, dl, Tmp1, ID); + Result = Tmp1; // chain } } else { Result = Tmp1; // chain Modified: llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp?rev=64714&r1=64713&r2=64714&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp (original) +++ llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp Mon Feb 16 19:02:43 2009 @@ -3915,8 +3915,12 @@ if (DW && DW->ValidDebugInfo(RSI.getContext())) { unsigned LabelID = DW->RecordRegionStart(cast(RSI.getContext())); - DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(), - getRoot(), LabelID)); + const Function *F = I.getParent()->getParent(); + + // FIXME: Support more than just -Os. + if (!F->hasFnAttr(Attribute::OptimizeForSize)) + DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(), + getRoot(), LabelID)); } return 0; @@ -3927,8 +3931,12 @@ if (DW && DW->ValidDebugInfo(REI.getContext())) { unsigned LabelID = DW->RecordRegionEnd(cast(REI.getContext())); - DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(), - getRoot(), LabelID)); + const Function *F = I.getParent()->getParent(); + + // FIXME: Support more than just -Os. + if (!F->hasFnAttr(Attribute::OptimizeForSize)) + DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(), + getRoot(), LabelID)); } return 0; @@ -3950,28 +3958,36 @@ // function start. It will be emitted at asm emission time. However, // create a label if this is a beginning of inlined function. unsigned Line = Subprogram.getLineNumber(); - unsigned LabelID = DW->RecordSourceLine(Line, 0, SrcFile); - if (DW->getRecordSourceLineCount() != 1) - DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(), - getRoot(), LabelID)); + // FIXME: Support more than just -Os. + const Function *F = I.getParent()->getParent(); + if (!F->hasFnAttr(Attribute::OptimizeForSize)) { + unsigned LabelID = DW->RecordSourceLine(Line, 0, SrcFile); + if (DW->getRecordSourceLineCount() != 1) + DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(), + getRoot(), LabelID)); + } setCurDebugLoc(DebugLoc::get(DAG.getMachineFunction(). - getOrCreateDebugLocID(SrcFile, Line, 0))); + getOrCreateDebugLocID(SrcFile, Line, 0))); } return 0; } case Intrinsic::dbg_declare: { - DwarfWriter *DW = DAG.getDwarfWriter(); - DbgDeclareInst &DI = cast(I); - Value *Variable = DI.getVariable(); - if (DW && DW->ValidDebugInfo(Variable)) - DAG.setRoot(DAG.getNode(ISD::DECLARE, dl, MVT::Other, getRoot(), - getValue(DI.getAddress()), getValue(Variable))); + const Function *F = I.getParent()->getParent(); + if (!F->hasFnAttr(Attribute::OptimizeForSize)) { + DwarfWriter *DW = DAG.getDwarfWriter(); + DbgDeclareInst &DI = cast(I); + Value *Variable = DI.getVariable(); + if (DW && DW->ValidDebugInfo(Variable)) + DAG.setRoot(DAG.getNode(ISD::DECLARE, dl, MVT::Other, getRoot(), + getValue(DI.getAddress()), getValue(Variable))); + } else { + // FIXME: Do something sensible here when we support debug declare. + } return 0; } - case Intrinsic::eh_exception: { if (!CurMBB->isLandingPad()) { // FIXME: Mark exception register as live in. Hack for PR1508. Modified: llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp?rev=64714&r1=64713&r2=64714&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp (original) +++ llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Mon Feb 16 19:02:43 2009 @@ -726,15 +726,20 @@ ++EmittedInsts; if (TAI->doesSupportDebugInformation()) { - static DebugLoc PrevDL = DebugLoc::getUnknownLoc(); - DebugLoc CurDL = MI->getDebugLoc(); + const Function *F = MF->getFunction(); - if (!CurDL.isInvalid() && !CurDL.isUnknown() && PrevDL != CurDL) { - DebugLocTuple DLT = MF->getDebugLocTuple(CurDL); - printLabel(DW->RecordSourceLine(DLT.Line, DLT.Col, DLT.Src)); - } + // FIXME: Support more than '-Os'. + if (F->hasFnAttr(Attribute::OptimizeForSize)) { + static DebugLoc PrevDL = DebugLoc::getUnknownLoc(); + DebugLoc CurDL = MI->getDebugLoc(); + + if (!CurDL.isUnknown() && PrevDL != CurDL) { + DebugLocTuple DLT = MF->getDebugLocTuple(CurDL); + printLabel(DW->RecordSourceLine(DLT.Line, DLT.Col, DLT.Src)); + } - PrevDL = CurDL; + PrevDL = CurDL; + } } // Call the autogenerated instruction printer routines. From isanbard at gmail.com Mon Feb 16 19:04:54 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 01:04:54 -0000 Subject: [llvm-commits] [llvm] r64715 - in /llvm/trunk: include/llvm/CodeGen/DebugLoc.h lib/CodeGen/SelectionDAG/LegalizeDAG.cpp lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Message-ID: <200902170104.n1H14t4Y028081@zion.cs.uiuc.edu> Author: void Date: Mon Feb 16 19:04:54 2009 New Revision: 64715 URL: http://llvm.org/viewvc/llvm-project?rev=64715&view=rev Log: --- Merging (from foreign repository) r64714 into '.': U include/llvm/CodeGen/DebugLoc.h U lib/CodeGen/SelectionDAG/LegalizeDAG.cpp U lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp U lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Enable debug location generation at -Os. This goes with the reapplication of the r63639 patch. Modified: llvm/trunk/include/llvm/CodeGen/DebugLoc.h llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Modified: llvm/trunk/include/llvm/CodeGen/DebugLoc.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/DebugLoc.h?rev=64715&r1=64714&r2=64715&view=diff ============================================================================== --- llvm/trunk/include/llvm/CodeGen/DebugLoc.h (original) +++ llvm/trunk/include/llvm/CodeGen/DebugLoc.h Mon Feb 16 19:04:54 2009 @@ -37,17 +37,14 @@ public: DebugLoc() : Idx(~0U) {} // Defaults to invalid. - static DebugLoc getUnknownLoc() { DebugLoc L; L.Idx = 0; return L; } + static DebugLoc getUnknownLoc() { DebugLoc L; L.Idx = ~0U; return L; } static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; } unsigned getIndex() const { return Idx; } - /// isInvalid - Return true if the DebugLoc is invalid. - bool isInvalid() const { return Idx == ~0U; } - /// isUnknown - Return true if there is no debug info for the SDNode / /// MachineInstr. - bool isUnknown() const { return Idx == 0; } + bool isUnknown() const { return Idx == ~0U; } bool operator==(const DebugLoc &DL) const { return Idx == DL.Idx; } bool operator!=(const DebugLoc &DL) const { return !(*this == DL); } Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=64715&r1=64714&r2=64715&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (original) +++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Mon Feb 16 19:04:54 2009 @@ -28,6 +28,7 @@ #include "llvm/CallingConv.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" +#include "llvm/Function.h" #include "llvm/GlobalVariable.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" @@ -1289,17 +1290,23 @@ unsigned Line = DSP->getLine(); unsigned Col = DSP->getColumn(); - - // A bit self-referential to have DebugLoc on Debug_Loc nodes, but - // it won't hurt anything. - if (useDEBUG_LOC) { - SDValue Ops[] = { Tmp1, DAG.getConstant(Line, MVT::i32), + + const Function *F = DAG.getMachineFunction().getFunction(); + + if (!F->hasFnAttr(Attribute::OptimizeForSize)) { + // A bit self-referential to have DebugLoc on Debug_Loc nodes, but it + // won't hurt anything. + if (useDEBUG_LOC) { + SDValue Ops[] = { Tmp1, DAG.getConstant(Line, MVT::i32), DAG.getConstant(Col, MVT::i32), DAG.getConstant(SrcFile, MVT::i32) }; - Result = DAG.getNode(ISD::DEBUG_LOC, dl, MVT::Other, Ops, 4); + Result = DAG.getNode(ISD::DEBUG_LOC, dl, MVT::Other, Ops, 4); + } else { + unsigned ID = DW->RecordSourceLine(Line, Col, SrcFile); + Result = DAG.getLabel(ISD::DBG_LABEL, dl, Tmp1, ID); + } } else { - unsigned ID = DW->RecordSourceLine(Line, Col, SrcFile); - Result = DAG.getLabel(ISD::DBG_LABEL, dl, Tmp1, ID); + Result = Tmp1; // chain } } else { Result = Tmp1; // chain Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp?rev=64715&r1=64714&r2=64715&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp (original) +++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp Mon Feb 16 19:04:54 2009 @@ -3915,8 +3915,12 @@ if (DW && DW->ValidDebugInfo(RSI.getContext())) { unsigned LabelID = DW->RecordRegionStart(cast(RSI.getContext())); - DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(), - getRoot(), LabelID)); + const Function *F = I.getParent()->getParent(); + + // FIXME: Support more than just -Os. + if (!F->hasFnAttr(Attribute::OptimizeForSize)) + DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(), + getRoot(), LabelID)); } return 0; @@ -3927,8 +3931,12 @@ if (DW && DW->ValidDebugInfo(REI.getContext())) { unsigned LabelID = DW->RecordRegionEnd(cast(REI.getContext())); - DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(), - getRoot(), LabelID)); + const Function *F = I.getParent()->getParent(); + + // FIXME: Support more than just -Os. + if (!F->hasFnAttr(Attribute::OptimizeForSize)) + DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(), + getRoot(), LabelID)); } return 0; @@ -3950,28 +3958,36 @@ // function start. It will be emitted at asm emission time. However, // create a label if this is a beginning of inlined function. unsigned Line = Subprogram.getLineNumber(); - unsigned LabelID = DW->RecordSourceLine(Line, 0, SrcFile); - if (DW->getRecordSourceLineCount() != 1) - DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(), - getRoot(), LabelID)); + // FIXME: Support more than just -Os. + const Function *F = I.getParent()->getParent(); + if (!F->hasFnAttr(Attribute::OptimizeForSize)) { + unsigned LabelID = DW->RecordSourceLine(Line, 0, SrcFile); + if (DW->getRecordSourceLineCount() != 1) + DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(), + getRoot(), LabelID)); + } setCurDebugLoc(DebugLoc::get(DAG.getMachineFunction(). - getOrCreateDebugLocID(SrcFile, Line, 0))); + getOrCreateDebugLocID(SrcFile, Line, 0))); } return 0; } case Intrinsic::dbg_declare: { - DwarfWriter *DW = DAG.getDwarfWriter(); - DbgDeclareInst &DI = cast(I); - Value *Variable = DI.getVariable(); - if (DW && DW->ValidDebugInfo(Variable)) - DAG.setRoot(DAG.getNode(ISD::DECLARE, dl, MVT::Other, getRoot(), - getValue(DI.getAddress()), getValue(Variable))); + const Function *F = I.getParent()->getParent(); + if (!F->hasFnAttr(Attribute::OptimizeForSize)) { + DwarfWriter *DW = DAG.getDwarfWriter(); + DbgDeclareInst &DI = cast(I); + Value *Variable = DI.getVariable(); + if (DW && DW->ValidDebugInfo(Variable)) + DAG.setRoot(DAG.getNode(ISD::DECLARE, dl, MVT::Other, getRoot(), + getValue(DI.getAddress()), getValue(Variable))); + } else { + // FIXME: Do something sensible here when we support debug declare. + } return 0; } - case Intrinsic::eh_exception: { if (!CurMBB->isLandingPad()) { // FIXME: Mark exception register as live in. Hack for PR1508. Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp?rev=64715&r1=64714&r2=64715&view=diff ============================================================================== --- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp (original) +++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Mon Feb 16 19:04:54 2009 @@ -726,15 +726,20 @@ ++EmittedInsts; if (TAI->doesSupportDebugInformation()) { - static DebugLoc PrevDL = DebugLoc::getUnknownLoc(); - DebugLoc CurDL = MI->getDebugLoc(); + const Function *F = MF->getFunction(); - if (!CurDL.isInvalid() && !CurDL.isUnknown() && PrevDL != CurDL) { - DebugLocTuple DLT = MF->getDebugLocTuple(CurDL); - printLabel(DW->RecordSourceLine(DLT.Line, DLT.Col, DLT.Src)); - } + // FIXME: Support more than '-Os'. + if (F->hasFnAttr(Attribute::OptimizeForSize)) { + static DebugLoc PrevDL = DebugLoc::getUnknownLoc(); + DebugLoc CurDL = MI->getDebugLoc(); + + if (!CurDL.isUnknown() && PrevDL != CurDL) { + DebugLocTuple DLT = MF->getDebugLocTuple(CurDL); + printLabel(DW->RecordSourceLine(DLT.Line, DLT.Col, DLT.Src)); + } - PrevDL = CurDL; + PrevDL = CurDL; + } } // Call the autogenerated instruction printer routines. From isanbard at gmail.com Mon Feb 16 19:06:30 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 01:06:30 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64717 - in /llvm-gcc-4.2/branches/Apple/Dib/gcc: config/darwin.h llvm-backend.cpp llvm-debug.cpp Message-ID: <200902170106.n1H16UM4028169@zion.cs.uiuc.edu> Author: void Date: Mon Feb 16 19:06:30 2009 New Revision: 64717 URL: http://llvm.org/viewvc/llvm-project?rev=64717&view=rev Log: Reapply r63639. This is ported over from TOT. Enable debug info at -O1+. However, for now, do not emit variable and line number info at -O1+. Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/config/darwin.h llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-backend.cpp llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/config/darwin.h URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/config/darwin.h?rev=64717&r1=64716&r2=64717&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/config/darwin.h (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/config/darwin.h Mon Feb 16 19:06:30 2009 @@ -340,7 +340,6 @@ specifying the handling of options understood by generic Unix linkers, and for positional arguments like libraries. */ /* APPLE LOCAL begin mainline */ -#ifdef ENABLE_LLVM #define LINK_COMMAND_SPEC "\ %{!fdump=*:%{!fsyntax-only:%{!precomp:%{!c:%{!M:%{!MM:%{!E:%{!S:\ %(linker) %l %X %{d} %{s} %{t} %{Z} %{u*} \ @@ -359,29 +358,7 @@ %{!fdump=*:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ "/* APPLE LOCAL end mainline 4.3 2006-10-31 4370146 */"\ %{.c|.cc|.C|.cpp|.cp|.c++|.cxx|.CPP|.m|.mm: \ - %{!O: %{!O1: %{!O2: %{!O3: %{!O4: %{!Os: \ -"/* LLVM LOCAL do not use dsymutil with -O1 or higher */"\ - %{g*:%{!gstabs*:%{!g0: dsymutil %{o*:%*}%{!o:a.out}}}}}}}}}}}}}}}}}}" -#else -#define LINK_COMMAND_SPEC "\ -%{!fdump=*:%{!fsyntax-only:%{!precomp:%{!c:%{!M:%{!MM:%{!E:%{!S:\ - %(linker) %l %X %{d} %{s} %{t} %{Z} %{u*} \ - %{A} %{e*} %{m} %{r} %{x} \ - %{o*}%{!o:-o a.out} \ - %{!A:%{!nostdlib:%{!nostartfiles:%S}}} \ - %{L*} %{fopenmp:%:include(libgomp.spec)%(link_gomp)} \ -"/* APPLE LOCAL add fcreate-profile */"\ - %(link_libgcc) %o %{fprofile-arcs|fprofile-generate|fcreate-profile|coverage:-lgcov} \ -"/* APPLE LOCAL nested functions 4357979 */"\ - %{fnested-functions: -allow_stack_execute} \ - %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %G %L}} \ -"/* APPLE LOCAL begin mainline 4.3 2006-10-31 4370146 */"\ - %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} %{F*} }}}}}}}}\n\ -%{!fdump=*:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ -"/* APPLE LOCAL end mainline 4.3 2006-10-31 4370146 */"\ - %{.c|.cc|.C|.cpp|.cp|.c++|.cxx|.CPP|.m|.mm: \ %{g*:%{!gstabs*:%{!g0: dsymutil %{o*:%*}%{!o:a.out}}}}}}}}}}}}" -#endif /* APPLE LOCAL end mainline */ #ifdef TARGET_SYSTEM_ROOT Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-backend.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-backend.cpp?rev=64717&r1=64716&r2=64717&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-backend.cpp (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-backend.cpp Mon Feb 16 19:06:30 2009 @@ -251,7 +251,7 @@ // FIXME - Do not disable debug info while writing pch. if (!flag_pch_file && - !optimize && debug_info_level > DINFO_LEVEL_NONE) + debug_info_level > DINFO_LEVEL_NONE) TheDebugInfo = new DebugInfo(TheModule); } @@ -288,8 +288,7 @@ delete MB; // FIXME - Do not disable debug info while writing pch. - if (!flag_pch_file && - !optimize && debug_info_level > DINFO_LEVEL_NONE) + if (!flag_pch_file && debug_info_level > DINFO_LEVEL_NONE) TheDebugInfo = new DebugInfo(TheModule); if (!TheModule) { Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp?rev=64717&r1=64716&r2=64717&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Mon Feb 16 19:06:30 2009 @@ -298,6 +298,10 @@ /// region - "llvm.dbg.declare." void DebugInfo::EmitDeclare(tree decl, unsigned Tag, const char *Name, tree type, Value *AI, BasicBlock *CurBB) { + // Do not emit variable declaration info, for now. + if (optimize) + return; + // Ignore compiler generated temporaries. if (DECL_IGNORED_P(decl)) return; @@ -319,6 +323,10 @@ /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of /// source line - "llvm.dbg.stoppoint." void DebugInfo::EmitStopPoint(Function *Fn, BasicBlock *CurBB) { + // Do not emit line number info, for now. + if (optimize) + return; + // Don't bother if things are the same as last time. if (PrevLineNo == CurLineNo && PrevBB == CurBB && From sabre at nondot.org Mon Feb 16 19:16:14 2009 From: sabre at nondot.org (Chris Lattner) Date: Tue, 17 Feb 2009 01:16:14 -0000 Subject: [llvm-commits] [llvm] r64719 - /llvm/trunk/lib/Target/X86/README.txt Message-ID: <200902170116.n1H1GEv9028550@zion.cs.uiuc.edu> Author: lattner Date: Mon Feb 16 19:16:14 2009 New Revision: 64719 URL: http://llvm.org/viewvc/llvm-project?rev=64719&view=rev Log: add a horrible note Modified: llvm/trunk/lib/Target/X86/README.txt Modified: llvm/trunk/lib/Target/X86/README.txt URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/README.txt?rev=64719&r1=64718&r2=64719&view=diff ============================================================================== --- llvm/trunk/lib/Target/X86/README.txt (original) +++ llvm/trunk/lib/Target/X86/README.txt Mon Feb 16 19:16:14 2009 @@ -1777,3 +1777,44 @@ it would be nice to produce "into" someday. //===---------------------------------------------------------------------===// + +This code: + +void vec_mpys1(int y[], const int x[], int scaler) { +int i; +for (i = 0; i < 150; i++) + y[i] += (((long long)scaler * (long long)x[i]) >> 31); +} + +Compiles to this loop with GCC 3.x: + +.L5: + movl %ebx, %eax + imull (%edi,%ecx,4) + shrdl $31, %edx, %eax + addl %eax, (%esi,%ecx,4) + incl %ecx + cmpl $149, %ecx + jle .L5 + +llvm-gcc compiles it to the much uglier: + +LBB1_1: ## bb1 + movl 24(%esp), %eax + movl (%eax,%edi,4), %ebx + movl %ebx, %ebp + imull %esi, %ebp + movl %ebx, %eax + mull %ecx + addl %ebp, %edx + sarl $31, %ebx + imull %ecx, %ebx + addl %edx, %ebx + shldl $1, %eax, %ebx + movl 20(%esp), %eax + addl %ebx, (%eax,%edi,4) + incl %edi + cmpl $150, %edi + jne LBB1_1 ## bb1 + +//===---------------------------------------------------------------------===// From isanbard at gmail.com Mon Feb 16 20:45:29 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 02:45:29 -0000 Subject: [llvm-commits] [llvm] r64726 - in /llvm/branches/Apple/Dib: include/llvm/Analysis/ScalarEvolution.h lib/Analysis/ScalarEvolution.cpp lib/Transforms/Scalar/IndVarSimplify.cpp test/Transforms/IndVarsSimplify/promote-iv-to-eliminate-casts.ll Message-ID: <200902170245.n1H2jUYJ032161@zion.cs.uiuc.edu> Author: void Date: Mon Feb 16 20:45:29 2009 New Revision: 64726 URL: http://llvm.org/viewvc/llvm-project?rev=64726&view=rev Log: Pull r64407 into Dib: Teach IndVarSimplify to optimize code using the C "int" type for loop induction on LP64 targets. When the induction variable is used in addressing, IndVars now is usually able to inserst a 64-bit induction variable and eliminates the sign-extending cast. This is also useful for code using C "short" types for induction variables on targets with 32-bit addressing. Inserting a wider induction variable is easy; the tricky part is determining when trunc(sext(i)) expressions are no-ops. This requires range analysis of the loop trip count. A common case is when the original loop iteration starts at 0 and exits when the induction variable is signed-less-than a fixed value; this case is now handled. This replaces IndVarSimplify's OptimizeCanonicalIVType. It was doing the same optimization, but it was limited to loops with constant trip counts, because it was running after the loop rewrite, and the information about the original induction variable is lost by that point. Rename ScalarEvolution's executesAtLeastOnce to isLoopGuardedByCond, generalize it to be able to test for ICMP_NE conditions, and move it to be a public function so that IndVars can use it. Added: llvm/branches/Apple/Dib/test/Transforms/IndVarsSimplify/promote-iv-to-eliminate-casts.ll Modified: llvm/branches/Apple/Dib/include/llvm/Analysis/ScalarEvolution.h llvm/branches/Apple/Dib/lib/Analysis/ScalarEvolution.cpp llvm/branches/Apple/Dib/lib/Transforms/Scalar/IndVarSimplify.cpp Modified: llvm/branches/Apple/Dib/include/llvm/Analysis/ScalarEvolution.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/Analysis/ScalarEvolution.h?rev=64726&r1=64725&r2=64726&view=diff ============================================================================== --- llvm/branches/Apple/Dib/include/llvm/Analysis/ScalarEvolution.h (original) +++ llvm/branches/Apple/Dib/include/llvm/Analysis/ScalarEvolution.h Mon Feb 16 20:45:29 2009 @@ -29,9 +29,7 @@ namespace llvm { class APInt; class ConstantInt; - class Instruction; class Type; - class ConstantRange; class SCEVHandle; class ScalarEvolution; @@ -282,6 +280,11 @@ /// object is returned. SCEVHandle getSCEVAtScope(Value *V, const Loop *L) const; + /// isLoopGuardedByCond - Test whether entry to the loop is protected by + /// a conditional between LHS and RHS. + bool isLoopGuardedByCond(const Loop *L, ICmpInst::Predicate Pred, + SCEV *LHS, SCEV *RHS); + /// getIterationCount - If the specified loop has a predictable iteration /// count, return it, otherwise return a SCEVCouldNotCompute object. SCEVHandle getIterationCount(const Loop *L) const; Modified: llvm/branches/Apple/Dib/lib/Analysis/ScalarEvolution.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Analysis/ScalarEvolution.cpp?rev=64726&r1=64725&r2=64726&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Analysis/ScalarEvolution.cpp (original) +++ llvm/branches/Apple/Dib/lib/Analysis/ScalarEvolution.cpp Mon Feb 16 20:45:29 2009 @@ -1414,6 +1414,11 @@ SCEVHandle getSCEVAtScope(SCEV *V, const Loop *L); + /// isLoopGuardedByCond - Test whether entry to the loop is protected by + /// a conditional between LHS and RHS. + bool isLoopGuardedByCond(const Loop *L, ICmpInst::Predicate Pred, + SCEV *LHS, SCEV *RHS); + /// hasLoopInvariantIterationCount - Return true if the specified loop has /// an analyzable loop-invariant iteration count. bool hasLoopInvariantIterationCount(const Loop *L); @@ -1486,10 +1491,6 @@ /// found. BasicBlock* getPredecessorWithUniqueSuccessorForBB(BasicBlock *BB); - /// executesAtLeastOnce - Test whether entry to the loop is protected by - /// a conditional between LHS and RHS. - bool executesAtLeastOnce(const Loop *L, bool isSigned, SCEV *LHS, SCEV *RHS); - /// getConstantEvolutionLoopExitValue - If we know that the specified Phi is /// in the header of its containing loop, we know the loop executes a /// constant number of times, and the PHI node is just a recurrence @@ -2736,9 +2737,10 @@ return 0; } -/// executesAtLeastOnce - Test whether entry to the loop is protected by +/// isLoopGuardedByCond - Test whether entry to the loop is protected by /// a conditional between LHS and RHS. -bool ScalarEvolutionsImpl::executesAtLeastOnce(const Loop *L, bool isSigned, +bool ScalarEvolutionsImpl::isLoopGuardedByCond(const Loop *L, + ICmpInst::Predicate Pred, SCEV *LHS, SCEV *RHS) { BasicBlock *Preheader = L->getLoopPreheader(); BasicBlock *PreheaderDest = L->getHeader(); @@ -2769,26 +2771,62 @@ else Cond = ICI->getInversePredicate(); - switch (Cond) { - case ICmpInst::ICMP_UGT: - if (isSigned) continue; - std::swap(PreCondLHS, PreCondRHS); - Cond = ICmpInst::ICMP_ULT; - break; - case ICmpInst::ICMP_SGT: - if (!isSigned) continue; - std::swap(PreCondLHS, PreCondRHS); - Cond = ICmpInst::ICMP_SLT; - break; - case ICmpInst::ICMP_ULT: - if (isSigned) continue; - break; - case ICmpInst::ICMP_SLT: - if (!isSigned) continue; - break; - default: - continue; - } + if (Cond == Pred) + ; // An exact match. + else if (!ICmpInst::isTrueWhenEqual(Cond) && Pred == ICmpInst::ICMP_NE) + ; // The actual condition is beyond sufficient. + else + // Check a few special cases. + switch (Cond) { + case ICmpInst::ICMP_UGT: + if (Pred == ICmpInst::ICMP_ULT) { + std::swap(PreCondLHS, PreCondRHS); + Cond = ICmpInst::ICMP_ULT; + break; + } + continue; + case ICmpInst::ICMP_SGT: + if (Pred == ICmpInst::ICMP_SLT) { + std::swap(PreCondLHS, PreCondRHS); + Cond = ICmpInst::ICMP_SLT; + break; + } + continue; + case ICmpInst::ICMP_NE: + // Expressions like (x >u 0) are often canonicalized to (x != 0), + // so check for this case by checking if the NE is comparing against + // a minimum or maximum constant. + if (!ICmpInst::isTrueWhenEqual(Pred)) + if (ConstantInt *CI = dyn_cast(PreCondRHS)) { + const APInt &A = CI->getValue(); + switch (Pred) { + case ICmpInst::ICMP_SLT: + if (A.isMaxSignedValue()) break; + continue; + case ICmpInst::ICMP_SGT: + if (A.isMinSignedValue()) break; + continue; + case ICmpInst::ICMP_ULT: + if (A.isMaxValue()) break; + continue; + case ICmpInst::ICMP_UGT: + if (A.isMinValue()) break; + continue; + default: + continue; + } + Cond = ICmpInst::ICMP_NE; + // NE is symmetric but the original comparison may not be. Swap + // the operands if necessary so that they match below. + if (isa(LHS)) + std::swap(PreCondLHS, PreCondRHS); + break; + } + continue; + default: + // We weren't able to reconcile the condition. + continue; + } if (!PreCondLHS->getType()->isInteger()) continue; @@ -2829,7 +2867,8 @@ // First, we get the value of the LHS in the first iteration: n SCEVHandle Start = AddRec->getOperand(0); - if (executesAtLeastOnce(L, isSigned, + if (isLoopGuardedByCond(L, + isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, SE.getMinusSCEV(AddRec->getOperand(0), One), RHS)) { // Since we know that the condition is true in order to enter the loop, // we know that it will run exactly m-n times. @@ -3007,6 +3046,13 @@ } +bool ScalarEvolution::isLoopGuardedByCond(const Loop *L, + ICmpInst::Predicate Pred, + SCEV *LHS, SCEV *RHS) { + return ((ScalarEvolutionsImpl*)Impl)->isLoopGuardedByCond(L, Pred, + LHS, RHS); +} + SCEVHandle ScalarEvolution::getIterationCount(const Loop *L) const { return ((ScalarEvolutionsImpl*)Impl)->getIterationCount(L); } Modified: llvm/branches/Apple/Dib/lib/Transforms/Scalar/IndVarSimplify.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=64726&r1=64725&r2=64726&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Transforms/Scalar/IndVarSimplify.cpp (original) +++ llvm/branches/Apple/Dib/lib/Transforms/Scalar/IndVarSimplify.cpp Mon Feb 16 20:45:29 2009 @@ -53,6 +53,7 @@ #include "llvm/Transforms/Utils/Local.h" #include "llvm/Support/CommandLine.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/Statistic.h" using namespace llvm; @@ -89,13 +90,14 @@ void EliminatePointerRecurrence(PHINode *PN, BasicBlock *Preheader, SmallPtrSet &DeadInsts); - Instruction *LinearFunctionTestReplace(Loop *L, SCEV *IterationCount, - SCEVExpander &RW); + void LinearFunctionTestReplace(Loop *L, SCEVHandle IterationCount, Value *IndVar, + BasicBlock *ExitingBlock, + BranchInst *BI, + SCEVExpander &Rewriter); void RewriteLoopExitValues(Loop *L, SCEV *IterationCount); void DeleteTriviallyDeadInstructions(SmallPtrSet &Insts); - void OptimizeCanonicalIVType(Loop *L); void HandleFloatingPointIV(Loop *L, PHINode *PH, SmallPtrSet &DeadInsts); }; @@ -225,68 +227,54 @@ /// variable. This pass is able to rewrite the exit tests of any loop where the /// SCEV analysis can determine a loop-invariant trip count of the loop, which /// is actually a much broader range than just linear tests. -/// -/// This method returns a "potentially dead" instruction whose computation chain -/// should be deleted when convenient. -Instruction *IndVarSimplify::LinearFunctionTestReplace(Loop *L, - SCEV *IterationCount, - SCEVExpander &RW) { - // Find the exit block for the loop. We can currently only handle loops with - // a single exit. - SmallVector ExitBlocks; - L->getExitBlocks(ExitBlocks); - if (ExitBlocks.size() != 1) return 0; - BasicBlock *ExitBlock = ExitBlocks[0]; - - // Make sure there is only one predecessor block in the loop. - BasicBlock *ExitingBlock = 0; - for (pred_iterator PI = pred_begin(ExitBlock), PE = pred_end(ExitBlock); - PI != PE; ++PI) - if (L->contains(*PI)) { - if (ExitingBlock == 0) - ExitingBlock = *PI; - else - return 0; // Multiple exits from loop to this block. - } - assert(ExitingBlock && "Loop info is broken"); - - if (!isa(ExitingBlock->getTerminator())) - return 0; // Can't rewrite non-branch yet - BranchInst *BI = cast(ExitingBlock->getTerminator()); - assert(BI->isConditional() && "Must be conditional to be part of loop!"); - - Instruction *PotentiallyDeadInst = dyn_cast(BI->getCondition()); - +void IndVarSimplify::LinearFunctionTestReplace(Loop *L, + SCEVHandle IterationCount, + Value *IndVar, + BasicBlock *ExitingBlock, + BranchInst *BI, + SCEVExpander &Rewriter) { // If the exiting block is not the same as the backedge block, we must compare // against the preincremented value, otherwise we prefer to compare against // the post-incremented value. - BasicBlock *Header = L->getHeader(); - pred_iterator HPI = pred_begin(Header); - assert(HPI != pred_end(Header) && "Loop with zero preds???"); - if (!L->contains(*HPI)) ++HPI; - assert(HPI != pred_end(Header) && L->contains(*HPI) && - "No backedge in loop?"); - - SCEVHandle TripCount = IterationCount; - Value *IndVar; - if (*HPI == ExitingBlock) { + Value *CmpIndVar; + if (ExitingBlock == L->getLoopLatch()) { + // What ScalarEvolution calls the "iteration count" is actually the + // number of times the branch is taken. Add one to get the number + // of times the branch is executed. If this addition may overflow, + // we have to be more pessimistic and cast the induction variable + // before doing the add. + SCEVHandle Zero = SE->getIntegerSCEV(0, IterationCount->getType()); + SCEVHandle N = + SE->getAddExpr(IterationCount, + SE->getIntegerSCEV(1, IterationCount->getType())); + if ((isa(N) && !N->isZero()) || + SE->isLoopGuardedByCond(L, ICmpInst::ICMP_NE, N, Zero)) { + // No overflow. Cast the sum. + IterationCount = SE->getTruncateOrZeroExtend(N, IndVar->getType()); + } else { + // Potential overflow. Cast before doing the add. + IterationCount = SE->getTruncateOrZeroExtend(IterationCount, + IndVar->getType()); + IterationCount = + SE->getAddExpr(IterationCount, + SE->getIntegerSCEV(1, IndVar->getType())); + } + // The IterationCount expression contains the number of times that the // backedge actually branches to the loop header. This is one less than the // number of times the loop executes, so add one to it. - ConstantInt *OneC = ConstantInt::get(IterationCount->getType(), 1); - TripCount = SE->getAddExpr(IterationCount, SE->getConstant(OneC)); - IndVar = L->getCanonicalInductionVariableIncrement(); + CmpIndVar = L->getCanonicalInductionVariableIncrement(); } else { // We have to use the preincremented value... - IndVar = L->getCanonicalInductionVariable(); + IterationCount = SE->getTruncateOrZeroExtend(IterationCount, + IndVar->getType()); + CmpIndVar = IndVar; } - - DOUT << "INDVARS: LFTR: TripCount = " << *TripCount - << " IndVar = " << *IndVar << "\n"; // Expand the code for the iteration count into the preheader of the loop. BasicBlock *Preheader = L->getLoopPreheader(); - Value *ExitCnt = RW.expandCodeFor(TripCount, Preheader->getTerminator()); + Value *ExitCnt = Rewriter.expandCodeFor(IterationCount, + Preheader->getTerminator()); // Insert a new icmp_ne or icmp_eq instruction before the branch. ICmpInst::Predicate Opcode; @@ -295,14 +283,18 @@ else Opcode = ICmpInst::ICMP_EQ; - Value *Cond = new ICmpInst(Opcode, IndVar, ExitCnt, "exitcond", BI); + DOUT << "INDVARS: Rewriting loop exit condition to:\n" + << " LHS:" << *CmpIndVar // includes a newline + << " op:\t" + << (Opcode == ICmpInst::ICMP_NE ? "!=" : "=") << "\n" + << " RHS:\t" << *IterationCount << "\n"; + + Value *Cond = new ICmpInst(Opcode, CmpIndVar, ExitCnt, "exitcond", BI); BI->setCondition(Cond); ++NumLFTR; Changed = true; - return PotentiallyDeadInst; } - /// RewriteLoopExitValues - Check to see if this loop has a computable /// loop-invariant execution count. If so, this means that we can compute the /// final value of any expressions that are recurrent in the loop, and @@ -444,15 +436,100 @@ return Changed; } -bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { +/// getEffectiveIndvarType - Determine the widest type that the +/// induction-variable PHINode Phi is cast to. +/// +static const Type *getEffectiveIndvarType(const PHINode *Phi) { + const Type *Ty = Phi->getType(); + + for (Value::use_const_iterator UI = Phi->use_begin(), UE = Phi->use_end(); + UI != UE; ++UI) { + const Type *CandidateType = NULL; + if (const ZExtInst *ZI = dyn_cast(UI)) + CandidateType = ZI->getDestTy(); + else if (const SExtInst *SI = dyn_cast(UI)) + CandidateType = SI->getDestTy(); + if (CandidateType && + CandidateType->getPrimitiveSizeInBits() > + Ty->getPrimitiveSizeInBits()) + Ty = CandidateType; + } + return Ty; +} + +/// isOrigIVAlwaysNonNegative - Analyze the original induction variable +/// in the loop to determine whether it would ever have a negative +/// value. +/// +/// TODO: This duplicates a fair amount of ScalarEvolution logic. +/// Perhaps this can be merged with ScalarEvolution::getIterationCount. +/// +static bool isOrigIVAlwaysNonNegative(const Loop *L, + const Instruction *OrigCond) { + // Verify that the loop is sane and find the exit condition. + const ICmpInst *Cmp = dyn_cast(OrigCond); + if (!Cmp) return false; + + // For now, analyze only SLT loops for signed overflow. + if (Cmp->getPredicate() != ICmpInst::ICMP_SLT) return false; + + // Get the increment instruction. Look past SExtInsts if we will + // be able to prove that the original induction variable doesn't + // undergo signed overflow. + const Value *OrigIncrVal = Cmp->getOperand(0); + const Value *IncrVal = OrigIncrVal; + if (SExtInst *SI = dyn_cast(Cmp->getOperand(0))) { + if (!isa(Cmp->getOperand(1)) || + !cast(Cmp->getOperand(1))->getValue() + .isSignedIntN(IncrVal->getType()->getPrimitiveSizeInBits())) + return false; + IncrVal = SI->getOperand(0); + } + + // For now, only analyze induction variables that have simple increments. + const BinaryOperator *IncrOp = dyn_cast(IncrVal); + if (!IncrOp || + IncrOp->getOpcode() != Instruction::Add || + !isa(IncrOp->getOperand(1)) || + !cast(IncrOp->getOperand(1))->equalsInt(1)) + return false; + + // Make sure the PHI looks like a normal IV. + const PHINode *PN = dyn_cast(IncrOp->getOperand(0)); + if (!PN || PN->getNumIncomingValues() != 2) + return false; + unsigned IncomingEdge = L->contains(PN->getIncomingBlock(0)); + unsigned BackEdge = !IncomingEdge; + if (!L->contains(PN->getIncomingBlock(BackEdge)) || + PN->getIncomingValue(BackEdge) != IncrOp) + return false; + + // For now, only analyze loops with a constant start value, so that + // we can easily determine if the start value is non-negative and + // not a maximum value which would wrap on the first iteration. + const Value *InitialVal = PN->getIncomingValue(IncomingEdge); + if (!isa(InitialVal) || + cast(InitialVal)->getValue().isNegative() || + cast(InitialVal)->getValue().isMaxSignedValue()) + return false; + + // The original induction variable will start at some non-negative + // non-max value, it counts up by one, and the loop iterates only + // while it remans less than (signed) some value in the same type. + // As such, it will always be non-negative. + return true; +} + +bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { LI = &getAnalysis(); SE = &getAnalysis(); Changed = false; - BasicBlock *Header = L->getHeader(); + BasicBlock *Header = L->getHeader(); + BasicBlock *ExitingBlock = L->getExitingBlock(); SmallPtrSet DeadInsts; - + // Verify the input to the pass in already in LCSSA form. assert(L->isLCSSAForm()); @@ -486,35 +563,23 @@ } } - // If there are no induction variables in the loop, there is nothing more to - // do. - if (IndVars.empty()) { - // Actually, if we know how many times the loop iterates, lets insert a - // canonical induction variable to help subsequent passes. - if (!isa(IterationCount)) { - SCEVExpander Rewriter(*SE, *LI); - Rewriter.getOrInsertCanonicalInductionVariable(L, - IterationCount->getType()); - if (Instruction *I = LinearFunctionTestReplace(L, IterationCount, - Rewriter)) { - SmallPtrSet InstructionsToDelete; - InstructionsToDelete.insert(I); - DeleteTriviallyDeadInstructions(InstructionsToDelete); - } - } - return Changed; + // Compute the type of the largest recurrence expression, and collect + // the set of the types of the other recurrence expressions. + const Type *LargestType = 0; + SmallSetVector SizesToInsert; + if (!isa(IterationCount)) { + LargestType = IterationCount->getType(); + SizesToInsert.insert(IterationCount->getType()); } - - // Compute the type of the largest recurrence expression. - // - const Type *LargestType = IndVars[0].first->getType(); - bool DifferingSizes = false; - for (unsigned i = 1, e = IndVars.size(); i != e; ++i) { - const Type *Ty = IndVars[i].first->getType(); - DifferingSizes |= - Ty->getPrimitiveSizeInBits() != LargestType->getPrimitiveSizeInBits(); - if (Ty->getPrimitiveSizeInBits() > LargestType->getPrimitiveSizeInBits()) - LargestType = Ty; + for (unsigned i = 0, e = IndVars.size(); i != e; ++i) { + const PHINode *PN = IndVars[i].first; + SizesToInsert.insert(PN->getType()); + const Type *EffTy = getEffectiveIndvarType(PN); + SizesToInsert.insert(EffTy); + if (!LargestType || + EffTy->getPrimitiveSizeInBits() > + LargestType->getPrimitiveSizeInBits()) + LargestType = EffTy; } // Create a rewriter object which we'll use to transform the code with. @@ -522,17 +587,32 @@ // Now that we know the largest of of the induction variables in this loop, // insert a canonical induction variable of the largest size. - Value *IndVar = Rewriter.getOrInsertCanonicalInductionVariable(L,LargestType); - ++NumInserted; - Changed = true; - DOUT << "INDVARS: New CanIV: " << *IndVar; - - if (!isa(IterationCount)) { - IterationCount = SE->getTruncateOrZeroExtend(IterationCount, LargestType); - if (Instruction *DI = LinearFunctionTestReplace(L, IterationCount,Rewriter)) - DeadInsts.insert(DI); + Value *IndVar = 0; + if (!SizesToInsert.empty()) { + IndVar = Rewriter.getOrInsertCanonicalInductionVariable(L,LargestType); + ++NumInserted; + Changed = true; + DOUT << "INDVARS: New CanIV: " << *IndVar; } + // If we have a trip count expression, rewrite the loop's exit condition + // using it. We can currently only handle loops with a single exit. + bool OrigIVAlwaysNonNegative = false; + if (!isa(IterationCount) && ExitingBlock) + // Can't rewrite non-branch yet. + if (BranchInst *BI = dyn_cast(ExitingBlock->getTerminator())) { + if (Instruction *OrigCond = dyn_cast(BI->getCondition())) { + // Determine if the OrigIV will ever have a non-zero sign bit. + OrigIVAlwaysNonNegative = isOrigIVAlwaysNonNegative(L, OrigCond); + + // We'll be replacing the original condition, so it'll be dead. + DeadInsts.insert(OrigCond); + } + + LinearFunctionTestReplace(L, IterationCount, IndVar, + ExitingBlock, BI, Rewriter); + } + // Now that we have a canonical induction variable, we can rewrite any // recurrences in terms of the induction variable. Start with the auxillary // induction variables, and recursively rewrite any of their uses. @@ -541,21 +621,13 @@ // If there were induction variables of other sizes, cast the primary // induction variable to the right size for them, avoiding the need for the // code evaluation methods to insert induction variables of different sizes. - if (DifferingSizes) { - SmallVector InsertedSizes; - InsertedSizes.push_back(LargestType->getPrimitiveSizeInBits()); - for (unsigned i = 0, e = IndVars.size(); i != e; ++i) { - unsigned ithSize = IndVars[i].first->getType()->getPrimitiveSizeInBits(); - if (std::find(InsertedSizes.begin(), InsertedSizes.end(), ithSize) - == InsertedSizes.end()) { - PHINode *PN = IndVars[i].first; - InsertedSizes.push_back(ithSize); - Instruction *New = new TruncInst(IndVar, PN->getType(), "indvar", - InsertPt); - Rewriter.addInsertedValue(New, SE->getSCEV(New)); - DOUT << "INDVARS: Made trunc IV for " << *PN - << " NewVal = " << *New << "\n"; - } + for (unsigned i = 0, e = SizesToInsert.size(); i != e; ++i) { + const Type *Ty = SizesToInsert[i]; + if (Ty != LargestType) { + Instruction *New = new TruncInst(IndVar, Ty, "indvar", InsertPt); + Rewriter.addInsertedValue(New, SE->getSCEV(New)); + DOUT << "INDVARS: Made trunc IV for type " << *Ty << ": " + << *New << "\n"; } } @@ -568,6 +640,23 @@ << " into = " << *NewVal << "\n"; NewVal->takeName(PN); + /// If the new canonical induction variable is wider than the original, + /// and the original has uses that are casts to wider types, see if the + /// truncate and extend can be omitted. + if (isa(NewVal)) + for (Value::use_iterator UI = PN->use_begin(), UE = PN->use_end(); + UI != UE; ++UI) + if (isa(UI) || + (isa(UI) && OrigIVAlwaysNonNegative)) { + Value *TruncIndVar = IndVar; + if (TruncIndVar->getType() != UI->getType()) + TruncIndVar = new TruncInst(IndVar, UI->getType(), "truncindvar", + InsertPt); + UI->replaceAllUsesWith(TruncIndVar); + if (Instruction *DeadUse = dyn_cast(*UI)) + DeadInsts.insert(DeadUse); + } + // Replace the old PHI Node with the inserted computation. PN->replaceAllUsesWith(NewVal); DeadInsts.insert(PN); @@ -603,125 +692,10 @@ #endif DeleteTriviallyDeadInstructions(DeadInsts); - OptimizeCanonicalIVType(L); assert(L->isLCSSAForm()); return Changed; } -/// OptimizeCanonicalIVType - If loop induction variable is always -/// sign or zero extended then extend the type of the induction -/// variable. -void IndVarSimplify::OptimizeCanonicalIVType(Loop *L) { - PHINode *PH = L->getCanonicalInductionVariable(); - if (!PH) return; - - // Check loop iteration count. - SCEVHandle IC = SE->getIterationCount(L); - if (isa(IC)) return; - SCEVConstant *IterationCount = dyn_cast(IC); - if (!IterationCount) return; - - unsigned IncomingEdge = L->contains(PH->getIncomingBlock(0)); - unsigned BackEdge = IncomingEdge^1; - - // Check IV uses. If all IV uses are either SEXT or ZEXT (except - // IV increment instruction) then this IV is suitable for this - // transformation. - bool isSEXT = false; - BinaryOperator *Incr = NULL; - const Type *NewType = NULL; - for(Value::use_iterator UI = PH->use_begin(), UE = PH->use_end(); - UI != UE; ++UI) { - const Type *CandidateType = NULL; - if (ZExtInst *ZI = dyn_cast(UI)) - CandidateType = ZI->getDestTy(); - else if (SExtInst *SI = dyn_cast(UI)) { - CandidateType = SI->getDestTy(); - isSEXT = true; - } - else if ((Incr = dyn_cast(UI))) { - // Validate IV increment instruction. - if (PH->getIncomingValue(BackEdge) == Incr) - continue; - } - if (!CandidateType) { - NewType = NULL; - break; - } - if (!NewType) - NewType = CandidateType; - else if (NewType != CandidateType) { - NewType = NULL; - break; - } - } - - // IV uses are not suitable then avoid this transformation. - if (!NewType || !Incr) - return; - - // IV increment instruction has two uses, one is loop exit condition - // and second is the IV (phi node) itself. - ICmpInst *Exit = NULL; - for(Value::use_iterator II = Incr->use_begin(), IE = Incr->use_end(); - II != IE; ++II) { - if (PH == *II) continue; - Exit = dyn_cast(*II); - break; - } - if (!Exit) return; - ConstantInt *EV = dyn_cast(Exit->getOperand(0)); - if (!EV) - EV = dyn_cast(Exit->getOperand(1)); - if (!EV) return; - - // Check iteration count max value to avoid loops that wrap around IV. - APInt ICount = IterationCount->getValue()->getValue(); - if (ICount.isNegative()) return; - uint32_t BW = PH->getType()->getPrimitiveSizeInBits(); - APInt Max = (isSEXT ? APInt::getSignedMaxValue(BW) : APInt::getMaxValue(BW)); - if (ICount.getZExtValue() > Max.getZExtValue()) return; - - // Extend IV type. - - SCEVExpander Rewriter(*SE, *LI); - Value *NewIV = Rewriter.getOrInsertCanonicalInductionVariable(L,NewType); - PHINode *NewPH = cast(NewIV); - Instruction *NewIncr = cast(NewPH->getIncomingValue(BackEdge)); - - // Replace all SEXT or ZEXT uses. - SmallVector PHUses; - for(Value::use_iterator UI = PH->use_begin(), UE = PH->use_end(); - UI != UE; ++UI) { - Instruction *I = cast(UI); - PHUses.push_back(I); - } - while (!PHUses.empty()){ - Instruction *Use = PHUses.back(); PHUses.pop_back(); - if (Incr == Use) continue; - - SE->deleteValueFromRecords(Use); - Use->replaceAllUsesWith(NewIV); - Use->eraseFromParent(); - } - - // Replace exit condition. - ConstantInt *NEV = ConstantInt::get(NewType, EV->getZExtValue()); - Instruction *NE = new ICmpInst(Exit->getPredicate(), - NewIncr, NEV, "new.exit", - Exit->getParent()->getTerminator()); - SE->deleteValueFromRecords(Exit); - Exit->replaceAllUsesWith(NE); - Exit->eraseFromParent(); - - // Remove old IV and increment instructions. - SE->deleteValueFromRecords(PH); - PH->removeIncomingValue((unsigned)0); - PH->removeIncomingValue((unsigned)0); - SE->deleteValueFromRecords(Incr); - Incr->eraseFromParent(); -} - /// Return true if it is OK to use SIToFPInst for an inducation variable /// with given inital and exit values. static bool useSIToFPInst(ConstantFP &InitV, ConstantFP &ExitV, Added: llvm/branches/Apple/Dib/test/Transforms/IndVarsSimplify/promote-iv-to-eliminate-casts.ll URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/Transforms/IndVarsSimplify/promote-iv-to-eliminate-casts.ll?rev=64726&view=auto ============================================================================== --- llvm/branches/Apple/Dib/test/Transforms/IndVarsSimplify/promote-iv-to-eliminate-casts.ll (added) +++ llvm/branches/Apple/Dib/test/Transforms/IndVarsSimplify/promote-iv-to-eliminate-casts.ll Mon Feb 16 20:45:29 2009 @@ -0,0 +1,62 @@ +; RUN: llvm-as < %s | opt -indvars | llvm-dis | not grep sext + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128" + +define i64 @test(i64* nocapture %first, i32 %count) nounwind readonly { +entry: + %t0 = icmp sgt i32 %count, 0 ; [#uses=1] + br i1 %t0, label %bb.nph, label %bb2 + +bb.nph: ; preds = %entry + br label %bb + +bb: ; preds = %bb1, %bb.nph + %result.02 = phi i64 [ %t5, %bb1 ], [ 0, %bb.nph ] ; [#uses=1] + %n.01 = phi i32 [ %t6, %bb1 ], [ 0, %bb.nph ] ; [#uses=2] + %t1 = sext i32 %n.01 to i64 ; [#uses=1] + %t2 = getelementptr i64* %first, i64 %t1 ; [#uses=1] + %t3 = load i64* %t2, align 8 ; [#uses=1] + %t4 = lshr i64 %t3, 4 ; [#uses=1] + %t5 = add i64 %t4, %result.02 ; [#uses=2] + %t6 = add i32 %n.01, 1 ; [#uses=2] + br label %bb1 + +bb1: ; preds = %bb + %t7 = icmp slt i32 %t6, %count ; [#uses=1] + br i1 %t7, label %bb, label %bb1.bb2_crit_edge + +bb1.bb2_crit_edge: ; preds = %bb1 + %.lcssa = phi i64 [ %t5, %bb1 ] ; [#uses=1] + br label %bb2 + +bb2: ; preds = %bb1.bb2_crit_edge, %entry + %result.0.lcssa = phi i64 [ %.lcssa, %bb1.bb2_crit_edge ], [ 0, %entry ] ; [#uses=1] + ret i64 %result.0.lcssa +} + +define void @foo(i16 signext %N, i32* nocapture %P) nounwind { +entry: + %t0 = icmp sgt i16 %N, 0 ; [#uses=1] + br i1 %t0, label %bb.nph, label %return + +bb.nph: ; preds = %entry + br label %bb + +bb: ; preds = %bb1, %bb.nph + %i.01 = phi i16 [ %t3, %bb1 ], [ 0, %bb.nph ] ; [#uses=2] + %t1 = sext i16 %i.01 to i64 ; [#uses=1] + %t2 = getelementptr i32* %P, i64 %t1 ; [#uses=1] + store i32 123, i32* %t2, align 4 + %t3 = add i16 %i.01, 1 ; [#uses=2] + br label %bb1 + +bb1: ; preds = %bb + %t4 = icmp slt i16 %t3, %N ; [#uses=1] + br i1 %t4, label %bb, label %bb1.return_crit_edge + +bb1.return_crit_edge: ; preds = %bb1 + br label %return + +return: ; preds = %bb1.return_crit_edge, %entry + ret void +} From isanbard at gmail.com Mon Feb 16 20:48:18 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 02:48:18 -0000 Subject: [llvm-commits] [llvm] r64728 - in /llvm/branches/Apple/Dib: lib/Transforms/Scalar/LoopStrengthReduce.cpp test/CodeGen/X86/lsr-sort.ll Message-ID: <200902170248.n1H2mI86032278@zion.cs.uiuc.edu> Author: void Date: Mon Feb 16 20:48:18 2009 New Revision: 64728 URL: http://llvm.org/viewvc/llvm-project?rev=64728&view=rev Log: Pull r64415 into Dib: Fix LSR's IV sorting function to explicitly sort by bitwidth after sorting by stride value. This prevents it from missing IV reuse opportunities in a host-sensitive manner. Added: llvm/branches/Apple/Dib/test/CodeGen/X86/lsr-sort.ll Modified: llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopStrengthReduce.cpp Modified: llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopStrengthReduce.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=64728&r1=64727&r2=64728&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original) +++ llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopStrengthReduce.cpp Mon Feb 16 20:48:18 2009 @@ -1772,12 +1772,19 @@ int64_t RV = RHSC->getValue()->getSExtValue(); uint64_t ALV = (LV < 0) ? -LV : LV; uint64_t ARV = (RV < 0) ? -RV : RV; - if (ALV == ARV) - return LV > RV; - else + if (ALV == ARV) { + if (LV != RV) + return LV > RV; + } else { return ALV < ARV; + } + + // If it's the same value but different type, sort by bit width so + // that we emit larger induction variables before smaller + // ones, letting the smaller be re-written in terms of larger ones. + return RHS->getBitWidth() < LHS->getBitWidth(); } - return (LHSC && !RHSC); + return LHSC && !RHSC; } }; } Added: llvm/branches/Apple/Dib/test/CodeGen/X86/lsr-sort.ll URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/CodeGen/X86/lsr-sort.ll?rev=64728&view=auto ============================================================================== --- llvm/branches/Apple/Dib/test/CodeGen/X86/lsr-sort.ll (added) +++ llvm/branches/Apple/Dib/test/CodeGen/X86/lsr-sort.ll Mon Feb 16 20:48:18 2009 @@ -0,0 +1,22 @@ +; RUN: llvm-as < %s | llc -march=x86-64 > %t +; RUN: grep inc %t | count 1 +; RUN: not grep incw %t + + at X = common global i16 0 ; [#uses=1] + +define void @foo(i32 %N) nounwind { +entry: + %0 = icmp sgt i32 %N, 0 ; [#uses=1] + br i1 %0, label %bb, label %return + +bb: ; preds = %bb, %entry + %i.03 = phi i32 [ 0, %entry ], [ %indvar.next, %bb ] ; [#uses=2] + %1 = trunc i32 %i.03 to i16 ; [#uses=1] + volatile store i16 %1, i16* @X, align 2 + %indvar.next = add i32 %i.03, 1 ; [#uses=2] + %exitcond = icmp eq i32 %indvar.next, %N ; [#uses=1] + br i1 %exitcond, label %return, label %bb + +return: ; preds = %bb, %entry + ret void +} From isanbard at gmail.com Mon Feb 16 20:49:49 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 02:49:49 -0000 Subject: [llvm-commits] [llvm] r64729 - /llvm/branches/Apple/Dib/lib/Support/MemoryBuffer.cpp Message-ID: <200902170249.n1H2nn6f032339@zion.cs.uiuc.edu> Author: void Date: Mon Feb 16 20:49:49 2009 New Revision: 64729 URL: http://llvm.org/viewvc/llvm-project?rev=64729&view=rev Log: Pulled r64444 and r64448 into Dib: Switch from new[] + delete[] to malloc + free since llvm does not catch C++ exceptions. Modified: llvm/branches/Apple/Dib/lib/Support/MemoryBuffer.cpp Modified: llvm/branches/Apple/Dib/lib/Support/MemoryBuffer.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Support/MemoryBuffer.cpp?rev=64729&r1=64728&r2=64729&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Support/MemoryBuffer.cpp (original) +++ llvm/branches/Apple/Dib/lib/Support/MemoryBuffer.cpp Mon Feb 16 20:49:49 2009 @@ -38,7 +38,7 @@ MemoryBuffer::~MemoryBuffer() { if (MustDeleteBuffer) - delete [] BufferStart; + free((void*)BufferStart); } /// initCopyOf - Initialize this source buffer with a copy of the specified @@ -46,7 +46,7 @@ /// successfully. void MemoryBuffer::initCopyOf(const char *BufStart, const char *BufEnd) { size_t Size = BufEnd-BufStart; - BufferStart = new char[Size+1]; + BufferStart = (char *)malloc((Size+1) * sizeof(char)); BufferEnd = BufferStart+Size; memcpy(const_cast(BufferStart), BufStart, Size); *const_cast(BufferEnd) = 0; // Null terminate buffer. @@ -108,7 +108,8 @@ /// the MemoryBuffer object. MemoryBuffer *MemoryBuffer::getNewUninitMemBuffer(size_t Size, const char *BufferName) { - char *Buf = new char[Size+1]; + char *Buf = (char *)malloc((Size+1) * sizeof(char)); + if (!Buf) return 0; Buf[Size] = 0; MemoryBufferMem *SB = new MemoryBufferMem(Buf, Buf+Size, BufferName); // The memory for this buffer is owned by the MemoryBuffer. @@ -123,6 +124,7 @@ MemoryBuffer *MemoryBuffer::getNewMemBuffer(size_t Size, const char *BufferName) { MemoryBuffer *SB = getNewUninitMemBuffer(Size, BufferName); + if (!SB) return 0; memset(const_cast(SB->getBufferStart()), 0, Size+1); return SB; } @@ -209,9 +211,16 @@ return new MemoryBufferMMapFile(Filename, Pages, FileSize); } } - - OwningPtr SB; - SB.reset(MemoryBuffer::getNewUninitMemBuffer(FileSize, Filename)); + + MemoryBuffer *Buf = MemoryBuffer::getNewUninitMemBuffer(FileSize, Filename); + if (!Buf) { + // Failed to create a buffer. + if (ErrStr) *ErrStr = "could not allocate buffer"; + ::close(FD); + return 0; + } + + OwningPtr SB(Buf); char *BufPtr = const_cast(SB->getBufferStart()); size_t BytesLeft = FileSize; From isanbard at gmail.com Mon Feb 16 20:51:41 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 02:51:41 -0000 Subject: [llvm-commits] [llvm] r64730 - in /llvm/branches/Apple/Dib: lib/CodeGen/SelectionDAG/TargetLowering.cpp lib/Target/X86/X86ISelLowering.cpp test/CodeGen/X86/2009-02-12-InlineAsm-nieZ-constraints.ll Message-ID: <200902170251.n1H2pfA4032421@zion.cs.uiuc.edu> Author: void Date: Mon Feb 16 20:51:41 2009 New Revision: 64730 URL: http://llvm.org/viewvc/llvm-project?rev=64730&view=rev Log: Pull r64400 into Dib: Arrange to print constants that match "n" and "i" constraints in inline asm as signed (what gcc does). Add partial support for x86-specific "e" and "Z" constraints, with appropriate signedness for printing. Added: llvm/branches/Apple/Dib/test/CodeGen/X86/2009-02-12-InlineAsm-nieZ-constraints.ll Modified: llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/TargetLowering.cpp llvm/branches/Apple/Dib/lib/Target/X86/X86ISelLowering.cpp Modified: llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/TargetLowering.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/TargetLowering.cpp?rev=64730&r1=64729&r2=64730&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/TargetLowering.cpp (original) +++ llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/TargetLowering.cpp Mon Feb 16 20:51:41 2009 @@ -2082,8 +2082,11 @@ if (C) { // just C, no GV. // Simple constants are not allowed for 's'. if (ConstraintLetter != 's') { - Ops.push_back(DAG.getTargetConstant(C->getAPIntValue(), - Op.getValueType())); + // gcc prints these as sign extended. Sign extend value to 64 bits + // now; without this it would get ZExt'd later in + // ScheduleDAGSDNodes::EmitNode, which is very generic. + Ops.push_back(DAG.getTargetConstant(C->getAPIntValue().getSExtValue(), + MVT::i64)); return; } } Modified: llvm/branches/Apple/Dib/lib/Target/X86/X86ISelLowering.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Target/X86/X86ISelLowering.cpp?rev=64730&r1=64729&r2=64730&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Target/X86/X86ISelLowering.cpp (original) +++ llvm/branches/Apple/Dib/lib/Target/X86/X86ISelLowering.cpp Mon Feb 16 20:51:41 2009 @@ -8151,6 +8151,9 @@ case 'y': case 'Y': return C_RegisterClass; + case 'e': + case 'Z': + return C_Other; default: break; } @@ -8210,10 +8213,38 @@ } } return; + case 'e': { + // 32-bit signed value + if (ConstantSDNode *C = dyn_cast(Op)) { + const ConstantInt *CI = C->getConstantIntValue(); + if (CI->isValueValidForType(Type::Int32Ty, C->getSExtValue())) { + // Widen to 64 bits here to get it sign extended. + Result = DAG.getTargetConstant(C->getSExtValue(), MVT::i64); + break; + } + // FIXME gcc accepts some relocatable values here too, but only in certain + // memory models; it's complicated. + } + return; + } + case 'Z': { + // 32-bit unsigned value + if (ConstantSDNode *C = dyn_cast(Op)) { + const ConstantInt *CI = C->getConstantIntValue(); + if (CI->isValueValidForType(Type::Int32Ty, C->getZExtValue())) { + Result = DAG.getTargetConstant(C->getZExtValue(), Op.getValueType()); + break; + } + } + // FIXME gcc accepts some relocatable values here too, but only in certain + // memory models; it's complicated. + return; + } case 'i': { // Literal immediates are always ok. if (ConstantSDNode *CST = dyn_cast(Op)) { - Result = DAG.getTargetConstant(CST->getZExtValue(), Op.getValueType()); + // Widen to 64 bits here to get it sign extended. + Result = DAG.getTargetConstant(CST->getSExtValue(), MVT::i64); break; } Added: llvm/branches/Apple/Dib/test/CodeGen/X86/2009-02-12-InlineAsm-nieZ-constraints.ll URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/CodeGen/X86/2009-02-12-InlineAsm-nieZ-constraints.ll?rev=64730&view=auto ============================================================================== --- llvm/branches/Apple/Dib/test/CodeGen/X86/2009-02-12-InlineAsm-nieZ-constraints.ll (added) +++ llvm/branches/Apple/Dib/test/CodeGen/X86/2009-02-12-InlineAsm-nieZ-constraints.ll Mon Feb 16 20:51:41 2009 @@ -0,0 +1,18 @@ +; RUN: llvm-as < %s | llc -march=x86 | grep {\$-81920} | count 3 +; RUN: llvm-as < %s | llc -march=x86 | grep {\$4294885376} | count 1 + +; ModuleID = 'shant.c' +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" +target triple = "i386-apple-darwin9.6" + +define void @f() nounwind { +entry: + call void asm sideeffect "foo $0", "n,~{dirflag},~{fpsr},~{flags}"(i32 -81920) nounwind + call void asm sideeffect "foo $0", "i,~{dirflag},~{fpsr},~{flags}"(i32 -81920) nounwind + call void asm sideeffect "foo $0", "e,~{dirflag},~{fpsr},~{flags}"(i32 -81920) nounwind + call void asm sideeffect "foo $0", "Z,~{dirflag},~{fpsr},~{flags}"(i64 4294885376) nounwind + br label %return + +return: ; preds = %entry + ret void +} From isanbard at gmail.com Mon Feb 16 20:53:02 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 02:53:02 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64731 - /llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-types.cpp Message-ID: <200902170253.n1H2r2JB032523@zion.cs.uiuc.edu> Author: void Date: Mon Feb 16 20:53:02 2009 New Revision: 64731 URL: http://llvm.org/viewvc/llvm-project?rev=64731&view=rev Log: Pull r64510 into Dib: Fix a bug handling zero-length fields in unions. Exposed by 64234, but it was always there if the zero-length field was the only one in the union. g{cc,++}.dg/compat/struct-layout-1.exp [several] Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-types.cpp Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-types.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-types.cpp?rev=64731&r1=64730&r2=64731&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-types.cpp (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-types.cpp Mon Feb 16 20:53:02 2009 @@ -2240,6 +2240,13 @@ continue; tree TheGccTy = TREE_TYPE(Field); + + // Skip zero-length fields; ConvertType refuses to construct a type + // of size 0. + if (DECL_SIZE(Field) && + TREE_CODE(DECL_SIZE(Field))==INTEGER_CST && + TREE_INT_CST_LOW(DECL_SIZE(Field))==0) + continue; #ifdef TARGET_POWERPC // Normally gcc reduces the size of bitfields to the size necessary // to hold the bits, e.g. a 1-bit field becomes QI. It does not do From isanbard at gmail.com Mon Feb 16 20:54:15 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 02:54:15 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64732 - /llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Message-ID: <200902170254.n1H2sF7c032621@zion.cs.uiuc.edu> Author: void Date: Mon Feb 16 20:54:14 2009 New Revision: 64732 URL: http://llvm.org/viewvc/llvm-project?rev=64732&view=rev Log: Pull r64704 into Dib: Use appropriate constructor and destructor names in debug info entry. Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp?rev=64732&r1=64731&r2=64732&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Mon Feb 16 20:54:14 2009 @@ -221,12 +221,13 @@ BasicBlock *CurBB) { // Gather location information. expanded_location Loc = GetNodeLocation(FnDecl, false); - const char *FnName = GetNodeName(FnDecl); const char *LinkageName = getLinkageName(FnDecl); DISubprogram SP = DebugFactory.CreateSubprogram(findRegion(FnDecl), - FnName, FnName, LinkageName, + lang_hooks.dwarf_name(FnDecl, 0), + lang_hooks.dwarf_name(FnDecl, 0), + LinkageName, getOrCreateCompileUnit(Loc.file), CurLineNo, getOrCreateType(TREE_TYPE(FnDecl)), Fn->hasInternalLinkage(), @@ -596,7 +597,7 @@ Member = TREE_CHAIN(Member)) { // Should we skip. if (DECL_P(Member) && DECL_IGNORED_P(Member)) continue; - + if (TREE_CODE(Member) == FIELD_DECL) { if (DECL_FIELD_OFFSET(Member) == 0 || @@ -639,11 +640,12 @@ Member = TREE_CHAIN(Member)) { if (DECL_ABSTRACT_ORIGIN (Member)) continue; - + if (DECL_ARTIFICIAL (Member)) continue; + // Get the location of the member. expanded_location MemLoc = GetNodeLocation(Member, false); - const char *MemberName = GetNodeName(Member); + const char *MemberName = lang_hooks.dwarf_name(Member, 0); const char *LinkageName = getLinkageName(Member); DIType SPTy = getOrCreateType(TREE_TYPE(Member)); DISubprogram SP = From isanbard at gmail.com Mon Feb 16 20:55:11 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 02:55:11 -0000 Subject: [llvm-commits] [llvm] r64733 - /llvm/branches/Apple/Dib/test/FrontendC++/2009-02-16-CtorNames-dbg.cpp Message-ID: <200902170255.n1H2tBom032688@zion.cs.uiuc.edu> Author: void Date: Mon Feb 16 20:55:11 2009 New Revision: 64733 URL: http://llvm.org/viewvc/llvm-project?rev=64733&view=rev Log: Pull r64705 into Dib: Testcase for r64704. Added: llvm/branches/Apple/Dib/test/FrontendC++/2009-02-16-CtorNames-dbg.cpp Added: llvm/branches/Apple/Dib/test/FrontendC++/2009-02-16-CtorNames-dbg.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/FrontendC%2B%2B/2009-02-16-CtorNames-dbg.cpp?rev=64733&view=auto ============================================================================== --- llvm/branches/Apple/Dib/test/FrontendC++/2009-02-16-CtorNames-dbg.cpp (added) +++ llvm/branches/Apple/Dib/test/FrontendC++/2009-02-16-CtorNames-dbg.cpp Mon Feb 16 20:55:11 2009 @@ -0,0 +1,12 @@ +// RUN: %llvmgcc -S -g --emit-llvm %s -o - | grep "\~A" +// RUN: %llvmgcc -S -g --emit-llvm %s -o - | not grep comp_ctor +// RUN: %llvmgcc -S -g --emit-llvm %s -o - | not grep comp_dtor +class A { + int i; +public: + A() { i = 0; } + ~A() { i = 42; } +}; + +A a; + From evan.cheng at apple.com Mon Feb 16 21:04:45 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 17 Feb 2009 03:04:45 -0000 Subject: [llvm-commits] [test-suite] r64734 - /test-suite/trunk/Makefile.programs Message-ID: <200902170304.n1H34jUc000609@zion.cs.uiuc.edu> Author: evancheng Date: Mon Feb 16 21:04:45 2009 New Revision: 64734 URL: http://llvm.org/viewvc/llvm-project?rev=64734&view=rev Log: Command line option -enable-sinking has been removed. Modified: test-suite/trunk/Makefile.programs Modified: test-suite/trunk/Makefile.programs URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/Makefile.programs?rev=64734&r1=64733&r2=64734&view=diff ============================================================================== --- test-suite/trunk/Makefile.programs (original) +++ test-suite/trunk/Makefile.programs Mon Feb 16 21:04:45 2009 @@ -227,14 +227,14 @@ LLCBETAOPTION := -disable-post-RA-scheduler=false endif ifeq ($(ARCH),x86) -LLCBETAOPTION := -disable-post-RA-scheduler=false +LLCBETAOPTION := -xx +#-disable-post-RA-scheduler=false #-pre-alloc-split #-join-cross-class-copies #-fast-isel #-aggressive-remat #-new-spilling-heuristic #-enable-value-prop -#-enable-sinking #-schedule-livein-copies #-new-coalescer-heuristic=true #-tailcallopt @@ -246,8 +246,7 @@ LLCBETAOPTION := -enable-sparc-v9-insts endif ifeq ($(ARCH),ARM) -LLCBETAOPTION := -enable-sinking -#-schedule-livein-copies +LLCBETAOPTION := -schedule-livein-copies #-new-coalescer-heuristic=true #-march=thumb endif From kremenek at apple.com Mon Feb 16 23:00:11 2009 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 17 Feb 2009 05:00:11 -0000 Subject: [llvm-commits] [llvm] r64738 - /llvm/tags/checker/checker-0.157/ Message-ID: <200902170500.n1H50BSB004647@zion.cs.uiuc.edu> Author: kremenek Date: Mon Feb 16 23:00:09 2009 New Revision: 64738 URL: http://llvm.org/viewvc/llvm-project?rev=64738&view=rev Log: Removing checker-0.157. Removed: llvm/tags/checker/checker-0.157/ From kremenek at apple.com Mon Feb 16 23:03:50 2009 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 17 Feb 2009 05:03:50 -0000 Subject: [llvm-commits] [llvm] r64741 - /llvm/tags/checker/checker-0.157/ Message-ID: <200902170503.n1H53oZl004833@zion.cs.uiuc.edu> Author: kremenek Date: Mon Feb 16 23:03:50 2009 New Revision: 64741 URL: http://llvm.org/viewvc/llvm-project?rev=64741&view=rev Log: Tagging checker-0.157. Added: llvm/tags/checker/checker-0.157/ - copied from r64740, llvm/trunk/ From evan.cheng at apple.com Mon Feb 16 23:56:13 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 17 Feb 2009 05:56:13 -0000 Subject: [llvm-commits] [test-suite] r64744 - in /test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia: AMGmk/main.c CrystalMk/SPEdriver.c IRSmk/main.c Message-ID: <200902170556.n1H5uETs007032@zion.cs.uiuc.edu> Author: evancheng Date: Mon Feb 16 23:56:13 2009 New Revision: 64744 URL: http://llvm.org/viewvc/llvm-project?rev=64744&view=rev Log: Shrinkify tests for SMALL_PROBLEM_SIZE. Modified: test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia/AMGmk/main.c test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia/CrystalMk/SPEdriver.c test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia/IRSmk/main.c Modified: test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia/AMGmk/main.c URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia/AMGmk/main.c?rev=64744&r1=64743&r2=64744&view=diff ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia/AMGmk/main.c (original) +++ test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia/AMGmk/main.c Mon Feb 16 23:56:13 2009 @@ -17,7 +17,11 @@ #include "headers.h" // +#ifdef SMALL_PROBLEM_SIZE +const int testIter = 100; +#else const int testIter = 2000; +#endif double totalWallTime = 0.0; double totalCPUTime = 0.0; Modified: test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia/CrystalMk/SPEdriver.c URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia/CrystalMk/SPEdriver.c?rev=64744&r1=64743&r2=64744&view=diff ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia/CrystalMk/SPEdriver.c (original) +++ test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia/CrystalMk/SPEdriver.c Mon Feb 16 23:56:13 2009 @@ -51,7 +51,11 @@ double del_wtime = 0.0; double tmp; +#ifdef SMALL_PROBLEM_SIZE + const int noIter = 200000; +#else const int noIter = 2000000; +#endif int i = 0; int j, k; Modified: test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia/IRSmk/main.c URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia/IRSmk/main.c?rev=64744&r1=64743&r2=64744&view=diff ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia/IRSmk/main.c (original) +++ test-suite/trunk/MultiSource/Benchmarks/ASC_Sequoia/IRSmk/main.c Mon Feb 16 23:56:13 2009 @@ -42,7 +42,11 @@ double *b; int i = 0; +#ifdef SMALL_PROBLEM_SIZE + const int noIter = 250; +#else const int noIter = 5000; +#endif printf ("\nSequoia Benchmark Version 1.0\n\n"); From evan.cheng at apple.com Tue Feb 17 00:41:03 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 17 Feb 2009 06:41:03 -0000 Subject: [llvm-commits] [llvm] r64745 - in /llvm/trunk: lib/CodeGen/VirtRegMap.cpp test/CodeGen/ARM/2008-11-19-ScavengerAssert.ll test/CodeGen/ARM/2009-02-16-SpillerBug.ll Message-ID: <200902170641.n1H6f4jl008775@zion.cs.uiuc.edu> Author: evancheng Date: Tue Feb 17 00:41:03 2009 New Revision: 64745 URL: http://llvm.org/viewvc/llvm-project?rev=64745&view=rev Log: A couple of places where reused use operands should be marked kill. This is exposed by recent availability fallthrough changes. Added: llvm/trunk/test/CodeGen/ARM/2009-02-16-SpillerBug.ll Modified: llvm/trunk/lib/CodeGen/VirtRegMap.cpp llvm/trunk/test/CodeGen/ARM/2008-11-19-ScavengerAssert.ll Modified: llvm/trunk/lib/CodeGen/VirtRegMap.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/VirtRegMap.cpp?rev=64745&r1=64744&r2=64745&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/VirtRegMap.cpp (original) +++ llvm/trunk/lib/CodeGen/VirtRegMap.cpp Tue Feb 17 00:41:03 2009 @@ -1599,6 +1599,12 @@ PotentialDeadStoreSlots.push_back(ReuseSlot); } + + // Assumes this is the last use. IsKill will be unset if reg is reused + // unless it's a two-address operand. + if (ti == -1) + MI.getOperand(i).setIsKill(); + continue; } // CanReuse @@ -1764,6 +1770,11 @@ DefMO = NextMII->findRegisterDefOperand(DestReg); DefMO->setSubReg(SubIdx); } + + // Mark is killed. + MachineOperand *KillOpnd = NextMII->findRegisterUseOperand(InReg); + KillOpnd->setIsKill(); + BackTracked = true; } else { DOUT << "Removing now-noop copy: " << MI; Modified: llvm/trunk/test/CodeGen/ARM/2008-11-19-ScavengerAssert.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/2008-11-19-ScavengerAssert.ll?rev=64745&r1=64744&r2=64745&view=diff ============================================================================== --- llvm/trunk/test/CodeGen/ARM/2008-11-19-ScavengerAssert.ll (original) +++ llvm/trunk/test/CodeGen/ARM/2008-11-19-ScavengerAssert.ll Tue Feb 17 00:41:03 2009 @@ -1,5 +1,5 @@ ; RUN: llvm-as < %s | llc -mtriple=arm-apple-darwin9 -; RUN: llvm-as < %s | llc -mtriple=arm-apple-darwin9 -stats |& grep asm-printer | grep 186 +; RUN: llvm-as < %s | llc -mtriple=arm-apple-darwin9 -stats |& grep asm-printer | grep 185 %"struct.Adv5::Ekin<3>" = type <{ i8 }> %"struct.Adv5::X::Energyflux<3>" = type { double } Added: llvm/trunk/test/CodeGen/ARM/2009-02-16-SpillerBug.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/2009-02-16-SpillerBug.ll?rev=64745&view=auto ============================================================================== --- llvm/trunk/test/CodeGen/ARM/2009-02-16-SpillerBug.ll (added) +++ llvm/trunk/test/CodeGen/ARM/2009-02-16-SpillerBug.ll Tue Feb 17 00:41:03 2009 @@ -0,0 +1,117 @@ +; RUN: llvm-as < %s | llc -march=arm -mattr=+v6,+vfp2 + +target triple = "arm-apple-darwin9" + %struct.FILE_POS = type { i8, i8, i16, i32 } + %struct.FIRST_UNION = type { %struct.FILE_POS } + %struct.FOURTH_UNION = type { %struct.STYLE } + %struct.GAP = type { i8, i8, i16 } + %struct.LIST = type { %struct.rec*, %struct.rec* } + %struct.SECOND_UNION = type { { i16, i8, i8 } } + %struct.STYLE = type { { %struct.GAP }, { %struct.GAP }, i16, i16, i32 } + %struct.THIRD_UNION = type { { [2 x i32], [2 x i32] } } + %struct.head_type = type { [2 x %struct.LIST], %struct.FIRST_UNION, %struct.SECOND_UNION, %struct.THIRD_UNION, %struct.FOURTH_UNION, %struct.rec*, { %struct.rec* }, %struct.rec*, %struct.rec*, %struct.rec*, %struct.rec*, %struct.rec*, %struct.rec*, %struct.rec*, %struct.rec*, i32 } + %struct.rec = type { %struct.head_type } + at no_file_pos = external global %struct.FILE_POS ; <%struct.FILE_POS*> [#uses=1] +@"\01LC13423" = external constant [23 x i8] ; <[23 x i8]*> [#uses=1] +@"\01LC18972" = external constant [13 x i8] ; <[13 x i8]*> [#uses=1] + +define fastcc void @FlushGalley(%struct.rec* %hd) nounwind { +entry: + br label %RESUME + +RESUME: ; preds = %bb520.preheader, %entry + br label %bb396 + +bb122: ; preds = %bb396 + switch i32 0, label %bb394 [ + i32 1, label %bb131 + i32 2, label %bb244 + i32 4, label %bb244 + i32 5, label %bb244 + i32 6, label %bb244 + i32 7, label %bb244 + i32 11, label %bb244 + i32 12, label %bb244 + i32 15, label %bb244 + i32 17, label %bb244 + i32 18, label %bb244 + i32 19, label %bb244 + i32 20, label %bb396 + i32 21, label %bb396 + i32 22, label %bb396 + i32 23, label %bb396 + i32 24, label %bb244 + i32 25, label %bb244 + i32 26, label %bb244 + i32 27, label %bb244 + i32 28, label %bb244 + i32 29, label %bb244 + i32 30, label %bb244 + i32 31, label %bb244 + i32 32, label %bb244 + i32 33, label %bb244 + i32 34, label %bb244 + i32 35, label %bb244 + i32 36, label %bb244 + i32 37, label %bb244 + i32 38, label %bb244 + i32 39, label %bb244 + i32 40, label %bb244 + i32 41, label %bb244 + i32 42, label %bb244 + i32 43, label %bb244 + i32 44, label %bb244 + i32 45, label %bb244 + i32 46, label %bb244 + i32 50, label %bb244 + i32 51, label %bb244 + i32 94, label %bb244 + i32 95, label %bb244 + i32 96, label %bb244 + i32 97, label %bb244 + i32 98, label %bb244 + i32 99, label %bb244 + ] + +bb131: ; preds = %bb122 + br label %bb396 + +bb244: ; preds = %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122 + %0 = icmp eq %struct.rec* %stop_link.3, null ; [#uses=1] + br i1 %0, label %bb435, label %bb433 + +bb394: ; preds = %bb122 + call void (i32, i32, i8*, i32, %struct.FILE_POS*, ...)* @Error(i32 1, i32 3, i8* getelementptr ([23 x i8]* @"\01LC13423", i32 0, i32 0), i32 0, %struct.FILE_POS* @no_file_pos, i8* getelementptr ([13 x i8]* @"\01LC18972", i32 0, i32 0), i8* null) nounwind + br label %bb396 + +bb396: ; preds = %bb394, %bb131, %bb122, %bb122, %bb122, %bb122, %RESUME + %stop_link.3 = phi %struct.rec* [ null, %RESUME ], [ %stop_link.3, %bb394 ], [ %stop_link.3, %bb122 ], [ %stop_link.3, %bb122 ], [ %stop_link.3, %bb122 ], [ %stop_link.3, %bb122 ], [ %link.1, %bb131 ] ; <%struct.rec*> [#uses=7] + %headers_seen.1 = phi i32 [ 0, %RESUME ], [ %headers_seen.1, %bb394 ], [ 1, %bb122 ], [ 1, %bb122 ], [ 1, %bb122 ], [ 1, %bb122 ], [ %headers_seen.1, %bb131 ] ; [#uses=2] + %link.1 = load %struct.rec** null ; <%struct.rec*> [#uses=2] + %1 = icmp eq %struct.rec* %link.1, %hd ; [#uses=1] + br i1 %1, label %bb398, label %bb122 + +bb398: ; preds = %bb396 + unreachable + +bb433: ; preds = %bb244 + call fastcc void @Promote(%struct.rec* %hd, %struct.rec* %stop_link.3, %struct.rec* null, i32 1) nounwind + br label %bb435 + +bb435: ; preds = %bb433, %bb244 + br i1 false, label %bb491, label %bb499 + +bb491: ; preds = %bb435 + br label %bb499 + +bb499: ; preds = %bb499, %bb491, %bb435 + %2 = icmp eq %struct.rec* null, null ; [#uses=1] + br i1 %2, label %bb520.preheader, label %bb499 + +bb520.preheader: ; preds = %bb499 + br label %RESUME +} + +declare fastcc void @Promote(%struct.rec*, %struct.rec*, %struct.rec* nocapture, i32) nounwind + +declare void @Error(i32, i32, i8*, i32, %struct.FILE_POS*, ...) nounwind From isanbard at gmail.com Tue Feb 17 07:50:57 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 13:50:57 -0000 Subject: [llvm-commits] [llvm] r64763 - in /llvm/branches/Apple/Dib: include/llvm/Analysis/LoopInfo.h lib/Transforms/Scalar/LoopIndexSplit.cpp Message-ID: <200902171350.n1HDovUd002632@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 07:50:55 2009 New Revision: 64763 URL: http://llvm.org/viewvc/llvm-project?rev=64763&view=rev Log: Pull r64388 into Dib: Add a utility function to LoopInfo to return the exit block when the loop has exactly one exit, and make use of it in LoopIndexSplit. Modified: llvm/branches/Apple/Dib/include/llvm/Analysis/LoopInfo.h llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopIndexSplit.cpp Modified: llvm/branches/Apple/Dib/include/llvm/Analysis/LoopInfo.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/Analysis/LoopInfo.h?rev=64763&r1=64762&r2=64763&view=diff ============================================================================== --- llvm/branches/Apple/Dib/include/llvm/Analysis/LoopInfo.h (original) +++ llvm/branches/Apple/Dib/include/llvm/Analysis/LoopInfo.h Tue Feb 17 07:50:55 2009 @@ -185,6 +185,16 @@ } } + /// getExitingBlock - If getExitingBlocks would return exactly one block, + /// return that block. Otherwise return null. + BlockT *getExitingBlock() const { + SmallVector ExitingBlocks; + getExitingBlocks(ExitingBlocks); + if (ExitingBlocks.size() == 1) + return ExitingBlocks[0]; + return 0; + } + /// getExitBlocks - Return all of the successor blocks of this loop. These /// are the blocks _outside of the current loop_ which are branched to. /// Modified: llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopIndexSplit.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopIndexSplit.cpp?rev=64763&r1=64762&r2=64763&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopIndexSplit.cpp (original) +++ llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopIndexSplit.cpp Tue Feb 17 07:50:55 2009 @@ -236,15 +236,14 @@ } // Reject loop if loop exit condition is not suitable. - SmallVector EBs; - L->getExitingBlocks(EBs); - if (EBs.size() != 1) + BasicBlock *ExitingBlock = L->getExitingBlock(); + if (!ExitingBlock) return false; - BranchInst *EBR = dyn_cast(EBs[0]->getTerminator()); + BranchInst *EBR = dyn_cast(ExitingBlock->getTerminator()); if (!EBR) return false; ExitCondition = dyn_cast(EBR->getCondition()); if (!ExitCondition) return false; - if (EBs[0] != L->getLoopLatch()) return false; + if (ExitingBlock != L->getLoopLatch()) return false; IVExitValue = ExitCondition->getOperand(1); if (!L->isLoopInvariant(IVExitValue)) IVExitValue = ExitCondition->getOperand(0); From gohman at apple.com Tue Feb 17 09:57:40 2009 From: gohman at apple.com (Dan Gohman) Date: Tue, 17 Feb 2009 15:57:40 -0000 Subject: [llvm-commits] [llvm] r64766 - /llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Message-ID: <200902171557.n1HFveOt007066@zion.cs.uiuc.edu> Author: djg Date: Tue Feb 17 09:57:39 2009 New Revision: 64766 URL: http://llvm.org/viewvc/llvm-project?rev=64766&view=rev Log: Fix 80-column violation. Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=64766&r1=64765&r2=64766&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Tue Feb 17 09:57:39 2009 @@ -90,7 +90,8 @@ void EliminatePointerRecurrence(PHINode *PN, BasicBlock *Preheader, SmallPtrSet &DeadInsts); - void LinearFunctionTestReplace(Loop *L, SCEVHandle IterationCount, Value *IndVar, + void LinearFunctionTestReplace(Loop *L, SCEVHandle IterationCount, + Value *IndVar, BasicBlock *ExitingBlock, BranchInst *BI, SCEVExpander &Rewriter); From baldrick at free.fr Tue Feb 17 11:50:05 2009 From: baldrick at free.fr (Duncan Sands) Date: Tue, 17 Feb 2009 17:50:05 -0000 Subject: [llvm-commits] [llvm] r64773 - /llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Message-ID: <200902171750.n1HHo5af011243@zion.cs.uiuc.edu> Author: baldrick Date: Tue Feb 17 11:50:04 2009 New Revision: 64773 URL: http://llvm.org/viewvc/llvm-project?rev=64773&view=rev Log: This transform also applies to private linkage. Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=64773&r1=64772&r2=64773&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original) +++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Tue Feb 17 11:50:04 2009 @@ -2398,11 +2398,11 @@ // @a = alias ... @f // into: // define ... @a(...) - if (!Target->hasInternalLinkage()) + if (!Target->hasLocalLinkage()) continue; // The transform is only useful if the alias does not have internal linkage. - if (J->hasInternalLinkage()) + if (J->hasLocalLinkage()) continue; // Do not perform the transform if multiple aliases potentially target the From Alireza.Moshtaghi at microchip.com Tue Feb 17 12:14:17 2009 From: Alireza.Moshtaghi at microchip.com (Alireza.Moshtaghi at microchip.com) Date: Tue, 17 Feb 2009 11:14:17 -0700 Subject: [llvm-commits] r64000 breaks PIC16 In-Reply-To: <9D65B45B-C932-40F7-BC02-991AB1817188@apple.com> References: <1234292444.7110.7.camel@idc-lt-i00171.microchip.com><3BEE949D-7D28-4B3F-A69C-3E972C8716A9@apple.com><1234324706.4728.5.camel@idc-lt-i00171.microchip.com> <9D65B45B-C932-40F7-BC02-991AB1817188@apple.com> Message-ID: Hi Chris, I was busy with some other stuff and just now got to try this... The flag SDNPOutFlag is set for subfw but the sinker does not look at it. I have to also set the flag SDNPSideEffect for it to work correctly. Now the question is SDNPOutFlag not a reason for keeping the instruction in its place? Or there may be need to for some corrections in the sinker? Thanks Ali > -----Original Message----- > From: llvm-commits-bounces at cs.uiuc.edu [mailto:llvm-commits- > bounces at cs.uiuc.edu] On Behalf Of Chris Lattner > Sent: Wednesday, February 11, 2009 11:09 PM > To: Commit Messages and Patches for LLVM > Subject: Re: [llvm-commits] r64000 breaks PIC16 > > On Feb 11, 2009, at 4:08 PM, Alireza.Moshtaghi at microchip.com wrote: > > > Looks like the problem is in sinking stuff; I disabled them and it > > worked. > > Too me it seems like sinker does not check if the instruction to > > sink is > > providing a flag to a successor, if so it shouldn't move the > > instruction. > > In our case, blt is linked to subwf only through a flag (no register > > is > > used... ) blt is kept in place and subwf is sinked, followed by all > > instructions that provided to it. > > How can we check if an instruction is used by a successor through a > > flag? > > Hi Alireza, > > It looks like subfw isn't declared to implicitly set the flags > register. On X86 for example, all the instructions that mutate the > flags are defined to implicitly set FLAGS, and all instructions that > read the flags implicitly read FLAGS. This prevents code motion from > moving the instructions around. > > -Chris > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits From evan.cheng at apple.com Tue Feb 17 12:23:06 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 17 Feb 2009 18:23:06 -0000 Subject: [llvm-commits] [test-suite] r64777 - /test-suite/trunk/Makefile.programs Message-ID: <200902171823.n1HIN623012433@zion.cs.uiuc.edu> Author: evancheng Date: Tue Feb 17 12:23:06 2009 New Revision: 64777 URL: http://llvm.org/viewvc/llvm-project?rev=64777&view=rev Log: Oops. Accidentailly checked in local change. Modified: test-suite/trunk/Makefile.programs Modified: test-suite/trunk/Makefile.programs URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/Makefile.programs?rev=64777&r1=64776&r2=64777&view=diff ============================================================================== --- test-suite/trunk/Makefile.programs (original) +++ test-suite/trunk/Makefile.programs Tue Feb 17 12:23:06 2009 @@ -227,8 +227,7 @@ LLCBETAOPTION := -disable-post-RA-scheduler=false endif ifeq ($(ARCH),x86) -LLCBETAOPTION := -xx -#-disable-post-RA-scheduler=false +LLCBETAOPTION := -disable-post-RA-scheduler=false #-pre-alloc-split #-join-cross-class-copies #-fast-isel From dalej at apple.com Tue Feb 17 12:34:05 2009 From: dalej at apple.com (Dale Johannesen) Date: Tue, 17 Feb 2009 10:34:05 -0800 Subject: [llvm-commits] [llvm-gcc-4.2] r64584 - /llvm-gcc-4.2/trunk/gcc/cgraphunit.c In-Reply-To: <200902151125.n1FBPs0e003747@zion.cs.uiuc.edu> References: <200902151125.n1FBPs0e003747@zion.cs.uiuc.edu> Message-ID: On Feb 15, 2009, at 3:25 AMPST, Bill Wendling wrote: > > @@ -1331,13 +1331,8 @@ > #endif > gcc_assert (node->global.inlined_to || !DECL_SAVED_TREE (decl) > /* LLVM LOCAL begin - extern inline */ > -#ifdef ENABLE_LLVM > || IS_EXTERN_INLINE (decl)); > -#else > - || DECL_EXTERNAL (decl)); > -#endif > /* LLVM LOCAL end - extern inline */ This is the wrong idea. IS_EXTERN_INLINE is defined as #ifdef ENABLE_LLVM #define IS_EXTERN_INLINE(f) (DECL_EXTERNAL(f) && \ !lookup_attribute("always_inline", DECL_ATTRIBUTES(f))) #else #define IS_EXTERN_INLINE(f) (DECL_EXTERNAL(f)) #endif so it reduces to DECL_EXTERNAL in the non-LLVM build. There should be no #ifdef's at any of the call sites, please remove them. From clattner at apple.com Tue Feb 17 12:58:41 2009 From: clattner at apple.com (Chris Lattner) Date: Tue, 17 Feb 2009 10:58:41 -0800 Subject: [llvm-commits] r64000 breaks PIC16 In-Reply-To: References: <1234292444.7110.7.camel@idc-lt-i00171.microchip.com> <3BEE949D-7D28-4B3F-A69C-3E972C8716A9@apple.com> <1234324706.4728.5.camel@idc-lt-i00171.microchip.com> <9D65B45B-C932-40F7-BC02-991AB1817188@apple.com> Message-ID: <230B69F8-151B-4A71-A439-EA20C3A1395A@apple.com> On Feb 17, 2009, at 10:14 AM, Alireza.Moshtaghi at microchip.com wrote: > Hi Chris, > I was busy with some other stuff and just now got to try this... > The flag SDNPOutFlag is set for subfw but the sinker does not look at > it. I have to also set the flag SDNPSideEffect for it to work > correctly. > Now the question is SDNPOutFlag not a reason for keeping the > instruction > in its place? Or there may be need to for some corrections in the > sinker? Hi Ali, This needs to be a property on the machine instruction, not on the dag node. The X86 backend uses: let Defs = [EFLAGS] in { } around instructions that define the flags for example. You can also use the "Imp" helper to set this on specific instructions. -Chris From tonic at nondot.org Tue Feb 17 13:01:36 2009 From: tonic at nondot.org (Tanya Lattner) Date: Tue, 17 Feb 2009 19:01:36 -0000 Subject: [llvm-commits] [llvm] r64782 - in /llvm/branches/release_25: lib/CodeGen/SelectionDAG/TargetLowering.cpp test/CodeGen/X86/nobt.ll Message-ID: <200902171901.n1HJ1a5O013968@zion.cs.uiuc.edu> Author: tbrethou Date: Tue Feb 17 13:01:36 2009 New Revision: 64782 URL: http://llvm.org/viewvc/llvm-project?rev=64782&view=rev Log: Merge 64314 from mainline. Make a transformation added in 63266 a bit less aggressive. It was transforming (x&y)==y to (x&y)!=0 in the case where y is variable and known to have at most one bit set (e.g. z&1). This is not correct; the expressions are not equivalent when y==0. I believe this patch salvages what can be salvaged, including all the cases in bt.ll. Added: llvm/branches/release_25/test/CodeGen/X86/nobt.ll - copied unchanged from r64314, llvm/trunk/test/CodeGen/X86/nobt.ll Modified: llvm/branches/release_25/lib/CodeGen/SelectionDAG/TargetLowering.cpp Modified: llvm/branches/release_25/lib/CodeGen/SelectionDAG/TargetLowering.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_25/lib/CodeGen/SelectionDAG/TargetLowering.cpp?rev=64782&r1=64781&r2=64782&view=diff ============================================================================== --- llvm/branches/release_25/lib/CodeGen/SelectionDAG/TargetLowering.cpp (original) +++ llvm/branches/release_25/lib/CodeGen/SelectionDAG/TargetLowering.cpp Tue Feb 17 13:01:36 2009 @@ -1346,20 +1346,21 @@ return 1; } -static bool ValueHasAtMostOneBitSet(SDValue Val, const SelectionDAG &DAG) { +static bool ValueHasExactlyOneBitSet(SDValue Val, const SelectionDAG &DAG) { // Logical shift right or left won't ever introduce new set bits. // We check for this case because we don't care which bits are // set, but ComputeMaskedBits won't know anything unless it can // determine which specific bits may be set. if (Val.getOpcode() == ISD::SHL || Val.getOpcode() == ISD::SRL) - return ValueHasAtMostOneBitSet(Val.getOperand(0), DAG); + return ValueHasExactlyOneBitSet(Val.getOperand(0), DAG); MVT OpVT = Val.getValueType(); unsigned BitWidth = OpVT.getSizeInBits(); APInt Mask = APInt::getAllOnesValue(BitWidth); APInt KnownZero, KnownOne; DAG.ComputeMaskedBits(Val, Mask, KnownZero, KnownOne); - return KnownZero.countPopulation() == BitWidth - 1; + return (KnownZero.countPopulation() == BitWidth - 1) && + (KnownOne.countPopulation() == 1); } /// SimplifySetCC - Try to simplify a setcc built with the specified operands @@ -1832,9 +1833,12 @@ } // Simplify x&y == y to x&y != 0 if y has exactly one bit set. + // Note that where y is variable and is known to have at most + // one bit set (for example, if it is z&1) we cannot do this; + // the expressions are not equivalent when y==0. if (N0.getOpcode() == ISD::AND) if (N0.getOperand(0) == N1 || N0.getOperand(1) == N1) { - if (ValueHasAtMostOneBitSet(N1, DAG)) { + if (ValueHasExactlyOneBitSet(N1, DAG)) { Cond = ISD::getSetCCInverse(Cond, /*isInteger=*/true); SDValue Zero = DAG.getConstant(0, N1.getValueType()); return DAG.getSetCC(dl, VT, N0, Zero, Cond); @@ -1842,7 +1846,7 @@ } if (N1.getOpcode() == ISD::AND) if (N1.getOperand(0) == N0 || N1.getOperand(1) == N0) { - if (ValueHasAtMostOneBitSet(N0, DAG)) { + if (ValueHasExactlyOneBitSet(N0, DAG)) { Cond = ISD::getSetCCInverse(Cond, /*isInteger=*/true); SDValue Zero = DAG.getConstant(0, N0.getValueType()); return DAG.getSetCC(dl, VT, N1, Zero, Cond); From gohman at apple.com Tue Feb 17 13:13:57 2009 From: gohman at apple.com (Dan Gohman) Date: Tue, 17 Feb 2009 19:13:57 -0000 Subject: [llvm-commits] [llvm] r64784 - /llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Message-ID: <200902171913.n1HJDv3G014499@zion.cs.uiuc.edu> Author: djg Date: Tue Feb 17 13:13:57 2009 New Revision: 64784 URL: http://llvm.org/viewvc/llvm-project?rev=64784&view=rev Log: Delete trailing whitespace. Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=64784&r1=64783&r2=64784&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Tue Feb 17 13:13:57 2009 @@ -99,7 +99,7 @@ void DeleteTriviallyDeadInstructions(SmallPtrSet &Insts); - void HandleFloatingPointIV(Loop *L, PHINode *PH, + void HandleFloatingPointIV(Loop *L, PHINode *PH, SmallPtrSet &DeadInsts); }; } @@ -147,7 +147,7 @@ if (GEPI->getOperand(0) == PN) { assert(GEPI->getNumOperands() == 2 && "GEP types must match!"); DOUT << "INDVARS: Eliminating pointer recurrence: " << *GEPI; - + // Okay, we found a pointer recurrence. Transform this pointer // recurrence into an integer recurrence. Compute the value that gets // added to the pointer at every iteration. @@ -191,7 +191,7 @@ Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[1] = NewAdd; GetElementPtrInst *NGEPI = GetElementPtrInst::Create( - NCE, Idx, Idx + 2, + NCE, Idx, Idx + 2, GEPI->getName(), GEPI); SE->deleteValueFromRecords(GEPI); GEPI->replaceAllUsesWith(NGEPI); @@ -329,18 +329,18 @@ // the exit blocks of the loop to find them. for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) { BasicBlock *ExitBB = ExitBlocks[i]; - + // If there are no PHI nodes in this exit block, then no values defined // inside the loop are used on this path, skip it. PHINode *PN = dyn_cast(ExitBB->begin()); if (!PN) continue; - + unsigned NumPreds = PN->getNumIncomingValues(); - + // Iterate over all of the PHI nodes. BasicBlock::iterator BBI = ExitBB->begin(); while ((PN = dyn_cast(BBI++))) { - + // Iterate over all of the values in all the PHI nodes. for (unsigned i = 0; i != NumPreds; ++i) { // If the value being merged in is not integer or is not defined @@ -352,14 +352,14 @@ continue; // If this pred is for a subloop, not L itself, skip it. - if (LI->getLoopFor(PN->getIncomingBlock(i)) != L) + if (LI->getLoopFor(PN->getIncomingBlock(i)) != L) continue; // The Block is in a subloop, skip it. // Check that InVal is defined in the loop. Instruction *Inst = cast(InVal); if (!L->contains(Inst->getParent())) continue; - + // We require that this value either have a computable evolution or that // the loop have a constant iteration count. In the case where the loop // has a constant iteration count, we can sometimes force evaluation of @@ -367,7 +367,7 @@ SCEVHandle SH = SE->getSCEV(Inst); if (!SH->hasComputableLoopEvolution(L) && !HasConstantItCount) continue; // Cannot get exit evolution for the loop value. - + // Okay, this instruction has a user outside of the current loop // and varies predictably *inside* the loop. Evaluate the value it // contains when the loop exits, if possible. @@ -378,22 +378,22 @@ Changed = true; ++NumReplaced; - + // See if we already computed the exit value for the instruction, if so, // just reuse it. Value *&ExitVal = ExitValues[Inst]; if (!ExitVal) ExitVal = Rewriter.expandCodeFor(ExitValue, InsertPt); - + DOUT << "INDVARS: RLEV: AfterLoopVal = " << *ExitVal << " LoopVal = " << *Inst << "\n"; PN->setIncomingValue(i, ExitVal); - + // If this instruction is dead now, schedule it to be removed. if (Inst->use_empty()) InstructionsToDelete.insert(Inst); - + // See if this is a single-entry LCSSA PHI node. If so, we can (and // have to) remove // the PHI entirely. This is safe, because the NewVal won't be variant @@ -407,7 +407,7 @@ } } } - + DeleteTriviallyDeadInstructions(InstructionsToDelete); } @@ -766,14 +766,14 @@ static bool useSIToFPInst(ConstantFP &InitV, ConstantFP &ExitV, uint64_t intIV, uint64_t intEV) { - if (InitV.getValueAPF().isNegative() || ExitV.getValueAPF().isNegative()) + if (InitV.getValueAPF().isNegative() || ExitV.getValueAPF().isNegative()) return true; // If the iteration range can be handled by SIToFPInst then use it. APInt Max = APInt::getSignedMaxValue(32); if (Max.getZExtValue() > static_cast(abs(intEV - intIV))) return true; - + return false; } @@ -783,11 +783,11 @@ bool isExact = false; if (&APF.getSemantics() == &APFloat::PPCDoubleDouble) return false; - if (APF.convertToInteger(intVal, 32, APF.isNegative(), + if (APF.convertToInteger(intVal, 32, APF.isNegative(), APFloat::rmTowardZero, &isExact) != APFloat::opOK) return false; - if (!isExact) + if (!isExact) return false; return true; @@ -802,12 +802,12 @@ /// for(int i = 0; i < 10000; ++i) /// bar((double)i); /// -void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PH, +void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PH, SmallPtrSet &DeadInsts) { unsigned IncomingEdge = L->contains(PH->getIncomingBlock(0)); unsigned BackEdge = IncomingEdge^1; - + // Check incoming value. ConstantFP *InitValue = dyn_cast(PH->getIncomingValue(IncomingEdge)); if (!InitValue) return; @@ -817,7 +817,7 @@ // Check IV increment. Reject this PH if increement operation is not // an add or increment value can not be represented by an integer. - BinaryOperator *Incr = + BinaryOperator *Incr = dyn_cast(PH->getIncomingValue(BackEdge)); if (!Incr) return; if (Incr->getOpcode() != Instruction::Add) return; @@ -830,7 +830,7 @@ uint64_t newIncrValue = Type::Int32Ty->getPrimitiveSizeInBits(); if (!convertToInt(IncrValue->getValueAPF(), &newIncrValue)) return; - + // Check Incr uses. One user is PH and the other users is exit condition used // by the conditional terminator. Value::use_iterator IncrUse = Incr->use_begin(); @@ -838,7 +838,7 @@ if (IncrUse == Incr->use_end()) return; Instruction *U2 = cast(IncrUse++); if (IncrUse != Incr->use_end()) return; - + // Find exit condition. FCmpInst *EC = dyn_cast(U1); if (!EC) @@ -861,7 +861,7 @@ uint64_t intEV = Type::Int32Ty->getPrimitiveSizeInBits(); if (!convertToInt(EV->getValueAPF(), &intEV)) return; - + // Find new predicate for integer comparison. CmpInst::Predicate NewPred = CmpInst::BAD_ICMP_PREDICATE; switch (EC->getPredicate()) { @@ -889,15 +889,15 @@ break; } if (NewPred == CmpInst::BAD_ICMP_PREDICATE) return; - + // Insert new integer induction variable. PHINode *NewPHI = PHINode::Create(Type::Int32Ty, PH->getName()+".int", PH); NewPHI->addIncoming(ConstantInt::get(Type::Int32Ty, newInitValue), PH->getIncomingBlock(IncomingEdge)); - Value *NewAdd = BinaryOperator::CreateAdd(NewPHI, - ConstantInt::get(Type::Int32Ty, + Value *NewAdd = BinaryOperator::CreateAdd(NewPHI, + ConstantInt::get(Type::Int32Ty, newIncrValue), Incr->getName()+".int", Incr); NewPHI->addIncoming(NewAdd, PH->getIncomingBlock(BackEdge)); @@ -905,25 +905,25 @@ ConstantInt *NewEV = ConstantInt::get(Type::Int32Ty, intEV); Value *LHS = (EVIndex == 1 ? NewPHI->getIncomingValue(BackEdge) : NewEV); Value *RHS = (EVIndex == 1 ? NewEV : NewPHI->getIncomingValue(BackEdge)); - ICmpInst *NewEC = new ICmpInst(NewPred, LHS, RHS, EC->getNameStart(), + ICmpInst *NewEC = new ICmpInst(NewPred, LHS, RHS, EC->getNameStart(), EC->getParent()->getTerminator()); - + // Delete old, floating point, exit comparision instruction. EC->replaceAllUsesWith(NewEC); DeadInsts.insert(EC); - + // Delete old, floating point, increment instruction. Incr->replaceAllUsesWith(UndefValue::get(Incr->getType())); DeadInsts.insert(Incr); - + // Replace floating induction variable. Give SIToFPInst preference over // UIToFPInst because it is faster on platforms that are widely used. if (useSIToFPInst(*InitValue, *EV, newInitValue, intEV)) { - SIToFPInst *Conv = new SIToFPInst(NewPHI, PH->getType(), "indvar.conv", + SIToFPInst *Conv = new SIToFPInst(NewPHI, PH->getType(), "indvar.conv", PH->getParent()->getFirstNonPHI()); PH->replaceAllUsesWith(Conv); } else { - UIToFPInst *Conv = new UIToFPInst(NewPHI, PH->getType(), "indvar.conv", + UIToFPInst *Conv = new UIToFPInst(NewPHI, PH->getType(), "indvar.conv", PH->getParent()->getFirstNonPHI()); PH->replaceAllUsesWith(Conv); } From tonic at nondot.org Tue Feb 17 13:21:47 2009 From: tonic at nondot.org (Tanya Lattner) Date: Tue, 17 Feb 2009 19:21:47 -0000 Subject: [llvm-commits] [llvm] r64785 - in /llvm/branches/release_25/lib/CodeGen: SimpleRegisterCoalescing.cpp SimpleRegisterCoalescing.h Message-ID: <200902171921.n1HJLlF0014779@zion.cs.uiuc.edu> Author: tbrethou Date: Tue Feb 17 13:21:47 2009 New Revision: 64785 URL: http://llvm.org/viewvc/llvm-project?rev=64785&view=rev Log: Merge all changes to SimpleRegisterCoalescing to the release. Modified: llvm/branches/release_25/lib/CodeGen/SimpleRegisterCoalescing.cpp llvm/branches/release_25/lib/CodeGen/SimpleRegisterCoalescing.h Modified: llvm/branches/release_25/lib/CodeGen/SimpleRegisterCoalescing.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_25/lib/CodeGen/SimpleRegisterCoalescing.cpp?rev=64785&r1=64784&r2=64785&view=diff ============================================================================== --- llvm/branches/release_25/lib/CodeGen/SimpleRegisterCoalescing.cpp (original) +++ llvm/branches/release_25/lib/CodeGen/SimpleRegisterCoalescing.cpp Tue Feb 17 13:21:47 2009 @@ -42,6 +42,7 @@ STATISTIC(NumReMats , "Number of instructions re-materialized"); STATISTIC(numPeep , "Number of identity moves eliminated after coalescing"); STATISTIC(numAborts , "Number of times interval joining aborted"); +STATISTIC(numDeadValNo, "Number of valno def marked dead"); char SimpleRegisterCoalescing::ID = 0; static cl::opt @@ -450,6 +451,97 @@ return true; } +/// isSameOrFallThroughBB - Return true if MBB == SuccMBB or MBB simply +/// fallthoughs to SuccMBB. +static bool isSameOrFallThroughBB(MachineBasicBlock *MBB, + MachineBasicBlock *SuccMBB, + const TargetInstrInfo *tii_) { + if (MBB == SuccMBB) + return true; + MachineBasicBlock *TBB = 0, *FBB = 0; + SmallVector Cond; + return !tii_->AnalyzeBranch(*MBB, TBB, FBB, Cond) && !TBB && !FBB && + MBB->isSuccessor(SuccMBB); +} + +/// removeRange - Wrapper for LiveInterval::removeRange. This removes a range +/// from a physical register live interval as well as from the live intervals +/// of its sub-registers. +static void removeRange(LiveInterval &li, unsigned Start, unsigned End, + LiveIntervals *li_, const TargetRegisterInfo *tri_) { + li.removeRange(Start, End, true); + if (TargetRegisterInfo::isPhysicalRegister(li.reg)) { + for (const unsigned* SR = tri_->getSubRegisters(li.reg); *SR; ++SR) { + if (!li_->hasInterval(*SR)) + continue; + LiveInterval &sli = li_->getInterval(*SR); + unsigned RemoveEnd = Start; + while (RemoveEnd != End) { + LiveInterval::iterator LR = sli.FindLiveRangeContaining(Start); + if (LR == sli.end()) + break; + RemoveEnd = (LR->end < End) ? LR->end : End; + sli.removeRange(Start, RemoveEnd, true); + Start = RemoveEnd; + } + } + } +} + +/// TrimLiveIntervalToLastUse - If there is a last use in the same basic block +/// as the copy instruction, trim the live interval to the last use and return +/// true. +bool +SimpleRegisterCoalescing::TrimLiveIntervalToLastUse(unsigned CopyIdx, + MachineBasicBlock *CopyMBB, + LiveInterval &li, + const LiveRange *LR) { + unsigned MBBStart = li_->getMBBStartIdx(CopyMBB); + unsigned LastUseIdx; + MachineOperand *LastUse = lastRegisterUse(LR->start, CopyIdx-1, li.reg, + LastUseIdx); + if (LastUse) { + MachineInstr *LastUseMI = LastUse->getParent(); + if (!isSameOrFallThroughBB(LastUseMI->getParent(), CopyMBB, tii_)) { + // r1024 = op + // ... + // BB1: + // = r1024 + // + // BB2: + // r1025 = r1024 + if (MBBStart < LR->end) + removeRange(li, MBBStart, LR->end, li_, tri_); + return true; + } + + // There are uses before the copy, just shorten the live range to the end + // of last use. + LastUse->setIsKill(); + removeRange(li, li_->getDefIndex(LastUseIdx), LR->end, li_, tri_); + unsigned SrcReg, DstReg, SrcSubIdx, DstSubIdx; + if (tii_->isMoveInstr(*LastUseMI, SrcReg, DstReg, SrcSubIdx, DstSubIdx) && + DstReg == li.reg) { + // Last use is itself an identity code. + int DeadIdx = LastUseMI->findRegisterDefOperandIdx(li.reg, false, tri_); + LastUseMI->getOperand(DeadIdx).setIsDead(); + } + return true; + } + + // Is it livein? + if (LR->start <= MBBStart && LR->end > MBBStart) { + if (LR->start == 0) { + assert(TargetRegisterInfo::isPhysicalRegister(li.reg)); + // Live-in to the function but dead. Remove it from entry live-in set. + mf_->begin()->removeLiveIn(li.reg); + } + // FIXME: Shorten intervals in BBs that reaches this BB. + } + + return false; +} + /// ReMaterializeTrivialDef - If the source of a copy is defined by a trivial /// computation, replace the copy by rematerialize the definition. bool SimpleRegisterCoalescing::ReMaterializeTrivialDef(LiveInterval &SrcInt, @@ -467,6 +559,9 @@ const TargetInstrDesc &TID = DefMI->getDesc(); if (!TID.isAsCheapAsAMove()) return false; + if (!DefMI->getDesc().isRematerializable() || + !tii_->isTriviallyReMaterializable(DefMI)) + return false; bool SawStore = false; if (!DefMI->isSafeToMove(tii_, SawStore)) return false; @@ -485,7 +580,12 @@ } } + // If copy kills the source register, find the last use and propagate + // kill. MachineBasicBlock *MBB = CopyMI->getParent(); + if (CopyMI->killsRegister(SrcInt.reg)) + TrimLiveIntervalToLastUse(CopyIdx, MBB, SrcInt, SrcLR); + MachineBasicBlock::iterator MII = next(MachineBasicBlock::iterator(CopyMI)); CopyMI->removeFromParent(); tii_->reMaterialize(*MBB, MII, DstReg, DefMI); @@ -660,30 +760,6 @@ } } -/// removeRange - Wrapper for LiveInterval::removeRange. This removes a range -/// from a physical register live interval as well as from the live intervals -/// of its sub-registers. -static void removeRange(LiveInterval &li, unsigned Start, unsigned End, - LiveIntervals *li_, const TargetRegisterInfo *tri_) { - li.removeRange(Start, End, true); - if (TargetRegisterInfo::isPhysicalRegister(li.reg)) { - for (const unsigned* SR = tri_->getSubRegisters(li.reg); *SR; ++SR) { - if (!li_->hasInterval(*SR)) - continue; - LiveInterval &sli = li_->getInterval(*SR); - unsigned RemoveEnd = Start; - while (RemoveEnd != End) { - LiveInterval::iterator LR = sli.FindLiveRangeContaining(Start); - if (LR == sli.end()) - break; - RemoveEnd = (LR->end < End) ? LR->end : End; - sli.removeRange(Start, RemoveEnd, true); - Start = RemoveEnd; - } - } - } -} - /// removeIntervalIfEmpty - Check if the live interval of a physical register /// is empty, if so remove it and also remove the empty intervals of its /// sub-registers. Return true if live interval is removed. @@ -752,19 +828,6 @@ } } -/// isSameOrFallThroughBB - Return true if MBB == SuccMBB or MBB simply -/// fallthoughs to SuccMBB. -static bool isSameOrFallThroughBB(MachineBasicBlock *MBB, - MachineBasicBlock *SuccMBB, - const TargetInstrInfo *tii_) { - if (MBB == SuccMBB) - return true; - MachineBasicBlock *TBB = 0, *FBB = 0; - SmallVector Cond; - return !tii_->AnalyzeBranch(*MBB, TBB, FBB, Cond) && !TBB && !FBB && - MBB->isSuccessor(SuccMBB); -} - /// ShortenDeadCopySrcLiveRange - Shorten a live range as it's artificially /// extended by a dead copy. Mark the last use (if any) of the val# as kill as /// ends the live range there. If there isn't another use, then this live range @@ -796,55 +859,31 @@ // More uses past this copy? Nothing to do. return false; + // If there is a last use in the same bb, we can't remove the live range. + // Shorten the live interval and return. MachineBasicBlock *CopyMBB = CopyMI->getParent(); - unsigned MBBStart = li_->getMBBStartIdx(CopyMBB); - unsigned LastUseIdx; - MachineOperand *LastUse = lastRegisterUse(LR->start, CopyIdx-1, li.reg, - LastUseIdx); - if (LastUse) { - MachineInstr *LastUseMI = LastUse->getParent(); - if (!isSameOrFallThroughBB(LastUseMI->getParent(), CopyMBB, tii_)) { - // r1024 = op - // ... - // BB1: - // = r1024 - // - // BB2: - // r1025 = r1024 - if (MBBStart < LR->end) - removeRange(li, MBBStart, LR->end, li_, tri_); - return false; - } - - // There are uses before the copy, just shorten the live range to the end - // of last use. - LastUse->setIsKill(); - removeRange(li, li_->getDefIndex(LastUseIdx), LR->end, li_, tri_); - unsigned SrcReg, DstReg, SrcSubIdx, DstSubIdx; - if (tii_->isMoveInstr(*LastUseMI, SrcReg, DstReg, SrcSubIdx, DstSubIdx) && - DstReg == li.reg) { - // Last use is itself an identity code. - int DeadIdx = LastUseMI->findRegisterDefOperandIdx(li.reg, false, tri_); - LastUseMI->getOperand(DeadIdx).setIsDead(); - } + if (TrimLiveIntervalToLastUse(CopyIdx, CopyMBB, li, LR)) return false; - } - // Is it livein? - if (LR->start <= MBBStart && LR->end > MBBStart) { - if (LR->start == 0) { - assert(TargetRegisterInfo::isPhysicalRegister(li.reg)); - // Live-in to the function but dead. Remove it from entry live-in set. - mf_->begin()->removeLiveIn(li.reg); + MachineBasicBlock *StartMBB = li_->getMBBFromIndex(RemoveStart); + if (!isSameOrFallThroughBB(StartMBB, CopyMBB, tii_)) + // If the live range starts in another mbb and the copy mbb is not a fall + // through mbb, then we can only cut the range from the beginning of the + // copy mbb. + RemoveStart = li_->getMBBStartIdx(CopyMBB) + 1; + + if (LR->valno->def == RemoveStart) { + // If the def MI defines the val# and this copy is the only kill of the + // val#, then propagate the dead marker. + if (li.isOnlyLROfValNo(LR)) { + PropagateDeadness(li, CopyMI, RemoveStart, li_, tri_); + ++numDeadValNo; } - // FIXME: Shorten intervals in BBs that reaches this BB. + if (li.isKill(LR->valno, RemoveEnd)) + li.removeKill(LR->valno, RemoveEnd); } - if (LR->valno->def == RemoveStart) - // If the def MI defines the val#, propagate the dead marker. - PropagateDeadness(li, CopyMI, RemoveStart, li_, tri_); - - removeRange(li, RemoveStart, LR->end, li_, tri_); + removeRange(li, RemoveStart, RemoveEnd, li_, tri_); return removeIntervalIfEmpty(li, li_, tri_); } @@ -2460,6 +2499,8 @@ if (!MO.isReg()) continue; unsigned Reg = MO.getReg(); + if (!Reg) + continue; if (TargetRegisterInfo::isVirtualRegister(Reg)) DeadDefs.push_back(Reg); if (MO.isDead()) Modified: llvm/branches/release_25/lib/CodeGen/SimpleRegisterCoalescing.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_25/lib/CodeGen/SimpleRegisterCoalescing.h?rev=64785&r1=64784&r2=64785&view=diff ============================================================================== --- llvm/branches/release_25/lib/CodeGen/SimpleRegisterCoalescing.h (original) +++ llvm/branches/release_25/lib/CodeGen/SimpleRegisterCoalescing.h Tue Feb 17 13:21:47 2009 @@ -196,6 +196,15 @@ bool RemoveCopyByCommutingDef(LiveInterval &IntA, LiveInterval &IntB, MachineInstr *CopyMI); + /// TrimLiveIntervalToLastUse - If there is a last use in the same basic + /// block as the copy instruction, trim the ive interval to the last use + /// and return true. + bool TrimLiveIntervalToLastUse(unsigned CopyIdx, + MachineBasicBlock *CopyMBB, + LiveInterval &li, const LiveRange *LR); + + /// ReMaterializeTrivialDef - If the source of a copy is defined by a trivial + /// computation, replace the copy by rematerialize the definition. bool ReMaterializeTrivialDef(LiveInterval &SrcInt, unsigned DstReg, MachineInstr *CopyMI); From tonic at nondot.org Tue Feb 17 13:32:46 2009 From: tonic at nondot.org (Tanya Lattner) Date: Tue, 17 Feb 2009 19:32:46 -0000 Subject: [llvm-commits] [llvm] r64789 - in /llvm/branches/release_25: lib/Transforms/Scalar/LoopStrengthReduce.cpp test/Transforms/LoopStrengthReduce/pr3571.ll Message-ID: <200902171932.n1HJWkar015333@zion.cs.uiuc.edu> Author: tbrethou Date: Tue Feb 17 13:32:45 2009 New Revision: 64789 URL: http://llvm.org/viewvc/llvm-project?rev=64789&view=rev Log: Merge 64579 from mainline. Fix pr3571: If stride is a value defined by an instruction, make sure it dominates the loop preheader. When IV users are strength reduced, the stride is inserted into the preheader. It could create a use before def situation. Added: llvm/branches/release_25/test/Transforms/LoopStrengthReduce/pr3571.ll Modified: llvm/branches/release_25/lib/Transforms/Scalar/LoopStrengthReduce.cpp Modified: llvm/branches/release_25/lib/Transforms/Scalar/LoopStrengthReduce.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_25/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=64789&r1=64788&r2=64789&view=diff ============================================================================== --- llvm/branches/release_25/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original) +++ llvm/branches/release_25/lib/Transforms/Scalar/LoopStrengthReduce.cpp Tue Feb 17 13:32:45 2009 @@ -400,7 +400,7 @@ /// outer loop of the current loop. static bool getSCEVStartAndStride(const SCEVHandle &SH, Loop *L, SCEVHandle &Start, SCEVHandle &Stride, - ScalarEvolution *SE) { + ScalarEvolution *SE, DominatorTree *DT) { SCEVHandle TheAddRec = Start; // Initialize to zero. // If the outer level is an AddExpr, the operands are all start values except @@ -437,9 +437,21 @@ Start = SE->getAddExpr(Start, AddRec->getOperand(0)); - if (!isa(AddRec->getOperand(1))) + if (!isa(AddRec->getOperand(1))) { + // If stride is an instruction, make sure it dominates the loop header. + // Otherwise we could end up with a use before def situation. + if (SCEVUnknown *SU = dyn_cast(AddRec->getOperand(1))) { + if (Instruction *I = dyn_cast(SU->getValue())) { + BasicBlock *StrideBB = I->getParent(); + BasicBlock *Preheader = L->getLoopPreheader(); + if (!DT->dominates(StrideBB, Preheader)) + return false; + } + } + DOUT << "[" << L->getHeader()->getName() << "] Variable stride: " << *AddRec << "\n"; + } Stride = AddRec->getOperand(1); return true; @@ -547,7 +559,7 @@ // Get the start and stride for this expression. SCEVHandle Start = SE->getIntegerSCEV(0, ISE->getType()); SCEVHandle Stride = Start; - if (!getSCEVStartAndStride(ISE, L, Start, Stride, SE)) + if (!getSCEVStartAndStride(ISE, L, Start, Stride, SE, DT)) return false; // Non-reducible symbolic expression, bail out. std::vector IUsers; Added: llvm/branches/release_25/test/Transforms/LoopStrengthReduce/pr3571.ll URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_25/test/Transforms/LoopStrengthReduce/pr3571.ll?rev=64789&view=auto ============================================================================== --- llvm/branches/release_25/test/Transforms/LoopStrengthReduce/pr3571.ll (added) +++ llvm/branches/release_25/test/Transforms/LoopStrengthReduce/pr3571.ll Tue Feb 17 13:32:45 2009 @@ -0,0 +1,27 @@ +; RUN: llvm-as < %s | opt -loop-reduce | llvm-dis +; PR3571 + +target triple = "i386-mingw32" +define void @_ZNK18qdesigner_internal10TreeWidget12drawBranchesEP8QPainterRK5QRectRK11QModelIndex() nounwind { +entry: + br label %_ZNK11QModelIndex7isValidEv.exit.i + +bb.i: ; preds = %_ZNK11QModelIndex7isValidEv.exit.i + %indvar.next = add i32 %result.0.i, 1 ; [#uses=1] + br label %_ZNK11QModelIndex7isValidEv.exit.i + +_ZNK11QModelIndex7isValidEv.exit.i: ; preds = %bb.i, %entry + %result.0.i = phi i32 [ 0, %entry ], [ %indvar.next, %bb.i ] ; [#uses=2] + %0 = load i32** null, align 4 ; <%struct.QAbstractItemDelegate*> [#uses=0] + br i1 false, label %_ZN18qdesigner_internalL5levelEP18QAbstractItemModelRK11QModelIndex.exit, label %bb.i + +_ZN18qdesigner_internalL5levelEP18QAbstractItemModelRK11QModelIndex.exit: ; preds = %_ZNK11QModelIndex7isValidEv.exit.i + %1 = call i32 @_ZNK9QTreeView11indentationEv(i32* null) nounwind ; [#uses=1] + %2 = mul i32 %1, %result.0.i ; [#uses=1] + %3 = add i32 %2, -2 ; [#uses=1] + %4 = add i32 %3, 0 ; [#uses=1] + store i32 %4, i32* null, align 8 + unreachable +} + +declare i32 @_ZNK9QTreeView11indentationEv(i32*) From tonic at nondot.org Tue Feb 17 13:33:52 2009 From: tonic at nondot.org (Tanya Lattner) Date: Tue, 17 Feb 2009 19:33:52 -0000 Subject: [llvm-commits] [llvm] r64790 - in /llvm/branches/release_25: lib/CodeGen/MachineSink.cpp test/CodeGen/X86/pr3522.ll Message-ID: <200902171933.n1HJXqVC015389@zion.cs.uiuc.edu> Author: tbrethou Date: Tue Feb 17 13:33:52 2009 New Revision: 64790 URL: http://llvm.org/viewvc/llvm-project?rev=64790&view=rev Log: Merge 64582 from mainline Fix PR3522. It's not safe to sink into landing pad BB's. Added: llvm/branches/release_25/test/CodeGen/X86/pr3522.ll - copied unchanged from r64582, llvm/trunk/test/CodeGen/X86/pr3522.ll Modified: llvm/branches/release_25/lib/CodeGen/MachineSink.cpp Modified: llvm/branches/release_25/lib/CodeGen/MachineSink.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_25/lib/CodeGen/MachineSink.cpp?rev=64790&r1=64789&r2=64790&view=diff ============================================================================== --- llvm/branches/release_25/lib/CodeGen/MachineSink.cpp (original) +++ llvm/branches/release_25/lib/CodeGen/MachineSink.cpp Tue Feb 17 13:33:52 2009 @@ -208,6 +208,11 @@ // If there are no outputs, it must have side-effects. if (SuccToSinkTo == 0) return false; + + // It's not safe to sink instructions to EH landing pad. Control flow into + // landing pad is implicitly defined. + if (SuccToSinkTo->isLandingPad()) + return false; DEBUG(cerr << "Sink instr " << *MI); DEBUG(cerr << "to block " << *SuccToSinkTo); From gohman at apple.com Tue Feb 17 13:34:54 2009 From: gohman at apple.com (Dan Gohman) Date: Tue, 17 Feb 2009 19:34:54 -0000 Subject: [llvm-commits] [llvm] r64791 - /llvm/trunk/include/llvm/Analysis/LoopPass.h Message-ID: <200902171934.n1HJYsMT015430@zion.cs.uiuc.edu> Author: djg Date: Tue Feb 17 13:34:54 2009 New Revision: 64791 URL: http://llvm.org/viewvc/llvm-project?rev=64791&view=rev Log: Tidy whitespace. Modified: llvm/trunk/include/llvm/Analysis/LoopPass.h Modified: llvm/trunk/include/llvm/Analysis/LoopPass.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopPass.h?rev=64791&r1=64790&r2=64791&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/LoopPass.h (original) +++ llvm/trunk/include/llvm/Analysis/LoopPass.h Tue Feb 17 13:34:54 2009 @@ -27,21 +27,20 @@ class PMStack; class LoopPass : public Pass { - - public: +public: explicit LoopPass(intptr_t pid) : Pass(pid) {} explicit LoopPass(void *pid) : Pass(pid) {} // runOnLoop - This method should be implemented by the subclass to perform // whatever action is necessary for the specified Loop. - virtual bool runOnLoop (Loop *L, LPPassManager &LPM) = 0; - virtual bool runOnFunctionBody (Function &F, LPPassManager &LPM) { - return false; + virtual bool runOnLoop(Loop *L, LPPassManager &LPM) = 0; + virtual bool runOnFunctionBody(Function &F, LPPassManager &LPM) { + return false; } // Initialization and finalization hooks. - virtual bool doInitialization(Loop *L, LPPassManager &LPM) { - return false; + virtual bool doInitialization(Loop *L, LPPassManager &LPM) { + return false; } // Finalization hook does not supply Loop because at this time @@ -82,7 +81,6 @@ }; class LPPassManager : public FunctionPass, public PMDataManager { - public: static char ID; explicit LPPassManager(int Depth); @@ -92,13 +90,13 @@ bool runOnFunction(Function &F); /// Pass Manager itself does not invalidate any analysis info. - // LPPassManager needs LoopInfo. - void getAnalysisUsage(AnalysisUsage &Info) const; - + // LPPassManager needs LoopInfo. + void getAnalysisUsage(AnalysisUsage &Info) const; + virtual const char *getPassName() const { return "Loop Pass Manager"; } - + // Print passes managed by this manager void dumpPassStructure(unsigned Offset) { llvm::cerr << std::string(Offset*2, ' ') << "Loop Pass Manager\n"; @@ -108,21 +106,21 @@ dumpLastUses(P, Offset+1); } } - + Pass *getContainedPass(unsigned N) { - assert ( N < PassVector.size() && "Pass number out of range!"); + assert(N < PassVector.size() && "Pass number out of range!"); Pass *FP = static_cast(PassVector[N]); return FP; } - virtual PassManagerType getPassManagerType() const { - return PMT_LoopPassManager; + virtual PassManagerType getPassManagerType() const { + return PMT_LoopPassManager; } public: // Delete loop from the loop queue and loop nest (LoopInfo). void deleteLoopFromQueue(Loop *L); - + // Insert loop into the loop nest(LoopInfo) and loop queue(LQ). void insertLoop(Loop *L, Loop *ParentLoop); @@ -145,6 +143,7 @@ /// deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes /// that implement simple analysis interface. void deleteSimpleAnalysisValue(Value *V, Loop *L); + private: std::deque LQ; bool skipThisLoop; From evan.cheng at apple.com Tue Feb 17 13:36:01 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 17 Feb 2009 19:36:01 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64792 - /llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Message-ID: <200902171936.n1HJa1kK015540@zion.cs.uiuc.edu> Author: evancheng Date: Tue Feb 17 13:36:00 2009 New Revision: 64792 URL: http://llvm.org/viewvc/llvm-project?rev=64792&view=rev Log: Forgot to check this in last time. This makes sure machine specfic options are passed to llvm backend. Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=64792&r1=64791&r2=64792&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Tue Feb 17 13:36:00 2009 @@ -136,6 +136,9 @@ #ifdef LLVM_SET_TARGET_OPTIONS LLVM_SET_TARGET_OPTIONS(Args); #endif +#ifdef LLVM_SET_MACHINE_OPTIONS + LLVM_SET_MACHINE_OPTIONS(Args); +#endif if (time_report) Args.push_back("--time-passes"); From evan.cheng at apple.com Tue Feb 17 13:38:20 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 17 Feb 2009 19:38:20 -0000 Subject: [llvm-commits] [llvm] r64793 - /llvm/branches/Apple/Dib/lib/AsmParser/LLLexer.cpp Message-ID: <200902171938.n1HJcKSJ015628@zion.cs.uiuc.edu> Author: evancheng Date: Tue Feb 17 13:38:20 2009 New Revision: 64793 URL: http://llvm.org/viewvc/llvm-project?rev=64793&view=rev Log: Bring back vicmp and vfcmp in the Dib branch. Modified: llvm/branches/Apple/Dib/lib/AsmParser/LLLexer.cpp Modified: llvm/branches/Apple/Dib/lib/AsmParser/LLLexer.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/AsmParser/LLLexer.cpp?rev=64793&r1=64792&r2=64793&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/AsmParser/LLLexer.cpp (original) +++ llvm/branches/Apple/Dib/lib/AsmParser/LLLexer.cpp Tue Feb 17 13:38:20 2009 @@ -560,6 +560,7 @@ INSTKEYWORD(shl, Shl); INSTKEYWORD(lshr, LShr); INSTKEYWORD(ashr, AShr); INSTKEYWORD(and, And); INSTKEYWORD(or, Or); INSTKEYWORD(xor, Xor); INSTKEYWORD(icmp, ICmp); INSTKEYWORD(fcmp, FCmp); + INSTKEYWORD(vicmp, VICmp); INSTKEYWORD(vfcmp, VFCmp); INSTKEYWORD(phi, PHI); INSTKEYWORD(call, Call); From kremenek at apple.com Tue Feb 17 13:38:21 2009 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 17 Feb 2009 19:38:21 -0000 Subject: [llvm-commits] [llvm] r64794 - /llvm/tags/checker/checker-0.158/ Message-ID: <200902171938.n1HJcLam015639@zion.cs.uiuc.edu> Author: kremenek Date: Tue Feb 17 13:38:20 2009 New Revision: 64794 URL: http://llvm.org/viewvc/llvm-project?rev=64794&view=rev Log: Tagging checker-0.158. Added: llvm/tags/checker/checker-0.158/ - copied from r64792, llvm/trunk/ From gohman at apple.com Tue Feb 17 13:41:27 2009 From: gohman at apple.com (Dan Gohman) Date: Tue, 17 Feb 2009 19:41:27 -0000 Subject: [llvm-commits] [llvm] r64796 - in /llvm/trunk: include/llvm/Analysis/LoopPass.h lib/Analysis/LoopPass.cpp Message-ID: <200902171941.n1HJfRxY015760@zion.cs.uiuc.edu> Author: djg Date: Tue Feb 17 13:41:26 2009 New Revision: 64796 URL: http://llvm.org/viewvc/llvm-project?rev=64796&view=rev Log: Move dumpPassStructure out of line. Modified: llvm/trunk/include/llvm/Analysis/LoopPass.h llvm/trunk/lib/Analysis/LoopPass.cpp Modified: llvm/trunk/include/llvm/Analysis/LoopPass.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopPass.h?rev=64796&r1=64795&r2=64796&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/LoopPass.h (original) +++ llvm/trunk/include/llvm/Analysis/LoopPass.h Tue Feb 17 13:41:26 2009 @@ -97,15 +97,8 @@ return "Loop Pass Manager"; } - // Print passes managed by this manager - void dumpPassStructure(unsigned Offset) { - llvm::cerr << std::string(Offset*2, ' ') << "Loop Pass Manager\n"; - for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { - Pass *P = getContainedPass(Index); - P->dumpPassStructure(Offset + 1); - dumpLastUses(P, Offset+1); - } - } + /// Print passes managed by this manager + void dumpPassStructure(unsigned Offset); Pass *getContainedPass(unsigned N) { assert(N < PassVector.size() && "Pass number out of range!"); Modified: llvm/trunk/lib/Analysis/LoopPass.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopPass.cpp?rev=64796&r1=64795&r2=64796&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/LoopPass.cpp (original) +++ llvm/trunk/lib/Analysis/LoopPass.cpp Tue Feb 17 13:41:26 2009 @@ -261,6 +261,16 @@ return Changed; } +/// Print passes managed by this manager +void LPPassManager::dumpPassStructure(unsigned Offset) { + llvm::cerr << std::string(Offset*2, ' ') << "Loop Pass Manager\n"; + for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { + Pass *P = getContainedPass(Index); + P->dumpPassStructure(Offset + 1); + dumpLastUses(P, Offset+1); + } +} + //===----------------------------------------------------------------------===// // LoopPass From isanbard at gmail.com Tue Feb 17 14:41:57 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 20:41:57 -0000 Subject: [llvm-commits] [llvm] r64807 - in /llvm/branches/Apple/Dib: lib/CodeGen/VirtRegMap.cpp test/CodeGen/ARM/2008-11-19-ScavengerAssert.ll test/CodeGen/ARM/2009-02-16-SpillerBug.ll Message-ID: <200902172041.n1HKfv0m018125@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 14:41:57 2009 New Revision: 64807 URL: http://llvm.org/viewvc/llvm-project?rev=64807&view=rev Log: --- Merging (from foreign repository) r64745 into '.': A test/CodeGen/ARM/2009-02-16-SpillerBug.ll U test/CodeGen/ARM/2008-11-19-ScavengerAssert.ll U lib/CodeGen/VirtRegMap.cpp A couple of places where reused use operands should be marked kill. This is exposed by recent availability fallthrough changes. Added: llvm/branches/Apple/Dib/test/CodeGen/ARM/2009-02-16-SpillerBug.ll Modified: llvm/branches/Apple/Dib/lib/CodeGen/VirtRegMap.cpp llvm/branches/Apple/Dib/test/CodeGen/ARM/2008-11-19-ScavengerAssert.ll Modified: llvm/branches/Apple/Dib/lib/CodeGen/VirtRegMap.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/VirtRegMap.cpp?rev=64807&r1=64806&r2=64807&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/CodeGen/VirtRegMap.cpp (original) +++ llvm/branches/Apple/Dib/lib/CodeGen/VirtRegMap.cpp Tue Feb 17 14:41:57 2009 @@ -1599,6 +1599,12 @@ PotentialDeadStoreSlots.push_back(ReuseSlot); } + + // Assumes this is the last use. IsKill will be unset if reg is reused + // unless it's a two-address operand. + if (ti == -1) + MI.getOperand(i).setIsKill(); + continue; } // CanReuse @@ -1764,6 +1770,11 @@ DefMO = NextMII->findRegisterDefOperand(DestReg); DefMO->setSubReg(SubIdx); } + + // Mark is killed. + MachineOperand *KillOpnd = NextMII->findRegisterUseOperand(InReg); + KillOpnd->setIsKill(); + BackTracked = true; } else { DOUT << "Removing now-noop copy: " << MI; Modified: llvm/branches/Apple/Dib/test/CodeGen/ARM/2008-11-19-ScavengerAssert.ll URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/CodeGen/ARM/2008-11-19-ScavengerAssert.ll?rev=64807&r1=64806&r2=64807&view=diff ============================================================================== --- llvm/branches/Apple/Dib/test/CodeGen/ARM/2008-11-19-ScavengerAssert.ll (original) +++ llvm/branches/Apple/Dib/test/CodeGen/ARM/2008-11-19-ScavengerAssert.ll Tue Feb 17 14:41:57 2009 @@ -1,5 +1,5 @@ ; RUN: llvm-as < %s | llc -mtriple=arm-apple-darwin9 -; RUN: llvm-as < %s | llc -mtriple=arm-apple-darwin9 -stats |& grep asm-printer | grep 186 +; RUN: llvm-as < %s | llc -mtriple=arm-apple-darwin9 -stats |& grep asm-printer | grep 185 %"struct.Adv5::Ekin<3>" = type <{ i8 }> %"struct.Adv5::X::Energyflux<3>" = type { double } Added: llvm/branches/Apple/Dib/test/CodeGen/ARM/2009-02-16-SpillerBug.ll URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/CodeGen/ARM/2009-02-16-SpillerBug.ll?rev=64807&view=auto ============================================================================== --- llvm/branches/Apple/Dib/test/CodeGen/ARM/2009-02-16-SpillerBug.ll (added) +++ llvm/branches/Apple/Dib/test/CodeGen/ARM/2009-02-16-SpillerBug.ll Tue Feb 17 14:41:57 2009 @@ -0,0 +1,117 @@ +; RUN: llvm-as < %s | llc -march=arm -mattr=+v6,+vfp2 + +target triple = "arm-apple-darwin9" + %struct.FILE_POS = type { i8, i8, i16, i32 } + %struct.FIRST_UNION = type { %struct.FILE_POS } + %struct.FOURTH_UNION = type { %struct.STYLE } + %struct.GAP = type { i8, i8, i16 } + %struct.LIST = type { %struct.rec*, %struct.rec* } + %struct.SECOND_UNION = type { { i16, i8, i8 } } + %struct.STYLE = type { { %struct.GAP }, { %struct.GAP }, i16, i16, i32 } + %struct.THIRD_UNION = type { { [2 x i32], [2 x i32] } } + %struct.head_type = type { [2 x %struct.LIST], %struct.FIRST_UNION, %struct.SECOND_UNION, %struct.THIRD_UNION, %struct.FOURTH_UNION, %struct.rec*, { %struct.rec* }, %struct.rec*, %struct.rec*, %struct.rec*, %struct.rec*, %struct.rec*, %struct.rec*, %struct.rec*, %struct.rec*, i32 } + %struct.rec = type { %struct.head_type } + at no_file_pos = external global %struct.FILE_POS ; <%struct.FILE_POS*> [#uses=1] +@"\01LC13423" = external constant [23 x i8] ; <[23 x i8]*> [#uses=1] +@"\01LC18972" = external constant [13 x i8] ; <[13 x i8]*> [#uses=1] + +define fastcc void @FlushGalley(%struct.rec* %hd) nounwind { +entry: + br label %RESUME + +RESUME: ; preds = %bb520.preheader, %entry + br label %bb396 + +bb122: ; preds = %bb396 + switch i32 0, label %bb394 [ + i32 1, label %bb131 + i32 2, label %bb244 + i32 4, label %bb244 + i32 5, label %bb244 + i32 6, label %bb244 + i32 7, label %bb244 + i32 11, label %bb244 + i32 12, label %bb244 + i32 15, label %bb244 + i32 17, label %bb244 + i32 18, label %bb244 + i32 19, label %bb244 + i32 20, label %bb396 + i32 21, label %bb396 + i32 22, label %bb396 + i32 23, label %bb396 + i32 24, label %bb244 + i32 25, label %bb244 + i32 26, label %bb244 + i32 27, label %bb244 + i32 28, label %bb244 + i32 29, label %bb244 + i32 30, label %bb244 + i32 31, label %bb244 + i32 32, label %bb244 + i32 33, label %bb244 + i32 34, label %bb244 + i32 35, label %bb244 + i32 36, label %bb244 + i32 37, label %bb244 + i32 38, label %bb244 + i32 39, label %bb244 + i32 40, label %bb244 + i32 41, label %bb244 + i32 42, label %bb244 + i32 43, label %bb244 + i32 44, label %bb244 + i32 45, label %bb244 + i32 46, label %bb244 + i32 50, label %bb244 + i32 51, label %bb244 + i32 94, label %bb244 + i32 95, label %bb244 + i32 96, label %bb244 + i32 97, label %bb244 + i32 98, label %bb244 + i32 99, label %bb244 + ] + +bb131: ; preds = %bb122 + br label %bb396 + +bb244: ; preds = %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122, %bb122 + %0 = icmp eq %struct.rec* %stop_link.3, null ; [#uses=1] + br i1 %0, label %bb435, label %bb433 + +bb394: ; preds = %bb122 + call void (i32, i32, i8*, i32, %struct.FILE_POS*, ...)* @Error(i32 1, i32 3, i8* getelementptr ([23 x i8]* @"\01LC13423", i32 0, i32 0), i32 0, %struct.FILE_POS* @no_file_pos, i8* getelementptr ([13 x i8]* @"\01LC18972", i32 0, i32 0), i8* null) nounwind + br label %bb396 + +bb396: ; preds = %bb394, %bb131, %bb122, %bb122, %bb122, %bb122, %RESUME + %stop_link.3 = phi %struct.rec* [ null, %RESUME ], [ %stop_link.3, %bb394 ], [ %stop_link.3, %bb122 ], [ %stop_link.3, %bb122 ], [ %stop_link.3, %bb122 ], [ %stop_link.3, %bb122 ], [ %link.1, %bb131 ] ; <%struct.rec*> [#uses=7] + %headers_seen.1 = phi i32 [ 0, %RESUME ], [ %headers_seen.1, %bb394 ], [ 1, %bb122 ], [ 1, %bb122 ], [ 1, %bb122 ], [ 1, %bb122 ], [ %headers_seen.1, %bb131 ] ; [#uses=2] + %link.1 = load %struct.rec** null ; <%struct.rec*> [#uses=2] + %1 = icmp eq %struct.rec* %link.1, %hd ; [#uses=1] + br i1 %1, label %bb398, label %bb122 + +bb398: ; preds = %bb396 + unreachable + +bb433: ; preds = %bb244 + call fastcc void @Promote(%struct.rec* %hd, %struct.rec* %stop_link.3, %struct.rec* null, i32 1) nounwind + br label %bb435 + +bb435: ; preds = %bb433, %bb244 + br i1 false, label %bb491, label %bb499 + +bb491: ; preds = %bb435 + br label %bb499 + +bb499: ; preds = %bb499, %bb491, %bb435 + %2 = icmp eq %struct.rec* null, null ; [#uses=1] + br i1 %2, label %bb520.preheader, label %bb499 + +bb520.preheader: ; preds = %bb499 + br label %RESUME +} + +declare fastcc void @Promote(%struct.rec*, %struct.rec*, %struct.rec* nocapture, i32) nounwind + +declare void @Error(i32, i32, i8*, i32, %struct.FILE_POS*, ...) nounwind From sabre at nondot.org Tue Feb 17 14:47:23 2009 From: sabre at nondot.org (Chris Lattner) Date: Tue, 17 Feb 2009 20:47:23 -0000 Subject: [llvm-commits] [llvm] r64809 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/zext.ll Message-ID: <200902172047.n1HKlNam018319@zion.cs.uiuc.edu> Author: lattner Date: Tue Feb 17 14:47:23 2009 New Revision: 64809 URL: http://llvm.org/viewvc/llvm-project?rev=64809&view=rev Log: commit a tweaked version of Daniel's patch for PR3599. We now eliminate all the extensions and all but the one required truncate from the testcase, but the or/and/shift stuff still isn't zapped. Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp llvm/trunk/test/Transforms/InstCombine/zext.ll Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=64809&r1=64808&r2=64809&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Tue Feb 17 14:47:23 2009 @@ -8271,32 +8271,35 @@ Value *Src = CI.getOperand(0); - // If this is a cast of a cast - if (CastInst *CSrc = dyn_cast(Src)) { // A->B->C cast - // If this is a TRUNC followed by a ZEXT then we are dealing with integral - // types and if the sizes are just right we can convert this into a logical - // 'and' which will be much cheaper than the pair of casts. - if (isa(CSrc)) { - // Get the sizes of the types involved - Value *A = CSrc->getOperand(0); - uint32_t SrcSize = A->getType()->getPrimitiveSizeInBits(); - uint32_t MidSize = CSrc->getType()->getPrimitiveSizeInBits(); - uint32_t DstSize = CI.getType()->getPrimitiveSizeInBits(); - // If we're actually extending zero bits and the trunc is a no-op - if (MidSize < DstSize && SrcSize == DstSize) { - // Replace both of the casts with an And of the type mask. - APInt AndValue(APInt::getLowBitsSet(SrcSize, MidSize)); - Constant *AndConst = ConstantInt::get(AndValue); - Instruction *And = - BinaryOperator::CreateAnd(CSrc->getOperand(0), AndConst); - // Unfortunately, if the type changed, we need to cast it back. - if (And->getType() != CI.getType()) { - And->setName(CSrc->getName()+".mask"); - InsertNewInstBefore(And, CI); - And = CastInst::CreateIntegerCast(And, CI.getType(), false/*ZExt*/); - } - return And; - } + // If this is a TRUNC followed by a ZEXT then we are dealing with integral + // types and if the sizes are just right we can convert this into a logical + // 'and' which will be much cheaper than the pair of casts. + if (TruncInst *CSrc = dyn_cast(Src)) { // A->B->C cast + // Get the sizes of the types involved. We know that the intermediate type + // will be smaller than A or C, but don't know the relation between A and C. + Value *A = CSrc->getOperand(0); + unsigned SrcSize = A->getType()->getPrimitiveSizeInBits(); + unsigned MidSize = CSrc->getType()->getPrimitiveSizeInBits(); + unsigned DstSize = CI.getType()->getPrimitiveSizeInBits(); + // If we're actually extending zero bits, then if + // SrcSize < DstSize: zext(a & mask) + // SrcSize == DstSize: a & mask + // SrcSize > DstSize: trunc(a) & mask + if (SrcSize < DstSize) { + APInt AndValue(APInt::getLowBitsSet(SrcSize, MidSize)); + Constant *AndConst = ConstantInt::get(AndValue); + Instruction *And = + BinaryOperator::CreateAnd(A, AndConst, CSrc->getName()+".mask"); + InsertNewInstBefore(And, CI); + return new ZExtInst(And, CI.getType()); + } else if (SrcSize == DstSize) { + APInt AndValue(APInt::getLowBitsSet(SrcSize, MidSize)); + return BinaryOperator::CreateAnd(A, ConstantInt::get(AndValue)); + } else if (SrcSize > DstSize) { + Instruction *Trunc = new TruncInst(A, CI.getType(), "tmp"); + InsertNewInstBefore(Trunc, CI); + APInt AndValue(APInt::getLowBitsSet(DstSize, MidSize)); + return BinaryOperator::CreateAnd(Trunc, ConstantInt::get(AndValue)); } } Modified: llvm/trunk/test/Transforms/InstCombine/zext.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/zext.ll?rev=64809&r1=64808&r2=64809&view=diff ============================================================================== --- llvm/trunk/test/Transforms/InstCombine/zext.ll (original) +++ llvm/trunk/test/Transforms/InstCombine/zext.ll Tue Feb 17 14:47:23 2009 @@ -8,3 +8,26 @@ ret i64 %c2 } +; PR3599 +define i32 @test2(i64 %tmp) nounwind readnone { +entry: + %tmp5 = trunc i64 %tmp to i8 ; [#uses=1] + %tmp7 = lshr i64 %tmp, 8 ; [#uses=1] + %tmp8 = trunc i64 %tmp7 to i8 ; [#uses=1] + %tmp10 = lshr i64 %tmp, 16 ; [#uses=1] + %tmp11 = trunc i64 %tmp10 to i8 ; [#uses=1] + %tmp13 = lshr i64 %tmp, 24 ; [#uses=1] + %tmp14 = trunc i64 %tmp13 to i8 ; [#uses=1] + %tmp1 = zext i8 %tmp5 to i32 ; [#uses=1] + %tmp2 = zext i8 %tmp8 to i32 ; [#uses=1] + %tmp3 = shl i32 %tmp2, 8 ; [#uses=1] + %tmp4 = zext i8 %tmp11 to i32 ; [#uses=1] + %tmp6 = shl i32 %tmp4, 16 ; [#uses=1] + %tmp9 = zext i8 %tmp14 to i32 ; [#uses=1] + %tmp12 = shl i32 %tmp9, 24 ; [#uses=1] + %tmp15 = or i32 %tmp12, %tmp1 ; [#uses=1] + %tmp16 = or i32 %tmp15, %tmp6 ; [#uses=1] + %tmp17 = or i32 %tmp16, %tmp3 ; [#uses=1] + ret i32 %tmp17 +} + From gohman at apple.com Tue Feb 17 14:49:49 2009 From: gohman at apple.com (Dan Gohman) Date: Tue, 17 Feb 2009 20:49:49 -0000 Subject: [llvm-commits] [llvm] r64810 - in /llvm/trunk: include/llvm/Analysis/ScalarEvolution.h lib/Analysis/LoopPass.cpp lib/Analysis/ScalarEvolution.cpp lib/Transforms/Scalar/IndVarSimplify.cpp Message-ID: <200902172049.n1HKnopg018457@zion.cs.uiuc.edu> Author: djg Date: Tue Feb 17 14:49:49 2009 New Revision: 64810 URL: http://llvm.org/viewvc/llvm-project?rev=64810&view=rev Log: Add a method to ScalarEvolution for telling it when a loop has been modified in a way that may effect the trip count calculation. Change IndVars to use this method when it rewrites pointer or floating-point induction variables instead of using a doInitialization method to sneak these changes in before ScalarEvolution has a chance to see the loop. This eliminates the need for LoopPass to depend on ScalarEvolution. Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolution.h llvm/trunk/lib/Analysis/LoopPass.cpp llvm/trunk/lib/Analysis/ScalarEvolution.cpp llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolution.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolution.h?rev=64810&r1=64809&r2=64810&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/ScalarEvolution.h (original) +++ llvm/trunk/include/llvm/Analysis/ScalarEvolution.h Tue Feb 17 14:49:49 2009 @@ -301,6 +301,11 @@ /// an analyzable loop-invariant iteration count. bool hasLoopInvariantIterationCount(const Loop *L) const; + /// forgetLoopIterationCount - This method should be called by the + /// client when it has changed a loop in a way that may effect + /// ScalarEvolution's ability to compute a trip count. + void forgetLoopIterationCount(const Loop *L); + /// deleteValueFromRecords - This method should be called by the /// client before it removes a Value from the program, to make sure /// that no dangling references are left around. Modified: llvm/trunk/lib/Analysis/LoopPass.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopPass.cpp?rev=64810&r1=64809&r2=64810&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/LoopPass.cpp (original) +++ llvm/trunk/lib/Analysis/LoopPass.cpp Tue Feb 17 14:49:49 2009 @@ -14,7 +14,6 @@ //===----------------------------------------------------------------------===// #include "llvm/Analysis/LoopPass.h" -#include "llvm/Analysis/ScalarEvolution.h" using namespace llvm; //===----------------------------------------------------------------------===// @@ -173,8 +172,6 @@ // LPPassManager needs LoopInfo. In the long term LoopInfo class will // become part of LPPassManager. Info.addRequired(); - // Used by IndVar doInitialization. - Info.addRequired(); Info.setPreservesAll(); } Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=64810&r1=64809&r2=64810&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original) +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Tue Feb 17 14:49:49 2009 @@ -1453,6 +1453,11 @@ /// an analyzable loop-invariant iteration count. bool hasLoopInvariantIterationCount(const Loop *L); + /// forgetLoopIterationCount - This method should be called by the + /// client when it has changed a loop in a way that may effect + /// ScalarEvolution's ability to compute a trip count. + void forgetLoopIterationCount(const Loop *L); + /// getIterationCount - If the specified loop has a predictable iteration /// count, return it. Note that it is not valid to call this method on a /// loop without a loop-invariant iteration count. @@ -1931,6 +1936,13 @@ return I->second; } +/// forgetLoopIterationCount - This method should be called by the +/// client when it has changed a loop in a way that may effect +/// ScalarEvolution's ability to compute a trip count. +void ScalarEvolutionsImpl::forgetLoopIterationCount(const Loop *L) { + IterationCounts.erase(L); +} + /// ComputeIterationCount - Compute the number of times the specified loop /// will iterate. SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) { @@ -3091,6 +3103,10 @@ return !isa(getIterationCount(L)); } +void ScalarEvolution::forgetLoopIterationCount(const Loop *L) { + return ((ScalarEvolutionsImpl*)Impl)->forgetLoopIterationCount(L); +} + SCEVHandle ScalarEvolution::getSCEVAtScope(Value *V, const Loop *L) const { return ((ScalarEvolutionsImpl*)Impl)->getSCEVAtScope(getSCEV(V), L); } Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=64810&r1=64809&r2=64810&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Tue Feb 17 14:49:49 2009 @@ -74,8 +74,8 @@ static char ID; // Pass identification, replacement for typeid IndVarSimplify() : LoopPass(&ID) {} - bool runOnLoop(Loop *L, LPPassManager &LPM); - bool doInitialization(Loop *L, LPPassManager &LPM); + virtual bool runOnLoop(Loop *L, LPPassManager &LPM); + virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); AU.addRequiredID(LCSSAID); @@ -88,6 +88,8 @@ private: + void RewriteNonIntegerIVs(Loop *L); + void EliminatePointerRecurrence(PHINode *PN, BasicBlock *Preheader, SmallPtrSet &DeadInsts); void LinearFunctionTestReplace(Loop *L, SCEVHandle IterationCount, @@ -411,16 +413,13 @@ DeleteTriviallyDeadInstructions(InstructionsToDelete); } -bool IndVarSimplify::doInitialization(Loop *L, LPPassManager &LPM) { - - Changed = false; +void IndVarSimplify::RewriteNonIntegerIVs(Loop *L) { // First step. Check to see if there are any trivial GEP pointer recurrences. // If there are, change them into integer recurrences, permitting analysis by // the SCEV routines. // BasicBlock *Header = L->getHeader(); BasicBlock *Preheader = L->getLoopPreheader(); - SE = &LPM.getAnalysis(); SmallPtrSet DeadInsts; for (BasicBlock::iterator I = Header->begin(); isa(I); ++I) { @@ -431,10 +430,14 @@ HandleFloatingPointIV(L, PN, DeadInsts); } + // If the loop previously had a pointer or floating-point IV, ScalarEvolution + // may not have been able to compute a trip count. Now that we've done some + // re-writing, the trip count may be computable. + if (Changed) + SE->forgetLoopIterationCount(L); + if (!DeadInsts.empty()) DeleteTriviallyDeadInstructions(DeadInsts); - - return Changed; } /// getEffectiveIndvarType - Determine the widest type that the @@ -594,8 +597,12 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { LI = &getAnalysis(); SE = &getAnalysis(); - Changed = false; + + // If there are any floating-point or pointer recurrences, attempt to + // transform them to use integer recurrences. + RewriteNonIntegerIVs(L); + BasicBlock *Header = L->getHeader(); BasicBlock *ExitingBlock = L->getExitingBlock(); SmallPtrSet DeadInsts; From gohman at apple.com Tue Feb 17 14:50:11 2009 From: gohman at apple.com (Dan Gohman) Date: Tue, 17 Feb 2009 20:50:11 -0000 Subject: [llvm-commits] [llvm] r64811 - /llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp Message-ID: <200902172050.n1HKoBTM018478@zion.cs.uiuc.edu> Author: djg Date: Tue Feb 17 14:50:11 2009 New Revision: 64811 URL: http://llvm.org/viewvc/llvm-project?rev=64811&view=rev Log: LoopIndexSplit doesn't actually use ScalarEvolution. Modified: llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp Modified: llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp?rev=64811&r1=64810&r2=64811&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp Tue Feb 17 14:50:11 2009 @@ -44,7 +44,7 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/IntrinsicInst.h" #include "llvm/Analysis/LoopPass.h" -#include "llvm/Analysis/ScalarEvolutionExpander.h" +#include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Analysis/Dominators.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/Cloning.h" @@ -70,7 +70,6 @@ bool runOnLoop(Loop *L, LPPassManager &LPM); void getAnalysisUsage(AnalysisUsage &AU) const { - AU.addRequired(); AU.addPreserved(); AU.addRequiredID(LCSSAID); AU.addPreservedID(LCSSAID); @@ -174,7 +173,6 @@ Loop *L; LPPassManager *LPM; LoopInfo *LI; - ScalarEvolution *SE; DominatorTree *DT; DominanceFrontier *DF; @@ -205,7 +203,6 @@ if (!L->getSubLoops().empty()) return false; - SE = &getAnalysis(); DT = &getAnalysis(); LI = &getAnalysis(); DF = &getAnalysis(); From rafael.espindola at gmail.com Tue Feb 17 15:08:22 2009 From: rafael.espindola at gmail.com (Rafael Espindola) Date: Tue, 17 Feb 2009 21:08:22 -0000 Subject: [llvm-commits] [llvm] r64812 - /llvm/trunk/tools/gold/gold-plugin.cpp Message-ID: <200902172108.n1HL8Mk5019285@zion.cs.uiuc.edu> Author: rafael Date: Tue Feb 17 15:08:21 2009 New Revision: 64812 URL: http://llvm.org/viewvc/llvm-project?rev=64812&view=rev Log: tools like nm and ar only need register_claim_file and add_symbols. Don't abort if other hooks are missing. Modified: llvm/trunk/tools/gold/gold-plugin.cpp Modified: llvm/trunk/tools/gold/gold-plugin.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=64812&r1=64811&r2=64812&view=diff ============================================================================== --- llvm/trunk/tools/gold/gold-plugin.cpp (original) +++ llvm/trunk/tools/gold/gold-plugin.cpp Tue Feb 17 15:08:21 2009 @@ -142,11 +142,16 @@ } } - if (!registeredClaimFile || !registeredAllSymbolsRead || !registeredCleanup || - !add_symbols || !get_symbols || !add_input_file) { - (*message)(LDPL_ERROR, "Not all hooks registered for LLVMgold."); - return LDPS_ERR; - } + if (!registeredClaimFile) + { + (*message)(LDPL_ERROR, "register_claim_file not passed to LLVMgold."); + return LDPS_ERR; + } + if (!add_symbols) + { + (*message)(LDPL_ERROR, "add_symbols not passed to LLVMgold."); + return LDPS_ERR; + } return LDPS_OK; } From isanbard at gmail.com Tue Feb 17 15:11:51 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 21:11:51 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64813 - in /llvm-gcc-4.2/trunk/gcc: cgraph.c cgraphunit.c ipa.c Message-ID: <200902172111.n1HLBpZu019523@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 15:11:51 2009 New Revision: 64813 URL: http://llvm.org/viewvc/llvm-project?rev=64813&view=rev Log: The IS_EXTERN_INLINE is already defined with ENABLE_LLVM in mind. No need for the #ifdefs here. Modified: llvm-gcc-4.2/trunk/gcc/cgraph.c llvm-gcc-4.2/trunk/gcc/cgraphunit.c llvm-gcc-4.2/trunk/gcc/ipa.c Modified: llvm-gcc-4.2/trunk/gcc/cgraph.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/cgraph.c?rev=64813&r1=64812&r2=64813&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/cgraph.c (original) +++ llvm-gcc-4.2/trunk/gcc/cgraph.c Tue Feb 17 15:11:51 2009 @@ -600,13 +600,8 @@ struct cgraph_node *n = (struct cgraph_node *) *slot; if (!n->next_clone && !n->global.inlined_to && (cgraph_global_info_ready - /* LLVM LOCAL begin - extern inline */ -#ifdef ENABLE_LLVM + /* LLVM LOCAL extern inline */ && (TREE_ASM_WRITTEN (n->decl) || IS_EXTERN_INLINE (n->decl)))) -#else - && (TREE_ASM_WRITTEN (n->decl) || DECL_EXTERNAL (n->decl)))) -#endif - /* LLVM LOCAL end - extern inline */ kill_body = true; } @@ -1189,13 +1184,8 @@ good optimization is what this optimization is about. */ else if (!(*targetm.binds_local_p) (node->decl) - /* LLVM LOCAL begin - extern inline */ -#ifdef ENABLE_LLVM + /* LLVM LOCAL extern inline */ && !DECL_COMDAT (node->decl) && !IS_EXTERN_INLINE (node->decl)) -#else - && !DECL_COMDAT (node->decl) && !DECL_EXTERNAL (node->decl)) -#endif - /* LLVM LOCAL end - extern inline */ avail = AVAIL_OVERWRITABLE; else avail = AVAIL_AVAILABLE; Modified: llvm-gcc-4.2/trunk/gcc/cgraphunit.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/cgraphunit.c?rev=64813&r1=64812&r2=64813&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/cgraphunit.c (original) +++ llvm-gcc-4.2/trunk/gcc/cgraphunit.c Tue Feb 17 15:11:51 2009 @@ -384,13 +384,8 @@ n->next_needed = NULL; if (!n->global.inlined_to && !n->alias - /* LLVM LOCAL begin - extern inline */ -#ifdef ENABLE_LLVM + /* LLVM LOCAL extern inline */ && !IS_EXTERN_INLINE (n->decl)) -#else - && !DECL_EXTERNAL (n->decl)) -#endif - /* LLVM LOCAL end - extern inline */ { cgraph_expand_function (n); output = true; @@ -853,13 +848,8 @@ if (node->analyzed && DECL_SAVED_TREE (node->decl) && !TREE_ASM_WRITTEN (node->decl) - /* LLVM LOCAL begin - extern inline */ -#ifdef ENABLE_LLVM + /* LLVM LOCAL extern inline */ && (!IS_EXTERN_INLINE (node->decl) || node->global.inlined_to)) -#else - && (!DECL_EXTERNAL (node->decl) || node->global.inlined_to)) -#endif - /* LLVM LOCAL end - extern inline */ { if (this_cfun->cfg) { @@ -1304,40 +1294,24 @@ && (node->needed || (e && node->reachable)) && !TREE_ASM_WRITTEN (decl) - /* LLVM LOCAL begin - extern inline */ -#ifdef ENABLE_LLVM + /* LLVM LOCAL extern inline */ && !IS_EXTERN_INLINE (decl)) -#else - && !DECL_EXTERNAL (decl)) -#endif - /* LLVM LOCAL end - extern inline */ node->output = 1; else { /* We should've reclaimed all functions that are not needed. */ #ifdef ENABLE_CHECKING if (!node->global.inlined_to && DECL_SAVED_TREE (decl) - /* LLVM LOCAL begin - extern inline */ -#ifdef ENABLE_LLVM + /* LLVM LOCAL extern inline */ && !IS_EXTERN_INLINE (decl)) -#else - && !DECL_EXTERNAL (decl)) -#endif - /* LLVM LOCAL end - extern inline */ { dump_cgraph_node (stderr, node); internal_error ("failed to reclaim unneeded function"); } #endif - /* LLVM LOCAL begin - extern inline */ -#ifdef ENABLE_LLVM + /* LLVM LOCAL extern inline */ gcc_assert (node->global.inlined_to || !DECL_SAVED_TREE (decl) || IS_EXTERN_INLINE (decl)); -#else - gcc_assert (node->global.inlined_to || !DECL_SAVED_TREE (decl) - || DECL_EXTERNAL (decl)); -#endif - /* LLVM LOCAL end - extern inline */ } } } Modified: llvm-gcc-4.2/trunk/gcc/ipa.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/ipa.c?rev=64813&r1=64812&r2=64813&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/ipa.c (original) +++ llvm-gcc-4.2/trunk/gcc/ipa.c Tue Feb 17 15:11:51 2009 @@ -112,13 +112,8 @@ #endif for (node = cgraph_nodes; node; node = node->next) if (node->needed && !node->global.inlined_to - /* LLVM LOCAL begin - extern inline */ -#ifdef ENABLE_LLVM + /* LLVM LOCAL extern inline */ && ((!IS_EXTERN_INLINE (node->decl)) -#else - && ((!DECL_EXTERNAL (node->decl)) -#endif - /* LLVM LOCAL end - extern inline */ || !node->analyzed || before_inlining_p)) { @@ -141,13 +136,8 @@ if (!e->callee->aux && node->analyzed && (!e->inline_failed || !e->callee->analyzed - /* LLVM LOCAL begin - extern inline */ -#ifdef ENABLE_LLVM + /* LLVM LOCAL extern inline */ || !IS_EXTERN_INLINE(e->callee->decl) -#else - || (!DECL_EXTERNAL (e->callee->decl)) -#endif - /* LLVM LOCAL end - extern inline */ || before_inlining_p)) { e->callee->aux = first; @@ -178,13 +168,8 @@ local_insns = 0; if (file) fprintf (file, " %s", cgraph_node_name (node)); - /* LLVM LOCAL begin - extern inline */ -#ifdef ENABLE_LLVM + /* LLVM LOCAL extern inline */ if (!node->analyzed || !IS_EXTERN_INLINE(node->decl) -#else - if (!node->analyzed || !DECL_EXTERNAL (node->decl) -#endif - /* LLVM LOCAL end - extern inline */ || before_inlining_p) cgraph_remove_node (node); else From wendling at apple.com Tue Feb 17 15:11:51 2009 From: wendling at apple.com (Bill Wendling) Date: Tue, 17 Feb 2009 13:11:51 -0800 Subject: [llvm-commits] [llvm-gcc-4.2] r64584 - /llvm-gcc-4.2/trunk/gcc/cgraphunit.c In-Reply-To: References: <200902151125.n1FBPs0e003747@zion.cs.uiuc.edu> Message-ID: <4B3D7B43-D877-45B6-8261-2DC2D5D72016@apple.com> Done. -bw On Feb 17, 2009, at 10:34 AM, Dale Johannesen wrote: > > On Feb 15, 2009, at 3:25 AMPST, Bill Wendling wrote: >> >> @@ -1331,13 +1331,8 @@ >> #endif >> gcc_assert (node->global.inlined_to || !DECL_SAVED_TREE (decl) >> /* LLVM LOCAL begin - extern inline */ >> -#ifdef ENABLE_LLVM >> || IS_EXTERN_INLINE (decl)); >> -#else >> - || DECL_EXTERNAL (decl)); >> -#endif >> /* LLVM LOCAL end - extern inline */ > > This is the wrong idea. IS_EXTERN_INLINE is defined as > > #ifdef ENABLE_LLVM > #define IS_EXTERN_INLINE(f) (DECL_EXTERNAL(f) && \ > !lookup_attribute("always_inline", DECL_ATTRIBUTES(f))) > #else > #define IS_EXTERN_INLINE(f) (DECL_EXTERNAL(f)) > #endif > > so it reduces to DECL_EXTERNAL in the non-LLVM build. There should > be no #ifdef's at any of the call sites, please remove them. > From Alireza.Moshtaghi at microchip.com Tue Feb 17 15:14:18 2009 From: Alireza.Moshtaghi at microchip.com (Alireza.Moshtaghi at microchip.com) Date: Tue, 17 Feb 2009 14:14:18 -0700 Subject: [llvm-commits] r64000 breaks PIC16 In-Reply-To: <230B69F8-151B-4A71-A439-EA20C3A1395A@apple.com> References: <1234292444.7110.7.camel@idc-lt-i00171.microchip.com><3BEE949D-7D28-4B3F-A69C-3E972C8716A9@apple.com><1234324706.4728.5.camel@idc-lt-i00171.microchip.com><9D65B45B-C932-40F7-BC02-991AB1817188@apple.com> <230B69F8-151B-4A71-A439-EA20C3A1395A@apple.com> Message-ID: Thanks, That worked, A. > -----Original Message----- > From: llvm-commits-bounces at cs.uiuc.edu [mailto:llvm-commits- > bounces at cs.uiuc.edu] On Behalf Of Chris Lattner > Sent: Tuesday, February 17, 2009 11:59 AM > To: Commit Messages and Patches for LLVM > Subject: Re: [llvm-commits] r64000 breaks PIC16 > > > On Feb 17, 2009, at 10:14 AM, Alireza.Moshtaghi at microchip.com wrote: > > > Hi Chris, > > I was busy with some other stuff and just now got to try this... > > The flag SDNPOutFlag is set for subfw but the sinker does not look at > > it. I have to also set the flag SDNPSideEffect for it to work > > correctly. > > Now the question is SDNPOutFlag not a reason for keeping the > > instruction > > in its place? Or there may be need to for some corrections in the > > sinker? > > Hi Ali, > > This needs to be a property on the machine instruction, not on the dag > node. The X86 backend uses: > > let Defs = [EFLAGS] in { > > } > > around instructions that define the flags for example. You can also > use the "Imp" helper to set this on specific instructions. > > -Chris > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits From tonic at nondot.org Tue Feb 17 15:17:01 2009 From: tonic at nondot.org (Tanya Lattner) Date: Tue, 17 Feb 2009 21:17:01 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64814 - in /llvm-gcc-4.2/branches/release_25/gcc: fortran/decl.c fortran/intrinsic.c fortran/match.c fortran/matchexp.c fortran/module.c fortran/primary.c fortran/symbol.c stub-c.c Message-ID: <200902172117.n1HLH1CV019760@zion.cs.uiuc.edu> Author: tbrethou Date: Tue Feb 17 15:17:01 2009 New Revision: 64814 URL: http://llvm.org/viewvc/llvm-project?rev=64814&view=rev Log: Merge r64598 and r64597 from mainline. Provide some default return values for the functions. This silences the warning and thus unbreaks apple-style build (which is -Werror) Fix format strings weirdness of fortran f.e. This caused warnings and thus broke apple-style build (which is -Werror) Modified: llvm-gcc-4.2/branches/release_25/gcc/fortran/decl.c llvm-gcc-4.2/branches/release_25/gcc/fortran/intrinsic.c llvm-gcc-4.2/branches/release_25/gcc/fortran/match.c llvm-gcc-4.2/branches/release_25/gcc/fortran/matchexp.c llvm-gcc-4.2/branches/release_25/gcc/fortran/module.c llvm-gcc-4.2/branches/release_25/gcc/fortran/primary.c llvm-gcc-4.2/branches/release_25/gcc/fortran/symbol.c llvm-gcc-4.2/branches/release_25/gcc/stub-c.c Modified: llvm-gcc-4.2/branches/release_25/gcc/fortran/decl.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/release_25/gcc/fortran/decl.c?rev=64814&r1=64813&r2=64814&view=diff ============================================================================== --- llvm-gcc-4.2/branches/release_25/gcc/fortran/decl.c (original) +++ llvm-gcc-4.2/branches/release_25/gcc/fortran/decl.c Tue Feb 17 15:17:01 2009 @@ -367,7 +367,7 @@ gfc_free_expr (expr); if (msg != NULL) { - gfc_error (msg); + gfc_error ("%s", msg); return MATCH_ERROR; } tail->repeat = tmp; @@ -1450,7 +1450,7 @@ msg = gfc_extract_int (e, &ts->kind); if (msg != NULL) { - gfc_error (msg); + gfc_error ("%s", msg); m = MATCH_ERROR; goto no_match; } Modified: llvm-gcc-4.2/branches/release_25/gcc/fortran/intrinsic.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/release_25/gcc/fortran/intrinsic.c?rev=64814&r1=64813&r2=64814&view=diff ============================================================================== --- llvm-gcc-4.2/branches/release_25/gcc/fortran/intrinsic.c (original) +++ llvm-gcc-4.2/branches/release_25/gcc/fortran/intrinsic.c Tue Feb 17 15:17:01 2009 @@ -126,7 +126,7 @@ sprintf (name, "__convert_%c%d_%c%d", gfc_type_letter (from->type), from->kind, gfc_type_letter (to->type), to->kind); - return gfc_get_string (name); + return gfc_get_string ("%s", name); } @@ -249,11 +249,11 @@ break; case SZ_NOTHING: - next_sym->name = gfc_get_string (name); + next_sym->name = gfc_get_string ("%s", name); strcpy (buf, "_gfortran_"); strcat (buf, name); - next_sym->lib_name = gfc_get_string (buf); + next_sym->lib_name = gfc_get_string ("%s", buf); next_sym->elemental = elemental; next_sym->actual_ok = actual_ok; @@ -871,7 +871,7 @@ case SZ_NOTHING: next_sym[0] = next_sym[-1]; - next_sym->name = gfc_get_string (name); + next_sym->name = gfc_get_string ("%s", name); next_sym++; break; Modified: llvm-gcc-4.2/branches/release_25/gcc/fortran/match.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/release_25/gcc/fortran/match.c?rev=64814&r1=64813&r2=64814&view=diff ============================================================================== --- llvm-gcc-4.2/branches/release_25/gcc/fortran/match.c (original) +++ llvm-gcc-4.2/branches/release_25/gcc/fortran/match.c Tue Feb 17 15:17:01 2009 @@ -212,7 +212,7 @@ if (p != NULL) { - gfc_error (p); + gfc_error ("%s", p); m = MATCH_ERROR; } Modified: llvm-gcc-4.2/branches/release_25/gcc/fortran/matchexp.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/release_25/gcc/fortran/matchexp.c?rev=64814&r1=64813&r2=64814&view=diff ============================================================================== --- llvm-gcc-4.2/branches/release_25/gcc/fortran/matchexp.c (original) +++ llvm-gcc-4.2/branches/release_25/gcc/fortran/matchexp.c Tue Feb 17 15:17:01 2009 @@ -198,7 +198,7 @@ return MATCH_YES; syntax: - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); return MATCH_ERROR; } @@ -493,7 +493,7 @@ m = match_ext_add_operand (&e); if (m == MATCH_NO) { - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); m = MATCH_ERROR; } } @@ -532,7 +532,7 @@ m = match_ext_add_operand (&e); if (m == MATCH_NO) - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); if (m != MATCH_YES) { gfc_free_expr (all); @@ -583,7 +583,7 @@ m = match_level_2 (&e); if (m == MATCH_NO) { - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); gfc_free_expr (all); } if (m != MATCH_YES) @@ -641,7 +641,7 @@ m = match_level_3 (&right); if (m == MATCH_NO) - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); if (m != MATCH_YES) { gfc_free_expr (left); @@ -744,7 +744,7 @@ m = match_and_operand (&e); if (m == MATCH_NO) - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); if (m != MATCH_YES) { gfc_free_expr (all); @@ -787,7 +787,7 @@ m = match_or_operand (&e); if (m == MATCH_NO) - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); if (m != MATCH_YES) { gfc_free_expr (all); @@ -841,7 +841,7 @@ m = match_equiv_operand (&e); if (m == MATCH_NO) - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); if (m != MATCH_YES) { gfc_free_expr (all); @@ -900,7 +900,7 @@ m = match_level_5 (&e); if (m == MATCH_NO) - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); if (m != MATCH_YES) { gfc_free_expr (all); Modified: llvm-gcc-4.2/branches/release_25/gcc/fortran/module.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/release_25/gcc/fortran/module.c?rev=64814&r1=64813&r2=64814&view=diff ============================================================================== --- llvm-gcc-4.2/branches/release_25/gcc/fortran/module.c (original) +++ llvm-gcc-4.2/branches/release_25/gcc/fortran/module.c Tue Feb 17 15:17:01 2009 @@ -716,9 +716,9 @@ gfc_symbol sym; int c; - sym.name = gfc_get_string (name); + sym.name = gfc_get_string ("%s", name); if (module != NULL) - sym.module = gfc_get_string (module); + sym.module = gfc_get_string ("%s", module); else sym.module = NULL; t.sym = &sym; @@ -1404,7 +1404,7 @@ else { require_atom (ATOM_STRING); - *stringp = atom_string[0] == '\0' ? NULL : gfc_get_string (atom_string); + *stringp = atom_string[0] == '\0' ? NULL : gfc_get_string ("%s", atom_string); gfc_free (atom_string); } } @@ -2617,7 +2617,7 @@ else { require_atom (ATOM_STRING); - e->value.function.name = gfc_get_string (atom_string); + e->value.function.name = gfc_get_string ("%s", atom_string); gfc_free (atom_string); mio_integer (&flag); @@ -3198,7 +3198,7 @@ } sym = gfc_new_symbol (p->u.rsym.true_name, ns); - sym->module = gfc_get_string (p->u.rsym.module); + sym->module = gfc_get_string ("%s", p->u.rsym.module); associate_integer_pointer (p, sym); } @@ -3420,7 +3420,7 @@ gfc_new_symbol (info->u.rsym.true_name, gfc_current_ns); - sym->module = gfc_get_string (info->u.rsym.module); + sym->module = gfc_get_string ("%s", info->u.rsym.module); } st->n.sym = sym; @@ -3656,7 +3656,7 @@ sym = st->n.sym; if (sym->module == NULL) - sym->module = gfc_get_string (module_name); + sym->module = gfc_get_string ("%s", module_name); if (sym->attr.flavor == FL_PROCEDURE && sym->attr.generic && !sym->attr.subroutine && !sym->attr.function) @@ -3735,7 +3735,7 @@ return; if (sym->module == NULL) - sym->module = gfc_get_string (module_name); + sym->module = gfc_get_string ("%s", module_name); mio_symbol_interface (&sym->name, &sym->module, &sym->generic); } Modified: llvm-gcc-4.2/branches/release_25/gcc/fortran/primary.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/release_25/gcc/fortran/primary.c?rev=64814&r1=64813&r2=64814&view=diff ============================================================================== --- llvm-gcc-4.2/branches/release_25/gcc/fortran/primary.c (original) +++ llvm-gcc-4.2/branches/release_25/gcc/fortran/primary.c Tue Feb 17 15:17:01 2009 @@ -254,7 +254,7 @@ msg = gfc_extract_int (e, &num); if (msg != NULL) { - gfc_error (msg); + gfc_error ("%s", msg); goto cleanup; } if (num == 0) @@ -925,7 +925,7 @@ q = gfc_extract_int (sym->value, &kind); if (q != NULL) { - gfc_error (q); + gfc_error ("%s", q); return MATCH_ERROR; } } @@ -1432,7 +1432,7 @@ } } - actual->name = gfc_get_string (name); + actual->name = gfc_get_string ("%s", name); return MATCH_YES; cleanup: Modified: llvm-gcc-4.2/branches/release_25/gcc/fortran/symbol.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/release_25/gcc/fortran/symbol.c?rev=64814&r1=64813&r2=64814&view=diff ============================================================================== --- llvm-gcc-4.2/branches/release_25/gcc/fortran/symbol.c (original) +++ llvm-gcc-4.2/branches/release_25/gcc/fortran/symbol.c Tue Feb 17 15:17:01 2009 @@ -1327,7 +1327,7 @@ else tail->next = p; - p->name = gfc_get_string (name); + p->name = gfc_get_string ("%s", name); p->loc = gfc_current_locus; *component = p; @@ -1788,7 +1788,7 @@ gfc_symtree *st; st = gfc_getmem (sizeof (gfc_symtree)); - st->name = gfc_get_string (name); + st->name = gfc_get_string ("%s", name); gfc_insert_bbt (root, st, compare_symtree); return st; @@ -1804,7 +1804,7 @@ st0 = gfc_find_symtree (*root, name); - st.name = gfc_get_string (name); + st.name = gfc_get_string ("%s", name); gfc_delete_bbt (root, &st, compare_symtree); gfc_free (st0); @@ -1849,7 +1849,7 @@ st = gfc_new_symtree (&gfc_current_ns->uop_root, name); uop = st->n.uop = gfc_getmem (sizeof (gfc_user_op)); - uop->name = gfc_get_string (name); + uop->name = gfc_get_string ("%s", name); uop->access = ACCESS_UNKNOWN; uop->ns = gfc_current_ns; @@ -1919,7 +1919,7 @@ if (strlen (name) > GFC_MAX_SYMBOL_LEN) gfc_internal_error ("new_symbol(): Symbol name too long"); - p->name = gfc_get_string (name); + p->name = gfc_get_string ("%s", name); return p; } @@ -2702,7 +2702,7 @@ s = gfc_getmem (sizeof (gfc_gsymbol)); s->type = GSYM_UNKNOWN; - s->name = gfc_get_string (name); + s->name = gfc_get_string ("%s", name); gfc_insert_bbt (&gfc_gsym_root, s, gsym_compare); Modified: llvm-gcc-4.2/branches/release_25/gcc/stub-c.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/release_25/gcc/stub-c.c?rev=64814&r1=64813&r2=64814&view=diff ============================================================================== --- llvm-gcc-4.2/branches/release_25/gcc/stub-c.c (original) +++ llvm-gcc-4.2/branches/release_25/gcc/stub-c.c Tue Feb 17 15:17:01 2009 @@ -40,6 +40,7 @@ tree iasm_addr (tree e ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } @@ -49,6 +50,7 @@ tree v2 ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } @@ -80,6 +82,7 @@ bool iasm_is_pseudo (const char *opcode ATTRIBUTE_UNUSED) { gcc_assert(0); + return false; } @@ -105,6 +108,7 @@ tree rhs ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } @@ -113,6 +117,7 @@ tree decl_constant_value (tree decl ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } @@ -122,6 +127,7 @@ tree params ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } @@ -130,6 +136,7 @@ tree build_stmt (enum tree_code code ATTRIBUTE_UNUSED, ...) { gcc_assert(0); + return NULL; } @@ -138,6 +145,7 @@ tree lookup_name (tree name ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } @@ -148,6 +156,7 @@ tree intop ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } @@ -168,6 +177,7 @@ size_t * numUniChars ATTRIBUTE_UNUSED) { gcc_assert(0); + return false; } tree create_init_utf16_var (const unsigned char *, size_t, @@ -179,4 +189,5 @@ size_t * numUniChars ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } From dpatel at apple.com Tue Feb 17 15:24:00 2009 From: dpatel at apple.com (Devang Patel) Date: Tue, 17 Feb 2009 21:24:00 -0000 Subject: [llvm-commits] [llvm] r64815 - in /llvm/trunk: include/llvm/Analysis/DebugInfo.h lib/Analysis/DebugInfo.cpp lib/CodeGen/AsmPrinter/DwarfWriter.cpp test/FrontendC/2009-02-17-BitField-dbg.c Message-ID: <200902172124.n1HLO0BA020090@zion.cs.uiuc.edu> Author: dpatel Date: Tue Feb 17 15:23:59 2009 New Revision: 64815 URL: http://llvm.org/viewvc/llvm-project?rev=64815&view=rev Log: Emit debug info for bitfields. Added: llvm/trunk/test/FrontendC/2009-02-17-BitField-dbg.c Modified: llvm/trunk/include/llvm/Analysis/DebugInfo.h llvm/trunk/lib/Analysis/DebugInfo.cpp llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Modified: llvm/trunk/include/llvm/Analysis/DebugInfo.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/DebugInfo.h?rev=64815&r1=64814&r2=64815&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/DebugInfo.h (original) +++ llvm/trunk/include/llvm/Analysis/DebugInfo.h Tue Feb 17 15:23:59 2009 @@ -118,9 +118,9 @@ /// code generator accepts maximum one main compile unit per module. If a /// module does not contain any main compile unit then the code generator /// will emit multiple compile units in the output object file. - bool isMain() const { return getUnsignedField(6); } - bool isOptimized() const { return getUnsignedField(7); } - std::string getFlags() const { return getStringField(8); } + bool isMain() const { return getUnsignedField(6); } + bool isOptimized() const { return getUnsignedField(7); } + std::string getFlags() const { return getStringField(8); } /// Verify - Verify that a compile unit is well formed. bool Verify() const; @@ -217,6 +217,9 @@ explicit DIDerivedType(GlobalVariable *GV); DIType getTypeDerivedFrom() const { return getFieldAs(9); } + /// getOriginalTypeSize - If this type is derived from a base type then + /// return base type size. + uint64_t getOriginalTypeSize() const; /// dump - print derived type. void dump() const; }; Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=64815&r1=64814&r2=64815&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/DebugInfo.cpp (original) +++ llvm/trunk/lib/Analysis/DebugInfo.cpp Tue Feb 17 15:23:59 2009 @@ -169,8 +169,8 @@ } } -DIVariable::DIVariable(GlobalVariable *GV) : DIDescriptor(GV) { - if (GV && !isVariable(getTag())) +DIVariable::DIVariable(GlobalVariable *gv) : DIDescriptor(gv) { + if (gv && !isVariable(getTag())) GV = 0; } @@ -273,7 +273,16 @@ return true; } - +/// getOriginalTypeSize - If this type is derived from a base type then +/// return base type size. +uint64_t DIDerivedType::getOriginalTypeSize() const { + if (getTag() != dwarf::DW_TAG_member) + return getSizeInBits(); + DIType BT = getTypeDerivedFrom(); + if (BT.getTag() != dwarf::DW_TAG_base_type) + return getSizeInBits(); + return BT.getSizeInBits(); +} //===----------------------------------------------------------------------===// // DIFactory: Basic Helpers Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp?rev=64815&r1=64814&r2=64815&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp (original) +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Tue Feb 17 15:23:59 2009 @@ -1873,7 +1873,24 @@ AddSourceLine(MemberDie, &DT); - // FIXME _ Handle bitfields + uint64_t Size = DT.getSizeInBits(); + uint64_t FieldSize = DT.getOriginalTypeSize(); + + if (Size != FieldSize) { + // Handle bitfield. + AddUInt(MemberDie, DW_AT_byte_size, 0, DT.getOriginalTypeSize() >> 3); + AddUInt(MemberDie, DW_AT_bit_size, 0, DT.getSizeInBits()); + + uint64_t Offset = DT.getOffsetInBits(); + uint64_t FieldOffset = Offset; + uint64_t AlignMask = ~(DT.getAlignInBits() - 1); + uint64_t HiMark = (Offset + FieldSize) & AlignMask; + FieldOffset = (HiMark - FieldSize); + Offset -= FieldOffset; + // Maybe we need to work from the other end. + if (TD->isLittleEndian()) Offset = FieldSize - (Offset + Size); + AddUInt(MemberDie, DW_AT_bit_offset, 0, Offset); + } DIEBlock *Block = new DIEBlock(); AddUInt(Block, 0, DW_FORM_data1, DW_OP_plus_uconst); AddUInt(Block, 0, DW_FORM_udata, DT.getOffsetInBits() >> 3); Added: llvm/trunk/test/FrontendC/2009-02-17-BitField-dbg.c URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FrontendC/2009-02-17-BitField-dbg.c?rev=64815&view=auto ============================================================================== --- llvm/trunk/test/FrontendC/2009-02-17-BitField-dbg.c (added) +++ llvm/trunk/test/FrontendC/2009-02-17-BitField-dbg.c Tue Feb 17 15:23:59 2009 @@ -0,0 +1,13 @@ +// Check bitfields. +// RUN: %llvmgcc -S -O0 -g %s -o - | llvm-as | \ +// RUN: llc --disable-fp-elim -o 2009-02-17-BitField-dbg.s -f +// RUN: %compile_c 2009-02-17-BitField-dbg.s -o 2009-02-17-BitField-dbg.o +// RUN: echo {ptype mystruct} > %t2 +// RUN: gdb -q -batch -n -x %t2 2009-02-17-BitField-dbg.o | \ +// RUN: tee 2009-02-17-BitField-dbg.out | grep "int a : 4" + +struct { + int a:4; + int b:2; +} mystruct; + From isanbard at gmail.com Tue Feb 17 15:24:55 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 21:24:55 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64816 - in /llvm-gcc-4.2/branches/Apple/Dib/gcc: config/arm/arm.h config/i386/i386.h config/rs6000/rs6000.h llvm-backend.cpp Message-ID: <200902172124.n1HLOuB5020133@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 15:24:55 2009 New Revision: 64816 URL: http://llvm.org/viewvc/llvm-project?rev=64816&view=rev Log: --- Merging (from foreign repository) r64506 into '.': U gcc/config/i386/i386.h U gcc/config/rs6000/rs6000.h U gcc/config/arm/arm.h Translate -msoft-float to -soft-float. --- Merging (from foreign repository) r64792 into '.': U gcc/llvm-backend.cpp Forgot to check this in last time. This makes sure machine specfic options are passed to llvm backend. Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/config/arm/arm.h llvm-gcc-4.2/branches/Apple/Dib/gcc/config/i386/i386.h llvm-gcc-4.2/branches/Apple/Dib/gcc/config/rs6000/rs6000.h llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-backend.cpp Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/config/arm/arm.h URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/config/arm/arm.h?rev=64816&r1=64815&r2=64816&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/config/arm/arm.h (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/config/arm/arm.h Tue Feb 17 15:24:55 2009 @@ -2922,6 +2922,10 @@ #define LLVM_OVERRIDE_TARGET_ARCH() \ (TARGET_THUMB ? "thumb" : "") +#define LLVM_SET_MACHINE_OPTIONS(argvec) \ + if (TARGET_SOFT_FLAT) \ + argvec.push_back("-soft-float"); + /* Doing struct copy by partial-word loads and stores is not a good idea on ARM. */ #define TARGET_LLVM_MIN_BYTES_COPY_BY_MEMCPY 4 Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/config/i386/i386.h URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/config/i386/i386.h?rev=64816&r1=64815&r2=64816&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/config/i386/i386.h (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/config/i386/i386.h Tue Feb 17 15:24:55 2009 @@ -3892,6 +3892,10 @@ if (TARGET_3DNOW) F.AddFeature("3dnow"); \ if (TARGET_3DNOW_A) F.AddFeature("3dnowa"); \ } + +#define LLVM_SET_MACHINE_OPTIONS(argvec) \ + if (!TARGET_80387) \ + argvec.push_back("-soft-float"); /* LLVM ABI definition macros. */ Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/config/rs6000/rs6000.h URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/config/rs6000/rs6000.h?rev=64816&r1=64815&r2=64816&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/config/rs6000/rs6000.h (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/config/rs6000/rs6000.h Tue Feb 17 15:24:55 2009 @@ -3464,6 +3464,10 @@ F.AddFeature("64bit", TARGET_POWERPC64); \ } +#define LLVM_SET_MACHINE_OPTIONS(argvec) \ + if (TARGET_SOFT_FLAT) \ + argvec.push_back("-soft-float"); + /* When -m64 is specified, set the architecture to powerpc64-os-blah even if the * compiler was configured for powerpc-os-blah. */ Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-backend.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-backend.cpp?rev=64816&r1=64815&r2=64816&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-backend.cpp (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-backend.cpp Tue Feb 17 15:24:55 2009 @@ -137,6 +137,9 @@ #ifdef LLVM_SET_TARGET_OPTIONS LLVM_SET_TARGET_OPTIONS(Args); #endif +#ifdef LLVM_SET_MACHINE_OPTIONS + LLVM_SET_MACHINE_OPTIONS(Args); +#endif if (time_report) Args.push_back("--time-passes"); From isanbard at gmail.com Tue Feb 17 15:26:49 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 21:26:49 -0000 Subject: [llvm-commits] [llvm] r64817 - in /llvm/branches/Apple/Dib: lib/Target/X86/X86ISelLowering.cpp test/CodeGen/X86/soft-fp.ll Message-ID: <200902172126.n1HLQnmi020222@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 15:26:48 2009 New Revision: 64817 URL: http://llvm.org/viewvc/llvm-project?rev=64817&view=rev Log: --- Merging (from foreign repository) r64496 into '.': A test/CodeGen/X86/soft-fp.ll U lib/Target/X86/X86ISelLowering.cpp Teach x86 target -soft-float. Added: llvm/branches/Apple/Dib/test/CodeGen/X86/soft-fp.ll Modified: llvm/branches/Apple/Dib/lib/Target/X86/X86ISelLowering.cpp Modified: llvm/branches/Apple/Dib/lib/Target/X86/X86ISelLowering.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Target/X86/X86ISelLowering.cpp?rev=64817&r1=64816&r2=64817&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Target/X86/X86ISelLowering.cpp (original) +++ llvm/branches/Apple/Dib/lib/Target/X86/X86ISelLowering.cpp Tue Feb 17 15:26:48 2009 @@ -375,7 +375,7 @@ else setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); - if (X86ScalarSSEf64) { + if (!UseSoftFloat && X86ScalarSSEf64) { // f32 and f64 use SSE. // Set up the FP register classes. addRegisterClass(MVT::f32, X86::FR32RegisterClass); @@ -413,7 +413,7 @@ setConvertAction(MVT::f80, MVT::f32, Expand); setConvertAction(MVT::f80, MVT::f64, Expand); } - } else if (X86ScalarSSEf32) { + } else if (!UseSoftFloat && X86ScalarSSEf32) { // Use SSE for f32, x87 for f64. // Set up the FP register classes. addRegisterClass(MVT::f32, X86::FR32RegisterClass); @@ -458,7 +458,7 @@ setOperationAction(ISD::FSIN , MVT::f64 , Expand); setOperationAction(ISD::FCOS , MVT::f64 , Expand); } - } else { + } else if (!UseSoftFloat) { // f32 and f64 in x87. // Set up the FP register classes. addRegisterClass(MVT::f64, X86::RFP64RegisterClass); @@ -493,28 +493,30 @@ } // Long double always uses X87. - addRegisterClass(MVT::f80, X86::RFP80RegisterClass); - setOperationAction(ISD::UNDEF, MVT::f80, Expand); - setOperationAction(ISD::FCOPYSIGN, MVT::f80, Expand); - { - bool ignored; - APFloat TmpFlt(+0.0); - TmpFlt.convert(APFloat::x87DoubleExtended, APFloat::rmNearestTiesToEven, - &ignored); - addLegalFPImmediate(TmpFlt); // FLD0 - TmpFlt.changeSign(); - addLegalFPImmediate(TmpFlt); // FLD0/FCHS - APFloat TmpFlt2(+1.0); - TmpFlt2.convert(APFloat::x87DoubleExtended, APFloat::rmNearestTiesToEven, - &ignored); - addLegalFPImmediate(TmpFlt2); // FLD1 - TmpFlt2.changeSign(); - addLegalFPImmediate(TmpFlt2); // FLD1/FCHS - } + if (!UseSoftFloat) { + addRegisterClass(MVT::f80, X86::RFP80RegisterClass); + setOperationAction(ISD::UNDEF, MVT::f80, Expand); + setOperationAction(ISD::FCOPYSIGN, MVT::f80, Expand); + { + bool ignored; + APFloat TmpFlt(+0.0); + TmpFlt.convert(APFloat::x87DoubleExtended, APFloat::rmNearestTiesToEven, + &ignored); + addLegalFPImmediate(TmpFlt); // FLD0 + TmpFlt.changeSign(); + addLegalFPImmediate(TmpFlt); // FLD0/FCHS + APFloat TmpFlt2(+1.0); + TmpFlt2.convert(APFloat::x87DoubleExtended, APFloat::rmNearestTiesToEven, + &ignored); + addLegalFPImmediate(TmpFlt2); // FLD1 + TmpFlt2.changeSign(); + addLegalFPImmediate(TmpFlt2); // FLD1/FCHS + } - if (!UnsafeFPMath) { - setOperationAction(ISD::FSIN , MVT::f80 , Expand); - setOperationAction(ISD::FCOS , MVT::f80 , Expand); + if (!UnsafeFPMath) { + setOperationAction(ISD::FSIN , MVT::f80 , Expand); + setOperationAction(ISD::FCOS , MVT::f80 , Expand); + } } // Always use a library call for pow. @@ -578,7 +580,9 @@ setOperationAction(ISD::FEXP2, (MVT::SimpleValueType)VT, Expand); } - if (!DisableMMX && Subtarget->hasMMX()) { + // FIXME: In order to prevent SSE instructions being expanded to MMX ones + // with -msoft-float, disable use of MMX as well. + if (!UseSoftFloat && !DisableMMX && Subtarget->hasMMX()) { addRegisterClass(MVT::v8i8, X86::VR64RegisterClass); addRegisterClass(MVT::v4i16, X86::VR64RegisterClass); addRegisterClass(MVT::v2i32, X86::VR64RegisterClass); @@ -660,7 +664,7 @@ setOperationAction(ISD::SELECT, MVT::v1i64, Custom); } - if (Subtarget->hasSSE1()) { + if (!UseSoftFloat && Subtarget->hasSSE1()) { addRegisterClass(MVT::v4f32, X86::VR128RegisterClass); setOperationAction(ISD::FADD, MVT::v4f32, Legal); @@ -677,8 +681,11 @@ setOperationAction(ISD::VSETCC, MVT::v4f32, Custom); } - if (Subtarget->hasSSE2()) { + if (!UseSoftFloat && Subtarget->hasSSE2()) { addRegisterClass(MVT::v2f64, X86::VR128RegisterClass); + + // FIXME: Unfortunately -soft-float means XMM registers cannot be used even + // for integer operations. addRegisterClass(MVT::v16i8, X86::VR128RegisterClass); addRegisterClass(MVT::v8i16, X86::VR128RegisterClass); addRegisterClass(MVT::v4i32, X86::VR128RegisterClass); @@ -756,7 +763,7 @@ setOperationAction(ISD::SELECT, MVT::v2i64, Custom); } - + if (Subtarget->hasSSE41()) { // FIXME: Do we need to handle scalar-to-vector here? setOperationAction(ISD::MUL, MVT::v4i32, Legal); @@ -1398,9 +1405,11 @@ unsigned NumXMMRegs = CCInfo.getFirstUnallocated(XMMArgRegs, TotalNumXMMRegs); - assert((Subtarget->hasSSE1() || !NumXMMRegs) && + assert(!(NumXMMRegs && !Subtarget->hasSSE1()) && + "SSE register cannot be used when SSE is disabled!"); + assert(!(NumXMMRegs && UseSoftFloat) && "SSE register cannot be used when SSE is disabled!"); - if (!Subtarget->hasSSE1()) { + if (UseSoftFloat || !Subtarget->hasSSE1()) { // Kernel mode asks for SSE to be disabled, so don't push them // on the stack. TotalNumXMMRegs = 0; Added: llvm/branches/Apple/Dib/test/CodeGen/X86/soft-fp.ll URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/CodeGen/X86/soft-fp.ll?rev=64817&view=auto ============================================================================== --- llvm/branches/Apple/Dib/test/CodeGen/X86/soft-fp.ll (added) +++ llvm/branches/Apple/Dib/test/CodeGen/X86/soft-fp.ll Tue Feb 17 15:26:48 2009 @@ -0,0 +1,27 @@ +; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse2 -soft-float | not grep xmm +; RUN: llvm-as < %s | llc -march=x86-64 -mattr=+sse2 -soft-float | not grep xmm + + %struct.__va_list_tag = type { i32, i32, i8*, i8* } + +define i32 @t1(i32 %a, ...) nounwind { +entry: + %va = alloca [1 x %struct.__va_list_tag], align 8 ; <[1 x %struct.__va_list_tag]*> [#uses=2] + %va12 = bitcast [1 x %struct.__va_list_tag]* %va to i8* ; [#uses=2] + call void @llvm.va_start(i8* %va12) + %va3 = getelementptr [1 x %struct.__va_list_tag]* %va, i64 0, i64 0 ; <%struct.__va_list_tag*> [#uses=1] + call void @bar(%struct.__va_list_tag* %va3) nounwind + call void @llvm.va_end(i8* %va12) + ret i32 undef +} + +declare void @llvm.va_start(i8*) nounwind + +declare void @bar(%struct.__va_list_tag*) + +declare void @llvm.va_end(i8*) nounwind + +define float @t2(float %a, float %b) nounwind readnone { +entry: + %0 = add float %a, %b ; [#uses=1] + ret float %0 +} From isanbard at gmail.com Tue Feb 17 15:34:45 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 21:34:45 -0000 Subject: [llvm-commits] [llvm] r64818 - in /llvm/branches/Apple/Dib: include/llvm/Analysis/DebugInfo.h lib/Analysis/DebugInfo.cpp lib/CodeGen/AsmPrinter/DwarfWriter.cpp test/FrontendC/2009-02-17-BitField-dbg.c Message-ID: <200902172134.n1HLYjZA020698@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 15:34:44 2009 New Revision: 64818 URL: http://llvm.org/viewvc/llvm-project?rev=64818&view=rev Log: --- Merging (from foreign repository) r64815 into '.': A test/FrontendC/2009-02-17-BitField-dbg.c U include/llvm/Analysis/DebugInfo.h U lib/Analysis/DebugInfo.cpp U lib/CodeGen/AsmPrinter/DwarfWriter.cpp Emit debug info for bitfields. Added: llvm/branches/Apple/Dib/test/FrontendC/2009-02-17-BitField-dbg.c Modified: llvm/branches/Apple/Dib/include/llvm/Analysis/DebugInfo.h llvm/branches/Apple/Dib/lib/Analysis/DebugInfo.cpp llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Modified: llvm/branches/Apple/Dib/include/llvm/Analysis/DebugInfo.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/Analysis/DebugInfo.h?rev=64818&r1=64817&r2=64818&view=diff ============================================================================== --- llvm/branches/Apple/Dib/include/llvm/Analysis/DebugInfo.h (original) +++ llvm/branches/Apple/Dib/include/llvm/Analysis/DebugInfo.h Tue Feb 17 15:34:44 2009 @@ -118,9 +118,9 @@ /// code generator accepts maximum one main compile unit per module. If a /// module does not contain any main compile unit then the code generator /// will emit multiple compile units in the output object file. - bool isMain() const { return getUnsignedField(6); } - bool isOptimized() const { return getUnsignedField(7); } - std::string getFlags() const { return getStringField(8); } + bool isMain() const { return getUnsignedField(6); } + bool isOptimized() const { return getUnsignedField(7); } + std::string getFlags() const { return getStringField(8); } /// Verify - Verify that a compile unit is well formed. bool Verify() const; @@ -217,6 +217,9 @@ explicit DIDerivedType(GlobalVariable *GV); DIType getTypeDerivedFrom() const { return getFieldAs(9); } + /// getOriginalTypeSize - If this type is derived from a base type then + /// return base type size. + uint64_t getOriginalTypeSize() const; /// dump - print derived type. void dump() const; }; Modified: llvm/branches/Apple/Dib/lib/Analysis/DebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Analysis/DebugInfo.cpp?rev=64818&r1=64817&r2=64818&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Analysis/DebugInfo.cpp (original) +++ llvm/branches/Apple/Dib/lib/Analysis/DebugInfo.cpp Tue Feb 17 15:34:44 2009 @@ -169,8 +169,8 @@ } } -DIVariable::DIVariable(GlobalVariable *GV) : DIDescriptor(GV) { - if (GV && !isVariable(getTag())) +DIVariable::DIVariable(GlobalVariable *gv) : DIDescriptor(gv) { + if (gv && !isVariable(getTag())) GV = 0; } @@ -273,7 +273,16 @@ return true; } - +/// getOriginalTypeSize - If this type is derived from a base type then +/// return base type size. +uint64_t DIDerivedType::getOriginalTypeSize() const { + if (getTag() != dwarf::DW_TAG_member) + return getSizeInBits(); + DIType BT = getTypeDerivedFrom(); + if (BT.getTag() != dwarf::DW_TAG_base_type) + return getSizeInBits(); + return BT.getSizeInBits(); +} //===----------------------------------------------------------------------===// // DIFactory: Basic Helpers Modified: llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp?rev=64818&r1=64817&r2=64818&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp (original) +++ llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Tue Feb 17 15:34:44 2009 @@ -1870,7 +1870,24 @@ AddSourceLine(MemberDie, &DT); - // FIXME _ Handle bitfields + uint64_t Size = DT.getSizeInBits(); + uint64_t FieldSize = DT.getOriginalTypeSize(); + + if (Size != FieldSize) { + // Handle bitfield. + AddUInt(MemberDie, DW_AT_byte_size, 0, DT.getOriginalTypeSize() >> 3); + AddUInt(MemberDie, DW_AT_bit_size, 0, DT.getSizeInBits()); + + uint64_t Offset = DT.getOffsetInBits(); + uint64_t FieldOffset = Offset; + uint64_t AlignMask = ~(DT.getAlignInBits() - 1); + uint64_t HiMark = (Offset + FieldSize) & AlignMask; + FieldOffset = (HiMark - FieldSize); + Offset -= FieldOffset; + // Maybe we need to work from the other end. + if (TD->isLittleEndian()) Offset = FieldSize - (Offset + Size); + AddUInt(MemberDie, DW_AT_bit_offset, 0, Offset); + } DIEBlock *Block = new DIEBlock(); AddUInt(Block, 0, DW_FORM_data1, DW_OP_plus_uconst); AddUInt(Block, 0, DW_FORM_udata, DT.getOffsetInBits() >> 3); Added: llvm/branches/Apple/Dib/test/FrontendC/2009-02-17-BitField-dbg.c URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/FrontendC/2009-02-17-BitField-dbg.c?rev=64818&view=auto ============================================================================== --- llvm/branches/Apple/Dib/test/FrontendC/2009-02-17-BitField-dbg.c (added) +++ llvm/branches/Apple/Dib/test/FrontendC/2009-02-17-BitField-dbg.c Tue Feb 17 15:34:44 2009 @@ -0,0 +1,13 @@ +// Check bitfields. +// RUN: %llvmgcc -S -O0 -g %s -o - | llvm-as | \ +// RUN: llc --disable-fp-elim -o 2009-02-17-BitField-dbg.s -f +// RUN: %compile_c 2009-02-17-BitField-dbg.s -o 2009-02-17-BitField-dbg.o +// RUN: echo {ptype mystruct} > %t2 +// RUN: gdb -q -batch -n -x %t2 2009-02-17-BitField-dbg.o | \ +// RUN: tee 2009-02-17-BitField-dbg.out | grep "int a : 4" + +struct { + int a:4; + int b:2; +} mystruct; + From evan.cheng at apple.com Tue Feb 17 15:39:28 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 17 Feb 2009 21:39:28 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64819 - /llvm-gcc-4.2/trunk/gcc/tree-optimize.c Message-ID: <200902172139.n1HLdT8p020871@zion.cs.uiuc.edu> Author: evancheng Date: Tue Feb 17 15:39:28 2009 New Revision: 64819 URL: http://llvm.org/viewvc/llvm-project?rev=64819&view=rev Log: Do not run optimize_inline_calls since llvm-gcc doesn't use gcc inliner any more. Modified: llvm-gcc-4.2/trunk/gcc/tree-optimize.c Modified: llvm-gcc-4.2/trunk/gcc/tree-optimize.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/tree-optimize.c?rev=64819&r1=64818&r2=64819&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/tree-optimize.c (original) +++ llvm-gcc-4.2/trunk/gcc/tree-optimize.c Tue Feb 17 15:39:28 2009 @@ -439,6 +439,8 @@ cfun->x_dont_save_pending_sizes_p = 1; cfun->after_inlining = true; +/* LLVM LOCAL begin */ +#ifndef ENABLE_LLVM if (flag_inline_trees) { struct cgraph_edge *e; @@ -452,6 +454,8 @@ timevar_pop (TV_INTEGRATION); } } +#endif +/* LLVM LOCAL end */ /* In non-unit-at-a-time we must mark all referenced functions as needed. */ if (!flag_unit_at_a_time) From isanbard at gmail.com Tue Feb 17 15:50:01 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 21:50:01 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64821 - /llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-optimize.c Message-ID: <200902172150.n1HLo2jo021273@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 15:50:01 2009 New Revision: 64821 URL: http://llvm.org/viewvc/llvm-project?rev=64821&view=rev Log: --- Merging (from foreign repository) r64819 into '.': U gcc/tree-optimize.c Do not run optimize_inline_calls since llvm-gcc doesn't use gcc inliner any more. Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-optimize.c Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-optimize.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-optimize.c?rev=64821&r1=64820&r2=64821&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-optimize.c (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-optimize.c Tue Feb 17 15:50:01 2009 @@ -439,6 +439,8 @@ cfun->x_dont_save_pending_sizes_p = 1; cfun->after_inlining = true; +/* LLVM LOCAL begin */ +#ifndef ENABLE_LLVM if (flag_inline_trees) { struct cgraph_edge *e; @@ -452,6 +454,8 @@ timevar_pop (TV_INTEGRATION); } } +#endif +/* LLVM LOCAL end */ /* In non-unit-at-a-time we must mark all referenced functions as needed. */ if (!flag_unit_at_a_time) From isanbard at gmail.com Tue Feb 17 15:52:02 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 21:52:02 -0000 Subject: [llvm-commits] [llvm] r64822 - /llvm/branches/Apple/Dib/lib/Transforms/Scalar/ScalarReplAggregates.cpp Message-ID: <200902172152.n1HLq2Zw021389@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 15:52:02 2009 New Revision: 64822 URL: http://llvm.org/viewvc/llvm-project?rev=64822&view=rev Log: Update SROA to TOT. Modified: llvm/branches/Apple/Dib/lib/Transforms/Scalar/ScalarReplAggregates.cpp Modified: llvm/branches/Apple/Dib/lib/Transforms/Scalar/ScalarReplAggregates.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/Scalar/ScalarReplAggregates.cpp?rev=64822&r1=64821&r2=64822&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Transforms/Scalar/ScalarReplAggregates.cpp (original) +++ llvm/branches/Apple/Dib/lib/Transforms/Scalar/ScalarReplAggregates.cpp Tue Feb 17 15:52:02 2009 @@ -34,6 +34,7 @@ #include "llvm/Transforms/Utils/Local.h" #include "llvm/Support/Debug.h" #include "llvm/Support/GetElementPtrTypeIterator.h" +#include "llvm/Support/IRBuilder.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/Compiler.h" #include "llvm/ADT/SmallVector.h" @@ -127,13 +128,13 @@ void RewriteLoadUserOfWholeAlloca(LoadInst *LI, AllocationInst *AI, SmallVector &NewElts); - const Type *CanConvertToScalar(Value *V, bool &IsNotTrivial); - void ConvertToScalar(AllocationInst *AI, const Type *Ty); - void ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, unsigned Offset); - Value *ConvertUsesOfLoadToScalar(LoadInst *LI, AllocaInst *NewAI, - unsigned Offset); - Value *ConvertUsesOfStoreToScalar(StoreInst *SI, AllocaInst *NewAI, - unsigned Offset); + bool CanConvertToScalar(Value *V, bool &IsNotTrivial, const Type *&VecTy, + bool &SawVec, uint64_t Offset, unsigned AllocaSize); + void ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, uint64_t Offset); + Value *ConvertScalar_ExtractValue(Value *NV, const Type *ToType, + uint64_t Offset, IRBuilder<> &Builder); + Value *ConvertScalar_InsertValue(Value *StoredVal, Value *ExistingVal, + uint64_t Offset, IRBuilder<> &Builder); static Instruction *isOnlyCopiedFromConstantGlobal(AllocationInst *AI); }; } @@ -225,17 +226,38 @@ AI->eraseFromParent(); continue; } + + // If this alloca is impossible for us to promote, reject it early. + if (AI->isArrayAllocation() || !AI->getAllocatedType()->isSized()) + continue; + + // Check to see if this allocation is only modified by a memcpy/memmove from + // a constant global. If this is the case, we can change all users to use + // the constant global instead. This is commonly produced by the CFE by + // constructs like "void foo() { int A[] = {1,2,3,4,5,6,7,8,9...}; }" if 'A' + // is only subsequently read. + if (Instruction *TheCopy = isOnlyCopiedFromConstantGlobal(AI)) { + DOUT << "Found alloca equal to global: " << *AI; + DOUT << " memcpy = " << *TheCopy; + Constant *TheSrc = cast(TheCopy->getOperand(2)); + AI->replaceAllUsesWith(ConstantExpr::getBitCast(TheSrc, AI->getType())); + TheCopy->eraseFromParent(); // Don't mutate the global. + AI->eraseFromParent(); + ++NumGlobals; + Changed = true; + continue; + } // Check to see if we can perform the core SROA transformation. We cannot // transform the allocation instruction if it is an array allocation // (allocations OF arrays are ok though), and an allocation of a scalar // value cannot be decomposed at all. - if (!AI->isArrayAllocation() && - (isa(AI->getAllocatedType()) || + uint64_t AllocaSize = TD->getTypePaddedSize(AI->getAllocatedType()); + + if ((isa(AI->getAllocatedType()) || isa(AI->getAllocatedType())) && - AI->getAllocatedType()->isSized() && - // Do not promote any struct whose size is larger than "128" bytes. - TD->getTypePaddedSize(AI->getAllocatedType()) < SRThreshold && + // Do not promote any struct whose size is too big. + AllocaSize < SRThreshold && // Do not promote any struct into more than "32" separate vars. getNumSAElements(AI->getAllocatedType()) < SRThreshold/4) { // Check that all of the users of the allocation are capable of being @@ -253,35 +275,47 @@ continue; } } - - // Check to see if this allocation is only modified by a memcpy/memmove from - // a constant global. If this is the case, we can change all users to use - // the constant global instead. This is commonly produced by the CFE by - // constructs like "void foo() { int A[] = {1,2,3,4,5,6,7,8,9...}; }" if 'A' - // is only subsequently read. - if (Instruction *TheCopy = isOnlyCopiedFromConstantGlobal(AI)) { - DOUT << "Found alloca equal to global: " << *AI; - DOUT << " memcpy = " << *TheCopy; - Constant *TheSrc = cast(TheCopy->getOperand(2)); - AI->replaceAllUsesWith(ConstantExpr::getBitCast(TheSrc, AI->getType())); - TheCopy->eraseFromParent(); // Don't mutate the global. - AI->eraseFromParent(); - ++NumGlobals; - Changed = true; - continue; - } // If we can turn this aggregate value (potentially with casts) into a // simple scalar value that can be mem2reg'd into a register value. + // IsNotTrivial tracks whether this is something that mem2reg could have + // promoted itself. If so, we don't want to transform it needlessly. Note + // that we can't just check based on the type: the alloca may be of an i32 + // but that has pointer arithmetic to set byte 3 of it or something. bool IsNotTrivial = false; - if (const Type *ActualType = CanConvertToScalar(AI, IsNotTrivial)) - if (IsNotTrivial && ActualType != Type::VoidTy) { - ConvertToScalar(AI, ActualType); - Changed = true; - continue; + const Type *VectorTy = 0; + bool HadAVector = false; + if (CanConvertToScalar(AI, IsNotTrivial, VectorTy, HadAVector, + 0, unsigned(AllocaSize)) && IsNotTrivial) { + AllocaInst *NewAI; + // If we were able to find a vector type that can handle this with + // insert/extract elements, and if there was at least one use that had + // a vector type, promote this to a vector. We don't want to promote + // random stuff that doesn't use vectors (e.g. <9 x double>) because then + // we just get a lot of insert/extracts. If at least one vector is + // involved, then we probably really do have a union of vector/array. + if (VectorTy && isa(VectorTy) && HadAVector) { + DOUT << "CONVERT TO VECTOR: " << *AI << " TYPE = " << *VectorTy <<"\n"; + + // Create and insert the vector alloca. + NewAI = new AllocaInst(VectorTy, 0, "", AI->getParent()->begin()); + ConvertUsesToScalar(AI, NewAI, 0); + } else { + DOUT << "CONVERT TO SCALAR INTEGER: " << *AI << "\n"; + + // Create and insert the integer alloca. + const Type *NewTy = IntegerType::get(AllocaSize*8); + NewAI = new AllocaInst(NewTy, 0, "", AI->getParent()->begin()); + ConvertUsesToScalar(AI, NewAI, 0); } + NewAI->takeName(AI); + AI->eraseFromParent(); + ++NumConverted; + Changed = true; + continue; + } - // Otherwise, couldn't process this. + // Otherwise, couldn't process this alloca. } return Changed; @@ -1108,47 +1142,52 @@ gep_type_iterator I = gep_type_begin(GEPI); ++I; - if (const ArrayType *AT = dyn_cast(*I)) { - uint64_t NumElements = AT->getNumElements(); + const ArrayType *AT = dyn_cast(*I); + if (!AT) + return; + + uint64_t NumElements = AT->getNumElements(); + + if (isa(I.getOperand())) + return; + + if (NumElements == 1) { + GEPI->setOperand(2, Constant::getNullValue(Type::Int32Ty)); + return; + } - if (!isa(I.getOperand())) { - if (NumElements == 1) { - GEPI->setOperand(2, Constant::getNullValue(Type::Int32Ty)); - } else { - assert(NumElements == 2 && "Unhandled case!"); - // All users of the GEP must be loads. At each use of the GEP, insert - // two loads of the appropriate indexed GEP and select between them. - Value *IsOne = new ICmpInst(ICmpInst::ICMP_NE, I.getOperand(), - Constant::getNullValue(I.getOperand()->getType()), - "isone", GEPI); - // Insert the new GEP instructions, which are properly indexed. - SmallVector Indices(GEPI->op_begin()+1, GEPI->op_end()); - Indices[1] = Constant::getNullValue(Type::Int32Ty); - Value *ZeroIdx = GetElementPtrInst::Create(GEPI->getOperand(0), - Indices.begin(), - Indices.end(), - GEPI->getName()+".0", GEPI); - Indices[1] = ConstantInt::get(Type::Int32Ty, 1); - Value *OneIdx = GetElementPtrInst::Create(GEPI->getOperand(0), - Indices.begin(), - Indices.end(), - GEPI->getName()+".1", GEPI); - // Replace all loads of the variable index GEP with loads from both - // indexes and a select. - while (!GEPI->use_empty()) { - LoadInst *LI = cast(GEPI->use_back()); - Value *Zero = new LoadInst(ZeroIdx, LI->getName()+".0", LI); - Value *One = new LoadInst(OneIdx , LI->getName()+".1", LI); - Value *R = SelectInst::Create(IsOne, One, Zero, LI->getName(), LI); - LI->replaceAllUsesWith(R); - LI->eraseFromParent(); - } - GEPI->eraseFromParent(); - } - } + assert(NumElements == 2 && "Unhandled case!"); + // All users of the GEP must be loads. At each use of the GEP, insert + // two loads of the appropriate indexed GEP and select between them. + Value *IsOne = new ICmpInst(ICmpInst::ICMP_NE, I.getOperand(), + Constant::getNullValue(I.getOperand()->getType()), + "isone", GEPI); + // Insert the new GEP instructions, which are properly indexed. + SmallVector Indices(GEPI->op_begin()+1, GEPI->op_end()); + Indices[1] = Constant::getNullValue(Type::Int32Ty); + Value *ZeroIdx = GetElementPtrInst::Create(GEPI->getOperand(0), + Indices.begin(), + Indices.end(), + GEPI->getName()+".0", GEPI); + Indices[1] = ConstantInt::get(Type::Int32Ty, 1); + Value *OneIdx = GetElementPtrInst::Create(GEPI->getOperand(0), + Indices.begin(), + Indices.end(), + GEPI->getName()+".1", GEPI); + // Replace all loads of the variable index GEP with loads from both + // indexes and a select. + while (!GEPI->use_empty()) { + LoadInst *LI = cast(GEPI->use_back()); + Value *Zero = new LoadInst(ZeroIdx, LI->getName()+".0", LI); + Value *One = new LoadInst(OneIdx , LI->getName()+".1", LI); + Value *R = SelectInst::Create(IsOne, One, Zero, LI->getName(), LI); + LI->replaceAllUsesWith(R); + LI->eraseFromParent(); } + GEPI->eraseFromParent(); } + /// CleanupAllocaUsers - If SROA reported that it can promote the specified /// allocation, but only if cleaned up, perform the cleanups required. void SROA::CleanupAllocaUsers(AllocationInst *AI) { @@ -1174,229 +1213,132 @@ } } -/// MergeInType - Add the 'In' type to the accumulated type so far. If the -/// types are incompatible, return true, otherwise update Accum and return -/// false. +/// MergeInType - Add the 'In' type to the accumulated type (Accum) so far at +/// the offset specified by Offset (which is specified in bytes). /// -/// There are three cases we handle here: -/// 1) An effectively-integer union, where the pieces are stored into as -/// smaller integers (common with byte swap and other idioms). -/// 2) A union of vector types of the same size and potentially its elements. +/// There are two cases we handle here: +/// 1) A union of vector types of the same size and potentially its elements. /// Here we turn element accesses into insert/extract element operations. -/// 3) A union of scalar types, such as int/float or int/pointer. Here we -/// merge together into integers, allowing the xform to work with #1 as -/// well. -static bool MergeInType(const Type *In, const Type *&Accum, - const TargetData &TD) { - // If this is our first type, just use it. - const VectorType *PTy; - if (Accum == Type::VoidTy || In == Accum) { - Accum = In; - } else if (In == Type::VoidTy) { - // Noop. - } else if (In->isInteger() && Accum->isInteger()) { // integer union. - // Otherwise pick whichever type is larger. - if (cast(In)->getBitWidth() > - cast(Accum)->getBitWidth()) - Accum = In; - } else if (isa(In) && isa(Accum)) { - // Pointer unions just stay as one of the pointers. - } else if (isa(In) || isa(Accum)) { - if ((PTy = dyn_cast(Accum)) && - PTy->getElementType() == In) { - // Accum is a vector, and we are accessing an element: ok. - } else if ((PTy = dyn_cast(In)) && - PTy->getElementType() == Accum) { - // In is a vector, and accum is an element: ok, remember In. - Accum = In; - } else if ((PTy = dyn_cast(In)) && isa(Accum) && - PTy->getBitWidth() == cast(Accum)->getBitWidth()) { - // Two vectors of the same size: keep Accum. - } else { - // Cannot insert an short into a <4 x int> or handle - // <2 x int> -> <4 x int> - return true; - } - } else { - // Pointer/FP/Integer unions merge together as integers. - switch (Accum->getTypeID()) { - case Type::PointerTyID: Accum = TD.getIntPtrType(); break; - case Type::FloatTyID: Accum = Type::Int32Ty; break; - case Type::DoubleTyID: Accum = Type::Int64Ty; break; - case Type::X86_FP80TyID: return true; - case Type::FP128TyID: return true; - case Type::PPC_FP128TyID: return true; - default: - assert(Accum->isInteger() && "Unknown FP type!"); - break; - } - - switch (In->getTypeID()) { - case Type::PointerTyID: In = TD.getIntPtrType(); break; - case Type::FloatTyID: In = Type::Int32Ty; break; - case Type::DoubleTyID: In = Type::Int64Ty; break; - case Type::X86_FP80TyID: return true; - case Type::FP128TyID: return true; - case Type::PPC_FP128TyID: return true; - default: - assert(In->isInteger() && "Unknown FP type!"); - break; +/// This promotes a <4 x float> with a store of float to the third element +/// into a <4 x float> that uses insert element. +/// 2) A fully general blob of memory, which we turn into some (potentially +/// large) integer type with extract and insert operations where the loads +/// and stores would mutate the memory. +static void MergeInType(const Type *In, uint64_t Offset, const Type *&VecTy, + unsigned AllocaSize, const TargetData &TD) { + // If this could be contributing to a vector, analyze it. + if (VecTy != Type::VoidTy) { // either null or a vector type. + + // If the In type is a vector that is the same size as the alloca, see if it + // matches the existing VecTy. + if (const VectorType *VInTy = dyn_cast(In)) { + if (VInTy->getBitWidth()/8 == AllocaSize && Offset == 0) { + // If we're storing/loading a vector of the right size, allow it as a + // vector. If this the first vector we see, remember the type so that + // we know the element size. + if (VecTy == 0) + VecTy = VInTy; + return; + } + } else if (In == Type::FloatTy || In == Type::DoubleTy || + (isa(In) && In->getPrimitiveSizeInBits() >= 8 && + isPowerOf2_32(In->getPrimitiveSizeInBits()))) { + // If we're accessing something that could be an element of a vector, see + // if the implied vector agrees with what we already have and if Offset is + // compatible with it. + unsigned EltSize = In->getPrimitiveSizeInBits()/8; + if (Offset % EltSize == 0 && + AllocaSize % EltSize == 0 && + (VecTy == 0 || + cast(VecTy)->getElementType() + ->getPrimitiveSizeInBits()/8 == EltSize)) { + if (VecTy == 0) + VecTy = VectorType::get(In, AllocaSize/EltSize); + return; + } } - return MergeInType(In, Accum, TD); } - return false; -} - -/// getIntAtLeastAsBigAs - Return an integer type that is at least as big as the -/// specified type. If there is no suitable type, this returns null. -const Type *getIntAtLeastAsBigAs(unsigned NumBits) { - if (NumBits > 64) return 0; - if (NumBits > 32) return Type::Int64Ty; - if (NumBits > 16) return Type::Int32Ty; - if (NumBits > 8) return Type::Int16Ty; - return Type::Int8Ty; + + // Otherwise, we have a case that we can't handle with an optimized vector + // form. We can still turn this into a large integer. + VecTy = Type::VoidTy; } -/// CanConvertToScalar - V is a pointer. If we can convert the pointee to a -/// single scalar integer type, return that type. Further, if the use is not -/// a completely trivial use that mem2reg could promote, set IsNotTrivial. If -/// there are no uses of this pointer, return Type::VoidTy to differentiate from -/// failure. +/// CanConvertToScalar - V is a pointer. If we can convert the pointee and all +/// its accesses to use a to single vector type, return true, and set VecTy to +/// the new type. If we could convert the alloca into a single promotable +/// integer, return true but set VecTy to VoidTy. Further, if the use is not a +/// completely trivial use that mem2reg could promote, set IsNotTrivial. Offset +/// is the current offset from the base of the alloca being analyzed. /// -const Type *SROA::CanConvertToScalar(Value *V, bool &IsNotTrivial) { - const Type *UsedType = Type::VoidTy; // No uses, no forced type. - const PointerType *PTy = cast(V->getType()); - +/// If we see at least one access to the value that is as a vector type, set the +/// SawVec flag. +/// +bool SROA::CanConvertToScalar(Value *V, bool &IsNotTrivial, const Type *&VecTy, + bool &SawVec, uint64_t Offset, + unsigned AllocaSize) { for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI!=E; ++UI) { Instruction *User = cast(*UI); if (LoadInst *LI = dyn_cast(User)) { + // Don't break volatile loads. if (LI->isVolatile()) - return 0; - - // FIXME: Loads of a first class aggregrate value could be converted to a - // series of loads and insertvalues - if (!LI->getType()->isSingleValueType()) - return 0; - - if (MergeInType(LI->getType(), UsedType, *TD)) - return 0; + return false; + MergeInType(LI->getType(), Offset, VecTy, AllocaSize, *TD); + SawVec |= isa(LI->getType()); continue; } if (StoreInst *SI = dyn_cast(User)) { // Storing the pointer, not into the value? if (SI->getOperand(0) == V || SI->isVolatile()) return 0; - - // FIXME: Stores of a first class aggregrate value could be converted to a - // series of extractvalues and stores - if (!SI->getOperand(0)->getType()->isSingleValueType()) - return 0; - - // NOTE: We could handle storing of FP imms into integers here! - - if (MergeInType(SI->getOperand(0)->getType(), UsedType, *TD)) - return 0; + MergeInType(SI->getOperand(0)->getType(), Offset, VecTy, AllocaSize, *TD); + SawVec |= isa(SI->getOperand(0)->getType()); continue; } - if (BitCastInst *CI = dyn_cast(User)) { + + if (BitCastInst *BCI = dyn_cast(User)) { + if (!CanConvertToScalar(BCI, IsNotTrivial, VecTy, SawVec, Offset, + AllocaSize)) + return false; IsNotTrivial = true; - const Type *SubTy = CanConvertToScalar(CI, IsNotTrivial); - if (!SubTy || MergeInType(SubTy, UsedType, *TD)) return 0; continue; } if (GetElementPtrInst *GEP = dyn_cast(User)) { - // Check to see if this is stepping over an element: GEP Ptr, int C - if (GEP->getNumOperands() == 2 && isa(GEP->getOperand(1))) { - unsigned Idx = cast(GEP->getOperand(1))->getZExtValue(); - unsigned ElSize = TD->getTypePaddedSize(PTy->getElementType()); - unsigned BitOffset = Idx*ElSize*8; - if (BitOffset > 64 || !isPowerOf2_32(ElSize)) return 0; - - IsNotTrivial = true; - const Type *SubElt = CanConvertToScalar(GEP, IsNotTrivial); - if (SubElt == 0) return 0; - if (SubElt != Type::VoidTy && SubElt->isInteger()) { - const Type *NewTy = - getIntAtLeastAsBigAs(TD->getTypePaddedSizeInBits(SubElt)+BitOffset); - if (NewTy == 0 || MergeInType(NewTy, UsedType, *TD)) return 0; - continue; - } - // Cannot handle this! - return 0; - } + // If this is a GEP with a variable indices, we can't handle it. + if (!GEP->hasAllConstantIndices()) + return false; - if (GEP->getNumOperands() == 3 && - isa(GEP->getOperand(1)) && - isa(GEP->getOperand(2)) && - cast(GEP->getOperand(1))->isZero()) { - // We are stepping into an element, e.g. a structure or an array: - // GEP Ptr, i32 0, i32 Cst - const Type *AggTy = PTy->getElementType(); - unsigned Idx = cast(GEP->getOperand(2))->getZExtValue(); - - if (const ArrayType *ATy = dyn_cast(AggTy)) { - if (Idx >= ATy->getNumElements()) return 0; // Out of range. - } else if (const VectorType *VectorTy = dyn_cast(AggTy)) { - // Getting an element of the vector. - if (Idx >= VectorTy->getNumElements()) return 0; // Out of range. - - // Merge in the vector type. - if (MergeInType(VectorTy, UsedType, *TD)) return 0; - - const Type *SubTy = CanConvertToScalar(GEP, IsNotTrivial); - if (SubTy == 0) return 0; - - if (SubTy != Type::VoidTy && MergeInType(SubTy, UsedType, *TD)) - return 0; - - // We'll need to change this to an insert/extract element operation. - IsNotTrivial = true; - continue; // Everything looks ok - - } else if (isa(AggTy)) { - // Structs are always ok. - } else { - return 0; - } - const Type *NTy = - getIntAtLeastAsBigAs(TD->getTypePaddedSizeInBits(AggTy)); - if (NTy == 0 || MergeInType(NTy, UsedType, *TD)) return 0; - const Type *SubTy = CanConvertToScalar(GEP, IsNotTrivial); - if (SubTy == 0) return 0; - if (SubTy != Type::VoidTy && MergeInType(SubTy, UsedType, *TD)) - return 0; - continue; // Everything looks ok - } - return 0; + // Compute the offset that this GEP adds to the pointer. + SmallVector Indices(GEP->op_begin()+1, GEP->op_end()); + uint64_t GEPOffset = TD->getIndexedOffset(GEP->getOperand(0)->getType(), + &Indices[0], Indices.size()); + // See if all uses can be converted. + if (!CanConvertToScalar(GEP, IsNotTrivial, VecTy, SawVec,Offset+GEPOffset, + AllocaSize)) + return false; + IsNotTrivial = true; + continue; } - // Cannot handle this! - return 0; + // If this is a constant sized memset of a constant value (e.g. 0) we can + // handle it. + if (isa(User) && + // Store of constant value. + isa(User->getOperand(2)) && + // Store with constant size. + isa(User->getOperand(3))) { + VecTy = Type::VoidTy; + IsNotTrivial = true; + continue; + } + + // Otherwise, we cannot handle this! + return false; } - return UsedType; -} - -/// ConvertToScalar - The specified alloca passes the CanConvertToScalar -/// predicate and is non-trivial. Convert it to something that can be trivially -/// promoted into a register by mem2reg. -void SROA::ConvertToScalar(AllocationInst *AI, const Type *ActualTy) { - DOUT << "CONVERT TO SCALAR: " << *AI << " TYPE = " - << *ActualTy << "\n"; - ++NumConverted; - - BasicBlock *EntryBlock = AI->getParent(); - assert(EntryBlock == &EntryBlock->getParent()->getEntryBlock() && - "Not in the entry block!"); - EntryBlock->getInstList().remove(AI); // Take the alloca out of the program. - - // Create and insert the alloca. - AllocaInst *NewAI = new AllocaInst(ActualTy, 0, AI->getName(), - EntryBlock->begin()); - ConvertUsesToScalar(AI, NewAI, 0); - delete AI; + return true; } @@ -1407,125 +1349,143 @@ /// /// Offset is an offset from the original alloca, in bits that need to be /// shifted to the right. By the end of this, there should be no uses of Ptr. -void SROA::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, unsigned Offset) { +void SROA::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, uint64_t Offset) { while (!Ptr->use_empty()) { Instruction *User = cast(Ptr->use_back()); + + if (BitCastInst *CI = dyn_cast(User)) { + ConvertUsesToScalar(CI, NewAI, Offset); + CI->eraseFromParent(); + continue; + } + + if (GetElementPtrInst *GEP = dyn_cast(User)) { + // Compute the offset that this GEP adds to the pointer. + SmallVector Indices(GEP->op_begin()+1, GEP->op_end()); + uint64_t GEPOffset = TD->getIndexedOffset(GEP->getOperand(0)->getType(), + &Indices[0], Indices.size()); + ConvertUsesToScalar(GEP, NewAI, Offset+GEPOffset*8); + GEP->eraseFromParent(); + continue; + } + + IRBuilder<> Builder(User->getParent(), User); if (LoadInst *LI = dyn_cast(User)) { - Value *NV = ConvertUsesOfLoadToScalar(LI, NewAI, Offset); - LI->replaceAllUsesWith(NV); + // The load is a bit extract from NewAI shifted right by Offset bits. + Value *LoadedVal = Builder.CreateLoad(NewAI, "tmp"); + Value *NewLoadVal + = ConvertScalar_ExtractValue(LoadedVal, LI->getType(), Offset, Builder); + LI->replaceAllUsesWith(NewLoadVal); LI->eraseFromParent(); continue; } if (StoreInst *SI = dyn_cast(User)) { assert(SI->getOperand(0) != Ptr && "Consistency error!"); - - Value *SV = ConvertUsesOfStoreToScalar(SI, NewAI, Offset); - new StoreInst(SV, NewAI, SI); + Value *Old = Builder.CreateLoad(NewAI, (NewAI->getName()+".in").c_str()); + Value *New = ConvertScalar_InsertValue(SI->getOperand(0), Old, Offset, + Builder); + Builder.CreateStore(New, NewAI); SI->eraseFromParent(); continue; } - if (BitCastInst *CI = dyn_cast(User)) { - ConvertUsesToScalar(CI, NewAI, Offset); - CI->eraseFromParent(); - continue; - } - - if (GetElementPtrInst *GEP = dyn_cast(User)) { - const PointerType *AggPtrTy = - cast(GEP->getOperand(0)->getType()); - unsigned AggSizeInBits = - TD->getTypePaddedSizeInBits(AggPtrTy->getElementType()); - - // Check to see if this is stepping over an element: GEP Ptr, int C - unsigned NewOffset = Offset; - if (GEP->getNumOperands() == 2) { - unsigned Idx = cast(GEP->getOperand(1))->getZExtValue(); - unsigned BitOffset = Idx*AggSizeInBits; - - NewOffset += BitOffset; - ConvertUsesToScalar(GEP, NewAI, NewOffset); - GEP->eraseFromParent(); - continue; - } - - assert(GEP->getNumOperands() == 3 && "Unsupported operation"); + // If this is a constant sized memset of a constant value (e.g. 0) we can + // transform it into a store of the expanded constant value. + if (MemSetInst *MSI = dyn_cast(User)) { + assert(MSI->getRawDest() == Ptr && "Consistency error!"); + unsigned NumBytes = cast(MSI->getLength())->getZExtValue(); + unsigned Val = cast(MSI->getValue())->getZExtValue(); - // We know that operand #2 is zero. - unsigned Idx = cast(GEP->getOperand(2))->getZExtValue(); - const Type *AggTy = AggPtrTy->getElementType(); - if (const SequentialType *SeqTy = dyn_cast(AggTy)) { - unsigned ElSizeBits = - TD->getTypePaddedSizeInBits(SeqTy->getElementType()); + // Compute the value replicated the right number of times. + APInt APVal(NumBytes*8, Val); - NewOffset += ElSizeBits*Idx; - } else { - const StructType *STy = cast(AggTy); - unsigned EltBitOffset = - TD->getStructLayout(STy)->getElementOffsetInBits(Idx); - - NewOffset += EltBitOffset; - } - ConvertUsesToScalar(GEP, NewAI, NewOffset); - GEP->eraseFromParent(); + // Splat the value if non-zero. + if (Val) + for (unsigned i = 1; i != NumBytes; ++i) + APVal |= APVal << 8; + + Value *Old = Builder.CreateLoad(NewAI, (NewAI->getName()+".in").c_str()); + Value *New = ConvertScalar_InsertValue(ConstantInt::get(APVal), Old, + Offset, Builder); + Builder.CreateStore(New, NewAI); + MSI->eraseFromParent(); continue; } + assert(0 && "Unsupported operation!"); abort(); } } -/// ConvertUsesOfLoadToScalar - Convert all of the users the specified load to -/// use the new alloca directly, returning the value that should replace the -/// load. This happens when we are converting an "integer union" to a -/// single integer scalar, or when we are converting a "vector union" to a -/// vector with insert/extractelement instructions. +/// ConvertScalar_ExtractValue - Extract a value of type ToType from an integer +/// or vector value FromVal, extracting the bits from the offset specified by +/// Offset. This returns the value, which is of type ToType. +/// +/// This happens when we are converting an "integer union" to a single +/// integer scalar, or when we are converting a "vector union" to a vector with +/// insert/extractelement instructions. /// /// Offset is an offset from the original alloca, in bits that need to be -/// shifted to the right. By the end of this, there should be no uses of Ptr. -Value *SROA::ConvertUsesOfLoadToScalar(LoadInst *LI, AllocaInst *NewAI, - unsigned Offset) { - // The load is a bit extract from NewAI shifted right by Offset bits. - Value *NV = new LoadInst(NewAI, LI->getName(), LI); - - if (NV->getType() == LI->getType() && Offset == 0) { - // We win, no conversion needed. - return NV; - } - - // If the result type of the 'union' is a pointer, then this must be ptr->ptr - // cast. Anything else would result in NV being an integer. - if (isa(NV->getType())) { - assert(isa(LI->getType())); - return new BitCastInst(NV, LI->getType(), LI->getName(), LI); - } - - if (const VectorType *VTy = dyn_cast(NV->getType())) { - // If the result alloca is a vector type, this is either an element - // access or a bitcast to another vector type. - if (isa(LI->getType())) - return new BitCastInst(NV, LI->getType(), LI->getName(), LI); +/// shifted to the right. +Value *SROA::ConvertScalar_ExtractValue(Value *FromVal, const Type *ToType, + uint64_t Offset, IRBuilder<> &Builder) { + // If the load is of the whole new alloca, no conversion is needed. + if (FromVal->getType() == ToType && Offset == 0) + return FromVal; + + // If the result alloca is a vector type, this is either an element + // access or a bitcast to another vector type of the same size. + if (const VectorType *VTy = dyn_cast(FromVal->getType())) { + if (isa(ToType)) + return Builder.CreateBitCast(FromVal, ToType, "tmp"); // Otherwise it must be an element access. unsigned Elt = 0; if (Offset) { unsigned EltSize = TD->getTypePaddedSizeInBits(VTy->getElementType()); Elt = Offset/EltSize; - Offset -= EltSize*Elt; + assert(EltSize*Elt == Offset && "Invalid modulus in validity checking"); } - NV = new ExtractElementInst(NV, ConstantInt::get(Type::Int32Ty, Elt), - "tmp", LI); - - // If we're done, return this element. - if (NV->getType() == LI->getType() && Offset == 0) - return NV; + // Return the element extracted out of it. + Value *V = Builder.CreateExtractElement(FromVal, + ConstantInt::get(Type::Int32Ty,Elt), + "tmp"); + if (V->getType() != ToType) + V = Builder.CreateBitCast(V, ToType, "tmp"); + return V; + } + + // If ToType is a first class aggregate, extract out each of the pieces and + // use insertvalue's to form the FCA. + if (const StructType *ST = dyn_cast(ToType)) { + const StructLayout &Layout = *TD->getStructLayout(ST); + Value *Res = UndefValue::get(ST); + for (unsigned i = 0, e = ST->getNumElements(); i != e; ++i) { + Value *Elt = ConvertScalar_ExtractValue(FromVal, ST->getElementType(i), + Offset+Layout.getElementOffsetInBits(i), + Builder); + Res = Builder.CreateInsertValue(Res, Elt, i, "tmp"); + } + return Res; + } + + if (const ArrayType *AT = dyn_cast(ToType)) { + uint64_t EltSize = TD->getTypePaddedSizeInBits(AT->getElementType()); + Value *Res = UndefValue::get(AT); + for (unsigned i = 0, e = AT->getNumElements(); i != e; ++i) { + Value *Elt = ConvertScalar_ExtractValue(FromVal, AT->getElementType(), + Offset+i*EltSize, Builder); + Res = Builder.CreateInsertValue(Res, Elt, i, "tmp"); + } + return Res; } - - const IntegerType *NTy = cast(NV->getType()); - + + // Otherwise, this must be a union that was converted to an integer value. + const IntegerType *NTy = cast(FromVal->getType()); + // If this is a big-endian system and the load is narrower than the // full alloca type, we need to do a shift to get the right bits. int ShAmt = 0; @@ -1534,137 +1494,155 @@ // from the pointer given by getTypeStoreSizeInBits. This matters for // integers with a bitwidth that is not a multiple of 8. ShAmt = TD->getTypeStoreSizeInBits(NTy) - - TD->getTypeStoreSizeInBits(LI->getType()) - Offset; + TD->getTypeStoreSizeInBits(ToType) - Offset; } else { ShAmt = Offset; } - + // Note: we support negative bitwidths (with shl) which are not defined. // We do this to support (f.e.) loads off the end of a structure where // only some bits are used. if (ShAmt > 0 && (unsigned)ShAmt < NTy->getBitWidth()) - NV = BinaryOperator::CreateLShr(NV, - ConstantInt::get(NV->getType(),ShAmt), - LI->getName(), LI); + FromVal = Builder.CreateLShr(FromVal, ConstantInt::get(FromVal->getType(), + ShAmt), "tmp"); else if (ShAmt < 0 && (unsigned)-ShAmt < NTy->getBitWidth()) - NV = BinaryOperator::CreateShl(NV, - ConstantInt::get(NV->getType(),-ShAmt), - LI->getName(), LI); - + FromVal = Builder.CreateShl(FromVal, ConstantInt::get(FromVal->getType(), + -ShAmt), "tmp"); + // Finally, unconditionally truncate the integer to the right width. - unsigned LIBitWidth = TD->getTypeSizeInBits(LI->getType()); + unsigned LIBitWidth = TD->getTypeSizeInBits(ToType); if (LIBitWidth < NTy->getBitWidth()) - NV = new TruncInst(NV, IntegerType::get(LIBitWidth), - LI->getName(), LI); - + FromVal = Builder.CreateTrunc(FromVal, IntegerType::get(LIBitWidth), "tmp"); + else if (LIBitWidth > NTy->getBitWidth()) + FromVal = Builder.CreateZExt(FromVal, IntegerType::get(LIBitWidth), "tmp"); + // If the result is an integer, this is a trunc or bitcast. - if (isa(LI->getType())) { + if (isa(ToType)) { // Should be done. - } else if (LI->getType()->isFloatingPoint()) { + } else if (ToType->isFloatingPoint() || isa(ToType)) { // Just do a bitcast, we know the sizes match up. - NV = new BitCastInst(NV, LI->getType(), LI->getName(), LI); + FromVal = Builder.CreateBitCast(FromVal, ToType, "tmp"); } else { // Otherwise must be a pointer. - NV = new IntToPtrInst(NV, LI->getType(), LI->getName(), LI); + FromVal = Builder.CreateIntToPtr(FromVal, ToType, "tmp"); } - assert(NV->getType() == LI->getType() && "Didn't convert right?"); - return NV; + assert(FromVal->getType() == ToType && "Didn't convert right?"); + return FromVal; } -/// ConvertUsesOfStoreToScalar - Convert the specified store to a load+store -/// pair of the new alloca directly, returning the value that should be stored -/// to the alloca. This happens when we are converting an "integer union" to a +/// ConvertScalar_InsertValue - Insert the value "SV" into the existing integer +/// or vector value "Old" at the offset specified by Offset. +/// +/// This happens when we are converting an "integer union" to a /// single integer scalar, or when we are converting a "vector union" to a /// vector with insert/extractelement instructions. /// /// Offset is an offset from the original alloca, in bits that need to be -/// shifted to the right. By the end of this, there should be no uses of Ptr. -Value *SROA::ConvertUsesOfStoreToScalar(StoreInst *SI, AllocaInst *NewAI, - unsigned Offset) { - +/// shifted to the right. +Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old, + uint64_t Offset, IRBuilder<> &Builder) { + // Convert the stored type to the actual type, shift it left to insert // then 'or' into place. - Value *SV = SI->getOperand(0); - const Type *AllocaType = NewAI->getType()->getElementType(); - if (SV->getType() == AllocaType && Offset == 0) { - // All is well. - } else if (const VectorType *PTy = dyn_cast(AllocaType)) { - Value *Old = new LoadInst(NewAI, NewAI->getName()+".in", SI); - + const Type *AllocaType = Old->getType(); + + if (const VectorType *VTy = dyn_cast(AllocaType)) { // If the result alloca is a vector type, this is either an element // access or a bitcast to another vector type. if (isa(SV->getType())) { - SV = new BitCastInst(SV, AllocaType, SV->getName(), SI); + SV = Builder.CreateBitCast(SV, AllocaType, "tmp"); } else { // Must be an element insertion. - unsigned Elt = Offset/TD->getTypePaddedSizeInBits(PTy->getElementType()); - SV = InsertElementInst::Create(Old, SV, - ConstantInt::get(Type::Int32Ty, Elt), - "tmp", SI); - } - } else if (isa(AllocaType)) { - // If the alloca type is a pointer, then all the elements must be - // pointers. - if (SV->getType() != AllocaType) - SV = new BitCastInst(SV, AllocaType, SV->getName(), SI); - } else { - Value *Old = new LoadInst(NewAI, NewAI->getName()+".in", SI); - - // If SV is a float, convert it to the appropriate integer type. - // If it is a pointer, do the same, and also handle ptr->ptr casts - // here. - unsigned SrcWidth = TD->getTypeSizeInBits(SV->getType()); - unsigned DestWidth = TD->getTypeSizeInBits(AllocaType); - unsigned SrcStoreWidth = TD->getTypeStoreSizeInBits(SV->getType()); - unsigned DestStoreWidth = TD->getTypeStoreSizeInBits(AllocaType); - if (SV->getType()->isFloatingPoint()) - SV = new BitCastInst(SV, IntegerType::get(SrcWidth), - SV->getName(), SI); - else if (isa(SV->getType())) - SV = new PtrToIntInst(SV, TD->getIntPtrType(), SV->getName(), SI); - - // Always zero extend the value if needed. - if (SV->getType() != AllocaType) - SV = new ZExtInst(SV, AllocaType, SV->getName(), SI); - - // If this is a big-endian system and the store is narrower than the - // full alloca type, we need to do a shift to get the right bits. - int ShAmt = 0; - if (TD->isBigEndian()) { - // On big-endian machines, the lowest bit is stored at the bit offset - // from the pointer given by getTypeStoreSizeInBits. This matters for - // integers with a bitwidth that is not a multiple of 8. - ShAmt = DestStoreWidth - SrcStoreWidth - Offset; - } else { - ShAmt = Offset; + unsigned Elt = Offset/TD->getTypePaddedSizeInBits(VTy->getElementType()); + + if (SV->getType() != VTy->getElementType()) + SV = Builder.CreateBitCast(SV, VTy->getElementType(), "tmp"); + + SV = Builder.CreateInsertElement(Old, SV, + ConstantInt::get(Type::Int32Ty, Elt), + "tmp"); } - - // Note: we support negative bitwidths (with shr) which are not defined. - // We do this to support (f.e.) stores off the end of a structure where - // only some bits in the structure are set. - APInt Mask(APInt::getLowBitsSet(DestWidth, SrcWidth)); - if (ShAmt > 0 && (unsigned)ShAmt < DestWidth) { - SV = BinaryOperator::CreateShl(SV, - ConstantInt::get(SV->getType(), ShAmt), - SV->getName(), SI); - Mask <<= ShAmt; - } else if (ShAmt < 0 && (unsigned)-ShAmt < DestWidth) { - SV = BinaryOperator::CreateLShr(SV, - ConstantInt::get(SV->getType(),-ShAmt), - SV->getName(), SI); - Mask = Mask.lshr(ShAmt); - } - - // Mask out the bits we are about to insert from the old value, and or - // in the new bits. - if (SrcWidth != DestWidth) { - assert(DestWidth > SrcWidth); - Old = BinaryOperator::CreateAnd(Old, ConstantInt::get(~Mask), - Old->getName()+".mask", SI); - SV = BinaryOperator::CreateOr(Old, SV, SV->getName()+".ins", SI); + return SV; + } + + // If SV is a first-class aggregate value, insert each value recursively. + if (const StructType *ST = dyn_cast(SV->getType())) { + const StructLayout &Layout = *TD->getStructLayout(ST); + for (unsigned i = 0, e = ST->getNumElements(); i != e; ++i) { + Value *Elt = Builder.CreateExtractValue(SV, i, "tmp"); + Old = ConvertScalar_InsertValue(Elt, Old, + Offset+Layout.getElementOffsetInBits(i), + Builder); + } + return Old; + } + + if (const ArrayType *AT = dyn_cast(SV->getType())) { + uint64_t EltSize = TD->getTypePaddedSizeInBits(AT->getElementType()); + for (unsigned i = 0, e = AT->getNumElements(); i != e; ++i) { + Value *Elt = Builder.CreateExtractValue(SV, i, "tmp"); + Old = ConvertScalar_InsertValue(Elt, Old, Offset+i*EltSize, Builder); + } + return Old; + } + + // If SV is a float, convert it to the appropriate integer type. + // If it is a pointer, do the same. + unsigned SrcWidth = TD->getTypeSizeInBits(SV->getType()); + unsigned DestWidth = TD->getTypeSizeInBits(AllocaType); + unsigned SrcStoreWidth = TD->getTypeStoreSizeInBits(SV->getType()); + unsigned DestStoreWidth = TD->getTypeStoreSizeInBits(AllocaType); + if (SV->getType()->isFloatingPoint() || isa(SV->getType())) + SV = Builder.CreateBitCast(SV, IntegerType::get(SrcWidth), "tmp"); + else if (isa(SV->getType())) + SV = Builder.CreatePtrToInt(SV, TD->getIntPtrType(), "tmp"); + + // Zero extend or truncate the value if needed. + if (SV->getType() != AllocaType) { + if (SV->getType()->getPrimitiveSizeInBits() < + AllocaType->getPrimitiveSizeInBits()) + SV = Builder.CreateZExt(SV, AllocaType, "tmp"); + else { + // Truncation may be needed if storing more than the alloca can hold + // (undefined behavior). + SV = Builder.CreateTrunc(SV, AllocaType, "tmp"); + SrcWidth = DestWidth; + SrcStoreWidth = DestStoreWidth; } } + + // If this is a big-endian system and the store is narrower than the + // full alloca type, we need to do a shift to get the right bits. + int ShAmt = 0; + if (TD->isBigEndian()) { + // On big-endian machines, the lowest bit is stored at the bit offset + // from the pointer given by getTypeStoreSizeInBits. This matters for + // integers with a bitwidth that is not a multiple of 8. + ShAmt = DestStoreWidth - SrcStoreWidth - Offset; + } else { + ShAmt = Offset; + } + + // Note: we support negative bitwidths (with shr) which are not defined. + // We do this to support (f.e.) stores off the end of a structure where + // only some bits in the structure are set. + APInt Mask(APInt::getLowBitsSet(DestWidth, SrcWidth)); + if (ShAmt > 0 && (unsigned)ShAmt < DestWidth) { + SV = Builder.CreateShl(SV, ConstantInt::get(SV->getType(), ShAmt), "tmp"); + Mask <<= ShAmt; + } else if (ShAmt < 0 && (unsigned)-ShAmt < DestWidth) { + SV = Builder.CreateLShr(SV, ConstantInt::get(SV->getType(), -ShAmt), "tmp"); + Mask = Mask.lshr(-ShAmt); + } + + // Mask out the bits we are about to insert from the old value, and or + // in the new bits. + if (SrcWidth != DestWidth) { + assert(DestWidth > SrcWidth); + Old = Builder.CreateAnd(Old, ConstantInt::get(~Mask), "mask"); + SV = Builder.CreateOr(Old, SV, "ins"); + } return SV; } From isanbard at gmail.com Tue Feb 17 15:59:19 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 21:59:19 -0000 Subject: [llvm-commits] [llvm] r64823 - in /llvm/branches/Apple/Dib: lib/VMCore/ConstantFold.cpp test/Transforms/InstCombine/2009-02-04-FPBitcast.ll Message-ID: <200902172159.n1HLxJq0021664@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 15:59:18 2009 New Revision: 64823 URL: http://llvm.org/viewvc/llvm-project?rev=64823&view=rev Log: --- Merging (from foreign repository) r63730 into '.': A test/Transforms/InstCombine/2009-02-04-FPBitcast.ll U lib/VMCore/ConstantFold.cpp Fix PR3468: a crash when constant folding a bitcast of i80 to x86 long double (this was presumably generated by sroa). --- Merging (from foreign repository) r63731 into '.': U test/Transforms/InstCombine/2009-02-04-FPBitcast.ll G lib/VMCore/ConstantFold.cpp Allow the inverse transform x86_fp80 -> i80 (also fires during the Ada build). --- Merging (from foreign repository) r63597 into '.': A test/Bitcode/extractelement.ll fix a bitcode reader bug where it can't handle extractelement correctly: the index of the value being extracted is always an i32. This fixes PR3465 Added: llvm/branches/Apple/Dib/test/Transforms/InstCombine/2009-02-04-FPBitcast.ll Modified: llvm/branches/Apple/Dib/lib/VMCore/ConstantFold.cpp Modified: llvm/branches/Apple/Dib/lib/VMCore/ConstantFold.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/VMCore/ConstantFold.cpp?rev=64823&r1=64822&r2=64823&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/VMCore/ConstantFold.cpp (original) +++ llvm/branches/Apple/Dib/lib/VMCore/ConstantFold.cpp Tue Feb 17 15:59:18 2009 @@ -153,26 +153,20 @@ // Integral -> Integral. This is a no-op because the bit widths must // be the same. Consequently, we just fold to V. return V; - - if (DestTy->isFloatingPoint()) { - assert((DestTy == Type::DoubleTy || DestTy == Type::FloatTy) && - "Unknown FP type!"); - return ConstantFP::get(APFloat(CI->getValue())); - } + + if (DestTy->isFloatingPoint()) + return ConstantFP::get(APFloat(CI->getValue(), + DestTy != Type::PPC_FP128Ty)); + // Otherwise, can't fold this (vector?) return 0; } - + // Handle ConstantFP input. - if (const ConstantFP *FP = dyn_cast(V)) { + if (const ConstantFP *FP = dyn_cast(V)) // FP -> Integral. - if (DestTy == Type::Int32Ty) { - return ConstantInt::get(FP->getValueAPF().bitcastToAPInt()); - } else { - assert(DestTy == Type::Int64Ty && "only support f32/f64 for now!"); - return ConstantInt::get(FP->getValueAPF().bitcastToAPInt()); - } - } + return ConstantInt::get(FP->getValueAPF().bitcastToAPInt()); + return 0; } Added: llvm/branches/Apple/Dib/test/Transforms/InstCombine/2009-02-04-FPBitcast.ll URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/Transforms/InstCombine/2009-02-04-FPBitcast.ll?rev=64823&view=auto ============================================================================== --- llvm/branches/Apple/Dib/test/Transforms/InstCombine/2009-02-04-FPBitcast.ll (added) +++ llvm/branches/Apple/Dib/test/Transforms/InstCombine/2009-02-04-FPBitcast.ll Tue Feb 17 15:59:18 2009 @@ -0,0 +1,12 @@ +; RUN: llvm-as < %s | opt -instcombine +; PR3468 + +define x86_fp80 @cast() { + %tmp = bitcast i80 0 to x86_fp80 ; [#uses=1] + ret x86_fp80 %tmp +} + +define i80 @invcast() { + %tmp = bitcast x86_fp80 0xK00000000000000000000 to i80 ; [#uses=1] + ret i80 %tmp +} From isanbard at gmail.com Tue Feb 17 16:03:51 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 22:03:51 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64824 - in /llvm-gcc-4.2/branches/Apple/Dib/gcc: cgraphunit.c ipa-inline.c passes.c tree-pass.h Message-ID: <200902172203.n1HM3q7S021826@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 16:03:51 2009 New Revision: 64824 URL: http://llvm.org/viewvc/llvm-project?rev=64824&view=rev Log: --- Reverse-merging (from foreign repository) r63857 into '.': U gcc/tree-pass.h U gcc/cgraphunit.c U gcc/ipa-inline.c U gcc/passes.c Re-disable GCC inliner from Dib. Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/cgraphunit.c llvm-gcc-4.2/branches/Apple/Dib/gcc/ipa-inline.c llvm-gcc-4.2/branches/Apple/Dib/gcc/passes.c llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-pass.h Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/cgraphunit.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/cgraphunit.c?rev=64824&r1=64823&r2=64824&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/cgraphunit.c (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/cgraphunit.c Tue Feb 17 16:03:51 2009 @@ -1600,6 +1600,8 @@ return false; } +/* LLVM LOCAL begin */ +#ifndef ENABLE_LLVM static void ipa_passes (void) { @@ -1609,6 +1611,8 @@ execute_ipa_pass_list (all_ipa_passes); bitmap_obstack_release (NULL); } +#endif +/* LLVM LOCAL end */ /* Perform simple optimizations based on callgraph. */ @@ -1646,9 +1650,13 @@ dump_cgraph (cgraph_dump_file); } + /* LLVM LOCAL begin */ +#ifndef ENABLE_LLVM /* Don't run the IPA passes if there was any error or sorry messages. */ if (errorcount == 0 && sorrycount == 0) ipa_passes (); +#endif + /* LLVM LOCAL end */ /* This pass remove bodies of extern inline functions we never inlined. Do this later so other IPA passes see what is really going on. */ Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/ipa-inline.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/ipa-inline.c?rev=64824&r1=64823&r2=64824&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/ipa-inline.c (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/ipa-inline.c Tue Feb 17 16:03:51 2009 @@ -942,11 +942,7 @@ /* At the moment, no IPA passes change function bodies before inlining. Save some time by not recomputing function body sizes if early inlining already did so. */ - /* LLVM local begin - Don't rely on pass_early_ipa_inline being run. */ -#ifndef ENABLE_LLVM if (!flag_early_inlining) -#endif - /* LLVM local end */ node->local.self_insns = node->global.insns = estimate_num_insns (node->decl); @@ -1033,19 +1029,9 @@ overall_insns - old_insns); } - /* LLVM local begin */ -#ifdef ENABLE_LLVM - if (1) /* FIXME: 1 should be 0 some day, see PR2353. */ -#endif - /* LLVM local end*/ if (!flag_really_no_inline) cgraph_decide_inlining_of_small_functions (); - /* LLVM local begin */ -#ifdef ENABLE_LLVM - if (1) /* FIXME: 1 should be 0 some day, see PR2353. */ -#endif - /* LLVM local end*/ if (!flag_really_no_inline && flag_inline_functions_called_once) { @@ -1164,11 +1150,6 @@ } /* Now do the automatic inlining. */ - /* LLVM local begin */ -#ifdef ENABLE_LLVM - if (1) /* FIXME: 1 should be 0 some day, see PR2353. */ -#endif - /* LLVM local end */ if (!flag_really_no_inline) for (e = node->callees; e; e = e->next_callee) if (e->callee->local.inlinable Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/passes.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/passes.c?rev=64824&r1=64823&r2=64824&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/passes.c (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/passes.c Tue Feb 17 16:03:51 2009 @@ -333,10 +333,11 @@ /* The root of the compilation pass tree, once constructed. */ -struct tree_opt_pass *all_passes, *all_ipa_passes, *all_lowering_passes; /* LLVM LOCAL begin */ #ifdef ENABLE_LLVM -struct tree_opt_pass *all_extra_lowering_passes; +struct tree_opt_pass *all_lowering_passes, *all_extra_lowering_passes; +#else +struct tree_opt_pass *all_passes, *all_ipa_passes, *all_lowering_passes; #endif /* LLVM LOCAL end */ @@ -479,23 +480,21 @@ struct tree_opt_pass **p; #define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS)) + /* LLVM LOCAL begin */ +#ifndef ENABLE_LLVM /* Interprocedural optimization passes. */ p = &all_ipa_passes; - /* LLVM local begin */ -#ifndef ENABLE_LLVM NEXT_PASS (pass_early_ipa_inline); NEXT_PASS (pass_early_local_passes); NEXT_PASS (pass_ipa_cp); -#endif - NEXT_PASS (pass_ipa_inline); /* LLVM: inline functions marked always_inline */ -#ifndef ENABLE_LLVM + NEXT_PASS (pass_ipa_inline); NEXT_PASS (pass_ipa_reference); NEXT_PASS (pass_ipa_pure_const); NEXT_PASS (pass_ipa_type_escape); NEXT_PASS (pass_ipa_pta); -#endif - /* LLVM local end */ *p = NULL; +#endif + /* LLVM LOCAL end */ /* All passes needed to lower the function into shape optimizers can operate on. */ @@ -765,14 +764,18 @@ NEXT_PASS (pass_final); *p = NULL; #endif - /* LLVM local end */ + /* LLVM LOCAL end */ #undef NEXT_PASS /* Register the passes with the tree dump code. */ + /* LLVM LOCAL begin */ +#ifndef ENABLE_LLVM register_dump_files (all_ipa_passes, true, PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh | PROP_cfg); +#endif + /* LLVM LOCAL end */ register_dump_files (all_lowering_passes, false, PROP_gimple_any); /* LLVM LOCAL begin */ #ifdef ENABLE_LLVM @@ -850,6 +853,7 @@ dump_file, dump_flags); else { +/* LLVM LOCAL begin */ #ifndef ENABLE_LLVM if (dump_flags & TDF_SLIM) print_rtl_slim_with_bb (dump_file, get_insns (), dump_flags); @@ -858,6 +862,7 @@ else print_rtl (dump_file, get_insns ()); #endif +/* LLVM LOCAL end */ if (curr_properties & PROP_cfg && graph_dump_format != no_graph && (dump_flags & TDF_GRAPH)) Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-pass.h URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-pass.h?rev=64824&r1=64823&r2=64824&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-pass.h (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-pass.h Tue Feb 17 16:03:51 2009 @@ -399,10 +399,11 @@ extern struct tree_opt_pass pass_rtl_seqabstr; /* The root of the compilation pass tree, once constructed. */ -extern struct tree_opt_pass *all_passes, *all_ipa_passes, *all_lowering_passes; /* LLVM LOCAL begin */ #ifdef ENABLE_LLVM -extern struct tree_opt_pass *all_extra_lowering_passes; +extern struct tree_opt_pass *all_lowering_passes, *all_extra_lowering_passes; +#else +extern struct tree_opt_pass *all_passes, *all_ipa_passes, *all_lowering_passes; #endif /* LLVM LOCAL end */ From isanbard at gmail.com Tue Feb 17 16:10:40 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 22:10:40 -0000 Subject: [llvm-commits] [llvm] r64825 - in /llvm/branches/Apple/Dib: lib/CodeGen/SelectionDAG/LegalizeTypes.cpp lib/Transforms/Scalar/InstructionCombining.cpp test/CodeGen/X86/2009-02-03-AnalyzedTwice.ll test/Transforms/InstCombine/vec_demanded_elts-2.ll Message-ID: <200902172210.n1HMAeNq022207@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 16:10:39 2009 New Revision: 64825 URL: http://llvm.org/viewvc/llvm-project?rev=64825&view=rev Log: --- Merging (from foreign repository) r63631 into '.': A test/Transforms/InstCombine/vec_demanded_elts-2.ll U lib/Transforms/Scalar/InstructionCombining.cpp APInt'fy SimplifyDemandedVectorElts so it can analyze vectors with more than 64 elements. --- Merging (from foreign repository) r63632 into '.': A test/CodeGen/X86/2009-02-03-AnalyzedTwice.ll U lib/CodeGen/SelectionDAG/LegalizeTypes.cpp Fix PR3411. When replacing values, nodes are analyzed in any old order. Since analyzing a node analyzes its operands also, this can mean that when we pop a node off the list of nodes to be analyzed, it may already have been analyzed. Added: llvm/branches/Apple/Dib/test/CodeGen/X86/2009-02-03-AnalyzedTwice.ll llvm/branches/Apple/Dib/test/Transforms/InstCombine/vec_demanded_elts-2.ll Modified: llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp llvm/branches/Apple/Dib/lib/Transforms/Scalar/InstructionCombining.cpp Modified: llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp?rev=64825&r1=64824&r2=64825&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp (original) +++ llvm/branches/Apple/Dib/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp Tue Feb 17 16:10:39 2009 @@ -651,7 +651,7 @@ DTL.NoteDeletion(N, E); // In theory the deleted node could also have been scheduled for analysis. - // So add it to the set of nodes which will not be analyzed. + // So remove it from the set of nodes which will be analyzed. NodesToAnalyze.remove(N); // In general nothing needs to be done for E, since it didn't change but @@ -669,6 +669,7 @@ assert(N->getNodeId() != DAGTypeLegalizer::ReadyToProcess && N->getNodeId() != DAGTypeLegalizer::Processed && "Invalid node ID for RAUW deletion!"); + N->setNodeId(DAGTypeLegalizer::NewNode); NodesToAnalyze.insert(N); } }; @@ -695,12 +696,13 @@ while (!NodesToAnalyze.empty()) { SDNode *N = NodesToAnalyze.back(); NodesToAnalyze.pop_back(); + if (N->getNodeId() != DAGTypeLegalizer::NewNode) + // The node was analyzed while reanalyzing an earlier node - it is safe to + // skip. Note that this is not a morphing node - otherwise it would still + // be marked NewNode. + continue; // Analyze the node's operands and recalculate the node ID. - assert(N->getNodeId() != DAGTypeLegalizer::ReadyToProcess && - N->getNodeId() != DAGTypeLegalizer::Processed && - "Invalid node ID for RAUW analysis!"); - N->setNodeId(NewNode); SDNode *M = AnalyzeNewNode(N); if (M != N) { // The node morphed into a different node. Make everyone use the new node Modified: llvm/branches/Apple/Dib/lib/Transforms/Scalar/InstructionCombining.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/Scalar/InstructionCombining.cpp?rev=64825&r1=64824&r2=64825&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Transforms/Scalar/InstructionCombining.cpp (original) +++ llvm/branches/Apple/Dib/lib/Transforms/Scalar/InstructionCombining.cpp Tue Feb 17 16:10:39 2009 @@ -352,8 +352,8 @@ /// properties that allow us to simplify its operands. bool SimplifyDemandedInstructionBits(Instruction &Inst); - Value *SimplifyDemandedVectorElts(Value *V, uint64_t DemandedElts, - uint64_t &UndefElts, unsigned Depth = 0); + Value *SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, + APInt& UndefElts, unsigned Depth = 0); // FoldOpIntoPhi - Given a binary operator or cast instruction which has a // PHI node as operand #0, see if we can fold the instruction into the PHI @@ -1396,19 +1396,18 @@ /// SimplifyDemandedVectorElts - The specified value produces a vector with -/// 64 or fewer elements. DemandedElts contains the set of elements that are +/// any number of elements. DemandedElts contains the set of elements that are /// actually used by the caller. This method analyzes which elements of the /// operand are undef and returns that information in UndefElts. /// /// If the information about demanded elements can be used to simplify the /// operation, the operation is simplified, then the resultant value is /// returned. This returns null if no change was made. -Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, uint64_t DemandedElts, - uint64_t &UndefElts, +Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, + APInt& UndefElts, unsigned Depth) { unsigned VWidth = cast(V->getType())->getNumElements(); - assert(VWidth <= 64 && "Vector too wide to analyze!"); - uint64_t EltMask = ~0ULL >> (64-VWidth); + APInt EltMask(APInt::getAllOnesValue(VWidth)); assert((DemandedElts & ~EltMask) == 0 && "Invalid DemandedElts!"); if (isa(V)) { @@ -1427,12 +1426,12 @@ std::vector Elts; for (unsigned i = 0; i != VWidth; ++i) - if (!(DemandedElts & (1ULL << i))) { // If not demanded, set to undef. + if (!DemandedElts[i]) { // If not demanded, set to undef. Elts.push_back(Undef); - UndefElts |= (1ULL << i); + UndefElts.set(i); } else if (isa(CP->getOperand(i))) { // Already undef. Elts.push_back(Undef); - UndefElts |= (1ULL << i); + UndefElts.set(i); } else { // Otherwise, defined. Elts.push_back(CP->getOperand(i)); } @@ -1453,8 +1452,10 @@ Constant *Zero = Constant::getNullValue(EltTy); Constant *Undef = UndefValue::get(EltTy); std::vector Elts; - for (unsigned i = 0; i != VWidth; ++i) - Elts.push_back((DemandedElts & (1ULL << i)) ? Zero : Undef); + for (unsigned i = 0; i != VWidth; ++i) { + Constant *Elt = DemandedElts[i] ? Zero : Undef; + Elts.push_back(Elt); + } UndefElts = DemandedElts ^ EltMask; return ConstantVector::get(Elts); } @@ -1482,7 +1483,7 @@ if (!I) return false; // Only analyze instructions. bool MadeChange = false; - uint64_t UndefElts2; + APInt UndefElts2(VWidth, 0); Value *TmpV; switch (I->getOpcode()) { default: break; @@ -1503,35 +1504,36 @@ // If this is inserting an element that isn't demanded, remove this // insertelement. unsigned IdxNo = Idx->getZExtValue(); - if (IdxNo >= VWidth || (DemandedElts & (1ULL << IdxNo)) == 0) + if (IdxNo >= VWidth || !DemandedElts[IdxNo]) return AddSoonDeadInstToWorklist(*I, 0); // Otherwise, the element inserted overwrites whatever was there, so the // input demanded set is simpler than the output set. - TmpV = SimplifyDemandedVectorElts(I->getOperand(0), - DemandedElts & ~(1ULL << IdxNo), + APInt DemandedElts2 = DemandedElts; + DemandedElts2.clear(IdxNo); + TmpV = SimplifyDemandedVectorElts(I->getOperand(0), DemandedElts2, UndefElts, Depth+1); if (TmpV) { I->setOperand(0, TmpV); MadeChange = true; } // The inserted element is defined. - UndefElts &= ~(1ULL << IdxNo); + UndefElts.clear(IdxNo); break; } case Instruction::ShuffleVector: { ShuffleVectorInst *Shuffle = cast(I); uint64_t LHSVWidth = cast(Shuffle->getOperand(0)->getType())->getNumElements(); - uint64_t LeftDemanded = 0, RightDemanded = 0; + APInt LeftDemanded(LHSVWidth, 0), RightDemanded(LHSVWidth, 0); for (unsigned i = 0; i < VWidth; i++) { - if (DemandedElts & (1ULL << i)) { + if (DemandedElts[i]) { unsigned MaskVal = Shuffle->getMaskValue(i); if (MaskVal != -1u) { assert(MaskVal < LHSVWidth * 2 && "shufflevector mask index out of range!"); if (MaskVal < LHSVWidth) - LeftDemanded |= 1ULL << MaskVal; + LeftDemanded.set(MaskVal); else - RightDemanded |= 1ULL << (MaskVal - LHSVWidth); + RightDemanded.set(MaskVal - LHSVWidth); } } } @@ -1540,7 +1542,7 @@ UndefElts2, Depth+1); if (TmpV) { I->setOperand(0, TmpV); MadeChange = true; } - uint64_t UndefElts3; + APInt UndefElts3(VWidth, 0); TmpV = SimplifyDemandedVectorElts(I->getOperand(1), RightDemanded, UndefElts3, Depth+1); if (TmpV) { I->setOperand(1, TmpV); MadeChange = true; } @@ -1549,16 +1551,17 @@ for (unsigned i = 0; i < VWidth; i++) { unsigned MaskVal = Shuffle->getMaskValue(i); if (MaskVal == -1u) { - uint64_t NewBit = 1ULL << i; - UndefElts |= NewBit; + UndefElts.set(i); } else if (MaskVal < LHSVWidth) { - uint64_t NewBit = ((UndefElts2 >> MaskVal) & 1) << i; - NewUndefElts |= NewBit; - UndefElts |= NewBit; + if (UndefElts2[MaskVal]) { + NewUndefElts = true; + UndefElts.set(i); + } } else { - uint64_t NewBit = ((UndefElts3 >> (MaskVal - LHSVWidth)) & 1) << i; - NewUndefElts |= NewBit; - UndefElts |= NewBit; + if (UndefElts3[MaskVal - LHSVWidth]) { + NewUndefElts = true; + UndefElts.set(i); + } } } @@ -1566,7 +1569,7 @@ // Add additional discovered undefs. std::vector Elts; for (unsigned i = 0; i < VWidth; ++i) { - if (UndefElts & (1ULL << i)) + if (UndefElts[i]) Elts.push_back(UndefValue::get(Type::Int32Ty)); else Elts.push_back(ConstantInt::get(Type::Int32Ty, @@ -1582,7 +1585,7 @@ const VectorType *VTy = dyn_cast(I->getOperand(0)->getType()); if (!VTy) break; unsigned InVWidth = VTy->getNumElements(); - uint64_t InputDemandedElts = 0; + APInt InputDemandedElts(InVWidth, 0); unsigned Ratio; if (VWidth == InVWidth) { @@ -1599,8 +1602,8 @@ // elements are live. Ratio = VWidth/InVWidth; for (unsigned OutIdx = 0; OutIdx != VWidth; ++OutIdx) { - if (DemandedElts & (1ULL << OutIdx)) - InputDemandedElts |= 1ULL << (OutIdx/Ratio); + if (DemandedElts[OutIdx]) + InputDemandedElts.set(OutIdx/Ratio); } } else { // Untested so far. @@ -1611,8 +1614,8 @@ // live. Ratio = InVWidth/VWidth; for (unsigned InIdx = 0; InIdx != InVWidth; ++InIdx) - if (DemandedElts & (1ULL << InIdx/Ratio)) - InputDemandedElts |= 1ULL << InIdx; + if (DemandedElts[InIdx/Ratio]) + InputDemandedElts.set(InIdx); } // div/rem demand all inputs, because they don't want divide by zero. @@ -1630,8 +1633,8 @@ // then an output element is undef if the corresponding input element is // undef. for (unsigned OutIdx = 0; OutIdx != VWidth; ++OutIdx) - if (UndefElts2 & (1ULL << (OutIdx/Ratio))) - UndefElts |= 1ULL << OutIdx; + if (UndefElts2[OutIdx/Ratio]) + UndefElts.set(OutIdx); } else if (VWidth < InVWidth) { assert(0 && "Unimp"); // If there are more elements in the source than there are in the result, @@ -1639,8 +1642,8 @@ // elements are undef. UndefElts = ~0ULL >> (64-VWidth); // Start out all undef. for (unsigned InIdx = 0; InIdx != InVWidth; ++InIdx) - if ((UndefElts2 & (1ULL << InIdx)) == 0) // Not undef? - UndefElts &= ~(1ULL << (InIdx/Ratio)); // Clear undef bit. + if (!UndefElts2[InIdx]) // Not undef? + UndefElts.clear(InIdx/Ratio); // Clear undef bit. } break; } @@ -9493,8 +9496,11 @@ case Intrinsic::x86_sse_cvttss2si: { // These intrinsics only demands the 0th element of its input vector. If // we can simplify the input based on that, do so now. - uint64_t UndefElts; - if (Value *V = SimplifyDemandedVectorElts(II->getOperand(1), 1, + unsigned VWidth = + cast(II->getOperand(1)->getType())->getNumElements(); + APInt DemandedElts(VWidth, 1); + APInt UndefElts(VWidth, 0); + if (Value *V = SimplifyDemandedVectorElts(II->getOperand(1), DemandedElts, UndefElts)) { II->setOperand(1, V); return II; @@ -11874,10 +11880,10 @@ // If the input vector has a single use, simplify it based on this use // property. if (EI.getOperand(0)->hasOneUse() && VectorWidth != 1) { - uint64_t UndefElts; + APInt UndefElts(VectorWidth, 0); + APInt DemandedMask(VectorWidth, 1 << IndexVal); if (Value *V = SimplifyDemandedVectorElts(EI.getOperand(0), - 1 << IndexVal, - UndefElts)) { + DemandedMask, UndefElts)) { EI.setOperand(0, V); return &EI; } @@ -12176,15 +12182,14 @@ if (isa(SVI.getOperand(2))) return ReplaceInstUsesWith(SVI, UndefValue::get(SVI.getType())); - uint64_t UndefElts; unsigned VWidth = cast(SVI.getType())->getNumElements(); if (VWidth != cast(LHS->getType())->getNumElements()) return 0; - uint64_t AllOnesEltMask = ~0ULL >> (64-VWidth); - if (VWidth <= 64 && - SimplifyDemandedVectorElts(&SVI, AllOnesEltMask, UndefElts)) { + APInt UndefElts(VWidth, 0); + APInt AllOnesEltMask(APInt::getAllOnesValue(VWidth)); + if (SimplifyDemandedVectorElts(&SVI, AllOnesEltMask, UndefElts)) { LHS = SVI.getOperand(0); RHS = SVI.getOperand(1); MadeChange = true; Added: llvm/branches/Apple/Dib/test/CodeGen/X86/2009-02-03-AnalyzedTwice.ll URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/CodeGen/X86/2009-02-03-AnalyzedTwice.ll?rev=64825&view=auto ============================================================================== --- llvm/branches/Apple/Dib/test/CodeGen/X86/2009-02-03-AnalyzedTwice.ll (added) +++ llvm/branches/Apple/Dib/test/CodeGen/X86/2009-02-03-AnalyzedTwice.ll Tue Feb 17 16:10:39 2009 @@ -0,0 +1,30 @@ +; RUN: llvm-as < %s | llc -march=x86 +; PR3411 + +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32" +target triple = "i386-pc-linux-gnu" + at g_3 = external global i32 ; [#uses=1] + +define void @bar(i64 %p_66) nounwind { +entry: + br i1 false, label %bb, label %bb1 + +bb: ; preds = %entry + unreachable + +bb1: ; preds = %entry + %0 = load i32* @g_3, align 4 ; [#uses=2] + %1 = sext i32 %0 to i64 ; [#uses=1] + %2 = or i64 %1, %p_66 ; [#uses=1] + %3 = shl i64 %2, 0 ; [#uses=1] + %4 = and i64 %3, %p_66 ; [#uses=1] + %5 = icmp eq i64 %4, 1 ; [#uses=1] + %6 = trunc i64 %p_66 to i32 ; [#uses=2] + %7 = or i32 %0, %6 ; [#uses=2] + %8 = sub i32 %7, %6 ; [#uses=1] + %iftmp.0.0 = select i1 %5, i32 %8, i32 %7 ; [#uses=1] + %9 = tail call i32 @foo(i32 %iftmp.0.0) nounwind ; [#uses=0] + ret void +} + +declare i32 @foo(i32) Added: llvm/branches/Apple/Dib/test/Transforms/InstCombine/vec_demanded_elts-2.ll URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/Transforms/InstCombine/vec_demanded_elts-2.ll?rev=64825&view=auto ============================================================================== --- llvm/branches/Apple/Dib/test/Transforms/InstCombine/vec_demanded_elts-2.ll (added) +++ llvm/branches/Apple/Dib/test/Transforms/InstCombine/vec_demanded_elts-2.ll Tue Feb 17 16:10:39 2009 @@ -0,0 +1,19 @@ +; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep extractelement + +define void @get_image() nounwind { +entry: + %0 = call i32 @fgetc(i8* null) nounwind ; [#uses=1] + %1 = trunc i32 %0 to i8 ; [#uses=1] + %tmp2 = insertelement <100 x i8> zeroinitializer, i8 %1, i32 1 ; <<100 x i8>> [#uses=1] + %tmp1 = extractelement <100 x i8> %tmp2, i32 0 ; [#uses=1] + %2 = icmp eq i8 %tmp1, 80 ; [#uses=1] + br i1 %2, label %bb2, label %bb3 + +bb2: ; preds = %entry + br label %bb3 + +bb3: ; preds = %bb2, %entry + unreachable +} + +declare i32 @fgetc(i8*) From scottm at aero.org Tue Feb 17 16:15:04 2009 From: scottm at aero.org (Scott Michel) Date: Tue, 17 Feb 2009 22:15:04 -0000 Subject: [llvm-commits] [llvm] r64827 - in /llvm/trunk: include/llvm/CodeGen/SelectionDAG.h include/llvm/CodeGen/SelectionDAGNodes.h lib/CodeGen/SelectionDAG/DAGCombiner.cpp lib/CodeGen/SelectionDAG/LegalizeDAG.cpp lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp lib/Target/PowerPC/PPCISelLowering.cpp lib/Target/X86/X86ISelLowering.cpp Message-ID: <200902172215.n1HMF5P2022402@zion.cs.uiuc.edu> Author: pingbak Date: Tue Feb 17 16:15:04 2009 New Revision: 64827 URL: http://llvm.org/viewvc/llvm-project?rev=64827&view=rev Log: Remove trailing whitespace to reduce later commit patch noise. (Note: Eventually, commits like this will be handled via a pre-commit hook that does this automagically, as well as expand tabs to spaces and look for 80-col violations.) Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAG.h llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAG.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAG.h?rev=64827&r1=64826&r2=64827&view=diff ============================================================================== --- llvm/trunk/include/llvm/CodeGen/SelectionDAG.h (original) +++ llvm/trunk/include/llvm/CodeGen/SelectionDAG.h Tue Feb 17 16:15:04 2009 @@ -143,7 +143,7 @@ /// void viewGraph(const std::string &Title); void viewGraph(); - + #ifndef NDEBUG std::map NodeGraphAttrs; #endif @@ -151,15 +151,15 @@ /// clearGraphAttrs - Clear all previously defined node graph attributes. /// Intended to be used from a debugging tool (eg. gdb). void clearGraphAttrs(); - + /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".) /// void setGraphAttrs(const SDNode *N, const char *Attrs); - + /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".) /// Used from getNodeAttributes. const std::string getGraphAttrs(const SDNode *N) const; - + /// setGraphColor - Convenience for setting node color attribute. /// void setGraphColor(const SDNode *N, const char *Color); @@ -177,7 +177,7 @@ ilist::size_type allnodes_size() const { return AllNodes.size(); } - + /// getRoot - Return the root tag of the SelectionDAG. /// const SDValue &getRoot() const { return Root; } @@ -233,7 +233,7 @@ SDVTList getVTList(MVT VT1, MVT VT2, MVT VT3); SDVTList getVTList(MVT VT1, MVT VT2, MVT VT3, MVT VT4); SDVTList getVTList(const MVT *VTs, unsigned NumVTs); - + /// getNodeValueTypes - These are obsolete, use getVTList instead. const MVT *getNodeValueTypes(MVT VT) { return getVTList(VT).VTs; @@ -250,8 +250,8 @@ const MVT *getNodeValueTypes(const std::vector &vtList) { return getVTList(&vtList[0], (unsigned)vtList.size()).VTs; } - - + + //===--------------------------------------------------------------------===// // Node creation methods. // @@ -320,7 +320,7 @@ SDValue getRegister(unsigned Reg, MVT VT); SDValue getDbgStopPoint(SDValue Root, unsigned Line, unsigned Col, Value *CU); - SDValue getLabel(unsigned Opcode, DebugLoc dl, SDValue Root, + SDValue getLabel(unsigned Opcode, DebugLoc dl, SDValue Root, unsigned LabelID); SDValue getCopyToReg(SDValue Chain, DebugLoc dl, unsigned Reg, SDValue N) { @@ -345,13 +345,13 @@ SDValue Ops[] = { Chain, Reg, N, Flag }; return getNode(ISD::CopyToReg, dl, VTs, 2, Ops, Flag.getNode() ? 4 : 3); } - + SDValue getCopyFromReg(SDValue Chain, DebugLoc dl, unsigned Reg, MVT VT) { const MVT *VTs = getNodeValueTypes(VT, MVT::Other); SDValue Ops[] = { Chain, getRegister(Reg, VT) }; return getNode(ISD::CopyFromReg, dl, VTs, 2, Ops, 2); } - + // This version of the getCopyFromReg method takes an extra operand, which // indicates that there is potentially an incoming flag value (if Flag is not // null) and that there should be a flag result. @@ -373,7 +373,7 @@ /// getZeroExtendInReg - Return the expression required to zero extend the Op /// value assuming it was the smaller SrcTy value. SDValue getZeroExtendInReg(SDValue Op, DebugLoc DL, MVT SrcTy); - + /// getNOT - Create a bitwise NOT operation as (XOR Val, -1). SDValue getNOT(DebugLoc DL, SDValue Val, MVT VT); @@ -383,7 +383,7 @@ SDValue getCALLSEQ_START(SDValue Chain, SDValue Op) { const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag); SDValue Ops[] = { Chain, Op }; - return getNode(ISD::CALLSEQ_START, DebugLoc::getUnknownLoc(), + return getNode(ISD::CALLSEQ_START, DebugLoc::getUnknownLoc(), VTs, 2, Ops, 2); } @@ -399,7 +399,7 @@ Ops.push_back(Op2); Ops.push_back(InFlag); return getNode(ISD::CALLSEQ_END, DebugLoc::getUnknownLoc(), NodeTys, - &Ops[0], + &Ops[0], (unsigned)Ops.size() - (InFlag.getNode() == 0 ? 1 : 0)); } @@ -487,15 +487,15 @@ return getNode(ISD::SELECT_CC, DL, True.getValueType(), LHS, RHS, True, False, getCondCode(Cond)); } - + /// getVAArg - VAArg produces a result and token chain, and takes a pointer /// and a source value as input. SDValue getVAArg(MVT VT, DebugLoc dl, SDValue Chain, SDValue Ptr, SDValue SV); - /// getAtomic - Gets a node for an atomic op, produces result and chain and + /// getAtomic - Gets a node for an atomic op, produces result and chain and /// takes 3 operands - SDValue getAtomic(unsigned Opcode, DebugLoc dl, MVT MemVT, SDValue Chain, + SDValue getAtomic(unsigned Opcode, DebugLoc dl, MVT MemVT, SDValue Chain, SDValue Ptr, SDValue Cmp, SDValue Swp, const Value* PtrVal, unsigned Alignment=0); @@ -585,7 +585,7 @@ SDValue Op3, SDValue Op4, SDValue Op5); SDValue UpdateNodeOperands(SDValue N, const SDValue *Ops, unsigned NumOps); - + /// SelectNodeTo - These are used for target selectors to *mutate* the /// specified node to have the specified return type, Target opcode, and /// operands. Note that target opcodes are stored as @@ -649,14 +649,14 @@ /// the current one. SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT); SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT, SDValue Op1); - SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT, SDValue Op1, + SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT, SDValue Op1, SDValue Op2); SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT, SDValue Op1, SDValue Op2, SDValue Op3); SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT, const SDValue *Ops, unsigned NumOps); SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT1, MVT VT2); - SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT1, MVT VT2, + SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT1, MVT VT2, SDValue Op1); SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT1, MVT VT2, SDValue Op1, SDValue Op2); @@ -680,7 +680,7 @@ /// else return NULL. SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTs, const SDValue *Ops, unsigned NumOps); - + /// DAGUpdateListener - Clients of various APIs that cause global effects on /// the DAG can optionally implement this interface. This allows the clients /// to handle the various sorts of updates that happen. @@ -695,12 +695,12 @@ /// NodeUpdated - The node N that was updated. virtual void NodeUpdated(SDNode *N) = 0; }; - + /// RemoveDeadNode - Remove the specified node from the system. If any of its /// operands then becomes dead, remove them as well. Inform UpdateListener /// for each node deleted. void RemoveDeadNode(SDNode *N, DAGUpdateListener *UpdateListener = 0); - + /// RemoveDeadNodes - This method deletes the unreachable nodes in the /// given list, and any nodes that become unreachable as a result. void RemoveDeadNodes(SmallVectorImpl &DeadNodes, @@ -711,7 +711,7 @@ /// version if 'From' is known to have a single result, use the second /// if you have two nodes with identical results, use the third otherwise. /// - /// These methods all take an optional UpdateListener, which (if not null) is + /// These methods all take an optional UpdateListener, which (if not null) is /// informed about nodes that are deleted and modified due to recursive /// changes in the dag. /// @@ -768,7 +768,7 @@ case ISD::AND: case ISD::OR: case ISD::XOR: - case ISD::ADDC: + case ISD::ADDC: case ISD::ADDE: return true; default: return false; } @@ -785,7 +785,7 @@ /// either of the specified value types. SDValue CreateStackTemporary(MVT VT1, MVT VT2); - /// FoldConstantArithmetic - + /// FoldConstantArithmetic - SDValue FoldConstantArithmetic(unsigned Opcode, MVT VT, ConstantSDNode *Cst1, @@ -794,7 +794,7 @@ /// FoldSetCC - Constant fold a setcc to true or false. SDValue FoldSetCC(MVT VT, SDValue N1, SDValue N2, ISD::CondCode Cond, DebugLoc dl); - + /// SignBitIsZero - Return true if the sign bit of Op is known to be zero. We /// use this predicate to simplify operations downstream. bool SignBitIsZero(SDValue Op, unsigned Depth = 0) const; @@ -804,11 +804,11 @@ /// known to be the same type. bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth = 0) const; - + /// ComputeMaskedBits - Determine which of the bits specified in Mask are /// known to be either zero or one and return them in the KnownZero/KnownOne /// bitsets. This code only analyzes bits in Mask, in order to short-circuit - /// processing. Targets can implement the computeMaskedBitsForTargetNode + /// processing. Targets can implement the computeMaskedBitsForTargetNode /// method in the TargetLowering class to allow target nodes to be understood. void ComputeMaskedBits(SDValue Op, const APInt &Mask, APInt &KnownZero, APInt &KnownOne, unsigned Depth = 0) const; @@ -829,7 +829,7 @@ /// getShuffleScalarElt - Returns the scalar element that will make up the ith /// element of the result of the vector shuffle. SDValue getShuffleScalarElt(const SDNode *N, unsigned Idx); - + private: bool RemoveNodeFromCSEMaps(SDNode *N); void AddModifiedNodeToCSEMaps(SDNode *N, DAGUpdateListener *UpdateListener); @@ -845,10 +845,10 @@ unsigned getMVTAlignment(MVT MemoryVT) const; void allnodes_clear(); - + /// VTList - List of non-single value types. std::vector VTList; - + /// CondCodeNodes - Maps to auto-CSE operations. std::vector CondCodeNodes; Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h?rev=64827&r1=64826&r2=64827&view=diff ============================================================================== --- llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h (original) +++ llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h Tue Feb 17 16:15:04 2009 @@ -78,7 +78,7 @@ // DELETED_NODE - This is an illegal flag value that is used to catch // errors. This opcode is not a legal opcode for any node. DELETED_NODE, - + // EntryToken - This is the marker used to indicate the start of the region. EntryToken, @@ -86,10 +86,10 @@ // single token result. This is used to represent the fact that the operand // operators are independent of each other. TokenFactor, - - // AssertSext, AssertZext - These nodes record if a register contains a - // value that has already been zero or sign extended from a narrower type. - // These nodes take two operands. The first is the node that has already + + // AssertSext, AssertZext - These nodes record if a register contains a + // value that has already been zero or sign extended from a narrower type. + // These nodes take two operands. The first is the node that has already // been extended, and the second is a value type node indicating the width // of the extension AssertSext, AssertZext, @@ -102,7 +102,7 @@ // The address of the GOT GLOBAL_OFFSET_TABLE, - + // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and // llvm.returnaddress on the DAG. These nodes take one operand, the index // of the frame or return address to return. An index of zero corresponds @@ -114,11 +114,11 @@ // first (possible) on-stack argument. This is needed for correct stack // adjustment during unwind. FRAME_TO_ARGS_OFFSET, - + // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the // address of the exception block on entry to an landing pad block. EXCEPTIONADDR, - + // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents // the selection index of the exception thrown. EHSELECTION, @@ -133,7 +133,7 @@ // simplification of the constant. TargetConstant, TargetConstantFP, - + // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or // anything else with this node, and this is valid in the target-specific // dag, turning into a GlobalAddress operand. @@ -143,14 +143,14 @@ TargetJumpTable, TargetConstantPool, TargetExternalSymbol, - + /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) /// This node represents a target intrinsic function with no side effects. /// The first operand is the ID number of the intrinsic from the /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The /// node has returns the result of the intrinsic. INTRINSIC_WO_CHAIN, - + /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) /// This node represents a target intrinsic function with side effects that /// returns a result. The first operand is a chain pointer. The second is @@ -165,9 +165,9 @@ /// second is the ID number of the intrinsic from the llvm::Intrinsic /// namespace. The operands to the intrinsic follow. INTRINSIC_VOID, - + // CopyToReg - This node has three operands: a chain, a register number to - // set to this value, and a value. + // set to this value, and a value. CopyToReg, // CopyFromReg - This node indicates that the input value is a virtual or @@ -177,7 +177,7 @@ // UNDEF - An undefined node UNDEF, - + /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node /// represents the formal arguments for a function. CC# is a Constant value /// indicating the calling convention of the function, and ISVARARG is a @@ -185,9 +185,9 @@ /// has one result value for each incoming argument, plus one for the output /// chain. It must be custom legalized. See description of CALL node for /// FLAG argument contents explanation. - /// + /// FORMAL_ARGUMENTS, - + /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CALLEE, /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn) /// This node represents a fully general function call, before the legalizer @@ -239,17 +239,17 @@ // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and // remainder result. SDIVREM, UDIVREM, - + // CARRY_FALSE - This node is used when folding other nodes, // like ADDC/SUBC, which indicate the carry result is always false. CARRY_FALSE, - + // Carry-setting nodes for multiple precision addition and subtraction. // These nodes take two operands of the same value type, and produce two // results. The first result is the normal add or sub result, the second // result is the carry flag result. ADDC, SUBC, - + // Carry-using nodes for multiple precision addition and subtraction. These // nodes take three operands: The first two are the normal lhs and rhs to // the add or sub, and the third is the input carry flag. These nodes @@ -286,12 +286,12 @@ // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point // value as an integer 0/1 value. FGETSIGN, - + /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector /// with the specified, possibly variable, elements. The number of elements /// is required to be a power of two. BUILD_VECTOR, - + /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element /// at IDX replaced with VAL. If the type of VAL is larger than the vector /// element type then VAL is truncated before replacement. @@ -300,13 +300,13 @@ /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR /// identified by the (potentially variable) element number IDX. EXTRACT_VECTOR_ELT, - + /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of /// vector type with the same length and element type, this produces a /// concatenated vector result value, with length equal to the sum of the /// lengths of the input vectors. CONCAT_VECTORS, - + /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an /// vector value) starting with the (potentially variable) element number /// IDX, which must be a multiple of the result vector length. @@ -325,19 +325,19 @@ /// scalar value into element 0 of the resultant vector type. The top /// elements 1 to N-1 of the N-element vector are undefined. SCALAR_TO_VECTOR, - - // EXTRACT_SUBREG - This node is used to extract a sub-register value. + + // EXTRACT_SUBREG - This node is used to extract a sub-register value. // This node takes a superreg and a constant sub-register index as operands. // Note sub-register indices must be increasing. That is, if the // sub-register index of a 8-bit sub-register is N, then the index for a // 16-bit sub-register must be at least N+1. EXTRACT_SUBREG, - - // INSERT_SUBREG - This node is used to insert a sub-register value. + + // INSERT_SUBREG - This node is used to insert a sub-register value. // This node takes a superreg, a subreg value, and a constant sub-register // index as operands. INSERT_SUBREG, - + // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing // an unsigned/signed value of type i[2*N], then return the top part. MULHU, MULHS, @@ -354,9 +354,9 @@ // i1 then the high bits must conform to getBooleanContents. SELECT, - // Select with condition operator - This selects between a true value and + // Select with condition operator - This selects between a true value and // a false value (ops #2 and #3) based on the boolean result of comparing - // the lhs and rhs (ops #0 and #1) of a conditional expression with the + // the lhs and rhs (ops #0 and #1) of a conditional expression with the // condition code in op #4, a CondCodeSDNode. SELECT_CC, @@ -369,7 +369,7 @@ // Vector SetCC operator - This evaluates to a vector of integer elements // with the high bit in each element set to true if the comparison is true - // and false if the comparison is false. All other bits in each element + // and false if the comparison is false. All other bits in each element // are undefined. The operands to this are the left and right operands // to compare (ops #0, and #1) and the condition code to compare them with // (op #2) as a CondCodeSDNode. @@ -395,7 +395,7 @@ // ANY_EXTEND - Used for integer types. The high bits are undefined. ANY_EXTEND, - + // TRUNCATE - Completely drop the high bits. TRUNCATE, @@ -425,10 +425,10 @@ /// The TRUNC = 1 case is used in cases where we know that the value will /// not be modified by the node, because Y is not using any of the extra /// precision of source type. This allows certain transformations like - /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for + /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed. FP_ROUND, - + // FLT_ROUNDS_ - Returns current rounding mode: // -1 Undefined // 0 Round to 0 @@ -449,12 +449,12 @@ // BIT_CONVERT - Theis operator converts between integer and FP values, as // if one was stored to memory as integer and the other was loaded from the - // same address (or equivalently for vector format conversions, etc). The - // source and result are required to have the same bit size (e.g. - // f32 <-> i32). This can also be used for int-to-int or fp-to-fp + // same address (or equivalently for vector format conversions, etc). The + // source and result are required to have the same bit size (e.g. + // f32 <-> i32). This can also be used for int-to-int or fp-to-fp // conversions, but that is a noop, deleted by getNode(). BIT_CONVERT, - + // CONVERT_RNDSAT - This operator is used to support various conversions // between various types (float, signed, unsigned and vectors of those // types) with rounding and saturation. NOTE: Avoid using this operator as @@ -467,7 +467,7 @@ // 4) saturation imm // 5) ISD::CvtCode indicating the type of conversion to do CONVERT_RNDSAT, - + // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW, // FLOG, FLOG2, FLOG10, FEXP, FEXP2, // FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR - Perform various unary floating @@ -475,7 +475,7 @@ FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW, FLOG, FLOG2, FLOG10, FEXP, FEXP2, FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR, - + // LOAD and STORE have token chains as their first operand, then the same // operands as an LLVM load/store instruction, then an offset node that // is added / subtracted from the base pointer to form the address (for @@ -517,7 +517,7 @@ // compare, rather than as a combined SetCC node. The operands in order are // chain, cc, lhs, rhs, block to branch to if condition is true. BR_CC, - + // RET - Return from function. The first operand is the chain, // and any subsequent operands are pairs of return value and return value // attributes (see CALL for description of attributes) for the function. @@ -532,7 +532,7 @@ // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def // Operand #last: Optional, an incoming flag. INLINEASM, - + // DBG_LABEL, EH_LABEL - Represents a label in mid basic block used to track // locations needed for debug and exception handling tables. These nodes // take a chain as input and return a chain. @@ -544,16 +544,16 @@ // a chain, while the next two operands are first two arguments (address // and variable) of a llvm.dbg.declare instruction. DECLARE, - + // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a // value, the same type as the pointer type for the system, and an output // chain. STACKSAVE, - + // STACKRESTORE has two operands, an input chain and a pointer to restore to // it returns an output chain. STACKRESTORE, - + // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of // a call sequence, and carry arbitrary information that target might want // to know. The first operand is a chain, the rest are specified by the @@ -561,16 +561,16 @@ // CALLSEQ_START..CALLSEQ_END pairs may not be nested. CALLSEQ_START, // Beginning of a call sequence CALLSEQ_END, // End of a call sequence - - // VAARG - VAARG has three operands: an input chain, a pointer, and a + + // VAARG - VAARG has three operands: an input chain, a pointer, and a // SRCVALUE. It returns a pair of values: the vaarg value and a new chain. VAARG, - + // VACOPY - VACOPY has five operands: an input chain, a destination pointer, // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the // source. VACOPY, - + // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a // pointer, and a SRCVALUE. VAEND, VASTART, @@ -589,7 +589,7 @@ // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic. // The only operand is a chain and a value and a chain are produced. The - // value is the contents of the architecture specific cycle counter like + // value is the contents of the architecture specific cycle counter like // register (or other high accuracy low latency clock source) READCYCLECOUNTER, @@ -601,7 +601,7 @@ // column number, and a pointer to a CompileUnit object identifying // the containing compilation unit. It produces a token chain as output. DBG_STOPPOINT, - + // DEBUG_LOC - This node is used to represent source line information // embedded in the code. It takes a token chain as input, then a line // number, then a column then a file id (provided by MachineModuleInfo.) It @@ -625,7 +625,7 @@ // read / write specifier, and locality specifier. PREFETCH, - // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load, + // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load, // store-store, device) // This corresponds to the memory.barrier intrinsic. // it takes an input chain, 4 operands to specify the type of barrier, an @@ -659,7 +659,7 @@ ATOMIC_LOAD_MAX, ATOMIC_LOAD_UMIN, ATOMIC_LOAD_UMAX, - + // BUILTIN_OP_END - This must be the last enum value in this list. BUILTIN_OP_END }; @@ -682,9 +682,9 @@ /// isDebugLabel - Return true if the specified node represents a debug /// label (i.e. ISD::DBG_LABEL or TargetInstrInfo::DBG_LABEL node). bool isDebugLabel(const SDNode *N); - + //===--------------------------------------------------------------------===// - /// MemIndexedMode enum - This enum defines the load / store indexed + /// MemIndexedMode enum - This enum defines the load / store indexed /// addressing modes. /// /// UNINDEXED "Normal" load / store. The effective address is already @@ -729,7 +729,7 @@ /// integer result type. /// ZEXTLOAD loads the integer operand and zero extends it to a larger /// integer result type. - /// EXTLOAD is used for three things: floating point extending loads, + /// EXTLOAD is used for three things: floating point extending loads, /// integer extending loads [the top bits are undefined], and vector /// extending loads [load into low elt]. /// @@ -834,7 +834,7 @@ CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger); //===--------------------------------------------------------------------===// - /// CvtCode enum - This enum defines the various converts CONVERT_RNDSAT + /// CvtCode enum - This enum defines the various converts CONVERT_RNDSAT /// supports. enum CvtCode { CVT_FF, // Float from Float @@ -915,15 +915,15 @@ inline unsigned getMachineOpcode() const; inline const DebugLoc getDebugLoc() const; - + /// reachesChainWithoutSideEffects - Return true if this operand (which must - /// be a chain) reaches the specified operand without crossing any + /// be a chain) reaches the specified operand without crossing any /// side-effecting instructions. In practice, this looks through token /// factors and non-volatile loads. In order to remain efficient, this only /// looks a couple of nodes in, it does not do an exhaustive search. - bool reachesChainWithoutSideEffects(SDValue Dest, + bool reachesChainWithoutSideEffects(SDValue Dest, unsigned Depth = 2) const; - + /// use_empty - Return true if there are no nodes using value ResNo /// of Node. /// @@ -937,10 +937,10 @@ template<> struct DenseMapInfo { - static inline SDValue getEmptyKey() { - return SDValue((SDNode*)-1, -1U); + static inline SDValue getEmptyKey() { + return SDValue((SDNode*)-1, -1U); } - static inline SDValue getTombstoneKey() { + static inline SDValue getTombstoneKey() { return SDValue((SDNode*)-1, 0); } static unsigned getHashValue(const SDValue &Val) { @@ -978,7 +978,7 @@ SDValue Val; /// User - The user of this value. SDNode *User; - /// Prev, Next - Pointers to the uses list of the SDNode referred by + /// Prev, Next - Pointers to the uses list of the SDNode referred by /// this operand. SDUse **Prev, *Next; @@ -994,7 +994,7 @@ /// If implicit conversion to SDValue doesn't work, the get() method returns /// the SDValue. const SDValue &get() const { return Val; } - + /// getUser - This returns the SDNode that contains this Use. SDNode *getUser() { return User; } @@ -1012,7 +1012,7 @@ bool operator==(const SDValue &V) const { return Val == V; } - + /// operator!= - Convenience function for get().operator!= bool operator!=(const SDValue &V) const { return Val != V; @@ -1075,7 +1075,7 @@ /// NodeType - The operation that this node performs. /// short NodeType; - + /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true, /// then they will be delete[]'d when the node is destroyed. unsigned short OperandsNeedDelete : 1; @@ -1093,7 +1093,7 @@ /// OperandList - The values that are used by this operation. /// SDUse *OperandList; - + /// ValueList - The types of the values this node defines. SDNode's may /// define multiple values simultaneously. const MVT *ValueList; @@ -1170,7 +1170,7 @@ void setDebugLoc(const DebugLoc dl) { debugLoc = dl; } /// use_iterator - This class provides iterator support for SDUse - /// operands that use a specific SDNode. + /// operands that use a specific SDNode. class use_iterator : public forward_iterator { SDUse *Op; @@ -1190,7 +1190,7 @@ bool operator!=(const use_iterator &x) const { return !operator==(x); } - + /// atEnd - return true if this iterator is at the end of uses list. bool atEnd() const { return Op == 0; } @@ -1260,7 +1260,7 @@ /// unsigned getNumOperands() const { return NumOperands; } - /// getConstantOperandVal - Helper method returns the integer value of a + /// getConstantOperandVal - Helper method returns the integer value of a /// ConstantSDNode operand. uint64_t getConstantOperandVal(unsigned Num) const; @@ -1353,7 +1353,7 @@ return Ret; } - SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs, const SDValue *Ops, + SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs, const SDValue *Ops, unsigned NumOps) : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0), NodeId(-1), @@ -1374,7 +1374,7 @@ NodeId(-1), OperandList(0), ValueList(VTs.VTs), UseList(NULL), NumOperands(0), NumValues(VTs.NumVTs), debugLoc(dl) {} - + /// InitOperands - Initialize the operands list of this with 1 operand. void InitOperands(SDUse *Ops, const SDValue &Op0) { Ops[0].setUser(this); @@ -1545,7 +1545,7 @@ getSDVTList(MVT::Other)) { InitOperands(&Op, X); } - ~HandleSDNode(); + ~HandleSDNode(); const SDValue &getValue() const { return Op; } }; @@ -1713,7 +1713,7 @@ protected: friend class SelectionDAG; ConstantSDNode(bool isTarget, const ConstantInt *val, MVT VT) - : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, + : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, DebugLoc::getUnknownLoc(), getSDVTList(VT)), Value(val) { } public: @@ -1752,7 +1752,7 @@ /// two floating point values. /// We leave the version with the double argument here because it's just so - /// convenient to write "2.0" and the like. Without this function we'd + /// convenient to write "2.0" and the like. Without this function we'd /// have to duplicate its logic everywhere it's called. bool isExactlyValue(double V) const { bool ignored; @@ -1770,7 +1770,7 @@ static bool classof(const ConstantFPSDNode *) { return true; } static bool classof(const SDNode *N) { - return N->getOpcode() == ISD::ConstantFP || + return N->getOpcode() == ISD::ConstantFP || N->getOpcode() == ISD::TargetConstantFP; } }; @@ -1801,7 +1801,7 @@ protected: friend class SelectionDAG; FrameIndexSDNode(int fi, MVT VT, bool isTarg) - : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, + : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, DebugLoc::getUnknownLoc(), getSDVTList(VT)), FI(fi) { } public: @@ -1824,9 +1824,9 @@ DebugLoc::getUnknownLoc(), getSDVTList(VT)), JTI(jti) { } public: - + int getIndex() const { return JTI; } - + static bool classof(const JumpTableSDNode *) { return true; } static bool classof(const SDNode *N) { return N->getOpcode() == ISD::JumpTable || @@ -1859,7 +1859,7 @@ } ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v, MVT VT, int o=0) - : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, + : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, DebugLoc::getUnknownLoc(), getSDVTList(VT)), Offset(o), Alignment(0) { assert((int)Offset >= 0 && "Offset is too large"); @@ -1894,7 +1894,7 @@ int getOffset() const { return Offset & ~(1 << (sizeof(unsigned)*8-1)); } - + // Return the alignment of this constant pool object, which is either 0 (for // default alignment) or log2 of the desired value. unsigned getAlignment() const { return Alignment; } @@ -2087,7 +2087,7 @@ friend class SelectionDAG; explicit CvtRndSatSDNode(MVT VT, DebugLoc dl, const SDValue *Ops, unsigned NumOps, ISD::CvtCode Code) - : SDNode(ISD::CONVERT_RNDSAT, dl, getSDVTList(VT), Ops, NumOps), + : SDNode(ISD::CONVERT_RNDSAT, dl, getSDVTList(VT), Ops, NumOps), CvtCode(Code) { assert(NumOps == 5 && "wrong number of operations"); } @@ -2150,14 +2150,14 @@ void setNest() { Flags |= One << NestOffs; } unsigned getByValAlign() const { - return (unsigned) + return (unsigned) ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2); } void setByValAlign(unsigned A) { Flags = (Flags & ~ByValAlign) | (uint64_t(Log2_32(A) + 1) << ByValAlignOffs); } - + bool isSplit() const { return Flags & Split; } void setSplit() { Flags |= One << SplitOffs; } @@ -2214,8 +2214,8 @@ bool Inreg; protected: friend class SelectionDAG; - CallSDNode(unsigned cc, DebugLoc dl, bool isvararg, bool istailcall, - bool isinreg, SDVTList VTs, const SDValue *Operands, + CallSDNode(unsigned cc, DebugLoc dl, bool isvararg, bool istailcall, + bool isinreg, SDVTList VTs, const SDValue *Operands, unsigned numOperands) : SDNode(ISD::CALL, dl, VTs, Operands, numOperands), CallingConv(cc), IsVarArg(isvararg), IsTailCall(istailcall), Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=64827&r1=64826&r2=64827&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original) +++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Tue Feb 17 16:15:04 2009 @@ -9,7 +9,7 @@ // // This pass combines dag nodes to form fewer, simpler DAG nodes. It can be run // both before and after the DAG is legalized. -// +// //===----------------------------------------------------------------------===// #define DEBUG_TYPE "dagcombine" @@ -89,14 +89,14 @@ WorkList.erase(std::remove(WorkList.begin(), WorkList.end(), N), WorkList.end()); } - + SDValue CombineTo(SDNode *N, const SDValue *To, unsigned NumTo, bool AddTo = true); - + SDValue CombineTo(SDNode *N, SDValue Res, bool AddTo = true) { return CombineTo(N, &Res, 1, AddTo); } - + SDValue CombineTo(SDNode *N, SDValue Res0, SDValue Res1, bool AddTo = true) { SDValue To[] = { Res0, Res1 }; @@ -104,9 +104,9 @@ } void CommitTargetLoweringOpt(const TargetLowering::TargetLoweringOpt &TLO); - - private: - + + private: + /// SimplifyDemandedBits - Check the specified integer node value to see if /// it can be simplified or if things it uses can be simplified by bit /// propagation. If so, return true. @@ -119,8 +119,8 @@ bool CombineToPreIndexedLoadStore(SDNode *N); bool CombineToPostIndexedLoadStore(SDNode *N); - - + + /// combine - call the node-specific routine that knows how to fold each /// particular type of node. If that doesn't do anything, try the /// target-specific DAG combines. @@ -197,18 +197,18 @@ SDValue XformToShuffleWithZero(SDNode *N); SDValue ReassociateOps(unsigned Opc, DebugLoc DL, SDValue LHS, SDValue RHS); - + SDValue visitShiftByConstant(SDNode *N, unsigned Amt); bool SimplifySelectOps(SDNode *SELECT, SDValue LHS, SDValue RHS); SDValue SimplifyBinOpWithSameOpcodeHands(SDNode *N); SDValue SimplifySelect(DebugLoc DL, SDValue N0, SDValue N1, SDValue N2); - SDValue SimplifySelectCC(DebugLoc DL, SDValue N0, SDValue N1, SDValue N2, - SDValue N3, ISD::CondCode CC, + SDValue SimplifySelectCC(DebugLoc DL, SDValue N0, SDValue N1, SDValue N2, + SDValue N3, ISD::CondCode CC, bool NotExtCompare = false); SDValue SimplifySetCC(MVT VT, SDValue N0, SDValue N1, ISD::CondCode Cond, DebugLoc DL, bool foldBooleans = true); - SDValue SimplifyNodeWithTwoResults(SDNode *N, unsigned LoOp, + SDValue SimplifyNodeWithTwoResults(SDNode *N, unsigned LoOp, unsigned HiOp); SDValue CombineConsecutiveLoads(SDNode *N, MVT VT); SDValue ConstantFoldBIT_CONVERTofBUILD_VECTOR(SDNode *, MVT); @@ -216,9 +216,9 @@ SDValue BuildUDIV(SDNode *N); SDNode *MatchRotate(SDValue LHS, SDValue RHS, DebugLoc DL); SDValue ReduceLoadWidth(SDNode *N); - + SDValue GetDemandedBits(SDValue V, const APInt &Mask); - + /// GatherAllAliases - Walk up chain skipping non-aliasing memory nodes, /// looking for aliasing nodes and adding them to the Aliases vector. void GatherAllAliases(SDNode *N, SDValue OriginalChain, @@ -230,13 +230,13 @@ const Value *SrcValue1, int SrcValueOffset1, SDValue Ptr2, int64_t Size2, const Value *SrcValue2, int SrcValueOffset2) const; - + /// FindAliasInfo - Extracts the relevant alias information from the memory /// node. Returns true if the operand was a load. bool FindAliasInfo(SDNode *N, SDValue &Ptr, int64_t &Size, const Value *&SrcValue, int &SrcValueOffset) const; - + /// FindBetterChain - Walk up chain skipping non-aliasing memory nodes, /// looking for a better chain (aliasing node.) SDValue FindBetterChain(SDNode *N, SDValue Chain); @@ -256,7 +256,7 @@ LegalTypes(false), Fast(fast), AA(A) {} - + /// Run - runs the dag combiner on all nodes in the work list void Run(CombineLevel AtLevel); }; @@ -266,16 +266,16 @@ namespace { /// WorkListRemover - This class is a DAGUpdateListener that removes any deleted /// nodes from the worklist. -class VISIBILITY_HIDDEN WorkListRemover : +class VISIBILITY_HIDDEN WorkListRemover : public SelectionDAG::DAGUpdateListener { DAGCombiner &DC; public: explicit WorkListRemover(DAGCombiner &dc) : DC(dc) {} - + virtual void NodeDeleted(SDNode *N, SDNode *E) { DC.removeFromWorkList(N); } - + virtual void NodeUpdated(SDNode *N) { // Ignore updates. } @@ -326,13 +326,13 @@ // fneg is removable even if it has multiple uses. if (Op.getOpcode() == ISD::FNEG) return 2; - + // Don't allow anything with multiple uses. if (!Op.hasOneUse()) return 0; - + // Don't recurse exponentially. if (Depth > 6) return 0; - + switch (Op.getOpcode()) { default: return false; case ISD::ConstantFP: @@ -342,29 +342,29 @@ case ISD::FADD: // FIXME: determine better conditions for this xform. if (!UnsafeFPMath) return 0; - + // fold (fsub (fadd A, B)) -> (fsub (fneg A), B) if (char V = isNegatibleForFree(Op.getOperand(0), LegalOperations, Depth+1)) return V; // fold (fneg (fadd A, B)) -> (fsub (fneg B), A) return isNegatibleForFree(Op.getOperand(1), LegalOperations, Depth+1); case ISD::FSUB: - // We can't turn -(A-B) into B-A when we honor signed zeros. + // We can't turn -(A-B) into B-A when we honor signed zeros. if (!UnsafeFPMath) return 0; - + // fold (fneg (fsub A, B)) -> (fsub B, A) return 1; - + case ISD::FMUL: case ISD::FDIV: if (HonorSignDependentRoundingFPMath()) return 0; - + // fold (fneg (fmul X, Y)) -> (fmul (fneg X), Y) or (fmul X, (fneg Y)) if (char V = isNegatibleForFree(Op.getOperand(0), LegalOperations, Depth+1)) return V; - + return isNegatibleForFree(Op.getOperand(1), LegalOperations, Depth+1); - + case ISD::FP_EXTEND: case ISD::FP_ROUND: case ISD::FSIN: @@ -378,10 +378,10 @@ bool LegalOperations, unsigned Depth = 0) { // fneg is removable even if it has multiple uses. if (Op.getOpcode() == ISD::FNEG) return Op.getOperand(0); - + // Don't allow anything with multiple uses. assert(Op.hasOneUse() && "Unknown reuse!"); - + assert(Depth <= 6 && "GetNegatedExpression doesn't match isNegatibleForFree"); switch (Op.getOpcode()) { default: assert(0 && "Unknown code"); @@ -393,56 +393,56 @@ case ISD::FADD: // FIXME: determine better conditions for this xform. assert(UnsafeFPMath); - + // fold (fneg (fadd A, B)) -> (fsub (fneg A), B) if (isNegatibleForFree(Op.getOperand(0), LegalOperations, Depth+1)) return DAG.getNode(ISD::FSUB, Op.getDebugLoc(), Op.getValueType(), - GetNegatedExpression(Op.getOperand(0), DAG, + GetNegatedExpression(Op.getOperand(0), DAG, LegalOperations, Depth+1), Op.getOperand(1)); // fold (fneg (fadd A, B)) -> (fsub (fneg B), A) return DAG.getNode(ISD::FSUB, Op.getDebugLoc(), Op.getValueType(), - GetNegatedExpression(Op.getOperand(1), DAG, + GetNegatedExpression(Op.getOperand(1), DAG, LegalOperations, Depth+1), Op.getOperand(0)); case ISD::FSUB: - // We can't turn -(A-B) into B-A when we honor signed zeros. + // We can't turn -(A-B) into B-A when we honor signed zeros. assert(UnsafeFPMath); // fold (fneg (fsub 0, B)) -> B if (ConstantFPSDNode *N0CFP = dyn_cast(Op.getOperand(0))) if (N0CFP->getValueAPF().isZero()) return Op.getOperand(1); - + // fold (fneg (fsub A, B)) -> (fsub B, A) return DAG.getNode(ISD::FSUB, Op.getDebugLoc(), Op.getValueType(), Op.getOperand(1), Op.getOperand(0)); - + case ISD::FMUL: case ISD::FDIV: assert(!HonorSignDependentRoundingFPMath()); - + // fold (fneg (fmul X, Y)) -> (fmul (fneg X), Y) if (isNegatibleForFree(Op.getOperand(0), LegalOperations, Depth+1)) return DAG.getNode(Op.getOpcode(), Op.getDebugLoc(), Op.getValueType(), - GetNegatedExpression(Op.getOperand(0), DAG, + GetNegatedExpression(Op.getOperand(0), DAG, LegalOperations, Depth+1), Op.getOperand(1)); - + // fold (fneg (fmul X, Y)) -> (fmul X, (fneg Y)) return DAG.getNode(Op.getOpcode(), Op.getDebugLoc(), Op.getValueType(), Op.getOperand(0), GetNegatedExpression(Op.getOperand(1), DAG, LegalOperations, Depth+1)); - + case ISD::FP_EXTEND: case ISD::FSIN: return DAG.getNode(Op.getOpcode(), Op.getDebugLoc(), Op.getValueType(), - GetNegatedExpression(Op.getOperand(0), DAG, + GetNegatedExpression(Op.getOperand(0), DAG, LegalOperations, Depth+1)); case ISD::FP_ROUND: return DAG.getNode(ISD::FP_ROUND, Op.getDebugLoc(), Op.getValueType(), - GetNegatedExpression(Op.getOperand(0), DAG, + GetNegatedExpression(Op.getOperand(0), DAG, LegalOperations, Depth+1), Op.getOperand(1)); } @@ -451,7 +451,7 @@ // isSetCCEquivalent - Return true if this node is a setcc, or is a select_cc // that selects between the values 1 and 0, making it equivalent to a setcc. -// Also, set the incoming LHS, RHS, and CC references to the appropriate +// Also, set the incoming LHS, RHS, and CC references to the appropriate // nodes based on the type of node we are checking. This simplifies life a // bit for the callers. static bool isSetCCEquivalent(SDValue N, SDValue &LHS, SDValue &RHS, @@ -462,7 +462,7 @@ CC = N.getOperand(2); return true; } - if (N.getOpcode() == ISD::SELECT_CC && + if (N.getOpcode() == ISD::SELECT_CC && N.getOperand(2).getOpcode() == ISD::Constant && N.getOperand(3).getOpcode() == ISD::Constant && cast(N.getOperand(2))->getAPIntValue() == 1 && @@ -537,7 +537,7 @@ "Cannot combine value to value of different type!")); WorkListRemover DeadNodes(*this); DAG.ReplaceAllUsesWith(N, To, &DeadNodes); - + if (AddTo) { // Push the new nodes and any users onto the worklist for (unsigned i = 0, e = NumTo; i != e; ++i) { @@ -545,7 +545,7 @@ AddUsersToWorkList(To[i].getNode()); } } - + // Finally, if the node is now dead, remove it from the graph. The node // may not be dead if the replacement process recursively simplified to // something else needing this node. @@ -553,7 +553,7 @@ // Nodes can be reintroduced into the worklist. Make sure we do not // process a node that has been replaced. removeFromWorkList(N); - + // Finally, since the node is now dead, remove it from the graph. DAG.DeleteNode(N); } @@ -563,7 +563,7 @@ void DAGCombiner::CommitTargetLoweringOpt(const TargetLowering::TargetLoweringOpt & TLO) { - // Replace all uses. If any nodes become isomorphic to other nodes and + // Replace all uses. If any nodes become isomorphic to other nodes and // are deleted, make sure to remove them from our worklist. WorkListRemover DeadNodes(*this); DAG.ReplaceAllUsesOfValueWith(TLO.Old, TLO.New, &DeadNodes); @@ -571,19 +571,19 @@ // Push the new node and any (possibly new) users onto the worklist. AddToWorkList(TLO.New.getNode()); AddUsersToWorkList(TLO.New.getNode()); - + // Finally, if the node is now dead, remove it from the graph. The node // may not be dead if the replacement process recursively simplified to // something else needing this node. if (TLO.Old.getNode()->use_empty()) { removeFromWorkList(TLO.Old.getNode()); - + // If the operands of this node are only used by the node, they will now // be dead. Make sure to visit them first to delete dead nodes early. for (unsigned i = 0, e = TLO.Old.getNode()->getNumOperands(); i != e; ++i) if (TLO.Old.getNode()->getOperand(i).getNode()->hasOneUse()) AddToWorkList(TLO.Old.getNode()->getOperand(i).getNode()); - + DAG.DeleteNode(TLO.Old.getNode()); } } @@ -596,16 +596,16 @@ APInt KnownZero, KnownOne; if (!TLI.SimplifyDemandedBits(Op, Demanded, KnownZero, KnownOne, TLO)) return false; - + // Revisit the node. AddToWorkList(Op.getNode()); - + // Replace the old value with the new one. ++NodesCombined; DOUT << "\nReplacing.2 "; DEBUG(TLO.Old.getNode()->dump(&DAG)); DOUT << "\nWith: "; DEBUG(TLO.New.getNode()->dump(&DAG)); DOUT << '\n'; - + CommitTargetLoweringOpt(TLO); return true; } @@ -630,42 +630,42 @@ // to the root node, preventing it from being deleted, and tracking any // changes of the root. HandleSDNode Dummy(DAG.getRoot()); - + // The root of the dag may dangle to deleted nodes until the dag combiner is // done. Set it to null to avoid confusion. DAG.setRoot(SDValue()); - + // while the worklist isn't empty, inspect the node on the end of it and // try and combine it. while (!WorkList.empty()) { SDNode *N = WorkList.back(); WorkList.pop_back(); - + // If N has no uses, it is dead. Make sure to revisit all N's operands once // N is deleted from the DAG, since they too may now be dead or may have a // reduced number of uses, allowing other xforms. if (N->use_empty() && N != &Dummy) { for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) AddToWorkList(N->getOperand(i).getNode()); - + DAG.DeleteNode(N); continue; } - + SDValue RV = combine(N); - + if (RV.getNode() == 0) continue; - + ++NodesCombined; - + // If we get back the same node we passed in, rather than a new node or // zero, we know that the node must have defined multiple values and - // CombineTo was used. Since CombineTo takes care of the worklist + // CombineTo was used. Since CombineTo takes care of the worklist // mechanics for us, we have no work to do in this case. if (RV.getNode() == N) continue; - + assert(N->getOpcode() != ISD::DELETED_NODE && RV.getNode()->getOpcode() != ISD::DELETED_NODE && "Node was deleted but visit returned new node!"); @@ -682,17 +682,17 @@ SDValue OpV = RV; DAG.ReplaceAllUsesWith(N, &OpV, &DeadNodes); } - + // Push the new node and any users onto the worklist AddToWorkList(RV.getNode()); AddUsersToWorkList(RV.getNode()); - + // Add any uses of the old node to the worklist in case this node is the // last one that uses them. They may become dead after this node is // deleted. for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) AddToWorkList(N->getOperand(i).getNode()); - + // Finally, if the node is now dead, remove it from the graph. The node // may not be dead if the replacement process recursively simplified to // something else needing this node. @@ -700,12 +700,12 @@ // Nodes can be reintroduced into the worklist. Make sure we do not // process a node that has been replaced. removeFromWorkList(N); - + // Finally, since the node is now dead, remove it from the graph. DAG.DeleteNode(N); } } - + // If the root changed (e.g. it was a dead load, update the root). DAG.setRoot(Dummy.getValue()); } @@ -789,16 +789,16 @@ TLI.hasTargetDAGCombine((ISD::NodeType)N->getOpcode())) { // Expose the DAG combiner to the target combiner impls. - TargetLowering::DAGCombinerInfo + TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, Level == Unrestricted, false, this); RV = TLI.PerformDAGCombine(N, DagCombineInfo); } } - // If N is a commutative binary node, try commuting it to enable more + // If N is a commutative binary node, try commuting it to enable more // sdisel CSE. - if (RV.getNode() == 0 && + if (RV.getNode() == 0 && SelectionDAG::isCommutativeBinOp(N->getOpcode()) && N->getNumValues() == 1) { SDValue N0 = N->getOperand(0); @@ -815,7 +815,7 @@ } return RV; -} +} /// getInputChainForNode - Given a node, return its input chain if it has one, /// otherwise return a null sd operand. @@ -841,31 +841,31 @@ if (getInputChainForNode(N->getOperand(1).getNode()) == N->getOperand(0)) return N->getOperand(1); } - + SmallVector TFs; // List of token factors to visit. SmallVector Ops; // Ops for replacing token factor. - SmallPtrSet SeenOps; + SmallPtrSet SeenOps; bool Changed = false; // If we should replace this token factor. - + // Start out with this token factor. TFs.push_back(N); - + // Iterate through token factors. The TFs grows when new token factors are // encountered. for (unsigned i = 0; i < TFs.size(); ++i) { SDNode *TF = TFs[i]; - + // Check each of the operands. for (unsigned i = 0, ie = TF->getNumOperands(); i != ie; ++i) { SDValue Op = TF->getOperand(i); - + switch (Op.getOpcode()) { case ISD::EntryToken: // Entry tokens don't need to be added to the list. They are // rededundant. Changed = true; break; - + case ISD::TokenFactor: if ((CombinerAA || Op.hasOneUse()) && std::find(TFs.begin(), TFs.end(), Op.getNode()) == TFs.end()) { @@ -877,7 +877,7 @@ break; } // Fall thru - + default: // Only add if it isn't already in the list. if (SeenOps.insert(Op.getNode())) @@ -905,7 +905,7 @@ // Don't add users to work list. return CombineTo(N, Result, false); } - + return Result; } @@ -1092,7 +1092,7 @@ if (!VT.isVector() && SimplifyDemandedBits(SDValue(N, 0))) return SDValue(N, 0); - + // fold (a+b) -> (a|b) iff a and b share no bits. if (VT.isInteger() && !VT.isVector()) { APInt LHSZero, LHSOne; @@ -1102,7 +1102,7 @@ if (LHSZero.getBoolValue()) { DAG.ComputeMaskedBits(N1, Mask, RHSZero, RHSOne); - + // If all possibly-set bits on the LHS are clear on the RHS, return an OR. // If all possibly-set bits on the RHS are clear on the LHS, return an OR. if ((RHSZero & (~LHSZero & Mask)) == (~LHSZero & Mask) || @@ -1140,22 +1140,22 @@ ConstantSDNode *N0C = dyn_cast(N0); ConstantSDNode *N1C = dyn_cast(N1); MVT VT = N0.getValueType(); - + // If the flag result is dead, turn this into an ADD. if (N->hasNUsesOfValue(0, 1)) return CombineTo(N, DAG.getNode(ISD::ADD, N->getDebugLoc(), VT, N1, N0), DAG.getNode(ISD::CARRY_FALSE, N->getDebugLoc(), MVT::Flag)); - + // canonicalize constant to RHS. if (N0C && !N1C) return DAG.getNode(ISD::ADDC, N->getDebugLoc(), N->getVTList(), N1, N0); - + // fold (addc x, 0) -> x + no carry out if (N1C && N1C->isNullValue()) return CombineTo(N, N0, DAG.getNode(ISD::CARRY_FALSE, N->getDebugLoc(), MVT::Flag)); - + // fold (addc a, b) -> (or a, b), CARRY_FALSE iff a and b share no bits. APInt LHSZero, LHSOne; APInt RHSZero, RHSOne; @@ -1164,7 +1164,7 @@ if (LHSZero.getBoolValue()) { DAG.ComputeMaskedBits(N1, Mask, RHSZero, RHSOne); - + // If all possibly-set bits on the LHS are clear on the RHS, return an OR. // If all possibly-set bits on the RHS are clear on the LHS, return an OR. if ((RHSZero & (~LHSZero & Mask)) == (~LHSZero & Mask) || @@ -1173,7 +1173,7 @@ DAG.getNode(ISD::CARRY_FALSE, N->getDebugLoc(), MVT::Flag)); } - + return SDValue(); } @@ -1183,16 +1183,16 @@ SDValue CarryIn = N->getOperand(2); ConstantSDNode *N0C = dyn_cast(N0); ConstantSDNode *N1C = dyn_cast(N1); - + // canonicalize constant to RHS if (N0C && !N1C) return DAG.getNode(ISD::ADDE, N->getDebugLoc(), N->getVTList(), N1, N0, CarryIn); - + // fold (adde x, y, false) -> (addc x, y) if (CarryIn.getOpcode() == ISD::CARRY_FALSE) return DAG.getNode(ISD::ADDC, N->getDebugLoc(), N->getVTList(), N1, N0); - + return SDValue(); } @@ -1202,7 +1202,7 @@ ConstantSDNode *N0C = dyn_cast(N0.getNode()); ConstantSDNode *N1C = dyn_cast(N1.getNode()); MVT VT = N0.getValueType(); - + // fold vector ops if (VT.isVector()) { SDValue FoldedVOp = SimplifyVBinOp(N); @@ -1224,7 +1224,7 @@ return N0.getOperand(1); // fold (A+B)-B -> A if (N0.getOpcode() == ISD::ADD && N0.getOperand(1) == N1) - return N0.getOperand(0); + return N0.getOperand(0); // fold ((A+(B+or-C))-B) -> A+or-C if (N0.getOpcode() == ISD::ADD && (N0.getOperand(1).getOpcode() == ISD::SUB || @@ -1280,13 +1280,13 @@ ConstantSDNode *N0C = dyn_cast(N0); ConstantSDNode *N1C = dyn_cast(N1); MVT VT = N0.getValueType(); - + // fold vector ops if (VT.isVector()) { SDValue FoldedVOp = SimplifyVBinOp(N); if (FoldedVOp.getNode()) return FoldedVOp; } - + // fold (mul x, undef) -> 0 if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF) return DAG.getConstant(0, VT); @@ -1310,7 +1310,7 @@ getShiftAmountTy())); // fold (mul x, -(1 << c)) -> -(x << c) or (-x) << c if (N1C && isPowerOf2_64(-N1C->getSExtValue())) - // FIXME: If the input is something that is easily negated (e.g. a + // FIXME: If the input is something that is easily negated (e.g. a // single-use add), we should put the negate there. return DAG.getNode(ISD::SUB, N->getDebugLoc(), VT, DAG.getConstant(0, VT), @@ -1326,7 +1326,7 @@ return DAG.getNode(ISD::MUL, N->getDebugLoc(), VT, N0.getOperand(0), C3); } - + // Change (mul (shl X, C), Y) -> (shl (mul X, Y), C) when the shift has one // use. { @@ -1335,7 +1335,7 @@ if (N0.getOpcode() == ISD::SHL && isa(N0.getOperand(1)) && N0.getNode()->hasOneUse()) { Sh = N0; Y = N1; - } else if (N1.getOpcode() == ISD::SHL && + } else if (N1.getOpcode() == ISD::SHL && isa(N1.getOperand(1)) && N1.getNode()->hasOneUse()) { Sh = N1; Y = N0; @@ -1350,14 +1350,14 @@ } // fold (mul (add x, c1), c2) -> (add (mul x, c2), c1*c2) - if (N1C && N0.getOpcode() == ISD::ADD && N0.getNode()->hasOneUse() && + if (N1C && N0.getOpcode() == ISD::ADD && N0.getNode()->hasOneUse() && isa(N0.getOperand(1))) return DAG.getNode(ISD::ADD, N->getDebugLoc(), VT, DAG.getNode(ISD::MUL, N0.getDebugLoc(), VT, N0.getOperand(0), N1), DAG.getNode(ISD::MUL, N1.getDebugLoc(), VT, N0.getOperand(1), N1)); - + // reassociate mul SDValue RMUL = ReassociateOps(ISD::MUL, N->getDebugLoc(), N0, N1); if (RMUL.getNode() != 0) @@ -1378,7 +1378,7 @@ SDValue FoldedVOp = SimplifyVBinOp(N); if (FoldedVOp.getNode()) return FoldedVOp; } - + // fold (sdiv c1, c2) -> c1/c2 if (N0C && N1C && !N1C->isNullValue()) return DAG.FoldConstantArithmetic(ISD::SDIV, VT, N0C, N1C); @@ -1398,7 +1398,7 @@ } // fold (sdiv X, pow2) -> simple ops after legalize if (N1C && !N1C->isNullValue() && !TLI.isIntDivCheap() && - (isPowerOf2_64(N1C->getSExtValue()) || + (isPowerOf2_64(N1C->getSExtValue()) || isPowerOf2_64(-N1C->getSExtValue()))) { // If dividing by powers of two is cheap, then don't perform the following // fold. @@ -1437,7 +1437,7 @@ // if integer divide is expensive and we satisfy the requirements, emit an // alternate sequence. - if (N1C && (N1C->getSExtValue() < -1 || N1C->getSExtValue() > 1) && + if (N1C && (N1C->getSExtValue() < -1 || N1C->getSExtValue() > 1) && !TLI.isIntDivCheap()) { SDValue Op = BuildSDIV(N); if (Op.getNode()) return Op; @@ -1459,19 +1459,19 @@ ConstantSDNode *N0C = dyn_cast(N0.getNode()); ConstantSDNode *N1C = dyn_cast(N1.getNode()); MVT VT = N->getValueType(0); - + // fold vector ops if (VT.isVector()) { SDValue FoldedVOp = SimplifyVBinOp(N); if (FoldedVOp.getNode()) return FoldedVOp; } - + // fold (udiv c1, c2) -> c1/c2 if (N0C && N1C && !N1C->isNullValue()) return DAG.FoldConstantArithmetic(ISD::UDIV, VT, N0C, N1C); // fold (udiv x, (1 << c)) -> x >>u c if (N1C && N1C->getAPIntValue().isPowerOf2()) - return DAG.getNode(ISD::SRL, N->getDebugLoc(), VT, N0, + return DAG.getNode(ISD::SRL, N->getDebugLoc(), VT, N0, DAG.getConstant(N1C->getAPIntValue().logBase2(), getShiftAmountTy())); // fold (udiv x, (shl c, y)) -> x >>u (log2(c)+y) iff c is power of 2 @@ -1511,7 +1511,7 @@ ConstantSDNode *N0C = dyn_cast(N0); ConstantSDNode *N1C = dyn_cast(N1); MVT VT = N->getValueType(0); - + // fold (srem c1, c2) -> c1%c2 if (N0C && N1C && !N1C->isNullValue()) return DAG.FoldConstantArithmetic(ISD::SREM, VT, N0C, N1C); @@ -1521,7 +1521,7 @@ if (DAG.SignBitIsZero(N1) && DAG.SignBitIsZero(N0)) return DAG.getNode(ISD::UREM, N->getDebugLoc(), VT, N0, N1); } - + // If X/C can be simplified by the division-by-constant logic, lower // X%C to the equivalent of X-X/C*C. if (N1C && !N1C->isNullValue()) { @@ -1536,7 +1536,7 @@ return Sub; } } - + // undef % X -> 0 if (N0.getOpcode() == ISD::UNDEF) return DAG.getConstant(0, VT); @@ -1553,7 +1553,7 @@ ConstantSDNode *N0C = dyn_cast(N0); ConstantSDNode *N1C = dyn_cast(N1); MVT VT = N->getValueType(0); - + // fold (urem c1, c2) -> c1%c2 if (N0C && N1C && !N1C->isNullValue()) return DAG.FoldConstantArithmetic(ISD::UREM, VT, N0C, N1C); @@ -1574,7 +1574,7 @@ } } } - + // If X/C can be simplified by the division-by-constant logic, lower // X%C to the equivalent of X-X/C*C. if (N1C && !N1C->isNullValue()) { @@ -1589,7 +1589,7 @@ return Sub; } } - + // undef % X -> 0 if (N0.getOpcode() == ISD::UNDEF) return DAG.getConstant(0, VT); @@ -1605,7 +1605,7 @@ SDValue N1 = N->getOperand(1); ConstantSDNode *N1C = dyn_cast(N1); MVT VT = N->getValueType(0); - + // fold (mulhs x, 0) -> 0 if (N1C && N1C->isNullValue()) return N1; @@ -1626,7 +1626,7 @@ SDValue N1 = N->getOperand(1); ConstantSDNode *N1C = dyn_cast(N1); MVT VT = N->getValueType(0); - + // fold (mulhu x, 0) -> 0 if (N1C && N1C->isNullValue()) return N1; @@ -1644,7 +1644,7 @@ /// compute two values. LoOp and HiOp give the opcodes for the two computations /// that are being performed. Return true if a simplification was made. /// -SDValue DAGCombiner::SimplifyNodeWithTwoResults(SDNode *N, unsigned LoOp, +SDValue DAGCombiner::SimplifyNodeWithTwoResults(SDNode *N, unsigned LoOp, unsigned HiOp) { // If the high half is not needed, just compute the low half. bool HiExists = N->hasAnyUseOfValue(1); @@ -1713,14 +1713,14 @@ SDValue DAGCombiner::visitSDIVREM(SDNode *N) { SDValue Res = SimplifyNodeWithTwoResults(N, ISD::SDIV, ISD::SREM); if (Res.getNode()) return Res; - + return SDValue(); } SDValue DAGCombiner::visitUDIVREM(SDNode *N) { SDValue Res = SimplifyNodeWithTwoResults(N, ISD::UDIV, ISD::UREM); if (Res.getNode()) return Res; - + return SDValue(); } @@ -1730,7 +1730,7 @@ SDValue N0 = N->getOperand(0), N1 = N->getOperand(1); MVT VT = N0.getValueType(); assert(N0.getOpcode() == N1.getOpcode() && "Bad input!"); - + // For each of OP in AND/OR/XOR: // fold (OP (zext x), (zext y)) -> (zext (OP x, y)) // fold (OP (sext x), (sext y)) -> (sext (OP x, y)) @@ -1745,7 +1745,7 @@ AddToWorkList(ORNode.getNode()); return DAG.getNode(N0.getOpcode(), N->getDebugLoc(), VT, ORNode); } - + // For each of OP in SHL/SRL/SRA/AND... // fold (and (OP x, z), (OP y, z)) -> (OP (and x, y), z) // fold (or (OP x, z), (OP y, z)) -> (OP (or x, y), z) @@ -1760,7 +1760,7 @@ return DAG.getNode(N0.getOpcode(), N->getDebugLoc(), VT, ORNode, N0.getOperand(1)); } - + return SDValue(); } @@ -1772,13 +1772,13 @@ ConstantSDNode *N1C = dyn_cast(N1); MVT VT = N1.getValueType(); unsigned BitWidth = VT.getSizeInBits(); - + // fold vector ops if (VT.isVector()) { SDValue FoldedVOp = SimplifyVBinOp(N); if (FoldedVOp.getNode()) return FoldedVOp; } - + // fold (and x, undef) -> 0 if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF) return DAG.getConstant(0, VT); @@ -1812,10 +1812,10 @@ if (DAG.MaskedValueIsZero(N0Op0, Mask)) { SDValue Zext = DAG.getNode(ISD::ZERO_EXTEND, N->getDebugLoc(), N0.getValueType(), N0Op0); - + // Replace uses of the AND with uses of the Zero extend node. CombineTo(N, Zext); - + // We actually want to replace all uses of the any_extend with the // zero_extend, to avoid duplicating things. This will later cause this // AND to be folded. @@ -1827,7 +1827,7 @@ if (isSetCCEquivalent(N0, LL, LR, CC0) && isSetCCEquivalent(N1, RL, RR, CC1)){ ISD::CondCode Op0 = cast(CC0)->get(); ISD::CondCode Op1 = cast(CC1)->get(); - + if (LR == RR && isa(LR) && Op0 == Op1 && LL.getValueType().isInteger()) { // fold (and (seteq X, 0), (seteq Y, 0)) -> (seteq (or X, Y), 0) @@ -1872,7 +1872,7 @@ SDValue Tmp = SimplifyBinOpWithSameOpcodeHands(N); if (Tmp.getNode()) return Tmp; } - + // fold (and (sign_extend_inreg x, i16 to i32), 1) -> (and x, 1) // fold (and (sra)) -> (and (srl)) when possible. if (!VT.isVector() && @@ -1921,7 +1921,7 @@ return SDValue(N, 0); // Return N so it doesn't get rechecked! } } - + // fold (and (load x), 255) -> (zextload x, i8) // fold (and (extload x, i16), 255) -> (zextload x, i8) if (N1C && N0.getOpcode() == ISD::LOAD) { @@ -1969,7 +1969,7 @@ } } } - + return SDValue(); } @@ -1980,13 +1980,13 @@ ConstantSDNode *N0C = dyn_cast(N0); ConstantSDNode *N1C = dyn_cast(N1); MVT VT = N1.getValueType(); - + // fold vector ops if (VT.isVector()) { SDValue FoldedVOp = SimplifyVBinOp(N); if (FoldedVOp.getNode()) return FoldedVOp; } - + // fold (or x, undef) -> -1 if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF) return DAG.getConstant(~0ULL, VT); @@ -2022,12 +2022,12 @@ if (isSetCCEquivalent(N0, LL, LR, CC0) && isSetCCEquivalent(N1, RL, RR, CC1)){ ISD::CondCode Op0 = cast(CC0)->get(); ISD::CondCode Op1 = cast(CC1)->get(); - + if (LR == RR && isa(LR) && Op0 == Op1 && LL.getValueType().isInteger()) { // fold (or (setne X, 0), (setne Y, 0)) -> (setne (or X, Y), 0) // fold (or (setlt X, 0), (setlt Y, 0)) -> (setne (or X, Y), 0) - if (cast(LR)->isNullValue() && + if (cast(LR)->isNullValue() && (Op1 == ISD::SETNE || Op1 == ISD::SETLT)) { SDValue ORNode = DAG.getNode(ISD::OR, LR.getDebugLoc(), LR.getValueType(), LL, RL); @@ -2036,7 +2036,7 @@ } // fold (or (setne X, -1), (setne Y, -1)) -> (setne (and X, Y), -1) // fold (or (setgt X, -1), (setgt Y -1)) -> (setgt (and X, Y), -1) - if (cast(LR)->isAllOnesValue() && + if (cast(LR)->isAllOnesValue() && (Op1 == ISD::SETNE || Op1 == ISD::SETGT)) { SDValue ANDNode = DAG.getNode(ISD::AND, LR.getDebugLoc(), LR.getValueType(), LL, RL); @@ -2058,13 +2058,13 @@ LL, LR, Result); } } - + // Simplify: (or (op x...), (op y...)) -> (op (or x, y)) if (N0.getOpcode() == N1.getOpcode()) { SDValue Tmp = SimplifyBinOpWithSameOpcodeHands(N); if (Tmp.getNode()) return Tmp; } - + // (or (and X, C1), (and Y, C2)) -> (and (or X, Y), C3) if possible. if (N0.getOpcode() == ISD::AND && N1.getOpcode() == ISD::AND && @@ -2078,7 +2078,7 @@ cast(N0.getOperand(1))->getAPIntValue(); const APInt &RHSMask = cast(N1.getOperand(1))->getAPIntValue(); - + if (DAG.MaskedValueIsZero(N0.getOperand(0), RHSMask&~LHSMask) && DAG.MaskedValueIsZero(N1.getOperand(0), LHSMask&~RHSMask)) { SDValue X = DAG.getNode(ISD::OR, N0.getDebugLoc(), VT, @@ -2087,7 +2087,7 @@ DAG.getConstant(LHSMask | RHSMask, VT)); } } - + // See if this is some rotate idiom. if (SDNode *Rot = MatchRotate(N0, N1, N->getDebugLoc())) return SDValue(Rot, 0); @@ -2105,13 +2105,13 @@ return false; } } - + if (Op.getOpcode() == ISD::SRL || Op.getOpcode() == ISD::SHL) { Shift = Op; return true; } - return false; + return false; } // MatchRotate - Handle an 'or' of two operands. If this is one of the many @@ -2137,13 +2137,13 @@ SDValue RHSMask; // AND value if any. if (!MatchRotateHalf(RHS, RHSShift, RHSMask)) return 0; // Not part of a rotate. - + if (LHSShift.getOperand(0) != RHSShift.getOperand(0)) return 0; // Not shifting the same value. if (LHSShift.getOpcode() == RHSShift.getOpcode()) return 0; // Shifts must disagree. - + // Canonicalize shl to left side in a shl/srl pair. if (RHSShift.getOpcode() == ISD::SHL) { std::swap(LHS, RHS); @@ -2170,11 +2170,11 @@ Rot = DAG.getNode(ISD::ROTL, DL, VT, LHSShiftArg, LHSShiftAmt); else Rot = DAG.getNode(ISD::ROTR, DL, VT, LHSShiftArg, RHSShiftAmt); - + // If there is an AND of either shifted operand, apply it to the result. if (LHSMask.getNode() || RHSMask.getNode()) { APInt Mask = APInt::getAllOnesValue(OpSizeInBits); - + if (LHSMask.getNode()) { APInt RHSBits = APInt::getLowBitsSet(OpSizeInBits, LShVal); Mask &= cast(LHSMask)->getAPIntValue() | RHSBits; @@ -2183,23 +2183,23 @@ APInt LHSBits = APInt::getHighBitsSet(OpSizeInBits, RShVal); Mask &= cast(RHSMask)->getAPIntValue() | LHSBits; } - + Rot = DAG.getNode(ISD::AND, DL, VT, Rot, DAG.getConstant(Mask, VT)); } - + return Rot.getNode(); } - + // If there is a mask here, and we have a variable shift, we can't be sure // that we're masking out the right stuff. if (LHSMask.getNode() || RHSMask.getNode()) return 0; - + // fold (or (shl x, y), (srl x, (sub 32, y))) -> (rotl x, y) // fold (or (shl x, y), (srl x, (sub 32, y))) -> (rotr x, (sub 32, y)) if (RHSShiftAmt.getOpcode() == ISD::SUB && LHSShiftAmt == RHSShiftAmt.getOperand(1)) { - if (ConstantSDNode *SUBC = + if (ConstantSDNode *SUBC = dyn_cast(RHSShiftAmt.getOperand(0))) { if (SUBC->getAPIntValue() == OpSizeInBits) { if (HasROTL) @@ -2211,12 +2211,12 @@ } } } - + // fold (or (shl x, (sub 32, y)), (srl x, r)) -> (rotr x, y) // fold (or (shl x, (sub 32, y)), (srl x, r)) -> (rotl x, (sub 32, y)) if (LHSShiftAmt.getOpcode() == ISD::SUB && RHSShiftAmt == LHSShiftAmt.getOperand(1)) { - if (ConstantSDNode *SUBC = + if (ConstantSDNode *SUBC = dyn_cast(LHSShiftAmt.getOperand(0))) { if (SUBC->getAPIntValue() == OpSizeInBits) { if (HasROTR) @@ -2256,7 +2256,7 @@ } } else if (LExtOp0.getOpcode() == ISD::SUB && RExtOp0 == LExtOp0.getOperand(1)) { - // fold (or (shl x, (*ext (sub 32, y))), (srl x, (*ext y))) -> + // fold (or (shl x, (*ext (sub 32, y))), (srl x, (*ext y))) -> // (rotr x, y) // fold (or (shl x, (*ext (sub 32, y))), (srl x, (*ext y))) -> // (rotl x, (sub 32, y)) @@ -2270,7 +2270,7 @@ } } } - + return 0; } @@ -2281,13 +2281,13 @@ ConstantSDNode *N0C = dyn_cast(N0); ConstantSDNode *N1C = dyn_cast(N1); MVT VT = N0.getValueType(); - + // fold vector ops if (VT.isVector()) { SDValue FoldedVOp = SimplifyVBinOp(N); if (FoldedVOp.getNode()) return FoldedVOp; } - + // fold (xor undef, undef) -> 0. This is a common idiom (misuse). if (N0.getOpcode() == ISD::UNDEF && N1.getOpcode() == ISD::UNDEF) return DAG.getConstant(0, VT); @@ -2335,12 +2335,12 @@ N0.getNode()->hasOneUse() && isSetCCEquivalent(N0.getOperand(0), LHS, RHS, CC)){ SDValue V = N0.getOperand(0); - V = DAG.getNode(ISD::XOR, N0.getDebugLoc(), V.getValueType(), V, + V = DAG.getNode(ISD::XOR, N0.getDebugLoc(), V.getValueType(), V, DAG.getConstant(1, V.getValueType())); AddToWorkList(V.getNode()); return DAG.getNode(ISD::ZERO_EXTEND, N->getDebugLoc(), VT, V); } - + // fold (not (or x, y)) -> (and (not x), (not y)) iff x or y are setcc if (N1C && N1C->getAPIntValue() == 1 && VT == MVT::i1 && (N0.getOpcode() == ISD::OR || N0.getOpcode() == ISD::AND)) { @@ -2354,7 +2354,7 @@ } } // fold (not (or x, y)) -> (and (not x), (not y)) iff x or y are constants - if (N1C && N1C->isAllOnesValue() && + if (N1C && N1C->isAllOnesValue() && (N0.getOpcode() == ISD::OR || N0.getOpcode() == ISD::AND)) { SDValue LHS = N0.getOperand(0), RHS = N0.getOperand(1); if (isa(RHS) || isa(LHS)) { @@ -2390,18 +2390,18 @@ &Ops[0], Ops.size()); } } - + // Simplify: xor (op x...), (op y...) -> (op (xor x, y)) if (N0.getOpcode() == N1.getOpcode()) { SDValue Tmp = SimplifyBinOpWithSameOpcodeHands(N); if (Tmp.getNode()) return Tmp; } - + // Simplify the expression using non-local knowledge. if (!VT.isVector() && SimplifyDemandedBits(SDValue(N, 0))) return SDValue(N, 0); - + return SDValue(); } @@ -2410,13 +2410,13 @@ SDValue DAGCombiner::visitShiftByConstant(SDNode *N, unsigned Amt) { SDNode *LHS = N->getOperand(0).getNode(); if (!LHS->hasOneUse()) return SDValue(); - + // We want to pull some binops through shifts, so that we have (and (shift)) // instead of (shift (and)), likewise for add, or, xor, etc. This sort of // thing happens with address calculations, so it's important to canonicalize // it. bool HighBitSet = false; // Can we transform this if the high bit is set? - + switch (LHS->getOpcode()) { default: return SDValue(); case ISD::OR: @@ -2427,12 +2427,12 @@ HighBitSet = true; // We can only transform sra if the high bit is set. break; case ISD::ADD: - if (N->getOpcode() != ISD::SHL) + if (N->getOpcode() != ISD::SHL) return SDValue(); // only shl(add) not sr[al](add). HighBitSet = false; // We can only transform sra if the high bit is clear. break; } - + // We require the RHS of the binop to be a constant as well. ConstantSDNode *BinOpCst = dyn_cast(LHS->getOperand(1)); if (!BinOpCst) return SDValue(); @@ -2443,14 +2443,14 @@ // void foo(int *X, int i) { X[i & 1235] = 1; } // int bar(int *X, int i) { return X[i & 255]; } SDNode *BinOpLHSVal = LHS->getOperand(0).getNode(); - if ((BinOpLHSVal->getOpcode() != ISD::SHL && + if ((BinOpLHSVal->getOpcode() != ISD::SHL && BinOpLHSVal->getOpcode() != ISD::SRA && BinOpLHSVal->getOpcode() != ISD::SRL) || !isa(BinOpLHSVal->getOperand(1))) return SDValue(); - + MVT VT = N->getValueType(0); - + // If this is a signed shift right, and the high bit is modified by the // logical operation, do not perform the transformation. The highBitSet // boolean indicates the value of the high bit of the constant which would @@ -2460,7 +2460,7 @@ if (BinOpRHSSignSet != HighBitSet) return SDValue(); } - + // Fold the constants, shifting the binop RHS by the shift amount. SDValue NewRHS = DAG.getNode(N->getOpcode(), LHS->getOperand(1).getDebugLoc(), N->getValueType(0), @@ -2481,7 +2481,7 @@ ConstantSDNode *N1C = dyn_cast(N1); MVT VT = N0.getValueType(); unsigned OpSizeInBits = VT.getSizeInBits(); - + // fold (shl c1, c2) -> c1< 0 or (shl x, (add c1, c2)) - if (N1C && N0.getOpcode() == ISD::SHL && + if (N1C && N0.getOpcode() == ISD::SHL && N0.getOperand(1).getOpcode() == ISD::Constant) { uint64_t c1 = cast(N0.getOperand(1))->getZExtValue(); uint64_t c2 = N1C->getZExtValue(); @@ -2532,7 +2532,7 @@ } // fold (shl (srl x, c1), c2) -> (shl (and x, (shl -1, c1)), (sub c2, c1)) or // (srl (and x, (shl -1, c1)), (sub c1, c2)) - if (N1C && N0.getOpcode() == ISD::SRL && + if (N1C && N0.getOpcode() == ISD::SRL && N0.getOperand(1).getOpcode() == ISD::Constant) { uint64_t c1 = cast(N0.getOperand(1))->getZExtValue(); uint64_t c2 = N1C->getZExtValue(); @@ -2549,7 +2549,7 @@ if (N1C && N0.getOpcode() == ISD::SRA && N1 == N0.getOperand(1)) return DAG.getNode(ISD::AND, N->getDebugLoc(), VT, N0.getOperand(0), DAG.getConstant(~0ULL << N1C->getZExtValue(), VT)); - + return N1C ? visitShiftByConstant(N, N1C->getZExtValue()) : SDValue(); } @@ -2559,7 +2559,7 @@ ConstantSDNode *N0C = dyn_cast(N0); ConstantSDNode *N1C = dyn_cast(N1); MVT VT = N0.getValueType(); - + // fold (sra c1, c2) -> (sra c1, c2) if (N0C && N1C) return DAG.FoldConstantArithmetic(ISD::SRA, VT, N0C, N1C); @@ -2597,8 +2597,8 @@ // fold (sra (shl X, m), (sub result_size, n)) // -> (sign_extend (trunc (shl X, (sub (sub result_size, n), m)))) for - // result_size - n != m. - // If truncate is free for the target sext(shl) is likely to result in better + // result_size - n != m. + // If truncate is free for the target sext(shl) is likely to result in better // code. if (N0.getOpcode() == ISD::SHL) { // Get the two constanst of the shifts, CN0 = m, CN = n. @@ -2611,8 +2611,8 @@ // Determine the residual right-shift amount. unsigned ShiftAmt = N1C->getZExtValue() - N01C->getZExtValue(); - // If the shift is not a no-op (in which case this should be just a sign - // extend already), the truncated to type is legal, sign_extend is legal + // If the shift is not a no-op (in which case this should be just a sign + // extend already), the truncated to type is legal, sign_extend is legal // on that type, and the the truncate to that type is both legal and free, // perform the transform. if (ShiftAmt && @@ -2630,7 +2630,7 @@ } } } - + // fold (sra x, (trunc (and y, c))) -> (sra x, (and (trunc y), (trunc c))). if (N1.getOpcode() == ISD::TRUNCATE && N1.getOperand(0).getOpcode() == ISD::AND && @@ -2651,11 +2651,11 @@ } } - // Simplify, based on bits shifted out of the LHS. + // Simplify, based on bits shifted out of the LHS. if (N1C && SimplifyDemandedBits(SDValue(N, 0))) return SDValue(N, 0); - - + + // If the sign bit is known to be zero, switch this to a SRL. if (DAG.SignBitIsZero(N0)) return DAG.getNode(ISD::SRL, N->getDebugLoc(), VT, N0, N1); @@ -2670,7 +2670,7 @@ ConstantSDNode *N1C = dyn_cast(N1); MVT VT = N0.getValueType(); unsigned OpSizeInBits = VT.getSizeInBits(); - + // fold (srl c1, c2) -> c1 >>u c2 if (N0C && N1C) return DAG.FoldConstantArithmetic(ISD::SRL, VT, N0C, N1C); @@ -2687,9 +2687,9 @@ if (N1C && DAG.MaskedValueIsZero(SDValue(N, 0), APInt::getAllOnesValue(OpSizeInBits))) return DAG.getConstant(0, VT); - + // fold (srl (srl x, c1), c2) -> 0 or (srl x, (add c1, c2)) - if (N1C && N0.getOpcode() == ISD::SRL && + if (N1C && N0.getOpcode() == ISD::SRL && N0.getOperand(1).getOpcode() == ISD::Constant) { uint64_t c1 = cast(N0.getOperand(1))->getZExtValue(); uint64_t c2 = N1C->getZExtValue(); @@ -2698,7 +2698,7 @@ return DAG.getNode(ISD::SRL, N->getDebugLoc(), VT, N0.getOperand(0), DAG.getConstant(c1 + c2, N1.getValueType())); } - + // fold (srl (anyextend x), c) -> (anyextend (srl x, c)) if (N1C && N0.getOpcode() == ISD::ANY_EXTEND) { // Shifting in all undef bits? @@ -2711,30 +2711,30 @@ AddToWorkList(SmallShift.getNode()); return DAG.getNode(ISD::ANY_EXTEND, N->getDebugLoc(), VT, SmallShift); } - + // fold (srl (sra X, Y), 31) -> (srl X, 31). This srl only looks at the sign // bit, which is unmodified by sra. if (N1C && N1C->getZExtValue() + 1 == VT.getSizeInBits()) { if (N0.getOpcode() == ISD::SRA) return DAG.getNode(ISD::SRL, N->getDebugLoc(), VT, N0.getOperand(0), N1); } - + // fold (srl (ctlz x), "5") -> x iff x has one bit set (the low bit). - if (N1C && N0.getOpcode() == ISD::CTLZ && + if (N1C && N0.getOpcode() == ISD::CTLZ && N1C->getAPIntValue() == Log2_32(VT.getSizeInBits())) { APInt KnownZero, KnownOne; APInt Mask = APInt::getAllOnesValue(VT.getSizeInBits()); DAG.ComputeMaskedBits(N0.getOperand(0), Mask, KnownZero, KnownOne); - + // If any of the input bits are KnownOne, then the input couldn't be all // zeros, thus the result of the srl will always be zero. if (KnownOne.getBoolValue()) return DAG.getConstant(0, VT); - + // If all of the bits input the to ctlz node are known to be zero, then // the result of the ctlz is "32" and the result of the shift is one. APInt UnknownBits = ~KnownZero & Mask; if (UnknownBits == 0) return DAG.getConstant(1, VT); - + // Otherwise, check to see if there is exactly one bit input to the ctlz. if ((UnknownBits & (UnknownBits - 1)) == 0) { // Okay, we know that only that the single bit specified by UnknownBits @@ -2774,12 +2774,12 @@ DAG.getConstant(TruncC, TruncVT))); } } - + // fold operands of srl based on knowledge that the low bits are not // demanded. if (N1C && SimplifyDemandedBits(SDValue(N, 0))) return SDValue(N, 0); - + return N1C ? visitShiftByConstant(N, N1C->getZExtValue()) : SDValue(); } @@ -2796,7 +2796,7 @@ SDValue DAGCombiner::visitCTTZ(SDNode *N) { SDValue N0 = N->getOperand(0); MVT VT = N->getValueType(0); - + // fold (cttz c1) -> c2 if (isa(N0)) return DAG.getNode(ISD::CTTZ, N->getDebugLoc(), VT, N0); @@ -2806,7 +2806,7 @@ SDValue DAGCombiner::visitCTPOP(SDNode *N) { SDValue N0 = N->getOperand(0); MVT VT = N->getValueType(0); - + // fold (ctpop c1) -> c2 if (isa(N0)) return DAG.getNode(ISD::CTPOP, N->getDebugLoc(), VT, N0); @@ -2875,7 +2875,7 @@ // fold (select X, Y, 0) -> (and X, Y) if (VT == MVT::i1 && (N0 == N2 || (N2C && N2C->getAPIntValue() == 0))) return DAG.getNode(ISD::AND, N->getDebugLoc(), VT, N0, N1); - + // If we can fold this based on the true/false value, do so. if (SimplifySelectOps(N, N1, N2)) return SDValue(N, 0); // Don't revisit N. @@ -2904,11 +2904,11 @@ SDValue N3 = N->getOperand(3); SDValue N4 = N->getOperand(4); ISD::CondCode CC = cast(N4)->get(); - + // fold select_cc lhs, rhs, x, x, cc -> x if (N2 == N3) return N2; - + // Determine if the condition we're dealing with is constant SDValue SCC = SimplifySetCC(TLI.getSetCCResultType(N0.getValueType()), N0, N1, CC, N->getDebugLoc(), false); @@ -2920,17 +2920,17 @@ else return N3; // cond always false -> false val } - + // Fold to a simpler select_cc if (SCC.getNode() && SCC.getOpcode() == ISD::SETCC) - return DAG.getNode(ISD::SELECT_CC, N->getDebugLoc(), N2.getValueType(), - SCC.getOperand(0), SCC.getOperand(1), N2, N3, + return DAG.getNode(ISD::SELECT_CC, N->getDebugLoc(), N2.getValueType(), + SCC.getOperand(0), SCC.getOperand(1), N2, N3, SCC.getOperand(2)); - + // If we can fold this based on the true/false value, do so. if (SimplifySelectOps(N, N2, N3)) return SDValue(N, 0); // Don't revisit N. - + // fold select_cc into other things, such as min/max/abs return SimplifySelectCC(N->getDebugLoc(), N0, N1, N2, N3, CC); } @@ -2944,7 +2944,7 @@ // ExtendUsesToFormExtLoad - Trying to extend uses of a load to enable this: // "fold ({s|z}ext (load x)) -> ({s|z}ext (truncate ({s|z}extload x)))" // transformation. Returns true if extension are possible and the above -// mentioned transformation is profitable. +// mentioned transformation is profitable. static bool ExtendUsesToFormExtLoad(SDNode *N, SDValue N0, unsigned ExtOpc, SmallVector &ExtendNodes, @@ -3017,13 +3017,13 @@ // fold (sext c1) -> c1 if (isa(N0)) return DAG.getNode(ISD::SIGN_EXTEND, N->getDebugLoc(), VT, N0); - + // fold (sext (sext x)) -> (sext x) // fold (sext (aext x)) -> (sext x) if (N0.getOpcode() == ISD::SIGN_EXTEND || N0.getOpcode() == ISD::ANY_EXTEND) return DAG.getNode(ISD::SIGN_EXTEND, N->getDebugLoc(), VT, N0.getOperand(0)); - + if (N0.getOpcode() == ISD::TRUNCATE) { // fold (sext (truncate (load x))) -> (sext (smaller load x)) // fold (sext (truncate (srl (load x), c))) -> (sext (smaller load (x+c/n))) @@ -3041,7 +3041,7 @@ unsigned MidBits = N0.getValueType().getSizeInBits(); unsigned DestBits = VT.getSizeInBits(); unsigned NumSignBits = DAG.ComputeNumSignBits(Op); - + if (OpBits == DestBits) { // Op is i32, Mid is i8, and Dest is i32. If Op has more than 24 sign // bits, it is already ready. @@ -3058,7 +3058,7 @@ if (NumSignBits > OpBits-MidBits) return DAG.getNode(ISD::TRUNCATE, N->getDebugLoc(), VT, Op); } - + // fold (sext (truncate x)) -> (sextinreg x). if (!LegalOperations || TLI.isOperationLegal(ISD::SIGN_EXTEND_INREG, N0.getValueType())) { @@ -3070,7 +3070,7 @@ DAG.getValueType(N0.getValueType())); } } - + // fold (sext (load x)) -> (sext (truncate (sextload x))) if (ISD::isNON_EXTLoad(N0.getNode()) && ((!LegalOperations && !cast(N0)->isVolatile()) || @@ -3137,21 +3137,21 @@ return SDValue(N, 0); // Return N so it doesn't get rechecked! } } - + // sext(setcc x, y, cc) -> (select_cc x, y, -1, 0, cc) if (N0.getOpcode() == ISD::SETCC) { - SDValue SCC = + SDValue SCC = SimplifySelectCC(N->getDebugLoc(), N0.getOperand(0), N0.getOperand(1), DAG.getConstant(~0ULL, VT), DAG.getConstant(0, VT), cast(N0.getOperand(2))->get(), true); if (SCC.getNode()) return SCC; } - + // fold (sext x) -> (zext x) if the sign bit is known zero. if ((!LegalOperations || TLI.isOperationLegal(ISD::ZERO_EXTEND, VT)) && DAG.SignBitIsZero(N0)) return DAG.getNode(ISD::ZERO_EXTEND, N->getDebugLoc(), VT, N0); - + return SDValue(); } @@ -3190,7 +3190,7 @@ } return DAG.getZeroExtendInReg(Op, N->getDebugLoc(), N0.getValueType()); } - + // fold (zext (and (trunc x), cst)) -> (and x, cst). if (N0.getOpcode() == ISD::AND && N0.getOperand(0).getOpcode() == ISD::TRUNCATE && @@ -3206,7 +3206,7 @@ return DAG.getNode(ISD::AND, N->getDebugLoc(), VT, X, DAG.getConstant(Mask, VT)); } - + // fold (zext (load x)) -> (zext (truncate (zextload x))) if (ISD::isNON_EXTLoad(N0.getNode()) && ((!LegalOperations && !cast(N0)->isVolatile()) || @@ -3273,23 +3273,23 @@ return SDValue(N, 0); // Return N so it doesn't get rechecked! } } - + // zext(setcc x,y,cc) -> select_cc x, y, 1, 0, cc if (N0.getOpcode() == ISD::SETCC) { - SDValue SCC = + SDValue SCC = SimplifySelectCC(N->getDebugLoc(), N0.getOperand(0), N0.getOperand(1), DAG.getConstant(1, VT), DAG.getConstant(0, VT), cast(N0.getOperand(2))->get(), true); if (SCC.getNode()) return SCC; } - + return SDValue(); } SDValue DAGCombiner::visitANY_EXTEND(SDNode *N) { SDValue N0 = N->getOperand(0); MVT VT = N->getValueType(0); - + // fold (aext c1) -> c1 if (isa(N0)) return DAG.getNode(ISD::ANY_EXTEND, N->getDebugLoc(), VT, N0); @@ -3300,7 +3300,7 @@ N0.getOpcode() == ISD::ZERO_EXTEND || N0.getOpcode() == ISD::SIGN_EXTEND) return DAG.getNode(N0.getOpcode(), N->getDebugLoc(), VT, N0.getOperand(0)); - + // fold (aext (truncate (load x))) -> (aext (smaller load x)) // fold (aext (truncate (srl (load x), c))) -> (aext (small load (x+c/n))) if (N0.getOpcode() == ISD::TRUNCATE) { @@ -3321,7 +3321,7 @@ return DAG.getNode(ISD::TRUNCATE, N->getDebugLoc(), VT, TruncOp); return DAG.getNode(ISD::ANY_EXTEND, N->getDebugLoc(), VT, TruncOp); } - + // fold (aext (and (trunc x), cst)) -> (and x, cst). if (N0.getOpcode() == ISD::AND && N0.getOperand(0).getOpcode() == ISD::TRUNCATE && @@ -3337,7 +3337,7 @@ return DAG.getNode(ISD::AND, N->getDebugLoc(), VT, X, DAG.getConstant(Mask, VT)); } - + // fold (aext (load x)) -> (aext (truncate (extload x))) if (ISD::isNON_EXTLoad(N0.getNode()) && N0.hasOneUse() && ((!LegalOperations && !cast(N0)->isVolatile()) || @@ -3360,7 +3360,7 @@ ExtLoad.getValue(1)); return SDValue(N, 0); // Return N so it doesn't get rechecked! } - + // fold (aext (zextload x)) -> (aext (truncate (zextload x))) // fold (aext (sextload x)) -> (aext (truncate (sextload x))) // fold (aext ( extload x)) -> (aext (truncate (extload x))) @@ -3381,17 +3381,17 @@ ExtLoad.getValue(1)); return SDValue(N, 0); // Return N so it doesn't get rechecked! } - + // aext(setcc x,y,cc) -> select_cc x, y, 1, 0, cc if (N0.getOpcode() == ISD::SETCC) { - SDValue SCC = + SDValue SCC = SimplifySelectCC(N->getDebugLoc(), N0.getOperand(0), N0.getOperand(1), DAG.getConstant(1, VT), DAG.getConstant(0, VT), cast(N0.getOperand(2))->get(), true); if (SCC.getNode()) return SCC; } - + return SDValue(); } @@ -3422,7 +3422,7 @@ APInt NewMask = Mask << Amt; SDValue SimplifyLHS = GetDemandedBits(V.getOperand(0), NewMask); if (SimplifyLHS.getNode()) - return DAG.getNode(ISD::SRL, V.getDebugLoc(), V.getValueType(), + return DAG.getNode(ISD::SRL, V.getDebugLoc(), V.getValueType(), SimplifyLHS, V.getOperand(1)); } } @@ -3519,15 +3519,15 @@ MVT EVT = cast(N1)->getVT(); unsigned VTBits = VT.getSizeInBits(); unsigned EVTBits = EVT.getSizeInBits(); - + // fold (sext_in_reg c1) -> c1 if (isa(N0) || N0.getOpcode() == ISD::UNDEF) return DAG.getNode(ISD::SIGN_EXTEND_INREG, N->getDebugLoc(), VT, N0, N1); - + // If the input is already sign extended, just drop the extension. if (DAG.ComputeNumSignBits(N0) >= VT.getSizeInBits()-EVTBits+1) return N0; - + // fold (sext_in_reg (sext_in_reg x, VT2), VT1) -> (sext_in_reg x, minVT) pt2 if (N0.getOpcode() == ISD::SIGN_EXTEND_INREG && EVT.bitsLT(cast(N0.getOperand(1))->getVT())) { @@ -3547,12 +3547,12 @@ // fold (sext_in_reg x) -> (zext_in_reg x) if the sign bit is known zero. if (DAG.MaskedValueIsZero(N0, APInt::getBitsSet(VTBits, EVTBits-1, EVTBits))) return DAG.getZeroExtendInReg(N0, N->getDebugLoc(), EVT); - + // fold operands of sext_in_reg based on knowledge that the top bits are not // demanded. if (SimplifyDemandedBits(SDValue(N, 0))) return SDValue(N, 0); - + // fold (sext_in_reg (load x)) -> (smaller sextload x) // fold (sext_in_reg (srl (load x), c)) -> (smaller sextload (x+c/evtbits)) SDValue NarrowLoad = ReduceLoadWidth(N); @@ -3575,7 +3575,7 @@ } // fold (sext_inreg (extload x)) -> (sextload x) - if (ISD::isEXTLoad(N0.getNode()) && + if (ISD::isEXTLoad(N0.getNode()) && ISD::isUNINDEXEDLoad(N0.getNode()) && EVT == cast(N0)->getMemoryVT() && ((!LegalOperations && !cast(N0)->isVolatile()) || @@ -3660,7 +3660,7 @@ } /// CombineConsecutiveLoads - build_pair (load, load) -> load -/// if load locations are consecutive. +/// if load locations are consecutive. SDValue DAGCombiner::CombineConsecutiveLoads(SDNode *N, MVT VT) { assert(N->getOpcode() == ISD::BUILD_PAIR); @@ -3709,23 +3709,23 @@ if (N0.getOperand(i).getOpcode() != ISD::UNDEF && N0.getOperand(i).getOpcode() != ISD::Constant && N0.getOperand(i).getOpcode() != ISD::ConstantFP) { - isSimple = false; + isSimple = false; break; } - + MVT DestEltVT = N->getValueType(0).getVectorElementType(); assert(!DestEltVT.isVector() && "Element type of vector ValueType must not be vector!"); if (isSimple) return ConstantFoldBIT_CONVERTofBUILD_VECTOR(N0.getNode(), DestEltVT); } - + // If the input is a constant, let getNode fold it. if (isa(N0) || isa(N0)) { SDValue Res = DAG.getNode(ISD::BIT_CONVERT, N->getDebugLoc(), VT, N0); if (Res.getNode() != N) return Res; } - + // (conv (conv x, t1), t2) -> (conv x, t2) if (N0.getOpcode() == ISD::BIT_CONVERT) return DAG.getNode(ISD::BIT_CONVERT, N->getDebugLoc(), VT, @@ -3764,7 +3764,7 @@ SDValue NewConv = DAG.getNode(ISD::BIT_CONVERT, N0.getDebugLoc(), VT, N0.getOperand(0)); AddToWorkList(NewConv.getNode()); - + APInt SignBit = APInt::getSignBit(VT.getSizeInBits()); if (N0.getOpcode() == ISD::FNEG) return DAG.getNode(ISD::XOR, N->getDebugLoc(), VT, @@ -3773,7 +3773,7 @@ return DAG.getNode(ISD::AND, N->getDebugLoc(), VT, NewConv, DAG.getConstant(~SignBit, VT)); } - + // fold (bitconvert (fcopysign cst, x)) -> // (or (and (bitconvert x), sign), (and cst, (not sign))) // Note that we don't handle (copysign x, cst) because this can always be @@ -3803,7 +3803,7 @@ X = DAG.getNode(ISD::TRUNCATE, X.getDebugLoc(), VT, X); AddToWorkList(X.getNode()); } - + APInt SignBit = APInt::getSignBit(VT.getSizeInBits()); X = DAG.getNode(ISD::AND, X.getDebugLoc(), VT, X, DAG.getConstant(SignBit, VT)); @@ -3819,13 +3819,13 @@ } } - // bitconvert(build_pair(ld, ld)) -> ld iff load locations are consecutive. + // bitconvert(build_pair(ld, ld)) -> ld iff load locations are consecutive. if (N0.getOpcode() == ISD::BUILD_PAIR) { SDValue CombineLD = CombineConsecutiveLoads(N0.getNode(), VT); if (CombineLD.getNode()) return CombineLD; } - + return SDValue(); } @@ -3835,18 +3835,18 @@ } /// ConstantFoldBIT_CONVERTofBUILD_VECTOR - We know that BV is a build_vector -/// node with Constant, ConstantFP or Undef operands. DstEltVT indicates the +/// node with Constant, ConstantFP or Undef operands. DstEltVT indicates the /// destination element value type. SDValue DAGCombiner:: ConstantFoldBIT_CONVERTofBUILD_VECTOR(SDNode *BV, MVT DstEltVT) { MVT SrcEltVT = BV->getOperand(0).getValueType(); - + // If this is already the right type, we're done. if (SrcEltVT == DstEltVT) return SDValue(BV, 0); - + unsigned SrcBitSize = SrcEltVT.getSizeInBits(); unsigned DstBitSize = DstEltVT.getSizeInBits(); - + // If this is a conversion of N elements of one type to N elements of another // type, convert each element. This handles FP<->INT cases. if (SrcBitSize == DstBitSize) { @@ -3861,7 +3861,7 @@ return DAG.getNode(ISD::BUILD_VECTOR, BV->getDebugLoc(), VT, &Ops[0], Ops.size()); } - + // Otherwise, we're growing or shrinking the elements. To avoid having to // handle annoying details of growing/shrinking FP values, we convert them to // int first. @@ -3873,24 +3873,24 @@ BV = ConstantFoldBIT_CONVERTofBUILD_VECTOR(BV, IntVT).getNode(); SrcEltVT = IntVT; } - + // Now we know the input is an integer vector. If the output is a FP type, // convert to integer first, then to FP of the right size. if (DstEltVT.isFloatingPoint()) { assert((DstEltVT == MVT::f32 || DstEltVT == MVT::f64) && "Unknown FP VT!"); MVT TmpVT = MVT::getIntegerVT(DstEltVT.getSizeInBits()); SDNode *Tmp = ConstantFoldBIT_CONVERTofBUILD_VECTOR(BV, TmpVT).getNode(); - + // Next, convert to FP elements of the same size. return ConstantFoldBIT_CONVERTofBUILD_VECTOR(Tmp, DstEltVT); } - + // Okay, we know the src/dst types are both integers of differing types. // Handling growing first. assert(SrcEltVT.isInteger() && DstEltVT.isInteger()); if (SrcBitSize < DstBitSize) { unsigned NumInputsPerOutput = DstBitSize/SrcBitSize; - + SmallVector Ops; for (unsigned i = 0, e = BV->getNumOperands(); i != e; i += NumInputsPerOutput) { @@ -3903,11 +3903,11 @@ SDValue Op = BV->getOperand(i+ (isLE ? (NumInputsPerOutput-j-1) : j)); if (Op.getOpcode() == ISD::UNDEF) continue; EltIsUndef = false; - + NewBits |= APInt(cast(Op)->getAPIntValue()).zext(DstBitSize); } - + if (EltIsUndef) Ops.push_back(DAG.getUNDEF(DstEltVT)); else @@ -3918,7 +3918,7 @@ return DAG.getNode(ISD::BUILD_VECTOR, BV->getDebugLoc(), VT, &Ops[0], Ops.size()); } - + // Finally, this must be the case where we are shrinking elements: each input // turns into multiple outputs. bool isS2V = ISD::isScalarToVector(BV); @@ -3960,13 +3960,13 @@ ConstantFPSDNode *N0CFP = dyn_cast(N0); ConstantFPSDNode *N1CFP = dyn_cast(N1); MVT VT = N->getValueType(0); - + // fold vector ops if (VT.isVector()) { SDValue FoldedVOp = SimplifyVBinOp(N); if (FoldedVOp.getNode()) return FoldedVOp; } - + // fold (fadd c1, c2) -> (fadd c1, c2) if (N0CFP && N1CFP && VT != MVT::ppcf128) return DAG.getNode(ISD::FADD, N->getDebugLoc(), VT, N0, N1); @@ -3984,14 +3984,14 @@ if (isNegatibleForFree(N0, LegalOperations) == 2) return DAG.getNode(ISD::FSUB, N->getDebugLoc(), VT, N1, GetNegatedExpression(N0, DAG, LegalOperations)); - + // If allowed, fold (fadd (fadd x, c1), c2) -> (fadd x, (fadd c1, c2)) if (UnsafeFPMath && N1CFP && N0.getOpcode() == ISD::FADD && N0.getNode()->hasOneUse() && isa(N0.getOperand(1))) return DAG.getNode(ISD::FADD, N->getDebugLoc(), VT, N0.getOperand(0), DAG.getNode(ISD::FADD, N->getDebugLoc(), VT, N0.getOperand(1), N1)); - + return SDValue(); } @@ -4001,13 +4001,13 @@ ConstantFPSDNode *N0CFP = dyn_cast(N0); ConstantFPSDNode *N1CFP = dyn_cast(N1); MVT VT = N->getValueType(0); - + // fold vector ops if (VT.isVector()) { SDValue FoldedVOp = SimplifyVBinOp(N); if (FoldedVOp.getNode()) return FoldedVOp; } - + // fold (fsub c1, c2) -> c1-c2 if (N0CFP && N1CFP && VT != MVT::ppcf128) return DAG.getNode(ISD::FSUB, N->getDebugLoc(), VT, N0, N1); @@ -4025,7 +4025,7 @@ if (isNegatibleForFree(N1, LegalOperations)) return DAG.getNode(ISD::FADD, N->getDebugLoc(), VT, N0, GetNegatedExpression(N1, DAG, LegalOperations)); - + return SDValue(); } @@ -4041,7 +4041,7 @@ SDValue FoldedVOp = SimplifyVBinOp(N); if (FoldedVOp.getNode()) return FoldedVOp; } - + // fold (fmul c1, c2) -> c1*c2 if (N0CFP && N1CFP && VT != MVT::ppcf128) return DAG.getNode(ISD::FMUL, N->getDebugLoc(), VT, N0, N1); @@ -4058,7 +4058,7 @@ if (N1CFP && N1CFP->isExactlyValue(-1.0)) if (!LegalOperations || TLI.isOperationLegal(ISD::FNEG, VT)) return DAG.getNode(ISD::FNEG, N->getDebugLoc(), VT, N0); - + // fold (fmul (fneg X), (fneg Y)) -> (fmul X, Y) if (char LHSNeg = isNegatibleForFree(N0, LegalOperations)) { if (char RHSNeg = isNegatibleForFree(N1, LegalOperations)) { @@ -4070,14 +4070,14 @@ GetNegatedExpression(N1, DAG, LegalOperations)); } } - + // If allowed, fold (fmul (fmul x, c1), c2) -> (fmul x, (fmul c1, c2)) if (UnsafeFPMath && N1CFP && N0.getOpcode() == ISD::FMUL && N0.getNode()->hasOneUse() && isa(N0.getOperand(1))) return DAG.getNode(ISD::FMUL, N->getDebugLoc(), VT, N0.getOperand(0), - DAG.getNode(ISD::FMUL, N->getDebugLoc(), VT, + DAG.getNode(ISD::FMUL, N->getDebugLoc(), VT, N0.getOperand(1), N1)); - + return SDValue(); } @@ -4093,24 +4093,24 @@ SDValue FoldedVOp = SimplifyVBinOp(N); if (FoldedVOp.getNode()) return FoldedVOp; } - + // fold (fdiv c1, c2) -> c1/c2 if (N0CFP && N1CFP && VT != MVT::ppcf128) return DAG.getNode(ISD::FDIV, N->getDebugLoc(), VT, N0, N1); - - + + // (fdiv (fneg X), (fneg Y)) -> (fdiv X, Y) if (char LHSNeg = isNegatibleForFree(N0, LegalOperations)) { if (char RHSNeg = isNegatibleForFree(N1, LegalOperations)) { // Both can be negated for free, check to see if at least one is cheaper // negated. if (LHSNeg == 2 || RHSNeg == 2) - return DAG.getNode(ISD::FDIV, N->getDebugLoc(), VT, + return DAG.getNode(ISD::FDIV, N->getDebugLoc(), VT, GetNegatedExpression(N0, DAG, LegalOperations), GetNegatedExpression(N1, DAG, LegalOperations)); } } - + return SDValue(); } @@ -4137,7 +4137,7 @@ if (N0CFP && N1CFP && VT != MVT::ppcf128) // Constant fold return DAG.getNode(ISD::FCOPYSIGN, N->getDebugLoc(), VT, N0, N1); - + if (N1CFP) { const APFloat& V = N1CFP->getValueAPF(); // copysign(x, c1) -> fabs(x) iff ispos(c1) @@ -4151,7 +4151,7 @@ DAG.getNode(ISD::FABS, N0.getDebugLoc(), VT, N0)); } } - + // copysign(fabs(x), y) -> copysign(x, y) // copysign(fneg(x), y) -> copysign(x, y) // copysign(copysign(x,z), y) -> copysign(x, y) @@ -4163,18 +4163,18 @@ // copysign(x, abs(y)) -> abs(x) if (N1.getOpcode() == ISD::FABS) return DAG.getNode(ISD::FABS, N->getDebugLoc(), VT, N0); - + // copysign(x, copysign(y,z)) -> copysign(x, z) if (N1.getOpcode() == ISD::FCOPYSIGN) return DAG.getNode(ISD::FCOPYSIGN, N->getDebugLoc(), VT, N0, N1.getOperand(1)); - + // copysign(x, fp_extend(y)) -> copysign(x, y) // copysign(x, fp_round(y)) -> copysign(x, y) if (N1.getOpcode() == ISD::FP_EXTEND || N1.getOpcode() == ISD::FP_ROUND) return DAG.getNode(ISD::FCOPYSIGN, N->getDebugLoc(), VT, N0, N1.getOperand(0)); - + return SDValue(); } @@ -4187,12 +4187,12 @@ // fold (sint_to_fp c1) -> c1fp if (N0C && OpVT != MVT::ppcf128) return DAG.getNode(ISD::SINT_TO_FP, N->getDebugLoc(), VT, N0); - + // If the input is a legal type, and SINT_TO_FP is not legal on this target, // but UINT_TO_FP is legal on this target, try to convert. if (!TLI.isOperationLegalOrCustom(ISD::SINT_TO_FP, OpVT) && TLI.isOperationLegalOrCustom(ISD::UINT_TO_FP, OpVT)) { - // If the sign bit is known to be zero, we can change this to UINT_TO_FP. + // If the sign bit is known to be zero, we can change this to UINT_TO_FP. if (DAG.SignBitIsZero(N0)) return DAG.getNode(ISD::UINT_TO_FP, N->getDebugLoc(), VT, N0); } @@ -4209,16 +4209,16 @@ // fold (uint_to_fp c1) -> c1fp if (N0C && OpVT != MVT::ppcf128) return DAG.getNode(ISD::UINT_TO_FP, N->getDebugLoc(), VT, N0); - + // If the input is a legal type, and UINT_TO_FP is not legal on this target, // but SINT_TO_FP is legal on this target, try to convert. if (!TLI.isOperationLegalOrCustom(ISD::UINT_TO_FP, OpVT) && TLI.isOperationLegalOrCustom(ISD::SINT_TO_FP, OpVT)) { - // If the sign bit is known to be zero, we can change this to SINT_TO_FP. + // If the sign bit is known to be zero, we can change this to SINT_TO_FP. if (DAG.SignBitIsZero(N0)) return DAG.getNode(ISD::SINT_TO_FP, N->getDebugLoc(), VT, N0); } - + return SDValue(); } @@ -4226,7 +4226,7 @@ SDValue N0 = N->getOperand(0); ConstantFPSDNode *N0CFP = dyn_cast(N0); MVT VT = N->getValueType(0); - + // fold (fp_to_sint c1fp) -> c1 if (N0CFP) return DAG.getNode(ISD::FP_TO_SINT, N->getDebugLoc(), VT, N0); @@ -4238,7 +4238,7 @@ SDValue N0 = N->getOperand(0); ConstantFPSDNode *N0CFP = dyn_cast(N0); MVT VT = N->getValueType(0); - + // fold (fp_to_uint c1fp) -> c1 if (N0CFP && VT != MVT::ppcf128) return DAG.getNode(ISD::FP_TO_UINT, N->getDebugLoc(), VT, N0); @@ -4251,15 +4251,15 @@ SDValue N1 = N->getOperand(1); ConstantFPSDNode *N0CFP = dyn_cast(N0); MVT VT = N->getValueType(0); - + // fold (fp_round c1fp) -> c1fp if (N0CFP && N0.getValueType() != MVT::ppcf128) return DAG.getNode(ISD::FP_ROUND, N->getDebugLoc(), VT, N0, N1); - + // fold (fp_round (fp_extend x)) -> x if (N0.getOpcode() == ISD::FP_EXTEND && VT == N0.getOperand(0).getValueType()) return N0.getOperand(0); - + // fold (fp_round (fp_round x)) -> (fp_round x) if (N0.getOpcode() == ISD::FP_ROUND) { // This is a value preserving truncation if both round's are. @@ -4268,7 +4268,7 @@ return DAG.getNode(ISD::FP_ROUND, N->getDebugLoc(), VT, N0.getOperand(0), DAG.getIntPtrConstant(IsTrunc)); } - + // fold (fp_round (copysign X, Y)) -> (copysign (fp_round X), Y) if (N0.getOpcode() == ISD::FCOPYSIGN && N0.getNode()->hasOneUse()) { SDValue Tmp = DAG.getNode(ISD::FP_ROUND, N0.getDebugLoc(), VT, @@ -4277,7 +4277,7 @@ return DAG.getNode(ISD::FCOPYSIGN, N->getDebugLoc(), VT, Tmp, N0.getOperand(1)); } - + return SDValue(); } @@ -4286,7 +4286,7 @@ MVT VT = N->getValueType(0); MVT EVT = cast(N->getOperand(1))->getVT(); ConstantFPSDNode *N0CFP = dyn_cast(N0); - + // fold (fp_round_inreg c1fp) -> c1fp if (N0CFP && (TLI.isTypeLegal(EVT) || !LegalTypes)) { SDValue Round = DAG.getConstantFP(*N0CFP->getConstantFPValue(), EVT); @@ -4300,9 +4300,9 @@ SDValue N0 = N->getOperand(0); ConstantFPSDNode *N0CFP = dyn_cast(N0); MVT VT = N->getValueType(0); - + // If this is fp_round(fpextend), don't fold it, allow ourselves to be folded. - if (N->hasOneUse() && + if (N->hasOneUse() && N->use_begin()->getOpcode() == ISD::FP_ROUND) return SDValue(); @@ -4321,7 +4321,7 @@ In, N0.getOperand(1)); return DAG.getNode(ISD::FP_EXTEND, N->getDebugLoc(), VT, In); } - + // fold (fpext (load x)) -> (fpext (fptrunc (extload x))) if (ISD::isNON_EXTLoad(N0.getNode()) && N0.hasOneUse() && ((!LegalOperations && !cast(N0)->isVolatile()) || @@ -4365,7 +4365,7 @@ N->getValueType(0), Int); } } - + return SDValue(); } @@ -4373,7 +4373,7 @@ SDValue N0 = N->getOperand(0); ConstantFPSDNode *N0CFP = dyn_cast(N0); MVT VT = N->getValueType(0); - + // fold (fabs c1) -> fabs(c1) if (N0CFP && VT != MVT::ppcf128) return DAG.getNode(ISD::FABS, N->getDebugLoc(), VT, N0); @@ -4384,7 +4384,7 @@ // fold (fabs (fcopysign x, y)) -> (fabs x) if (N0.getOpcode() == ISD::FNEG || N0.getOpcode() == ISD::FCOPYSIGN) return DAG.getNode(ISD::FABS, N->getDebugLoc(), VT, N0.getOperand(0)); - + // Transform fabs(bitconvert(x)) -> bitconvert(x&~sign) to avoid loading // constant pool values. if (N0.getOpcode() == ISD::BIT_CONVERT && N0.getNode()->hasOneUse() && @@ -4393,14 +4393,14 @@ SDValue Int = N0.getOperand(0); MVT IntVT = Int.getValueType(); if (IntVT.isInteger() && !IntVT.isVector()) { - Int = DAG.getNode(ISD::AND, N0.getDebugLoc(), IntVT, Int, + Int = DAG.getNode(ISD::AND, N0.getDebugLoc(), IntVT, Int, DAG.getConstant(~APInt::getSignBit(IntVT.getSizeInBits()), IntVT)); AddToWorkList(Int.getNode()); return DAG.getNode(ISD::BIT_CONVERT, N->getDebugLoc(), N->getValueType(0), Int); } } - + return SDValue(); } @@ -4409,7 +4409,7 @@ SDValue N1 = N->getOperand(1); SDValue N2 = N->getOperand(2); ConstantSDNode *N1C = dyn_cast(N1); - + // never taken branch, fold to chain if (N1C && N1C->isNullValue()) return Chain; @@ -4418,7 +4418,7 @@ return DAG.getNode(ISD::BR, N->getDebugLoc(), MVT::Other, Chain, N2); // fold a brcond with a setcc condition into a BR_CC node if BR_CC is legal // on the target. - if (N1.getOpcode() == ISD::SETCC && + if (N1.getOpcode() == ISD::SETCC && TLI.isOperationLegalOrCustom(ISD::BR_CC, MVT::Other)) { return DAG.getNode(ISD::BR_CC, N->getDebugLoc(), MVT::Other, Chain, N1.getOperand(2), @@ -4433,7 +4433,7 @@ SDValue DAGCombiner::visitBR_CC(SDNode *N) { CondCodeSDNode *CC = cast(N->getOperand(1)); SDValue CondLHS = N->getOperand(2), CondRHS = N->getOperand(3); - + // Use SimplifySetCC to simplify SETCC's. SDValue Simp = SimplifySetCC(TLI.getSetCCResultType(CondLHS.getValueType()), CondLHS, CondRHS, CC->get(), N->getDebugLoc(), @@ -4510,7 +4510,7 @@ if (isa(Offset) && cast(Offset)->isNullValue()) return false; - + // Try turning it into a pre-indexed load / store except when: // 1) The new base ptr is a frame index. // 2) If N is a store and the new base ptr is either the same as or is a @@ -4523,7 +4523,7 @@ // (plus the implicit offset) to a register to preinc anyway. if (isa(BasePtr)) return false; - + // Check #2. if (!isLoad) { SDValue Val = cast(N)->getValue(); @@ -4621,7 +4621,7 @@ if (Ptr.getNode()->hasOneUse()) return false; - + for (SDNode::use_iterator I = Ptr.getNode()->use_begin(), E = Ptr.getNode()->use_end(); I != E; ++I) { SDNode *Op = *I; @@ -4729,13 +4729,13 @@ int64_t FrameOffset = 0; if (FrameIndexSDNode *FI = dyn_cast(Ptr)) { FrameIdx = FI->getIndex(); - } else if (Ptr.getOpcode() == ISD::ADD && + } else if (Ptr.getOpcode() == ISD::ADD && isa(Ptr.getOperand(1)) && isa(Ptr.getOperand(0))) { FrameIdx = cast(Ptr.getOperand(0))->getIndex(); FrameOffset = Ptr.getConstantOperandVal(1); } - + if (FrameIdx != (1 << 31)) { // FIXME: Handle FI+CST. const MachineFrameInfo &MFI = *DAG.getMachineFunction().getFrameInfo(); @@ -4748,18 +4748,18 @@ // object is 16-byte aligned. unsigned StackAlign = DAG.getTarget().getFrameInfo()->getStackAlignment(); unsigned Align = MinAlign(ObjectOffset, StackAlign); - + // Finally, the frame object itself may have a known alignment. Factor // the alignment + offset into a new alignment. For example, if we know // the FI is 8 byte aligned, but the pointer is 4 off, we really have a // 4-byte alignment of the resultant pointer. Likewise align 4 + 4-byte // offset = 4-byte alignment, align 4 + 1-byte offset = align 1, etc. - unsigned FIInfoAlign = MinAlign(MFI.getObjectAlignment(FrameIdx), + unsigned FIInfoAlign = MinAlign(MFI.getObjectAlignment(FrameIdx), FrameOffset); return std::max(Align, FIInfoAlign); } } - + return 0; } @@ -4767,7 +4767,7 @@ LoadSDNode *LD = cast(N); SDValue Chain = LD->getChain(); SDValue Ptr = LD->getBasePtr(); - + // Try to infer better alignment information than the load already has. if (!Fast && LD->isUnindexed()) { if (unsigned Align = InferAlignment(Ptr, DAG)) { @@ -4826,7 +4826,7 @@ } } } - + // If this load is directly stored, replace the load value with the stored // value. // TODO: Handle store large -> read small portion. @@ -4840,11 +4840,11 @@ return CombineTo(N, Chain.getOperand(1), Chain); } } - + if (CombinerAA) { // Walk up chain skipping non-aliasing memory nodes. SDValue BetterChain = FindBetterChain(N, Chain); - + // If there is a better chain. if (Chain != BetterChain) { SDValue ReplLoad; @@ -4861,14 +4861,14 @@ BetterChain, Ptr, LD->getSrcValue(), LD->getSrcValueOffset(), LD->getMemoryVT(), - LD->isVolatile(), + LD->isVolatile(), LD->getAlignment()); } // Create token factor to keep old chain connected. SDValue Token = DAG.getNode(ISD::TokenFactor, N->getDebugLoc(), MVT::Other, Chain, ReplLoad.getValue(1)); - + // Replace uses with load result and token factor. Don't add users // to work list. return CombineTo(N, ReplLoad.getValue(0), Token, false); @@ -4887,7 +4887,7 @@ SDValue Chain = ST->getChain(); SDValue Value = ST->getValue(); SDValue Ptr = ST->getBasePtr(); - + // Try to infer better alignment information than the store already has. if (!Fast && ST->isUnindexed()) { if (unsigned Align = InferAlignment(Ptr, DAG)) { @@ -4985,10 +4985,10 @@ } } - if (CombinerAA) { + if (CombinerAA) { // Walk up chain skipping non-aliasing memory nodes. SDValue BetterChain = FindBetterChain(N, Chain); - + // If there is a better chain. if (Chain != BetterChain) { // Replace the chain to avoid dependency. @@ -5003,7 +5003,7 @@ ST->getSrcValue(), ST->getSrcValueOffset(), ST->isVolatile(), ST->getAlignment()); } - + // Create token to keep both nodes around. SDValue Token = DAG.getNode(ISD::TokenFactor, N->getDebugLoc(), MVT::Other, Chain, ReplStore); @@ -5012,7 +5012,7 @@ return CombineTo(N, Token, false); } } - + // Try transforming N to an indexed store. if (CombineToPreIndexedLoadStore(N) || CombineToPostIndexedLoadStore(N)) return SDValue(N, 0); @@ -5023,7 +5023,7 @@ // See if we can simplify the input to this truncstore with knowledge that // only the low bits are being used. For example: // "truncstore (or (shl x, 8), y), i8" -> "truncstore y, i8" - SDValue Shorter = + SDValue Shorter = GetDemandedBits(Value, APInt::getLowBitsSet(Value.getValueSizeInBits(), ST->getMemoryVT().getSizeInBits())); @@ -5033,7 +5033,7 @@ Ptr, ST->getSrcValue(), ST->getSrcValueOffset(), ST->getMemoryVT(), ST->isVolatile(), ST->getAlignment()); - + // Otherwise, see if we can simplify the operation with // SimplifyDemandedBits, which only works if the value has a single use. if (SimplifyDemandedBits(Value, @@ -5042,7 +5042,7 @@ ST->getMemoryVT().getSizeInBits()))) return SDValue(N, 0); } - + // If this is a load followed by a store to the same location, then the store // is dead/noop. if (LoadSDNode *Ld = dyn_cast(Value)) { @@ -5075,7 +5075,7 @@ SDValue InVec = N->getOperand(0); SDValue InVal = N->getOperand(1); SDValue EltNo = N->getOperand(2); - + // If the invec is a BUILD_VECTOR and if EltNo is a constant, build a new // vector with the inserted element. if (InVec.getOpcode() == ISD::BUILD_VECTOR && isa(EltNo)) { @@ -5087,7 +5087,7 @@ return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), InVec.getValueType(), &Ops[0], Ops.size()); } - + return SDValue(); } @@ -5137,7 +5137,7 @@ // (vextract (vector_shuffle (load $addr), v2, <1, u, u, u>), 1) // => // (load $addr+1*size) - + // If the bit convert changed the number of elements, it is unsafe // to examine the mask. if (BCNumEltsChanged) @@ -5201,7 +5201,7 @@ for (unsigned i = 0; i != NumInScalars; ++i) { // Ignore undef inputs. if (N->getOperand(i).getOpcode() == ISD::UNDEF) continue; - + // If this input is something other than a EXTRACT_VECTOR_ELT with a // constant index, bail out. if (N->getOperand(i).getOpcode() != ISD::EXTRACT_VECTOR_ELT || @@ -5209,7 +5209,7 @@ VecIn1 = VecIn2 = SDValue(0, 0); break; } - + // If the input vector type disagrees with the result of the build_vector, // we can't make a shuffle. SDValue ExtractedFromVec = N->getOperand(i).getOperand(0); @@ -5217,11 +5217,11 @@ VecIn1 = VecIn2 = SDValue(0, 0); break; } - + // Otherwise, remember this. We allow up to two distinct input vectors. if (ExtractedFromVec == VecIn1 || ExtractedFromVec == VecIn2) continue; - + if (VecIn1.getNode() == 0) { VecIn1 = ExtractedFromVec; } else if (VecIn2.getNode() == 0) { @@ -5232,7 +5232,7 @@ break; } } - + // If everything is good, we can make a shuffle operation. if (VecIn1.getNode()) { SmallVector BuildVecIndices; @@ -5241,9 +5241,9 @@ BuildVecIndices.push_back(DAG.getUNDEF(TLI.getPointerTy())); continue; } - + SDValue Extract = N->getOperand(i); - + // If extracting from the first vector, just use the index directly. if (Extract.getOperand(0) == VecIn1) { BuildVecIndices.push_back(Extract.getOperand(1)); @@ -5255,7 +5255,7 @@ cast(Extract.getOperand(1))->getZExtValue(); BuildVecIndices.push_back(DAG.getIntPtrConstant(Idx+NumInScalars)); } - + // Add count and size info. MVT BuildVecVT = MVT::getVectorVT(TLI.getPointerTy(), NumElts); if (!TLI.isTypeLegal(BuildVecVT) && LegalTypes) @@ -5279,7 +5279,7 @@ &BuildVecIndices[0], BuildVecIndices.size()); return DAG.getNode(ISD::VECTOR_SHUFFLE, N->getDebugLoc(), VT, Ops, 3); } - + return SDValue(); } @@ -5411,7 +5411,7 @@ NumElts) { MappedOps.push_back(ShufMask.getOperand(i)); } else { - unsigned NewIdx = + unsigned NewIdx = cast(ShufMask.getOperand(i))->getZExtValue() - NumElts; MappedOps.push_back(DAG.getConstant(NewIdx, @@ -5428,7 +5428,7 @@ DAG.getUNDEF(N->getValueType(0)), ShufMask); } - + return SDValue(); } @@ -5507,7 +5507,7 @@ // If the LHS and RHS are BUILD_VECTOR nodes, see if we can constant fold // this operation. - if (LHS.getOpcode() == ISD::BUILD_VECTOR && + if (LHS.getOpcode() == ISD::BUILD_VECTOR && RHS.getOpcode() == ISD::BUILD_VECTOR) { SmallVector Ops; for (unsigned i = 0, e = LHS.getNumOperands(); i != e; ++i) { @@ -5540,21 +5540,21 @@ Ops.back().getOpcode() == ISD::ConstantFP) && "Scalar binop didn't fold!"); } - + if (Ops.size() == LHS.getNumOperands()) { MVT VT = LHS.getValueType(); return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), VT, &Ops[0], Ops.size()); } } - + return SDValue(); } SDValue DAGCombiner::SimplifySelect(DebugLoc DL, SDValue N0, SDValue N1, SDValue N2){ assert(N0.getOpcode() ==ISD::SETCC && "First argument must be a SetCC node!"); - + SDValue SCC = SimplifySelectCC(DL, N0.getOperand(0), N0.getOperand(1), N1, N2, cast(N0.getOperand(2))->get()); @@ -5567,7 +5567,7 @@ if (SCC.getOpcode() == ISD::SELECT_CC) { SDValue SETCC = DAG.getNode(ISD::SETCC, N0.getDebugLoc(), N0.getValueType(), - SCC.getOperand(0), SCC.getOperand(1), + SCC.getOperand(0), SCC.getOperand(1), SCC.getOperand(4)); AddToWorkList(SETCC.getNode()); return DAG.getNode(ISD::SELECT, SCC.getDebugLoc(), SCC.getValueType(), @@ -5585,9 +5585,9 @@ /// returns true. As such, they should return the appropriate thing (e.g. the /// node) back to the top-level of the DAG combiner loop to avoid it being /// looked at. -bool DAGCombiner::SimplifySelectOps(SDNode *TheSelect, SDValue LHS, +bool DAGCombiner::SimplifySelectOps(SDNode *TheSelect, SDValue LHS, SDValue RHS) { - + // If this is a select from two identical things, try to pull the operation // through the select. if (LHS.getOpcode() == RHS.getOpcode() && LHS.hasOneUse() && RHS.hasOneUse()){ @@ -5630,21 +5630,21 @@ Addr = DAG.getNode(ISD::SELECT_CC, TheSelect->getDebugLoc(), LLD->getBasePtr().getValueType(), TheSelect->getOperand(0), - TheSelect->getOperand(1), + TheSelect->getOperand(1), LLD->getBasePtr(), RLD->getBasePtr(), TheSelect->getOperand(4)); } } - + if (Addr.getNode()) { SDValue Load; if (LLD->getExtensionType() == ISD::NON_EXTLOAD) { Load = DAG.getLoad(TheSelect->getValueType(0), TheSelect->getDebugLoc(), LLD->getChain(), - Addr,LLD->getSrcValue(), + Addr,LLD->getSrcValue(), LLD->getSrcValueOffset(), - LLD->isVolatile(), + LLD->isVolatile(), LLD->getAlignment()); } else { Load = DAG.getExtLoad(LLD->getExtensionType(), @@ -5653,13 +5653,13 @@ LLD->getChain(), Addr, LLD->getSrcValue(), LLD->getSrcValueOffset(), LLD->getMemoryVT(), - LLD->isVolatile(), + LLD->isVolatile(), LLD->getAlignment()); } // Users of the select now use the result of the load. CombineTo(TheSelect, Load); - + // Users of the old loads now use the new load's chain. We know the // old-load value is dead now. CombineTo(LHS.getNode(), Load.getValue(0), Load.getValue(1)); @@ -5669,11 +5669,11 @@ } } } - + return false; } -SDValue DAGCombiner::SimplifySelectCC(DebugLoc DL, SDValue N0, SDValue N1, +SDValue DAGCombiner::SimplifySelectCC(DebugLoc DL, SDValue N0, SDValue N1, SDValue N2, SDValue N3, ISD::CondCode CC, bool NotExtCompare) { MVT VT = N2.getValueType(); @@ -5693,7 +5693,7 @@ // fold select_cc false, x, y -> y if (SCCC && SCCC->isNullValue()) return N3; - + // Check to see if we can simplify the select into an fabs node if (ConstantFPSDNode *CFP = dyn_cast(N1)) { // Allow either -0.0 or 0.0 @@ -5703,7 +5703,7 @@ N0 == N2 && N3.getOpcode() == ISD::FNEG && N2 == N3.getOperand(0)) return DAG.getNode(ISD::FABS, DL, VT, N0); - + // select (setl[te] X, +/-0.0), fneg(X), X -> fabs if ((CC == ISD::SETLT || CC == ISD::SETLE) && N0 == N3 && N2.getOpcode() == ISD::FNEG && @@ -5711,7 +5711,7 @@ return DAG.getNode(ISD::FABS, DL, VT, N3); } } - + // Check to see if we can perform the "gzip trick", transforming // (select_cc setlt X, 0, A, 0) -> (and (sra X, (sub size(X), 1), A) if (N1C && N3C && N3C->isNullValue() && CC == ISD::SETLT && @@ -5754,16 +5754,16 @@ return DAG.getNode(ISD::AND, DL, AType, Shift, N2); } } - + // fold select C, 16, 0 -> shl C, 4 if (N2C && N3C && N3C->isNullValue() && N2C->getAPIntValue().isPowerOf2() && TLI.getBooleanContents() == TargetLowering::ZeroOrOneBooleanContent) { - + // If the caller doesn't want us to simplify this into a zext of a compare, // don't do it. if (NotExtCompare && N2C->getAPIntValue() == 1) return SDValue(); - + // Get a SetCC of the condition // FIXME: Should probably make sure that setcc is legal if we ever have a // target where it isn't. @@ -5785,7 +5785,7 @@ AddToWorkList(SCC.getNode()); AddToWorkList(Temp.getNode()); - + if (N2C->getAPIntValue() == 1) return Temp; @@ -5794,7 +5794,7 @@ DAG.getConstant(N2C->getAPIntValue().logBase2(), getShiftAmountTy())); } - + // Check to see if this is the equivalent of setcc // FIXME: Turn all of these into setcc if setcc if setcc is legal // otherwise, go ahead with the folds. @@ -5807,18 +5807,18 @@ Res = DAG.getNode(ISD::ZERO_EXTEND, DL, VT, Res); return Res; } - + // fold (seteq X, 0) -> (srl (ctlz X, log2(size(X)))) - if (N1C && N1C->isNullValue() && CC == ISD::SETEQ && + if (N1C && N1C->isNullValue() && CC == ISD::SETEQ && (!LegalOperations || TLI.isOperationLegal(ISD::CTLZ, XType))) { SDValue Ctlz = DAG.getNode(ISD::CTLZ, N0.getDebugLoc(), XType, N0); - return DAG.getNode(ISD::SRL, DL, XType, Ctlz, + return DAG.getNode(ISD::SRL, DL, XType, Ctlz, DAG.getConstant(Log2_32(XType.getSizeInBits()), getShiftAmountTy())); } // fold (setgt X, 0) -> (srl (and (-X, ~X), size(X)-1)) - if (N1C && N1C->isNullValue() && CC == ISD::SETGT) { + if (N1C && N1C->isNullValue() && CC == ISD::SETGT) { SDValue NegN0 = DAG.getNode(ISD::SUB, N0.getDebugLoc(), XType, DAG.getConstant(0, XType), N0); SDValue NotN0 = DAG.getNOT(N0.getDebugLoc(), N0, XType); @@ -5835,7 +5835,7 @@ return DAG.getNode(ISD::XOR, DL, XType, Sign, DAG.getConstant(1, XType)); } } - + // Check to see if this is an integer abs. select_cc setl[te] X, 0, -X, X -> // Y = sra (X, size(X)-1); xor (add (X, Y), Y) if (N1C && N1C->isNullValue() && (CC == ISD::SETLT || CC == ISD::SETLE) && @@ -5870,7 +5870,7 @@ } } } - + return SDValue(); } @@ -5878,7 +5878,7 @@ SDValue DAGCombiner::SimplifySetCC(MVT VT, SDValue N0, SDValue N1, ISD::CondCode Cond, DebugLoc DL, bool foldBooleans) { - TargetLowering::DAGCombinerInfo + TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, Level == Unrestricted, false, this); return TLI.SimplifySetCC(VT, N0, N1, Cond, foldBooleans, DagCombineInfo, DL); } @@ -5916,7 +5916,7 @@ static bool FindBaseOffset(SDValue Ptr, SDValue &Base, int64_t &Offset) { // Assume it is a primitive operation. Base = Ptr; Offset = 0; - + // If it's an adding a simple constant then integrate the offset. if (Base.getOpcode() == ISD::ADD) { if (ConstantSDNode *C = dyn_cast(Base.getOperand(1))) { @@ -5924,7 +5924,7 @@ Offset += C->getZExtValue(); } } - + // If it's any of the following then it can't alias with anything but itself. return isa(Base) || isa(Base) || @@ -5939,18 +5939,18 @@ const Value *SrcValue2, int SrcValueOffset2) const { // If they are the same then they must be aliases. if (Ptr1 == Ptr2) return true; - + // Gather base node and offset information. SDValue Base1, Base2; int64_t Offset1, Offset2; bool KnownBase1 = FindBaseOffset(Ptr1, Base1, Offset1); bool KnownBase2 = FindBaseOffset(Ptr2, Base2, Offset2); - + // If they have a same base address then... if (Base1 == Base2) // Check to see if the addresses overlap. return !((Offset1 + Size1) <= Offset2 || (Offset2 + Size2) <= Offset1); - + // If we know both bases then they can't alias. if (KnownBase1 && KnownBase2) return false; @@ -5959,7 +5959,7 @@ int64_t MinOffset = std::min(SrcValueOffset1, SrcValueOffset2); int64_t Overlap1 = Size1 + SrcValueOffset1 - MinOffset; int64_t Overlap2 = Size2 + SrcValueOffset2 - MinOffset; - AliasAnalysis::AliasResult AAResult = + AliasAnalysis::AliasResult AAResult = AA.alias(SrcValue1, Overlap1, SrcValue2, Overlap2); if (AAResult == AliasAnalysis::NoAlias) return false; @@ -5988,7 +5988,7 @@ } else { assert(0 && "FindAliasInfo expected a memory operand"); } - + return false; } @@ -5998,7 +5998,7 @@ SmallVector &Aliases) { SmallVector Chains; // List of chains to visit. std::set Visited; // Visited node set. - + // Get alias information for node. SDValue Ptr; int64_t Size; @@ -6008,23 +6008,23 @@ // Starting off. Chains.push_back(OriginalChain); - + // Look at each chain and determine if it is an alias. If so, add it to the // aliases list. If not, then continue up the chain looking for the next - // candidate. + // candidate. while (!Chains.empty()) { SDValue Chain = Chains.back(); Chains.pop_back(); - + // Don't bother if we've been before. if (Visited.find(Chain.getNode()) != Visited.end()) continue; Visited.insert(Chain.getNode()); - + switch (Chain.getOpcode()) { case ISD::EntryToken: // Entry token is ideal chain operand, but handled in FindBetterChain. break; - + case ISD::LOAD: case ISD::STORE: { // Get alias information for Chain. @@ -6034,7 +6034,7 @@ int OpSrcValueOffset; bool IsOpLoad = FindAliasInfo(Chain.getNode(), OpPtr, OpSize, OpSrcValue, OpSrcValueOffset); - + // If chain is alias then stop here. if (!(IsLoad && IsOpLoad) && isAlias(Ptr, Size, SrcValue, SrcValueOffset, @@ -6042,13 +6042,13 @@ Aliases.push_back(Chain); } else { // Look further up the chain. - Chains.push_back(Chain.getOperand(0)); + Chains.push_back(Chain.getOperand(0)); // Clean up old chain. AddToWorkList(Chain.getNode()); } break; } - + case ISD::TokenFactor: // We have to check each of the operands of the token factor, so we queue // then up. Adding the operands to the queue (stack) in reverse order @@ -6059,7 +6059,7 @@ // Eliminate the token factor if we can. AddToWorkList(Chain.getNode()); break; - + default: // For all other instructions we will just have to take what we can get. Aliases.push_back(Chain); @@ -6072,10 +6072,10 @@ /// for a better chain (aliasing node.) SDValue DAGCombiner::FindBetterChain(SDNode *N, SDValue OldChain) { SmallVector Aliases; // Ops for replacing token factor. - + // Accumulate all the aliases to this node. GatherAllAliases(N, OldChain, Aliases); - + if (Aliases.size() == 0) { // If no operands then chain to entry token. return DAG.getEntryNode(); @@ -6090,7 +6090,7 @@ // Make sure the old chain gets cleaned up. if (NewChain != OldChain) AddToWorkList(OldChain.getNode()); - + return NewChain; } Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=64827&r1=64826&r2=64827&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (original) +++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Tue Feb 17 16:15:04 2009 @@ -58,17 +58,17 @@ bool TypesNeedLegalizing; // Libcall insertion helpers. - + /// LastCALLSEQ_END - This keeps track of the CALLSEQ_END node that has been /// legalized. We use this to ensure that calls are properly serialized /// against each other, including inserted libcalls. SDValue LastCALLSEQ_END; - + /// IsLegalizingCall - This member is used *only* for purposes of providing - /// helpful assertions that a libcall isn't created while another call is + /// helpful assertions that a libcall isn't created while another call is /// being legalized (which could lead to non-serialized call sequences). bool IsLegalizingCall; - + /// IsLegalizingCallArguments - This member is used only for the purpose /// of providing assert to check for LegalizeTypes because legalizing an /// operation might introduce call nodes that might need type legalization. @@ -79,7 +79,7 @@ Promote, // This operation should be executed in a larger type. Expand // Try to expand this to other ops, otherwise use a libcall. }; - + /// ValueTypeActions - This is a bitvector that contains two bits for each /// value type, where the two bits correspond to the LegalizeAction enum. /// This can be queried with "getTypeAction(VT)". @@ -104,12 +104,12 @@ /// which operands are the split version of the input. This allows us /// to avoid splitting the same node more than once. std::map > SplitNodes; - + /// ScalarizedNodes - For nodes that need to be converted from vector types to /// scalar types, this contains the mapping of ones we have already /// processed to the result. std::map ScalarizedNodes; - + /// WidenNodes - For nodes that need to be widened from one vector type to /// another, this contains the mapping of those that we have already widen. /// This allows us to avoid widening more than once. @@ -158,18 +158,18 @@ /// HandleOp - Legalize, Promote, or Expand the specified operand as /// appropriate for its type. void HandleOp(SDValue Op); - + /// LegalizeOp - We know that the specified value has a legal type. /// Recursively ensure that the operands have legal types, then return the /// result. SDValue LegalizeOp(SDValue O); - + /// UnrollVectorOp - We know that the given vector has a legal type, however /// the operation it performs is not legal and is an operation that we have /// no way of lowering. "Unroll" the vector, splitting out the scalars and /// operating on each element individually. SDValue UnrollVectorOp(SDValue O); - + /// PerformInsertVectorEltInMemory - Some target cannot handle a variable /// insertion index for the INSERT_VECTOR_ELT instruction. In this case, it /// is necessary to spill the vector being inserted into to memory, perform @@ -192,7 +192,7 @@ /// types. void ExpandOp(SDValue O, SDValue &Lo, SDValue &Hi); - /// WidenVectorOp - Widen a vector operation to a wider type given by WidenVT + /// WidenVectorOp - Widen a vector operation to a wider type given by WidenVT /// (e.g., v3i32 to v4i32). The produced value will have the correct value /// for the existing elements but no guarantee is made about the new elements /// at the end of the vector: it may be zero, ones, or garbage. This is useful @@ -203,15 +203,15 @@ /// SplitVectorOp - Given an operand of vector type, break it down into /// two smaller values. void SplitVectorOp(SDValue O, SDValue &Lo, SDValue &Hi); - + /// ScalarizeVectorOp - Given an operand of single-element vector type /// (e.g. v1f32), convert it into the equivalent operation that returns a /// scalar (e.g. f32) value. SDValue ScalarizeVectorOp(SDValue O); - + /// Useful 16 element vector type that is used to pass operands for widening. - typedef SmallVector SDValueVector; - + typedef SmallVector SDValueVector; + /// LoadWidenVectorOp - Load a vector for a wider type. Returns true if /// the LdChain contains a single load and false if it contains a token /// factor for multiple loads. It takes @@ -219,9 +219,9 @@ /// LdChain: location to return the load chain /// Op: load operation to widen /// NVT: widen vector result type we want for the load - bool LoadWidenVectorOp(SDValue& Result, SDValue& LdChain, + bool LoadWidenVectorOp(SDValue& Result, SDValue& LdChain, SDValue Op, MVT NVT); - + /// Helper genWidenVectorLoads - Helper function to generate a set of /// loads to load a vector with a resulting wider type. It takes /// LdChain: list of chains for the load we have generated @@ -231,22 +231,22 @@ /// SVOffset: memory disambiugation offset /// Alignment: alignment of the memory /// isVolatile: volatile load - /// LdWidth: width of memory that we want to load + /// LdWidth: width of memory that we want to load /// ResType: the wider result result type for the resulting loaded vector SDValue genWidenVectorLoads(SDValueVector& LdChain, SDValue Chain, SDValue BasePtr, const Value *SV, int SVOffset, unsigned Alignment, bool isVolatile, unsigned LdWidth, MVT ResType, DebugLoc dl); - + /// StoreWidenVectorOp - Stores a widen vector into non widen memory /// location. It takes /// ST: store node that we want to replace /// Chain: incoming store chain /// BasePtr: base address of where we want to store into - SDValue StoreWidenVectorOp(StoreSDNode *ST, SDValue Chain, + SDValue StoreWidenVectorOp(StoreSDNode *ST, SDValue Chain, SDValue BasePtr); - + /// Helper genWidenVectorStores - Helper function to generate a set of /// stores to store a widen vector into non widen memory // It takes @@ -257,14 +257,14 @@ // SVOffset: memory disambiugation offset // Alignment: alignment of the memory // isVolatile: volatile lod - // ValOp: value to store - // StWidth: width of memory that we want to store + // ValOp: value to store + // StWidth: width of memory that we want to store void genWidenVectorStores(SDValueVector& StChain, SDValue Chain, SDValue BasePtr, const Value *SV, int SVOffset, unsigned Alignment, bool isVolatile, SDValue ValOp, unsigned StWidth, DebugLoc dl); - + /// isShuffleLegal - Return non-null if a vector shuffle is legal with the /// specified mask and type. Targets can specify exactly which masks they /// support and the code generator is tasked with not creating illegal masks. @@ -275,7 +275,7 @@ /// If this is a legal shuffle, this method returns the (possibly promoted) /// build_vector Mask. If it's not a legal shuffle, it returns null. SDNode *isShuffleLegal(MVT VT, SDValue Mask) const; - + bool LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, SmallPtrSet &NodesLeadingTo); @@ -288,7 +288,7 @@ LegalizeSetCCOperands(LHS, RHS, CC, dl); LegalizeSetCCCondCode(VT, LHS, RHS, CC, dl); } - + SDValue ExpandLibCall(RTLIB::Libcall LC, SDNode *Node, bool isSigned, SDValue &Hi); SDValue ExpandIntToFP(bool isSigned, MVT DestTy, SDValue Source, DebugLoc dl); @@ -296,7 +296,7 @@ SDValue EmitStackConvert(SDValue SrcOp, MVT SlotVT, MVT DestVT, DebugLoc dl); SDValue ExpandBUILD_VECTOR(SDNode *Node); SDValue ExpandSCALAR_TO_VECTOR(SDNode *Node); - SDValue LegalizeINT_TO_FP(SDValue Result, bool isSigned, MVT DestTy, + SDValue LegalizeINT_TO_FP(SDValue Result, bool isSigned, MVT DestTy, SDValue Op, DebugLoc dl); SDValue ExpandLegalINT_TO_FP(bool isSigned, SDValue LegalOp, MVT DestVT, DebugLoc dl); @@ -410,7 +410,7 @@ return Node; if (Node->use_empty()) return 0; // No CallSeqEnd - + // The chain is usually at the end. SDValue TheChain(Node, Node->getNumValues()-1); if (TheChain.getValueType() != MVT::Other) { @@ -423,16 +423,16 @@ TheChain = SDValue(Node, i); break; } - - // Otherwise, we walked into a node without a chain. + + // Otherwise, we walked into a node without a chain. if (TheChain.getValueType() != MVT::Other) return 0; } } - + for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end(); UI != E; ++UI) { - + // Make sure to only follow users of our token chain. SDNode *User = *UI; for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) @@ -443,19 +443,19 @@ return 0; } -/// FindCallStartFromCallEnd - Given a chained node that is part of a call +/// FindCallStartFromCallEnd - Given a chained node that is part of a call /// sequence, find the CALLSEQ_START node that initiates the call sequence. static SDNode *FindCallStartFromCallEnd(SDNode *Node) { assert(Node && "Didn't find callseq_start for a call??"); if (Node->getOpcode() == ISD::CALLSEQ_START) return Node; - + assert(Node->getOperand(0).getValueType() == MVT::Other && "Node doesn't have a token chain argument!"); return FindCallStartFromCallEnd(Node->getOperand(0).getNode()); } /// LegalizeAllNodesNotLeadingTo - Recursively walk the uses of N, looking to -/// see if any uses can reach Dest. If no dest operands can get to dest, +/// see if any uses can reach Dest. If no dest operands can get to dest, /// legalize them, legalize ourself, and return false, otherwise, return true. /// /// Keep track of the nodes we fine that actually do lead to Dest in @@ -464,15 +464,15 @@ bool SelectionDAGLegalize::LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, SmallPtrSet &NodesLeadingTo) { if (N == Dest) return true; // N certainly leads to Dest :) - + // If we've already processed this node and it does lead to Dest, there is no // need to reprocess it. if (NodesLeadingTo.count(N)) return true; - + // If the first result of this node has been already legalized, then it cannot // reach N. switch (getTypeAction(N->getValueType(0))) { - case Legal: + case Legal: if (LegalizedNodes.count(SDValue(N, 0))) return false; break; case Promote: @@ -482,7 +482,7 @@ if (ExpandedNodes.count(SDValue(N, 0))) return false; break; } - + // Okay, this node has not already been legalized. Check and legalize all // operands. If none lead to Dest, then we can legalize this node. bool OperandsLeadToDest = false; @@ -619,7 +619,7 @@ ? DAG.getConstantFP(BitsToDouble(1ULL << 63), SrcVT) : DAG.getConstantFP(BitsToFloat(1U << 31), SrcVT); Mask1 = DAG.getNode(ISD::BIT_CONVERT, dl, SrcNVT, Mask1); - SDValue SignBit= DAG.getNode(ISD::BIT_CONVERT, dl, SrcNVT, + SDValue SignBit= DAG.getNode(ISD::BIT_CONVERT, dl, SrcNVT, Node->getOperand(1)); SignBit = DAG.getNode(ISD::AND, dl, SrcNVT, SignBit, Mask1); // Shift right or sign-extend it if the two operands have different types. @@ -682,7 +682,7 @@ SDValue StackPtr = DAG.CreateStackTemporary(StoredVT, RegVT); // Perform the original store, only redirected to the stack slot. - SDValue Store = DAG.getTruncStore(Chain, dl, + SDValue Store = DAG.getTruncStore(Chain, dl, Val, StackPtr, NULL, 0,StoredVT); SDValue Increment = DAG.getConstant(RegBytes, TLI.getPointerTy()); SmallVector Stores; @@ -841,7 +841,7 @@ MVT NewLoadedVT; NewLoadedVT = MVT::getIntegerVT(NumBits/2); NumBits >>= 1; - + unsigned Alignment = LD->getAlignment(); unsigned IncrementSize = NumBits / 8; ISD::LoadExtType HiExtType = LD->getExtensionType(); @@ -958,7 +958,7 @@ SDValue Tmp1 = Vec; SDValue Tmp2 = Val; SDValue Tmp3 = Idx; - + // If the target doesn't support this, we have to spill the input vector // to a temporary stack slot, update the element, then reload it. This is // badness. We could also load the value into a vector register (either @@ -1000,7 +1000,7 @@ SDValue SelectionDAGLegalize::LegalizeOp(SDValue Op) { if (Op.getOpcode() == ISD::TargetConstant) // Allow illegal target nodes. return Op; - + assert(isTypeLegal(Op.getValueType()) && "Caller should expand or promote operands that are not legal!"); SDNode *Node = Op.getNode(); @@ -1026,7 +1026,7 @@ SDValue Tmp1, Tmp2, Tmp3, Tmp4; SDValue Result = Op; bool isCustom = false; - + switch (Node->getOpcode()) { case ISD::FrameIndex: case ISD::EntryToken: @@ -1090,7 +1090,7 @@ // The only option for these nodes is to custom lower them. If the target // does not custom lower them, then return zero. Tmp1 = TLI.LowerOperation(Op, DAG); - if (Tmp1.getNode()) + if (Tmp1.getNode()) Result = Tmp1; else Result = DAG.getConstant(0, TLI.getPointerTy()); @@ -1239,7 +1239,7 @@ } break; } - + case ISD::INTRINSIC_W_CHAIN: case ISD::INTRINSIC_WO_CHAIN: case ISD::INTRINSIC_VOID: { @@ -1247,9 +1247,9 @@ for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) Ops.push_back(LegalizeOp(Node->getOperand(i))); Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); - + // Allow the target to custom lower its intrinsics if it wants to. - if (TLI.getOperationAction(Node->getOpcode(), MVT::Other) == + if (TLI.getOperationAction(Node->getOpcode(), MVT::Other) == TargetLowering::Custom) { Tmp3 = TLI.LowerOperation(Result, DAG); if (Tmp3.getNode()) Result = Tmp3; @@ -1261,17 +1261,17 @@ assert(Result.getNode()->getNumValues() == 2 && "Cannot return more than two values!"); - // Since loads produce two values, make sure to remember that we + // Since loads produce two values, make sure to remember that we // legalized both of them. AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); return Result.getValue(Op.getResNo()); - } + } case ISD::DBG_STOPPOINT: assert(Node->getNumOperands() == 1 && "Invalid DBG_STOPPOINT node!"); Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input chain. - + switch (TLI.getOperationAction(ISD::DBG_STOPPOINT, MVT::Other)) { case TargetLowering::Promote: default: assert(0 && "This action is not supported yet!"); @@ -1280,14 +1280,14 @@ bool useDEBUG_LOC = TLI.isOperationLegalOrCustom(ISD::DEBUG_LOC, MVT::Other); bool useLABEL = TLI.isOperationLegalOrCustom(ISD::DBG_LABEL, MVT::Other); - + const DbgStopPointSDNode *DSP = cast(Node); GlobalVariable *CU_GV = cast(DSP->getCompileUnit()); if (DW && (useDEBUG_LOC || useLABEL) && !CU_GV->isDeclaration()) { DICompileUnit CU(cast(DSP->getCompileUnit())); unsigned SrcFile = DW->RecordSource(CU.getDirectory(), CU.getFilename()); - + unsigned Line = DSP->getLine(); unsigned Col = DSP->getColumn(); @@ -1350,8 +1350,8 @@ Result = LegalizeOp(Node->getOperand(0)); break; } - break; - + break; + case ISD::DEBUG_LOC: assert(Node->getNumOperands() == 4 && "Invalid DEBUG_LOC node!"); switch (TLI.getOperationAction(ISD::DEBUG_LOC, MVT::Other)) { @@ -1374,7 +1374,7 @@ break; } } - break; + break; case ISD::DBG_LABEL: case ISD::EH_LABEL: @@ -1439,7 +1439,7 @@ for (unsigned int x = 0; x < num_operands; ++x) Ops[x] = LegalizeOp(Node->getOperand(x)); Result = DAG.UpdateNodeOperands(Result, &Ops[0], num_operands); - + switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { default: assert(0 && "This action is not supported yet!"); case TargetLowering::Custom: @@ -1551,7 +1551,7 @@ Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); } break; - + case ISD::FORMAL_ARGUMENTS: case ISD::CALL: // The only option for this is to custom lower it. @@ -1572,7 +1572,7 @@ Tmp3.getNode()->getValueType(Tmp3.getNode()->getNumValues() - 1) == MVT::Flag)) && "Lowering call/formal_arguments produced unexpected # results!"); - + // Since CALL/FORMAL_ARGUMENTS nodes produce multiple values, make sure to // remember that we legalized all of them, so it doesn't get relegalized. for (unsigned i = 0, e = Tmp3.getNode()->getNumValues(); i != e; ++i) { @@ -1594,13 +1594,13 @@ break; case ISD::INSERT_SUBREG: { Tmp1 = LegalizeOp(Node->getOperand(0)); - Tmp2 = LegalizeOp(Node->getOperand(1)); + Tmp2 = LegalizeOp(Node->getOperand(1)); ConstantSDNode *idx = dyn_cast(Node->getOperand(2)); assert(idx && "Operand must be a constant"); Tmp3 = DAG.getTargetConstant(idx->getAPIntValue(), idx->getValueType(0)); Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); } - break; + break; case ISD::BUILD_VECTOR: switch (TLI.getOperationAction(ISD::BUILD_VECTOR, Node->getValueType(0))) { default: assert(0 && "This action is not supported yet!"); @@ -1629,13 +1629,13 @@ case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break; case Expand: // FIXME: An alternative would be to check to see if the target is not - // going to custom lower this operation, we could bitcast to half elt + // going to custom lower this operation, we could bitcast to half elt // width and perform two inserts at that width, if that is legal. Tmp2 = Node->getOperand(1); break; } Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); - + switch (TLI.getOperationAction(ISD::INSERT_VECTOR_ELT, Node->getValueType(0))) { default: assert(0 && "This action is not supported yet!"); @@ -1656,16 +1656,16 @@ if (ConstantSDNode *InsertPos = dyn_cast(Tmp3)) { // SCALAR_TO_VECTOR requires that the type of the value being inserted // match the element type of the vector being created. - if (Tmp2.getValueType() == + if (Tmp2.getValueType() == Op.getValueType().getVectorElementType()) { SDValue ScVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, Tmp1.getValueType(), Tmp2); - + unsigned NumElts = Tmp1.getValueType().getVectorNumElements(); MVT ShufMaskVT = MVT::getIntVectorWithNumElements(NumElts); MVT ShufMaskEltVT = ShufMaskVT.getVectorElementType(); - + // We generate a shuffle of InVec and ScVec, so the shuffle mask // should be 0,1,2,3,4,5... with the appropriate element replaced with // elt 0 of the RHS. @@ -1678,7 +1678,7 @@ } SDValue ShufMask = DAG.getNode(ISD::BUILD_VECTOR, dl, ShufMaskVT, &ShufOps[0], ShufOps.size()); - + Result = DAG.getNode(ISD::VECTOR_SHUFFLE, dl, Tmp1.getValueType(), Tmp1, ScVec, ShufMask); Result = LegalizeOp(Result); @@ -1695,7 +1695,7 @@ Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); break; } - + Tmp1 = LegalizeOp(Node->getOperand(0)); // InVal Result = DAG.UpdateNodeOperands(Result, Tmp1); switch (TLI.getOperationAction(ISD::SCALAR_TO_VECTOR, @@ -1767,7 +1767,7 @@ // Cast the two input vectors. Tmp1 = DAG.getNode(ISD::BIT_CONVERT, dl, NVT, Tmp1); Tmp2 = DAG.getNode(ISD::BIT_CONVERT, dl, NVT, Tmp2); - + // Convert the shuffle mask to the right # elements. Tmp3 = SDValue(isShuffleLegal(OVT, Node->getOperand(2)), 0); assert(Tmp3.getNode() && "Shuffle not legal?"); @@ -1777,7 +1777,7 @@ } } break; - + case ISD::EXTRACT_VECTOR_ELT: Tmp1 = Node->getOperand(0); Tmp2 = LegalizeOp(Node->getOperand(1)); @@ -1785,13 +1785,13 @@ Result = ExpandEXTRACT_VECTOR_ELT(Result); break; - case ISD::EXTRACT_SUBVECTOR: + case ISD::EXTRACT_SUBVECTOR: Tmp1 = Node->getOperand(0); Tmp2 = LegalizeOp(Node->getOperand(1)); Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); Result = ExpandEXTRACT_SUBVECTOR(Result); break; - + case ISD::CONCAT_VECTORS: { // Use extract/insert/build vector for now. We might try to be // more clever later. @@ -1814,7 +1814,7 @@ case ISD::CALLSEQ_START: { SDNode *CallEnd = FindCallEndFromCallStart(Node); - + // Recursively Legalize all of the inputs of the call end that do not lead // to this call start. This ensures that any libcalls that need be inserted // are inserted *before* the CALLSEQ_START. @@ -1833,32 +1833,32 @@ // Merge in the last call, to ensure that this call start after the last // call ended. if (LastCALLSEQ_END.getOpcode() != ISD::EntryToken) { - Tmp1 = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, + Tmp1 = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Tmp1, LastCALLSEQ_END); Tmp1 = LegalizeOp(Tmp1); } - + // Do not try to legalize the target-specific arguments (#1+). if (Tmp1 != Node->getOperand(0)) { SmallVector Ops(Node->op_begin(), Node->op_end()); Ops[0] = Tmp1; Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); } - + // Remember that the CALLSEQ_START is legalized. AddLegalizedOperand(Op.getValue(0), Result); if (Node->getNumValues() == 2) // If this has a flag result, remember it. AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); - + // Now that the callseq_start and all of the non-call nodes above this call - // sequence have been legalized, legalize the call itself. During this + // sequence have been legalized, legalize the call itself. During this // process, no libcalls can/will be inserted, guaranteeing that no calls // can overlap. assert(!IsLegalizingCall && "Inconsistent sequentialization of calls!"); // Note that we are selecting this call! LastCALLSEQ_END = SDValue(CallEnd, 0); IsLegalizingCall = true; - + // Legalize the call, starting from the CALLSEQ_END. LegalizeOp(LastCALLSEQ_END); assert(!IsLegalizingCall && "CALLSEQ_END should have cleared this!"); @@ -1874,8 +1874,8 @@ "Legalizing the call start should have legalized this node!"); return I->second; } - - // Otherwise, the call start has been legalized and everything is going + + // Otherwise, the call start has been legalized and everything is going // according to plan. Just legalize ourselves normally here. Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. // Do not try to legalize the target-specific arguments (#1+), except for @@ -1899,7 +1899,7 @@ assert(IsLegalizingCall && "Call sequence imbalance between start/end?"); // This finishes up call legalization. IsLegalizingCall = false; - + // If the CALLSEQ_END node has a flag, remember that we legalized it. AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); if (Node->getNumValues() == 2) @@ -1988,10 +1988,10 @@ Changed |= Op != Ops.back(); Ops.back() = Op; } - + if (Changed) Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); - + // INLINE asm returns a chain and flag, make sure to add both to the map. AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1)); @@ -2003,7 +2003,7 @@ Tmp1 = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Tmp1, LastCALLSEQ_END); Tmp1 = LegalizeOp(Tmp1); LastCALLSEQ_END = DAG.getEntryNode(); - + Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); break; case ISD::BRIND: @@ -2012,7 +2012,7 @@ Tmp1 = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Tmp1, LastCALLSEQ_END); Tmp1 = LegalizeOp(Tmp1); LastCALLSEQ_END = DAG.getEntryNode(); - + switch (getTypeAction(Node->getOperand(1).getValueType())) { default: assert(0 && "Indirect target must be legal type (pointer)!"); case Legal: @@ -2031,7 +2031,7 @@ Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the jumptable node. Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); - switch (TLI.getOperationAction(ISD::BR_JT, MVT::Other)) { + switch (TLI.getOperationAction(ISD::BR_JT, MVT::Other)) { default: assert(0 && "This action is not supported yet!"); case TargetLowering::Legal: break; case TargetLowering::Custom: @@ -2046,7 +2046,7 @@ MVT PTy = TLI.getPointerTy(); MachineFunction &MF = DAG.getMachineFunction(); unsigned EntrySize = MF.getJumpTableInfo()->getEntrySize(); - Index= DAG.getNode(ISD::MUL, dl, PTy, + Index= DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(EntrySize, PTy)); SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); @@ -2079,11 +2079,11 @@ break; case Promote: { Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition. - + // The top bits of the promoted condition are not necessarily zero, ensure // that the value is properly zero extended. unsigned BitWidth = Tmp2.getValueSizeInBits(); - if (!DAG.MaskedValueIsZero(Tmp2, + if (!DAG.MaskedValueIsZero(Tmp2, APInt::getHighBitsSet(BitWidth, BitWidth-1))) Tmp2 = DAG.getZeroExtendInReg(Tmp2, dl, MVT::i1); break; @@ -2092,8 +2092,8 @@ // Basic block destination (Op#2) is always legal. Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); - - switch (TLI.getOperationAction(ISD::BRCOND, MVT::Other)) { + + switch (TLI.getOperationAction(ISD::BRCOND, MVT::Other)) { default: assert(0 && "This action is not supported yet!"); case TargetLowering::Legal: break; case TargetLowering::Custom: @@ -2104,12 +2104,12 @@ // Expand brcond's setcc into its constituent parts and create a BR_CC // Node. if (Tmp2.getOpcode() == ISD::SETCC) { - Result = DAG.getNode(ISD::BR_CC, dl, MVT::Other, + Result = DAG.getNode(ISD::BR_CC, dl, MVT::Other, Tmp1, Tmp2.getOperand(2), Tmp2.getOperand(0), Tmp2.getOperand(1), Node->getOperand(2)); } else { - Result = DAG.getNode(ISD::BR_CC, dl, MVT::Other, Tmp1, + Result = DAG.getNode(ISD::BR_CC, dl, MVT::Other, Tmp1, DAG.getCondCode(ISD::SETNE), Tmp2, DAG.getConstant(0, Tmp2.getValueType()), Node->getOperand(2)); @@ -2122,11 +2122,11 @@ // Ensure that libcalls are emitted before a branch. Tmp1 = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Tmp1, LastCALLSEQ_END); Tmp1 = LegalizeOp(Tmp1); - Tmp2 = Node->getOperand(2); // LHS + Tmp2 = Node->getOperand(2); // LHS Tmp3 = Node->getOperand(3); // RHS Tmp4 = Node->getOperand(1); // CC - LegalizeSetCC(TLI.getSetCCResultType(Tmp2.getValueType()), + LegalizeSetCC(TLI.getSetCCResultType(Tmp2.getValueType()), Tmp2, Tmp3, Tmp4, dl); LastCALLSEQ_END = DAG.getEntryNode(); @@ -2137,10 +2137,10 @@ Tmp3 = DAG.getConstant(0, Tmp2.getValueType()); Tmp4 = DAG.getCondCode(ISD::SETNE); } - - Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp4, Tmp2, Tmp3, + + Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp4, Tmp2, Tmp3, Node->getOperand(4)); - + switch (TLI.getOperationAction(ISD::BR_CC, Tmp3.getValueType())) { default: assert(0 && "Unexpected action for BR_CC!"); case TargetLowering::Legal: break; @@ -2161,7 +2161,7 @@ Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); Tmp3 = Result.getValue(0); Tmp4 = Result.getValue(1); - + switch (TLI.getOperationAction(Node->getOpcode(), VT)) { default: assert(0 && "This action is not supported yet!"); case TargetLowering::Legal: @@ -2201,7 +2201,7 @@ break; } } - // Since loads produce two values, make sure to remember that we + // Since loads produce two values, make sure to remember that we // legalized both of them. AddLegalizedOperand(SDValue(Node, 0), Tmp3); AddLegalizedOperand(SDValue(Node, 1), Tmp4); @@ -2243,12 +2243,12 @@ if (ExtType == ISD::SEXTLOAD) // Having the top bits zero doesn't help when sign extending. - Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, + Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, Result.getValueType(), Result, DAG.getValueType(SrcVT)); else if (ExtType == ISD::ZEXTLOAD || NVT == Result.getValueType()) // All the top bits are guaranteed to be zero - inform the optimizers. - Result = DAG.getNode(ISD::AssertZext, dl, + Result = DAG.getNode(ISD::AssertZext, dl, Result.getValueType(), Result, DAG.getValueType(SrcVT)); @@ -2309,7 +2309,7 @@ IncrementSize = RoundWidth / 8; Tmp2 = DAG.getNode(ISD::ADD, dl, Tmp2.getValueType(), Tmp2, DAG.getIntPtrConstant(IncrementSize)); - Lo = DAG.getExtLoad(ISD::ZEXTLOAD, dl, + Lo = DAG.getExtLoad(ISD::ZEXTLOAD, dl, Node->getValueType(0), Tmp1, Tmp2, LD->getSrcValue(), SVOffset + IncrementSize, ExtraVT, isVolatile, @@ -2370,7 +2370,7 @@ SDValue Load = DAG.getLoad(SrcVT, dl, Tmp1, Tmp2, LD->getSrcValue(), LD->getSrcValueOffset(), LD->isVolatile(), LD->getAlignment()); - Result = DAG.getNode(ISD::FP_EXTEND, dl, + Result = DAG.getNode(ISD::FP_EXTEND, dl, Node->getValueType(0), Load); Tmp1 = LegalizeOp(Result); // Relegalize new nodes. Tmp2 = LegalizeOp(Load.getValue(1)); @@ -2416,7 +2416,7 @@ Result = DAG.getNode(ISD::TRUNCATE, dl, Node->getValueType(0), Result); } else { // 0 -> Lo - Result = DAG.getNode(ISD::TRUNCATE, dl, Node->getValueType(0), + Result = DAG.getNode(ISD::TRUNCATE, dl, Node->getValueType(0), Node->getOperand(0)); } break; @@ -2450,7 +2450,7 @@ } else { Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); } - + // Since this produces two values, make sure to remember that we legalized // both of them. AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0)); @@ -2466,7 +2466,7 @@ Tmp1 = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Tmp1, LastCALLSEQ_END); Tmp1 = LegalizeOp(Tmp1); LastCALLSEQ_END = DAG.getEntryNode(); - + switch (Node->getNumOperands()) { case 3: // ret val Tmp2 = Node->getOperand(1); @@ -2483,9 +2483,9 @@ // Big endian systems want the hi reg first. if (TLI.isBigEndian()) std::swap(Lo, Hi); - + if (Hi.getNode()) - Result = DAG.getNode(ISD::RET, dl, MVT::Other, + Result = DAG.getNode(ISD::RET, dl, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); else Result = DAG.getNode(ISD::RET, dl, MVT::Other, Tmp1, Lo, Tmp3); @@ -2495,7 +2495,7 @@ int InIx = Tmp2.getResNo(); unsigned NumElems = InVal->getValueType(InIx).getVectorNumElements(); MVT EVT = InVal->getValueType(InIx).getVectorElementType(); - + // Figure out if there is a simple type corresponding to this Vector // type. If so, convert to the vector type. MVT TVT = MVT::getVectorVT(EVT, NumElems); @@ -2508,10 +2508,10 @@ Tmp2 = ScalarizeVectorOp(Tmp2); Tmp2 = LegalizeOp(Tmp2); Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); - + // FIXME: Returns of gcc generic vectors smaller than a legal type // should be returned in integer registers! - + // The scalarized value type may not be legal, e.g. it might require // promotion or expansion. Relegalize the return. Result = LegalizeOp(Result); @@ -2520,7 +2520,7 @@ // type should be returned by reference! SDValue Lo, Hi; SplitVectorOp(Tmp2, Lo, Hi); - Result = DAG.getNode(ISD::RET, dl, MVT::Other, + Result = DAG.getNode(ISD::RET, dl, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); Result = LegalizeOp(Result); } @@ -2561,7 +2561,7 @@ case Promote: assert(0 && "Can't promote multiple return value yet!"); } - + if (NewValues.size() == Node->getNumOperands()) Result = DAG.UpdateNodeOperands(Result, &NewValues[0],NewValues.size()); else @@ -2599,7 +2599,7 @@ // together. // We generally can't do this one for long doubles. if (ConstantFPSDNode *CFP = dyn_cast(ST->getValue())) { - if (CFP->getValueType(0) == MVT::f32 && + if (CFP->getValueType(0) == MVT::f32 && getTypeAction(MVT::i32) == Legal) { Tmp3 = DAG.getConstant(CFP->getValueAPF(). bitcastToAPInt().zextOrTrunc(32), @@ -2636,11 +2636,11 @@ } } } - + switch (getTypeAction(ST->getMemoryVT())) { case Legal: { Tmp3 = LegalizeOp(ST->getValue()); - Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, + Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, ST->getOffset()); MVT VT = Tmp3.getValueType(); @@ -2663,7 +2663,7 @@ break; case TargetLowering::Promote: assert(VT.isVector() && "Unknown legal promote case!"); - Tmp3 = DAG.getNode(ISD::BIT_CONVERT, dl, + Tmp3 = DAG.getNode(ISD::BIT_CONVERT, dl, TLI.getTypeToPromoteTo(ISD::STORE, VT), Tmp3); Result = DAG.getStore(Tmp1, dl, Tmp3, Tmp2, ST->getSrcValue(), SVOffset, isVolatile, @@ -2685,7 +2685,7 @@ case Expand: { unsigned IncrementSize = 0; SDValue Lo, Hi; - + // If this is a vector type, then we have to calculate the increment as // the product of the element size in bytes, and the number of elements // in the high half of the vector. @@ -2883,7 +2883,7 @@ Result = DAG.UpdateNodeOperands(Result, Tmp1); Tmp1 = Result.getValue(0); Tmp2 = Result.getValue(1); - + switch (TLI.getOperationAction(ISD::STACKSAVE, MVT::Other)) { default: assert(0 && "This action is not supported yet!"); case TargetLowering::Legal: break; @@ -2895,7 +2895,7 @@ } break; case TargetLowering::Expand: - // Expand to CopyFromReg if the target set + // Expand to CopyFromReg if the target set // StackPointerRegisterToSaveRestore. if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { Tmp1 = DAG.getCopyFromReg(Result.getOperand(0), dl, SP, @@ -2918,7 +2918,7 @@ Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); - + switch (TLI.getOperationAction(ISD::STACKRESTORE, MVT::Other)) { default: assert(0 && "This action is not supported yet!"); case TargetLowering::Legal: break; @@ -2927,7 +2927,7 @@ if (Tmp1.getNode()) Result = Tmp1; break; case TargetLowering::Expand: - // Expand to CopyToReg if the target set + // Expand to CopyToReg if the target set // StackPointerRegisterToSaveRestore. if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { Result = DAG.getCopyToReg(Tmp1, dl, SP, Tmp2); @@ -2982,7 +2982,7 @@ Tmp3 = LegalizeOp(Node->getOperand(2)); // FalseVal Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); - + switch (TLI.getOperationAction(ISD::SELECT, Tmp2.getValueType())) { default: assert(0 && "This action is not supported yet!"); case TargetLowering::Legal: break; @@ -2993,11 +2993,11 @@ } case TargetLowering::Expand: if (Tmp1.getOpcode() == ISD::SETCC) { - Result = DAG.getSelectCC(dl, Tmp1.getOperand(0), Tmp1.getOperand(1), + Result = DAG.getSelectCC(dl, Tmp1.getOperand(0), Tmp1.getOperand(1), Tmp2, Tmp3, cast(Tmp1.getOperand(2))->get()); } else { - Result = DAG.getSelectCC(dl, Tmp1, + Result = DAG.getSelectCC(dl, Tmp1, DAG.getConstant(0, Tmp1.getValueType()), Tmp2, Tmp3, ISD::SETNE); } @@ -3036,10 +3036,10 @@ Tmp3 = LegalizeOp(Node->getOperand(2)); // True Tmp4 = LegalizeOp(Node->getOperand(3)); // False SDValue CC = Node->getOperand(4); - - LegalizeSetCC(TLI.getSetCCResultType(Tmp1.getValueType()), + + LegalizeSetCC(TLI.getSetCCResultType(Tmp1.getValueType()), Tmp1, Tmp2, CC, dl); - + // If we didn't get both a LHS and RHS back from LegalizeSetCC, // the LHS is a legal SETCC itself. In this case, we need to compare // the result against zero to select between true and false values. @@ -3065,9 +3065,9 @@ Tmp2 = Node->getOperand(1); Tmp3 = Node->getOperand(2); LegalizeSetCC(Node->getValueType(0), Tmp1, Tmp2, Tmp3, dl); - - // If we had to Expand the SetCC operands into a SELECT node, then it may - // not always be possible to return a true LHS & RHS. In this case, just + + // If we had to Expand the SetCC operands into a SELECT node, then it may + // not always be possible to return a true LHS & RHS. In this case, just // return the value we legalized, returned in the LHS if (Tmp2.getNode() == 0) { Result = Tmp1; @@ -3101,7 +3101,7 @@ "Fell off of the edge of the integer world"); assert(NewInTy.isFloatingPoint() == OldVT.isFloatingPoint() && "Fell off of the edge of the floating point world"); - + // If the target supports SETCC of this type, use it. if (TLI.isOperationLegalOrCustom(ISD::SETCC, NewInTy)) break; @@ -3122,7 +3122,7 @@ // Expand a setcc node into a select_cc of the same condition, lhs, and // rhs that selects between const 1 (true) and const 0 (false). MVT VT = Node->getValueType(0); - Result = DAG.getNode(ISD::SELECT_CC, dl, VT, Tmp1, Tmp2, + Result = DAG.getNode(ISD::SELECT_CC, dl, VT, Tmp1, Tmp2, DAG.getConstant(1, VT), DAG.getConstant(0, VT), Tmp3); break; @@ -3132,7 +3132,7 @@ Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS SDValue CC = Node->getOperand(2); - + Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, CC); // Everything is legal, see if we should expand this op or something. @@ -3263,7 +3263,7 @@ // Fall through if the custom lower can't deal with the operation case TargetLowering::Expand: { MVT VT = Op.getValueType(); - + // See if multiply or divide can be lowered using two-result operations. SDVTList VTs = DAG.getVTList(VT, VT); if (Node->getOpcode() == ISD::MUL) { @@ -3293,12 +3293,12 @@ } if (Node->getOpcode() == ISD::MULHS && TLI.isOperationLegalOrCustom(ISD::SMUL_LOHI, VT)) { - Result = SDValue(DAG.getNode(ISD::SMUL_LOHI, dl, + Result = SDValue(DAG.getNode(ISD::SMUL_LOHI, dl, VTs, Tmp1, Tmp2).getNode(), 1); break; } - if (Node->getOpcode() == ISD::MULHU && + if (Node->getOpcode() == ISD::MULHU && TLI.isOperationLegalOrCustom(ISD::UMUL_LOHI, VT)) { Result = SDValue(DAG.getNode(ISD::UMUL_LOHI, dl, VTs, Tmp1, Tmp2).getNode(), @@ -3307,7 +3307,7 @@ } if (Node->getOpcode() == ISD::SDIV && TLI.isOperationLegalOrCustom(ISD::SDIVREM, VT)) { - Result = SDValue(DAG.getNode(ISD::SDIVREM, dl, + Result = SDValue(DAG.getNode(ISD::SDIVREM, dl, VTs, Tmp1, Tmp2).getNode(), 0); break; @@ -3353,7 +3353,7 @@ Result = ExpandLibCall(LC, Node, isSigned, Dummy); break; } - + assert(Node->getValueType(0).isVector() && "Cannot expand this binary operator!"); // Expand the operation into a bunch of nasty scalar code. @@ -3381,7 +3381,7 @@ } } break; - + case ISD::SMUL_LOHI: case ISD::UMUL_LOHI: case ISD::SDIVREM: @@ -3407,9 +3407,9 @@ Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. break; } - + Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); - + switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { default: assert(0 && "Operation not supported"); case TargetLowering::Custom: @@ -3436,13 +3436,13 @@ // Select between the nabs and abs value based on the sign bit of // the input. Result = DAG.getNode(ISD::SELECT, dl, AbsVal.getValueType(), SignBit, - DAG.getNode(ISD::FNEG, dl, AbsVal.getValueType(), + DAG.getNode(ISD::FNEG, dl, AbsVal.getValueType(), AbsVal), AbsVal); Result = LegalizeOp(Result); break; } - + // Otherwise, do bitwise ops! MVT NVT = Node->getValueType(0) == MVT::f32 ? MVT::i32 : MVT::i64; @@ -3453,7 +3453,7 @@ } } break; - + case ISD::ADDC: case ISD::SUBC: Tmp1 = LegalizeOp(Node->getOperand(0)); @@ -3506,7 +3506,7 @@ AddLegalizedOperand(SDValue(Node, 0), Tmp3); AddLegalizedOperand(SDValue(Node, 1), Tmp4); return Op.getResNo() ? Tmp4 : Tmp3; - + case ISD::BUILD_PAIR: { MVT PairTy = Node->getValueType(0); // TODO: handle the case where the Lo and Hi operands are not of legal type @@ -3554,12 +3554,12 @@ unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; bool isSigned = DivOpc == ISD::SDIV; MVT VT = Node->getValueType(0); - + // See if remainder can be lowered using two-result operations. SDVTList VTs = DAG.getVTList(VT, VT); if (Node->getOpcode() == ISD::SREM && TLI.isOperationLegalOrCustom(ISD::SDIVREM, VT)) { - Result = SDValue(DAG.getNode(ISD::SDIVREM, dl, + Result = SDValue(DAG.getNode(ISD::SDIVREM, dl, VTs, Tmp1, Tmp2).getNode(), 1); break; } @@ -3644,14 +3644,14 @@ break; } } - // Since VAARG produces two values, make sure to remember that we + // Since VAARG produces two values, make sure to remember that we // legalized both of them. AddLegalizedOperand(SDValue(Node, 0), Result); AddLegalizedOperand(SDValue(Node, 1), Tmp1); return Op.getResNo() ? Tmp1 : Result; } - - case ISD::VACOPY: + + case ISD::VACOPY: Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the dest pointer. Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the source pointer. @@ -3680,7 +3680,7 @@ } break; - case ISD::VAEND: + case ISD::VAEND: Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. @@ -3701,13 +3701,13 @@ break; } break; - - case ISD::VASTART: + + case ISD::VASTART: Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); - + switch (TLI.getOperationAction(ISD::VASTART, MVT::Other)) { default: assert(0 && "This action is not supported yet!"); case TargetLowering::Legal: break; @@ -3717,7 +3717,7 @@ break; } break; - + case ISD::ROTL: case ISD::ROTR: Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS @@ -3741,7 +3741,7 @@ break; } break; - + case ISD::BSWAP: Tmp1 = LegalizeOp(Node->getOperand(0)); // Op switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { @@ -3766,7 +3766,7 @@ break; } break; - + case ISD::CTPOP: case ISD::CTTZ: case ISD::CTLZ: @@ -3867,7 +3867,7 @@ } case ISD::FSQRT: case ISD::FSIN: - case ISD::FCOS: + case ISD::FCOS: case ISD::FLOG: case ISD::FLOG2: case ISD::FLOG10: @@ -3978,18 +3978,18 @@ int InIx = Node->getOperand(0).getResNo(); unsigned NumElems = InVal->getValueType(InIx).getVectorNumElements(); MVT EVT = InVal->getValueType(InIx).getVectorElementType(); - + // Figure out if there is a simple type corresponding to this Vector // type. If so, convert to the vector type. MVT TVT = MVT::getVectorVT(EVT, NumElems); if (TLI.isTypeLegal(TVT)) { // Turn this into a bit convert of the vector input. - Result = DAG.getNode(ISD::BIT_CONVERT, dl, Node->getValueType(0), + Result = DAG.getNode(ISD::BIT_CONVERT, dl, Node->getValueType(0), LegalizeOp(Node->getOperand(0))); break; } else if (NumElems == 1) { // Turn this into a bit convert of the scalar input. - Result = DAG.getNode(ISD::BIT_CONVERT, dl, Node->getValueType(0), + Result = DAG.getNode(ISD::BIT_CONVERT, dl, Node->getValueType(0), ScalarizeVectorOp(Node->getOperand(0))); break; } else { @@ -4044,7 +4044,7 @@ case Promote: Result = PromoteOp(Node->getOperand(0)); // For FP, make Op1 a i32 - + Result = DAG.getConvertRndSat(Op.getValueType(), dl, Result, DTyOp, STyOp, RndOp, SatOp, CvtCode); break; @@ -4118,7 +4118,7 @@ break; case TargetLowering::Promote: Result = PromoteLegalFP_TO_INT(Tmp1, Node->getValueType(0), - Node->getOpcode() == ISD::FP_TO_SINT, + Node->getOpcode() == ISD::FP_TO_SINT, dl); break; case TargetLowering::Expand: @@ -4131,12 +4131,12 @@ APInt x = APInt::getSignBit(NVT.getSizeInBits()); (void)apf.convertFromAPInt(x, false, APFloat::rmNearestTiesToEven); Tmp2 = DAG.getConstantFP(apf, VT); - Tmp3 = DAG.getSetCC(dl, TLI.getSetCCResultType(VT), + Tmp3 = DAG.getSetCC(dl, TLI.getSetCCResultType(VT), Node->getOperand(0), Tmp2, ISD::SETLT); True = DAG.getNode(ISD::FP_TO_SINT, dl, NVT, Node->getOperand(0)); False = DAG.getNode(ISD::FP_TO_SINT, dl, NVT, - DAG.getNode(ISD::FSUB, dl, VT, + DAG.getNode(ISD::FSUB, dl, VT, Node->getOperand(0), Tmp2)); False = DAG.getNode(ISD::XOR, dl, NVT, False, DAG.getConstant(x, NVT)); @@ -4154,9 +4154,9 @@ // Convert ppcf128 to i32 if (OVT == MVT::ppcf128 && VT == MVT::i32) { if (Node->getOpcode() == ISD::FP_TO_SINT) { - Result = DAG.getNode(ISD::FP_ROUND_INREG, dl, MVT::ppcf128, + Result = DAG.getNode(ISD::FP_ROUND_INREG, dl, MVT::ppcf128, Node->getOperand(0), DAG.getValueType(MVT::f64)); - Result = DAG.getNode(ISD::FP_ROUND, dl, MVT::f64, Result, + Result = DAG.getNode(ISD::FP_ROUND, dl, MVT::f64, Result, DAG.getIntPtrConstant(1)); Result = DAG.getNode(ISD::FP_TO_SINT, dl, VT, Result); } else { @@ -4165,14 +4165,14 @@ Tmp2 = DAG.getConstantFP(apf, OVT); // X>=2^31 ? (int)(X-2^31)+0x80000000 : (int)X // FIXME: generated code sucks. - Result = DAG.getNode(ISD::SELECT_CC, dl, VT, Node->getOperand(0), + Result = DAG.getNode(ISD::SELECT_CC, dl, VT, Node->getOperand(0), Tmp2, DAG.getNode(ISD::ADD, dl, MVT::i32, DAG.getNode(ISD::FP_TO_SINT, dl, VT, DAG.getNode(ISD::FSUB, dl, OVT, Node->getOperand(0), Tmp2)), DAG.getConstant(0x80000000, MVT::i32)), - DAG.getNode(ISD::FP_TO_SINT, dl, VT, + DAG.getNode(ISD::FP_TO_SINT, dl, VT, Node->getOperand(0)), DAG.getCondCode(ISD::SETGE)); } @@ -4315,7 +4315,7 @@ // NOTE: there is a choice here between constantly creating new stack // slots and always reusing the same one. We currently always create // new ones, as reuse may inhibit scheduling. - Result = EmitStackConvert(Node->getOperand(0), ExtraVT, + Result = EmitStackConvert(Node->getOperand(0), ExtraVT, Node->getValueType(0), dl); } else { assert(0 && "Unknown op"); @@ -4396,7 +4396,7 @@ SDValue LHS = LegalizeOp(Node->getOperand(0)); SDValue RHS = LegalizeOp(Node->getOperand(1)); - SDValue Sum = DAG.getNode(Node->getOpcode() == ISD::SADDO ? + SDValue Sum = DAG.getNode(Node->getOpcode() == ISD::SADDO ? ISD::ADD : ISD::SUB, dl, LHS.getValueType(), LHS, RHS); MVT OType = Node->getValueType(1); @@ -4414,8 +4414,8 @@ // SDValue LHSSign = DAG.getSetCC(dl, OType, LHS, Zero, ISD::SETGE); SDValue RHSSign = DAG.getSetCC(dl, OType, RHS, Zero, ISD::SETGE); - SDValue SignsMatch = DAG.getSetCC(dl, OType, LHSSign, RHSSign, - Node->getOpcode() == ISD::SADDO ? + SDValue SignsMatch = DAG.getSetCC(dl, OType, LHSSign, RHSSign, + Node->getOpcode() == ISD::SADDO ? ISD::SETEQ : ISD::SETNE); SDValue SumSign = DAG.getSetCC(dl, OType, Sum, Zero, ISD::SETGE); @@ -4426,7 +4426,7 @@ MVT ValueVTs[] = { LHS.getValueType(), OType }; SDValue Ops[] = { Sum, Cmp }; - Result = DAG.getNode(ISD::MERGE_VALUES, dl, + Result = DAG.getNode(ISD::MERGE_VALUES, dl, DAG.getVTList(&ValueVTs[0], 2), &Ops[0], 2); SDNode *RNode = Result.getNode(); @@ -4456,13 +4456,13 @@ LHS, RHS); MVT OType = Node->getValueType(1); SDValue Cmp = DAG.getSetCC(dl, OType, Sum, LHS, - Node->getOpcode () == ISD::UADDO ? + Node->getOpcode () == ISD::UADDO ? ISD::SETULT : ISD::SETUGT); MVT ValueVTs[] = { LHS.getValueType(), OType }; SDValue Ops[] = { Sum, Cmp }; - Result = DAG.getNode(ISD::MERGE_VALUES, dl, + Result = DAG.getNode(ISD::MERGE_VALUES, dl, DAG.getVTList(&ValueVTs[0], 2), &Ops[0], 2); SDNode *RNode = Result.getNode(); @@ -4487,17 +4487,17 @@ // FIXME: According to Hacker's Delight, this can be implemented in // target independent lowering, but it would be inefficient, since it // requires a division + a branch. - assert(0 && "Target independent lowering is not supported for SMULO/UMULO!"); + assert(0 && "Target independent lowering is not supported for SMULO/UMULO!"); break; } break; } } - + assert(Result.getValueType() == Op.getValueType() && "Bad legalization!"); - + // Make sure that the generated code is itself legal. if (Result != Op) Result = LegalizeOp(Result); @@ -4621,7 +4621,7 @@ Node->getValueType(0), dl); Result = PromoteOp(Result); break; - + case ISD::FP_EXTEND: assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); case ISD::FP_ROUND: @@ -4635,7 +4635,7 @@ DAG.getValueType(VT)); } else { // Just remove the truncate, it isn't affecting the value. - Result = DAG.getNode(ISD::FP_ROUND, dl, NVT, Node->getOperand(0), + Result = DAG.getNode(ISD::FP_ROUND, dl, NVT, Node->getOperand(0), Node->getOperand(1)); } break; @@ -4674,7 +4674,7 @@ case ISD::SIGN_EXTEND_INREG: Result = PromoteOp(Node->getOperand(0)); - Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, NVT, Result, + Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, NVT, Result, Node->getOperand(1)); break; case ISD::FP_TO_SINT: @@ -4695,7 +4695,7 @@ // we can use that instead. This allows us to generate better code for // FP_TO_UINT for small destination sizes on targets where FP_TO_UINT is not // legal, such as PowerPC. - if (Node->getOpcode() == ISD::FP_TO_UINT && + if (Node->getOpcode() == ISD::FP_TO_UINT && !TLI.isOperationLegalOrCustom(ISD::FP_TO_UINT, NVT) && (TLI.isOperationLegalOrCustom(ISD::FP_TO_SINT, NVT) || TLI.getOperationAction(ISD::FP_TO_SINT, NVT)==TargetLowering::Custom)){ @@ -4751,13 +4751,13 @@ DAG.getValueType(VT)); break; } - + case ISD::ATOMIC_CMP_SWAP: { AtomicSDNode* AtomNode = cast(Node); Tmp2 = PromoteOp(Node->getOperand(2)); Tmp3 = PromoteOp(Node->getOperand(3)); - Result = DAG.getAtomic(Node->getOpcode(), dl, AtomNode->getMemoryVT(), - AtomNode->getChain(), + Result = DAG.getAtomic(Node->getOpcode(), dl, AtomNode->getMemoryVT(), + AtomNode->getChain(), AtomNode->getBasePtr(), Tmp2, Tmp3, AtomNode->getSrcValue(), AtomNode->getAlignment()); @@ -4779,7 +4779,7 @@ AtomicSDNode* AtomNode = cast(Node); Tmp2 = PromoteOp(Node->getOperand(2)); Result = DAG.getAtomic(Node->getOpcode(), dl, AtomNode->getMemoryVT(), - AtomNode->getChain(), + AtomNode->getChain(), AtomNode->getBasePtr(), Tmp2, AtomNode->getSrcValue(), AtomNode->getAlignment()); @@ -4809,7 +4809,7 @@ Tmp2 = PromoteOp(Node->getOperand(1)); assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); Result = DAG.getNode(Node->getOpcode(), dl, NVT, Tmp1, Tmp2); - + // Floating point operations will give excess precision that we may not be // able to tolerate. If we DO allow excess precision, just leave it, // otherwise excise it. @@ -4853,7 +4853,7 @@ case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break; } Result = DAG.getNode(Node->getOpcode(), dl, NVT, Tmp1, Tmp2); - + // Perform FP_ROUND: this is probably overly pessimistic. if (NoExcessFPPrecision && Node->getOpcode() != ISD::FCOPYSIGN) Result = DAG.getNode(ISD::FP_ROUND_INREG, dl, NVT, Result, @@ -4899,7 +4899,7 @@ const Value *V = cast(Node->getOperand(2))->getValue(); SDValue VAList = DAG.getLoad(TLI.getPointerTy(), dl, Tmp1, Tmp2, V, 0); // Increment the pointer, VAList, to the next vaarg - Tmp3 = DAG.getNode(ISD::ADD, dl, TLI.getPointerTy(), VAList, + Tmp3 = DAG.getNode(ISD::ADD, dl, TLI.getPointerTy(), VAList, DAG.getConstant(VT.getSizeInBits()/8, TLI.getPointerTy())); // Store the incremented VAList to the legalized pointer @@ -4992,7 +4992,7 @@ // Make sure the result is itself legal. Result = LegalizeOp(Result); - + // Remember that we promoted this! AddPromotedOperand(Op, Result); return Result; @@ -5009,10 +5009,10 @@ SDValue Vec = Op.getOperand(0); SDValue Idx = Op.getOperand(1); DebugLoc dl = Op.getDebugLoc(); - + MVT TVT = Vec.getValueType(); unsigned NumElems = TVT.getVectorNumElements(); - + switch (TLI.getOperationAction(ISD::EXTRACT_VECTOR_ELT, TVT)) { default: assert(0 && "This action is not supported yet!"); case TargetLowering::Custom: { @@ -5052,7 +5052,7 @@ Idx = DAG.getConstant(CIdx->getZExtValue() - NumLoElts, Idx.getValueType()); } - + // It's now an extract from the appropriate high or low part. Recurse. Op = DAG.UpdateNodeOperands(Op, Vec, Idx); Op = ExpandEXTRACT_VECTOR_ELT(Op); @@ -5086,9 +5086,9 @@ // is a constant and that the extracted result is a supported hardware type. SDValue Vec = Op.getOperand(0); SDValue Idx = LegalizeOp(Op.getOperand(1)); - + unsigned NumElems = Vec.getValueType().getVectorNumElements(); - + if (NumElems == Op.getValueType().getVectorNumElements()) { // This must be an access of the desired vector length. Return it. return Vec; @@ -5104,7 +5104,7 @@ Idx = DAG.getConstant(CIdx->getZExtValue() - NumElems/2, Idx.getValueType()); } - + // It's now an extract from the appropriate high or low part. Recurse. Op = DAG.UpdateNodeOperands(Op, Vec, Idx); return ExpandEXTRACT_SUBVECTOR(Op); @@ -5120,8 +5120,8 @@ SDValue &RHS, SDValue &CC, DebugLoc dl) { - SDValue Tmp1, Tmp2, Tmp3, Result; - + SDValue Tmp1, Tmp2, Tmp3, Result; + switch (getTypeAction(LHS.getValueType())) { case Legal: Tmp1 = LegalizeOp(LHS); // LHS @@ -5300,7 +5300,7 @@ // If this is a comparison of the sign bit, just look at the top part. // X > -1, x < 0 if (ConstantSDNode *CST = dyn_cast(RHS)) - if ((cast(CC)->get() == ISD::SETLT && + if ((cast(CC)->get() == ISD::SETLT && CST->isNullValue()) || // X < 0 (cast(CC)->get() == ISD::SETGT && CST->isAllOnesValue())) { // X > -1 @@ -5341,7 +5341,7 @@ Tmp2 = DAG.getNode(ISD::SETCC, dl, TLI.getSetCCResultType(LHSHi.getValueType()), LHSHi, RHSHi,CC); - + ConstantSDNode *Tmp1C = dyn_cast(Tmp1.getNode()); ConstantSDNode *Tmp2C = dyn_cast(Tmp2.getNode()); if ((Tmp1C && Tmp1C->isNullValue()) || @@ -5432,7 +5432,7 @@ unsigned SrcAlign = TLI.getTargetData()->getPrefTypeAlignment( SrcOp.getValueType().getTypeForMVT()); SDValue FIPtr = DAG.CreateStackTemporary(SlotVT, SrcAlign); - + FrameIndexSDNode *StackPtrFI = cast(FIPtr); int SPFI = StackPtrFI->getIndex(); const Value *SV = PseudoSourceValue::getFixedStack(SPFI); @@ -5442,11 +5442,11 @@ unsigned DestSize = DestVT.getSizeInBits(); unsigned DestAlign = TLI.getTargetData()->getPrefTypeAlignment( DestVT.getTypeForMVT()); - + // Emit a store to the stack slot. Use a truncstore if the input value is // later than DestVT. SDValue Store; - + if (SrcSize > SlotSize) Store = DAG.getTruncStore(DAG.getEntryNode(), dl, SrcOp, FIPtr, SV, 0, SlotVT, false, SrcAlign); @@ -5455,11 +5455,11 @@ Store = DAG.getStore(DAG.getEntryNode(), dl, SrcOp, FIPtr, SV, 0, false, SrcAlign); } - + // Result is a load from the stack slot. if (SlotSize == DestSize) return DAG.getLoad(DestVT, dl, Store, FIPtr, SV, 0, false, DestAlign); - + assert(SlotSize < DestSize && "Unknown extension!"); return DAG.getExtLoad(ISD::EXTLOAD, dl, DestVT, Store, FIPtr, SV, 0, SlotVT, false, DestAlign); @@ -5474,7 +5474,7 @@ FrameIndexSDNode *StackPtrFI = cast(StackPtr); int SPFI = StackPtrFI->getIndex(); - SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Node->getOperand(0), + SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Node->getOperand(0), StackPtr, PseudoSourceValue::getFixedStack(SPFI), 0); return DAG.getLoad(Node->getValueType(0), dl, Ch, StackPtr, @@ -5485,14 +5485,14 @@ /// ExpandBUILD_VECTOR - Expand a BUILD_VECTOR node on targets that don't /// support the operation, but do support the resultant vector type. SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) { - - // If the only non-undef value is the low element, turn this into a + + // If the only non-undef value is the low element, turn this into a // SCALAR_TO_VECTOR node. If this is { X, X, X, X }, determine X. unsigned NumElems = Node->getNumOperands(); bool isOnlyLowElement = true; SDValue SplatValue = Node->getOperand(0); DebugLoc dl = Node->getDebugLoc(); - + // FIXME: it would be far nicer to change this into map // and use a bitmask instead of a list of elements. std::map > Values; @@ -5501,7 +5501,7 @@ if (!isa(SplatValue) && !isa(SplatValue) && SplatValue.getOpcode() != ISD::UNDEF) isConstant = false; - + for (unsigned i = 1; i < NumElems; ++i) { SDValue V = Node->getOperand(i); Values[V].push_back(i); @@ -5516,7 +5516,7 @@ V.getOpcode() != ISD::UNDEF) isConstant = false; } - + if (isOnlyLowElement) { // If the low element is an undef too, then this whole things is an undef. if (Node->getOperand(0).getOpcode() == ISD::UNDEF) @@ -5525,21 +5525,21 @@ return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, Node->getValueType(0), Node->getOperand(0)); } - + // If all elements are constants, create a load from the constant pool. if (isConstant) { MVT VT = Node->getValueType(0); std::vector CV; for (unsigned i = 0, e = NumElems; i != e; ++i) { - if (ConstantFPSDNode *V = + if (ConstantFPSDNode *V = dyn_cast(Node->getOperand(i))) { CV.push_back(const_cast(V->getConstantFPValue())); - } else if (ConstantSDNode *V = + } else if (ConstantSDNode *V = dyn_cast(Node->getOperand(i))) { CV.push_back(const_cast(V->getConstantIntValue())); } else { assert(Node->getOperand(i).getOpcode() == ISD::UNDEF); - const Type *OpNTy = + const Type *OpNTy = Node->getOperand(0).getValueType().getTypeForMVT(); CV.push_back(UndefValue::get(OpNTy)); } @@ -5551,7 +5551,7 @@ PseudoSourceValue::getConstantPool(), 0, false, Alignment); } - + if (SplatValue.getNode()) { // Splat of one value? // Build the shuffle constant vector: <0, 0, 0, 0> MVT MaskVT = MVT::getIntVectorWithNumElements(NumElems); @@ -5563,18 +5563,18 @@ // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. if (isShuffleLegal(Node->getValueType(0), SplatMask)) { // Get the splatted value into the low element of a vector register. - SDValue LowValVec = - DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, + SDValue LowValVec = + DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, Node->getValueType(0), SplatValue); - + // Return shuffle(LowValVec, undef, <0,0,0,0>) - return DAG.getNode(ISD::VECTOR_SHUFFLE, dl, + return DAG.getNode(ISD::VECTOR_SHUFFLE, dl, Node->getValueType(0), LowValVec, DAG.getUNDEF(Node->getValueType(0)), SplatMask); } } - + // If there are only two unique elements, we may be able to turn this into a // vector shuffle. if (Values.size() == 2) { @@ -5586,12 +5586,12 @@ Val2 = MI->first; else Val2 = (++MI)->first; - - // If Val1 is an undef, make sure end ends up as Val2, to ensure that our + + // If Val1 is an undef, make sure end ends up as Val2, to ensure that our // vector shuffle has the undef vector on the RHS. if (Val1.getOpcode() == ISD::UNDEF) std::swap(Val1, Val2); - + // Build the shuffle constant vector: e.g. <0, 4, 0, 4> MVT MaskVT = MVT::getIntVectorWithNumElements(NumElems); MVT MaskEltVT = MaskVT.getVectorElementType(); @@ -5609,7 +5609,7 @@ MaskVec[Val2Elts[i]] = DAG.getConstant(NumElems, MaskEltVT); else MaskVec[Val2Elts[i]] = DAG.getUNDEF(MaskEltVT); - + SDValue ShuffleMask = DAG.getNode(ISD::BUILD_VECTOR, dl, MaskVT, &MaskVec[0], MaskVec.size()); @@ -5625,7 +5625,7 @@ return DAG.getNode(ISD::VECTOR_SHUFFLE, dl,Node->getValueType(0), Ops, 3); } } - + // Otherwise, we can't handle this case efficiently. Allocate a sufficiently // aligned object on the stack, store each element into it, then load // the result as a vector. @@ -5642,23 +5642,23 @@ for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { // Ignore undef elements. if (Node->getOperand(i).getOpcode() == ISD::UNDEF) continue; - + unsigned Offset = TypeByteSize*i; - + SDValue Idx = DAG.getConstant(Offset, FIPtr.getValueType()); Idx = DAG.getNode(ISD::ADD, dl, FIPtr.getValueType(), FIPtr, Idx); - + Stores.push_back(DAG.getStore(DAG.getEntryNode(), dl, Node->getOperand(i), Idx, SV, Offset)); } - + SDValue StoreChain; if (!Stores.empty()) // Not all undef elements? StoreChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &Stores[0], Stores.size()); else StoreChain = DAG.getEntryNode(); - + // Result is a load from the stack slot. return DAG.getLoad(VT, dl, StoreChain, FIPtr, SV, 0); } @@ -5717,7 +5717,7 @@ Lo = DAG.getNode(ISD::SHL, dl, NVT, InL, DAG.getConstant(Cst, ShTy)); Hi = DAG.getNode(ISD::OR, dl, NVT, DAG.getNode(ISD::SHL, dl, NVT, InH, DAG.getConstant(Cst, ShTy)), - DAG.getNode(ISD::SRL, dl, NVT, InL, + DAG.getNode(ISD::SRL, dl, NVT, InL, DAG.getConstant(NVTBits-Cst, ShTy))); } return true; @@ -5726,7 +5726,7 @@ Lo = DAG.getConstant(0, NVT); Hi = DAG.getConstant(0, NVT); } else if (Cst > NVTBits) { - Lo = DAG.getNode(ISD::SRL, dl, NVT, + Lo = DAG.getNode(ISD::SRL, dl, NVT, InH, DAG.getConstant(Cst-NVTBits,ShTy)); Hi = DAG.getConstant(0, NVT); } else if (Cst == NVTBits) { @@ -5735,7 +5735,7 @@ } else { Lo = DAG.getNode(ISD::OR, dl, NVT, DAG.getNode(ISD::SRL, dl, NVT, InL, DAG.getConstant(Cst, ShTy)), - DAG.getNode(ISD::SHL, dl, NVT, InH, + DAG.getNode(ISD::SHL, dl, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); Hi = DAG.getNode(ISD::SRL, dl, NVT, InH, DAG.getConstant(Cst, ShTy)); } @@ -5756,27 +5756,27 @@ } else { Lo = DAG.getNode(ISD::OR, dl, NVT, DAG.getNode(ISD::SRL, dl, NVT, InL, DAG.getConstant(Cst, ShTy)), - DAG.getNode(ISD::SHL, dl, + DAG.getNode(ISD::SHL, dl, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); Hi = DAG.getNode(ISD::SRA, dl, NVT, InH, DAG.getConstant(Cst, ShTy)); } return true; } } - + // Okay, the shift amount isn't constant. However, if we can tell that it is // >= 32 or < 32, we can still simplify it, without knowing the actual value. APInt Mask = APInt::getHighBitsSet(ShBits, ShBits - Log2_32(NVTBits)); APInt KnownZero, KnownOne; DAG.ComputeMaskedBits(Amt, Mask, KnownZero, KnownOne); - + // If we know that if any of the high bits of the shift amount are one, then // we can do this as a couple of simple shifts. if (KnownOne.intersects(Mask)) { // Mask out the high bit, which we know is set. Amt = DAG.getNode(ISD::AND, dl, Amt.getValueType(), Amt, DAG.getConstant(~Mask, Amt.getValueType())); - + // Expand the incoming operand to be shifted, so that we have its parts SDValue InL, InH; ExpandOp(Op, InL, InH); @@ -5796,7 +5796,7 @@ return true; } } - + // If we know that the high bits of the shift amount are all zero, then we can // do this as a couple of simple shifts. if ((KnownZero & Mask) == Mask) { @@ -5804,7 +5804,7 @@ SDValue Amt2 = DAG.getNode(ISD::SUB, dl, Amt.getValueType(), DAG.getConstant(NVTBits, Amt.getValueType()), Amt); - + // Expand the incoming operand to be shifted, so that we have its parts SDValue InL, InH; ExpandOp(Op, InL, InH); @@ -5829,7 +5829,7 @@ return true; } } - + return false; } @@ -5841,17 +5841,17 @@ SDValue SelectionDAGLegalize::ExpandLibCall(RTLIB::Libcall LC, SDNode *Node, bool isSigned, SDValue &Hi) { assert(!IsLegalizingCall && "Cannot overlap legalization of calls!"); - // The input chain to this libcall is the entry node of the function. + // The input chain to this libcall is the entry node of the function. // Legalizing the call will automatically add the previous call to the // dependence. SDValue InChain = DAG.getEntryNode(); - + TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { MVT ArgVT = Node->getOperand(i).getValueType(); const Type *ArgTy = ArgVT.getTypeForMVT(); - Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy; + Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy; Entry.isSExt = isSigned; Entry.isZExt = !isSigned; Args.push_back(Entry); @@ -5927,7 +5927,7 @@ Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, Tmp1.getValueType(), Tmp1, DAG.getValueType(Op.getValueType())); } else { - Tmp1 = DAG.getZeroExtendInReg(Tmp1, dl, + Tmp1 = DAG.getZeroExtendInReg(Tmp1, dl, Op.getValueType()); } if (Result.getNode()) @@ -5963,9 +5963,9 @@ SplitVectorOp(Source, Lo, Hi); MVT SplitDestTy = MVT::getVectorVT(DestEltTy, DestTy.getVectorNumElements() / 2); - SDValue LoResult = LegalizeINT_TO_FP(SDValue(), isSigned, SplitDestTy, + SDValue LoResult = LegalizeINT_TO_FP(SDValue(), isSigned, SplitDestTy, Lo, dl); - SDValue HiResult = LegalizeINT_TO_FP(SDValue(), isSigned, SplitDestTy, + SDValue HiResult = LegalizeINT_TO_FP(SDValue(), isSigned, SplitDestTy, Hi, dl); return LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, dl, DestTy, LoResult, HiResult)); @@ -6006,7 +6006,7 @@ // signed, then adjust the result if the sign bit is set. SDValue SignedConv = ExpandIntToFP(true, DestTy, Source, dl); - SDValue SignSet = DAG.getSetCC(dl, + SDValue SignSet = DAG.getSetCC(dl, TLI.getSetCCResultType(Hi.getValueType()), Hi, DAG.getConstant(0, Hi.getValueType()), ISD::SETLT); @@ -6032,7 +6032,7 @@ CPIdx, PseudoSourceValue::getConstantPool(), 0, MVT::f32, false, Alignment); - else + else assert(0 && "Unexpected conversion"); MVT SCVT = SignedConv.getValueType(); @@ -6095,19 +6095,19 @@ DebugLoc dl) { if (Op0.getValueType() == MVT::i32) { // simple 32-bit [signed|unsigned] integer to float/double expansion - + // Get the stack frame index of a 8 byte buffer. SDValue StackSlot = DAG.CreateStackTemporary(MVT::f64); - + // word offset constant for Hi/Lo address computation SDValue WordOff = DAG.getConstant(sizeof(int), TLI.getPointerTy()); // set up Hi and Lo (into buffer) address based on endian SDValue Hi = StackSlot; - SDValue Lo = DAG.getNode(ISD::ADD, dl, + SDValue Lo = DAG.getNode(ISD::ADD, dl, TLI.getPointerTy(), StackSlot,WordOff); if (TLI.isLittleEndian()) std::swap(Hi, Lo); - + // if signed map to unsigned space SDValue Op0Mapped; if (isSigned) { @@ -6295,7 +6295,7 @@ // Otherwise, try a larger type. } - + // Okay, we found the operation and type to use. SDValue Operation = DAG.getNode(OpToUse, dl, NewOutTy, LegalOp); @@ -6363,7 +6363,7 @@ /// ExpandBitCount - Expand the specified bitcount instruction into operations. /// -SDValue SelectionDAGLegalize::ExpandBitCount(unsigned Opc, SDValue Op, +SDValue SelectionDAGLegalize::ExpandBitCount(unsigned Opc, SDValue Op, DebugLoc dl) { switch (Opc) { default: assert(0 && "Cannot expand this yet!"); @@ -6382,7 +6382,7 @@ VT.getVectorElementType().getSizeInBits() : len; SDValue Tmp2 = DAG.getConstant(APInt(EltSize, mask[i]), VT); SDValue Tmp3 = DAG.getConstant(1ULL << i, ShVT); - Op = DAG.getNode(ISD::ADD, dl, VT, + Op = DAG.getNode(ISD::ADD, dl, VT, DAG.getNode(ISD::AND, dl, VT, Op, Tmp2), DAG.getNode(ISD::AND, dl, VT, DAG.getNode(ISD::SRL, dl, VT, Op, Tmp3), @@ -6405,7 +6405,7 @@ unsigned len = VT.getSizeInBits(); for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { SDValue Tmp3 = DAG.getConstant(1ULL << i, ShVT); - Op = DAG.getNode(ISD::OR, dl, VT, Op, + Op = DAG.getNode(ISD::OR, dl, VT, Op, DAG.getNode(ISD::SRL, dl, VT, Op, Tmp3)); } Op = DAG.getNOT(dl, Op, VT); @@ -6459,8 +6459,8 @@ case ISD::CopyFromReg: assert(0 && "CopyFromReg must be legal!"); case ISD::FP_ROUND_INREG: - if (VT == MVT::ppcf128 && - TLI.getOperationAction(ISD::FP_ROUND_INREG, VT) == + if (VT == MVT::ppcf128 && + TLI.getOperationAction(ISD::FP_ROUND_INREG, VT) == TargetLowering::Custom) { SDValue SrcLo, SrcHi, Src; ExpandOp(Op.getOperand(0), SrcLo, SrcHi); @@ -6505,7 +6505,7 @@ APInt api = CFP->getValueAPF().bitcastToAPInt(); Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[1])), MVT::f64); - Hi = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[0])), + Hi = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[0])), MVT::f64); break; } @@ -6519,7 +6519,7 @@ Lo = Node->getOperand(0); Hi = Node->getOperand(1); break; - + case ISD::MERGE_VALUES: if (Node->getNumValues() == 1) { ExpandOp(Op.getOperand(0), Lo, Hi); @@ -6533,12 +6533,12 @@ // Remember that we legalized the chain. AddLegalizedOperand(Op.getValue(1), LegalizeOp(Op.getOperand(1))); break; - + case ISD::SIGN_EXTEND_INREG: ExpandOp(Node->getOperand(0), Lo, Hi); // sext_inreg the low part if needed. Lo = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, NVT, Lo, Node->getOperand(1)); - + // The high part gets the sign extension from the lo-part. This handles // things like sextinreg V:i64 from i8. Hi = DAG.getNode(ISD::SRA, dl, NVT, Lo, @@ -6553,7 +6553,7 @@ Lo = TempLo; break; } - + case ISD::CTPOP: ExpandOp(Node->getOperand(0), Lo, Hi); Lo = DAG.getNode(ISD::ADD, dl, NVT, // ctpop(HL) -> ctpop(H)+ctpop(L) @@ -6605,7 +6605,7 @@ std::swap(Lo, Hi); break; } - + case ISD::LOAD: { LoadSDNode *LD = cast(Node); SDValue Ch = LD->getChain(); // Legalize the chain. @@ -6660,7 +6660,7 @@ ExpandOp(DAG.getNode(ISD::FP_EXTEND, dl, VT, Load), Lo, Hi); break; } - + if (EVT == NVT) Lo = DAG.getLoad(NVT, dl, Ch, Ptr, SV, SVOffset, isVolatile, Alignment); @@ -6668,7 +6668,7 @@ Lo = DAG.getExtLoad(ExtType, dl, NVT, Ch, Ptr, SV, SVOffset, EVT, isVolatile, Alignment); - + // Remember that we legalized the chain. AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Lo.getValue(1))); @@ -6748,12 +6748,12 @@ // The high part is just a zero. Hi = DAG.getConstant(0, NVT); break; - + case ISD::TRUNCATE: { // The input value must be larger than this value. Expand *it*. SDValue NewLo; ExpandOp(Node->getOperand(0), NewLo, Hi); - + // The low part is now either the right size, or it is closer. If not the // right size, make an illegal truncate so we recursively expand it. if (NewLo.getValueType() != Node->getValueType(0)) @@ -6761,7 +6761,7 @@ ExpandOp(NewLo, Lo, Hi); break; } - + case ISD::BIT_CONVERT: { SDValue Tmp; if (TLI.getOperationAction(ISD::BIT_CONVERT, VT) == TargetLowering::Custom){ @@ -6793,13 +6793,13 @@ // Turn this into a load/store pair by default. if (Tmp.getNode() == 0) Tmp = EmitStackConvert(Node->getOperand(0), VT, VT, dl); - + ExpandOp(Tmp, Lo, Hi); break; } case ISD::READCYCLECOUNTER: { - assert(TLI.getOperationAction(ISD::READCYCLECOUNTER, VT) == + assert(TLI.getOperationAction(ISD::READCYCLECOUNTER, VT) == TargetLowering::Custom && "Must custom expand ReadCycleCounter"); SDValue Tmp = TLI.LowerOperation(Op, DAG); @@ -6833,7 +6833,7 @@ ExpandOp(Op.getOperand(2), In2Lo, In2Hi); In2 = DAG.getNode(ISD::BUILD_PAIR, dl, VT, In2Lo, In2Hi); AtomicSDNode* Anode = cast(Node); - SDValue Replace = + SDValue Replace = DAG.getAtomic(Op.getOpcode(), dl, Anode->getMemoryVT(), Op.getOperand(0), Op.getOperand(1), In2, Anode->getSrcValue(), Anode->getAlignment()); @@ -6880,7 +6880,7 @@ case Legal: Op = LegalizeOp(Node->getOperand(0)); break; case Promote: Op = PromoteOp (Node->getOperand(0)); break; } - + Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_UINT, dl, VT, Op), DAG); // Now that the custom expander is done, expand the result. @@ -6910,12 +6910,12 @@ break; } } - - // If ADDC/ADDE are supported and if the shift amount is a constant 1, emit + + // If ADDC/ADDE are supported and if the shift amount is a constant 1, emit // this X << 1 as X+X. if (ConstantSDNode *ShAmt = dyn_cast(ShiftAmt)) { if (ShAmt->getAPIntValue() == 1 && - TLI.isOperationLegalOrCustom(ISD::ADDC, NVT) && + TLI.isOperationLegalOrCustom(ISD::ADDC, NVT) && TLI.isOperationLegalOrCustom(ISD::ADDE, NVT)) { SDValue LoOps[2], HiOps[3]; ExpandOp(Node->getOperand(0), LoOps[0], HiOps[0]); @@ -6929,7 +6929,7 @@ break; } } - + // If we can emit an efficient shift operation, do so now. if (ExpandShift(ISD::SHL, Node->getOperand(0), ShiftAmt, Lo, Hi, dl)) break; @@ -6939,7 +6939,7 @@ TLI.getOperationAction(ISD::SHL_PARTS, NVT); if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || Action == TargetLowering::Custom) { - ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0), + ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi, dl); break; } @@ -6962,7 +6962,7 @@ break; } } - + // If we can emit an efficient shift operation, do so now. if (ExpandShift(ISD::SRA, Node->getOperand(0), ShiftAmt, Lo, Hi, dl)) break; @@ -6972,7 +6972,7 @@ TLI.getOperationAction(ISD::SRA_PARTS, NVT); if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || Action == TargetLowering::Custom) { - ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0), + ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi, dl); break; } @@ -7066,12 +7066,12 @@ SDValue Cmp1 = DAG.getSetCC(dl, TLI.getSetCCResultType(NVT), Lo, LoOps[0], ISD::SETULT); SDValue Carry1 = DAG.getNode(ISD::SELECT, dl, NVT, Cmp1, - DAG.getConstant(1, NVT), + DAG.getConstant(1, NVT), DAG.getConstant(0, NVT)); SDValue Cmp2 = DAG.getSetCC(dl, TLI.getSetCCResultType(NVT), Lo, LoOps[1], ISD::SETULT); SDValue Carry2 = DAG.getNode(ISD::SELECT, dl, NVT, Cmp2, - DAG.getConstant(1, NVT), + DAG.getConstant(1, NVT), Carry1); Hi = DAG.getNode(ISD::ADD, dl, NVT, Hi, Carry2); } else { @@ -7079,14 +7079,14 @@ Hi = DAG.getNode(ISD::SUB, dl, NVT, HiOps, 2); SDValue Cmp = DAG.getSetCC(dl, NVT, LoOps[0], LoOps[1], ISD::SETULT); SDValue Borrow = DAG.getNode(ISD::SELECT, dl, NVT, Cmp, - DAG.getConstant(1, NVT), + DAG.getConstant(1, NVT), DAG.getConstant(0, NVT)); Hi = DAG.getNode(ISD::SUB, dl, NVT, Hi, Borrow); } break; } } - + case ISD::ADDC: case ISD::SUBC: { // Expand the subcomponents. @@ -7096,7 +7096,7 @@ SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); SDValue LoOps[2] = { LHSL, RHSL }; SDValue HiOps[3] = { LHSH, RHSH }; - + if (Node->getOpcode() == ISD::ADDC) { Lo = DAG.getNode(ISD::ADDC, dl, VTList, LoOps, 2); HiOps[2] = Lo.getValue(1); @@ -7119,11 +7119,11 @@ SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); SDValue LoOps[3] = { LHSL, RHSL, Node->getOperand(2) }; SDValue HiOps[3] = { LHSH, RHSH }; - + Lo = DAG.getNode(Node->getOpcode(), dl, VTList, LoOps, 3); HiOps[2] = Lo.getValue(1); Hi = DAG.getNode(Node->getOpcode(), dl, VTList, HiOps, 3); - + // Remember that we legalized the flag. AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1))); break; @@ -7137,7 +7137,7 @@ break; } } - + bool HasMULHS = TLI.isOperationLegalOrCustom(ISD::MULHS, NVT); bool HasMULHU = TLI.isOperationLegalOrCustom(ISD::MULHU, NVT); bool HasSMUL_LOHI = TLI.isOperationLegalOrCustom(ISD::SMUL_LOHI, NVT); @@ -7276,7 +7276,7 @@ } case ISD::FSQRT: case ISD::FSIN: - case ISD::FCOS: + case ISD::FCOS: case ISD::FLOG: case ISD::FLOG2: case ISD::FLOG10: @@ -7420,19 +7420,19 @@ if (VT == MVT::ppcf128 && SrcVT == MVT::i32) { static const uint64_t zero = 0; if (isSigned) { - Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, dl, MVT::f64, + Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, dl, MVT::f64, Node->getOperand(0))); Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); } else { static const uint64_t TwoE32[] = { 0x41f0000000000000LL, 0 }; - Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, dl, MVT::f64, + Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, dl, MVT::f64, Node->getOperand(0))); Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64); Hi = DAG.getNode(ISD::BUILD_PAIR, dl, VT, Lo, Hi); // X>=0 ? {(f64)x, 0} : {(f64)x, 0} + 2^32 ExpandOp(DAG.getNode(ISD::SELECT_CC, dl, MVT::ppcf128, Node->getOperand(0), - DAG.getConstant(0, MVT::i32), + DAG.getConstant(0, MVT::i32), DAG.getNode(ISD::FADD, dl, MVT::ppcf128, Hi, DAG.getConstantFP( APFloat(APInt(128, 2, TwoE32)), @@ -7452,7 +7452,7 @@ // x>=0 ? (ppcf128)(i64)x : (ppcf128)(i64)x + 2^64 ExpandOp(DAG.getNode(ISD::SELECT_CC, dl, MVT::ppcf128, Node->getOperand(0), - DAG.getConstant(0, MVT::i64), + DAG.getConstant(0, MVT::i64), DAG.getNode(ISD::FADD, dl, MVT::ppcf128, Hi, DAG.getConstantFP( APFloat(APInt(128, 2, TwoE64)), @@ -7514,9 +7514,9 @@ Hi = I->second.second; return; } - + switch (Node->getOpcode()) { - default: + default: #ifndef NDEBUG Node->dump(&DAG); #endif @@ -7553,8 +7553,8 @@ SDValue Mask = Node->getOperand(2); SmallVector Ops; MVT PtrVT = TLI.getPointerTy(); - - // Insert all of the elements from the input that are needed. We use + + // Insert all of the elements from the input that are needed. We use // buildvector of extractelement here because the input vectors will have // to be legalized, so this makes the code simpler. for (unsigned i = 0; i != NewNumElts_Lo; ++i) { @@ -7574,7 +7574,7 @@ } Lo = DAG.getNode(ISD::BUILD_VECTOR, dl, NewVT_Lo, &Ops[0], Ops.size()); Ops.clear(); - + for (unsigned i = NewNumElts_Lo; i != NumElements; ++i) { SDValue IdxNode = Mask.getOperand(i); if (IdxNode.getOpcode() == ISD::UNDEF) { @@ -7594,11 +7594,11 @@ break; } case ISD::BUILD_VECTOR: { - SmallVector LoOps(Node->op_begin(), + SmallVector LoOps(Node->op_begin(), Node->op_begin()+NewNumElts_Lo); Lo = DAG.getNode(ISD::BUILD_VECTOR, dl, NewVT_Lo, &LoOps[0], LoOps.size()); - SmallVector HiOps(Node->op_begin()+NewNumElts_Lo, + SmallVector HiOps(Node->op_begin()+NewNumElts_Lo, Node->op_end()); Hi = DAG.getNode(ISD::BUILD_VECTOR, dl, NewVT_Hi, &HiOps[0], HiOps.size()); break; @@ -7612,12 +7612,12 @@ } else { SmallVector LoOps(Node->op_begin(), Node->op_begin()+NewNumSubvectors); - Lo = DAG.getNode(ISD::CONCAT_VECTORS, dl, NewVT_Lo, + Lo = DAG.getNode(ISD::CONCAT_VECTORS, dl, NewVT_Lo, &LoOps[0], LoOps.size()); SmallVector HiOps(Node->op_begin()+NewNumSubvectors, Node->op_end()); - Hi = DAG.getNode(ISD::CONCAT_VECTORS, dl, NewVT_Hi, + Hi = DAG.getNode(ISD::CONCAT_VECTORS, dl, NewVT_Hi, &HiOps[0], HiOps.size()); } break; @@ -7630,7 +7630,7 @@ Lo = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, NewVT_Lo, Vec, Idx); ConstantSDNode *CIdx = dyn_cast(Idx); if (CIdx) { - Hi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, NewVT_Hi, Vec, + Hi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, NewVT_Hi, Vec, DAG.getConstant(CIdx->getZExtValue() + NewNumElts_Lo, IdxVT)); } else { @@ -7664,15 +7664,15 @@ SDValue CondLHS = Node->getOperand(0); SDValue CondRHS = Node->getOperand(1); SDValue CondCode = Node->getOperand(4); - + SDValue LL, LH, RL, RH; SplitVectorOp(Node->getOperand(2), LL, LH); SplitVectorOp(Node->getOperand(3), RL, RH); - + // Handle a simple select with vector operands. Lo = DAG.getNode(ISD::SELECT_CC, dl, NewVT_Lo, CondLHS, CondRHS, LL, RL, CondCode); - Hi = DAG.getNode(ISD::SELECT_CC, dl, NewVT_Hi, CondLHS, CondRHS, + Hi = DAG.getNode(ISD::SELECT_CC, dl, NewVT_Hi, CondLHS, CondRHS, LH, RH, CondCode); break; } @@ -7706,7 +7706,7 @@ SDValue LL, LH, RL, RH; SplitVectorOp(Node->getOperand(0), LL, LH); SplitVectorOp(Node->getOperand(1), RL, RH); - + Lo = DAG.getNode(Node->getOpcode(), dl, NewVT_Lo, LL, RL); Hi = DAG.getNode(Node->getOpcode(), dl, NewVT_Hi, LH, RH); break; @@ -7796,12 +7796,12 @@ Hi = DAG.getLoad(ISD::UNINDEXED, dl, ExtType, NewVT_Hi, Ch, Ptr, Offset, SV, SVOffset, MemNewVT_Hi, isVolatile, Alignment); - + // Build a factor node to remember that this load is independent of the // other one. SDValue TF = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo.getValue(1), Hi.getValue(1)); - + // Remember that we legalized the chain. AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); break; @@ -7833,9 +7833,9 @@ break; } } - + // Remember in a map if the values will be reused later. - bool isNew = + bool isNew = SplitNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; assert(isNew && "Value already split?!?"); isNew = isNew; @@ -7851,14 +7851,14 @@ DebugLoc dl = Node->getDebugLoc(); MVT NewVT = Op.getValueType().getVectorElementType(); assert(Op.getValueType().getVectorNumElements() == 1); - + // See if we already scalarized it. std::map::iterator I = ScalarizedNodes.find(Op); if (I != ScalarizedNodes.end()) return I->second; - + SDValue Result; switch (Node->getOpcode()) { - default: + default: #ifndef NDEBUG Node->dump(&DAG); cerr << "\n"; #endif @@ -7880,7 +7880,7 @@ case ISD::OR: case ISD::XOR: Result = DAG.getNode(Node->getOpcode(), dl, - NewVT, + NewVT, ScalarizeVectorOp(Node->getOperand(0)), ScalarizeVectorOp(Node->getOperand(1))); break; @@ -7904,7 +7904,7 @@ case ISD::TRUNCATE: case ISD::FP_EXTEND: Result = DAG.getNode(Node->getOpcode(), dl, - NewVT, + NewVT, ScalarizeVectorOp(Node->getOperand(0))); break; case ISD::CONVERT_RNDSAT: { @@ -7920,7 +7920,7 @@ case ISD::FPOWI: case ISD::FP_ROUND: Result = DAG.getNode(Node->getOpcode(), dl, - NewVT, + NewVT, ScalarizeVectorOp(Node->getOperand(0)), Node->getOperand(1)); break; @@ -7937,7 +7937,7 @@ assert(LD->isUnindexed() && "Indexed vector loads are not supported yet!"); SDValue Offset = DAG.getUNDEF(Ptr.getValueType()); - + Result = DAG.getLoad(ISD::UNINDEXED, dl, ExtType, NewVT, Ch, Ptr, Offset, SV, SVOffset, MemoryVT.getVectorElementType(), @@ -7969,7 +7969,7 @@ break; } case ISD::EXTRACT_SUBVECTOR: - Result = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, NewVT, + Result = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, NewVT, Node->getOperand(0), Node->getOperand(1)); break; case ISD::BIT_CONVERT: { @@ -7985,7 +7985,7 @@ ScalarizeVectorOp(Op.getOperand(2))); break; case ISD::SELECT_CC: - Result = DAG.getNode(ISD::SELECT_CC, dl, NewVT, Node->getOperand(0), + Result = DAG.getNode(ISD::SELECT_CC, dl, NewVT, Node->getOperand(0), Node->getOperand(1), ScalarizeVectorOp(Op.getOperand(2)), ScalarizeVectorOp(Op.getOperand(3)), @@ -8016,7 +8016,7 @@ SDValue SelectionDAGLegalize::WidenVectorOp(SDValue Op, MVT WidenVT) { std::map::iterator I = WidenNodes.find(Op); if (I != WidenNodes.end()) return I->second; - + MVT VT = Op.getValueType(); assert(VT.isVector() && "Cannot widen non-vector type!"); @@ -8040,7 +8040,7 @@ // code to pack/unpack the results. It is the function that calls widen // that is responsible for seeing this doesn't happen. switch (Node->getOpcode()) { - default: + default: #ifndef NDEBUG Node->dump(&DAG); #endif @@ -8066,8 +8066,8 @@ for (unsigned i = NumElts; i < NewNumElts; ++i) { NewOps.push_back(DAG.getUNDEF(EVT)); } - Result = DAG.getNode(ISD::BUILD_VECTOR, dl, WidenVT, - &NewOps[0], NewOps.size()); + Result = DAG.getNode(ISD::BUILD_VECTOR, dl, WidenVT, + &NewOps[0], NewOps.size()); break; } case ISD::INSERT_VECTOR_ELT: { @@ -8097,17 +8097,17 @@ else { NewOps.push_back(DAG.getConstant(Idx + NewNumElts - NumElts, PermOp.getOperand(i).getValueType())); - } + } } } for (unsigned i = NumElts; i < NewNumElts; ++i) { NewOps.push_back(DAG.getUNDEF(PVT)); } - - SDValue Tmp3 = DAG.getNode(ISD::BUILD_VECTOR, dl, + + SDValue Tmp3 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::getVectorVT(PVT, NewOps.size()), - &NewOps[0], NewOps.size()); - + &NewOps[0], NewOps.size()); + Result = DAG.getNode(ISD::VECTOR_SHUFFLE, dl, WidenVT, Tmp1, Tmp2, Tmp3); break; } @@ -8128,7 +8128,7 @@ // Converts between two different types so we need to determine // the correct widen type for the input operand. MVT InVT = Tmp1.getValueType(); - unsigned WidenSize = WidenVT.getSizeInBits(); + unsigned WidenSize = WidenVT.getSizeInBits(); if (InVT.isVector()) { MVT InEltVT = InVT.getVectorElementType(); unsigned InEltSize = InEltVT.getSizeInBits(); @@ -8221,7 +8221,7 @@ break; } case ISD::FPOW: - case ISD::FPOWI: + case ISD::FPOWI: case ISD::ADD: case ISD::SUB: case ISD::MUL: @@ -8337,7 +8337,7 @@ Result = DAG.getNode(Node->getOpcode(), dl, WidenVT, Cond1, Tmp1, Tmp2); break; } - + case ISD::SELECT_CC: { // Determine new condition widen type and widen SDValue Cond1 = Node->getOperand(0); @@ -8395,7 +8395,7 @@ } // end switch (Node->getOpcode()) - assert(Result.getNode() && "Didn't set a result!"); + assert(Result.getNode() && "Didn't set a result!"); if (Result != Op) Result = LegalizeOp(Result); @@ -8455,7 +8455,7 @@ isVolatile, Alignment); SDValue VecOp = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VecEVT, LdOp); LdChain.push_back(LdOp.getValue(1)); - + // Check if we can load the element with one instruction if (LdWidth == EVTWidth) { return DAG.getNode(ISD::BIT_CONVERT, dl, ResType, VecOp); @@ -8465,7 +8465,7 @@ unsigned Idx = 1; LdWidth -= EVTWidth; unsigned Offset = 0; - + while (LdWidth > 0) { unsigned Increment = EVTWidth / 8; Offset += Increment; @@ -8482,14 +8482,14 @@ Idx = Idx * (oEVTWidth/EVTWidth); VecOp = DAG.getNode(ISD::BIT_CONVERT, dl, VecEVT, VecOp); } - + SDValue LdOp = DAG.getLoad(EVT, dl, Chain, BasePtr, SV, SVOffset+Offset, isVolatile, MinAlign(Alignment, Offset)); LdChain.push_back(LdOp.getValue(1)); VecOp = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VecEVT, VecOp, LdOp, DAG.getIntPtrConstant(Idx++)); - + LdWidth -= EVTWidth; } @@ -8505,14 +8505,14 @@ // to memory mapping is strange (e.g., vector elements are not // stored in some sequential order). - // It must be true that the widen vector type is bigger than where + // It must be true that the widen vector type is bigger than where // we need to load from. LoadSDNode *LD = cast(Op.getNode()); MVT LdVT = LD->getMemoryVT(); DebugLoc dl = LD->getDebugLoc(); assert(LdVT.isVector() && NVT.isVector()); assert(LdVT.getVectorElementType() == NVT.getVectorElementType()); - + // Load information SDValue Chain = LD->getChain(); SDValue BasePtr = LD->getBasePtr(); @@ -8521,7 +8521,7 @@ bool isVolatile = LD->isVolatile(); const Value *SV = LD->getSrcValue(); unsigned int LdWidth = LdVT.getSizeInBits(); - + // Load value as a large register SDValueVector LdChain; Result = genWidenVectorLoads(LdChain, Chain, BasePtr, SV, SVOffset, @@ -8532,7 +8532,7 @@ return true; } else { - TFOp=DAG.getNode(ISD::TokenFactor, dl, MVT::Other, + TFOp=DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &LdChain[0], LdChain.size()); return false; } @@ -8552,7 +8552,7 @@ // Breaks the stores into a series of power of 2 width stores. For any // width, we convert the vector to the vector of element size that we // want to store. This avoids requiring a stack convert. - + // Find a width of the element type we can store with MVT VVT = ValOp.getValueType(); MVT EVT, VecEVT; @@ -8571,17 +8571,17 @@ if (StWidth == EVTWidth) { return; } - + unsigned Idx = 1; StWidth -= EVTWidth; unsigned Offset = 0; - + while (StWidth > 0) { unsigned Increment = EVTWidth / 8; Offset += Increment; BasePtr = DAG.getNode(ISD::ADD, dl, BasePtr.getValueType(), BasePtr, DAG.getIntPtrConstant(Increment)); - + if (StWidth < EVTWidth) { // Our current type we are using is too large, use a smaller size by // using a smaller power of 2 @@ -8592,7 +8592,7 @@ Idx = Idx * (oEVTWidth/EVTWidth); VecOp = DAG.getNode(ISD::BIT_CONVERT, dl, VecEVT, VecOp); } - + EOp = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EVT, VecOp, DAG.getIntPtrConstant(Idx++)); StChain.push_back(DAG.getStore(Chain, dl, EOp, BasePtr, SV, @@ -8611,7 +8611,7 @@ // be stored as a word). This will not work when a vector register // to memory mapping is strange (e.g., vector elements are not // stored in some sequential order). - + MVT StVT = ST->getMemoryVT(); SDValue ValOp = ST->getValue(); DebugLoc dl = ST->getDebugLoc(); @@ -8620,7 +8620,7 @@ std::map::iterator I = WidenNodes.find(ValOp); if (I != WidenNodes.end()) ValOp = I->second; - + MVT VVT = ValOp.getValueType(); // It must be true that we the widen vector type is bigger than where @@ -8636,7 +8636,7 @@ ST->isVolatile(), ValOp, StVT.getSizeInBits(), dl); if (StChain.size() == 1) return StChain[0]; - else + else return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &StChain[0], StChain.size()); } Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp?rev=64827&r1=64826&r2=64827&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp (original) +++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp Tue Feb 17 16:15:04 2009 @@ -150,7 +150,7 @@ SDValue DAGTypeLegalizer::PromoteIntRes_Atomic2(AtomicSDNode *N) { SDValue Op2 = GetPromotedInteger(N->getOperand(2)); SDValue Op3 = GetPromotedInteger(N->getOperand(3)); - SDValue Res = DAG.getAtomic(N->getOpcode(), N->getDebugLoc(), + SDValue Res = DAG.getAtomic(N->getOpcode(), N->getDebugLoc(), N->getMemoryVT(), N->getChain(), N->getBasePtr(), Op2, Op3, N->getSrcValue(), N->getAlignment()); // Legalized the chain result - switch anything that used the old chain to @@ -2067,7 +2067,7 @@ } NewLHS = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi.getValueType()), - LHSHi, RHSHi, ISD::SETEQ, false, + LHSHi, RHSHi, ISD::SETEQ, false, DagCombineInfo, dl); if (!NewLHS.getNode()) NewLHS = DAG.getSetCC(dl, TLI.getSetCCResultType(LHSHi.getValueType()), Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp?rev=64827&r1=64826&r2=64827&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp (original) +++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp Tue Feb 17 16:15:04 2009 @@ -126,7 +126,7 @@ SDValue DAGTypeLegalizer::ScalarizeVecRes_CONVERT_RNDSAT(SDNode *N) { MVT NewVT = N->getValueType(0).getVectorElementType(); SDValue Op0 = GetScalarizedVector(N->getOperand(0)); - return DAG.getConvertRndSat(NewVT, N->getDebugLoc(), + return DAG.getConvertRndSat(NewVT, N->getDebugLoc(), Op0, DAG.getValueType(NewVT), DAG.getValueType(Op0.getValueType()), N->getOperand(3), @@ -544,7 +544,7 @@ SDValue SatOp = N->getOperand(4); ISD::CvtCode CvtCode = cast(N)->getCvtCode(); - Lo = DAG.getConvertRndSat(LoVT, dl, VLo, DTyOpLo, STyOpLo, RndOp, SatOp, + Lo = DAG.getConvertRndSat(LoVT, dl, VLo, DTyOpLo, STyOpLo, RndOp, SatOp, CvtCode); Hi = DAG.getConvertRndSat(HiVT, dl, VHi, DTyOpHi, STyOpHi, RndOp, SatOp, CvtCode); @@ -1227,7 +1227,7 @@ if (InVTNumElts % WidenNumElts == 0) { // Extract the input and convert the shorten input vector. return DAG.getNode(Opcode, dl, WidenVT, - DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, InWidenVT, + DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, InWidenVT, InOp, DAG.getIntPtrConstant(0))); } } @@ -1953,7 +1953,7 @@ if (StChain.size() == 1) return StChain[0]; else - return DAG.getNode(ISD::TokenFactor, dl, + return DAG.getNode(ISD::TokenFactor, dl, MVT::Other,&StChain[0],StChain.size()); } Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=64827&r1=64826&r2=64827&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original) +++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Tue Feb 17 16:15:04 2009 @@ -77,12 +77,12 @@ bool ConstantFPSDNode::isValueValidForType(MVT VT, const APFloat& Val) { assert(VT.isFloatingPoint() && "Can only convert between FP types"); - + // PPC long double cannot be converted to any other type. if (VT == MVT::ppcf128 || &Val.getSemantics() == &APFloat::PPCDoubleDouble) return false; - + // convert modifies in place, so make a copy. APFloat Val2 = APFloat(Val); bool losesInfo; @@ -101,18 +101,18 @@ // Look through a bit convert. if (N->getOpcode() == ISD::BIT_CONVERT) N = N->getOperand(0).getNode(); - + if (N->getOpcode() != ISD::BUILD_VECTOR) return false; - + unsigned i = 0, e = N->getNumOperands(); - + // Skip over all of the undef values. while (i != e && N->getOperand(i).getOpcode() == ISD::UNDEF) ++i; - + // Do not accept an all-undef vector. if (i == e) return false; - + // Do not accept build_vectors that aren't all constants or which have non-~0 // elements. SDValue NotZero = N->getOperand(i); @@ -125,7 +125,7 @@ return false; } else return false; - + // Okay, we have at least one ~0 value, check to see if the rest match or are // undefs. for (++i; i != e; ++i) @@ -142,18 +142,18 @@ // Look through a bit convert. if (N->getOpcode() == ISD::BIT_CONVERT) N = N->getOperand(0).getNode(); - + if (N->getOpcode() != ISD::BUILD_VECTOR) return false; - + unsigned i = 0, e = N->getNumOperands(); - + // Skip over all of the undef values. while (i != e && N->getOperand(i).getOpcode() == ISD::UNDEF) ++i; - + // Do not accept an all-undef vector. if (i == e) return false; - + // Do not accept build_vectors that aren't all constants or which have non-~0 // elements. SDValue Zero = N->getOperand(i); @@ -165,7 +165,7 @@ return false; } else return false; - + // Okay, we have at least one ~0 value, check to see if the rest match or are // undefs. for (++i; i != e; ++i) @@ -271,11 +271,11 @@ // care about orderedness, and is true when ordered. if (Op > ISD::SETTRUE2) Op &= ~16; // Clear the U bit if the N bit is set. - + // Canonicalize illegal integer setcc's. if (isInteger && Op == ISD::SETUNE) // e.g. SETUGT | SETULT Op = ISD::SETNE; - + return ISD::CondCode(Op); } @@ -291,7 +291,7 @@ // Combine all of the condition bits. ISD::CondCode Result = ISD::CondCode(Op1 & Op2); - + // Canonicalize illegal integer setcc's. if (isInteger) { switch (Result) { @@ -303,7 +303,7 @@ case ISD::SETOGT: Result = ISD::SETUGT ; break; // SETUGT & SETNE } } - + return Result; } @@ -324,7 +324,7 @@ /// AddNodeIDValueTypes - Value type lists are intern'd so we can represent them /// solely with their pointer. static void AddNodeIDValueTypes(FoldingSetNodeID &ID, SDVTList VTList) { - ID.AddPointer(VTList.VTs); + ID.AddPointer(VTList.VTs); } /// AddNodeIDOperands - Various routines for adding operands to the NodeID data. @@ -348,7 +348,7 @@ } static void AddNodeIDNode(FoldingSetNodeID &ID, - unsigned short OpC, SDVTList VTList, + unsigned short OpC, SDVTList VTList, const SDValue *OpList, unsigned N) { AddNodeIDOpcode(ID, OpC); AddNodeIDValueTypes(ID, VTList); @@ -524,14 +524,14 @@ HandleSDNode Dummy(getRoot()); SmallVector DeadNodes; - + // Add all obviously-dead nodes to the DeadNodes worklist. for (allnodes_iterator I = allnodes_begin(), E = allnodes_end(); I != E; ++I) if (I->use_empty()) DeadNodes.push_back(I); RemoveDeadNodes(DeadNodes); - + // If the root changed (e.g. it was a dead load, update the root). setRoot(Dummy.getValue()); } @@ -545,10 +545,10 @@ // worklist. while (!DeadNodes.empty()) { SDNode *N = DeadNodes.pop_back_val(); - + if (UpdateListener) UpdateListener->NodeDeleted(N, 0); - + // Take the node out of the appropriate CSE map. RemoveNodeFromCSEMaps(N); @@ -577,7 +577,7 @@ // First take this out of the appropriate CSE map. RemoveNodeFromCSEMaps(N); - // Finally, remove uses due to operands of this node, remove from the + // Finally, remove uses due to operands of this node, remove from the // AllNodes list, and delete the node. DeleteNodeNotInCSEMaps(N); } @@ -595,7 +595,7 @@ void SelectionDAG::DeallocateNode(SDNode *N) { if (N->OperandsNeedDelete) delete[] N->OperandList; - + // Set the opcode to DELETED_NODE to help catch bugs when node // memory is reallocated. N->NodeType = ISD::DELETED_NODE; @@ -643,7 +643,7 @@ break; } #ifndef NDEBUG - // Verify that the node was actually in one of the CSE maps, unless it has a + // Verify that the node was actually in one of the CSE maps, unless it has a // flag result (which cannot be CSE'd) or is one of the special cases that are // not subject to CSE. if (!Erased && N->getValueType(N->getNumValues()-1) != MVT::Flag && @@ -675,7 +675,7 @@ ReplaceAllUsesWith(N, Existing, UpdateListener); // N is now dead. Inform the listener if it exists and delete it. - if (UpdateListener) + if (UpdateListener) UpdateListener->NodeDeleted(N, Existing); DeleteNodeNotInCSEMaps(N); return; @@ -684,12 +684,12 @@ // If the node doesn't already exist, we updated it. Inform a listener if // it exists. - if (UpdateListener) + if (UpdateListener) UpdateListener->NodeUpdated(N); } /// FindModifiedNodeSlot - Find a slot for the specified node if its operands -/// were replaced with those specified. If this node is never memoized, +/// were replaced with those specified. If this node is never memoized, /// return null, otherwise return a pointer to the slot it would take. If a /// node already exists with these operands, the slot will be non-null. SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, SDValue Op, @@ -705,10 +705,10 @@ } /// FindModifiedNodeSlot - Find a slot for the specified node if its operands -/// were replaced with those specified. If this node is never memoized, +/// were replaced with those specified. If this node is never memoized, /// return null, otherwise return a pointer to the slot it would take. If a /// node already exists with these operands, the slot will be non-null. -SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, +SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2, void *&InsertPos) { if (doNotCSE(N)) @@ -723,10 +723,10 @@ /// FindModifiedNodeSlot - Find a slot for the specified node if its operands -/// were replaced with those specified. If this node is never memoized, +/// were replaced with those specified. If this node is never memoized, /// return null, otherwise return a pointer to the slot it would take. If a /// node already exists with these operands, the slot will be non-null. -SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, +SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, const SDValue *Ops,unsigned NumOps, void *&InsertPos) { if (doNotCSE(N)) @@ -910,7 +910,7 @@ SDValue SelectionDAG::getConstantFP(const ConstantFP& V, MVT VT, bool isTarget){ assert(VT.isFloatingPoint() && "Cannot create integer FP constant!"); - + MVT EltVT = VT.isVector() ? VT.getVectorElementType() : VT; @@ -1259,7 +1259,7 @@ const Type *Ty = VT.getTypeForMVT(); unsigned StackAlign = std::max((unsigned)TLI.getTargetData()->getPrefTypeAlignment(Ty), minAlign); - + int FrameIdx = FrameInfo->CreateStackObject(ByteSize, StackAlign); return getFrameIndex(FrameIdx, TLI.getPointerTy()); } @@ -1289,7 +1289,7 @@ case ISD::SETFALSE2: return getConstant(0, VT); case ISD::SETTRUE: case ISD::SETTRUE2: return getConstant(1, VT); - + case ISD::SETOEQ: case ISD::SETOGT: case ISD::SETOGE: @@ -1303,12 +1303,12 @@ assert(!N1.getValueType().isInteger() && "Illegal setcc for integer!"); break; } - + if (ConstantSDNode *N2C = dyn_cast(N2.getNode())) { const APInt &C2 = N2C->getAPIntValue(); if (ConstantSDNode *N1C = dyn_cast(N1.getNode())) { const APInt &C1 = N1C->getAPIntValue(); - + switch (Cond) { default: assert(0 && "Unknown integer setcc!"); case ISD::SETEQ: return getConstant(C1 == C2, VT); @@ -1333,29 +1333,29 @@ APFloat::cmpResult R = N1C->getValueAPF().compare(N2C->getValueAPF()); switch (Cond) { default: break; - case ISD::SETEQ: if (R==APFloat::cmpUnordered) + case ISD::SETEQ: if (R==APFloat::cmpUnordered) return getUNDEF(VT); // fall through case ISD::SETOEQ: return getConstant(R==APFloat::cmpEqual, VT); - case ISD::SETNE: if (R==APFloat::cmpUnordered) + case ISD::SETNE: if (R==APFloat::cmpUnordered) return getUNDEF(VT); // fall through case ISD::SETONE: return getConstant(R==APFloat::cmpGreaterThan || R==APFloat::cmpLessThan, VT); - case ISD::SETLT: if (R==APFloat::cmpUnordered) + case ISD::SETLT: if (R==APFloat::cmpUnordered) return getUNDEF(VT); // fall through case ISD::SETOLT: return getConstant(R==APFloat::cmpLessThan, VT); - case ISD::SETGT: if (R==APFloat::cmpUnordered) + case ISD::SETGT: if (R==APFloat::cmpUnordered) return getUNDEF(VT); // fall through case ISD::SETOGT: return getConstant(R==APFloat::cmpGreaterThan, VT); - case ISD::SETLE: if (R==APFloat::cmpUnordered) + case ISD::SETLE: if (R==APFloat::cmpUnordered) return getUNDEF(VT); // fall through case ISD::SETOLE: return getConstant(R==APFloat::cmpLessThan || R==APFloat::cmpEqual, VT); - case ISD::SETGE: if (R==APFloat::cmpUnordered) + case ISD::SETGE: if (R==APFloat::cmpUnordered) return getUNDEF(VT); // fall through case ISD::SETOGE: return getConstant(R==APFloat::cmpGreaterThan || @@ -1392,11 +1392,11 @@ /// MaskedValueIsZero - Return true if 'V & Mask' is known to be zero. We use /// this predicate to simplify operations downstream. Mask is known to be zero /// for bits that V cannot have. -bool SelectionDAG::MaskedValueIsZero(SDValue Op, const APInt &Mask, +bool SelectionDAG::MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth) const { APInt KnownZero, KnownOne; ComputeMaskedBits(Op, Mask, KnownZero, KnownOne, Depth); - assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); + assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); return (KnownZero & Mask) == Mask; } @@ -1404,7 +1404,7 @@ /// known to be either zero or one and return them in the KnownZero/KnownOne /// bitsets. This code only analyzes bits in Mask, in order to short-circuit /// processing. -void SelectionDAG::ComputeMaskedBits(SDValue Op, const APInt &Mask, +void SelectionDAG::ComputeMaskedBits(SDValue Op, const APInt &Mask, APInt &KnownZero, APInt &KnownOne, unsigned Depth) const { unsigned BitWidth = Mask.getBitWidth(); @@ -1414,7 +1414,7 @@ KnownZero = KnownOne = APInt(BitWidth, 0); // Don't know anything. if (Depth == 6 || Mask == 0) return; // Limit search depth. - + APInt KnownZero2, KnownOne2; switch (Op.getOpcode()) { @@ -1428,8 +1428,8 @@ ComputeMaskedBits(Op.getOperand(1), Mask, KnownZero, KnownOne, Depth+1); ComputeMaskedBits(Op.getOperand(0), Mask & ~KnownZero, KnownZero2, KnownOne2, Depth+1); - assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); - assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); + assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); + assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); // Output known-1 bits are only known if set in both the LHS & RHS. KnownOne &= KnownOne2; @@ -1440,9 +1440,9 @@ ComputeMaskedBits(Op.getOperand(1), Mask, KnownZero, KnownOne, Depth+1); ComputeMaskedBits(Op.getOperand(0), Mask & ~KnownOne, KnownZero2, KnownOne2, Depth+1); - assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); - assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); - + assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); + assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); + // Output known-0 bits are only known if clear in both the LHS & RHS. KnownZero &= KnownZero2; // Output known-1 are known to be set if set in either the LHS | RHS. @@ -1451,9 +1451,9 @@ case ISD::XOR: { ComputeMaskedBits(Op.getOperand(1), Mask, KnownZero, KnownOne, Depth+1); ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero2, KnownOne2, Depth+1); - assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); - assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); - + assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); + assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); + // Output known-0 bits are known if clear or set in both the LHS & RHS. APInt KnownZeroOut = (KnownZero & KnownZero2) | (KnownOne & KnownOne2); // Output known-1 are known to be set if set in only one of the LHS, RHS. @@ -1510,9 +1510,9 @@ case ISD::SELECT: ComputeMaskedBits(Op.getOperand(2), Mask, KnownZero, KnownOne, Depth+1); ComputeMaskedBits(Op.getOperand(1), Mask, KnownZero2, KnownOne2, Depth+1); - assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); - assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); - + assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); + assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); + // Only known if known in both the LHS and RHS. KnownOne &= KnownOne2; KnownZero &= KnownZero2; @@ -1520,9 +1520,9 @@ case ISD::SELECT_CC: ComputeMaskedBits(Op.getOperand(3), Mask, KnownZero, KnownOne, Depth+1); ComputeMaskedBits(Op.getOperand(2), Mask, KnownZero2, KnownOne2, Depth+1); - assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); - assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); - + assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); + assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); + // Only known if known in both the LHS and RHS. KnownOne &= KnownOne2; KnownZero &= KnownZero2; @@ -1553,7 +1553,7 @@ ComputeMaskedBits(Op.getOperand(0), Mask.lshr(ShAmt), KnownZero, KnownOne, Depth+1); - assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); + assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); KnownZero <<= ShAmt; KnownOne <<= ShAmt; // low bits known zero. @@ -1571,7 +1571,7 @@ ComputeMaskedBits(Op.getOperand(0), (Mask << ShAmt), KnownZero, KnownOne, Depth+1); - assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); + assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); KnownZero = KnownZero.lshr(ShAmt); KnownOne = KnownOne.lshr(ShAmt); @@ -1593,17 +1593,17 @@ APInt HighBits = APInt::getHighBitsSet(BitWidth, ShAmt) & Mask; if (HighBits.getBoolValue()) InDemandedMask |= APInt::getSignBit(BitWidth); - + ComputeMaskedBits(Op.getOperand(0), InDemandedMask, KnownZero, KnownOne, Depth+1); - assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); + assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); KnownZero = KnownZero.lshr(ShAmt); KnownOne = KnownOne.lshr(ShAmt); - + // Handle the sign bits. APInt SignBit = APInt::getSignBit(BitWidth); SignBit = SignBit.lshr(ShAmt); // Adjust to where it is now in the mask. - + if (KnownZero.intersects(SignBit)) { KnownZero |= HighBits; // New bits are known zero. } else if (KnownOne.intersects(SignBit)) { @@ -1614,24 +1614,24 @@ case ISD::SIGN_EXTEND_INREG: { MVT EVT = cast(Op.getOperand(1))->getVT(); unsigned EBits = EVT.getSizeInBits(); - - // Sign extension. Compute the demanded bits in the result that are not + + // Sign extension. Compute the demanded bits in the result that are not // present in the input. APInt NewBits = APInt::getHighBitsSet(BitWidth, BitWidth - EBits) & Mask; APInt InSignBit = APInt::getSignBit(EBits); APInt InputDemandedBits = Mask & APInt::getLowBitsSet(BitWidth, EBits); - + // If the sign extended bits are demanded, we know that the sign // bit is demanded. InSignBit.zext(BitWidth); if (NewBits.getBoolValue()) InputDemandedBits |= InSignBit; - + ComputeMaskedBits(Op.getOperand(0), InputDemandedBits, KnownZero, KnownOne, Depth+1); - assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); - + assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); + // If the sign bit of the input is known set or clear, then we know the // top bits of the result. if (KnownZero.intersects(InSignBit)) { // Input sign bit known clear @@ -1738,7 +1738,7 @@ KnownZero.zext(InBits); KnownOne.zext(InBits); ComputeMaskedBits(Op.getOperand(0), InMask, KnownZero, KnownOne, Depth+1); - assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); + assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); KnownZero.trunc(BitWidth); KnownOne.trunc(BitWidth); break; @@ -1746,7 +1746,7 @@ case ISD::AssertZext: { MVT VT = cast(Op.getOperand(1))->getVT(); APInt InMask = APInt::getLowBitsSet(BitWidth, VT.getSizeInBits()); - ComputeMaskedBits(Op.getOperand(0), Mask & InMask, KnownZero, + ComputeMaskedBits(Op.getOperand(0), Mask & InMask, KnownZero, KnownOne, Depth+1); KnownZero |= (~InMask) & Mask; return; @@ -1755,7 +1755,7 @@ // All bits are zero except the low bit. KnownZero = APInt::getHighBitsSet(BitWidth, BitWidth - 1); return; - + case ISD::SUB: { if (ConstantSDNode *CLHS = dyn_cast(Op.getOperand(0))) { // We know that the top bits of C-X are clear if X contains less bits @@ -1786,11 +1786,11 @@ // low 3 bits clear. APInt Mask2 = APInt::getLowBitsSet(BitWidth, Mask.countTrailingOnes()); ComputeMaskedBits(Op.getOperand(0), Mask2, KnownZero2, KnownOne2, Depth+1); - assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); + assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); unsigned KnownZeroOut = KnownZero2.countTrailingOnes(); ComputeMaskedBits(Op.getOperand(1), Mask2, KnownZero2, KnownOne2, Depth+1); - assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); + assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); KnownZeroOut = std::min(KnownZeroOut, KnownZero2.countTrailingOnes()); @@ -1867,7 +1867,7 @@ unsigned VTBits = VT.getSizeInBits(); unsigned Tmp, Tmp2; unsigned FirstAnswer = 1; - + if (Depth == 6) return 1; // Limit search depth. @@ -1879,26 +1879,26 @@ case ISD::AssertZext: Tmp = cast(Op.getOperand(1))->getVT().getSizeInBits(); return VTBits-Tmp; - + case ISD::Constant: { const APInt &Val = cast(Op)->getAPIntValue(); // If negative, return # leading ones. if (Val.isNegative()) return Val.countLeadingOnes(); - + // Return # leading zeros. return Val.countLeadingZeros(); } - + case ISD::SIGN_EXTEND: Tmp = VTBits-Op.getOperand(0).getValueType().getSizeInBits(); return ComputeNumSignBits(Op.getOperand(0), Depth+1) + Tmp; - + case ISD::SIGN_EXTEND_INREG: // Max of the input and what this extends. Tmp = cast(Op.getOperand(1))->getVT().getSizeInBits(); Tmp = VTBits-Tmp+1; - + Tmp2 = ComputeNumSignBits(Op.getOperand(0), Depth+1); return std::max(Tmp, Tmp2); @@ -1958,7 +1958,7 @@ case ISD::ROTR: if (ConstantSDNode *C = dyn_cast(Op.getOperand(1))) { unsigned RotAmt = C->getZExtValue() & (VTBits-1); - + // Handle rotate right by N like a rotate left by 32-N. if (Op.getOpcode() == ISD::ROTR) RotAmt = (VTBits-RotAmt) & (VTBits-1); @@ -1974,34 +1974,34 @@ // is, at worst, one more bit than the inputs. Tmp = ComputeNumSignBits(Op.getOperand(0), Depth+1); if (Tmp == 1) return 1; // Early out. - + // Special case decrementing a value (ADD X, -1): if (ConstantSDNode *CRHS = dyn_cast(Op.getOperand(0))) if (CRHS->isAllOnesValue()) { APInt KnownZero, KnownOne; APInt Mask = APInt::getAllOnesValue(VTBits); ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1); - + // If the input is known to be 0 or 1, the output is 0/-1, which is all // sign bits set. if ((KnownZero | APInt(VTBits, 1)) == Mask) return VTBits; - + // If we are subtracting one from a positive number, there is no carry // out of the result. if (KnownZero.isNegative()) return Tmp; } - + Tmp2 = ComputeNumSignBits(Op.getOperand(1), Depth+1); if (Tmp2 == 1) return 1; return std::min(Tmp, Tmp2)-1; break; - + case ISD::SUB: Tmp2 = ComputeNumSignBits(Op.getOperand(1), Depth+1); if (Tmp2 == 1) return 1; - + // Handle NEG. if (ConstantSDNode *CLHS = dyn_cast(Op.getOperand(0))) if (CLHS->isNullValue()) { @@ -2012,15 +2012,15 @@ // sign bits set. if ((KnownZero | APInt(VTBits, 1)) == Mask) return VTBits; - + // If the input is known to be positive (the sign bit is known clear), // the output of the NEG has the same number of sign bits as the input. if (KnownZero.isNegative()) return Tmp2; - + // Otherwise, we treat this like a SUB. } - + // Sub can have at most one carry bit. Thus we know that the output // is, at worst, one more bit than the inputs. Tmp = ComputeNumSignBits(Op.getOperand(0), Depth+1); @@ -2032,7 +2032,7 @@ // case for targets like X86. break; } - + // Handle LOADX separately here. EXTLOAD case will fallthrough. if (Op.getOpcode() == ISD::LOAD) { LoadSDNode *LD = cast(Op); @@ -2050,19 +2050,19 @@ // Allow the target to implement this method for its nodes. if (Op.getOpcode() >= ISD::BUILTIN_OP_END || - Op.getOpcode() == ISD::INTRINSIC_WO_CHAIN || + Op.getOpcode() == ISD::INTRINSIC_WO_CHAIN || Op.getOpcode() == ISD::INTRINSIC_W_CHAIN || Op.getOpcode() == ISD::INTRINSIC_VOID) { unsigned NumBits = TLI.ComputeNumSignBitsForTargetNode(Op, Depth); if (NumBits > 1) FirstAnswer = std::max(FirstAnswer, NumBits); } - + // Finally, if we can prove that the top bits of the result are 0's or 1's, // use this information. APInt KnownZero, KnownOne; APInt Mask = APInt::getAllOnesValue(VTBits); ComputeMaskedBits(Op, Mask, KnownZero, KnownOne, Depth); - + if (KnownZero.isNegative()) { // sign bit is 0 Mask = KnownZero; } else if (KnownOne.isNegative()) { // sign bit is 1; @@ -2071,7 +2071,7 @@ // Nothing known. return FirstAnswer; } - + // Okay, we know that the sign bit in Mask is set. Use CLZ to determine // the number of identical bits in the top of the input value. Mask = ~Mask; @@ -2135,7 +2135,7 @@ SDNode *N = NodeAllocator.Allocate(); new (N) SDNode(Opcode, DL, SDNode::getSDVTList(VT)); CSEMap.InsertNode(N, IP); - + AllNodes.push_back(N); #ifndef NDEBUG VerifyNode(N); @@ -2164,7 +2164,7 @@ if (VT==MVT::ppcf128) break; APFloat apf = APFloat(APInt(BitWidth, 2, zero)); - (void)apf.convertFromAPInt(Val, + (void)apf.convertFromAPInt(Val, Opcode==ISD::SINT_TO_FP, APFloat::rmNearestTiesToEven); return getConstantFP(apf, VT); @@ -2259,7 +2259,7 @@ assert(Operand.getValueType().bitsLT(VT) && "Invalid zext node, dst < src!"); if (OpOpcode == ISD::ZERO_EXTEND) // (zext (zext x)) -> (zext x) - return getNode(ISD::ZERO_EXTEND, DL, VT, + return getNode(ISD::ZERO_EXTEND, DL, VT, Operand.getNode()->getOperand(0)); break; case ISD::ANY_EXTEND: @@ -2536,7 +2536,7 @@ // EXTRACT_VECTOR_ELT of an UNDEF is an UNDEF. if (N1.getOpcode() == ISD::UNDEF) return getUNDEF(VT); - + // EXTRACT_VECTOR_ELT of CONCAT_VECTORS is often formed while lowering is // expanding copies of large vectors from registers. if (N2C && @@ -2554,7 +2554,7 @@ // expanding large vector constants. if (N2C && N1.getOpcode() == ISD::BUILD_VECTOR) return N1.getOperand(N2C->getZExtValue()); - + // EXTRACT_VECTOR_ELT of INSERT_VECTOR_ELT is often formed when vector // operations are lowered to scalars. if (N1.getOpcode() == ISD::INSERT_VECTOR_ELT) { @@ -2576,7 +2576,7 @@ // EXTRACT_ELEMENT of BUILD_PAIR is often formed while legalize is expanding // 64-bit integers into 32-bit parts. Instead of building the extract of - // the BUILD_PAIR, only to have legalize rip it apart, just do it now. + // the BUILD_PAIR, only to have legalize rip it apart, just do it now. if (N1.getOpcode() == ISD::BUILD_PAIR) return N1.getOperand(N2C->getZExtValue()); @@ -2618,12 +2618,12 @@ APFloat V1 = N1CFP->getValueAPF(), V2 = N2CFP->getValueAPF(); APFloat::opStatus s; switch (Opcode) { - case ISD::FADD: + case ISD::FADD: s = V1.add(V2, APFloat::rmNearestTiesToEven); if (s != APFloat::opInvalidOp) return getConstantFP(V1, VT); break; - case ISD::FSUB: + case ISD::FSUB: s = V1.subtract(V2, APFloat::rmNearestTiesToEven); if (s!=APFloat::opInvalidOp) return getConstantFP(V1, VT); @@ -2650,7 +2650,7 @@ } } } - + // Canonicalize an UNDEF to the RHS, even over a constant. if (N1.getOpcode() == ISD::UNDEF) { if (isCommutativeBinOp(Opcode)) { @@ -2679,8 +2679,8 @@ } } } - - // Fold a bunch of operators when the RHS is undef. + + // Fold a bunch of operators when the RHS is undef. if (N2.getOpcode() == ISD::UNDEF) { switch (Opcode) { case ISD::XOR: @@ -2703,7 +2703,7 @@ case ISD::UREM: case ISD::SREM: return N2; // fold op(arg1, undef) -> undef - case ISD::MUL: + case ISD::MUL: case ISD::AND: case ISD::SRL: case ISD::SHL: @@ -2905,7 +2905,7 @@ return DAG.getConstant(Val, VT); } -/// getMemBasePlusOffset - Returns base and offset node for the +/// getMemBasePlusOffset - Returns base and offset node for the /// static SDValue getMemBasePlusOffset(SDValue Base, unsigned Offset, SelectionDAG &DAG) { @@ -3330,7 +3330,7 @@ SDValue SelectionDAG::getAtomic(unsigned Opcode, DebugLoc dl, MVT MemVT, SDValue Chain, - SDValue Ptr, SDValue Cmp, + SDValue Ptr, SDValue Cmp, SDValue Swp, const Value* PtrVal, unsigned Alignment) { assert(Opcode == ISD::ATOMIC_CMP_SWAP && "Invalid Atomic Op"); @@ -3359,7 +3359,7 @@ SDValue SelectionDAG::getAtomic(unsigned Opcode, DebugLoc dl, MVT MemVT, SDValue Chain, - SDValue Ptr, SDValue Val, + SDValue Ptr, SDValue Val, const Value* PtrVal, unsigned Alignment) { assert((Opcode == ISD::ATOMIC_LOAD_ADD || @@ -3368,9 +3368,9 @@ Opcode == ISD::ATOMIC_LOAD_OR || Opcode == ISD::ATOMIC_LOAD_XOR || Opcode == ISD::ATOMIC_LOAD_NAND || - Opcode == ISD::ATOMIC_LOAD_MIN || + Opcode == ISD::ATOMIC_LOAD_MIN || Opcode == ISD::ATOMIC_LOAD_MAX || - Opcode == ISD::ATOMIC_LOAD_UMIN || + Opcode == ISD::ATOMIC_LOAD_UMIN || Opcode == ISD::ATOMIC_LOAD_UMAX || Opcode == ISD::ATOMIC_SWAP) && "Invalid Atomic Op"); @@ -3407,7 +3407,7 @@ VTs.reserve(NumOps); for (unsigned i = 0; i < NumOps; ++i) VTs.push_back(Ops[i].getValueType()); - return getNode(ISD::MERGE_VALUES, dl, getVTList(&VTs[0], NumOps), + return getNode(ISD::MERGE_VALUES, dl, getVTList(&VTs[0], NumOps), Ops, NumOps); } @@ -3437,7 +3437,7 @@ void *IP = 0; if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) return SDValue(E, 0); - + N = NodeAllocator.Allocate(); new (N) MemIntrinsicSDNode(Opcode, dl, VTList, Ops, NumOps, MemVT, srcValue, SVOff, Align, Vol, ReadMem, WriteMem); @@ -3477,7 +3477,7 @@ } SDValue -SelectionDAG::getLoad(ISD::MemIndexedMode AM, DebugLoc dl, +SelectionDAG::getLoad(ISD::MemIndexedMode AM, DebugLoc dl, ISD::LoadExtType ExtType, MVT VT, SDValue Chain, SDValue Ptr, SDValue Offset, const Value *SV, int SVOffset, MVT EVT, @@ -3675,7 +3675,7 @@ case 3: return getNode(Opcode, DL, VT, Ops[0], Ops[1], Ops[2]); default: break; } - + switch (Opcode) { default: break; case ISD::SELECT_CC: { @@ -3736,8 +3736,8 @@ if (NumVTs == 1) return getNode(Opcode, DL, VTs[0], Ops, NumOps); return getNode(Opcode, DL, makeVTList(VTs, NumVTs), Ops, NumOps); -} - +} + SDValue SelectionDAG::getNode(unsigned Opcode, DebugLoc DL, SDVTList VTList, const SDValue *Ops, unsigned NumOps) { if (VTList.NumVTs == 1) @@ -3910,7 +3910,7 @@ E = VTList.rend(); I != E; ++I) { if (I->NumVTs != NumVTs || VTs[0] != I->VTs[0] || VTs[1] != I->VTs[1]) continue; - + bool NoMatch = false; for (unsigned i = 2; i != NumVTs; ++i) if (VTs[i] != I->VTs[i]) { @@ -3920,7 +3920,7 @@ if (!NoMatch) return *I; } - + MVT *Array = Allocator.Allocate(NumVTs); std::copy(VTs, VTs+NumVTs, Array); SDVTList Result = makeVTList(Array, NumVTs); @@ -3938,23 +3938,23 @@ SDValue SelectionDAG::UpdateNodeOperands(SDValue InN, SDValue Op) { SDNode *N = InN.getNode(); assert(N->getNumOperands() == 1 && "Update with wrong number of operands"); - + // Check to see if there is no change. if (Op == N->getOperand(0)) return InN; - + // See if the modified node already exists. void *InsertPos = 0; if (SDNode *Existing = FindModifiedNodeSlot(N, Op, InsertPos)) return SDValue(Existing, InN.getResNo()); - + // Nope it doesn't. Remove the node from its current place in the maps. if (InsertPos) if (!RemoveNodeFromCSEMaps(N)) InsertPos = 0; - + // Now we update the operands. N->OperandList[0].set(Op); - + // If this gets put into a CSE map, add it. if (InsertPos) CSEMap.InsertNode(N, InsertPos); return InN; @@ -3964,27 +3964,27 @@ UpdateNodeOperands(SDValue InN, SDValue Op1, SDValue Op2) { SDNode *N = InN.getNode(); assert(N->getNumOperands() == 2 && "Update with wrong number of operands"); - + // Check to see if there is no change. if (Op1 == N->getOperand(0) && Op2 == N->getOperand(1)) return InN; // No operands changed, just return the input node. - + // See if the modified node already exists. void *InsertPos = 0; if (SDNode *Existing = FindModifiedNodeSlot(N, Op1, Op2, InsertPos)) return SDValue(Existing, InN.getResNo()); - + // Nope it doesn't. Remove the node from its current place in the maps. if (InsertPos) if (!RemoveNodeFromCSEMaps(N)) InsertPos = 0; - + // Now we update the operands. if (N->OperandList[0] != Op1) N->OperandList[0].set(Op1); if (N->OperandList[1] != Op2) N->OperandList[1].set(Op2); - + // If this gets put into a CSE map, add it. if (InsertPos) CSEMap.InsertNode(N, InsertPos); return InN; @@ -3997,7 +3997,7 @@ } SDValue SelectionDAG:: -UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2, +UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2, SDValue Op3, SDValue Op4) { SDValue Ops[] = { Op1, Op2, Op3, Op4 }; return UpdateNodeOperands(N, Ops, 4); @@ -4015,7 +4015,7 @@ SDNode *N = InN.getNode(); assert(N->getNumOperands() == NumOps && "Update with wrong number of operands"); - + // Check to see if there is no change. bool AnyChange = false; for (unsigned i = 0; i != NumOps; ++i) { @@ -4024,20 +4024,20 @@ break; } } - + // No operands changed, just return the input node. if (!AnyChange) return InN; - + // See if the modified node already exists. void *InsertPos = 0; if (SDNode *Existing = FindModifiedNodeSlot(N, Ops, NumOps, InsertPos)) return SDValue(Existing, InN.getResNo()); - + // Nope it doesn't. Remove the node from its current place in the maps. if (InsertPos) if (!RemoveNodeFromCSEMaps(N)) InsertPos = 0; - + // Now we update the operands. for (unsigned i = 0; i != NumOps; ++i) if (N->OperandList[i] != Ops[i]) @@ -4125,7 +4125,7 @@ return SelectNodeTo(N, MachineOpc, VTs, Ops, NumOps); } -SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, +SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, MVT VT1, MVT VT2, SDValue Op1) { SDVTList VTs = getVTList(VT1, VT2); @@ -4133,7 +4133,7 @@ return SelectNodeTo(N, MachineOpc, VTs, Ops, 1); } -SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, +SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, MVT VT1, MVT VT2, SDValue Op1, SDValue Op2) { SDVTList VTs = getVTList(VT1, VT2); @@ -4143,7 +4143,7 @@ SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, MVT VT1, MVT VT2, - SDValue Op1, SDValue Op2, + SDValue Op1, SDValue Op2, SDValue Op3) { SDVTList VTs = getVTList(VT1, VT2); SDValue Ops[] = { Op1, Op2, Op3 }; @@ -4152,7 +4152,7 @@ SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, MVT VT1, MVT VT2, MVT VT3, - SDValue Op1, SDValue Op2, + SDValue Op1, SDValue Op2, SDValue Op3) { SDVTList VTs = getVTList(VT1, VT2, VT3); SDValue Ops[] = { Op1, Op2, Op3 }; @@ -4221,7 +4221,7 @@ return MorphNodeTo(N, Opc, VTs, Ops, NumOps); } -SDNode *SelectionDAG::MorphNodeTo(SDNode *N, unsigned Opc, +SDNode *SelectionDAG::MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, MVT VT2, SDValue Op1) { SDVTList VTs = getVTList(VT1, VT2); @@ -4229,7 +4229,7 @@ return MorphNodeTo(N, Opc, VTs, Ops, 1); } -SDNode *SelectionDAG::MorphNodeTo(SDNode *N, unsigned Opc, +SDNode *SelectionDAG::MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, MVT VT2, SDValue Op1, SDValue Op2) { SDVTList VTs = getVTList(VT1, VT2); @@ -4239,7 +4239,7 @@ SDNode *SelectionDAG::MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, MVT VT2, - SDValue Op1, SDValue Op2, + SDValue Op1, SDValue Op2, SDValue Op3) { SDVTList VTs = getVTList(VT1, VT2); SDValue Ops[] = { Op1, Op2, Op3 }; @@ -4277,7 +4277,7 @@ N->NodeType = Opc; N->ValueList = VTs.VTs; N->NumValues = VTs.NumVTs; - + // Clear the operands list, updating used nodes to remove this from their // use list. Keep track of any operands that become dead as a result. SmallPtrSet DeadNodeSet; @@ -4306,7 +4306,7 @@ N->OperandsNeedDelete = true; } } - + // Assign the new operands. N->NumOperands = NumOps; for (unsigned i = 0, e = NumOps; i != e; ++i) { @@ -4360,7 +4360,7 @@ return getNode(~Opcode, dl, VT, Ops, NumOps).getNode(); } -SDNode *SelectionDAG::getTargetNode(unsigned Opcode, DebugLoc dl, +SDNode *SelectionDAG::getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT1, MVT VT2) { const MVT *VTs = getNodeValueTypes(VT1, VT2); SDValue Op; @@ -4389,7 +4389,7 @@ return getNode(~Opcode, dl, VTs, 2, Ops, 3).getNode(); } -SDNode *SelectionDAG::getTargetNode(unsigned Opcode, DebugLoc dl, +SDNode *SelectionDAG::getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT1, MVT VT2, const SDValue *Ops, unsigned NumOps) { const MVT *VTs = getNodeValueTypes(VT1, VT2); @@ -4462,7 +4462,7 @@ void SelectionDAG::ReplaceAllUsesWith(SDValue FromN, SDValue To, DAGUpdateListener *UpdateListener) { SDNode *From = FromN.getNode(); - assert(From->getNumValues() == 1 && FromN.getResNo() == 0 && + assert(From->getNumValues() == 1 && FromN.getResNo() == 0 && "Cannot replace with this method!"); assert(From != To.getNode() && "Cannot replace uses of with self"); @@ -4665,7 +4665,7 @@ for (unsigned i = 0; i != Num; ++i) { unsigned FromResNo = From[i].getResNo(); SDNode *FromNode = From[i].getNode(); - for (SDNode::use_iterator UI = FromNode->use_begin(), + for (SDNode::use_iterator UI = FromNode->use_begin(), E = FromNode->use_end(); UI != E; ++UI) { SDUse &Use = UI.getUse(); if (Use.getResNo() == FromResNo) { @@ -4810,7 +4810,7 @@ assert(isVolatile() == vol && "Volatile representation error!"); } -MemSDNode::MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, +MemSDNode::MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, const SDValue *Ops, unsigned NumOps, MVT memvt, const Value *srcValue, int SVO, unsigned alignment, bool vol) @@ -4842,9 +4842,9 @@ int Size = (getMemoryVT().getSizeInBits() + 7) >> 3; if (isVolatile()) Flags |= MachineMemOperand::MOVolatile; - + // Check if the memory reference references a frame index - const FrameIndexSDNode *FI = + const FrameIndexSDNode *FI = dyn_cast(getBasePtr().getNode()); if (!getSrcValue() && FI) return MachineMemOperand(PseudoSourceValue::getFixedStack(FI->getIndex()), @@ -4938,18 +4938,18 @@ } /// reachesChainWithoutSideEffects - Return true if this operand (which must -/// be a chain) reaches the specified operand without crossing any +/// be a chain) reaches the specified operand without crossing any /// side-effecting instructions. In practice, this looks through token /// factors and non-volatile loads. In order to remain efficient, this only /// looks a couple of nodes in, it does not do an exhaustive search. -bool SDValue::reachesChainWithoutSideEffects(SDValue Dest, +bool SDValue::reachesChainWithoutSideEffects(SDValue Dest, unsigned Depth) const { if (*this == Dest) return true; - + // Don't search too deeply, we just want to be able to see through // TokenFactor's etc. if (Depth == 0) return false; - + // If this is a token factor, all inputs to the TF happen in parallel. If any // of the operands of the TF reach dest, then we can do the xform. if (getOpcode() == ISD::TokenFactor) { @@ -4958,7 +4958,7 @@ return true; return false; } - + // Loads don't have side effects, look through them. if (LoadSDNode *Ld = dyn_cast(*this)) { if (!Ld->isVolatile()) @@ -5018,7 +5018,7 @@ return "<>"; } return "<>"; - + #ifndef NDEBUG case ISD::DELETED_NODE: return "<>"; @@ -5097,7 +5097,7 @@ case ISD::HANDLENODE: return "handlenode"; case ISD::FORMAL_ARGUMENTS: return "formal_arguments"; case ISD::CALL: return "call"; - + // Unary operators case ISD::FABS: return "fabs"; case ISD::FNEG: return "fneg"; @@ -5166,10 +5166,10 @@ case ISD::SHL_PARTS: return "shl_parts"; case ISD::SRA_PARTS: return "sra_parts"; case ISD::SRL_PARTS: return "srl_parts"; - + case ISD::EXTRACT_SUBREG: return "extract_subreg"; case ISD::INSERT_SUBREG: return "insert_subreg"; - + // Conversion operators. case ISD::SIGN_EXTEND: return "sign_extend"; case ISD::ZERO_EXTEND: return "zero_extend"; @@ -5186,7 +5186,7 @@ case ISD::FP_TO_SINT: return "fp_to_sint"; case ISD::FP_TO_UINT: return "fp_to_uint"; case ISD::BIT_CONVERT: return "bit_convert"; - + case ISD::CONVERT_RNDSAT: { switch (cast(this)->getCvtCode()) { default: assert(0 && "Unknown cvt code!"); @@ -5494,7 +5494,7 @@ void SelectionDAG::dump() const { cerr << "SelectionDAG has " << AllNodes.size() << " nodes:"; - + for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end(); I != E; ++I) { const SDNode *N = I; Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp?rev=64827&r1=64826&r2=64827&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp (original) +++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp Tue Feb 17 16:15:04 2009 @@ -338,7 +338,7 @@ unsigned SrcFile = DW->RecordSource(CU.getDirectory(), CU.getFilename()); unsigned idx = MF->getOrCreateDebugLocID(SrcFile, - SPI->getLine(), + SPI->getLine(), SPI->getColumn()); DL = DebugLoc::get(idx); } @@ -360,7 +360,7 @@ DL = DebugLoc::get(MF->getOrCreateDebugLocID(SrcFile, Line, 0)); } } - + break; } } @@ -463,7 +463,7 @@ // Assemble the trailing non-power-of-2 part. unsigned OddParts = NumParts - RoundParts; MVT OddVT = MVT::getIntegerVT(OddParts * PartBits); - Hi = getCopyFromParts(DAG, dl, + Hi = getCopyFromParts(DAG, dl, Parts+RoundParts, OddParts, PartVT, OddVT); // Combine the round and odd parts. @@ -646,7 +646,7 @@ // The number of parts is a power of 2. Repeatedly bisect the value using // EXTRACT_ELEMENT. - Parts[0] = DAG.getNode(ISD::BIT_CONVERT, dl, + Parts[0] = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::getIntegerVT(ValueVT.getSizeInBits()), Val); for (unsigned StepSize = NumParts; StepSize > 1; StepSize /= 2) { @@ -656,17 +656,17 @@ SDValue &Part0 = Parts[i]; SDValue &Part1 = Parts[i+StepSize/2]; - Part1 = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, + Part1 = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, ThisVT, Part0, DAG.getConstant(1, PtrVT)); - Part0 = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, + Part0 = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, ThisVT, Part0, DAG.getConstant(0, PtrVT)); if (ThisBits == PartBits && ThisVT != PartVT) { - Part0 = DAG.getNode(ISD::BIT_CONVERT, dl, + Part0 = DAG.getNode(ISD::BIT_CONVERT, dl, PartVT, Part0); - Part1 = DAG.getNode(ISD::BIT_CONVERT, dl, + Part1 = DAG.getNode(ISD::BIT_CONVERT, dl, PartVT, Part1); } } @@ -687,7 +687,7 @@ assert(ValueVT.getVectorElementType() == PartVT && ValueVT.getVectorNumElements() == 1 && "Only trivial vector-to-scalar conversions should get here!"); - Val = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, + Val = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, PartVT, Val, DAG.getConstant(0, PtrVT)); } @@ -713,12 +713,12 @@ SmallVector Ops(NumIntermediates); for (unsigned i = 0; i != NumIntermediates; ++i) if (IntermediateVT.isVector()) - Ops[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, + Ops[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, IntermediateVT, Val, DAG.getConstant(i * (NumElements / NumIntermediates), PtrVT)); else - Ops[i] = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, + Ops[i] = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, IntermediateVT, Val, DAG.getConstant(i, PtrVT)); @@ -935,7 +935,7 @@ } // Create a BUILD_VECTOR node. - return NodeMap[V] = DAG.getNode(ISD::BUILD_VECTOR, getCurDebugLoc(), + return NodeMap[V] = DAG.getNode(ISD::BUILD_VECTOR, getCurDebugLoc(), VT, &Ops[0], Ops.size()); } @@ -959,7 +959,7 @@ void SelectionDAGLowering::visitRet(ReturnInst &I) { if (I.getNumOperands() == 0) { - DAG.setRoot(DAG.getNode(ISD::RET, getCurDebugLoc(), + DAG.setRoot(DAG.getNode(ISD::RET, getCurDebugLoc(), MVT::Other, getControlRoot())); return; } @@ -1250,7 +1250,7 @@ // If this is not a fall-through branch, emit the branch. if (Succ0MBB != NextBlock) - DAG.setRoot(DAG.getNode(ISD::BR, getCurDebugLoc(), + DAG.setRoot(DAG.getNode(ISD::BR, getCurDebugLoc(), MVT::Other, getControlRoot(), DAG.getBasicBlock(Succ0MBB))); return; @@ -1344,7 +1344,7 @@ MVT VT = CmpOp.getValueType(); if (cast(CB.CmpLHS)->isMinValue(true)) { - Cond = DAG.getSetCC(dl, MVT::i1, CmpOp, DAG.getConstant(High, VT), + Cond = DAG.getSetCC(dl, MVT::i1, CmpOp, DAG.getConstant(High, VT), ISD::SETLE); } else { SDValue SUB = DAG.getNode(ISD::SUB, dl, @@ -1401,7 +1401,7 @@ SDValue Index = DAG.getCopyFromReg(getControlRoot(), getCurDebugLoc(), JT.Reg, PTy); SDValue Table = DAG.getJumpTable(JT.JTI, PTy); - DAG.setRoot(DAG.getNode(ISD::BR_JT, getCurDebugLoc(), + DAG.setRoot(DAG.getNode(ISD::BR_JT, getCurDebugLoc(), MVT::Other, Index.getValue(1), Table, Index)); } @@ -1424,10 +1424,10 @@ // This value may be smaller or larger than the target's pointer type, and // therefore require extension or truncating. if (VT.bitsGT(TLI.getPointerTy())) - SwitchOp = DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(), + SwitchOp = DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(), TLI.getPointerTy(), SUB); else - SwitchOp = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), + SwitchOp = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), TLI.getPointerTy(), SUB); unsigned JumpTableReg = FuncInfo.MakeReg(TLI.getPointerTy()); @@ -1478,10 +1478,10 @@ SDValue ShiftOp; if (VT.bitsGT(TLI.getPointerTy())) - ShiftOp = DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(), + ShiftOp = DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(), TLI.getPointerTy(), SUB); else - ShiftOp = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), + ShiftOp = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), TLI.getPointerTy(), SUB); B.Reg = FuncInfo.MakeReg(TLI.getPointerTy()); @@ -1518,13 +1518,13 @@ // Make desired shift SDValue ShiftOp = DAG.getCopyFromReg(getControlRoot(), getCurDebugLoc(), Reg, TLI.getPointerTy()); - SDValue SwitchVal = DAG.getNode(ISD::SHL, getCurDebugLoc(), + SDValue SwitchVal = DAG.getNode(ISD::SHL, getCurDebugLoc(), TLI.getPointerTy(), DAG.getConstant(1, TLI.getPointerTy()), ShiftOp); // Emit bit tests and jumps - SDValue AndOp = DAG.getNode(ISD::AND, getCurDebugLoc(), + SDValue AndOp = DAG.getNode(ISD::AND, getCurDebugLoc(), TLI.getPointerTy(), SwitchVal, DAG.getConstant(B.Mask, TLI.getPointerTy())); SDValue AndCmp = DAG.getSetCC(getCurDebugLoc(), @@ -1577,7 +1577,7 @@ CurMBB->addSuccessor(LandingPad); // Drop into normal successor. - DAG.setRoot(DAG.getNode(ISD::BR, getCurDebugLoc(), + DAG.setRoot(DAG.getNode(ISD::BR, getCurDebugLoc(), MVT::Other, getControlRoot(), DAG.getBasicBlock(Return))); } @@ -2144,7 +2144,7 @@ Constant *CNZ = ConstantVector::get(&NZ[0], NZ.size()); if (CV == CNZ) { SDValue Op2 = getValue(I.getOperand(1)); - setValue(&I, DAG.getNode(ISD::FNEG, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::FNEG, getCurDebugLoc(), Op2.getValueType(), Op2)); return; } @@ -2155,7 +2155,7 @@ if (ConstantFP *CFP = dyn_cast(I.getOperand(0))) if (CFP->isExactlyValue(ConstantFP::getNegativeZero(Ty)->getValueAPF())) { SDValue Op2 = getValue(I.getOperand(1)); - setValue(&I, DAG.getNode(ISD::FNEG, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::FNEG, getCurDebugLoc(), Op2.getValueType(), Op2)); return; } @@ -2168,7 +2168,7 @@ SDValue Op1 = getValue(I.getOperand(0)); SDValue Op2 = getValue(I.getOperand(1)); - setValue(&I, DAG.getNode(OpCode, getCurDebugLoc(), + setValue(&I, DAG.getNode(OpCode, getCurDebugLoc(), Op1.getValueType(), Op1, Op2)); } @@ -2177,14 +2177,14 @@ SDValue Op2 = getValue(I.getOperand(1)); if (!isa(I.getType())) { if (TLI.getPointerTy().bitsLT(Op2.getValueType())) - Op2 = DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(), + Op2 = DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(), TLI.getPointerTy(), Op2); else if (TLI.getPointerTy().bitsGT(Op2.getValueType())) - Op2 = DAG.getNode(ISD::ANY_EXTEND, getCurDebugLoc(), + Op2 = DAG.getNode(ISD::ANY_EXTEND, getCurDebugLoc(), TLI.getPointerTy(), Op2); } - setValue(&I, DAG.getNode(Opcode, getCurDebugLoc(), + setValue(&I, DAG.getNode(Opcode, getCurDebugLoc(), Op1.getValueType(), Op1, Op2)); } @@ -2221,7 +2221,7 @@ SDValue Op1 = getValue(I.getOperand(0)); SDValue Op2 = getValue(I.getOperand(1)); ISD::CondCode Opcode = getICmpCondCode(predicate); - setValue(&I, DAG.getVSetCC(getCurDebugLoc(), Op1.getValueType(), + setValue(&I, DAG.getVSetCC(getCurDebugLoc(), Op1.getValueType(), Op1, Op2, Opcode)); } @@ -2250,12 +2250,12 @@ SDValue FalseVal = getValue(I.getOperand(2)); for (unsigned i = 0; i != NumValues; ++i) - Values[i] = DAG.getNode(ISD::SELECT, getCurDebugLoc(), + Values[i] = DAG.getNode(ISD::SELECT, getCurDebugLoc(), TrueVal.getValueType(), Cond, SDValue(TrueVal.getNode(), TrueVal.getResNo() + i), SDValue(FalseVal.getNode(), FalseVal.getResNo() + i)); - setValue(&I, DAG.getNode(ISD::MERGE_VALUES, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::MERGE_VALUES, getCurDebugLoc(), DAG.getVTList(&ValueVTs[0], NumValues), &Values[0], NumValues)); } @@ -2289,7 +2289,7 @@ // FPTrunc is never a no-op cast, no need to check SDValue N = getValue(I.getOperand(0)); MVT DestVT = TLI.getValueType(I.getType()); - setValue(&I, DAG.getNode(ISD::FP_ROUND, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::FP_ROUND, getCurDebugLoc(), DestVT, N, DAG.getIntPtrConstant(0))); } @@ -2353,7 +2353,7 @@ setValue(&I, DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(), DestVT, N)); else // Note: ZERO_EXTEND can handle cases where the sizes are equal too - setValue(&I, DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), DestVT, N)); } @@ -2364,7 +2364,7 @@ // BitCast assures us that source and destination are the same size so this // is either a BIT_CONVERT or a no-op. if (DestVT != N.getValueType()) - setValue(&I, DAG.getNode(ISD::BIT_CONVERT, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::BIT_CONVERT, getCurDebugLoc(), DestVT, N)); // convert types else setValue(&I, N); // noop cast. @@ -2373,18 +2373,18 @@ void SelectionDAGLowering::visitInsertElement(User &I) { SDValue InVec = getValue(I.getOperand(0)); SDValue InVal = getValue(I.getOperand(1)); - SDValue InIdx = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), + SDValue InIdx = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), TLI.getPointerTy(), getValue(I.getOperand(2))); - setValue(&I, DAG.getNode(ISD::INSERT_VECTOR_ELT, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::INSERT_VECTOR_ELT, getCurDebugLoc(), TLI.getValueType(I.getType()), InVec, InVal, InIdx)); } void SelectionDAGLowering::visitExtractElement(User &I) { SDValue InVec = getValue(I.getOperand(0)); - SDValue InIdx = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), + SDValue InIdx = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), TLI.getPointerTy(), getValue(I.getOperand(1))); setValue(&I, DAG.getNode(ISD::EXTRACT_VECTOR_ELT, getCurDebugLoc(), @@ -2417,7 +2417,7 @@ int SrcNumElts = SrcVT.getVectorNumElements(); if (SrcNumElts == MaskNumElts) { - setValue(&I, DAG.getNode(ISD::VECTOR_SHUFFLE, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::VECTOR_SHUFFLE, getCurDebugLoc(), VT, Src1, Src2, Mask)); return; } @@ -2431,7 +2431,7 @@ // lengths match. if (SrcNumElts*2 == MaskNumElts && SequentialMask(Mask, 0)) { // The shuffle is concatenating two vectors together. - setValue(&I, DAG.getNode(ISD::CONCAT_VECTORS, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::CONCAT_VECTORS, getCurDebugLoc(), VT, Src1, Src2)); return; } @@ -2448,9 +2448,9 @@ MOps1[i] = UndefVal; MOps2[i] = UndefVal; } - Src1 = DAG.getNode(ISD::CONCAT_VECTORS, getCurDebugLoc(), + Src1 = DAG.getNode(ISD::CONCAT_VECTORS, getCurDebugLoc(), VT, MOps1, NumConcat); - Src2 = DAG.getNode(ISD::CONCAT_VECTORS, getCurDebugLoc(), + Src2 = DAG.getNode(ISD::CONCAT_VECTORS, getCurDebugLoc(), VT, MOps2, NumConcat); delete [] MOps1; @@ -2470,11 +2470,11 @@ MaskEltVT)); } } - Mask = DAG.getNode(ISD::BUILD_VECTOR, getCurDebugLoc(), + Mask = DAG.getNode(ISD::BUILD_VECTOR, getCurDebugLoc(), Mask.getValueType(), &MappedOps[0], MappedOps.size()); - setValue(&I, DAG.getNode(ISD::VECTOR_SHUFFLE, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::VECTOR_SHUFFLE, getCurDebugLoc(), VT, Src1, Src2, Mask)); return; } @@ -2570,10 +2570,10 @@ } } } - Mask = DAG.getNode(ISD::BUILD_VECTOR, getCurDebugLoc(), + Mask = DAG.getNode(ISD::BUILD_VECTOR, getCurDebugLoc(), Mask.getValueType(), &MappedOps[0], MappedOps.size()); - setValue(&I, DAG.getNode(ISD::VECTOR_SHUFFLE, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::VECTOR_SHUFFLE, getCurDebugLoc(), VT, Src1, Src2, Mask)); return; } @@ -2597,11 +2597,11 @@ EltVT, Src1, DAG.getConstant(Idx, PtrVT))); else Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, getCurDebugLoc(), - EltVT, Src2, + EltVT, Src2, DAG.getConstant(Idx - SrcNumElts, PtrVT))); } } - setValue(&I, DAG.getNode(ISD::BUILD_VECTOR, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::BUILD_VECTOR, getCurDebugLoc(), VT, &Ops[0], Ops.size())); } @@ -2641,7 +2641,7 @@ Values[i] = IntoUndef ? DAG.getUNDEF(AggValueVTs[i]) : SDValue(Agg.getNode(), Agg.getResNo() + i); - setValue(&I, DAG.getNode(ISD::MERGE_VALUES, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::MERGE_VALUES, getCurDebugLoc(), DAG.getVTList(&AggValueVTs[0], NumAggValues), &Values[0], NumAggValues)); } @@ -2669,7 +2669,7 @@ DAG.getUNDEF(Agg.getNode()->getValueType(Agg.getResNo() + i)) : SDValue(Agg.getNode(), Agg.getResNo() + i); - setValue(&I, DAG.getNode(ISD::MERGE_VALUES, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::MERGE_VALUES, getCurDebugLoc(), DAG.getVTList(&ValValueVTs[0], NumValValues), &Values[0], NumValValues)); } @@ -2719,10 +2719,10 @@ // If the index is smaller or larger than intptr_t, truncate or extend // it. if (IdxN.getValueType().bitsLT(N.getValueType())) - IdxN = DAG.getNode(ISD::SIGN_EXTEND, getCurDebugLoc(), + IdxN = DAG.getNode(ISD::SIGN_EXTEND, getCurDebugLoc(), N.getValueType(), IdxN); else if (IdxN.getValueType().bitsGT(N.getValueType())) - IdxN = DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(), + IdxN = DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(), N.getValueType(), IdxN); // If this is a multiply by a power of two, turn it into a shl @@ -2730,17 +2730,17 @@ if (ElementSize != 1) { if (isPowerOf2_64(ElementSize)) { unsigned Amt = Log2_64(ElementSize); - IdxN = DAG.getNode(ISD::SHL, getCurDebugLoc(), + IdxN = DAG.getNode(ISD::SHL, getCurDebugLoc(), N.getValueType(), IdxN, DAG.getConstant(Amt, TLI.getPointerTy())); } else { SDValue Scale = DAG.getIntPtrConstant(ElementSize); - IdxN = DAG.getNode(ISD::MUL, getCurDebugLoc(), + IdxN = DAG.getNode(ISD::MUL, getCurDebugLoc(), N.getValueType(), IdxN, Scale); } } - N = DAG.getNode(ISD::ADD, getCurDebugLoc(), + N = DAG.getNode(ISD::ADD, getCurDebugLoc(), N.getValueType(), N, IdxN); } } @@ -2762,10 +2762,10 @@ SDValue AllocSize = getValue(I.getArraySize()); MVT IntPtr = TLI.getPointerTy(); if (IntPtr.bitsLT(AllocSize.getValueType())) - AllocSize = DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(), + AllocSize = DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(), IntPtr, AllocSize); else if (IntPtr.bitsGT(AllocSize.getValueType())) - AllocSize = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), + AllocSize = DAG.getNode(ISD::ZERO_EXTEND, getCurDebugLoc(), IntPtr, AllocSize); AllocSize = DAG.getNode(ISD::MUL, getCurDebugLoc(), IntPtr, AllocSize, @@ -2781,18 +2781,18 @@ // Round the size of the allocation up to the stack alignment size // by add SA-1 to the size. - AllocSize = DAG.getNode(ISD::ADD, getCurDebugLoc(), + AllocSize = DAG.getNode(ISD::ADD, getCurDebugLoc(), AllocSize.getValueType(), AllocSize, DAG.getIntPtrConstant(StackAlign-1)); // Mask out the low bits for alignment purposes. - AllocSize = DAG.getNode(ISD::AND, getCurDebugLoc(), + AllocSize = DAG.getNode(ISD::AND, getCurDebugLoc(), AllocSize.getValueType(), AllocSize, DAG.getIntPtrConstant(~(uint64_t)(StackAlign-1))); SDValue Ops[] = { getRoot(), AllocSize, DAG.getIntPtrConstant(Align) }; const MVT *VTs = DAG.getNodeValueTypes(AllocSize.getValueType(), MVT::Other); - SDValue DSA = DAG.getNode(ISD::DYNAMIC_STACKALLOC, getCurDebugLoc(), + SDValue DSA = DAG.getNode(ISD::DYNAMIC_STACKALLOC, getCurDebugLoc(), VTs, 2, Ops, 3); setValue(&I, DSA); DAG.setRoot(DSA.getValue(1)); @@ -2836,7 +2836,7 @@ MVT PtrVT = Ptr.getValueType(); for (unsigned i = 0; i != NumValues; ++i) { SDValue L = DAG.getLoad(ValueVTs[i], getCurDebugLoc(), Root, - DAG.getNode(ISD::ADD, getCurDebugLoc(), + DAG.getNode(ISD::ADD, getCurDebugLoc(), PtrVT, Ptr, DAG.getConstant(Offsets[i], PtrVT)), SV, Offsets[i], @@ -2846,7 +2846,7 @@ } if (!ConstantMemory) { - SDValue Chain = DAG.getNode(ISD::TokenFactor, getCurDebugLoc(), + SDValue Chain = DAG.getNode(ISD::TokenFactor, getCurDebugLoc(), MVT::Other, &Chains[0], NumValues); if (isVolatile) @@ -2855,7 +2855,7 @@ PendingLoads.push_back(Chain); } - setValue(&I, DAG.getNode(ISD::MERGE_VALUES, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::MERGE_VALUES, getCurDebugLoc(), DAG.getVTList(&ValueVTs[0], NumValues), &Values[0], NumValues)); } @@ -2886,13 +2886,13 @@ for (unsigned i = 0; i != NumValues; ++i) Chains[i] = DAG.getStore(Root, getCurDebugLoc(), SDValue(Src.getNode(), Src.getResNo() + i), - DAG.getNode(ISD::ADD, getCurDebugLoc(), + DAG.getNode(ISD::ADD, getCurDebugLoc(), PtrVT, Ptr, DAG.getConstant(Offsets[i], PtrVT)), PtrV, Offsets[i], isVolatile, Alignment); - DAG.setRoot(DAG.getNode(ISD::TokenFactor, getCurDebugLoc(), + DAG.setRoot(DAG.getNode(ISD::TokenFactor, getCurDebugLoc(), MVT::Other, &Chains[0], NumValues)); } @@ -2961,15 +2961,15 @@ Info.readMem, Info.writeMem); } else if (!HasChain) - Result = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, getCurDebugLoc(), + Result = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, getCurDebugLoc(), VTList, VTs.size(), &Ops[0], Ops.size()); else if (I.getType() != Type::VoidTy) - Result = DAG.getNode(ISD::INTRINSIC_W_CHAIN, getCurDebugLoc(), + Result = DAG.getNode(ISD::INTRINSIC_W_CHAIN, getCurDebugLoc(), VTList, VTs.size(), &Ops[0], Ops.size()); else - Result = DAG.getNode(ISD::INTRINSIC_VOID, getCurDebugLoc(), + Result = DAG.getNode(ISD::INTRINSIC_VOID, getCurDebugLoc(), VTList, VTs.size(), &Ops[0], Ops.size()); @@ -3121,7 +3121,7 @@ MVT ValueVTs[] = { Op1.getValueType(), MVT::i1 }; SDValue Ops[] = { Op1, Op2 }; - SDValue Result = DAG.getNode(Op, getCurDebugLoc(), + SDValue Result = DAG.getNode(Op, getCurDebugLoc(), DAG.getVTList(&ValueVTs[0], 2), &Ops[0], 2); setValue(&I, Result); @@ -3235,7 +3235,7 @@ SDValue t12 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t11, X); SDValue t13 = DAG.getNode(ISD::FADD, dl, MVT::f32, t12, getF32Constant(DAG, 0x3f800000)); - SDValue TwoToFracPartOfX = DAG.getNode(ISD::BIT_CONVERT, dl, + SDValue TwoToFracPartOfX = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i32, t13); // Add the exponent into the result in integer domain. @@ -3291,7 +3291,7 @@ SDValue LogOfMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t2, getF32Constant(DAG, 0x3f949a29)); - result = DAG.getNode(ISD::FADD, dl, + result = DAG.getNode(ISD::FADD, dl, MVT::f32, LogOfExponent, LogOfMantissa); } else if (LimitFloatPrecision > 6 && LimitFloatPrecision <= 12) { // For floating-point precision of 12: @@ -3317,7 +3317,7 @@ SDValue LogOfMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t6, getF32Constant(DAG, 0x3fdef31a)); - result = DAG.getNode(ISD::FADD, dl, + result = DAG.getNode(ISD::FADD, dl, MVT::f32, LogOfExponent, LogOfMantissa); } else { // LimitFloatPrecision > 12 && LimitFloatPrecision <= 18 // For floating-point precision of 18: @@ -3351,7 +3351,7 @@ SDValue LogOfMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t10, getF32Constant(DAG, 0x4006dcab)); - result = DAG.getNode(ISD::FADD, dl, + result = DAG.getNode(ISD::FADD, dl, MVT::f32, LogOfExponent, LogOfMantissa); } } else { @@ -3399,7 +3399,7 @@ SDValue Log2ofMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t2, getF32Constant(DAG, 0x3fd6633d)); - result = DAG.getNode(ISD::FADD, dl, + result = DAG.getNode(ISD::FADD, dl, MVT::f32, LogOfExponent, Log2ofMantissa); } else if (LimitFloatPrecision > 6 && LimitFloatPrecision <= 12) { // For floating-point precision of 12: @@ -3425,7 +3425,7 @@ SDValue Log2ofMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t6, getF32Constant(DAG, 0x4020d29c)); - result = DAG.getNode(ISD::FADD, dl, + result = DAG.getNode(ISD::FADD, dl, MVT::f32, LogOfExponent, Log2ofMantissa); } else { // LimitFloatPrecision > 12 && LimitFloatPrecision <= 18 // For floating-point precision of 18: @@ -3460,7 +3460,7 @@ SDValue Log2ofMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t10, getF32Constant(DAG, 0x4042902c)); - result = DAG.getNode(ISD::FADD, dl, + result = DAG.getNode(ISD::FADD, dl, MVT::f32, LogOfExponent, Log2ofMantissa); } } else { @@ -3510,7 +3510,7 @@ SDValue Log10ofMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t2, getF32Constant(DAG, 0x3f011300)); - result = DAG.getNode(ISD::FADD, dl, + result = DAG.getNode(ISD::FADD, dl, MVT::f32, LogOfExponent, Log10ofMantissa); } else if (LimitFloatPrecision > 6 && LimitFloatPrecision <= 12) { // For floating-point precision of 12: @@ -3532,7 +3532,7 @@ SDValue Log10ofMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t4, getF32Constant(DAG, 0x3f25f7c3)); - result = DAG.getNode(ISD::FADD, dl, + result = DAG.getNode(ISD::FADD, dl, MVT::f32, LogOfExponent, Log10ofMantissa); } else { // LimitFloatPrecision > 12 && LimitFloatPrecision <= 18 // For floating-point precision of 18: @@ -3562,7 +3562,7 @@ SDValue Log10ofMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t8, getF32Constant(DAG, 0x3f57ce70)); - result = DAG.getNode(ISD::FADD, dl, + result = DAG.getNode(ISD::FADD, dl, MVT::f32, LogOfExponent, Log10ofMantissa); } } else { @@ -3615,7 +3615,7 @@ SDValue TwoToFractionalPartOfX = DAG.getNode(ISD::ADD, dl, MVT::i32, t6, IntegerPartOfX); - result = DAG.getNode(ISD::BIT_CONVERT, dl, + result = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f32, TwoToFractionalPartOfX); } else if (LimitFloatPrecision > 6 && LimitFloatPrecision <= 12) { // For floating-point precision of 12: @@ -3640,7 +3640,7 @@ SDValue TwoToFractionalPartOfX = DAG.getNode(ISD::ADD, dl, MVT::i32, t8, IntegerPartOfX); - result = DAG.getNode(ISD::BIT_CONVERT, dl, + result = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f32, TwoToFractionalPartOfX); } else { // LimitFloatPrecision > 12 && LimitFloatPrecision <= 18 // For floating-point precision of 18: @@ -3676,7 +3676,7 @@ SDValue TwoToFractionalPartOfX = DAG.getNode(ISD::ADD, dl, MVT::i32, t14, IntegerPartOfX); - result = DAG.getNode(ISD::BIT_CONVERT, dl, + result = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f32, TwoToFractionalPartOfX); } } else { @@ -3773,7 +3773,7 @@ SDValue TwoToFractionalPartOfX = DAG.getNode(ISD::ADD, dl, MVT::i32, t8, IntegerPartOfX); - result = DAG.getNode(ISD::BIT_CONVERT, dl, + result = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f32, TwoToFractionalPartOfX); } else { // LimitFloatPrecision > 12 && LimitFloatPrecision <= 18 // For floating-point precision of 18: @@ -3809,7 +3809,7 @@ SDValue TwoToFractionalPartOfX = DAG.getNode(ISD::ADD, dl, MVT::i32, t14, IntegerPartOfX); - result = DAG.getNode(ISD::BIT_CONVERT, dl, + result = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f32, TwoToFractionalPartOfX); } } else { @@ -3903,7 +3903,7 @@ unsigned SrcFile = DW->RecordSource(CU.getDirectory(), CU.getFilename()); unsigned idx = DAG.getMachineFunction(). getOrCreateDebugLocID(SrcFile, - SPI.getLine(), + SPI.getLine(), SPI.getColumn()); setCurDebugLoc(DebugLoc::get(idx)); } @@ -4477,7 +4477,7 @@ I.getType() == I.getOperand(2)->getType()) { SDValue LHS = getValue(I.getOperand(1)); SDValue RHS = getValue(I.getOperand(2)); - setValue(&I, DAG.getNode(ISD::FCOPYSIGN, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::FCOPYSIGN, getCurDebugLoc(), LHS.getValueType(), LHS, RHS)); return; } @@ -4489,7 +4489,7 @@ I.getOperand(1)->getType()->isFloatingPoint() && I.getType() == I.getOperand(1)->getType()) { SDValue Tmp = getValue(I.getOperand(1)); - setValue(&I, DAG.getNode(ISD::FABS, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::FABS, getCurDebugLoc(), Tmp.getValueType(), Tmp)); return; } @@ -4501,7 +4501,7 @@ I.getOperand(1)->getType()->isFloatingPoint() && I.getType() == I.getOperand(1)->getType()) { SDValue Tmp = getValue(I.getOperand(1)); - setValue(&I, DAG.getNode(ISD::FSIN, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::FSIN, getCurDebugLoc(), Tmp.getValueType(), Tmp)); return; } @@ -4513,7 +4513,7 @@ I.getOperand(1)->getType()->isFloatingPoint() && I.getType() == I.getOperand(1)->getType()) { SDValue Tmp = getValue(I.getOperand(1)); - setValue(&I, DAG.getNode(ISD::FCOS, getCurDebugLoc(), + setValue(&I, DAG.getNode(ISD::FCOS, getCurDebugLoc(), Tmp.getValueType(), Tmp)); return; } @@ -4606,7 +4606,7 @@ Parts[i] = P; } - Values[Value] = getCopyFromParts(DAG, dl, Parts.begin(), + Values[Value] = getCopyFromParts(DAG, dl, Parts.begin(), NumRegs, RegisterVT, ValueVT); Part += NumRegs; Parts.clear(); @@ -5370,7 +5370,7 @@ // If this asm returns a register value, copy the result from that register // and set it as the value of the call. if (!RetValRegs.Regs.empty()) { - SDValue Val = RetValRegs.getCopyFromRegs(DAG, getCurDebugLoc(), + SDValue Val = RetValRegs.getCopyFromRegs(DAG, getCurDebugLoc(), Chain, &Flag); // FIXME: Why don't we do this for inline asms with MRVs? @@ -5817,7 +5817,7 @@ ComputeValueVTs(TLI, AI->getType(), ValueVTs); unsigned NumValues = ValueVTs.size(); if (!AI->use_empty()) { - SDL->setValue(AI, SDL->DAG.getMergeValues(&Args[a], NumValues, + SDL->setValue(AI, SDL->DAG.getMergeValues(&Args[a], NumValues, SDL->getCurDebugLoc())); // If this argument is live outside of the entry block, insert a copy from // whereever we got it to the vreg that other BB's will reference it as. Modified: llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp?rev=64827&r1=64826&r2=64827&view=diff ============================================================================== --- llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp (original) +++ llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp Tue Feb 17 16:15:04 2009 @@ -34,30 +34,30 @@ #include "llvm/Support/CommandLine.h" using namespace llvm; -static cl::opt EnablePPCPreinc("enable-ppc-preinc", +static cl::opt EnablePPCPreinc("enable-ppc-preinc", cl::desc("enable preincrement load/store generation on PPC (experimental)"), cl::Hidden); PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM) : TargetLowering(TM), PPCSubTarget(*TM.getSubtargetImpl()) { - + setPow2DivIsCheap(); // Use _setjmp/_longjmp instead of setjmp/longjmp. setUseUnderscoreSetJmp(true); setUseUnderscoreLongJmp(true); - + // Set up the register classes. addRegisterClass(MVT::i32, PPC::GPRCRegisterClass); addRegisterClass(MVT::f32, PPC::F4RCRegisterClass); addRegisterClass(MVT::f64, PPC::F8RCRegisterClass); - + // PowerPC has an i16 but no i8 (or i1) SEXTLOAD setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); setLoadExtAction(ISD::SEXTLOAD, MVT::i8, Expand); setTruncStoreAction(MVT::f64, MVT::f32, Expand); - + // PowerPC has pre-inc load and store's. setIndexedLoadAction(ISD::PRE_INC, MVT::i1, Legal); setIndexedLoadAction(ISD::PRE_INC, MVT::i8, Legal); @@ -92,7 +92,7 @@ setOperationAction(ISD::SDIVREM, MVT::i32, Expand); setOperationAction(ISD::UDIVREM, MVT::i64, Expand); setOperationAction(ISD::SDIVREM, MVT::i64, Expand); - + // We don't support sin/cos/sqrt/fmod/pow setOperationAction(ISD::FSIN , MVT::f64, Expand); setOperationAction(ISD::FCOS , MVT::f64, Expand); @@ -104,16 +104,16 @@ setOperationAction(ISD::FPOW , MVT::f32, Expand); setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); - + // If we're enabling GP optimizations, use hardware square root if (!TM.getSubtarget().hasFSQRT()) { setOperationAction(ISD::FSQRT, MVT::f64, Expand); setOperationAction(ISD::FSQRT, MVT::f32, Expand); } - + setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand); setOperationAction(ISD::FCOPYSIGN, MVT::f32, Expand); - + // PowerPC does not have BSWAP, CTPOP or CTTZ setOperationAction(ISD::BSWAP, MVT::i32 , Expand); setOperationAction(ISD::CTPOP, MVT::i32 , Expand); @@ -121,29 +121,29 @@ setOperationAction(ISD::BSWAP, MVT::i64 , Expand); setOperationAction(ISD::CTPOP, MVT::i64 , Expand); setOperationAction(ISD::CTTZ , MVT::i64 , Expand); - + // PowerPC does not have ROTR setOperationAction(ISD::ROTR, MVT::i32 , Expand); setOperationAction(ISD::ROTR, MVT::i64 , Expand); - + // PowerPC does not have Select setOperationAction(ISD::SELECT, MVT::i32, Expand); setOperationAction(ISD::SELECT, MVT::i64, Expand); setOperationAction(ISD::SELECT, MVT::f32, Expand); setOperationAction(ISD::SELECT, MVT::f64, Expand); - + // PowerPC wants to turn select_cc of FP into fsel when possible. setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); // PowerPC wants to optimize integer setcc a bit setOperationAction(ISD::SETCC, MVT::i32, Custom); - + // PowerPC does not have BRCOND which requires SetCC setOperationAction(ISD::BRCOND, MVT::Other, Expand); setOperationAction(ISD::BR_JT, MVT::Other, Expand); - + // PowerPC turns FP_TO_SINT into FCTIWZ and some load/stores. setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); @@ -162,14 +162,14 @@ // Support label based line numbers. setOperationAction(ISD::DBG_STOPPOINT, MVT::Other, Expand); setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand); - + setOperationAction(ISD::EXCEPTIONADDR, MVT::i64, Expand); setOperationAction(ISD::EHSELECTION, MVT::i64, Expand); setOperationAction(ISD::EXCEPTIONADDR, MVT::i32, Expand); setOperationAction(ISD::EHSELECTION, MVT::i32, Expand); - - - // We want to legalize GlobalAddress and ConstantPool nodes into the + + + // We want to legalize GlobalAddress and ConstantPool nodes into the // appropriate instructions to materialize the address. setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); @@ -179,7 +179,7 @@ setOperationAction(ISD::GlobalTLSAddress, MVT::i64, Custom); setOperationAction(ISD::ConstantPool, MVT::i64, Custom); setOperationAction(ISD::JumpTable, MVT::i64, Custom); - + // RET must be custom lowered, to meet ABI requirements. setOperationAction(ISD::RET , MVT::Other, Custom); @@ -191,24 +191,24 @@ // VASTART needs to be custom lowered to use the VarArgsFrameIndex setOperationAction(ISD::VASTART , MVT::Other, Custom); - + // VAARG is custom lowered with ELF 32 ABI if (TM.getSubtarget().isELF32_ABI()) setOperationAction(ISD::VAARG, MVT::Other, Custom); else setOperationAction(ISD::VAARG, MVT::Other, Expand); - + // Use the default implementation. setOperationAction(ISD::VACOPY , MVT::Other, Expand); setOperationAction(ISD::VAEND , MVT::Other, Expand); - setOperationAction(ISD::STACKSAVE , MVT::Other, Expand); + setOperationAction(ISD::STACKSAVE , MVT::Other, Expand); setOperationAction(ISD::STACKRESTORE , MVT::Other, Custom); setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32 , Custom); setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64 , Custom); // We want to custom lower some of our intrinsics. setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); - + // Comparisons that require checking two conditions. setCondCodeAction(ISD::SETULT, MVT::f32, Expand); setCondCodeAction(ISD::SETULT, MVT::f64, Expand); @@ -222,7 +222,7 @@ setCondCodeAction(ISD::SETOLE, MVT::f64, Expand); setCondCodeAction(ISD::SETONE, MVT::f32, Expand); setCondCodeAction(ISD::SETONE, MVT::f64, Expand); - + if (TM.getSubtarget().has64BitSupport()) { // They also have instructions for converting between i64 and fp. setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom); @@ -230,12 +230,12 @@ setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom); setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand); setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand); - + // FIXME: disable this lowered code. This generates 64-bit register values, // and we don't model the fact that the top part is clobbered by calls. We // need to flag these together so that the value isn't live across a call. //setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); - + // To take advantage of the above i64 FP_TO_SINT, promote i32 FP_TO_UINT setOperationAction(ISD::FP_TO_UINT, MVT::i32, Promote); } else { @@ -269,7 +269,7 @@ // add/sub are legal for all supported vector VT's. setOperationAction(ISD::ADD , VT, Legal); setOperationAction(ISD::SUB , VT, Legal); - + // We promote all shuffles to v16i8. setOperationAction(ISD::VECTOR_SHUFFLE, VT, Promote); AddPromotedToType (ISD::VECTOR_SHUFFLE, VT, MVT::v16i8); @@ -287,7 +287,7 @@ AddPromotedToType (ISD::SELECT, VT, MVT::v4i32); setOperationAction(ISD::STORE, VT, Promote); AddPromotedToType (ISD::STORE, VT, MVT::v4i32); - + // No other operations are legal. setOperationAction(ISD::MUL , VT, Expand); setOperationAction(ISD::SDIV, VT, Expand); @@ -320,12 +320,12 @@ setOperationAction(ISD::LOAD , MVT::v4i32, Legal); setOperationAction(ISD::SELECT, MVT::v4i32, Expand); setOperationAction(ISD::STORE , MVT::v4i32, Legal); - + addRegisterClass(MVT::v4f32, PPC::VRRCRegisterClass); addRegisterClass(MVT::v4i32, PPC::VRRCRegisterClass); addRegisterClass(MVT::v8i16, PPC::VRRCRegisterClass); addRegisterClass(MVT::v16i8, PPC::VRRCRegisterClass); - + setOperationAction(ISD::MUL, MVT::v4f32, Legal); setOperationAction(ISD::MUL, MVT::v4i32, Custom); setOperationAction(ISD::MUL, MVT::v8i16, Custom); @@ -333,16 +333,16 @@ setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4f32, Custom); setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4i32, Custom); - + setOperationAction(ISD::BUILD_VECTOR, MVT::v16i8, Custom); setOperationAction(ISD::BUILD_VECTOR, MVT::v8i16, Custom); setOperationAction(ISD::BUILD_VECTOR, MVT::v4i32, Custom); setOperationAction(ISD::BUILD_VECTOR, MVT::v4f32, Custom); } - + setShiftAmountType(MVT::i32); setBooleanContents(ZeroOrOneBooleanContent); - + if (TM.getSubtarget().isPPC64()) { setStackPointerRegisterToSaveRestore(PPC::X1); setExceptionPointerRegister(PPC::X3); @@ -352,13 +352,13 @@ setExceptionPointerRegister(PPC::R3); setExceptionSelectorRegister(PPC::R4); } - + // We have target-specific dag combine patterns for the following nodes: setTargetDAGCombine(ISD::SINT_TO_FP); setTargetDAGCombine(ISD::STORE); setTargetDAGCombine(ISD::BR_CC); setTargetDAGCombine(ISD::BSWAP); - + // Darwin long double math library functions have $LDBL128 appended. if (TM.getSubtarget().isDarwin()) { setLibcallName(RTLIB::COS_PPCF128, "cosl$LDBL128"); @@ -457,7 +457,7 @@ /// isConstantOrUndef - Op is either an undef node or a ConstantSDNode. Return /// true if Op is undef or if it matches the specified value. static bool isConstantOrUndef(SDValue Op, unsigned Val) { - return Op.getOpcode() == ISD::UNDEF || + return Op.getOpcode() == ISD::UNDEF || cast(Op)->getZExtValue() == Val; } @@ -498,13 +498,13 @@ /// isVMerge - Common function, used to match vmrg* shuffles. /// -static bool isVMerge(SDNode *N, unsigned UnitSize, +static bool isVMerge(SDNode *N, unsigned UnitSize, unsigned LHSStart, unsigned RHSStart) { assert(N->getOpcode() == ISD::BUILD_VECTOR && N->getNumOperands() == 16 && "PPC only supports shuffles by bytes!"); assert((UnitSize == 1 || UnitSize == 2 || UnitSize == 4) && "Unsupported merge size!"); - + for (unsigned i = 0; i != 8/UnitSize; ++i) // Step over units for (unsigned j = 0; j != UnitSize; ++j) { // Step over bytes within unit if (!isConstantOrUndef(N->getOperand(i*UnitSize*2+j), @@ -542,9 +542,9 @@ unsigned i; for (i = 0; i != 16 && N->getOperand(i).getOpcode() == ISD::UNDEF; ++i) /*search*/; - + if (i == 16) return -1; // all undef. - + // Otherwise, check to see if the rest of the elements are consequtively // numbered from this value. unsigned ShiftAmt = cast(N->getOperand(i))->getZExtValue(); @@ -562,7 +562,7 @@ if (!isConstantOrUndef(N->getOperand(i), (ShiftAmt+i) & 15)) return -1; } - + return ShiftAmt; } @@ -573,7 +573,7 @@ assert(N->getOpcode() == ISD::BUILD_VECTOR && N->getNumOperands() == 16 && (EltSize == 1 || EltSize == 2 || EltSize == 4)); - + // This is a splat operation if each element of the permute is the same, and // if the value doesn't reference the second vector. unsigned ElementBase = 0; @@ -585,14 +585,14 @@ if (cast(Elt)->getZExtValue() >= 16) return false; - + // Check that they are consequtive. for (unsigned i = 1; i != EltSize; ++i) { if (!isa(N->getOperand(i)) || cast(N->getOperand(i))->getZExtValue() != i+ElementBase) return false; } - + assert(isa(Elt) && "Invalid VECTOR_SHUFFLE mask!"); for (unsigned i = EltSize, e = 16; i != e; i += EltSize) { if (N->getOperand(i).getOpcode() == ISD::UNDEF) continue; @@ -639,31 +639,31 @@ unsigned Multiple = ByteSize/EltSize; // Number of BV entries per spltval. SDValue UniquedVals[4]; assert(Multiple > 1 && Multiple <= 4 && "How can this happen?"); - + // See if all of the elements in the buildvector agree across. for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { if (N->getOperand(i).getOpcode() == ISD::UNDEF) continue; // If the element isn't a constant, bail fully out. if (!isa(N->getOperand(i))) return SDValue(); - + if (UniquedVals[i&(Multiple-1)].getNode() == 0) UniquedVals[i&(Multiple-1)] = N->getOperand(i); else if (UniquedVals[i&(Multiple-1)] != N->getOperand(i)) return SDValue(); // no match. } - + // Okay, if we reached this point, UniquedVals[0..Multiple-1] contains // either constant or undef values that are identical for each chunk. See // if these chunks can form into a larger vspltis*. - + // Check to see if all of the leading entries are either 0 or -1. If // neither, then this won't fit into the immediate field. bool LeadingZero = true; bool LeadingOnes = true; for (unsigned i = 0; i != Multiple-1; ++i) { if (UniquedVals[i].getNode() == 0) continue; // Must have been undefs. - + LeadingZero &= cast(UniquedVals[i])->isNullValue(); LeadingOnes &= cast(UniquedVals[i])->isAllOnesValue(); } @@ -682,10 +682,10 @@ if (Val >= -16) // -1,-1,-1,-2 -> vspltisw(-2) return DAG.getTargetConstant(Val, MVT::i32); } - + return SDValue(); } - + // Check to see if this buildvec has a single non-undef value in its elements. for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { if (N->getOperand(i).getOpcode() == ISD::UNDEF) continue; @@ -694,9 +694,9 @@ else if (OpVal != N->getOperand(i)) return SDValue(); } - + if (OpVal.getNode() == 0) return SDValue(); // All UNDEF: use implicit def. - + unsigned ValSizeInBytes = 0; uint64_t Value = 0; if (ConstantSDNode *CN = dyn_cast(OpVal)) { @@ -712,13 +712,13 @@ // this splat. The only case that we could fit the replicated bits into our // immediate field for would be zero, and we prefer to use vxor for it. if (ValSizeInBytes < ByteSize) return SDValue(); - + // If the element value is larger than the splat value, cut it in half and // check to see if the two halves are equal. Continue doing this until we // get to ByteSize. This allows us to handle 0x01010101 as 0x01. while (ValSizeInBytes > ByteSize) { ValSizeInBytes >>= 1; - + // If the top half equals the bottom half, we're still ok. if (((Value >> (ValSizeInBytes*8)) & ((1 << (8*ValSizeInBytes))-1)) != (Value & ((1 << (8*ValSizeInBytes))-1))) @@ -728,7 +728,7 @@ // Properly sign extend the value. int ShAmt = (4-ByteSize)*8; int MaskVal = ((int)Value << ShAmt) >> ShAmt; - + // If this is zero, don't match, zero matches ISD::isBuildVectorAllZeros. if (MaskVal == 0) return SDValue(); @@ -749,7 +749,7 @@ static bool isIntS16Immediate(SDNode *N, short &Imm) { if (N->getOpcode() != ISD::Constant) return false; - + Imm = (short)cast(N)->getZExtValue(); if (N->getValueType(0) == MVT::i32) return Imm == (int32_t)cast(N)->getZExtValue(); @@ -773,14 +773,14 @@ return false; // r+i if (N.getOperand(1).getOpcode() == PPCISD::Lo) return false; // r+i - + Base = N.getOperand(0); Index = N.getOperand(1); return true; } else if (N.getOpcode() == ISD::OR) { if (isIntS16Immediate(N.getOperand(1), imm)) return false; // r+i can fold it if we can. - + // If this is an or of disjoint bitfields, we can codegen this as an add // (for better address arithmetic) if the LHS and RHS of the OR are provably // disjoint. @@ -790,7 +790,7 @@ APInt::getAllOnesValue(N.getOperand(0) .getValueSizeInBits()), LHSKnownZero, LHSKnownOne); - + if (LHSKnownZero.getBoolValue()) { DAG.ComputeMaskedBits(N.getOperand(1), APInt::getAllOnesValue(N.getOperand(1) @@ -805,7 +805,7 @@ } } } - + return false; } @@ -820,7 +820,7 @@ // If this can be more profitably realized as r+r, fail. if (SelectAddressRegReg(N, Disp, Base, DAG)) return false; - + if (N.getOpcode() == ISD::ADD) { short imm = 0; if (isIntS16Immediate(N.getOperand(1), imm)) { @@ -864,7 +864,7 @@ } } else if (ConstantSDNode *CN = dyn_cast(N)) { // Loading from a constant address. - + // If this address fits entirely in a 16-bit sext immediate field, codegen // this as "d, 0" short Imm; @@ -878,17 +878,17 @@ if (CN->getValueType(0) == MVT::i32 || (int64_t)CN->getZExtValue() == (int)CN->getZExtValue()) { int Addr = (int)CN->getZExtValue(); - + // Otherwise, break this down into an LIS + disp. Disp = DAG.getTargetConstant((short)Addr, MVT::i32); - + Base = DAG.getTargetConstant((Addr - (signed short)Addr) >> 16, MVT::i32); unsigned Opc = CN->getValueType(0) == MVT::i32 ? PPC::LIS : PPC::LIS8; Base = SDValue(DAG.getTargetNode(Opc, dl, CN->getValueType(0), Base), 0); return true; } } - + Disp = DAG.getTargetConstant(0, getPointerTy()); if (FrameIndexSDNode *FI = dyn_cast(N)) Base = DAG.getTargetFrameIndex(FI->getIndex(), N.getValueType()); @@ -907,7 +907,7 @@ // reg+imm, e.g. where imm = 0. if (SelectAddressRegReg(N, Base, Index, DAG)) return true; - + // If the operand is an addition, always emit this as [r+r], since this is // better (for code size, and execution, as the memop does the add for free) // than emitting an explicit add. @@ -916,7 +916,7 @@ Index = N.getOperand(1); return true; } - + // Otherwise, do it the hard way, using R0 as the base register. Base = DAG.getRegister(PPC::R0, N.getValueType()); Index = N; @@ -934,7 +934,7 @@ // If this can be more profitably realized as r+r, fail. if (SelectAddressRegReg(N, Disp, Base, DAG)) return false; - + if (N.getOpcode() == ISD::ADD) { short imm = 0; if (isIntS16Immediate(N.getOperand(1), imm) && (imm & 3) == 0) { @@ -986,12 +986,12 @@ Base = DAG.getRegister(PPC::R0, CN->getValueType(0)); return true; } - + // Fold the low-part of 32-bit absolute addresses into addr mode. if (CN->getValueType(0) == MVT::i32 || (int64_t)CN->getZExtValue() == (int)CN->getZExtValue()) { int Addr = (int)CN->getZExtValue(); - + // Otherwise, break this down into an LIS + disp. Disp = DAG.getTargetConstant((short)Addr >> 2, MVT::i32); Base = DAG.getTargetConstant((Addr-(signed short)Addr) >> 16, MVT::i32); @@ -1001,7 +1001,7 @@ } } } - + Disp = DAG.getTargetConstant(0, getPointerTy()); if (FrameIndexSDNode *FI = dyn_cast(N)) Base = DAG.getTargetFrameIndex(FI->getIndex(), N.getValueType()); @@ -1020,13 +1020,13 @@ SelectionDAG &DAG) const { // Disabled by default for now. if (!EnablePPCPreinc) return false; - + SDValue Ptr; MVT VT; if (LoadSDNode *LD = dyn_cast(N)) { Ptr = LD->getBasePtr(); VT = LD->getMemoryVT(); - + } else if (StoreSDNode *ST = dyn_cast(N)) { ST = ST; Ptr = ST->getBasePtr(); @@ -1037,9 +1037,9 @@ // PowerPC doesn't have preinc load/store instructions for vectors. if (VT.isVector()) return false; - + // TODO: Check reg+reg first. - + // LDU/STU use reg+imm*4, others use reg+imm. if (VT != MVT::i64) { // reg + imm @@ -1058,8 +1058,8 @@ LD->getExtensionType() == ISD::SEXTLOAD && isa(Offset)) return false; - } - + } + AM = ISD::PRE_INC; return true; } @@ -1068,7 +1068,7 @@ // LowerOperation implementation //===----------------------------------------------------------------------===// -SDValue PPCTargetLowering::LowerConstantPool(SDValue Op, +SDValue PPCTargetLowering::LowerConstantPool(SDValue Op, SelectionDAG &DAG) { MVT PtrVT = Op.getValueType(); ConstantPoolSDNode *CP = cast(Op); @@ -1079,7 +1079,7 @@ DebugLoc dl = Op.getDebugLoc(); const TargetMachine &TM = DAG.getTarget(); - + SDValue Hi = DAG.getNode(PPCISD::Hi, dl, PtrVT, CPI, Zero); SDValue Lo = DAG.getNode(PPCISD::Lo, dl, PtrVT, CPI, Zero); @@ -1091,14 +1091,14 @@ // The address of the global is just (hi(&g)+lo(&g)). return DAG.getNode(ISD::ADD, dl, PtrVT, Hi, Lo); } - + if (TM.getRelocationModel() == Reloc::PIC_) { // With PIC, the first instruction is actually "GR+hi(&G)". Hi = DAG.getNode(ISD::ADD, dl, PtrVT, - DAG.getNode(PPCISD::GlobalBaseReg, + DAG.getNode(PPCISD::GlobalBaseReg, DebugLoc::getUnknownLoc(), PtrVT), Hi); } - + Lo = DAG.getNode(ISD::ADD, dl, PtrVT, Hi, Lo); return Lo; } @@ -1110,7 +1110,7 @@ SDValue Zero = DAG.getConstant(0, PtrVT); // FIXME there isn't really any debug loc here DebugLoc dl = Op.getDebugLoc(); - + const TargetMachine &TM = DAG.getTarget(); SDValue Hi = DAG.getNode(PPCISD::Hi, dl, PtrVT, JTI, Zero); @@ -1124,25 +1124,25 @@ // The address of the global is just (hi(&g)+lo(&g)). return DAG.getNode(ISD::ADD, dl, PtrVT, Hi, Lo); } - + if (TM.getRelocationModel() == Reloc::PIC_) { // With PIC, the first instruction is actually "GR+hi(&G)". Hi = DAG.getNode(ISD::ADD, dl, PtrVT, - DAG.getNode(PPCISD::GlobalBaseReg, + DAG.getNode(PPCISD::GlobalBaseReg, DebugLoc::getUnknownLoc(), PtrVT), Hi); } - + Lo = DAG.getNode(ISD::ADD, dl, PtrVT, Hi, Lo); return Lo; } -SDValue PPCTargetLowering::LowerGlobalTLSAddress(SDValue Op, +SDValue PPCTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) { assert(0 && "TLS not implemented for PPC."); return SDValue(); // Not reached } -SDValue PPCTargetLowering::LowerGlobalAddress(SDValue Op, +SDValue PPCTargetLowering::LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) { MVT PtrVT = Op.getValueType(); GlobalAddressSDNode *GSDN = cast(Op); @@ -1151,7 +1151,7 @@ SDValue Zero = DAG.getConstant(0, PtrVT); // FIXME there isn't really any debug info here DebugLoc dl = GSDN->getDebugLoc(); - + const TargetMachine &TM = DAG.getTarget(); SDValue Hi = DAG.getNode(PPCISD::Hi, dl, PtrVT, GA, Zero); @@ -1165,19 +1165,19 @@ // The address of the global is just (hi(&g)+lo(&g)). return DAG.getNode(ISD::ADD, dl, PtrVT, Hi, Lo); } - + if (TM.getRelocationModel() == Reloc::PIC_) { // With PIC, the first instruction is actually "GR+hi(&G)". Hi = DAG.getNode(ISD::ADD, dl, PtrVT, - DAG.getNode(PPCISD::GlobalBaseReg, + DAG.getNode(PPCISD::GlobalBaseReg, DebugLoc::getUnknownLoc(), PtrVT), Hi); } - + Lo = DAG.getNode(ISD::ADD, dl, PtrVT, Hi, Lo); - + if (!TM.getSubtarget().hasLazyResolverStub(GV)) return Lo; - + // If the global is weak or external, we have to go through the lazy // resolution stub. return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Lo, NULL, 0); @@ -1186,7 +1186,7 @@ SDValue PPCTargetLowering::LowerSETCC(SDValue Op, SelectionDAG &DAG) { ISD::CondCode CC = cast(Op.getOperand(2))->get(); DebugLoc dl = Op.getDebugLoc(); - + // If we're comparing for equality to zero, expose the fact that this is // implented as a ctlz/srl pair on ppc, so that the dag combiner can // fold the new nodes. @@ -1197,20 +1197,20 @@ if (VT.bitsLT(MVT::i32)) { VT = MVT::i32; Zext = DAG.getNode(ISD::ZERO_EXTEND, dl, VT, Op.getOperand(0)); - } + } unsigned Log2b = Log2_32(VT.getSizeInBits()); SDValue Clz = DAG.getNode(ISD::CTLZ, dl, VT, Zext); SDValue Scc = DAG.getNode(ISD::SRL, dl, VT, Clz, DAG.getConstant(Log2b, MVT::i32)); return DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, Scc); } - // Leave comparisons against 0 and -1 alone for now, since they're usually + // Leave comparisons against 0 and -1 alone for now, since they're usually // optimized. FIXME: revisit this when we can custom lower all setcc // optimizations. if (C->isAllOnesValue() || C->isNullValue()) return SDValue(); } - + // If we have an integer seteq/setne, turn it into a compare against zero // by xor'ing the rhs with the lhs, which is faster than setting a // condition register, reading it back out, and masking the correct bit. The @@ -1219,7 +1219,7 @@ MVT LHSVT = Op.getOperand(0).getValueType(); if (LHSVT.isInteger() && (CC == ISD::SETEQ || CC == ISD::SETNE)) { MVT VT = Op.getValueType(); - SDValue Sub = DAG.getNode(ISD::XOR, dl, LHSVT, Op.getOperand(0), + SDValue Sub = DAG.getNode(ISD::XOR, dl, LHSVT, Op.getOperand(0), Op.getOperand(1)); return DAG.getSetCC(dl, VT, Sub, DAG.getConstant(0, LHSVT), CC); } @@ -1232,7 +1232,7 @@ unsigned VarArgsNumGPR, unsigned VarArgsNumFPR, const PPCSubtarget &Subtarget) { - + assert(0 && "VAARG in ELF32 ABI not implemented yet!"); return SDValue(); // Not reached } @@ -1249,7 +1249,7 @@ const Type *IntPtrTy = DAG.getTargetLoweringInfo().getTargetData()->getIntPtrType(); - TargetLowering::ArgListTy Args; + TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; Entry.Ty = IntPtrTy; @@ -1262,7 +1262,7 @@ Entry.Node = FPtr; Args.push_back(Entry); Entry.Node = Nest; Args.push_back(Entry); - + // Lower to a call to __trampoline_setup(Trmp, TrampSize, FPtr, ctx_reg) std::pair CallResult = LowerCallTo(Chain, Op.getValueType().getTypeForMVT(), false, false, @@ -1320,13 +1320,13 @@ SDValue ArgGPR = DAG.getConstant(VarArgsNumGPR, MVT::i8); SDValue ArgFPR = DAG.getConstant(VarArgsNumFPR, MVT::i8); - + MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); - + SDValue StackOffsetFI = DAG.getFrameIndex(VarArgsStackOffset, PtrVT); SDValue FR = DAG.getFrameIndex(VarArgsFrameIndex, PtrVT); - + uint64_t FrameOffset = PtrVT.getSizeInBits()/8; SDValue ConstFrameOffset = DAG.getConstant(FrameOffset, PtrVT); @@ -1335,22 +1335,22 @@ uint64_t FPROffset = 1; SDValue ConstFPROffset = DAG.getConstant(FPROffset, PtrVT); - + const Value *SV = cast(Op.getOperand(2))->getValue(); - + // Store first byte : number of int regs SDValue firstStore = DAG.getStore(Op.getOperand(0), dl, ArgGPR, Op.getOperand(1), SV, 0); uint64_t nextOffset = FPROffset; SDValue nextPtr = DAG.getNode(ISD::ADD, dl, PtrVT, Op.getOperand(1), ConstFPROffset); - + // Store second byte : number of float regs SDValue secondStore = DAG.getStore(firstStore, dl, ArgFPR, nextPtr, SV, nextOffset); nextOffset += StackOffset; nextPtr = DAG.getNode(ISD::ADD, dl, PtrVT, nextPtr, ConstStackOffset); - + // Store second word : arguments given on stack SDValue thirdStore = DAG.getStore(secondStore, dl, StackOffsetFI, nextPtr, SV, nextOffset); @@ -1374,8 +1374,8 @@ }; return FPR; } - - + + static const unsigned FPR[] = { PPC::F1, PPC::F2, PPC::F3, PPC::F4, PPC::F5, PPC::F6, PPC::F7, PPC::F8 @@ -1397,7 +1397,7 @@ } SDValue -PPCTargetLowering::LowerFORMAL_ARGUMENTS(SDValue Op, +PPCTargetLowering::LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG, int &VarArgsFrameIndex, int &VarArgsStackOffset, @@ -1413,7 +1413,7 @@ SDValue Root = Op.getOperand(0); bool isVarArg = cast(Op.getOperand(2))->getZExtValue() != 0; DebugLoc dl = Op.getDebugLoc(); - + MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); bool isPPC64 = PtrVT == MVT::i64; bool isMachoABI = Subtarget.isMachoABI(); @@ -1435,9 +1435,9 @@ PPC::X3, PPC::X4, PPC::X5, PPC::X6, PPC::X7, PPC::X8, PPC::X9, PPC::X10, }; - + static const unsigned *FPR = GetFPR(Subtarget); - + static const unsigned VR[] = { PPC::V2, PPC::V3, PPC::V4, PPC::V5, PPC::V6, PPC::V7, PPC::V8, PPC::V9, PPC::V10, PPC::V11, PPC::V12, PPC::V13 @@ -1448,13 +1448,13 @@ const unsigned Num_VR_Regs = array_lengthof( VR); unsigned GPR_idx = 0, FPR_idx = 0, VR_idx = 0; - + const unsigned *GPR = isPPC64 ? GPR_64 : GPR_32; - + // In 32-bit non-varargs functions, the stack space for vectors is after the // stack space for non-vectors. We do not use this space unless we have // too many vectors to fit in registers, something that only occurs in - // constructed examples:), but we have to walk the arglist to figure + // constructed examples:), but we have to walk the arglist to figure // that out...for the pathological case, compute VecArgOffset as the // start of the vector parameter area. Computing VecArgOffset is the // entire point of the following loop. @@ -1462,7 +1462,7 @@ // to handle Elf here. unsigned VecArgOffset = ArgOffset; if (!isVarArg && !isPPC64) { - for (unsigned ArgNo = 0, e = Op.getNode()->getNumValues()-1; ArgNo != e; + for (unsigned ArgNo = 0, e = Op.getNode()->getNumValues()-1; ArgNo != e; ++ArgNo) { MVT ObjectVT = Op.getValue(ArgNo).getValueType(); unsigned ObjSize = ObjectVT.getSizeInBits()/8; @@ -1472,7 +1472,7 @@ if (Flags.isByVal()) { // ObjSize is the true size, ArgSize rounded up to multiple of regs. ObjSize = Flags.getByValSize(); - unsigned ArgSize = + unsigned ArgSize = ((ObjSize + PtrByteSize - 1)/PtrByteSize) * PtrByteSize; VecArgOffset += ArgSize; continue; @@ -1505,7 +1505,7 @@ // Add DAG nodes to load the arguments or copy them out of registers. On // entry to a function on PPC, the arguments start after the linkage area, // although the first ones are often in registers. - // + // // In the ELF 32 ABI, GPRs and stack are double word align: an argument // represented with two words (long long or double) must be copied to an // even GPR_idx value or to an even ArgOffset value. @@ -1522,7 +1522,7 @@ ISD::ArgFlagsTy Flags = cast(Op.getOperand(ArgNo+3))->getArgFlags(); // See if next argument requires stack alignment in ELF - bool Align = Flags.isSplit(); + bool Align = Flags.isSplit(); unsigned CurArgOffset = ArgOffset; @@ -1566,7 +1566,7 @@ unsigned VReg = RegInfo.createVirtualRegister(&PPC::GPRCRegClass); RegInfo.addLiveIn(GPR[GPR_idx], VReg); SDValue Val = DAG.getCopyFromReg(Root, dl, VReg, PtrVT); - SDValue Store = DAG.getTruncStore(Val.getValue(1), dl, Val, FIN, + SDValue Store = DAG.getTruncStore(Val.getValue(1), dl, Val, FIN, NULL, 0, ObjSize==1 ? MVT::i8 : MVT::i16 ); MemOps.push_back(Store); ++GPR_idx; @@ -1615,7 +1615,7 @@ ArgSize = PtrByteSize; } // Stack align in ELF - if (needsLoad && Align && isELF32_ABI) + if (needsLoad && Align && isELF32_ABI) ArgOffset += ((ArgOffset/4) % 2) * PtrByteSize; // All int arguments reserve stack space in Macho ABI. if (isMachoABI || needsLoad) ArgOffset += PtrByteSize; @@ -1649,7 +1649,7 @@ // All int arguments reserve stack space in Macho ABI. if (isMachoABI || needsLoad) ArgOffset += 8; break; - + case MVT::f32: case MVT::f64: // Every 4 bytes of argument space consumes one of the GPRs available for @@ -1671,7 +1671,7 @@ } else { needsLoad = true; } - + // Stack align in ELF if (needsLoad && Align && isELF32_ABI) ArgOffset += ((ArgOffset/4) % 2) * PtrByteSize; @@ -1713,7 +1713,7 @@ } break; } - + // We need to load the argument to a virtual register if we determined above // that we ran out of physical registers of the appropriate type. if (needsLoad) { @@ -1723,7 +1723,7 @@ SDValue FIN = DAG.getFrameIndex(FI, PtrVT); ArgVal = DAG.getLoad(ObjectVT, dl, Root, FIN, NULL, 0); } - + ArgValues.push_back(ArgVal); } @@ -1749,29 +1749,29 @@ // If the function takes variable number of arguments, make a frame index for // the start of the first vararg value... for expansion of llvm.va_start. if (isVarArg) { - + int depth; if (isELF32_ABI) { VarArgsNumGPR = GPR_idx; VarArgsNumFPR = FPR_idx; - + // Make room for Num_GPR_Regs, Num_FPR_Regs and for a possible frame // pointer. depth = -(Num_GPR_Regs * PtrVT.getSizeInBits()/8 + Num_FPR_Regs * MVT(MVT::f64).getSizeInBits()/8 + PtrVT.getSizeInBits()/8); - + VarArgsStackOffset = MFI->CreateFixedObject(PtrVT.getSizeInBits()/8, ArgOffset); } else depth = ArgOffset; - + VarArgsFrameIndex = MFI->CreateFixedObject(PtrVT.getSizeInBits()/8, depth); SDValue FIN = DAG.getFrameIndex(VarArgsFrameIndex, PtrVT); - + // In ELF 32 ABI, the fixed integer arguments of a variadic function are // stored to the VarArgsFrameIndex on the stack. if (isELF32_ABI) { @@ -1832,13 +1832,13 @@ } } } - + if (!MemOps.empty()) - Root = DAG.getNode(ISD::TokenFactor, dl, + Root = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &MemOps[0], MemOps.size()); ArgValues.push_back(Root); - + // Return the new list of results. return DAG.getNode(ISD::MERGE_VALUES, dl, Op.getNode()->getVTList(), &ArgValues[0], ArgValues.size()); @@ -1973,12 +1973,12 @@ static SDNode *isBLACompatibleAddress(SDValue Op, SelectionDAG &DAG) { ConstantSDNode *C = dyn_cast(Op); if (!C) return 0; - + int Addr = C->getZExtValue(); if ((Addr & 3) != 0 || // Low 2 bits are implicitly zero. (Addr << 6 >> 6) != Addr) return 0; // Top 6 bits have to be sext of immediate. - + return DAG.getConstant((int)C->getZExtValue() >> 2, DAG.getTargetLoweringInfo().getPointerTy()).getNode(); } @@ -2087,12 +2087,12 @@ } /// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified -/// by "Src" to address "Dst" of size "Size". Alignment information is +/// by "Src" to address "Dst" of size "Size". Alignment information is /// specified by the specific parameter attribute. The copy will be passed as /// a byval function parameter. /// Sometimes what we are copying is the end of a larger object, the part that /// does not fit in registers. -static SDValue +static SDValue CreateCopyOfByValArgument(SDValue Src, SDValue Dst, SDValue Chain, ISD::ArgFlagsTy Flags, SelectionDAG &DAG, unsigned Size, DebugLoc dl) { @@ -2139,20 +2139,20 @@ SDValue Callee = TheCall->getCallee(); unsigned NumOps = TheCall->getNumArgs(); DebugLoc dl = TheCall->getDebugLoc(); - + bool isMachoABI = Subtarget.isMachoABI(); bool isELF32_ABI = Subtarget.isELF32_ABI(); MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); bool isPPC64 = PtrVT == MVT::i64; unsigned PtrByteSize = isPPC64 ? 8 : 4; - + MachineFunction &MF = DAG.getMachineFunction(); // args_to_use will accumulate outgoing args for the PPCISD::CALL case in // SelectExpr to use to put the arguments in the appropriate registers. std::vector args_to_use; - + // Mark this function as potentially containing a function that contains a // tail call. As a consequence the frame pointer will be used for dynamicalloc // and restoring the callers stack pointer in this functions epilog. This is @@ -2173,12 +2173,12 @@ // Calculate by how many bytes the stack has to be adjusted in case of tail // call optimization. int SPDiff = CalculateTailCallSPDiff(DAG, isTailCall, NumBytes); - + // Adjust the stack pointer for the new arguments... // These operations are automatically eliminated by the prolog/epilog pass Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); SDValue CallSeqStart = Chain; - + // Load the return address and frame pointer so it can be move somewhere else // later. SDValue LROp, FPOp; @@ -2192,14 +2192,14 @@ StackPtr = DAG.getRegister(PPC::X1, MVT::i64); else StackPtr = DAG.getRegister(PPC::R1, MVT::i32); - + // Figure out which arguments are going to go in registers, and which in // memory. Also, if this is a vararg function, floating point operations // must be stored to our stack, and loaded into integer regs as well, if // any integer regs are available for argument passing. unsigned ArgOffset = PPCFrameInfo::getLinkageSize(isPPC64, isMachoABI); unsigned GPR_idx = 0, FPR_idx = 0, VR_idx = 0; - + static const unsigned GPR_32[] = { // 32-bit registers. PPC::R3, PPC::R4, PPC::R5, PPC::R6, PPC::R7, PPC::R8, PPC::R9, PPC::R10, @@ -2209,7 +2209,7 @@ PPC::X7, PPC::X8, PPC::X9, PPC::X10, }; static const unsigned *FPR = GetFPR(Subtarget); - + static const unsigned VR[] = { PPC::V2, PPC::V3, PPC::V4, PPC::V5, PPC::V6, PPC::V7, PPC::V8, PPC::V9, PPC::V10, PPC::V11, PPC::V12, PPC::V13 @@ -2217,7 +2217,7 @@ const unsigned NumGPRs = array_lengthof(GPR_32); const unsigned NumFPRs = isMachoABI ? 13 : 8; const unsigned NumVRs = array_lengthof( VR); - + const unsigned *GPR = isPPC64 ? GPR_64 : GPR_32; std::vector > RegsToPass; @@ -2234,7 +2234,7 @@ // PtrOff will be used to store the current argument to the stack if a // register cannot be found for it. SDValue PtrOff; - + // Stack align in ELF 32 if (isELF32_ABI && Align) PtrOff = DAG.getConstant(ArgOffset + ((ArgOffset/4) % 2) * PtrByteSize, @@ -2261,7 +2261,7 @@ // Everything else is passed left-justified. MVT VT = (Size==1) ? MVT::i8 : MVT::i16; if (GPR_idx != NumGPRs) { - SDValue Load = DAG.getExtLoad(ISD::EXTLOAD, dl, PtrVT, Chain, Arg, + SDValue Load = DAG.getExtLoad(ISD::EXTLOAD, dl, PtrVT, Chain, Arg, NULL, 0, VT); MemOpChains.push_back(Load.getValue(1)); RegsToPass.push_back(std::make_pair(GPR[GPR_idx++], Load)); @@ -2271,7 +2271,7 @@ SDValue Const = DAG.getConstant(4 - Size, PtrOff.getValueType()); SDValue AddPtr = DAG.getNode(ISD::ADD, dl, PtrVT, PtrOff, Const); SDValue MemcpyCall = CreateCopyOfByValArgument(Arg, AddPtr, - CallSeqStart.getNode()->getOperand(0), + CallSeqStart.getNode()->getOperand(0), Flags, DAG, Size, dl); // This must go outside the CALLSEQ_START..END. SDValue NewCallSeqStart = DAG.getCALLSEQ_START(MemcpyCall, @@ -2287,7 +2287,7 @@ // code assumes it is there, even if it could be put entirely into // registers. (This is not what the doc says.) SDValue MemcpyCall = CreateCopyOfByValArgument(Arg, PtrOff, - CallSeqStart.getNode()->getOperand(0), + CallSeqStart.getNode()->getOperand(0), Flags, DAG, Size, dl); // This must go outside the CALLSEQ_START..END. SDValue NewCallSeqStart = DAG.getCALLSEQ_START(MemcpyCall, @@ -2392,7 +2392,7 @@ case MVT::v16i8: if (isVarArg) { // These go aligned on the stack, or in the corresponding R registers - // when within range. The Darwin PPC ABI doc claims they also go in + // when within range. The Darwin PPC ABI doc claims they also go in // V registers; in fact gcc does this only for arguments that are // prototyped, not for those that match the ... We do it for all // arguments, seems to work. @@ -2403,7 +2403,7 @@ } // We could elide this store in the case where the object fits // entirely in R registers. Maybe later. - PtrOff = DAG.getNode(ISD::ADD, dl, PtrVT, StackPtr, + PtrOff = DAG.getNode(ISD::ADD, dl, PtrVT, StackPtr, DAG.getConstant(ArgOffset, PtrVT)); SDValue Store = DAG.getStore(Chain, dl, Arg, PtrOff, NULL, 0); MemOpChains.push_back(Store); @@ -2470,16 +2470,16 @@ if (!MemOpChains.empty()) Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &MemOpChains[0], MemOpChains.size()); - + // Build a sequence of copy-to-reg nodes chained together with token chain // and flag operands which copy the outgoing args into the appropriate regs. SDValue InFlag; for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { - Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, + Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, RegsToPass[i].second, InFlag); InFlag = Chain.getValue(1); } - + // With the ELF 32 ABI, set CR6 to true if this is a vararg call. if (isVarArg && isELF32_ABI) { SDValue SetCR(DAG.getTargetNode(PPC::CRSET, dl, MVT::i32), 0); @@ -2517,7 +2517,7 @@ SmallVector Ops; unsigned CallOpc = isMachoABI? PPCISD::CALL_Macho : PPCISD::CALL_ELF; - + // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol // node so that legalize doesn't hack it. @@ -2535,7 +2535,7 @@ Chain = DAG.getNode(PPCISD::MTCTR, dl, NodeTys, MTCTROps, 2 + (InFlag.getNode() != 0)); InFlag = Chain.getValue(1); - + // Copy the callee address into R12/X12 on darwin. if (isMachoABI) { unsigned Reg = Callee.getValueType() == MVT::i32 ? PPC::R12 : PPC::X12; @@ -2566,7 +2566,7 @@ // Add argument registers to the end of the list so that they are known live // into the call. for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) - Ops.push_back(DAG.getRegister(RegsToPass[i].first, + Ops.push_back(DAG.getRegister(RegsToPass[i].first, RegsToPass[i].second.getValueType())); // When performing tail call optimization the callee pops its arguments off @@ -2601,13 +2601,13 @@ unsigned CallerCC = DAG.getMachineFunction().getFunction()->getCallingConv(); CCState CCInfo(CallerCC, isVarArg, TM, RVLocs); CCInfo.AnalyzeCallResult(TheCall, RetCC_PPC); - + // Copy all of the result registers out of their specified physreg. for (unsigned i = 0, e = RVLocs.size(); i != e; ++i) { CCValAssign &VA = RVLocs[i]; MVT VT = VA.getValVT(); assert(VA.isRegLoc() && "Can only return in registers!"); - Chain = DAG.getCopyFromReg(Chain, dl, + Chain = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VT, InFlag).getValue(1); ResultVals.push_back(Chain.getValue(0)); InFlag = Chain.getValue(2); @@ -2616,7 +2616,7 @@ // If the function returns void, just return the chain. if (RVLocs.empty()) return Chain; - + // Otherwise, merge everything together with a MERGE_VALUES node. ResultVals.push_back(Chain); SDValue Res = DAG.getNode(ISD::MERGE_VALUES, dl, TheCall->getVTList(), @@ -2624,7 +2624,7 @@ return Res.getValue(Op.getResNo()); } -SDValue PPCTargetLowering::LowerRET(SDValue Op, SelectionDAG &DAG, +SDValue PPCTargetLowering::LowerRET(SDValue Op, SelectionDAG &DAG, TargetMachine &TM) { SmallVector RVLocs; unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv(); @@ -2632,7 +2632,7 @@ DebugLoc dl = Op.getDebugLoc(); CCState CCInfo(CC, isVarArg, TM, RVLocs); CCInfo.AnalyzeReturn(Op.getNode(), RetCC_PPC); - + // If this is the first return lowered for this function, add the regs to the // liveout set for the function. if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { @@ -2672,12 +2672,12 @@ } SDValue Flag; - + // Copy the result values into the output registers. for (unsigned i = 0; i != RVLocs.size(); ++i) { CCValAssign &VA = RVLocs[i]; assert(VA.isRegLoc() && "Can only return in registers!"); - Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), + Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Op.getOperand(i*2+1), Flag); Flag = Chain.getValue(1); } @@ -2692,7 +2692,7 @@ const PPCSubtarget &Subtarget) { // When we pop the dynamic allocation we need to restore the SP link. DebugLoc dl = Op.getDebugLoc(); - + // Get the corect type for pointers. MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); @@ -2704,13 +2704,13 @@ // Get the operands for the STACKRESTORE. SDValue Chain = Op.getOperand(0); SDValue SaveSP = Op.getOperand(1); - + // Load the old link SP. SDValue LoadLinkSP = DAG.getLoad(PtrVT, dl, Chain, StackPtr, NULL, 0); - + // Restore the stack pointer. Chain = DAG.getCopyToReg(LoadLinkSP.getValue(1), dl, SP, SaveSP); - + // Store the old link SP. return DAG.getStore(Chain, dl, LoadLinkSP, StackPtr, NULL, 0); } @@ -2757,11 +2757,11 @@ if (!FPSI) { // Find out what the fix offset of the frame pointer save area. int FPOffset = PPCFrameInfo::getFramePointerSaveOffset(IsPPC64, isMachoABI); - + // Allocate the frame index for frame pointer save area. - FPSI = MF.getFrameInfo()->CreateFixedObject(IsPPC64? 8 : 4, FPOffset); + FPSI = MF.getFrameInfo()->CreateFixedObject(IsPPC64? 8 : 4, FPOffset); // Save the result. - FI->setFramePointerSaveIndex(FPSI); + FI->setFramePointerSaveIndex(FPSI); } return DAG.getFrameIndex(FPSI, PtrVT); } @@ -2772,8 +2772,8 @@ // Get the inputs. SDValue Chain = Op.getOperand(0); SDValue Size = Op.getOperand(1); - DebugLoc dl = Op.getDebugLoc(); - + DebugLoc dl = Op.getDebugLoc(); + // Get the corect type for pointers. MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); // Negate the size. @@ -2794,18 +2794,18 @@ if (!Op.getOperand(0).getValueType().isFloatingPoint() || !Op.getOperand(2).getValueType().isFloatingPoint()) return SDValue(); - + ISD::CondCode CC = cast(Op.getOperand(4))->get(); - + // Cannot handle SETEQ/SETNE. if (CC == ISD::SETEQ || CC == ISD::SETNE) return SDValue(); - + MVT ResVT = Op.getValueType(); MVT CmpVT = Op.getOperand(0).getValueType(); SDValue LHS = Op.getOperand(0), RHS = Op.getOperand(1); SDValue TV = Op.getOperand(2), FV = Op.getOperand(3); DebugLoc dl = Op.getDebugLoc(); - + // If the RHS of the comparison is a 0.0, we don't need to do the // subtraction at all. if (isFloatingPointZero(RHS)) @@ -2829,7 +2829,7 @@ return DAG.getNode(PPCISD::FSEL, dl, ResVT, DAG.getNode(ISD::FNEG, dl, MVT::f64, LHS), TV, FV); } - + SDValue Cmp; switch (CC) { default: break; // SETUO etc aren't handled by fsel. @@ -2901,15 +2901,15 @@ return SDValue(); if (Op.getOperand(0).getValueType() == MVT::i64) { - SDValue Bits = DAG.getNode(ISD::BIT_CONVERT, dl, + SDValue Bits = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f64, Op.getOperand(0)); SDValue FP = DAG.getNode(PPCISD::FCFID, dl, MVT::f64, Bits); if (Op.getValueType() == MVT::f32) - FP = DAG.getNode(ISD::FP_ROUND, dl, + FP = DAG.getNode(ISD::FP_ROUND, dl, MVT::f32, FP, DAG.getIntPtrConstant(0)); return FP; } - + assert(Op.getOperand(0).getValueType() == MVT::i32 && "Unhandled SINT_TO_FP type in custom expander!"); // Since we only generate this in 64-bit mode, we can take advantage of @@ -2920,10 +2920,10 @@ int FrameIdx = FrameInfo->CreateStackObject(8, 8); MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); SDValue FIdx = DAG.getFrameIndex(FrameIdx, PtrVT); - + SDValue Ext64 = DAG.getNode(PPCISD::EXTSW_32, dl, MVT::i32, Op.getOperand(0)); - + // STD the extended value into the stack slot. MachineMemOperand MO(PseudoSourceValue::getFixedStack(FrameIdx), MachineMemOperand::MOStore, 0, 8, 8); @@ -2932,7 +2932,7 @@ DAG.getMemOperand(MO)); // Load the value as a double. SDValue Ld = DAG.getLoad(MVT::f64, dl, Store, FIdx, NULL, 0); - + // FCFID it and return it. SDValue FP = DAG.getNode(PPCISD::FCFID, dl, MVT::f64, Ld); if (Op.getValueType() == MVT::f32) @@ -3009,14 +3009,14 @@ assert(Op.getNumOperands() == 3 && VT == Op.getOperand(1).getValueType() && "Unexpected SHL!"); - + // Expand into a bunch of logical ops. Note that these ops // depend on the PPC behavior for oversized shift amounts. SDValue Lo = Op.getOperand(0); SDValue Hi = Op.getOperand(1); SDValue Amt = Op.getOperand(2); MVT AmtVT = Amt.getValueType(); - + SDValue Tmp1 = DAG.getNode(ISD::SUB, dl, AmtVT, DAG.getConstant(BitWidth, AmtVT), Amt); SDValue Tmp2 = DAG.getNode(PPCISD::SHL, dl, VT, Hi, Amt); @@ -3038,14 +3038,14 @@ assert(Op.getNumOperands() == 3 && VT == Op.getOperand(1).getValueType() && "Unexpected SRL!"); - + // Expand into a bunch of logical ops. Note that these ops // depend on the PPC behavior for oversized shift amounts. SDValue Lo = Op.getOperand(0); SDValue Hi = Op.getOperand(1); SDValue Amt = Op.getOperand(2); MVT AmtVT = Amt.getValueType(); - + SDValue Tmp1 = DAG.getNode(ISD::SUB, dl, AmtVT, DAG.getConstant(BitWidth, AmtVT), Amt); SDValue Tmp2 = DAG.getNode(PPCISD::SRL, dl, VT, Lo, Amt); @@ -3067,13 +3067,13 @@ assert(Op.getNumOperands() == 3 && VT == Op.getOperand(1).getValueType() && "Unexpected SRA!"); - + // Expand into a bunch of logical ops, followed by a select_cc. SDValue Lo = Op.getOperand(0); SDValue Hi = Op.getOperand(1); SDValue Amt = Op.getOperand(2); MVT AmtVT = Amt.getValueType(); - + SDValue Tmp1 = DAG.getNode(ISD::SUB, dl, AmtVT, DAG.getConstant(BitWidth, AmtVT), Amt); SDValue Tmp2 = DAG.getNode(PPCISD::SRL, dl, VT, Lo, Amt); @@ -3094,7 +3094,7 @@ // // If this is a vector of constants or undefs, get the bits. A bit in -// UndefBits is set if the corresponding element of the vector is an +// UndefBits is set if the corresponding element of the vector is an // ISD::UNDEF value. For undefs, the corresponding VectorBits values are // zero. Return true if this is not an array of constants, false if it is. // @@ -3102,11 +3102,11 @@ uint64_t UndefBits[2]) { // Start with zero'd results. VectorBits[0] = VectorBits[1] = UndefBits[0] = UndefBits[1] = 0; - + unsigned EltBitSize = BV->getOperand(0).getValueType().getSizeInBits(); for (unsigned i = 0, e = BV->getNumOperands(); i != e; ++i) { SDValue OpVal = BV->getOperand(i); - + unsigned PartNo = i >= e/2; // In the upper 128 bits? unsigned SlotNo = e/2 - (i & (e/2-1))-1; // Which subpiece of the uint64_t. @@ -3125,32 +3125,32 @@ // Nonconstant element. return true; } - + VectorBits[PartNo] |= EltBits << (SlotNo*EltBitSize); } - - //printf("%llx %llx %llx %llx\n", + + //printf("%llx %llx %llx %llx\n", // VectorBits[0], VectorBits[1], UndefBits[0], UndefBits[1]); return false; } // If this is a splat (repetition) of a value across the whole vector, return // the smallest size that splats it. For example, "0x01010101010101..." is a -// splat of 0x01, 0x0101, and 0x01010101. We return SplatBits = 0x01 and +// splat of 0x01, 0x0101, and 0x01010101. We return SplatBits = 0x01 and // SplatSize = 1 byte. -static bool isConstantSplat(const uint64_t Bits128[2], +static bool isConstantSplat(const uint64_t Bits128[2], const uint64_t Undef128[2], unsigned &SplatBits, unsigned &SplatUndef, unsigned &SplatSize) { - + // Don't let undefs prevent splats from matching. See if the top 64-bits are // the same as the lower 64-bits, ignoring undefs. if ((Bits128[0] & ~Undef128[1]) != (Bits128[1] & ~Undef128[0])) return false; // Can't be a splat if two pieces don't match. - + uint64_t Bits64 = Bits128[0] | Bits128[1]; uint64_t Undef64 = Undef128[0] & Undef128[1]; - + // Check that the top 32-bits are the same as the lower 32-bits, ignoring // undefs. if ((Bits64 & (~Undef64 >> 32)) != ((Bits64 >> 32) & ~Undef64)) @@ -3167,7 +3167,7 @@ SplatSize = 4; return true; } - + uint16_t Bits16 = uint16_t(Bits32) | uint16_t(Bits32 >> 16); uint16_t Undef16 = uint16_t(Undef32) & uint16_t(Undef32 >> 16); @@ -3179,7 +3179,7 @@ SplatSize = 2; return true; } - + // Otherwise, we have an 8-bit splat. SplatBits = uint8_t(Bits16) | uint8_t(Bits16 >> 8); SplatUndef = uint8_t(Undef16) & uint8_t(Undef16 >> 8); @@ -3198,13 +3198,13 @@ }; MVT ReqVT = VT != MVT::Other ? VT : VTys[SplatSize-1]; - + // Force vspltis[hw] -1 to vspltisb -1 to canonicalize. if (Val == -1) SplatSize = 1; - + MVT CanonicalVT = VTys[SplatSize-1]; - + // Build a canonical splat for this value. SDValue Elt = DAG.getConstant(Val, CanonicalVT.getVectorElementType()); SmallVector Ops; @@ -3256,28 +3256,28 @@ // selects to a single instruction, return Op. Otherwise, if we can codegen // this case more efficiently than a constant pool load, lower it to the // sequence of ops that should be used. -SDValue PPCTargetLowering::LowerBUILD_VECTOR(SDValue Op, +SDValue PPCTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) { // If this is a vector of constants or undefs, get the bits. A bit in - // UndefBits is set if the corresponding element of the vector is an + // UndefBits is set if the corresponding element of the vector is an // ISD::UNDEF value. For undefs, the corresponding VectorBits values are - // zero. + // zero. uint64_t VectorBits[2]; uint64_t UndefBits[2]; DebugLoc dl = Op.getDebugLoc(); if (GetConstantBuildVectorBits(Op.getNode(), VectorBits, UndefBits)) return SDValue(); // Not a constant vector. - + // If this is a splat (repetition) of a value across the whole vector, return // the smallest size that splats it. For example, "0x01010101010101..." is a - // splat of 0x01, 0x0101, and 0x01010101. We return SplatBits = 0x01 and + // splat of 0x01, 0x0101, and 0x01010101. We return SplatBits = 0x01 and // SplatSize = 1 byte. unsigned SplatBits, SplatUndef, SplatSize; if (isConstantSplat(VectorBits, UndefBits, SplatBits, SplatUndef, SplatSize)){ bool HasAnyUndefs = (UndefBits[0] | UndefBits[1]) != 0; - + // First, handle single instruction cases. - + // All zeros? if (SplatBits == 0) { // Canonicalize all zero vectors to be v4i32. @@ -3293,10 +3293,10 @@ int32_t SextVal= int32_t(SplatBits << (32-8*SplatSize)) >> (32-8*SplatSize); if (SextVal >= -16 && SextVal <= 15) return BuildSplatI(SextVal, SplatSize, Op.getValueType(), DAG, dl); - - + + // Two instruction sequences. - + // If this value is in the range [-32,30] and is even, use: // tmp = VSPLTI[bhw], result = add tmp, tmp if (SextVal >= -32 && SextVal <= 30 && (SextVal & 1) == 0) { @@ -3304,18 +3304,18 @@ Res = DAG.getNode(ISD::ADD, dl, Res.getValueType(), Res, Res); return DAG.getNode(ISD::BIT_CONVERT, dl, Op.getValueType(), Res); } - - // If this is 0x8000_0000 x 4, turn into vspltisw + vslw. If it is + + // If this is 0x8000_0000 x 4, turn into vspltisw + vslw. If it is // 0x7FFF_FFFF x 4, turn it into not(0x8000_0000). This is important // for fneg/fabs. if (SplatSize == 4 && SplatBits == (0x7FFFFFFF&~SplatUndef)) { // Make -1 and vspltisw -1: SDValue OnesV = BuildSplatI(-1, 4, MVT::v4i32, DAG, dl); - + // Make the VSLW intrinsic, computing 0x8000_0000. - SDValue Res = BuildIntrinsicOp(Intrinsic::ppc_altivec_vslw, OnesV, + SDValue Res = BuildIntrinsicOp(Intrinsic::ppc_altivec_vslw, OnesV, OnesV, DAG, dl); - + // xor by OnesV to invert it. Res = DAG.getNode(ISD::XOR, dl, MVT::v4i32, Res, OnesV); return DAG.getNode(ISD::BIT_CONVERT, dl, Op.getValueType(), Res); @@ -3327,16 +3327,16 @@ -1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -8, 8, -9, 9, -10, 10, -11, 11, -12, 12, -13, 13, 14, -14, 15, -15, -16 }; - + for (unsigned idx = 0; idx < array_lengthof(SplatCsts); ++idx) { // Indirect through the SplatCsts array so that we favor 'vsplti -1' for // cases which are ambiguous (e.g. formation of 0x8000_0000). 'vsplti -1' int i = SplatCsts[idx]; - + // Figure out what shift amount will be used by altivec if shifted by i in // this splat size. unsigned TypeShiftAmt = i & (SplatBitSize-1); - + // vsplti + shl self. if (SextVal == (i << (int)TypeShiftAmt)) { SDValue Res = BuildSplatI(i, SplatSize, MVT::Other, DAG, dl); @@ -3347,7 +3347,7 @@ Res = BuildIntrinsicOp(IIDs[SplatSize-1], Res, Res, DAG, dl); return DAG.getNode(ISD::BIT_CONVERT, dl, Op.getValueType(), Res); } - + // vsplti + srl self. if (SextVal == (int)((unsigned)i >> TypeShiftAmt)) { SDValue Res = BuildSplatI(i, SplatSize, MVT::Other, DAG, dl); @@ -3358,7 +3358,7 @@ Res = BuildIntrinsicOp(IIDs[SplatSize-1], Res, Res, DAG, dl); return DAG.getNode(ISD::BIT_CONVERT, dl, Op.getValueType(), Res); } - + // vsplti + sra self. if (SextVal == (int)((unsigned)i >> TypeShiftAmt)) { SDValue Res = BuildSplatI(i, SplatSize, MVT::Other, DAG, dl); @@ -3369,7 +3369,7 @@ Res = BuildIntrinsicOp(IIDs[SplatSize-1], Res, Res, DAG, dl); return DAG.getNode(ISD::BIT_CONVERT, dl, Op.getValueType(), Res); } - + // vsplti + rol self. if (SextVal == (int)(((unsigned)i << TypeShiftAmt) | ((unsigned)i >> (SplatBitSize-TypeShiftAmt)))) { @@ -3398,9 +3398,9 @@ return BuildVSLDOI(T, T, 3, Op.getValueType(), DAG, dl); } } - + // Three instruction sequences. - + // Odd, in range [17,31]: (vsplti C)-(vsplti -16). if (SextVal >= 0 && SextVal <= 31) { SDValue LHS = BuildSplatI(SextVal-16, SplatSize, MVT::Other, DAG, dl); @@ -3416,19 +3416,19 @@ return DAG.getNode(ISD::BIT_CONVERT, dl, Op.getValueType(), LHS); } } - + return SDValue(); } /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit /// the specified operations to build the shuffle. static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, - SDValue RHS, SelectionDAG &DAG, + SDValue RHS, SelectionDAG &DAG, DebugLoc dl) { unsigned OpNum = (PFEntry >> 26) & 0x0F; unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); - + enum { OP_COPY = 0, // Copy, used for things like to say it is <0,1,2,3> OP_VMRGHW, @@ -3441,17 +3441,17 @@ OP_VSLDOI8, OP_VSLDOI12 }; - + if (OpNum == OP_COPY) { if (LHSID == (1*9+2)*9+3) return LHS; assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); return RHS; } - + SDValue OpLHS, OpRHS; OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); - + unsigned ShufIdxs[16]; switch (OpNum) { default: assert(0 && "Unknown i32 permute!"); @@ -3493,8 +3493,8 @@ SDValue Ops[16]; for (unsigned i = 0; i != 16; ++i) Ops[i] = DAG.getConstant(ShufIdxs[i], MVT::i8); - - return DAG.getNode(ISD::VECTOR_SHUFFLE, dl, OpLHS.getValueType(), + + return DAG.getNode(ISD::VECTOR_SHUFFLE, dl, OpLHS.getValueType(), OpLHS, OpRHS, DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v16i8, Ops, 16)); } @@ -3503,13 +3503,13 @@ /// is a shuffle we can handle in a single instruction, return it. Otherwise, /// return the code it can be lowered into. Worst case, it can always be /// lowered into a vperm. -SDValue PPCTargetLowering::LowerVECTOR_SHUFFLE(SDValue Op, +SDValue PPCTargetLowering::LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { DebugLoc dl = Op.getDebugLoc(); SDValue V1 = Op.getOperand(0); SDValue V2 = Op.getOperand(1); SDValue PermMask = Op.getOperand(2); - + // Cases that are handled by instructions that take permute immediates // (such as vsplt*) should be left as VECTOR_SHUFFLE nodes so they can be // selected by the instruction selector. @@ -3529,7 +3529,7 @@ return Op; } } - + // Altivec has a variety of "shuffle immediates" that take two vector inputs // and produce a fixed permutation. If any of these match, do not lower to // VPERM. @@ -3543,7 +3543,7 @@ PPC::isVMRGHShuffleMask(PermMask.getNode(), 2, false) || PPC::isVMRGHShuffleMask(PermMask.getNode(), 4, false)) return Op; - + // Check to see if this is a shuffle of 4-byte values. If so, we can use our // perfect shuffle table to emit an optimal matching sequence. unsigned PFIndexes[4]; @@ -3553,14 +3553,14 @@ for (unsigned j = 0; j != 4; ++j) { // Intra-element byte. if (PermMask.getOperand(i*4+j).getOpcode() == ISD::UNDEF) continue; // Undef, ignore it. - - unsigned ByteSource = + + unsigned ByteSource = cast(PermMask.getOperand(i*4+j))->getZExtValue(); if ((ByteSource & 3) != j) { isFourElementShuffle = false; break; } - + if (EltNo == 8) { EltNo = ByteSource/4; } else if (EltNo != ByteSource/4) { @@ -3570,18 +3570,18 @@ } PFIndexes[i] = EltNo; } - - // If this shuffle can be expressed as a shuffle of 4-byte elements, use the + + // If this shuffle can be expressed as a shuffle of 4-byte elements, use the // perfect shuffle vector to determine if it is cost effective to do this as // discrete instructions, or whether we should use a vperm. if (isFourElementShuffle) { // Compute the index in the perfect shuffle table. - unsigned PFTableIndex = + unsigned PFTableIndex = PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; - + unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; unsigned Cost = (PFEntry >> 30); - + // Determining when to avoid vperm is tricky. Many things affect the cost // of vperm, particularly how many times the perm mask needs to be computed. // For example, if the perm mask can be hoisted out of a loop or is already @@ -3590,35 +3590,35 @@ // the loop requires an extra register. // // As a compromise, we only emit discrete instructions if the shuffle can be - // generated in 3 or fewer operations. When we have loop information + // generated in 3 or fewer operations. When we have loop information // available, if this block is within a loop, we should avoid using vperm // for 3-operation perms and use a constant pool load instead. - if (Cost < 3) + if (Cost < 3) return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); } - + // Lower this to a VPERM(V1, V2, V3) expression, where V3 is a constant // vector that will get spilled to the constant pool. if (V2.getOpcode() == ISD::UNDEF) V2 = V1; - + // The SHUFFLE_VECTOR mask is almost exactly what we want for vperm, except // that it is in input element units, not in bytes. Convert now. MVT EltVT = V1.getValueType().getVectorElementType(); unsigned BytesPerElement = EltVT.getSizeInBits()/8; - + SmallVector ResultMask; for (unsigned i = 0, e = PermMask.getNumOperands(); i != e; ++i) { unsigned SrcElt; if (PermMask.getOperand(i).getOpcode() == ISD::UNDEF) SrcElt = 0; - else + else SrcElt = cast(PermMask.getOperand(i))->getZExtValue(); - + for (unsigned j = 0; j != BytesPerElement; ++j) ResultMask.push_back(DAG.getConstant(SrcElt*BytesPerElement+j, MVT::i8)); } - + SDValue VPermMask = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v16i8, &ResultMask[0], ResultMask.size()); return DAG.getNode(PPCISD::VPERM, dl, V1.getValueType(), V1, V2, VPermMask); @@ -3649,7 +3649,7 @@ case Intrinsic::ppc_altivec_vcmpgtub_p: CompareOpc = 518; isDot = 1; break; case Intrinsic::ppc_altivec_vcmpgtuh_p: CompareOpc = 582; isDot = 1; break; case Intrinsic::ppc_altivec_vcmpgtuw_p: CompareOpc = 646; isDot = 1; break; - + // Normal Comparisons. case Intrinsic::ppc_altivec_vcmpbfp: CompareOpc = 966; isDot = 0; break; case Intrinsic::ppc_altivec_vcmpeqfp: CompareOpc = 198; isDot = 0; break; @@ -3670,7 +3670,7 @@ /// LowerINTRINSIC_WO_CHAIN - If this is an intrinsic that we want to custom /// lower, do it, otherwise return null. -SDValue PPCTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, +SDValue PPCTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) { // If this is a lowered altivec predicate compare, CompareOpc is set to the // opcode number of the comparison. @@ -3679,7 +3679,7 @@ bool isDot; if (!getAltivecCompareInfo(Op, CompareOpc, isDot)) return SDValue(); // Don't custom lower most intrinsics. - + // If this is a non-dot comparison, make the VCMP node and we are done. if (!isDot) { SDValue Tmp = DAG.getNode(PPCISD::VCMP, dl, Op.getOperand(2).getValueType(), @@ -3687,7 +3687,7 @@ DAG.getConstant(CompareOpc, MVT::i32)); return DAG.getNode(ISD::BIT_CONVERT, dl, Op.getValueType(), Tmp); } - + // Create the PPCISD altivec 'dot' comparison node. SDValue Ops[] = { Op.getOperand(2), // LHS @@ -3698,13 +3698,13 @@ VTs.push_back(Op.getOperand(2).getValueType()); VTs.push_back(MVT::Flag); SDValue CompNode = DAG.getNode(PPCISD::VCMPo, dl, VTs, Ops, 3); - + // Now that we have the comparison, emit a copy from the CR to a GPR. // This is flagged to the above dot comparison. SDValue Flags = DAG.getNode(PPCISD::MFCR, dl, MVT::i32, DAG.getRegister(PPC::CR6, MVT::i32), - CompNode.getValue(1)); - + CompNode.getValue(1)); + // Unpack the result based on how the target uses it. unsigned BitNo; // Bit # of CR6. bool InvertBit; // Invert result? @@ -3723,14 +3723,14 @@ BitNo = 2; InvertBit = true; break; } - + // Shift the bit into the low position. Flags = DAG.getNode(ISD::SRL, dl, MVT::i32, Flags, DAG.getConstant(8-(3-BitNo), MVT::i32)); // Isolate the bit. Flags = DAG.getNode(ISD::AND, dl, MVT::i32, Flags, DAG.getConstant(1, MVT::i32)); - + // If we are supposed to, toggle the bit. if (InvertBit) Flags = DAG.getNode(ISD::XOR, dl, MVT::i32, Flags, @@ -3738,7 +3738,7 @@ return Flags; } -SDValue PPCTargetLowering::LowerSCALAR_TO_VECTOR(SDValue Op, +SDValue PPCTargetLowering::LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) { DebugLoc dl = Op.getDebugLoc(); // Create a stack slot that is 16-byte aligned. @@ -3746,7 +3746,7 @@ int FrameIdx = FrameInfo->CreateStackObject(16, 16); MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); SDValue FIdx = DAG.getFrameIndex(FrameIdx, PtrVT); - + // Store the input value into Value#0 of the stack slot. SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, Op.getOperand(0), FIdx, NULL, 0); @@ -3758,49 +3758,49 @@ DebugLoc dl = Op.getDebugLoc(); if (Op.getValueType() == MVT::v4i32) { SDValue LHS = Op.getOperand(0), RHS = Op.getOperand(1); - + SDValue Zero = BuildSplatI( 0, 1, MVT::v4i32, DAG, dl); SDValue Neg16 = BuildSplatI(-16, 4, MVT::v4i32, DAG, dl);//+16 as shift amt. - + SDValue RHSSwap = // = vrlw RHS, 16 BuildIntrinsicOp(Intrinsic::ppc_altivec_vrlw, RHS, Neg16, DAG, dl); - + // Shrinkify inputs to v8i16. LHS = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::v8i16, LHS); RHS = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::v8i16, RHS); RHSSwap = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::v8i16, RHSSwap); - + // Low parts multiplied together, generating 32-bit results (we ignore the // top parts). SDValue LoProd = BuildIntrinsicOp(Intrinsic::ppc_altivec_vmulouh, LHS, RHS, DAG, dl, MVT::v4i32); - + SDValue HiProd = BuildIntrinsicOp(Intrinsic::ppc_altivec_vmsumuhm, LHS, RHSSwap, Zero, DAG, dl, MVT::v4i32); // Shift the high parts up 16 bits. - HiProd = BuildIntrinsicOp(Intrinsic::ppc_altivec_vslw, HiProd, + HiProd = BuildIntrinsicOp(Intrinsic::ppc_altivec_vslw, HiProd, Neg16, DAG, dl); return DAG.getNode(ISD::ADD, dl, MVT::v4i32, LoProd, HiProd); } else if (Op.getValueType() == MVT::v8i16) { SDValue LHS = Op.getOperand(0), RHS = Op.getOperand(1); - + SDValue Zero = BuildSplatI(0, 1, MVT::v8i16, DAG, dl); return BuildIntrinsicOp(Intrinsic::ppc_altivec_vmladduhm, LHS, RHS, Zero, DAG, dl); } else if (Op.getValueType() == MVT::v16i8) { SDValue LHS = Op.getOperand(0), RHS = Op.getOperand(1); - + // Multiply the even 8-bit parts, producing 16-bit sums. SDValue EvenParts = BuildIntrinsicOp(Intrinsic::ppc_altivec_vmuleub, LHS, RHS, DAG, dl, MVT::v8i16); EvenParts = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::v16i8, EvenParts); - + // Multiply the odd 8-bit parts, producing 16-bit sums. SDValue OddParts = BuildIntrinsicOp(Intrinsic::ppc_altivec_vmuloub, LHS, RHS, DAG, dl, MVT::v8i16); OddParts = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::v16i8, OddParts); - + // Merge the results together. SDValue Ops[16]; for (unsigned i = 0; i != 8; ++i) { @@ -3819,23 +3819,23 @@ /// SDValue PPCTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) { switch (Op.getOpcode()) { - default: assert(0 && "Wasn't expecting to be able to lower this!"); + default: assert(0 && "Wasn't expecting to be able to lower this!"); case ISD::ConstantPool: return LowerConstantPool(Op, DAG); case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG); case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); case ISD::JumpTable: return LowerJumpTable(Op, DAG); case ISD::SETCC: return LowerSETCC(Op, DAG); case ISD::TRAMPOLINE: return LowerTRAMPOLINE(Op, DAG); - case ISD::VASTART: + case ISD::VASTART: return LowerVASTART(Op, DAG, VarArgsFrameIndex, VarArgsStackOffset, VarArgsNumGPR, VarArgsNumFPR, PPCSubTarget); - - case ISD::VAARG: + + case ISD::VAARG: return LowerVAARG(Op, DAG, VarArgsFrameIndex, VarArgsStackOffset, VarArgsNumGPR, VarArgsNumFPR, PPCSubTarget); case ISD::FORMAL_ARGUMENTS: - return LowerFORMAL_ARGUMENTS(Op, DAG, VarArgsFrameIndex, + return LowerFORMAL_ARGUMENTS(Op, DAG, VarArgsFrameIndex, VarArgsStackOffset, VarArgsNumGPR, VarArgsNumFPR, PPCSubTarget); @@ -3863,7 +3863,7 @@ case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG); case ISD::SCALAR_TO_VECTOR: return LowerSCALAR_TO_VECTOR(Op, DAG); case ISD::MUL: return LowerMUL(Op, DAG); - + // Frame & Return address. case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); @@ -3882,7 +3882,7 @@ case ISD::FP_ROUND_INREG: { assert(N->getValueType(0) == MVT::ppcf128); assert(N->getOperand(0).getValueType() == MVT::ppcf128); - SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, + SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::f64, N->getOperand(0), DAG.getIntPtrConstant(0)); SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, @@ -3936,7 +3936,7 @@ // We know the low half is about to be thrown away, so just use something // convenient. - Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::ppcf128, + Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::ppcf128, FPreg, FPreg)); return; } @@ -3999,7 +3999,7 @@ BuildMI(BB, dl, TII->get(is64bit ? PPC::STDCX : PPC::STWCX)) .addReg(TmpReg).addReg(ptrA).addReg(ptrB); BuildMI(BB, dl, TII->get(PPC::BCC)) - .addImm(PPC::PRED_NE).addReg(PPC::CR0).addMBB(loopMBB); + .addImm(PPC::PRED_NE).addReg(PPC::CR0).addMBB(loopMBB); BB->addSuccessor(loopMBB); BB->addSuccessor(exitMBB); @@ -4010,7 +4010,7 @@ } MachineBasicBlock * -PPCTargetLowering::EmitPartwordAtomicBinary(MachineInstr *MI, +PPCTargetLowering::EmitPartwordAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, bool is8bit, // operation unsigned BinOpcode) const { @@ -4040,7 +4040,7 @@ exitMBB->transferSuccessors(BB); MachineRegisterInfo &RegInfo = F->getRegInfo(); - const TargetRegisterClass *RC = + const TargetRegisterClass *RC = is64bit ? (const TargetRegisterClass *) &PPC::G8RCRegClass : (const TargetRegisterClass *) &PPC::GPRCRegClass; unsigned PtrReg = RegInfo.createVirtualRegister(RC); @@ -4125,7 +4125,7 @@ BuildMI(BB, dl, TII->get(PPC::STWCX)) .addReg(Tmp4Reg).addReg(PPC::R0).addReg(PtrReg); BuildMI(BB, dl, TII->get(PPC::BCC)) - .addImm(PPC::PRED_NE).addReg(PPC::CR0).addMBB(loopMBB); + .addImm(PPC::PRED_NE).addReg(PPC::CR0).addMBB(loopMBB); BB->addSuccessor(loopMBB); BB->addSuccessor(exitMBB); @@ -4180,15 +4180,15 @@ // Next, add the true and fallthrough blocks as its successors. BB->addSuccessor(copy0MBB); BB->addSuccessor(sinkMBB); - + // copy0MBB: // %FalseValue = ... // # fallthrough to sinkMBB BB = copy0MBB; - + // Update machine-CFG edges BB->addSuccessor(sinkMBB); - + // sinkMBB: // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] // ... @@ -4315,7 +4315,7 @@ BuildMI(BB, dl, TII->get(PPC::B)).addMBB(exitMBB); BB->addSuccessor(loop1MBB); BB->addSuccessor(exitMBB); - + BB = midMBB; BuildMI(BB, dl, TII->get(is64bit ? PPC::STDCX : PPC::STWCX)) .addReg(dest).addReg(ptrA).addReg(ptrB); @@ -4350,7 +4350,7 @@ exitMBB->transferSuccessors(BB); MachineRegisterInfo &RegInfo = F->getRegInfo(); - const TargetRegisterClass *RC = + const TargetRegisterClass *RC = is64bit ? (const TargetRegisterClass *) &PPC::G8RCRegClass : (const TargetRegisterClass *) &PPC::GPRCRegClass; unsigned PtrReg = RegInfo.createVirtualRegister(RC); @@ -4459,7 +4459,7 @@ BuildMI(BB, dl, TII->get(PPC::B)).addMBB(exitMBB); BB->addSuccessor(loop1MBB); BB->addSuccessor(exitMBB); - + BB = midMBB; BuildMI(BB, dl, TII->get(PPC::STWCX)).addReg(TmpDestReg) .addReg(PPC::R0).addReg(PtrReg); @@ -4507,7 +4507,7 @@ return N->getOperand(0); } break; - + case ISD::SINT_TO_FP: if (TM.getSubtarget().has64BitSupport()) { if (N->getOperand(0).getOpcode() == ISD::FP_TO_SINT) { @@ -4521,13 +4521,13 @@ Val = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Val); DCI.AddToWorklist(Val.getNode()); } - + Val = DAG.getNode(PPCISD::FCTIDZ, dl, MVT::f64, Val); DCI.AddToWorklist(Val.getNode()); Val = DAG.getNode(PPCISD::FCFID, dl, MVT::f64, Val); DCI.AddToWorklist(Val.getNode()); if (N->getValueType(0) == MVT::f32) { - Val = DAG.getNode(ISD::FP_ROUND, dl, MVT::f32, Val, + Val = DAG.getNode(ISD::FP_ROUND, dl, MVT::f32, Val, DAG.getIntPtrConstant(0)); DCI.AddToWorklist(Val.getNode()); } @@ -4559,7 +4559,7 @@ DCI.AddToWorklist(Val.getNode()); return Val; } - + // Turn STORE (BSWAP) -> sthbrx/stwbrx. if (N->getOperand(1).getOpcode() == ISD::BSWAP && N->getOperand(1).getNode()->hasOneUse() && @@ -4595,11 +4595,11 @@ }; SDValue BSLoad = DAG.getNode(PPCISD::LBRX, dl, VTs, Ops, 4); - // If this is an i16 load, insert the truncate. + // If this is an i16 load, insert the truncate. SDValue ResVal = BSLoad; if (N->getValueType(0) == MVT::i16) ResVal = DAG.getNode(ISD::TRUNCATE, dl, MVT::i16, BSLoad); - + // First, combine the bswap away. This makes the value produced by the // load dead. DCI.CombineTo(N, ResVal); @@ -4607,11 +4607,11 @@ // Next, combine the load away, we give it a bogus result value but a real // chain result. The result value is dead because the bswap is dead. DCI.CombineTo(Load.getNode(), ResVal, BSLoad.getValue(1)); - + // Return N so it doesn't get rechecked! return SDValue(N, 0); } - + break; case PPCISD::VCMP: { // If a VCMPo node already exists with exactly the same operands as this @@ -4621,10 +4621,10 @@ if (!N->getOperand(0).hasOneUse() && !N->getOperand(1).hasOneUse() && !N->getOperand(2).hasOneUse()) { - + // Scan all of the users of the LHS, looking for VCMPo's that match. SDNode *VCMPoNode = 0; - + SDNode *LHSN = N->getOperand(0).getNode(); for (SDNode::use_iterator UI = LHSN->use_begin(), E = LHSN->use_end(); UI != E; ++UI) @@ -4635,17 +4635,17 @@ VCMPoNode = *UI; break; } - + // If there is no VCMPo node, or if the flag value has a single use, don't // transform this. if (!VCMPoNode || VCMPoNode->hasNUsesOfValue(0, 1)) break; - - // Look at the (necessarily single) use of the flag value. If it has a + + // Look at the (necessarily single) use of the flag value. If it has a // chain, this transformation is more complex. Note that multiple things // could use the value result, which we should ignore. SDNode *FlagUser = 0; - for (SDNode::use_iterator UI = VCMPoNode->use_begin(); + for (SDNode::use_iterator UI = VCMPoNode->use_begin(); FlagUser == 0; ++UI) { assert(UI != VCMPoNode->use_end() && "Didn't find user!"); SDNode *User = *UI; @@ -4656,7 +4656,7 @@ } } } - + // If the user is a MFCR instruction, we know this is safe. Otherwise we // give up for right now. if (FlagUser->getOpcode() == PPCISD::MFCR) @@ -4673,12 +4673,12 @@ SDValue LHS = N->getOperand(2), RHS = N->getOperand(3); int CompareOpc; bool isDot; - + if (LHS.getOpcode() == ISD::INTRINSIC_WO_CHAIN && isa(RHS) && (CC == ISD::SETEQ || CC == ISD::SETNE) && getAltivecCompareInfo(LHS, CompareOpc, isDot)) { assert(isDot && "Can't compare against a vector result!"); - + // If this is a comparison against something other than 0/1, then we know // that the condition is never/always true. unsigned Val = cast(RHS)->getZExtValue(); @@ -4689,9 +4689,9 @@ return DAG.getNode(ISD::BR, dl, MVT::Other, N->getOperand(0), N->getOperand(4)); } - + bool BranchOnWhenPredTrue = (CC == ISD::SETEQ) ^ (Val == 0); - + // Create the PPCISD altivec 'dot' comparison node. std::vector VTs; SDValue Ops[] = { @@ -4702,7 +4702,7 @@ VTs.push_back(LHS.getOperand(2).getValueType()); VTs.push_back(MVT::Flag); SDValue CompNode = DAG.getNode(PPCISD::VCMPo, dl, VTs, Ops, 3); - + // Unpack the result based on how the target uses it. PPC::Predicate CompOpc; switch (cast(LHS.getOperand(1))->getZExtValue()) { @@ -4729,7 +4729,7 @@ break; } } - + return SDValue(); } @@ -4739,7 +4739,7 @@ void PPCTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, const APInt &Mask, - APInt &KnownZero, + APInt &KnownZero, APInt &KnownOne, const SelectionDAG &DAG, unsigned Depth) const { @@ -4770,7 +4770,7 @@ case Intrinsic::ppc_altivec_vcmpgtuw_p: KnownZero = ~1U; // All bits but the low one are known to be zero. break; - } + } } } } @@ -4778,7 +4778,7 @@ /// getConstraintType - Given a constraint, return the type of /// constraint it is for this target. -PPCTargetLowering::ConstraintType +PPCTargetLowering::ConstraintType PPCTargetLowering::getConstraintType(const std::string &Constraint) const { if (Constraint.size() == 1) { switch (Constraint[0]) { @@ -4794,7 +4794,7 @@ return TargetLowering::getConstraintType(Constraint); } -std::pair +std::pair PPCTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, MVT VT) const { if (Constraint.size() == 1) { @@ -4811,13 +4811,13 @@ else if (VT == MVT::f64) return std::make_pair(0U, PPC::F8RCRegisterClass); break; - case 'v': + case 'v': return std::make_pair(0U, PPC::VRRCRegisterClass); case 'y': // crrc return std::make_pair(0U, PPC::CRRCRegisterClass); } } - + return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); } @@ -4867,7 +4867,7 @@ if ((int)Value > 0 && isPowerOf2_32(Value)) Result = DAG.getTargetConstant(Value, Op.getValueType()); break; - case 'O': // "O" is the constant zero. + case 'O': // "O" is the constant zero. if (Value == 0) Result = DAG.getTargetConstant(Value, Op.getValueType()); break; @@ -4879,31 +4879,31 @@ break; } } - + if (Result.getNode()) { Ops.push_back(Result); return; } - + // Handle standard constraint letters. TargetLowering::LowerAsmOperandForConstraint(Op, Letter, hasMemory, Ops, DAG); } // isLegalAddressingMode - Return true if the addressing mode represented // by AM is legal for this target, for a load/store of the specified type. -bool PPCTargetLowering::isLegalAddressingMode(const AddrMode &AM, +bool PPCTargetLowering::isLegalAddressingMode(const AddrMode &AM, const Type *Ty) const { // FIXME: PPC does not allow r+i addressing modes for vectors! - + // PPC allows a sign-extended 16-bit immediate field. if (AM.BaseOffs <= -(1LL << 16) || AM.BaseOffs >= (1LL << 16)-1) return false; - + // No global is ever allowed as a base. if (AM.BaseGV) return false; - - // PPC only support r+r, + + // PPC only support r+r, switch (AM.Scale) { case 0: // "r+i" or just "i", depending on HasBaseReg. break; @@ -4921,7 +4921,7 @@ // No other scales are supported. return false; } - + return true; } @@ -4934,12 +4934,12 @@ } bool PPCTargetLowering::isLegalAddressImmediate(llvm::GlobalValue* GV) const { - return false; + return false; } SDValue PPCTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) { DebugLoc dl = Op.getDebugLoc(); - // Depths > 0 not supported yet! + // Depths > 0 not supported yet! if (cast(Op.getOperand(0))->getZExtValue() > 0) return SDValue(); @@ -4952,22 +4952,22 @@ // Make sure the function really does not optimize away the store of the RA // to the stack. FuncInfo->setLRStoreRequired(); - return DAG.getLoad(getPointerTy(), dl, + return DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(), RetAddrFI, NULL, 0); } SDValue PPCTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) { DebugLoc dl = Op.getDebugLoc(); - // Depths > 0 not supported yet! + // Depths > 0 not supported yet! if (cast(Op.getOperand(0))->getZExtValue() > 0) return SDValue(); - + MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); bool isPPC64 = PtrVT == MVT::i64; - + MachineFunction &MF = DAG.getMachineFunction(); MachineFrameInfo *MFI = MF.getFrameInfo(); - bool is31 = (NoFramePointerElim || MFI->hasVarSizedObjects()) + bool is31 = (NoFramePointerElim || MFI->hasVarSizedObjects()) && MFI->getStackSize(); if (isPPC64) Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=64827&r1=64826&r2=64827&view=diff ============================================================================== --- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original) +++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Tue Feb 17 16:15:04 2009 @@ -80,7 +80,7 @@ setUseUnderscoreSetJmp(true); setUseUnderscoreLongJmp(true); } - + // Set up the register classes. addRegisterClass(MVT::i8, X86::GR8RegisterClass); addRegisterClass(MVT::i16, X86::GR16RegisterClass); @@ -90,7 +90,7 @@ setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); - // We don't accept any truncstore of integer registers. + // We don't accept any truncstore of integer registers. setTruncStoreAction(MVT::i64, MVT::i32, Expand); setTruncStoreAction(MVT::i64, MVT::i16, Expand); setTruncStoreAction(MVT::i64, MVT::i8 , Expand); @@ -234,7 +234,7 @@ setOperationAction(ISD::FREM , MVT::f64 , Expand); setOperationAction(ISD::FREM , MVT::f80 , Expand); setOperationAction(ISD::FLT_ROUNDS_ , MVT::i32 , Custom); - + setOperationAction(ISD::CTPOP , MVT::i8 , Expand); setOperationAction(ISD::CTTZ , MVT::i8 , Custom); setOperationAction(ISD::CTLZ , MVT::i8 , Custom); @@ -448,7 +448,7 @@ if (Fast) { setConvertAction(MVT::f32, MVT::f64, Expand); setConvertAction(MVT::f32, MVT::f80, Expand); - setConvertAction(MVT::f80, MVT::f32, Expand); + setConvertAction(MVT::f80, MVT::f32, Expand); setConvertAction(MVT::f64, MVT::f32, Expand); // And x87->x87 truncations also. setConvertAction(MVT::f80, MVT::f64, Expand); @@ -473,7 +473,7 @@ // this though and handle it in InstructionSelectPreprocess so that // dagcombine2 can hack on these. if (Fast) { - setConvertAction(MVT::f80, MVT::f32, Expand); + setConvertAction(MVT::f80, MVT::f32, Expand); setConvertAction(MVT::f64, MVT::f32, Expand); setConvertAction(MVT::f80, MVT::f64, Expand); } @@ -512,7 +512,7 @@ TmpFlt2.changeSign(); addLegalFPImmediate(TmpFlt2); // FLD1/FCHS } - + if (!UnsafeFPMath) { setOperationAction(ISD::FSIN , MVT::f80 , Expand); setOperationAction(ISD::FCOS , MVT::f80 , Expand); @@ -761,7 +761,7 @@ setOperationAction(ISD::LOAD, MVT::v2i64, Legal); setOperationAction(ISD::SELECT, MVT::v2f64, Custom); setOperationAction(ISD::SELECT, MVT::v2i64, Custom); - + } if (Subtarget->hasSSE41()) { @@ -791,7 +791,7 @@ if (Subtarget->hasSSE42()) { setOperationAction(ISD::VSETCC, MVT::v2i64, Custom); } - + // We want to custom lower some of our intrinsics. setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); @@ -926,13 +926,13 @@ SDValue X86TargetLowering::LowerRET(SDValue Op, SelectionDAG &DAG) { DebugLoc dl = Op.getDebugLoc(); assert((Op.getNumOperands() & 1) == 1 && "ISD::RET should have odd # args"); - + SmallVector RVLocs; unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv(); bool isVarArg = DAG.getMachineFunction().getFunction()->isVarArg(); CCState CCInfo(CC, isVarArg, getTargetMachine(), RVLocs); CCInfo.AnalyzeReturn(Op.getNode(), RetCC_X86); - + // If this is the first return lowered for this function, add the regs to the // liveout set for the function. if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { @@ -941,7 +941,7 @@ DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); } SDValue Chain = Op.getOperand(0); - + // Handle tail call return. Chain = GetPossiblePreceedingTailCall(Chain, X86ISD::TAILCALL); if (Chain.getOpcode() == X86ISD::TAILCALL) { @@ -952,7 +952,7 @@ (cast(TargetAddress)->getReg() == X86::EAX || cast(TargetAddress)->getReg() == X86::R9)) || TargetAddress.getOpcode() == ISD::TargetExternalSymbol || - TargetAddress.getOpcode() == ISD::TargetGlobalAddress) && + TargetAddress.getOpcode() == ISD::TargetGlobalAddress) && "Expecting an global address, external symbol, or register"); assert(StackAdjustment.getOpcode() == ISD::Constant && "Expecting a const value"); @@ -966,10 +966,10 @@ for (unsigned i=3; i < TailCall.getNumOperands()-1; i++) { Operands.push_back(Chain.getOperand(i)); } - return DAG.getNode(X86ISD::TC_RETURN, dl, MVT::Other, &Operands[0], + return DAG.getNode(X86ISD::TC_RETURN, dl, MVT::Other, &Operands[0], Operands.size()); } - + // Regular return. SDValue Flag; @@ -977,13 +977,13 @@ RetOps.push_back(Chain); // Operand #0 = Chain (updated below) // Operand #1 = Bytes To Pop RetOps.push_back(DAG.getConstant(getBytesToPopOnReturn(), MVT::i16)); - + // Copy the result values into the output registers. for (unsigned i = 0; i != RVLocs.size(); ++i) { CCValAssign &VA = RVLocs[i]; assert(VA.isRegLoc() && "Can only return in registers!"); SDValue ValToCopy = Op.getOperand(i*2+1); - + // Returns in ST0/ST1 are handled specially: these are pushed as operands to // the RET instruction and handled by the FP Stackifier. if (VA.getLocReg() == X86::ST0 || @@ -1019,14 +1019,14 @@ Chain = DAG.getCopyToReg(Chain, dl, X86::RAX, Val, Flag); Flag = Chain.getValue(1); } - + RetOps[0] = Chain; // Update chain. // Add the flag if we have it. if (Flag.getNode()) RetOps.push_back(Flag); - - return DAG.getNode(X86ISD::RET_FLAG, dl, + + return DAG.getNode(X86ISD::RET_FLAG, dl, MVT::Other, &RetOps[0], RetOps.size()); } @@ -1037,10 +1037,10 @@ /// being lowered. The returns a SDNode with the same number of values as the /// ISD::CALL. SDNode *X86TargetLowering:: -LowerCallResult(SDValue Chain, SDValue InFlag, CallSDNode *TheCall, +LowerCallResult(SDValue Chain, SDValue InFlag, CallSDNode *TheCall, unsigned CallingConv, SelectionDAG &DAG) { - DebugLoc dl = TheCall->getDebugLoc(); + DebugLoc dl = TheCall->getDebugLoc(); // Assign locations to each value returned by this call. SmallVector RVLocs; bool isVarArg = TheCall->isVarArg(); @@ -1049,14 +1049,14 @@ CCInfo.AnalyzeCallResult(TheCall, RetCC_X86); SmallVector ResultVals; - + // Copy all of the result registers out of their specified physreg. for (unsigned i = 0; i != RVLocs.size(); ++i) { CCValAssign &VA = RVLocs[i]; MVT CopyVT = VA.getValVT(); - + // If this is x86-64, and we disabled SSE, we can't return FP values - if ((CopyVT == MVT::f32 || CopyVT == MVT::f64) && + if ((CopyVT == MVT::f32 || CopyVT == MVT::f64) && ((Is64Bit || TheCall->isInreg()) && !Subtarget->hasSSE1())) { cerr << "SSE register return with SSE disabled\n"; exit(1); @@ -1070,7 +1070,7 @@ isScalarFPTypeInSSEReg(VA.getValVT())) { CopyVT = MVT::f80; } - + Chain = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), CopyVT, InFlag).getValue(1); SDValue Val = Chain.getValue(0); @@ -1083,7 +1083,7 @@ // This truncation won't change the value. DAG.getIntPtrConstant(1)); } - + ResultVals.push_back(Val); } @@ -1197,9 +1197,9 @@ /// CallRequiresFnAddressInReg - Check whether the call requires the function /// address to be loaded in a register. -bool +bool X86TargetLowering::CallRequiresFnAddressInReg(bool Is64Bit, bool IsTailCall) { - return !Is64Bit && IsTailCall && + return !Is64Bit && IsTailCall && getTargetMachine().getRelocationModel() == Reloc::PIC_ && Subtarget->isPICStyleGOT(); } @@ -1208,7 +1208,7 @@ /// by "Src" to address "Dst" with size and alignment information specified by /// the specific parameter attribute. The copy will be passed as a byval /// function parameter. -static SDValue +static SDValue CreateCopyOfByValArgument(SDValue Src, SDValue Dst, SDValue Chain, ISD::ArgFlagsTy Flags, SelectionDAG &DAG, DebugLoc dl) { @@ -1229,7 +1229,7 @@ bool isImmutable = !AlwaysUseMutable && !Flags.isByVal(); // FIXME: For now, all byval parameter objects are marked mutable. This can be - // changed with more analysis. + // changed with more analysis. // In case of tail call optimization mark all arguments mutable. Since they // could be overwritten by lowering of arguments in case of a tail call. int FI = MFI->CreateFixedObject(VA.getValVT().getSizeInBits()/8, @@ -1246,7 +1246,7 @@ MachineFunction &MF = DAG.getMachineFunction(); X86MachineFunctionInfo *FuncInfo = MF.getInfo(); DebugLoc dl = Op.getDebugLoc(); - + const Function* Fn = MF.getFunction(); if (Fn->hasExternalLinkage() && Subtarget->isTargetCygMing() && @@ -1255,7 +1255,7 @@ // Decorate the function name. FuncInfo->setDecorationStyle(NameDecorationForFORMAL_ARGUMENTS(Op)); - + MachineFrameInfo *MFI = MF.getFrameInfo(); SDValue Root = Op.getOperand(0); bool isVarArg = cast(Op.getOperand(2))->getZExtValue() != 0; @@ -1270,7 +1270,7 @@ SmallVector ArgLocs; CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs); CCInfo.AnalyzeFormalArguments(Op.getNode(), CCAssignFnForNode(CC)); - + SmallVector ArgValues; unsigned LastVal = ~0U; for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { @@ -1280,7 +1280,7 @@ assert(VA.getValNo() != LastVal && "Don't support value assigned to multiple locs yet"); LastVal = VA.getValNo(); - + if (VA.isRegLoc()) { MVT RegVT = VA.getLocVT(); TargetRegisterClass *RC = NULL; @@ -1315,7 +1315,7 @@ unsigned Reg = AddLiveIn(DAG.getMachineFunction(), VA.getLocReg(), RC); SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, RegVT); - + // If this is an 8 or 16-bit value, it is really passed promoted to 32 // bits. Insert an assert[sz]ext to capture this, then truncate to the // right size. @@ -1325,10 +1325,10 @@ else if (VA.getLocInfo() == CCValAssign::ZExt) ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, DAG.getValueType(VA.getValVT())); - + if (VA.getLocInfo() != CCValAssign::Full) ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); - + // Handle MMX values passed in GPRs. if (Is64Bit && RegVT != VA.getLocVT()) { if (RegVT.getSizeInBits() == 64 && RC == X86::GR64RegisterClass) @@ -1339,7 +1339,7 @@ ArgValue = DAG.getNode(ISD::BIT_CONVERT, dl, VA.getLocVT(), ArgValue); } } - + ArgValues.push_back(ArgValue); } else { assert(VA.isMemLoc()); @@ -1459,7 +1459,7 @@ &MemOps[0], MemOps.size()); } } - + ArgValues.push_back(Root); // Some CCs need callee pop. @@ -1470,7 +1470,7 @@ BytesToPopOnReturn = 0; // Callee pops nothing. // If this is an sret function, the return should pop the hidden pointer. if (!Is64Bit && CC != CallingConv::Fast && ArgsAreStructReturn(Op)) - BytesToPopOnReturn = 4; + BytesToPopOnReturn = 4; BytesCallerReserves = StackSize; } @@ -1506,12 +1506,12 @@ /// EmitTailCallLoadRetAddr - Emit a load of return address if tail call /// optimization is performed and it is required. -SDValue -X86TargetLowering::EmitTailCallLoadRetAddr(SelectionDAG &DAG, +SDValue +X86TargetLowering::EmitTailCallLoadRetAddr(SelectionDAG &DAG, SDValue &OutRetAddr, - SDValue Chain, - bool IsTailCall, - bool Is64Bit, + SDValue Chain, + bool IsTailCall, + bool Is64Bit, int FPDiff, DebugLoc dl) { if (!IsTailCall || FPDiff==0) return Chain; @@ -1527,19 +1527,19 @@ /// EmitTailCallStoreRetAddr - Emit a store of the return adress if tail call /// optimization is performed and it is required (FPDiff!=0). -static SDValue -EmitTailCallStoreRetAddr(SelectionDAG & DAG, MachineFunction &MF, +static SDValue +EmitTailCallStoreRetAddr(SelectionDAG & DAG, MachineFunction &MF, SDValue Chain, SDValue RetAddrFrIdx, bool Is64Bit, int FPDiff, DebugLoc dl) { // Store the return address to the appropriate stack slot. if (!FPDiff) return Chain; // Calculate the new stack slot for the return address. int SlotSize = Is64Bit ? 8 : 4; - int NewReturnAddrFI = + int NewReturnAddrFI = MF.getFrameInfo()->CreateFixedObject(SlotSize, FPDiff-SlotSize); MVT VT = Is64Bit ? MVT::i64 : MVT::i32; SDValue NewRetAddrFrIdx = DAG.getFrameIndex(NewReturnAddrFI, VT); - Chain = DAG.getStore(Chain, dl, RetAddrFrIdx, NewRetAddrFrIdx, + Chain = DAG.getStore(Chain, dl, RetAddrFrIdx, NewRetAddrFrIdx, PseudoSourceValue::getFixedStack(NewReturnAddrFI), 0); return Chain; } @@ -1564,7 +1564,7 @@ SmallVector ArgLocs; CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs); CCInfo.AnalyzeCallOperands(TheCall, CCAssignFnForNode(CC)); - + // Get a count of how many bytes are to be pushed on the stack. unsigned NumBytes = CCInfo.getNextStackOffset(); if (PerformTailCallOpt && CC == CallingConv::Fast) @@ -1573,7 +1573,7 @@ int FPDiff = 0; if (IsTailCall) { // Lower arguments at fp - stackoffset + fpdiff. - unsigned NumBytesCallerPushed = + unsigned NumBytesCallerPushed = MF.getInfo()->getBytesToPopOnReturn(); FPDiff = NumBytesCallerPushed - NumBytes; @@ -1601,7 +1601,7 @@ SDValue Arg = TheCall->getArg(i); ISD::ArgFlagsTy Flags = TheCall->getArgFlags(i); bool isByVal = Flags.isByVal(); - + // Promote the value if needed. switch (VA.getLocInfo()) { default: assert(0 && "Unknown loc info!"); @@ -1616,7 +1616,7 @@ Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); break; } - + if (VA.isRegLoc()) { if (Is64Bit) { MVT RegVT = VA.getLocVT(); @@ -1648,13 +1648,13 @@ assert(VA.isMemLoc()); if (StackPtr.getNode() == 0) StackPtr = DAG.getCopyFromReg(Chain, dl, X86StackPtr, getPointerTy()); - + MemOpChains.push_back(LowerMemOpCallTo(TheCall, DAG, StackPtr, VA, Chain, Arg, Flags)); } } } - + if (!MemOpChains.empty()) Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &MemOpChains[0], MemOpChains.size()); @@ -1666,17 +1666,17 @@ // tail call optimization the copies to registers are lowered later. if (!IsTailCall) for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { - Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, + Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, RegsToPass[i].second, InFlag); InFlag = Chain.getValue(1); } // ELF / PIC requires GOT in the EBX register before function calls via PLT - // GOT pointer. + // GOT pointer. if (CallRequiresGOTPtrInReg(Is64Bit, IsTailCall)) { Chain = DAG.getCopyToReg(Chain, dl, X86::EBX, - DAG.getNode(X86ISD::GlobalBaseReg, - DebugLoc::getUnknownLoc(), + DAG.getNode(X86ISD::GlobalBaseReg, + DebugLoc::getUnknownLoc(), getPointerTy()), InFlag); InFlag = Chain.getValue(1); @@ -1713,9 +1713,9 @@ X86::XMM4, X86::XMM5, X86::XMM6, X86::XMM7 }; unsigned NumXMMRegs = CCInfo.getFirstUnallocated(XMMArgRegs, 8); - assert((Subtarget->hasSSE1() || !NumXMMRegs) + assert((Subtarget->hasSSE1() || !NumXMMRegs) && "SSE registers cannot be used when SSE is disabled"); - + Chain = DAG.getCopyToReg(Chain, dl, X86::AL, DAG.getConstant(NumXMMRegs, MVT::i8), InFlag); InFlag = Chain.getValue(1); @@ -1745,7 +1745,7 @@ // Copy relative to framepointer. SDValue Source = DAG.getIntPtrConstant(VA.getLocMemOffset()); if (StackPtr.getNode() == 0) - StackPtr = DAG.getCopyFromReg(Chain, dl, X86StackPtr, + StackPtr = DAG.getCopyFromReg(Chain, dl, X86StackPtr, getPointerTy()); Source = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, Source); @@ -1756,7 +1756,7 @@ MemOpChains2.push_back( DAG.getStore(Chain, dl, Arg, FIN, PseudoSourceValue::getFixedStack(FI), 0)); - } + } } } @@ -1766,7 +1766,7 @@ // Copy arguments to their registers. for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { - Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, + Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, RegsToPass[i].second, InFlag); InFlag = Chain.getValue(1); } @@ -1792,13 +1792,13 @@ unsigned Opc = Is64Bit ? X86::R9 : X86::EAX; Chain = DAG.getCopyToReg(Chain, dl, - DAG.getRegister(Opc, getPointerTy()), + DAG.getRegister(Opc, getPointerTy()), Callee,InFlag); Callee = DAG.getRegister(Opc, getPointerTy()); // Add register as live out. DAG.getMachineFunction().getRegInfo().addLiveOut(Opc); } - + // Returns a chain & a flag for retval copy to use. SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag); SmallVector Ops; @@ -1807,12 +1807,12 @@ Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), DAG.getIntPtrConstant(0, true), InFlag); InFlag = Chain.getValue(1); - + // Returns a chain & a flag for retval copy to use. NodeTys = DAG.getVTList(MVT::Other, MVT::Flag); Ops.clear(); } - + Ops.push_back(Chain); Ops.push_back(Callee); @@ -1824,7 +1824,7 @@ for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) Ops.push_back(DAG.getRegister(RegsToPass[i].first, RegsToPass[i].second.getValueType())); - + // Add an implicit use GOT pointer in EBX. if (!IsTailCall && !Is64Bit && getTargetMachine().getRelocationModel() == Reloc::PIC_ && @@ -1839,11 +1839,11 @@ Ops.push_back(InFlag); if (IsTailCall) { - assert(InFlag.getNode() && + assert(InFlag.getNode() && "Flag must be set. Depend on flag being set in LowerRET"); Chain = DAG.getNode(X86ISD::TAILCALL, dl, TheCall->getVTList(), &Ops[0], Ops.size()); - + return SDValue(Chain.getNode(), Op.getResNo()); } @@ -1861,7 +1861,7 @@ NumBytesForCalleeToPush = 4; else NumBytesForCalleeToPush = 0; // Callee pops nothing. - + // Returns a flag for retval copy to use. Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), @@ -1901,7 +1901,7 @@ // arg1 // arg2 // RETADDR -// [ new RETADDR +// [ new RETADDR // move area ] // (possible EBP) // ESI @@ -1910,13 +1910,13 @@ /// GetAlignedArgumentStackSize - Make the stack size align e.g 16n + 12 aligned /// for a 16 byte align requirement. -unsigned X86TargetLowering::GetAlignedArgumentStackSize(unsigned StackSize, +unsigned X86TargetLowering::GetAlignedArgumentStackSize(unsigned StackSize, SelectionDAG& DAG) { MachineFunction &MF = DAG.getMachineFunction(); const TargetMachine &TM = MF.getTarget(); const TargetFrameInfo &TFI = *TM.getFrameInfo(); unsigned StackAlignment = TFI.getStackAlignment(); - uint64_t AlignMask = StackAlignment - 1; + uint64_t AlignMask = StackAlignment - 1; int64_t Offset = StackSize; uint64_t SlotSize = TD->getPointerSize(); if ( (Offset & AlignMask) <= (StackAlignment - SlotSize) ) { @@ -1924,7 +1924,7 @@ Offset += ((StackAlignment - SlotSize) - (Offset & AlignMask)); } else { // Mask out lower bits, add stackalignment once plus the 12 bytes. - Offset = ((~AlignMask) & Offset) + StackAlignment + + Offset = ((~AlignMask) & Offset) + StackAlignment + (StackAlignment-SlotSize); } return Offset; @@ -2038,7 +2038,7 @@ case ISD::SETUGE: return X86::COND_AE; } } - + // First determine if it is required or is profitable to flip the operands. // If LHS is a foldable load, but RHS is not, flip the condition. @@ -2896,7 +2896,7 @@ SDValue Arg = Mask.getOperand(i); if (Arg.getOpcode() == ISD::UNDEF) continue; - + unsigned Idx = cast(Arg)->getZExtValue(); if (Idx < NumElems) { unsigned Opc = V1.getNode()->getOpcode(); @@ -2922,7 +2922,7 @@ static SDValue getZeroVector(MVT VT, bool HasSSE2, SelectionDAG &DAG, DebugLoc dl) { assert(VT.isVector() && "Expected a vector type"); - + // Always build zero vectors as <4 x i32> or <2 x i32> bitcasted to their dest // type. This ensures they get CSE'd. SDValue Vec; @@ -2943,7 +2943,7 @@ /// static SDValue getOnesVector(MVT VT, SelectionDAG &DAG, DebugLoc dl) { assert(VT.isVector() && "Expected a vector type"); - + // Always build ones vectors as <4 x i32> or <2 x i32> bitcasted to their dest // type. This ensures they get CSE'd. SDValue Cst = DAG.getTargetConstant(~0U, MVT::i32); @@ -2993,13 +2993,13 @@ MaskVec.push_back(DAG.getConstant(NumElems, BaseVT)); for (unsigned i = 1; i != NumElems; ++i) MaskVec.push_back(DAG.getConstant(i, BaseVT)); - return DAG.getNode(ISD::BUILD_VECTOR, dl, MaskVT, + return DAG.getNode(ISD::BUILD_VECTOR, dl, MaskVT, &MaskVec[0], MaskVec.size()); } /// getUnpacklMask - Returns a vector_shuffle mask for an unpackl operation /// of specified width. -static SDValue getUnpacklMask(unsigned NumElems, SelectionDAG &DAG, +static SDValue getUnpacklMask(unsigned NumElems, SelectionDAG &DAG, DebugLoc dl) { MVT MaskVT = MVT::getIntVectorWithNumElements(NumElems); MVT BaseVT = MaskVT.getVectorElementType(); @@ -3008,7 +3008,7 @@ MaskVec.push_back(DAG.getConstant(i, BaseVT)); MaskVec.push_back(DAG.getConstant(i + NumElems, BaseVT)); } - return DAG.getNode(ISD::BUILD_VECTOR, dl, MaskVT, + return DAG.getNode(ISD::BUILD_VECTOR, dl, MaskVT, &MaskVec[0], MaskVec.size()); } @@ -3024,7 +3024,7 @@ MaskVec.push_back(DAG.getConstant(i + Half, BaseVT)); MaskVec.push_back(DAG.getConstant(i + NumElems + Half, BaseVT)); } - return DAG.getNode(ISD::BUILD_VECTOR, dl, MaskVT, + return DAG.getNode(ISD::BUILD_VECTOR, dl, MaskVT, &MaskVec[0], MaskVec.size()); } @@ -3040,7 +3040,7 @@ MaskVec.push_back(DAG.getConstant(DestElt, BaseVT)); for (unsigned i = 1; i != NumElems; ++i) MaskVec.push_back(DAG.getConstant(i == DestElt ? 0 : i, BaseVT)); - return DAG.getNode(ISD::BUILD_VECTOR, dl, MaskVT, + return DAG.getNode(ISD::BUILD_VECTOR, dl, MaskVT, &MaskVec[0], MaskVec.size()); } @@ -3113,7 +3113,7 @@ assert(NumElems == 4); SDValue Cst0 = DAG.getTargetConstant(0, MVT::i32); SDValue Cst1 = DAG.getTargetConstant(1, MVT::i32); - Mask = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, + Mask = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, Cst0, Cst1, Cst0, Cst1); } @@ -3237,7 +3237,7 @@ SDValue ThisElt(0, 0), LastElt(0, 0); bool LastIsNonZero = (NonZeros & (1 << (i-1))) != 0; if (LastIsNonZero) { - LastElt = DAG.getNode(ISD::ZERO_EXTEND, dl, + LastElt = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, Op.getOperand(i-1)); } if (ThisIsNonZero) { @@ -3279,7 +3279,7 @@ V = DAG.getUNDEF(MVT::v8i16); First = false; } - V = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, + V = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v8i16, V, Op.getOperand(i), DAG.getIntPtrConstant(i)); } @@ -3354,7 +3354,7 @@ if (NumNonZero == 1 && NumElems <= 4) { unsigned Idx = CountTrailingZeros_32(NonZeros); SDValue Item = Op.getOperand(Idx); - + // If this is an insertion of an i64 value on x86-32, and if the top bits of // the value are obviously zero, truncate the value to i32 and do the // insertion that way. Only do this if the value is non-constant or if the @@ -3366,18 +3366,18 @@ // Handle MMX and SSE both. MVT VecVT = VT == MVT::v2i64 ? MVT::v4i32 : MVT::v2i32; unsigned VecElts = VT == MVT::v2i64 ? 4 : 2; - + // Truncate the value (which may itself be a constant) to i32, and // convert it to a vector with movd (S2V+shuffle to zero extend). Item = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, Item); Item = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VecVT, Item); Item = getShuffleVectorZeroOrUndef(Item, 0, true, Subtarget->hasSSE2(), DAG); - + // Now we have our 32-bit value zero extended in the low element of // a vector. If Idx != 0, swizzle it into place. if (Idx != 0) { - SDValue Ops[] = { + SDValue Ops[] = { Item, DAG.getUNDEF(Item.getValueType()), getSwapEltZeroMask(VecElts, Idx, DAG, dl) }; @@ -3386,7 +3386,7 @@ return DAG.getNode(ISD::BIT_CONVERT, dl, Op.getValueType(), Item); } } - + // If we have a constant or non-constant insertion into the low element of // a vector, we can do this with SCALAR_TO_VECTOR + shuffle of zero into // the rest of the elements. This will be matched as movd/movq/movss/movsd @@ -3406,11 +3406,11 @@ isZeroNode(Op.getOperand(0)) && !isZeroNode(Op.getOperand(1))) { unsigned NumBits = VT.getSizeInBits(); return getVShift(true, VT, - DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, + DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Op.getOperand(1)), NumBits/2, DAG, *this, dl); } - + if (IsAllConstants) // Otherwise, it's better to do a constpool load. return SDValue(); @@ -3421,7 +3421,7 @@ // place. if (EVTBits == 32) { Item = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Item); - + // Turn it into a shuffle of zero and zero-extended scalar to vector. Item = getShuffleVectorZeroOrUndef(Item, 0, NumZero > 0, Subtarget->hasSSE2(), DAG); @@ -3440,7 +3440,7 @@ // Splat is obviously ok. Let legalizer expand it to a shuffle. if (Values.size() == 1) return SDValue(); - + // A vector full of immediates; various special cases are already // handled, so this is best done with a single constant-pool load. if (IsAllConstants) @@ -3647,9 +3647,9 @@ if (AnyOutOrder) { for (unsigned i = 4; i != 8; ++i) MaskVec.push_back(DAG.getConstant(i, MaskEVT)); - SDValue Mask = DAG.getNode(ISD::BUILD_VECTOR, dl, MaskVT, + SDValue Mask = DAG.getNode(ISD::BUILD_VECTOR, dl, MaskVT, &MaskVec[0], 8); - NewV = DAG.getNode(ISD::VECTOR_SHUFFLE, dl, MVT::v8i16, + NewV = DAG.getNode(ISD::VECTOR_SHUFFLE, dl, MVT::v8i16, NewV, NewV, Mask); } } @@ -3682,9 +3682,9 @@ } if (AnyOutOrder) { - SDValue Mask = DAG.getNode(ISD::BUILD_VECTOR, dl, + SDValue Mask = DAG.getNode(ISD::BUILD_VECTOR, dl, MaskVT, &MaskVec[0], 8); - NewV = DAG.getNode(ISD::VECTOR_SHUFFLE, dl, MVT::v8i16, + NewV = DAG.getNode(ISD::VECTOR_SHUFFLE, dl, MVT::v8i16, NewV, NewV, Mask); } } @@ -3894,7 +3894,7 @@ return DAG.getNode(ISD::BIT_CONVERT, dl, VT, DAG.getNode(X86ISD::VZEXT_MOVL, dl, OpVT, - DAG.getNode(ISD::BIT_CONVERT, dl, + DAG.getNode(ISD::BIT_CONVERT, dl, OpVT, SrcOp))); } @@ -3992,7 +3992,7 @@ Mask1[2] = DAG.getConstant(HiIndex & 1 ? 6 : 4, MaskEVT); Mask1[3] = DAG.getConstant(HiIndex & 1 ? 4 : 6, MaskEVT); return DAG.getNode(ISD::VECTOR_SHUFFLE, dl, VT, V1, V2, - DAG.getNode(ISD::BUILD_VECTOR, dl, + DAG.getNode(ISD::BUILD_VECTOR, dl, MaskVT, &Mask1[0], 4)); } else { Mask1[0] = DAG.getConstant(HiIndex & 1 ? 2 : 0, MaskEVT); @@ -4008,7 +4008,7 @@ DAG.getConstant(cast(Mask1[3])->getZExtValue()+4, MaskEVT); return DAG.getNode(ISD::VECTOR_SHUFFLE, dl, VT, V2, V1, - DAG.getNode(ISD::BUILD_VECTOR, dl, + DAG.getNode(ISD::BUILD_VECTOR, dl, MaskVT, &Mask1[0], 4)); } } @@ -4105,7 +4105,7 @@ SDValue NewOp= RewriteAsNarrowerShuffle(V1, V2, VT, PermMask, DAG, *this, dl); if (NewOp.getNode()) - return DAG.getNode(ISD::BIT_CONVERT, dl, VT, + return DAG.getNode(ISD::BIT_CONVERT, dl, VT, LowerVECTOR_SHUFFLE(NewOp, DAG)); } else if ((VT == MVT::v4i32 || (VT == MVT::v4f32 && Subtarget->hasSSE2()))) { // FIXME: Figure out a cleaner way to do this. @@ -4138,7 +4138,7 @@ SDValue ShVal; bool isShift = isVectorShift(Op, PermMask, DAG, isLeft, ShVal, ShAmt); if (isShift && ShVal.hasOneUse()) { - // If the shifted value has multiple uses, it may be cheaper to use + // If the shifted value has multiple uses, it may be cheaper to use // v_set0 + movlhps or movhlps, etc. MVT EVT = VT.getVectorElementType(); ShAmt *= EVT.getSizeInBits(); @@ -4177,7 +4177,7 @@ // 1,1,1,1 -> v8i16 though. V1IsSplat = isSplatVector(V1.getNode()); V2IsSplat = isSplatVector(V2.getNode()); - + // Canonicalize the splat or undef, if present, to be on the RHS. if ((V1IsSplat || V1IsUndef) && !(V2IsSplat || V2IsUndef)) { Op = CommuteVectorShuffle(Op, V1, V2, PermMask, DAG); @@ -4328,7 +4328,7 @@ User->getValueType(0) != MVT::i32)) return SDValue(); SDValue Extract = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::i32, - DAG.getNode(ISD::BIT_CONVERT, dl, MVT::v4i32, + DAG.getNode(ISD::BIT_CONVERT, dl, MVT::v4i32, Op.getOperand(0)), Op.getOperand(1)); return DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f32, Extract); @@ -4361,7 +4361,7 @@ if (Idx == 0) return DAG.getNode(ISD::TRUNCATE, dl, MVT::i16, DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::i32, - DAG.getNode(ISD::BIT_CONVERT, dl, + DAG.getNode(ISD::BIT_CONVERT, dl, MVT::v4i32, Vec), Op.getOperand(1))); // Transform it so it match pextrw which produces a 32-bit result. @@ -4413,7 +4413,7 @@ &IdxVec[0], IdxVec.size()); SDValue Vec = Op.getOperand(0); Vec = DAG.getNode(ISD::VECTOR_SHUFFLE, dl, Vec.getValueType(), - Vec, DAG.getUNDEF(Vec.getValueType()), + Vec, DAG.getUNDEF(Vec.getValueType()), Mask); return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, VT, Vec, DAG.getIntPtrConstant(0)); @@ -4448,9 +4448,9 @@ // zero here. The DAG Combiner may combine an extract_elt index into these // bits. For example (insert (extract, 3), 2) could be matched by putting // the '3' into bits [7:6] of X86ISD::INSERTPS. - // Bits [5:4] of the constant are the destination select. This is the + // Bits [5:4] of the constant are the destination select. This is the // value of the incoming immediate. - // Bits [3:0] of the constant are the zero mask. The DAG Combiner may + // Bits [3:0] of the constant are the zero mask. The DAG Combiner may // combine either bitwise AND or insert of float 0.0 to set these bits. N2 = DAG.getIntPtrConstant(cast(N2)->getZExtValue() << 4); return DAG.getNode(X86ISD::INSERTPS, dl, VT, N0, N1, N2); @@ -4564,7 +4564,7 @@ DAG.getNode(X86ISD::GlobalBaseReg, dl, getPointerTy()), Result); } - + // For Darwin & Mingw32, external and weak symbols are indirect, so we want to // load the value at address GV, not the value of GV itself. This means that // the GlobalAddress must be in the base or index register of the address, not @@ -4718,7 +4718,7 @@ if (getTargetMachine().getRelocationModel() == Reloc::PIC_ && !Subtarget->isPICStyleRIPRel()) { Result = DAG.getNode(ISD::ADD, dl, getPointerTy(), - DAG.getNode(X86ISD::GlobalBaseReg, + DAG.getNode(X86ISD::GlobalBaseReg, DebugLoc::getUnknownLoc(), getPointerTy()), Result); @@ -4747,7 +4747,7 @@ } /// LowerShift - Lower SRA_PARTS and friends, which return two i32 values and -/// take a 2 x i32 value to shift plus a shift amount. +/// take a 2 x i32 value to shift plus a shift amount. SDValue X86TargetLowering::LowerShift(SDValue Op, SelectionDAG &DAG) { assert(Op.getNumOperands() == 3 && "Not a double-shift!"); MVT VT = Op.getValueType(); @@ -4758,7 +4758,7 @@ SDValue ShOpHi = Op.getOperand(1); SDValue ShAmt = Op.getOperand(2); SDValue Tmp1 = isSRA ? - DAG.getNode(ISD::SRA, dl, VT, ShOpHi, + DAG.getNode(ISD::SRA, dl, VT, ShOpHi, DAG.getConstant(VTBits - 1, MVT::i8)) : DAG.getConstant(0, VT); @@ -4797,14 +4797,14 @@ MVT SrcVT = Op.getOperand(0).getValueType(); assert(SrcVT.getSimpleVT() <= MVT::i64 && SrcVT.getSimpleVT() >= MVT::i16 && "Unknown SINT_TO_FP to lower!"); - + // These are really Legal; caller falls through into that case. if (SrcVT == MVT::i32 && isScalarFPTypeInSSEReg(Op.getValueType())) return SDValue(); - if (SrcVT == MVT::i64 && Op.getValueType() != MVT::f80 && + if (SrcVT == MVT::i64 && Op.getValueType() != MVT::f80 && Subtarget->is64Bit()) return SDValue(); - + DebugLoc dl = Op.getDebugLoc(); unsigned Size = SrcVT.getSizeInBits()/8; MachineFunction &MF = DAG.getMachineFunction(); @@ -4911,12 +4911,12 @@ MaskVec.push_back(DAG.getConstant(4, MVT::i32)); MaskVec.push_back(DAG.getConstant(1, MVT::i32)); MaskVec.push_back(DAG.getConstant(5, MVT::i32)); - SDValue UnpcklMask = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, + SDValue UnpcklMask = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, &MaskVec[0], MaskVec.size()); SmallVector MaskVec2; MaskVec2.push_back(DAG.getConstant(1, MVT::i32)); MaskVec2.push_back(DAG.getConstant(0, MVT::i32)); - SDValue ShufMask = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v2i32, + SDValue ShufMask = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v2i32, &MaskVec2[0], MaskVec2.size()); SDValue XR1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v4i32, @@ -5027,7 +5027,7 @@ "Unknown FP_TO_SINT to lower!"); // These are really Legal. - if (Op.getValueType() == MVT::i32 && + if (Op.getValueType() == MVT::i32 && isScalarFPTypeInSSEReg(Op.getOperand(0).getValueType())) return std::make_pair(SDValue(), SDValue()); if (Subtarget->is64Bit() && @@ -5076,7 +5076,7 @@ std::pair Vals = FP_TO_SINTHelper(Op, DAG); SDValue FIST = Vals.first, StackSlot = Vals.second; if (FIST.getNode() == 0) return SDValue(); - + // Load the result. return DAG.getLoad(Op.getValueType(), Op.getDebugLoc(), FIST, StackSlot, NULL, 0); @@ -5137,7 +5137,7 @@ if (VT.isVector()) { return DAG.getNode(ISD::BIT_CONVERT, dl, VT, DAG.getNode(ISD::XOR, dl, MVT::v2i64, - DAG.getNode(ISD::BIT_CONVERT, dl, MVT::v2i64, + DAG.getNode(ISD::BIT_CONVERT, dl, MVT::v2i64, Op.getOperand(0)), DAG.getNode(ISD::BIT_CONVERT, dl, MVT::v2i64, Mask))); } else { @@ -5223,7 +5223,7 @@ SDValue Op1 = Op.getOperand(1); DebugLoc dl = Op.getDebugLoc(); ISD::CondCode CC = cast(Op.getOperand(2))->get(); - + // Lower (X & (1 << N)) == 0 to BT(X, N). // Lower ((X >>u N) & 1) != 0 to BT(X, N). // Lower ((X >>s N) & 1) != 0 to BT(X, N). @@ -5278,7 +5278,7 @@ bool isFP = Op.getOperand(1).getValueType().isFloatingPoint(); unsigned X86CC = TranslateX86CC(CC, isFP, Op0, Op1, DAG); - + SDValue Cond = DAG.getNode(X86ISD::CMP, dl, MVT::i32, Op0, Op1); return DAG.getNode(X86ISD::SETCC, dl, MVT::i8, DAG.getConstant(X86CC, MVT::i8), Cond); @@ -5305,7 +5305,7 @@ default: break; case ISD::SETOEQ: case ISD::SETEQ: SSECC = 0; break; - case ISD::SETOGT: + case ISD::SETOGT: case ISD::SETGT: Swap = true; // Fallthrough case ISD::SETLT: case ISD::SETOLT: SSECC = 1; break; @@ -5344,13 +5344,13 @@ // Handle all other FP comparisons here. return DAG.getNode(Opc, dl, VT, Op0, Op1, DAG.getConstant(SSECC, MVT::i8)); } - + // We are handling one of the integer comparisons here. Since SSE only has // GT and EQ comparisons for integer, swapping operands and multiple // operations may be required for some comparisons. unsigned Opc = 0, EQOpc = 0, GTOpc = 0; bool Swap = false, Invert = false, FlipSigns = false; - + switch (VT.getSimpleVT()) { default: break; case MVT::v16i8: EQOpc = X86ISD::PCMPEQB; GTOpc = X86ISD::PCMPGTB; break; @@ -5358,7 +5358,7 @@ case MVT::v4i32: EQOpc = X86ISD::PCMPEQD; GTOpc = X86ISD::PCMPGTD; break; case MVT::v2i64: EQOpc = X86ISD::PCMPEQQ; GTOpc = X86ISD::PCMPGTQ; break; } - + switch (SetCCOpcode) { default: break; case ISD::SETNE: Invert = true; @@ -5374,7 +5374,7 @@ } if (Swap) std::swap(Op0, Op1); - + // Since SSE has no unsigned integer comparisons, we need to flip the sign // bits of the inputs before performing those operations. if (FlipSigns) { @@ -5387,7 +5387,7 @@ Op0 = DAG.getNode(ISD::XOR, dl, VT, Op0, SignVec); Op1 = DAG.getNode(ISD::XOR, dl, VT, Op1, SignVec); } - + SDValue Result = DAG.getNode(Opc, dl, VT, Op0, Op1); // If the logical-not of the result is required, perform that now. @@ -5419,12 +5419,12 @@ SDValue Cmp = Cond.getOperand(1); unsigned Opc = Cmp.getOpcode(); MVT VT = Op.getValueType(); - + bool IllegalFPCMov = false; if (VT.isFloatingPoint() && !VT.isVector() && !isScalarFPTypeInSSEReg(VT)) // FPStack? IllegalFPCMov = !hasFPCMov(cast(CC)->getSExtValue()); - + if ((isX86LogicalCmp(Opc) && !IllegalFPCMov) || Opc == X86ISD::BT) { // FIXME Cond = Cmp; addTest = false; @@ -5433,7 +5433,7 @@ if (addTest) { CC = DAG.getConstant(X86::COND_NE, MVT::i8); - Cond= DAG.getNode(X86ISD::CMP, dl, MVT::i32, Cond, + Cond= DAG.getNode(X86ISD::CMP, dl, MVT::i32, Cond, DAG.getConstant(0, MVT::i8)); } @@ -5493,7 +5493,7 @@ Cond.getOpcode() == X86ISD::UMUL) Cond = LowerXALUO(Cond, DAG); #endif - + // If condition flag is set by a X86ISD::CMP, then use it as the condition // setting operand in place of the X86ISD::SETCC. if (Cond.getOpcode() == X86ISD::SETCC) { @@ -5585,7 +5585,7 @@ if (addTest) { CC = DAG.getConstant(X86::COND_NE, MVT::i8); - Cond= DAG.getNode(X86ISD::CMP, dl, MVT::i32, Cond, + Cond= DAG.getNode(X86ISD::CMP, dl, MVT::i32, Cond, DAG.getConstant(0, MVT::i8)); } return DAG.getNode(X86ISD::BRCOND, dl, Op.getValueType(), @@ -5665,7 +5665,7 @@ V->isNullValue() ? Subtarget->getBZeroEntry() : 0) { MVT IntPtr = getPointerTy(); const Type *IntPtrTy = TD->getIntPtrType(); - TargetLowering::ArgListTy Args; + TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; Entry.Node = Dst; Entry.Ty = IntPtrTy; @@ -5673,8 +5673,8 @@ Entry.Node = Size; Args.push_back(Entry); std::pair CallResult = - LowerCallTo(Chain, Type::VoidTy, false, false, false, false, - CallingConv::C, false, + LowerCallTo(Chain, Type::VoidTy, false, false, false, false, + CallingConv::C, false, DAG.getExternalSymbol(bzeroEntry, IntPtr), Args, DAG, dl); return CallResult.second; } @@ -5735,11 +5735,11 @@ InFlag = Chain.getValue(1); } - Chain = DAG.getCopyToReg(Chain, dl, Subtarget->is64Bit() ? X86::RCX : + Chain = DAG.getCopyToReg(Chain, dl, Subtarget->is64Bit() ? X86::RCX : X86::ECX, Count, InFlag); InFlag = Chain.getValue(1); - Chain = DAG.getCopyToReg(Chain, dl, Subtarget->is64Bit() ? X86::RDI : + Chain = DAG.getCopyToReg(Chain, dl, Subtarget->is64Bit() ? X86::RDI : X86::EDI, Dst, InFlag); InFlag = Chain.getValue(1); @@ -5757,7 +5757,7 @@ MVT CVT = Count.getValueType(); SDValue Left = DAG.getNode(ISD::AND, dl, CVT, Count, DAG.getConstant((AVT == MVT::i64) ? 7 : 3, CVT)); - Chain = DAG.getCopyToReg(Chain, dl, (CVT == MVT::i64) ? X86::RCX : + Chain = DAG.getCopyToReg(Chain, dl, (CVT == MVT::i64) ? X86::RCX : X86::ECX, Left, InFlag); InFlag = Chain.getValue(1); @@ -5791,7 +5791,7 @@ SDValue Size, unsigned Align, bool AlwaysInline, const Value *DstSV, uint64_t DstSVOff, - const Value *SrcSV, uint64_t SrcSVOff) { + const Value *SrcSV, uint64_t SrcSVOff) { // This requires the copy size to be a constant, preferrably // within a subtarget-specific limit. ConstantSDNode *ConstantSize = dyn_cast(Size); @@ -5816,15 +5816,15 @@ unsigned BytesLeft = SizeVal % UBytes; SDValue InFlag(0, 0); - Chain = DAG.getCopyToReg(Chain, dl, Subtarget->is64Bit() ? X86::RCX : + Chain = DAG.getCopyToReg(Chain, dl, Subtarget->is64Bit() ? X86::RCX : X86::ECX, Count, InFlag); InFlag = Chain.getValue(1); - Chain = DAG.getCopyToReg(Chain, dl, Subtarget->is64Bit() ? X86::RDI : + Chain = DAG.getCopyToReg(Chain, dl, Subtarget->is64Bit() ? X86::RDI : X86::EDI, Dst, InFlag); InFlag = Chain.getValue(1); - Chain = DAG.getCopyToReg(Chain, dl, Subtarget->is64Bit() ? X86::RSI : + Chain = DAG.getCopyToReg(Chain, dl, Subtarget->is64Bit() ? X86::RSI : X86::ESI, Src, InFlag); InFlag = Chain.getValue(1); @@ -5844,7 +5844,7 @@ MVT DstVT = Dst.getValueType(); MVT SrcVT = Src.getValueType(); MVT SizeVT = Size.getValueType(); - Results.push_back(DAG.getMemcpy(Chain, dl, + Results.push_back(DAG.getMemcpy(Chain, dl, DAG.getNode(ISD::ADD, dl, DstVT, Dst, DAG.getConstant(Offset, DstVT)), DAG.getNode(ISD::ADD, dl, SrcVT, Src, @@ -5855,7 +5855,7 @@ SrcSV, SrcSVOff + Offset)); } - return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, + return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &Results[0], Results.size()); } @@ -5884,7 +5884,7 @@ MemOps.push_back(Store); // Store fp_offset - FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), + FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, DAG.getIntPtrConstant(4)); Store = DAG.getStore(Op.getOperand(0), dl, DAG.getConstant(VarArgsFPOffset, MVT::i32), @@ -5892,19 +5892,19 @@ MemOps.push_back(Store); // Store ptr to overflow_arg_area - FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), + FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, DAG.getIntPtrConstant(4)); SDValue OVFIN = DAG.getFrameIndex(VarArgsFrameIndex, getPointerTy()); Store = DAG.getStore(Op.getOperand(0), dl, OVFIN, FIN, SV, 0); MemOps.push_back(Store); // Store ptr to reg_save_area. - FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), + FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, DAG.getIntPtrConstant(8)); SDValue RSFIN = DAG.getFrameIndex(RegSaveFrameIndex, getPointerTy()); Store = DAG.getStore(Op.getOperand(0), dl, RSFIN, FIN, SV, 0); MemOps.push_back(Store); - return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, + return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &MemOps[0], MemOps.size()); } @@ -6142,14 +6142,14 @@ DAG.getConstant(TD->getPointerSize(), Subtarget->is64Bit() ? MVT::i64 : MVT::i32); return DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(), - DAG.getNode(ISD::ADD, dl, getPointerTy(), + DAG.getNode(ISD::ADD, dl, getPointerTy(), FrameAddr, Offset), NULL, 0); } // Just load the return address. SDValue RetAddrFI = getReturnAddressFrameIndex(DAG); - return DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(), + return DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(), RetAddrFI, NULL, 0); } @@ -6227,31 +6227,31 @@ OutChains[0] = DAG.getStore(Root, dl, DAG.getConstant(OpCode, MVT::i16), Addr, TrmpAddr, 0); - Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp, + Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp, DAG.getConstant(2, MVT::i64)); OutChains[1] = DAG.getStore(Root, dl, FPtr, Addr, TrmpAddr, 2, false, 2); // Load the 'nest' parameter value into R10. // R10 is specified in X86CallingConv.td OpCode = ((MOV64ri | N86R10) << 8) | REX_WB; // movabsq r10 - Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp, + Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp, DAG.getConstant(10, MVT::i64)); OutChains[2] = DAG.getStore(Root, dl, DAG.getConstant(OpCode, MVT::i16), Addr, TrmpAddr, 10); - Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp, + Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp, DAG.getConstant(12, MVT::i64)); OutChains[3] = DAG.getStore(Root, dl, Nest, Addr, TrmpAddr, 12, false, 2); // Jump to the nested function. OpCode = (JMP64r << 8) | REX_WB; // jmpq *... - Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp, + Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp, DAG.getConstant(20, MVT::i64)); OutChains[4] = DAG.getStore(Root, dl, DAG.getConstant(OpCode, MVT::i16), Addr, TrmpAddr, 20); unsigned char ModRM = N86R11 | (4 << 3) | (3 << 6); // ...r11 - Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp, + Addr = DAG.getNode(ISD::ADD, dl, MVT::i64, Trmp, DAG.getConstant(22, MVT::i64)); OutChains[5] = DAG.getStore(Root, dl, DAG.getConstant(ModRM, MVT::i8), Addr, TrmpAddr, 22); @@ -6306,27 +6306,27 @@ SDValue OutChains[4]; SDValue Addr, Disp; - Addr = DAG.getNode(ISD::ADD, dl, MVT::i32, Trmp, + Addr = DAG.getNode(ISD::ADD, dl, MVT::i32, Trmp, DAG.getConstant(10, MVT::i32)); Disp = DAG.getNode(ISD::SUB, dl, MVT::i32, FPtr, Addr); const unsigned char MOV32ri = TII->getBaseOpcodeFor(X86::MOV32ri); const unsigned char N86Reg = RegInfo->getX86RegNum(NestReg); - OutChains[0] = DAG.getStore(Root, dl, + OutChains[0] = DAG.getStore(Root, dl, DAG.getConstant(MOV32ri|N86Reg, MVT::i8), Trmp, TrmpAddr, 0); - Addr = DAG.getNode(ISD::ADD, dl, MVT::i32, Trmp, + Addr = DAG.getNode(ISD::ADD, dl, MVT::i32, Trmp, DAG.getConstant(1, MVT::i32)); OutChains[1] = DAG.getStore(Root, dl, Nest, Addr, TrmpAddr, 1, false, 1); const unsigned char JMP = TII->getBaseOpcodeFor(X86::JMP); - Addr = DAG.getNode(ISD::ADD, dl, MVT::i32, Trmp, + Addr = DAG.getNode(ISD::ADD, dl, MVT::i32, Trmp, DAG.getConstant(5, MVT::i32)); OutChains[2] = DAG.getStore(Root, dl, DAG.getConstant(JMP, MVT::i8), Addr, TrmpAddr, 5, false, 1); - Addr = DAG.getNode(ISD::ADD, dl, MVT::i32, Trmp, + Addr = DAG.getNode(ISD::ADD, dl, MVT::i32, Trmp, DAG.getConstant(6, MVT::i32)); OutChains[3] = DAG.getStore(Root, dl, Disp, Addr, TrmpAddr, 6, false, 1); @@ -6463,7 +6463,7 @@ MVT VT = Op.getValueType(); assert(VT == MVT::v2i64 && "Only know how to lower V2I64 multiply"); DebugLoc dl = Op.getDebugLoc(); - + // ulong2 Ahi = __builtin_ia32_psrlqi128( a, 32); // ulong2 Bhi = __builtin_ia32_psrlqi128( b, 32); // ulong2 AloBlo = __builtin_ia32_pmuludq128( a, b ); @@ -6476,7 +6476,7 @@ SDValue A = Op.getOperand(0); SDValue B = Op.getOperand(1); - + SDValue Ahi = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, DAG.getConstant(Intrinsic::x86_sse2_psrli_q, MVT::i32), A, DAG.getConstant(32, MVT::i32)); @@ -6567,7 +6567,7 @@ case MVT::i8: Reg = X86::AL; size = 1; break; case MVT::i16: Reg = X86::AX; size = 2; break; case MVT::i32: Reg = X86::EAX; size = 4; break; - case MVT::i64: + case MVT::i64: assert(Subtarget->is64Bit() && "Node not type legal!"); Reg = X86::RAX; size = 8; break; @@ -6581,7 +6581,7 @@ cpIn.getValue(1) }; SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Flag); SDValue Result = DAG.getNode(X86ISD::LCMPXCHG_DAG, dl, Tys, Ops, 5); - SDValue cpOut = + SDValue cpOut = DAG.getCopyFromReg(Result.getValue(0), dl, Reg, T, Result.getValue(1)); return cpOut; } @@ -6725,7 +6725,7 @@ SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Flag); SDValue TheChain = N->getOperand(0); SDValue rd = DAG.getNode(X86ISD::RDTSC_DAG, dl, Tys, &TheChain, 1); - SDValue eax = DAG.getCopyFromReg(rd, dl, X86::EAX, MVT::i32, + SDValue eax = DAG.getCopyFromReg(rd, dl, X86::EAX, MVT::i32, rd.getValue(1)); SDValue edx = DAG.getCopyFromReg(eax.getValue(1), dl, X86::EDX, MVT::i32, eax.getValue(2)); @@ -6871,14 +6871,14 @@ // isLegalAddressingMode - Return true if the addressing mode represented // by AM is legal for this target, for a load/store of the specified type. -bool X86TargetLowering::isLegalAddressingMode(const AddrMode &AM, +bool X86TargetLowering::isLegalAddressingMode(const AddrMode &AM, const Type *Ty) const { // X86 supports extremely general addressing modes. - + // X86 allows a sign-extended 32-bit immediate field as a displacement. if (AM.BaseOffs <= -(1LL << 32) || AM.BaseOffs >= (1LL << 32)-1) return false; - + if (AM.BaseGV) { // We can only fold this if we don't need an extra load. if (Subtarget->GVRequiresExtraLoad(AM.BaseGV, getTargetMachine(), false)) @@ -6897,7 +6897,7 @@ return false; } } - + switch (AM.Scale) { case 0: case 1: @@ -6917,7 +6917,7 @@ default: // Other stuff never works. return false; } - + return true; } @@ -6971,7 +6971,7 @@ if (NumElts == 4) { return (isMOVLMask(&BVOps[0], 4) || isCommutedMOVL(&BVOps[0], 4, true) || - isSHUFPMask(&BVOps[0], 4) || + isSHUFPMask(&BVOps[0], 4) || isCommutedSHUFP(&BVOps[0], 4)); } return false; @@ -7007,7 +7007,7 @@ const BasicBlock *LLVM_BB = MBB->getBasicBlock(); MachineFunction::iterator MBBIter = MBB; ++MBBIter; - + /// First build the CFG MachineFunction *F = MBB->getParent(); MachineBasicBlock *thisMBB = MBB; @@ -7015,17 +7015,17 @@ MachineBasicBlock *nextMBB = F->CreateMachineBasicBlock(LLVM_BB); F->insert(MBBIter, newMBB); F->insert(MBBIter, nextMBB); - + // Move all successors to thisMBB to nextMBB nextMBB->transferSuccessors(thisMBB); - + // Update thisMBB to fall through to newMBB thisMBB->addSuccessor(newMBB); - + // newMBB jumps to itself and fall through to nextMBB newMBB->addSuccessor(nextMBB); newMBB->addSuccessor(newMBB); - + // Insert instructions into newMBB based on incoming instruction assert(bInstr->getNumOperands() < 8 && "unexpected number of operands"); DebugLoc dl = bInstr->getDebugLoc(); @@ -7038,7 +7038,7 @@ // x86 address has 4 operands: base, index, scale, and displacement int lastAddrIndx = 3; // [0,3] int valArgIndx = 4; - + unsigned t1 = F->getRegInfo().createVirtualRegister(RC); MachineInstrBuilder MIB = BuildMI(newMBB, dl, TII->get(LoadOpc), t1); for (int i=0; i <= lastAddrIndx; ++i) @@ -7048,7 +7048,7 @@ if (invSrc) { MIB = BuildMI(newMBB, dl, TII->get(notOpc), tt).addReg(t1); } - else + else tt = t1; unsigned t2 = F->getRegInfo().createVirtualRegister(RC); @@ -7064,7 +7064,7 @@ MIB = BuildMI(newMBB, dl, TII->get(copyOpc), EAXreg); MIB.addReg(t1); - + MIB = BuildMI(newMBB, dl, TII->get(CXchgOpc)); for (int i=0; i <= lastAddrIndx; ++i) (*MIB).addOperand(*argOpers[i]); @@ -7074,7 +7074,7 @@ MIB = BuildMI(newMBB, dl, TII->get(copyOpc), destOper.getReg()); MIB.addReg(EAXreg); - + // insert branch BuildMI(newMBB, dl, TII->get(X86::JNE)).addMBB(newMBB); @@ -7114,7 +7114,7 @@ const BasicBlock *LLVM_BB = MBB->getBasicBlock(); MachineFunction::iterator MBBIter = MBB; ++MBBIter; - + /// First build the CFG MachineFunction *F = MBB->getParent(); MachineBasicBlock *thisMBB = MBB; @@ -7122,17 +7122,17 @@ MachineBasicBlock *nextMBB = F->CreateMachineBasicBlock(LLVM_BB); F->insert(MBBIter, newMBB); F->insert(MBBIter, nextMBB); - + // Move all successors to thisMBB to nextMBB nextMBB->transferSuccessors(thisMBB); - + // Update thisMBB to fall through to newMBB thisMBB->addSuccessor(newMBB); - + // newMBB jumps to itself and fall through to nextMBB newMBB->addSuccessor(nextMBB); newMBB->addSuccessor(newMBB); - + DebugLoc dl = bInstr->getDebugLoc(); // Insert instructions into newMBB based on incoming instruction // There are 8 "real" operands plus 9 implicit def/uses, ignored here. @@ -7145,7 +7145,7 @@ // x86 address has 4 operands: base, index, scale, and displacement int lastAddrIndx = 3; // [0,3] - + unsigned t1 = F->getRegInfo().createVirtualRegister(RC); MachineInstrBuilder MIB = BuildMI(thisMBB, dl, TII->get(LoadOpc), t1); for (int i=0; i <= lastAddrIndx; ++i) @@ -7172,7 +7172,7 @@ unsigned tt1 = F->getRegInfo().createVirtualRegister(RC); unsigned tt2 = F->getRegInfo().createVirtualRegister(RC); - if (invSrc) { + if (invSrc) { MIB = BuildMI(newMBB, dl, TII->get(NotOpc), tt1).addReg(t1); MIB = BuildMI(newMBB, dl, TII->get(NotOpc), tt2).addReg(t2); } else { @@ -7210,7 +7210,7 @@ MIB.addReg(t5); MIB = BuildMI(newMBB, dl, TII->get(copyOpc), X86::ECX); MIB.addReg(t6); - + MIB = BuildMI(newMBB, dl, TII->get(X86::LCMPXCHG8B)); for (int i=0; i <= lastAddrIndx; ++i) (*MIB).addOperand(*argOpers[i]); @@ -7222,7 +7222,7 @@ MIB.addReg(X86::EAX); MIB = BuildMI(newMBB, dl, TII->get(copyOpc), t4); MIB.addReg(X86::EDX); - + // insert branch BuildMI(newMBB, dl, TII->get(X86::JNE)).addMBB(newMBB); @@ -7239,7 +7239,7 @@ // thisMBB: // newMBB: // ld t1 = [min/max.addr] - // mov t2 = [min/max.val] + // mov t2 = [min/max.val] // cmp t1, t2 // cmov[cond] t2 = t1 // mov EAX = t1 @@ -7251,7 +7251,7 @@ const BasicBlock *LLVM_BB = MBB->getBasicBlock(); MachineFunction::iterator MBBIter = MBB; ++MBBIter; - + /// First build the CFG MachineFunction *F = MBB->getParent(); MachineBasicBlock *thisMBB = MBB; @@ -7259,17 +7259,17 @@ MachineBasicBlock *nextMBB = F->CreateMachineBasicBlock(LLVM_BB); F->insert(MBBIter, newMBB); F->insert(MBBIter, nextMBB); - + // Move all successors to thisMBB to nextMBB nextMBB->transferSuccessors(thisMBB); - + // Update thisMBB to fall through to newMBB thisMBB->addSuccessor(newMBB); - + // newMBB jumps to newMBB and fall through to nextMBB newMBB->addSuccessor(nextMBB); newMBB->addSuccessor(newMBB); - + DebugLoc dl = mInstr->getDebugLoc(); // Insert instructions into newMBB based on incoming instruction assert(mInstr->getNumOperands() < 8 && "unexpected number of operands"); @@ -7278,11 +7278,11 @@ int numArgs = mInstr->getNumOperands() - 1; for (int i=0; i < numArgs; ++i) argOpers[i] = &mInstr->getOperand(i+1); - + // x86 address has 4 operands: base, index, scale, and displacement int lastAddrIndx = 3; // [0,3] int valArgIndx = 4; - + unsigned t1 = F->getRegInfo().createVirtualRegister(X86::GR32RegisterClass); MachineInstrBuilder MIB = BuildMI(newMBB, dl, TII->get(X86::MOV32rm), t1); for (int i=0; i <= lastAddrIndx; ++i) @@ -7292,11 +7292,11 @@ assert((argOpers[valArgIndx]->isReg() || argOpers[valArgIndx]->isImm()) && "invalid operand"); - - unsigned t2 = F->getRegInfo().createVirtualRegister(X86::GR32RegisterClass); + + unsigned t2 = F->getRegInfo().createVirtualRegister(X86::GR32RegisterClass); if (argOpers[valArgIndx]->isReg()) MIB = BuildMI(newMBB, dl, TII->get(X86::MOV32rr), t2); - else + else MIB = BuildMI(newMBB, dl, TII->get(X86::MOV32rr), t2); (*MIB).addOperand(*argOpers[valArgIndx]); @@ -7320,10 +7320,10 @@ MIB.addReg(t3); assert(mInstr->hasOneMemOperand() && "Unexpected number of memoperand"); (*MIB).addMemOperand(*F, *mInstr->memoperands_begin()); - + MIB = BuildMI(newMBB, dl, TII->get(X86::MOV32rr), destOper.getReg()); MIB.addReg(X86::EAX); - + // insert branch BuildMI(newMBB, dl, TII->get(X86::JNE)).addMBB(newMBB); @@ -7414,7 +7414,7 @@ // Load the old value of the high byte of the control word... unsigned OldCW = F->getRegInfo().createVirtualRegister(X86::GR16RegisterClass); - addFrameReference(BuildMI(BB, dl, TII->get(X86::MOV16rm), OldCW), + addFrameReference(BuildMI(BB, dl, TII->get(X86::MOV16rm), OldCW), CWFrameIdx); // Set the high part to be round to zero... @@ -7475,19 +7475,19 @@ } case X86::ATOMAND32: return EmitAtomicBitwiseWithCustomInserter(MI, BB, X86::AND32rr, - X86::AND32ri, X86::MOV32rm, + X86::AND32ri, X86::MOV32rm, X86::LCMPXCHG32, X86::MOV32rr, X86::NOT32r, X86::EAX, X86::GR32RegisterClass); case X86::ATOMOR32: - return EmitAtomicBitwiseWithCustomInserter(MI, BB, X86::OR32rr, - X86::OR32ri, X86::MOV32rm, + return EmitAtomicBitwiseWithCustomInserter(MI, BB, X86::OR32rr, + X86::OR32ri, X86::MOV32rm, X86::LCMPXCHG32, X86::MOV32rr, X86::NOT32r, X86::EAX, X86::GR32RegisterClass); case X86::ATOMXOR32: return EmitAtomicBitwiseWithCustomInserter(MI, BB, X86::XOR32rr, - X86::XOR32ri, X86::MOV32rm, + X86::XOR32ri, X86::MOV32rm, X86::LCMPXCHG32, X86::MOV32rr, X86::NOT32r, X86::EAX, X86::GR32RegisterClass); @@ -7513,7 +7513,7 @@ X86::NOT16r, X86::AX, X86::GR16RegisterClass); case X86::ATOMOR16: - return EmitAtomicBitwiseWithCustomInserter(MI, BB, X86::OR16rr, + return EmitAtomicBitwiseWithCustomInserter(MI, BB, X86::OR16rr, X86::OR16ri, X86::MOV16rm, X86::LCMPXCHG16, X86::MOV16rr, X86::NOT16r, X86::AX, @@ -7546,7 +7546,7 @@ X86::NOT8r, X86::AL, X86::GR8RegisterClass); case X86::ATOMOR8: - return EmitAtomicBitwiseWithCustomInserter(MI, BB, X86::OR8rr, + return EmitAtomicBitwiseWithCustomInserter(MI, BB, X86::OR8rr, X86::OR8ri, X86::MOV8rm, X86::LCMPXCHG8, X86::MOV8rr, X86::NOT8r, X86::AL, @@ -7567,19 +7567,19 @@ // This group is for 64-bit host. case X86::ATOMAND64: return EmitAtomicBitwiseWithCustomInserter(MI, BB, X86::AND64rr, - X86::AND64ri32, X86::MOV64rm, + X86::AND64ri32, X86::MOV64rm, X86::LCMPXCHG64, X86::MOV64rr, X86::NOT64r, X86::RAX, X86::GR64RegisterClass); case X86::ATOMOR64: - return EmitAtomicBitwiseWithCustomInserter(MI, BB, X86::OR64rr, - X86::OR64ri32, X86::MOV64rm, + return EmitAtomicBitwiseWithCustomInserter(MI, BB, X86::OR64rr, + X86::OR64ri32, X86::MOV64rm, X86::LCMPXCHG64, X86::MOV64rr, X86::NOT64r, X86::RAX, X86::GR64RegisterClass); case X86::ATOMXOR64: return EmitAtomicBitwiseWithCustomInserter(MI, BB, X86::XOR64rr, - X86::XOR64ri32, X86::MOV64rm, + X86::XOR64ri32, X86::MOV64rm, X86::LCMPXCHG64, X86::MOV64rr, X86::NOT64r, X86::RAX, X86::GR64RegisterClass); @@ -7600,37 +7600,37 @@ // This group does 64-bit operations on a 32-bit host. case X86::ATOMAND6432: - return EmitAtomicBit6432WithCustomInserter(MI, BB, + return EmitAtomicBit6432WithCustomInserter(MI, BB, X86::AND32rr, X86::AND32rr, X86::AND32ri, X86::AND32ri, false); case X86::ATOMOR6432: - return EmitAtomicBit6432WithCustomInserter(MI, BB, + return EmitAtomicBit6432WithCustomInserter(MI, BB, X86::OR32rr, X86::OR32rr, X86::OR32ri, X86::OR32ri, false); case X86::ATOMXOR6432: - return EmitAtomicBit6432WithCustomInserter(MI, BB, + return EmitAtomicBit6432WithCustomInserter(MI, BB, X86::XOR32rr, X86::XOR32rr, X86::XOR32ri, X86::XOR32ri, false); case X86::ATOMNAND6432: - return EmitAtomicBit6432WithCustomInserter(MI, BB, + return EmitAtomicBit6432WithCustomInserter(MI, BB, X86::AND32rr, X86::AND32rr, X86::AND32ri, X86::AND32ri, true); case X86::ATOMADD6432: - return EmitAtomicBit6432WithCustomInserter(MI, BB, + return EmitAtomicBit6432WithCustomInserter(MI, BB, X86::ADD32rr, X86::ADC32rr, X86::ADD32ri, X86::ADC32ri, false); case X86::ATOMSUB6432: - return EmitAtomicBit6432WithCustomInserter(MI, BB, + return EmitAtomicBit6432WithCustomInserter(MI, BB, X86::SUB32rr, X86::SBB32rr, X86::SUB32ri, X86::SBB32ri, false); case X86::ATOMSWAP6432: - return EmitAtomicBit6432WithCustomInserter(MI, BB, + return EmitAtomicBit6432WithCustomInserter(MI, BB, X86::MOV32rr, X86::MOV32rr, X86::MOV32ri, X86::MOV32ri, false); @@ -7751,7 +7751,7 @@ LoadSDNode *LD = cast(Base); if (isBaseAlignmentOfN(16, Base->getOperand(1).getNode(), TLI)) return DAG.getLoad(VT, dl, LD->getChain(), LD->getBasePtr(), - LD->getSrcValue(), LD->getSrcValueOffset(), + LD->getSrcValue(), LD->getSrcValueOffset(), LD->isVolatile()); return DAG.getLoad(VT, dl, LD->getChain(), LD->getBasePtr(), LD->getSrcValue(), LD->getSrcValueOffset(), @@ -7794,7 +7794,7 @@ // Transform it into VZEXT_LOAD addr. LoadSDNode *LD = cast(Base); - + // Load must not be an extload. if (LD->getExtensionType() != ISD::NON_EXTLOAD) return SDValue(); @@ -7810,7 +7810,7 @@ TLO.CombineTo(SDValue(Base, 1), ResNode.getValue(1)); DCI.CommitTargetLoweringOpt(TLO); return ResNode; -} +} /// PerformSELECTCombine - Do target-specific dag combines on SELECT nodes. static SDValue PerformSELECTCombine(SDNode *N, SelectionDAG &DAG, @@ -7895,11 +7895,11 @@ // so we have no knowledge of the shift amount. if (!Subtarget->hasSSE2()) return SDValue(); - + MVT VT = N->getValueType(0); if (VT != MVT::v2i64 && VT != MVT::v4i32 && VT != MVT::v8i16) return SDValue(); - + SDValue ShAmtOp = N->getOperand(1); MVT EltVT = VT.getVectorElementType(); DebugLoc dl = N->getDebugLoc(); @@ -8017,14 +8017,14 @@ DebugLoc dl = N->getDebugLoc(); // If we are a 64-bit capable x86, lower to a single movq load/store pair. if (Subtarget->is64Bit()) { - SDValue NewLd = DAG.getLoad(MVT::i64, dl, Ld->getChain(), - Ld->getBasePtr(), Ld->getSrcValue(), + SDValue NewLd = DAG.getLoad(MVT::i64, dl, Ld->getChain(), + Ld->getBasePtr(), Ld->getSrcValue(), Ld->getSrcValueOffset(), Ld->isVolatile(), Ld->getAlignment()); SDValue NewChain = NewLd.getValue(1); if (TokenFactorIndex != -1) { Ops.push_back(NewChain); - NewChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &Ops[0], + NewChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &Ops[0], Ops.size()); } return DAG.getStore(NewChain, dl, NewLd, St->getBasePtr(), @@ -8042,14 +8042,14 @@ Ld->isVolatile(), Ld->getAlignment()); SDValue HiLd = DAG.getLoad(MVT::i32, dl, Ld->getChain(), HiAddr, Ld->getSrcValue(), Ld->getSrcValueOffset()+4, - Ld->isVolatile(), + Ld->isVolatile(), MinAlign(Ld->getAlignment(), 4)); SDValue NewChain = LoLd.getValue(1); if (TokenFactorIndex != -1) { Ops.push_back(LoLd); Ops.push_back(HiLd); - NewChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &Ops[0], + NewChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &Ops[0], Ops.size()); } @@ -8063,7 +8063,7 @@ SDValue HiSt = DAG.getStore(NewChain, dl, HiLd, HiAddr, St->getSrcValue(), St->getSrcValueOffset() + 4, - St->isVolatile(), + St->isVolatile(), MinAlign(St->getAlignment(), 4)); return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, LoSt, HiSt); } @@ -8184,7 +8184,7 @@ if (Subtarget->hasSSE1()) return "x"; } - + return TargetLowering::LowerXConstraint(ConstraintVT); } @@ -8196,7 +8196,7 @@ std::vector&Ops, SelectionDAG &DAG) const { SDValue Result(0, 0); - + switch (Constraint) { default: break; case 'I': @@ -8262,7 +8262,7 @@ // an optional displacement) to be used with 'i'. GlobalAddressSDNode *GA = dyn_cast(Op); int64_t Offset = 0; - + // Match either (GA) or (GA+C) if (GA) { Offset = GA->getOffset(); @@ -8280,9 +8280,9 @@ C = 0, GA = 0; } } - + if (GA) { - if (hasMemory) + if (hasMemory) Op = LowerGlobalAddress(GA->getGlobal(), Op.getDebugLoc(), Offset, DAG); else @@ -8296,7 +8296,7 @@ return; } } - + if (Result.getNode()) { Ops.push_back(Result); return; @@ -8346,7 +8346,7 @@ if (VT == MVT::i16) return std::make_pair(0U, X86::GR16RegisterClass); if (VT == MVT::i32 || !Subtarget->is64Bit()) - return std::make_pair(0U, X86::GR32RegisterClass); + return std::make_pair(0U, X86::GR32RegisterClass); return std::make_pair(0U, X86::GR64RegisterClass); case 'f': // FP Stack registers. // If SSE is enabled for this VT, use f80 to ensure the isel moves the @@ -8386,7 +8386,7 @@ break; } } - + // Use the default implementation in TargetLowering to convert the register // constraint into a member of a register class. std::pair Res; @@ -8498,24 +8498,24 @@ assert(VT.isVector()); if (isTypeLegal(VT)) return VT; - + // TODO: In computeRegisterProperty, we can compute the list of legal vector // type based on element type. This would speed up our search (though // it may not be worth it since the size of the list is relatively // small). MVT EltVT = VT.getVectorElementType(); unsigned NElts = VT.getVectorNumElements(); - + // On X86, it make sense to widen any vector wider than 1 if (NElts <= 1) return MVT::Other; - - for (unsigned nVT = MVT::FIRST_VECTOR_VALUETYPE; + + for (unsigned nVT = MVT::FIRST_VECTOR_VALUETYPE; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) { MVT SVT = (MVT::SimpleValueType)nVT; - - if (isTypeLegal(SVT) && - SVT.getVectorElementType() == EltVT && + + if (isTypeLegal(SVT) && + SVT.getVectorElementType() == EltVT && SVT.getVectorNumElements() > NElts) return SVT; } From kremenek at apple.com Tue Feb 17 16:16:30 2009 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 17 Feb 2009 22:16:30 -0000 Subject: [llvm-commits] [llvm] r64829 - /llvm/tags/checker/checker-0.158/ Message-ID: <200902172216.n1HMGUGV022483@zion.cs.uiuc.edu> Author: kremenek Date: Tue Feb 17 16:16:29 2009 New Revision: 64829 URL: http://llvm.org/viewvc/llvm-project?rev=64829&view=rev Log: Removing checker-0.158. Removed: llvm/tags/checker/checker-0.158/ From baldrick at free.fr Tue Feb 17 16:20:32 2009 From: baldrick at free.fr (Duncan Sands) Date: Tue, 17 Feb 2009 23:20:32 +0100 Subject: [llvm-commits] [llvm] r64827 - in /llvm/trunk: include/llvm/CodeGen/SelectionDAG.h include/llvm/CodeGen/SelectionDAGNodes.h lib/CodeGen/SelectionDAG/DAGCombiner.cpp lib/CodeGen/SelectionDAG/LegalizeDAG.cpp lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp lib/Target/PowerPC/PPCISelLowering.cpp lib/Target/X86/X86ISelLowering.cpp In-Reply-To: <200902172215.n1HMF5P2022402@zion.cs.uiuc.edu> References: <200902172215.n1HMF5P2022402@zion.cs.uiuc.edu> Message-ID: <200902172320.33140.baldrick@free.fr> Hi Scott, > (Note: Eventually, commits like this will be handled via a pre-commit hook that > does this automagically, as well as expand tabs to spaces and look for 80-col > violations.) the last time I read the subversion book, it recommended not doing this. They instead advised having a script that rejects a commit if it introduces trailing whitespace. Ciao, Duncan. From mrs at apple.com Tue Feb 17 16:33:53 2009 From: mrs at apple.com (Mike Stump) Date: Tue, 17 Feb 2009 14:33:53 -0800 Subject: [llvm-commits] [llvm] r64827 - in /llvm/trunk: include/llvm/CodeGen/SelectionDAG.h include/llvm/CodeGen/SelectionDAGNodes.h lib/CodeGen/SelectionDAG/DAGCombiner.cpp lib/CodeGen/SelectionDAG/LegalizeDAG.cpp lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp lib/Target/PowerPC/PPCISelLowering.cpp lib/Target/X86/X86ISelLowering.cpp In-Reply-To: <200902172320.33140.baldrick@free.fr> References: <200902172215.n1HMF5P2022402@zion.cs.uiuc.edu> <200902172320.33140.baldrick@free.fr> Message-ID: On Feb 17, 2009, at 2:20 PM, Duncan Sands wrote: > the last time I read the subversion book, it recommended not doing > this. > They instead advised having a script that rejects a commit if it > introduces > trailing whitespace. Yeah, and we could wire up make to check during a build as well. From isanbard at gmail.com Tue Feb 17 16:34:17 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 22:34:17 -0000 Subject: [llvm-commits] [llvm] r64833 - /llvm/branches/Apple/Dib/lib/Transforms/Scalar/InstructionCombining.cpp Message-ID: <200902172234.n1HMYH86023224@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 16:34:16 2009 New Revision: 64833 URL: http://llvm.org/viewvc/llvm-project?rev=64833&view=rev Log: Upgrade to TOT. Modified: llvm/branches/Apple/Dib/lib/Transforms/Scalar/InstructionCombining.cpp Modified: llvm/branches/Apple/Dib/lib/Transforms/Scalar/InstructionCombining.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/Scalar/InstructionCombining.cpp?rev=64833&r1=64832&r2=64833&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Transforms/Scalar/InstructionCombining.cpp (original) +++ llvm/branches/Apple/Dib/lib/Transforms/Scalar/InstructionCombining.cpp Tue Feb 17 16:34:16 2009 @@ -1538,11 +1538,12 @@ } } + APInt UndefElts4(LHSVWidth, 0); TmpV = SimplifyDemandedVectorElts(I->getOperand(0), LeftDemanded, - UndefElts2, Depth+1); + UndefElts4, Depth+1); if (TmpV) { I->setOperand(0, TmpV); MadeChange = true; } - APInt UndefElts3(VWidth, 0); + APInt UndefElts3(LHSVWidth, 0); TmpV = SimplifyDemandedVectorElts(I->getOperand(1), RightDemanded, UndefElts3, Depth+1); if (TmpV) { I->setOperand(1, TmpV); MadeChange = true; } @@ -1553,7 +1554,7 @@ if (MaskVal == -1u) { UndefElts.set(i); } else if (MaskVal < LHSVWidth) { - if (UndefElts2[MaskVal]) { + if (UndefElts4[MaskVal]) { NewUndefElts = true; UndefElts.set(i); } @@ -8270,32 +8271,35 @@ Value *Src = CI.getOperand(0); - // If this is a cast of a cast - if (CastInst *CSrc = dyn_cast(Src)) { // A->B->C cast - // If this is a TRUNC followed by a ZEXT then we are dealing with integral - // types and if the sizes are just right we can convert this into a logical - // 'and' which will be much cheaper than the pair of casts. - if (isa(CSrc)) { - // Get the sizes of the types involved - Value *A = CSrc->getOperand(0); - uint32_t SrcSize = A->getType()->getPrimitiveSizeInBits(); - uint32_t MidSize = CSrc->getType()->getPrimitiveSizeInBits(); - uint32_t DstSize = CI.getType()->getPrimitiveSizeInBits(); - // If we're actually extending zero bits and the trunc is a no-op - if (MidSize < DstSize && SrcSize == DstSize) { - // Replace both of the casts with an And of the type mask. - APInt AndValue(APInt::getLowBitsSet(SrcSize, MidSize)); - Constant *AndConst = ConstantInt::get(AndValue); - Instruction *And = - BinaryOperator::CreateAnd(CSrc->getOperand(0), AndConst); - // Unfortunately, if the type changed, we need to cast it back. - if (And->getType() != CI.getType()) { - And->setName(CSrc->getName()+".mask"); - InsertNewInstBefore(And, CI); - And = CastInst::CreateIntegerCast(And, CI.getType(), false/*ZExt*/); - } - return And; - } + // If this is a TRUNC followed by a ZEXT then we are dealing with integral + // types and if the sizes are just right we can convert this into a logical + // 'and' which will be much cheaper than the pair of casts. + if (TruncInst *CSrc = dyn_cast(Src)) { // A->B->C cast + // Get the sizes of the types involved. We know that the intermediate type + // will be smaller than A or C, but don't know the relation between A and C. + Value *A = CSrc->getOperand(0); + unsigned SrcSize = A->getType()->getPrimitiveSizeInBits(); + unsigned MidSize = CSrc->getType()->getPrimitiveSizeInBits(); + unsigned DstSize = CI.getType()->getPrimitiveSizeInBits(); + // If we're actually extending zero bits, then if + // SrcSize < DstSize: zext(a & mask) + // SrcSize == DstSize: a & mask + // SrcSize > DstSize: trunc(a) & mask + if (SrcSize < DstSize) { + APInt AndValue(APInt::getLowBitsSet(SrcSize, MidSize)); + Constant *AndConst = ConstantInt::get(AndValue); + Instruction *And = + BinaryOperator::CreateAnd(A, AndConst, CSrc->getName()+".mask"); + InsertNewInstBefore(And, CI); + return new ZExtInst(And, CI.getType()); + } else if (SrcSize == DstSize) { + APInt AndValue(APInt::getLowBitsSet(SrcSize, MidSize)); + return BinaryOperator::CreateAnd(A, ConstantInt::get(AndValue)); + } else if (SrcSize > DstSize) { + Instruction *Trunc = new TruncInst(A, CI.getType(), "tmp"); + InsertNewInstBefore(Trunc, CI); + APInt AndValue(APInt::getLowBitsSet(DstSize, MidSize)); + return BinaryOperator::CreateAnd(Trunc, ConstantInt::get(AndValue)); } } @@ -9236,15 +9240,23 @@ // If there is a large requested alignment and we can, bump up the alignment // of the global. if (!GV->isDeclaration()) { - GV->setAlignment(PrefAlign); - Align = PrefAlign; + if (GV->getAlignment() >= PrefAlign) + Align = GV->getAlignment(); + else { + GV->setAlignment(PrefAlign); + Align = PrefAlign; + } } } else if (AllocationInst *AI = dyn_cast(V)) { // If there is a requested alignment and if this is an alloca, round up. We // don't do this for malloc, because some systems can't respect the request. if (isa(AI)) { - AI->setAlignment(PrefAlign); - Align = PrefAlign; + if (AI->getAlignment() >= PrefAlign) + Align = AI->getAlignment(); + else { + AI->setAlignment(PrefAlign); + Align = PrefAlign; + } } } @@ -9274,7 +9286,7 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) { unsigned DstAlign = GetOrEnforceKnownAlignment(MI->getOperand(1)); - unsigned SrcAlign = GetOrEnforceKnownAlignment(MI->getOperand(2)); + unsigned SrcAlign = GetOrEnforceKnownAlignment(MI->getOperand(2), DstAlign); unsigned MinAlign = std::min(DstAlign, SrcAlign); unsigned CopyAlign = MI->getAlignment()->getZExtValue(); @@ -11096,7 +11108,8 @@ Value *Op = LI.getOperand(0); // Attempt to improve the alignment. - unsigned KnownAlign = GetOrEnforceKnownAlignment(Op); + unsigned KnownAlign = + GetOrEnforceKnownAlignment(Op, TD->getPrefTypeAlignment(LI.getType())); if (KnownAlign > (LI.getAlignment() == 0 ? TD->getABITypeAlignment(LI.getType()) : LI.getAlignment())) @@ -11375,7 +11388,8 @@ } // Attempt to improve the alignment. - unsigned KnownAlign = GetOrEnforceKnownAlignment(Ptr); + unsigned KnownAlign = + GetOrEnforceKnownAlignment(Ptr, TD->getPrefTypeAlignment(Val->getType())); if (KnownAlign > (SI.getAlignment() == 0 ? TD->getABITypeAlignment(Val->getType()) : SI.getAlignment())) From dalej at apple.com Tue Feb 17 16:36:32 2009 From: dalej at apple.com (Dale Johannesen) Date: Tue, 17 Feb 2009 14:36:32 -0800 Subject: [llvm-commits] [llvm] r64827 - in /llvm/trunk: include/llvm/CodeGen/SelectionDAG.h include/llvm/CodeGen/SelectionDAGNodes.h lib/CodeGen/SelectionDAG/DAGCombiner.cpp lib/CodeGen/SelectionDAG/LegalizeDAG.cpp lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp lib/Target/PowerPC/PPCISelLowering.cpp lib/Target/X86/X86ISelLowering.cpp In-Reply-To: <200902172320.33140.baldrick@free.fr> References: <200902172215.n1HMF5P2022402@zion.cs.uiuc.edu> <200902172320.33140.baldrick@free.fr> Message-ID: <60C9CCC9-2E35-43C1-8782-514D4C522D8C@apple.com> On Feb 17, 2009, at 2:20 PMPST, Duncan Sands wrote: > Hi Scott, > >> (Note: Eventually, commits like this will be handled via a pre- >> commit hook that >> does this automagically, as well as expand tabs to spaces and look >> for 80-col >> violations.) > > the last time I read the subversion book, it recommended not doing > this. > They instead advised having a script that rejects a commit if it > introduces > trailing whitespace. Whoa! There is absolutely no reason (except pedantry) to disallow this, and everybody's time would be better spent working on things that actually matter. If you've got an editor that makes changes to your code you didn't tell it to, that's a serious bug; I'd either fix it or get a different editor. I realize not everybody sees things that way, but I see no reason your misguided opinion should interfere with my work.:) A script along the lines Scott suggests is OK (assuming it doesn't slow things down noticeably), but I strongly object to having patches rejected for mere pedantry. From dpatel at apple.com Tue Feb 17 16:43:44 2009 From: dpatel at apple.com (Devang Patel) Date: Tue, 17 Feb 2009 22:43:44 -0000 Subject: [llvm-commits] [llvm] r64834 - in /llvm/trunk: include/llvm/Analysis/DebugInfo.h include/llvm/Support/Dwarf.h lib/Analysis/DebugInfo.cpp lib/CodeGen/AsmPrinter/DwarfWriter.cpp lib/Support/Dwarf.cpp tools/lto/LTOCodeGenerator.cpp Message-ID: <200902172243.n1HMhiaQ023672@zion.cs.uiuc.edu> Author: dpatel Date: Tue Feb 17 16:43:44 2009 New Revision: 64834 URL: http://llvm.org/viewvc/llvm-project?rev=64834&view=rev Log: The debugger sometimes lookup dynamically in the runtime to find ivar info of any Objective-C classes. It would be very helpful to debugger if the compiler encodes runtime version number in DWARF. Add support for two additional DWARF attributes to encode Objective-C runtime version number. Modified: llvm/trunk/include/llvm/Analysis/DebugInfo.h llvm/trunk/include/llvm/Support/Dwarf.h llvm/trunk/lib/Analysis/DebugInfo.cpp llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp llvm/trunk/lib/Support/Dwarf.cpp llvm/trunk/tools/lto/LTOCodeGenerator.cpp Modified: llvm/trunk/include/llvm/Analysis/DebugInfo.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/DebugInfo.h?rev=64834&r1=64833&r2=64834&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/DebugInfo.h (original) +++ llvm/trunk/include/llvm/Analysis/DebugInfo.h Tue Feb 17 16:43:44 2009 @@ -118,9 +118,11 @@ /// code generator accepts maximum one main compile unit per module. If a /// module does not contain any main compile unit then the code generator /// will emit multiple compile units in the output object file. + bool isMain() const { return getUnsignedField(6); } bool isOptimized() const { return getUnsignedField(7); } std::string getFlags() const { return getStringField(8); } + unsigned getRunTimeVersion() const { return getUnsignedField(9); } /// Verify - Verify that a compile unit is well formed. bool Verify() const; @@ -231,6 +233,7 @@ public: explicit DICompositeType(GlobalVariable *GV); DIArray getTypeArray() const { return getFieldAs(10); } + unsigned getRunTimeLang() const { return getUnsignedField(11); } /// Verify - Verify that a composite type descriptor is well formed. bool Verify() const; @@ -381,7 +384,8 @@ const std::string &Producer, bool isMain = false, bool isOptimized = false, - const char *Flags = ""); + const char *Flags = "", + unsigned RunTimeVer = 0); /// CreateEnumerator - Create a single enumerator value. DIEnumerator CreateEnumerator(const std::string &Name, uint64_t Val); @@ -412,7 +416,8 @@ uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, DIType DerivedFrom, - DIArray Elements); + DIArray Elements, + unsigned RunTimeLang = 0); /// CreateSubprogram - Create a new descriptor for the specified subprogram. /// See comments in DISubprogram for descriptions of these fields. Modified: llvm/trunk/include/llvm/Support/Dwarf.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Dwarf.h?rev=64834&r1=64833&r2=64834&view=diff ============================================================================== --- llvm/trunk/include/llvm/Support/Dwarf.h (original) +++ llvm/trunk/include/llvm/Support/Dwarf.h Tue Feb 17 16:43:44 2009 @@ -225,6 +225,8 @@ // Apple extensions. DW_AT_APPLE_optimized = 0x3fe1, DW_AT_APPLE_flags = 0x3fe2, + DW_AT_APPLE_major_runtime_vers = 0x3fe5, + DW_AT_APPLE_runtime_class = 0x3fe6, // Attribute form encodings DW_FORM_addr = 0x01, Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=64834&r1=64833&r2=64834&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/DebugInfo.cpp (original) +++ llvm/trunk/lib/Analysis/DebugInfo.cpp Tue Feb 17 16:43:44 2009 @@ -453,7 +453,8 @@ const std::string &Producer, bool isMain, bool isOptimized, - const char *Flags) { + const char *Flags, + unsigned RunTimeVer) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_compile_unit), getCastToEmpty(GetOrCreateCompileUnitAnchor()), @@ -463,7 +464,8 @@ GetStringConstant(Producer), ConstantInt::get(Type::Int1Ty, isMain), ConstantInt::get(Type::Int1Ty, isOptimized), - GetStringConstant(Flags) + GetStringConstant(Flags), + ConstantInt::get(Type::Int32Ty, RunTimeVer) }; Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); @@ -573,7 +575,8 @@ uint64_t OffsetInBits, unsigned Flags, DIType DerivedFrom, - DIArray Elements) { + DIArray Elements, + unsigned RuntimeLang) { Constant *Elts[] = { GetTagConstant(Tag), @@ -586,7 +589,8 @@ ConstantInt::get(Type::Int64Ty, OffsetInBits), ConstantInt::get(Type::Int32Ty, Flags), getCastToEmpty(DerivedFrom), - getCastToEmpty(Elements) + getCastToEmpty(Elements), + ConstantInt::get(Type::Int32Ty, RuntimeLang) }; Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp?rev=64834&r1=64833&r2=64834&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp (original) +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Tue Feb 17 16:43:44 2009 @@ -1770,6 +1770,9 @@ DIDerivedType(Element.getGV())); Buffer.AddChild(ElemDie); } + unsigned RLang = CTy.getRunTimeLang(); + if (RLang) + AddUInt(&Buffer, DW_AT_APPLE_runtime_class, DW_FORM_data1, RLang); } break; default: @@ -2800,6 +2803,9 @@ const std::string &Flags = DIUnit.getFlags(); if (!Flags.empty()) AddString(Die, DW_AT_APPLE_flags, DW_FORM_string, Flags); + unsigned RVer = DIUnit.getRunTimeVersion(); + if (RVer) + AddUInt(Die, DW_AT_APPLE_major_runtime_vers, DW_FORM_data1, RVer); CompileUnit *Unit = new CompileUnit(ID, Die); if (DIUnit.isMain()) { Modified: llvm/trunk/lib/Support/Dwarf.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Dwarf.cpp?rev=64834&r1=64833&r2=64834&view=diff ============================================================================== --- llvm/trunk/lib/Support/Dwarf.cpp (original) +++ llvm/trunk/lib/Support/Dwarf.cpp Tue Feb 17 16:43:44 2009 @@ -200,6 +200,8 @@ case DW_AT_hi_user: return "DW_AT_hi_user"; case DW_AT_APPLE_optimized: return "DW_AT_APPLE_optimized"; case DW_AT_APPLE_flags: return "DW_AT_APPLE_flags"; + case DW_AT_APPLE_major_runtime_vers: return "DW_AT_APPLE_major_runtime_vers"; + case DW_AT_APPLE_runtime_class: return "DW_AT_APPLE_runtime_class"; } assert(0 && "Unknown Dwarf Attribute"); return ""; Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=64834&r1=64833&r2=64834&view=diff ============================================================================== --- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original) +++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Tue Feb 17 16:43:44 2009 @@ -356,6 +356,10 @@ // Add an appropriate TargetData instance for this module... passes.add(new TargetData(*_target->getTargetData())); + std::string targetTriple = _linker.getModule()->getTargetTriple(); +// if ( targetTriple.find("darwin") != targetTriple.size() ) + passes.add(createStripSymbolsPass(true /* strip debug info only */)); + // Propagate constants at call sites into the functions they call. This // opens opportunities for globalopt (and inlining) by substituting function // pointers passed as arguments to direct uses of functions. @@ -412,6 +416,8 @@ // Make sure everything is still good. passes.add(createVerifierPass()); + setCodeGenDebugOptions("-debug-pass=Structure"); + FunctionPassManager* codeGenPasses = new FunctionPassManager(new ExistingModuleProvider(mergedModule)); From dpatel at apple.com Tue Feb 17 16:45:18 2009 From: dpatel at apple.com (Devang Patel) Date: Tue, 17 Feb 2009 22:45:18 -0000 Subject: [llvm-commits] [llvm] r64835 - /llvm/trunk/tools/lto/LTOCodeGenerator.cpp Message-ID: <200902172245.n1HMjInf023733@zion.cs.uiuc.edu> Author: dpatel Date: Tue Feb 17 16:45:18 2009 New Revision: 64835 URL: http://llvm.org/viewvc/llvm-project?rev=64835&view=rev Log: Remove changes that were accidently included in previous commit. Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=64835&r1=64834&r2=64835&view=diff ============================================================================== --- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original) +++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Tue Feb 17 16:45:18 2009 @@ -356,10 +356,6 @@ // Add an appropriate TargetData instance for this module... passes.add(new TargetData(*_target->getTargetData())); - std::string targetTriple = _linker.getModule()->getTargetTriple(); -// if ( targetTriple.find("darwin") != targetTriple.size() ) - passes.add(createStripSymbolsPass(true /* strip debug info only */)); - // Propagate constants at call sites into the functions they call. This // opens opportunities for globalopt (and inlining) by substituting function // pointers passed as arguments to direct uses of functions. @@ -416,8 +412,6 @@ // Make sure everything is still good. passes.add(createVerifierPass()); - setCodeGenDebugOptions("-debug-pass=Structure"); - FunctionPassManager* codeGenPasses = new FunctionPassManager(new ExistingModuleProvider(mergedModule)); From dpatel at apple.com Tue Feb 17 16:47:23 2009 From: dpatel at apple.com (Devang Patel) Date: Tue, 17 Feb 2009 22:47:23 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64836 - in /llvm-gcc-4.2/trunk/gcc: llvm-backend.cpp llvm-debug.cpp Message-ID: <200902172247.n1HMlN64023820@zion.cs.uiuc.edu> Author: dpatel Date: Tue Feb 17 16:47:23 2009 New Revision: 64836 URL: http://llvm.org/viewvc/llvm-project?rev=64836&view=rev Log: The debugger sometimes lookup dynamically in the runtime to find ivar info of any Objective-C classes. It would be very helpful to debugger if the compiler encodes runtime version number in DWARF. Update llvm-gcc FE to encode objective runtime version number in compile unit and class DIEs. - This line, and those below, will be ignored-- M gcc/llvm-backend.cpp M gcc/llvm-debug.cpp Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=64836&r1=64835&r2=64836&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Tue Feb 17 16:47:23 2009 @@ -264,6 +264,18 @@ } void llvm_lang_dependent_init(const char *Name) { + + // Each input file is encoded as a separate compile unit in LLVM + // debugging information output. However, many target specific tool chains + // prefer to encode only one compile unit in an object file. In this + // situation, the LLVM code generator will include debugging information + // entities in the compile unit that is marked as main compile unit. The + // code generator accepts maximum one main compile unit per module. If a + // module does not contain any main compile unit then the code generator + // will emit multiple compile units in the output object file. + if (TheDebugInfo) + TheDebugInfo->getOrCreateCompileUnit(main_input_filename, true); + if (Name) TheModule->setModuleIdentifier(Name); } Modified: llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp?rev=64836&r1=64835&r2=64836&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Tue Feb 17 16:47:23 2009 @@ -202,18 +202,7 @@ , PrevLineNo(0) , PrevBB(NULL) , RegionStack() -{ - - // Each input file is encoded as a separate compile unit in LLVM - // debugging information output. However, many target specific tool chains - // prefer to encode only one compile unit in an object file. In this - // situation, the LLVM code generator will include debugging information - // entities in the compile unit that is marked as main compile unit. The - // code generator accepts maximum one main compile unit per module. If a - // module does not contain any main compile unit then the code generator - // will emit multiple compile units in the output object file. - DICompileUnit M = getOrCreateCompileUnit(main_input_filename, true); -} +{} /// EmitFunctionStart - Constructs the debug code for entering a function - /// "llvm.dbg.func.start." @@ -546,6 +535,27 @@ unsigned Tag = TREE_CODE(type) == RECORD_TYPE ? DW_TAG_structure_type : DW_TAG_union_type; + unsigned RunTimeLang = 0; + if (TYPE_LANG_SPECIFIC (type) + && lang_hooks.types.is_runtime_specific_type (type)) + { + DICompileUnit CU = getOrCreateCompileUnit(main_input_filename); + unsigned CULang = CU.getLanguage(); + switch (CULang) { + case DW_LANG_ObjC_plus_plus : + RunTimeLang = DW_LANG_ObjC_plus_plus; + break; + case DW_LANG_ObjC : + RunTimeLang = DW_LANG_ObjC; + break; + case DW_LANG_C_plus_plus : + RunTimeLang = DW_LANG_C_plus_plus; + break; + default: + break; + } + } + // Records and classes and unions can all be recursive. To handle them, // we first generate a debug descriptor for the struct as a forward // declaration. Then (if it is a definition) we go through and get debug @@ -561,7 +571,8 @@ getOrCreateCompileUnit(Loc.file), Loc.line, 0, 0, 0, llvm::DIType::FlagFwdDecl, - llvm::DIType(), llvm::DIArray()); + llvm::DIType(), llvm::DIArray(), + RunTimeLang); // forward declaration, if (TYPE_SIZE(type) == 0) @@ -667,7 +678,8 @@ getOrCreateCompileUnit(Loc.file), Loc.line, NodeSizeInBits(type), NodeAlignInBits(type), - 0, 0, llvm::DIType(), Elements); + 0, 0, llvm::DIType(), Elements, + RunTimeLang); // Now that we have a real decl for the struct, replace anything using the // old decl with the new one. This will recursively update the debug info. @@ -856,10 +868,13 @@ if (debugopt && debugopt[0]) Flags = get_arguments(); - DICompileUnit NewCU = DebugFactory.CreateCompileUnit(LangTag, FileName, - Directory, - version_string, isMain, - optimize, Flags); + // flag_objc_abi represents Objective-C runtime version number. It is zero + // for all other language. + DICompileUnit NewCU = DebugFactory.CreateCompileUnit(LangTag, FileName, + Directory, + version_string, isMain, + optimize, Flags, + flag_objc_abi); CU = NewCU.getGV(); return NewCU; } From dpatel at apple.com Tue Feb 17 16:48:18 2009 From: dpatel at apple.com (Devang Patel) Date: Tue, 17 Feb 2009 22:48:18 -0000 Subject: [llvm-commits] [llvm] r64838 - /llvm/trunk/test/FrontendObjC/2009-02-17-RunTimeVer-dbg.m Message-ID: <200902172248.n1HMmIKT023877@zion.cs.uiuc.edu> Author: dpatel Date: Tue Feb 17 16:48:18 2009 New Revision: 64838 URL: http://llvm.org/viewvc/llvm-project?rev=64838&view=rev Log: And now, not so elegant, test case... Added: llvm/trunk/test/FrontendObjC/2009-02-17-RunTimeVer-dbg.m Added: llvm/trunk/test/FrontendObjC/2009-02-17-RunTimeVer-dbg.m URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FrontendObjC/2009-02-17-RunTimeVer-dbg.m?rev=64838&view=auto ============================================================================== --- llvm/trunk/test/FrontendObjC/2009-02-17-RunTimeVer-dbg.m (added) +++ llvm/trunk/test/FrontendObjC/2009-02-17-RunTimeVer-dbg.m Tue Feb 17 16:48:18 2009 @@ -0,0 +1,13 @@ +// RUN: %llvmgcc -x objective-c -S %s -g --emit-llvm -o - | grep "dbg.compile_unit =" | grep "null, i32" +// Last parameter represent i32 runtime version id. The previous paramenter +// encodes command line flags when certain env. variables are set. In this +// example it is the only compile_unit parameter that is null. This test case +// tests existence of new additional compile_unit parameter to encode +// Objective-C runtime version number. + + at interface foo + at end + at implementation foo + at end + +void fn(foo *f) {} From isanbard at gmail.com Tue Feb 17 16:52:33 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 22:52:33 -0000 Subject: [llvm-commits] [llvm] r64839 - in /llvm/branches/Apple/Dib: include/llvm/Analysis/DebugInfo.h include/llvm/Support/Dwarf.h lib/Analysis/DebugInfo.cpp lib/CodeGen/AsmPrinter/DwarfWriter.cpp lib/Support/Dwarf.cpp tools/lto/LTOCodeGenerator.cpp Message-ID: <200902172252.n1HMqXH2024054@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 16:52:33 2009 New Revision: 64839 URL: http://llvm.org/viewvc/llvm-project?rev=64839&view=rev Log: --- Merging (from foreign repository) r64834 into '.': U include/llvm/Analysis/DebugInfo.h U include/llvm/Support/Dwarf.h U tools/lto/LTOCodeGenerator.cpp U lib/Analysis/DebugInfo.cpp U lib/CodeGen/AsmPrinter/DwarfWriter.cpp U lib/Support/Dwarf.cpp The debugger sometimes lookup dynamically in the runtime to find ivar info of any Objective-C classes. It would be very helpful to debugger if the compiler encodes runtime version number in DWARF. Add support for two additional DWARF attributes to encode Objective-C runtime version number. Modified: llvm/branches/Apple/Dib/include/llvm/Analysis/DebugInfo.h llvm/branches/Apple/Dib/include/llvm/Support/Dwarf.h llvm/branches/Apple/Dib/lib/Analysis/DebugInfo.cpp llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp llvm/branches/Apple/Dib/lib/Support/Dwarf.cpp llvm/branches/Apple/Dib/tools/lto/LTOCodeGenerator.cpp Modified: llvm/branches/Apple/Dib/include/llvm/Analysis/DebugInfo.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/Analysis/DebugInfo.h?rev=64839&r1=64838&r2=64839&view=diff ============================================================================== --- llvm/branches/Apple/Dib/include/llvm/Analysis/DebugInfo.h (original) +++ llvm/branches/Apple/Dib/include/llvm/Analysis/DebugInfo.h Tue Feb 17 16:52:33 2009 @@ -118,9 +118,11 @@ /// code generator accepts maximum one main compile unit per module. If a /// module does not contain any main compile unit then the code generator /// will emit multiple compile units in the output object file. + bool isMain() const { return getUnsignedField(6); } bool isOptimized() const { return getUnsignedField(7); } std::string getFlags() const { return getStringField(8); } + unsigned getRunTimeVersion() const { return getUnsignedField(9); } /// Verify - Verify that a compile unit is well formed. bool Verify() const; @@ -231,6 +233,7 @@ public: explicit DICompositeType(GlobalVariable *GV); DIArray getTypeArray() const { return getFieldAs(10); } + unsigned getRunTimeLang() const { return getUnsignedField(11); } /// Verify - Verify that a composite type descriptor is well formed. bool Verify() const; @@ -381,7 +384,8 @@ const std::string &Producer, bool isMain = false, bool isOptimized = false, - const char *Flags = ""); + const char *Flags = "", + unsigned RunTimeVer = 0); /// CreateEnumerator - Create a single enumerator value. DIEnumerator CreateEnumerator(const std::string &Name, uint64_t Val); @@ -412,7 +416,8 @@ uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, DIType DerivedFrom, - DIArray Elements); + DIArray Elements, + unsigned RunTimeLang = 0); /// CreateSubprogram - Create a new descriptor for the specified subprogram. /// See comments in DISubprogram for descriptions of these fields. Modified: llvm/branches/Apple/Dib/include/llvm/Support/Dwarf.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/Support/Dwarf.h?rev=64839&r1=64838&r2=64839&view=diff ============================================================================== --- llvm/branches/Apple/Dib/include/llvm/Support/Dwarf.h (original) +++ llvm/branches/Apple/Dib/include/llvm/Support/Dwarf.h Tue Feb 17 16:52:33 2009 @@ -225,6 +225,8 @@ // Apple extensions. DW_AT_APPLE_optimized = 0x3fe1, DW_AT_APPLE_flags = 0x3fe2, + DW_AT_APPLE_major_runtime_vers = 0x3fe5, + DW_AT_APPLE_runtime_class = 0x3fe6, // Attribute form encodings DW_FORM_addr = 0x01, Modified: llvm/branches/Apple/Dib/lib/Analysis/DebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Analysis/DebugInfo.cpp?rev=64839&r1=64838&r2=64839&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Analysis/DebugInfo.cpp (original) +++ llvm/branches/Apple/Dib/lib/Analysis/DebugInfo.cpp Tue Feb 17 16:52:33 2009 @@ -453,7 +453,8 @@ const std::string &Producer, bool isMain, bool isOptimized, - const char *Flags) { + const char *Flags, + unsigned RunTimeVer) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_compile_unit), getCastToEmpty(GetOrCreateCompileUnitAnchor()), @@ -463,7 +464,8 @@ GetStringConstant(Producer), ConstantInt::get(Type::Int1Ty, isMain), ConstantInt::get(Type::Int1Ty, isOptimized), - GetStringConstant(Flags) + GetStringConstant(Flags), + ConstantInt::get(Type::Int32Ty, RunTimeVer) }; Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); @@ -573,7 +575,8 @@ uint64_t OffsetInBits, unsigned Flags, DIType DerivedFrom, - DIArray Elements) { + DIArray Elements, + unsigned RuntimeLang) { Constant *Elts[] = { GetTagConstant(Tag), @@ -586,7 +589,8 @@ ConstantInt::get(Type::Int64Ty, OffsetInBits), ConstantInt::get(Type::Int32Ty, Flags), getCastToEmpty(DerivedFrom), - getCastToEmpty(Elements) + getCastToEmpty(Elements), + ConstantInt::get(Type::Int32Ty, RuntimeLang) }; Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); Modified: llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp?rev=64839&r1=64838&r2=64839&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp (original) +++ llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Tue Feb 17 16:52:33 2009 @@ -1767,6 +1767,9 @@ DIDerivedType(Element.getGV())); Buffer.AddChild(ElemDie); } + unsigned RLang = CTy.getRunTimeLang(); + if (RLang) + AddUInt(&Buffer, DW_AT_APPLE_runtime_class, DW_FORM_data1, RLang); } break; default: @@ -2797,6 +2800,9 @@ const std::string &Flags = DIUnit.getFlags(); if (!Flags.empty()) AddString(Die, DW_AT_APPLE_flags, DW_FORM_string, Flags); + unsigned RVer = DIUnit.getRunTimeVersion(); + if (RVer) + AddUInt(Die, DW_AT_APPLE_major_runtime_vers, DW_FORM_data1, RVer); CompileUnit *Unit = new CompileUnit(ID, Die); if (DIUnit.isMain()) { Modified: llvm/branches/Apple/Dib/lib/Support/Dwarf.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Support/Dwarf.cpp?rev=64839&r1=64838&r2=64839&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Support/Dwarf.cpp (original) +++ llvm/branches/Apple/Dib/lib/Support/Dwarf.cpp Tue Feb 17 16:52:33 2009 @@ -200,6 +200,8 @@ case DW_AT_hi_user: return "DW_AT_hi_user"; case DW_AT_APPLE_optimized: return "DW_AT_APPLE_optimized"; case DW_AT_APPLE_flags: return "DW_AT_APPLE_flags"; + case DW_AT_APPLE_major_runtime_vers: return "DW_AT_APPLE_major_runtime_vers"; + case DW_AT_APPLE_runtime_class: return "DW_AT_APPLE_runtime_class"; } assert(0 && "Unknown Dwarf Attribute"); return ""; Modified: llvm/branches/Apple/Dib/tools/lto/LTOCodeGenerator.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/tools/lto/LTOCodeGenerator.cpp?rev=64839&r1=64838&r2=64839&view=diff ============================================================================== --- llvm/branches/Apple/Dib/tools/lto/LTOCodeGenerator.cpp (original) +++ llvm/branches/Apple/Dib/tools/lto/LTOCodeGenerator.cpp Tue Feb 17 16:52:33 2009 @@ -356,6 +356,10 @@ // Add an appropriate TargetData instance for this module... passes.add(new TargetData(*_target->getTargetData())); + std::string targetTriple = _linker.getModule()->getTargetTriple(); +// if ( targetTriple.find("darwin") != targetTriple.size() ) + passes.add(createStripSymbolsPass(true /* strip debug info only */)); + // Propagate constants at call sites into the functions they call. This // opens opportunities for globalopt (and inlining) by substituting function // pointers passed as arguments to direct uses of functions. @@ -412,6 +416,8 @@ // Make sure everything is still good. passes.add(createVerifierPass()); + setCodeGenDebugOptions("-debug-pass=Structure"); + FunctionPassManager* codeGenPasses = new FunctionPassManager(new ExistingModuleProvider(mergedModule)); From scottm at aero.org Tue Feb 17 16:52:35 2009 From: scottm at aero.org (Scott Michel) Date: Tue, 17 Feb 2009 14:52:35 -0800 Subject: [llvm-commits] [llvm] r64827 - in /llvm/trunk: include/llvm/CodeGen/SelectionDAG.h include/llvm/CodeGen/SelectionDAGNodes.h lib/CodeGen/SelectionDAG/DAGCombiner.cpp lib/CodeGen/SelectionDAG/LegalizeDAG.cpp lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp lib/Target/PowerPC/PPCISelLowering.cpp lib/Target/X86/X86ISelLowering.cpp In-Reply-To: <60C9CCC9-2E35-43C1-8782-514D4C522D8C@apple.com> References: <200902172215.n1HMF5P2022402@zion.cs.uiuc.edu> <200902172320.33140.baldrick@free.fr> <60C9CCC9-2E35-43C1-8782-514D4C522D8C@apple.com> Message-ID: On Feb 17, 2009, at 2:36 PM, Dale Johannesen wrote: > > On Feb 17, 2009, at 2:20 PMPST, Duncan Sands wrote: > >> Hi Scott, >> >>> (Note: Eventually, commits like this will be handled via a pre- >>> commit hook that >>> does this automagically, as well as expand tabs to spaces and >>> look for 80-col >>> violations.) >> >> the last time I read the subversion book, it recommended not doing >> this. >> They instead advised having a script that rejects a commit if it >> introduces >> trailing whitespace. > > Whoa! There is absolutely no reason (except pedantry) to disallow > this, and everybody's time would be better spent working on things > that actually matter. > If you've got an editor that makes changes to your code you didn't > tell it to, that's a serious bug; I'd either fix it or get a > different editor. > I realize not everybody sees things that way, but I see no reason > your misguided opinion should interfere with my work.:) A script > along the lines Scott suggests is OK (assuming it doesn't slow > things down noticeably), but I strongly object to having patches > rejected for mere pedantry. Wait a second -- there's a bit of an overreaction to the "Note:", IMNSHO. It's got nothing to do with "an editor that changes your code you didn't tell it to"; it's not as if vim or Eclipse functionally changed the code. The editor is merely doing some grooming that's functionally a NOP. Many editors do this, including Emacs with the right flags set. Heck, even NetBeans does this by default as does Eclipse. I'm happy to find out the consensus for why a commit should be rejected by a pre-commit script. I'm not completely wedded to the idea of stripping off trailing whitespace, but it would seem to be a useful grooming feature. -scooter From isanbard at gmail.com Tue Feb 17 16:57:43 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 22:57:43 -0000 Subject: [llvm-commits] [llvm] r64840 - /llvm/branches/Apple/Dib/tools/lto/LTOCodeGenerator.cpp Message-ID: <200902172257.n1HMvhUE024238@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 16:57:43 2009 New Revision: 64840 URL: http://llvm.org/viewvc/llvm-project?rev=64840&view=rev Log: --- Merging (from foreign repository) r64835 into '.': U tools/lto/LTOCodeGenerator.cpp Remove changes that were accidently included in previous commit. Modified: llvm/branches/Apple/Dib/tools/lto/LTOCodeGenerator.cpp Modified: llvm/branches/Apple/Dib/tools/lto/LTOCodeGenerator.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/tools/lto/LTOCodeGenerator.cpp?rev=64840&r1=64839&r2=64840&view=diff ============================================================================== --- llvm/branches/Apple/Dib/tools/lto/LTOCodeGenerator.cpp (original) +++ llvm/branches/Apple/Dib/tools/lto/LTOCodeGenerator.cpp Tue Feb 17 16:57:43 2009 @@ -356,10 +356,6 @@ // Add an appropriate TargetData instance for this module... passes.add(new TargetData(*_target->getTargetData())); - std::string targetTriple = _linker.getModule()->getTargetTriple(); -// if ( targetTriple.find("darwin") != targetTriple.size() ) - passes.add(createStripSymbolsPass(true /* strip debug info only */)); - // Propagate constants at call sites into the functions they call. This // opens opportunities for globalopt (and inlining) by substituting function // pointers passed as arguments to direct uses of functions. @@ -416,8 +412,6 @@ // Make sure everything is still good. passes.add(createVerifierPass()); - setCodeGenDebugOptions("-debug-pass=Structure"); - FunctionPassManager* codeGenPasses = new FunctionPassManager(new ExistingModuleProvider(mergedModule)); From tonic at nondot.org Tue Feb 17 16:58:40 2009 From: tonic at nondot.org (Tanya Lattner) Date: Tue, 17 Feb 2009 22:58:40 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64841 - /llvm-gcc-4.2/branches/release_25/gcc/tree-optimize.c Message-ID: <200902172258.n1HMwe2J024286@zion.cs.uiuc.edu> Author: tbrethou Date: Tue Feb 17 16:58:40 2009 New Revision: 64841 URL: http://llvm.org/viewvc/llvm-project?rev=64841&view=rev Log: Merge from mainline (64819). Do not run optimize_inline_calls since llvm-gcc doesn't use gcc inliner any more. -gThis line, and those below, will be ignored-- M gcc/tree-optimize.c Modified: llvm-gcc-4.2/branches/release_25/gcc/tree-optimize.c Modified: llvm-gcc-4.2/branches/release_25/gcc/tree-optimize.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/release_25/gcc/tree-optimize.c?rev=64841&r1=64840&r2=64841&view=diff ============================================================================== --- llvm-gcc-4.2/branches/release_25/gcc/tree-optimize.c (original) +++ llvm-gcc-4.2/branches/release_25/gcc/tree-optimize.c Tue Feb 17 16:58:40 2009 @@ -439,6 +439,8 @@ cfun->x_dont_save_pending_sizes_p = 1; cfun->after_inlining = true; +/* LLVM LOCAL begin */ +#ifndef ENABLE_LLVM if (flag_inline_trees) { struct cgraph_edge *e; @@ -452,6 +454,8 @@ timevar_pop (TV_INTEGRATION); } } +#endif +/* LLVM LOCAL end */ /* In non-unit-at-a-time we must mark all referenced functions as needed. */ if (!flag_unit_at_a_time) From isanbard at gmail.com Tue Feb 17 17:03:28 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 23:03:28 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64842 - in /llvm-gcc-4.2/branches/Apple/Dib/gcc: llvm-backend.cpp llvm-debug.cpp Message-ID: <200902172303.n1HN3Sn1024445@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 17:03:28 2009 New Revision: 64842 URL: http://llvm.org/viewvc/llvm-project?rev=64842&view=rev Log: --- Merging (from foreign repository) r63640 into '.': U gcc/llvm-debug.cpp Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-backend.cpp llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-backend.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-backend.cpp?rev=64842&r1=64841&r2=64842&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-backend.cpp (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-backend.cpp Tue Feb 17 17:03:28 2009 @@ -265,6 +265,18 @@ } void llvm_lang_dependent_init(const char *Name) { + + // Each input file is encoded as a separate compile unit in LLVM + // debugging information output. However, many target specific tool chains + // prefer to encode only one compile unit in an object file. In this + // situation, the LLVM code generator will include debugging information + // entities in the compile unit that is marked as main compile unit. The + // code generator accepts maximum one main compile unit per module. If a + // module does not contain any main compile unit then the code generator + // will emit multiple compile units in the output object file. + if (TheDebugInfo) + TheDebugInfo->getOrCreateCompileUnit(main_input_filename, true); + if (Name) TheModule->setModuleIdentifier(Name); } Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp?rev=64842&r1=64841&r2=64842&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Tue Feb 17 17:03:28 2009 @@ -847,9 +847,17 @@ else LangTag = DW_LANG_C89; + const char *Flags = ""; + // Do this only when RC_DEBUG_OPTIONS environment variable is set to + // a nonempty string. This is intended only for internal Apple use. + char * debugopt = getenv("RC_DEBUG_OPTIONS"); + if (debugopt && debugopt[0]) + Flags = get_arguments(); + DICompileUnit NewCU = DebugFactory.CreateCompileUnit(LangTag, FileName, Directory, - version_string, isMain); + version_string, isMain, + optimize, Flags); CU = NewCU.getGV(); return NewCU; } From isanbard at gmail.com Tue Feb 17 17:05:22 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 23:05:22 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64843 - /llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Message-ID: <200902172305.n1HN5MnZ024533@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 17:05:21 2009 New Revision: 64843 URL: http://llvm.org/viewvc/llvm-project?rev=64843&view=rev Log: --- Merging (from foreign repository) r64836 into '.': The debugger sometimes lookup dynamically in the runtime to find ivar info of any Objective-C classes. It would be very helpful to debugger if the compiler encodes runtime version number in DWARF. Update llvm-gcc FE to encode objective runtime version number in compile unit and class DIEs. Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp?rev=64843&r1=64842&r2=64843&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Tue Feb 17 17:05:21 2009 @@ -202,18 +202,7 @@ , PrevLineNo(0) , PrevBB(NULL) , RegionStack() -{ - - // Each input file is encoded as a separate compile unit in LLVM - // debugging information output. However, many target specific tool chains - // prefer to encode only one compile unit in an object file. In this - // situation, the LLVM code generator will include debugging information - // entities in the compile unit that is marked as main compile unit. The - // code generator accepts maximum one main compile unit per module. If a - // module does not contain any main compile unit then the code generator - // will emit multiple compile units in the output object file. - DICompileUnit M = getOrCreateCompileUnit(main_input_filename, true); -} +{} /// EmitFunctionStart - Constructs the debug code for entering a function - /// "llvm.dbg.func.start." @@ -544,6 +533,27 @@ unsigned Tag = TREE_CODE(type) == RECORD_TYPE ? DW_TAG_structure_type : DW_TAG_union_type; + unsigned RunTimeLang = 0; + if (TYPE_LANG_SPECIFIC (type) + && lang_hooks.types.is_runtime_specific_type (type)) + { + DICompileUnit CU = getOrCreateCompileUnit(main_input_filename); + unsigned CULang = CU.getLanguage(); + switch (CULang) { + case DW_LANG_ObjC_plus_plus : + RunTimeLang = DW_LANG_ObjC_plus_plus; + break; + case DW_LANG_ObjC : + RunTimeLang = DW_LANG_ObjC; + break; + case DW_LANG_C_plus_plus : + RunTimeLang = DW_LANG_C_plus_plus; + break; + default: + break; + } + } + // Records and classes and unions can all be recursive. To handle them, // we first generate a debug descriptor for the struct as a forward // declaration. Then (if it is a definition) we go through and get debug @@ -559,7 +569,8 @@ getOrCreateCompileUnit(Loc.file), Loc.line, 0, 0, 0, llvm::DIType::FlagFwdDecl, - llvm::DIType(), llvm::DIArray()); + llvm::DIType(), llvm::DIArray(), + RunTimeLang); // forward declaration, if (TYPE_SIZE(type) == 0) @@ -665,7 +676,8 @@ getOrCreateCompileUnit(Loc.file), Loc.line, NodeSizeInBits(type), NodeAlignInBits(type), - 0, 0, llvm::DIType(), Elements); + 0, 0, llvm::DIType(), Elements, + RunTimeLang); // Now that we have a real decl for the struct, replace anything using the // old decl with the new one. This will recursively update the debug info. @@ -854,10 +866,13 @@ if (debugopt && debugopt[0]) Flags = get_arguments(); - DICompileUnit NewCU = DebugFactory.CreateCompileUnit(LangTag, FileName, - Directory, - version_string, isMain, - optimize, Flags); + // flag_objc_abi represents Objective-C runtime version number. It is zero + // for all other language. + DICompileUnit NewCU = DebugFactory.CreateCompileUnit(LangTag, FileName, + Directory, + version_string, isMain, + optimize, Flags, + flag_objc_abi); CU = NewCU.getGV(); return NewCU; } From baldrick at free.fr Tue Feb 17 17:05:27 2009 From: baldrick at free.fr (Duncan Sands) Date: Tue, 17 Feb 2009 23:05:27 -0000 Subject: [llvm-commits] [llvm] r64844 - in /llvm/trunk: lib/Transforms/IPO/GlobalDCE.cpp test/Transforms/GlobalDCE/2009-02-17-AliasUsesAliasee.ll Message-ID: <200902172305.n1HN5Ret024546@zion.cs.uiuc.edu> Author: baldrick Date: Tue Feb 17 17:05:26 2009 New Revision: 64844 URL: http://llvm.org/viewvc/llvm-project?rev=64844&view=rev Log: If an alias is dead and so is its aliasee, then globaldce would crash because the alias would still be using the aliasee when the aliasee was deleted. Added: llvm/trunk/test/Transforms/GlobalDCE/2009-02-17-AliasUsesAliasee.ll Modified: llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp Modified: llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp?rev=64844&r1=64843&r2=64844&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp (original) +++ llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp Tue Feb 17 17:05:26 2009 @@ -82,7 +82,7 @@ I != E; ++I) { Changed |= RemoveUnusedGlobalValue(*I); // Externally visible aliases are needed. - if (!I->hasInternalLinkage() && !I->hasLinkOnceLinkage()) + if (!I->hasLocalLinkage() && !I->hasLinkOnceLinkage()) GlobalIsNeeded(I); } @@ -107,6 +107,15 @@ I->deleteBody(); } + // The third pass drops targets of aliases which are dead... + std::vector DeadAliases; + for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E; + ++I) + if (!AliveGlobals.count(I)) { + DeadAliases.push_back(I); + I->setAliasee(0); + } + if (!DeadFunctions.empty()) { // Now that all interferences have been dropped, delete the actual objects // themselves. @@ -128,14 +137,13 @@ } // Now delete any dead aliases. - for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E;) { - Module::alias_iterator J = I++; - if (!AliveGlobals.count(J)) { - RemoveUnusedGlobalValue(*J); - M.getAliasList().erase(J); - ++NumAliases; - Changed = true; + if (!DeadAliases.empty()) { + for (unsigned i = 0, e = DeadAliases.size(); i != e; ++i) { + RemoveUnusedGlobalValue(*DeadAliases[i]); + M.getAliasList().erase(DeadAliases[i]); } + NumAliases += DeadAliases.size(); + Changed = true; } // Make sure that all memory is released Added: llvm/trunk/test/Transforms/GlobalDCE/2009-02-17-AliasUsesAliasee.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalDCE/2009-02-17-AliasUsesAliasee.ll?rev=64844&view=auto ============================================================================== --- llvm/trunk/test/Transforms/GlobalDCE/2009-02-17-AliasUsesAliasee.ll (added) +++ llvm/trunk/test/Transforms/GlobalDCE/2009-02-17-AliasUsesAliasee.ll Tue Feb 17 17:05:26 2009 @@ -0,0 +1,4 @@ +; RUN: llvm-as < %s | opt -globaldce + + at A = alias internal void ()* @F +define internal void @F() { ret void } From isanbard at gmail.com Tue Feb 17 17:06:40 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 17 Feb 2009 23:06:40 -0000 Subject: [llvm-commits] [llvm] r64845 - /llvm/branches/Apple/Dib/test/FrontendObjC/2009-02-17-RunTimeVer-dbg.m Message-ID: <200902172306.n1HN6eMa024604@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 17:06:40 2009 New Revision: 64845 URL: http://llvm.org/viewvc/llvm-project?rev=64845&view=rev Log: --- Merging (from foreign repository) r64838 into '.': A test/FrontendObjC/2009-02-17-RunTimeVer-dbg.m And now, not so elegant, test case... Added: llvm/branches/Apple/Dib/test/FrontendObjC/2009-02-17-RunTimeVer-dbg.m Added: llvm/branches/Apple/Dib/test/FrontendObjC/2009-02-17-RunTimeVer-dbg.m URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/FrontendObjC/2009-02-17-RunTimeVer-dbg.m?rev=64845&view=auto ============================================================================== --- llvm/branches/Apple/Dib/test/FrontendObjC/2009-02-17-RunTimeVer-dbg.m (added) +++ llvm/branches/Apple/Dib/test/FrontendObjC/2009-02-17-RunTimeVer-dbg.m Tue Feb 17 17:06:40 2009 @@ -0,0 +1,13 @@ +// RUN: %llvmgcc -x objective-c -S %s -g --emit-llvm -o - | grep "dbg.compile_unit =" | grep "null, i32" +// Last parameter represent i32 runtime version id. The previous paramenter +// encodes command line flags when certain env. variables are set. In this +// example it is the only compile_unit parameter that is null. This test case +// tests existence of new additional compile_unit parameter to encode +// Objective-C runtime version number. + + at interface foo + at end + at implementation foo + at end + +void fn(foo *f) {} From dalej at apple.com Tue Feb 17 17:13:08 2009 From: dalej at apple.com (Dale Johannesen) Date: Tue, 17 Feb 2009 15:13:08 -0800 Subject: [llvm-commits] [llvm] r64827 - in /llvm/trunk: include/llvm/CodeGen/SelectionDAG.h include/llvm/CodeGen/SelectionDAGNodes.h lib/CodeGen/SelectionDAG/DAGCombiner.cpp lib/CodeGen/SelectionDAG/LegalizeDAG.cpp lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp lib/Target/PowerPC/PPCISelLowering.cpp lib/Target/X86/X86ISelLowering.cpp In-Reply-To: References: <200902172215.n1HMF5P2022402@zion.cs.uiuc.edu> <200902172320.33140.baldrick@free.fr> <60C9CCC9-2E35-43C1-8782-514D4C522D8C@apple.com> Message-ID: <3C6D3F6B-B95B-46EE-B7E4-FB84A8C4D1E8@apple.com> On Feb 17, 2009, at 2:52 PMPST, Scott Michel wrote: >>> >>>> (Note: Eventually, commits like this will be handled via a pre- >>>> commit hook that >>>> does this automagically, as well as expand tabs to spaces and >>>> look for 80-col >>>> violations.) >>> >>> the last time I read the subversion book, it recommended not doing >>> this. >>> They instead advised having a script that rejects a commit if it >>> introduces >>> trailing whitespace. >> >> Whoa! There is absolutely no reason (except pedantry) to disallow >> this, and everybody's time would be better spent working on things >> that actually matter. >> If you've got an editor that makes changes to your code you didn't >> tell it to, that's a serious bug; I'd either fix it or get a >> different editor. >> I realize not everybody sees things that way, but I see no reason >> your misguided opinion should interfere with my work.:) A script >> along the lines Scott suggests is OK (assuming it doesn't slow >> things down noticeably), but I strongly object to having patches >> rejected for mere pedantry. > > Wait a second -- there's a bit of an overreaction to the "Note:", > IMNSHO. I'm reacting to the suggestion that patches that don't conform to your preference should be rejected automatically, not to your note. I understand it was not your suggestion. One observation I have after years of suffering through working on gcc is that people on that project waste an incredible amount of time worrying about this and other coding style issues that simply Do Not Matter. I think it's a major reason gcc is so far behind current technology and I don't want to see llvm go down that road. > It's got nothing to do with "an editor that changes your code you > didn't tell it to"; it's not as if vim or Eclipse functionally > changed the code. The editor is merely doing some grooming that's > functionally a NOP. Many editors do this, including Emacs with the > right flags set. Heck, even NetBeans does this by default as does > Eclipse. Another reason I'm sticking with Emacs. This sort of thing isn't always safe; for example, the dialect supported by early versions of gcc allowed newlines in the middle of strings, so trailing spaces were semantically significant. For another, the difference between tabs and spaces is semantically significant in some versions of make. And as a matter of theory, letting a tool's behavior drive your workflow is not the way things are supposed to be. Tools are to do what you want, not to make you adapt to what they do. From kremenek at apple.com Tue Feb 17 17:33:53 2009 From: kremenek at apple.com (Ted Kremenek) Date: Tue, 17 Feb 2009 23:33:53 -0000 Subject: [llvm-commits] [llvm] r64855 - /llvm/tags/checker/checker-0.158/ Message-ID: <200902172333.n1HNXraR025785@zion.cs.uiuc.edu> Author: kremenek Date: Tue Feb 17 17:33:53 2009 New Revision: 64855 URL: http://llvm.org/viewvc/llvm-project?rev=64855&view=rev Log: Tagging checker-0.158. Added: llvm/tags/checker/checker-0.158/ - copied from r64854, llvm/trunk/ From dpatel at apple.com Tue Feb 17 17:56:00 2009 From: dpatel at apple.com (Devang Patel) Date: Tue, 17 Feb 2009 23:56:00 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64857 - /llvm-gcc-4.2/trunk/build_gcc Message-ID: <200902172356.n1HNu068004894@zion.cs.uiuc.edu> Author: dpatel Date: Tue Feb 17 17:55:59 2009 New Revision: 64857 URL: http://llvm.org/viewvc/llvm-project?rev=64857&view=rev Log: Copy man pages in destination install folder. Modified: llvm-gcc-4.2/trunk/build_gcc Modified: llvm-gcc-4.2/trunk/build_gcc URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/build_gcc?rev=64857&r1=64856&r2=64857&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/build_gcc (original) +++ llvm-gcc-4.2/trunk/build_gcc Tue Feb 17 17:55:59 2009 @@ -512,9 +512,11 @@ # LLVM LOCAL begin # Compress manpages gzip -f $MDIR/* -mkdir -p /Developer/usr/share/man/man1 -cp $ORIG_SRC_DIR/gcc/doc/llvm-gcc.1 /Developer/usr/share/man/man1/llvm-gcc.1 -gzip -f /Developer/usr/share/man/man1/llvm-gcc.1 +mkdir -p $DEST_DIR/Developer/usr/share/man/man1 +cp $ORIG_SRC_DIR/gcc/doc/llvm-gcc.1 $DEST_DIR/Developer/usr/share/man/man1/llvm-gcc.1 +cp $ORIG_SRC_DIR/gcc/doc/llvm-gcc.1 $DEST_DIR/Developer/usr/share/man/man1/llvm-g++.1 +gzip -f $DEST_DIR/Developer/usr/share/man/man1/llvm-gcc.1 +gzip -f $DEST_DIR/Developer/usr/share/man/man1/llvm-g++.1 # LLVM LOCAL end # Build driver-driver using fully-named drivers From isanbard at gmail.com Tue Feb 17 18:05:56 2009 From: isanbard at gmail.com (Bill Wendling) Date: Wed, 18 Feb 2009 00:05:56 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64858 - /llvm-gcc-4.2/branches/Apple/Dib/build_gcc Message-ID: <200902180005.n1I05uq9009612@zion.cs.uiuc.edu> Author: void Date: Tue Feb 17 18:05:55 2009 New Revision: 64858 URL: http://llvm.org/viewvc/llvm-project?rev=64858&view=rev Log: --- Merging (from foreign repository) r64857 into '.': U build_gcc Copy man pages in destination install folder. Modified: llvm-gcc-4.2/branches/Apple/Dib/build_gcc Modified: llvm-gcc-4.2/branches/Apple/Dib/build_gcc URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/build_gcc?rev=64858&r1=64857&r2=64858&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/build_gcc (original) +++ llvm-gcc-4.2/branches/Apple/Dib/build_gcc Tue Feb 17 18:05:55 2009 @@ -512,9 +512,11 @@ # LLVM LOCAL begin # Compress manpages gzip -f $MDIR/* -mkdir -p /Developer/usr/share/man/man1 -cp $ORIG_SRC_DIR/gcc/doc/llvm-gcc.1 /Developer/usr/share/man/man1/llvm-gcc.1 -gzip -f /Developer/usr/share/man/man1/llvm-gcc.1 +mkdir -p $DEST_DIR/Developer/usr/share/man/man1 +cp $ORIG_SRC_DIR/gcc/doc/llvm-gcc.1 $DEST_DIR/Developer/usr/share/man/man1/llvm-gcc.1 +cp $ORIG_SRC_DIR/gcc/doc/llvm-gcc.1 $DEST_DIR/Developer/usr/share/man/man1/llvm-g++.1 +gzip -f $DEST_DIR/Developer/usr/share/man/man1/llvm-gcc.1 +gzip -f $DEST_DIR/Developer/usr/share/man/man1/llvm-g++.1 # LLVM LOCAL end # Build driver-driver using fully-named drivers From gohman at apple.com Tue Feb 17 18:08:39 2009 From: gohman at apple.com (Dan Gohman) Date: Wed, 18 Feb 2009 00:08:39 -0000 Subject: [llvm-commits] [llvm] r64859 - /llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200902180008.n1I08dmc009878@zion.cs.uiuc.edu> Author: djg Date: Tue Feb 17 18:08:39 2009 New Revision: 64859 URL: http://llvm.org/viewvc/llvm-project?rev=64859&view=rev Log: Fix a typo in a comment. Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=64859&r1=64858&r2=64859&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Tue Feb 17 18:08:39 2009 @@ -509,7 +509,7 @@ return true; } -/// isAddress - Returns true if the specified instruction is using the +/// isAddressUse - Returns true if the specified instruction is using the /// specified value as an address. static bool isAddressUse(Instruction *Inst, Value *OperandVal) { bool isAddress = isa(Inst); From tonic at nondot.org Tue Feb 17 18:23:25 2009 From: tonic at nondot.org (Tanya Lattner) Date: Wed, 18 Feb 2009 00:23:25 -0000 Subject: [llvm-commits] [llvm] r64861 - /llvm/branches/release_25/include/llvm/CodeGen/LiveInterval.h Message-ID: <200902180023.n1I0NPhB012275@zion.cs.uiuc.edu> Author: tbrethou Date: Tue Feb 17 18:23:25 2009 New Revision: 64861 URL: http://llvm.org/viewvc/llvm-project?rev=64861&view=rev Log: Merge from mainline. Complete 64076 merge from mainline. Modified: llvm/branches/release_25/include/llvm/CodeGen/LiveInterval.h Modified: llvm/branches/release_25/include/llvm/CodeGen/LiveInterval.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_25/include/llvm/CodeGen/LiveInterval.h?rev=64861&r1=64860&r2=64861&view=diff ============================================================================== --- llvm/branches/release_25/include/llvm/CodeGen/LiveInterval.h (original) +++ llvm/branches/release_25/include/llvm/CodeGen/LiveInterval.h Tue Feb 17 18:23:25 2009 @@ -271,6 +271,17 @@ I = std::lower_bound(kills.begin(), kills.end(), KillIdx); return I != kills.end() && *I == KillIdx; } + + /// isOnlyLROfValNo - Return true if the specified live range is the only + /// one defined by the its val#. + bool isOnlyLROfValNo( const LiveRange *LR) { + for (const_iterator I = begin(), E = end(); I != E; ++I) { + const LiveRange *Tmp = I; + if (Tmp != LR && Tmp->valno == LR->valno) + return false; + } + return true; + } /// MergeValueNumberInto - This method is called when two value nubmers /// are found to be equivalent. This eliminates V1, replacing all From gohman at apple.com Tue Feb 17 18:52:01 2009 From: gohman at apple.com (Dan Gohman) Date: Wed, 18 Feb 2009 00:52:01 -0000 Subject: [llvm-commits] [llvm] r64866 - in /llvm/trunk: lib/Transforms/Scalar/IndVarSimplify.cpp test/Transforms/IndVarSimplify/preserve-signed-wrap.ll Message-ID: <200902180052.n1I0q1QG024742@zion.cs.uiuc.edu> Author: djg Date: Tue Feb 17 18:52:00 2009 New Revision: 64866 URL: http://llvm.org/viewvc/llvm-project?rev=64866&view=rev Log: Fix a corner case in the new indvars promotion logic: if there are multiple IV's in a loop, some of them may under go signed or unsigned wrapping even if the IV that's used in the loop exit condition doesn't. Restrict sign-extension-elimination and zero-extension-elimination to only those that operate on the original loop-controlling IV. Added: llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=64866&r1=64865&r2=64866&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Tue Feb 17 18:52:00 2009 @@ -463,21 +463,24 @@ } /// TestOrigIVForWrap - Analyze the original induction variable -/// in the loop to determine whether it would ever undergo signed -/// or unsigned overflow. +/// that controls the loop's iteration to determine whether it +/// would ever undergo signed or unsigned overflow. +/// +/// In addition to setting the NoSignedWrap and NoUnsignedWrap +/// variables, return the PHI for this induction variable. /// /// TODO: This duplicates a fair amount of ScalarEvolution logic. /// Perhaps this can be merged with ScalarEvolution::getIterationCount /// and/or ScalarEvolution::get{Sign,Zero}ExtendExpr. /// -static void TestOrigIVForWrap(const Loop *L, - const BranchInst *BI, - const Instruction *OrigCond, - bool &NoSignedWrap, - bool &NoUnsignedWrap) { +static const PHINode *TestOrigIVForWrap(const Loop *L, + const BranchInst *BI, + const Instruction *OrigCond, + bool &NoSignedWrap, + bool &NoUnsignedWrap) { // Verify that the loop is sane and find the exit condition. const ICmpInst *Cmp = dyn_cast(OrigCond); - if (!Cmp) return; + if (!Cmp) return 0; const Value *CmpLHS = Cmp->getOperand(0); const Value *CmpRHS = Cmp->getOperand(1); @@ -530,7 +533,7 @@ } // For now, analyze only LT loops for signed overflow. if (Pred != ICmpInst::ICMP_SLT && Pred != ICmpInst::ICMP_ULT) - return; + return 0; bool isSigned = Pred == ICmpInst::ICMP_SLT; @@ -543,7 +546,7 @@ if (!isa(CmpRHS) || !cast(CmpRHS)->getValue() .isSignedIntN(IncrVal->getType()->getPrimitiveSizeInBits())) - return; + return 0; IncrVal = SI->getOperand(0); } } else { @@ -551,7 +554,7 @@ if (!isa(CmpRHS) || !cast(CmpRHS)->getValue() .isIntN(IncrVal->getType()->getPrimitiveSizeInBits())) - return; + return 0; IncrVal = ZI->getOperand(0); } } @@ -562,26 +565,26 @@ IncrOp->getOpcode() != Instruction::Add || !isa(IncrOp->getOperand(1)) || !cast(IncrOp->getOperand(1))->equalsInt(1)) - return; + return 0; // Make sure the PHI looks like a normal IV. const PHINode *PN = dyn_cast(IncrOp->getOperand(0)); if (!PN || PN->getNumIncomingValues() != 2) - return; + return 0; unsigned IncomingEdge = L->contains(PN->getIncomingBlock(0)); unsigned BackEdge = !IncomingEdge; if (!L->contains(PN->getIncomingBlock(BackEdge)) || PN->getIncomingValue(BackEdge) != IncrOp) - return; + return 0; if (!L->contains(TrueBB)) - return; + return 0; // For now, only analyze loops with a constant start value, so that // we can easily determine if the start value is not a maximum value // which would wrap on the first iteration. const Value *InitialVal = PN->getIncomingValue(IncomingEdge); if (!isa(InitialVal)) - return; + return 0; // The original induction variable will start at some non-max value, // it counts up by one, and the loop iterates only while it remans @@ -592,6 +595,7 @@ else if (!isSigned && !cast(InitialVal)->getValue().isMaxValue()) NoUnsignedWrap = true; + return PN; } bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { @@ -675,13 +679,15 @@ // using it. We can currently only handle loops with a single exit. bool NoSignedWrap = false; bool NoUnsignedWrap = false; + const PHINode *OrigControllingPHI = 0; if (!isa(IterationCount) && ExitingBlock) // Can't rewrite non-branch yet. if (BranchInst *BI = dyn_cast(ExitingBlock->getTerminator())) { if (Instruction *OrigCond = dyn_cast(BI->getCondition())) { // Determine if the OrigIV will ever undergo overflow. - TestOrigIVForWrap(L, BI, OrigCond, - NoSignedWrap, NoUnsignedWrap); + OrigControllingPHI = + TestOrigIVForWrap(L, BI, OrigCond, + NoSignedWrap, NoUnsignedWrap); // We'll be replacing the original condition, so it'll be dead. DeadInsts.insert(OrigCond); @@ -722,7 +728,7 @@ /// If the new canonical induction variable is wider than the original, /// and the original has uses that are casts to wider types, see if the /// truncate and extend can be omitted. - if (PN->getType() != LargestType) + if (PN == OrigControllingPHI && PN->getType() != LargestType) for (Value::use_iterator UI = PN->use_begin(), UE = PN->use_end(); UI != UE; ++UI) { if (isa(UI) && NoSignedWrap) { Added: llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll?rev=64866&view=auto ============================================================================== --- llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll (added) +++ llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll Tue Feb 17 18:52:00 2009 @@ -0,0 +1,38 @@ +; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t +; RUN: grep sext %t | count 1 +; RUN: grep phi %t | count 1 +; RUN: grep {phi i64} %t + +; Indvars should insert a 64-bit induction variable to eliminate the +; sext for the addressing, however it shouldn't eliminate the sext +; on the other phi, since that value undergoes signed wrapping. + +define void @foo(i32* nocapture %d, i32 %n) nounwind { +entry: + %0 = icmp sgt i32 %n, 0 ; [#uses=1] + br i1 %0, label %bb.nph, label %return + +bb.nph: ; preds = %entry + br label %bb + +bb: ; preds = %bb1, %bb.nph + %i.02 = phi i32 [ %5, %bb1 ], [ 0, %bb.nph ] ; [#uses=2] + %p.01 = phi i8 [ %4, %bb1 ], [ -1, %bb.nph ] ; [#uses=2] + %1 = sext i8 %p.01 to i32 ; [#uses=1] + %2 = sext i32 %i.02 to i64 ; [#uses=1] + %3 = getelementptr i32* %d, i64 %2 ; [#uses=1] + store i32 %1, i32* %3, align 4 + %4 = add i8 %p.01, 1 ; [#uses=1] + %5 = add i32 %i.02, 1 ; [#uses=2] + br label %bb1 + +bb1: ; preds = %bb + %6 = icmp slt i32 %5, %n ; [#uses=1] + br i1 %6, label %bb, label %bb1.return_crit_edge + +bb1.return_crit_edge: ; preds = %bb1 + br label %return + +return: ; preds = %bb1.return_crit_edge, %entry + ret void +} From sabre at nondot.org Tue Feb 17 19:48:18 2009 From: sabre at nondot.org (Chris Lattner) Date: Wed, 18 Feb 2009 01:48:18 -0000 Subject: [llvm-commits] [llvm] r64874 - /llvm/trunk/include/llvm/Support/Timer.h Message-ID: <200902180148.n1I1mIFC001592@zion.cs.uiuc.edu> Author: lattner Date: Tue Feb 17 19:48:17 2009 New Revision: 64874 URL: http://llvm.org/viewvc/llvm-project?rev=64874&view=rev Log: allow TimeRegion to take a potentially-null pointer to a timer for clang. Modified: llvm/trunk/include/llvm/Support/Timer.h Modified: llvm/trunk/include/llvm/Support/Timer.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Timer.h?rev=64874&r1=64873&r2=64874&view=diff ============================================================================== --- llvm/trunk/include/llvm/Support/Timer.h (original) +++ llvm/trunk/include/llvm/Support/Timer.h Tue Feb 17 19:48:17 2009 @@ -113,14 +113,19 @@ /// the relevant timer. This makes it easy to time a region of code. /// class TimeRegion { - Timer &T; + Timer *T; TimeRegion(const TimeRegion &); // DO NOT IMPLEMENT public: - explicit TimeRegion(Timer &t) : T(t) { - T.startTimer(); + explicit TimeRegion(Timer &t) : T(&t) { + T->startTimer(); + } + explicit TimeRegion(Timer *t) : T(t) { + if (T) + T->startTimer(); } ~TimeRegion() { - T.stopTimer(); + if (T) + T->stopTimer(); } }; From evan.cheng at apple.com Tue Feb 17 20:19:53 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Wed, 18 Feb 2009 02:19:53 -0000 Subject: [llvm-commits] [llvm] r64877 - in /llvm/trunk: lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp test/CodeGen/X86/cstring.ll Message-ID: <200902180219.n1I2JrjZ030169@zion.cs.uiuc.edu> Author: evancheng Date: Tue Feb 17 20:19:52 2009 New Revision: 64877 URL: http://llvm.org/viewvc/llvm-project?rev=64877&view=rev Log: GV with null value initializer shouldn't go to BSS if it's meant for a mergeable strings section. Currently it only checks for Darwin. Someone else please check if it should apply to other targets as well. Added: llvm/trunk/test/CodeGen/X86/cstring.ll Modified: llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Modified: llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp?rev=64877&r1=64876&r2=64877&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp (original) +++ llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp Tue Feb 17 20:19:52 2009 @@ -835,7 +835,9 @@ if (Subtarget->isTargetELF()) O << "\t.type " << name << ",%object\n"; - if (C->isNullValue() && !GVar->hasSection() && !GVar->isThreadLocal()) { + if (C->isNullValue() && !GVar->hasSection() && !GVar->isThreadLocal() && + !(isDarwin && + TAI->SectionKindForGlobal(GVar) == SectionKind::RODataMergeStr)) { // FIXME: This seems to be pretty darwin-specific if (GVar->hasExternalLinkage()) { Modified: llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp?rev=64877&r1=64876&r2=64877&view=diff ============================================================================== --- llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp (original) +++ llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp Tue Feb 17 20:19:52 2009 @@ -915,7 +915,8 @@ if (C->isNullValue() && /* FIXME: Verify correct */ !GVar->hasSection() && (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() || - GVar->mayBeOverridden())) { + GVar->mayBeOverridden()) && + TAI->SectionKindForGlobal(GVar) != SectionKind::RODataMergeStr) { if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. if (GVar->hasExternalLinkage()) { Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp?rev=64877&r1=64876&r2=64877&view=diff ============================================================================== --- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp (original) +++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Tue Feb 17 20:19:52 2009 @@ -799,7 +799,9 @@ SwitchToSection(TAI->SectionForGlobal(GVar)); - if (C->isNullValue() && !GVar->hasSection()) { + if (C->isNullValue() && !GVar->hasSection() && + !(Subtarget->isTargetDarwin() && + TAI->SectionKindForGlobal(GVar) == SectionKind::RODataMergeStr)) { // FIXME: This seems to be pretty darwin-specific if (GVar->hasExternalLinkage()) { if (const char *Directive = TAI->getZeroFillDirective()) { Added: llvm/trunk/test/CodeGen/X86/cstring.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/cstring.ll?rev=64877&view=auto ============================================================================== --- llvm/trunk/test/CodeGen/X86/cstring.ll (added) +++ llvm/trunk/test/CodeGen/X86/cstring.ll Tue Feb 17 20:19:52 2009 @@ -0,0 +1,4 @@ +; RUN: llvm-as < %s | llc -mtriple=i386-apple-darwin | not grep comm +; rdar://6479858 + + at str1 = internal constant [1 x i8] zeroinitializer From evan.cheng at apple.com Tue Feb 17 21:05:24 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Wed, 18 Feb 2009 03:05:24 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64878 - in /llvm-gcc-4.2/trunk/gcc: tree-inline.c tree-optimize.c Message-ID: <200902180305.n1I35OEq009507@zion.cs.uiuc.edu> Author: evancheng Date: Tue Feb 17 21:05:23 2009 New Revision: 64878 URL: http://llvm.org/viewvc/llvm-project?rev=64878&view=rev Log: Turns out 64819 isn't safe. It can trigger verify_cgraph_node failure later. gcc is relying on some optimization pass to clear certain states. Nice. This fixes that and just disable -Winline warnings instead. Modified: llvm-gcc-4.2/trunk/gcc/tree-inline.c llvm-gcc-4.2/trunk/gcc/tree-optimize.c Modified: llvm-gcc-4.2/trunk/gcc/tree-inline.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/tree-inline.c?rev=64878&r1=64877&r2=64878&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/tree-inline.c (original) +++ llvm-gcc-4.2/trunk/gcc/tree-inline.c Tue Feb 17 21:05:23 2009 @@ -2037,6 +2037,8 @@ inlining. */ if (!cgraph_inline_p (cg_edge, &reason)) { +/* LLVM LOCAL begin */ +#ifndef ENABLE_LLVM if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) /* Avoid warnings during early inline pass. */ && (!flag_unit_at_a_time || cgraph_global_info_ready)) @@ -2057,6 +2059,8 @@ fn, reason); warning (OPT_Winline, "called from here"); } +#endif +/* LLVM LOCAL end */ goto egress; } fn = cg_edge->callee->decl; Modified: llvm-gcc-4.2/trunk/gcc/tree-optimize.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/tree-optimize.c?rev=64878&r1=64877&r2=64878&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/tree-optimize.c (original) +++ llvm-gcc-4.2/trunk/gcc/tree-optimize.c Tue Feb 17 21:05:23 2009 @@ -439,8 +439,6 @@ cfun->x_dont_save_pending_sizes_p = 1; cfun->after_inlining = true; -/* LLVM LOCAL begin */ -#ifndef ENABLE_LLVM if (flag_inline_trees) { struct cgraph_edge *e; @@ -454,8 +452,6 @@ timevar_pop (TV_INTEGRATION); } } -#endif -/* LLVM LOCAL end */ /* In non-unit-at-a-time we must mark all referenced functions as needed. */ if (!flag_unit_at_a_time) From clattner at apple.com Tue Feb 17 21:48:33 2009 From: clattner at apple.com (Chris Lattner) Date: Tue, 17 Feb 2009 19:48:33 -0800 Subject: [llvm-commits] [llvm] r64877 - in /llvm/trunk: lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp test/CodeGen/X86/cstring.ll In-Reply-To: <200902180219.n1I2JrjZ030169@zion.cs.uiuc.edu> References: <200902180219.n1I2JrjZ030169@zion.cs.uiuc.edu> Message-ID: On Feb 17, 2009, at 6:19 PM, Evan Cheng wrote: > Author: evancheng > Date: Tue Feb 17 20:19:52 2009 > New Revision: 64877 > > URL: http://llvm.org/viewvc/llvm-project?rev=64877&view=rev > Log: > GV with null value initializer shouldn't go to BSS if it's meant for > a mergeable strings section. Currently it only checks for Darwin. > Someone else please check if it should apply to other targets as well. Evan, this seems like the wrong fix. What *requires* an empty string to go into the cstring section? If there is some semantics that require it, then whatever produces the llvm global should set the section of the global to the cstring section explicitly. -Chris From nicholas at mxc.ca Tue Feb 17 21:59:19 2009 From: nicholas at mxc.ca (Nick Lewycky) Date: Tue, 17 Feb 2009 19:59:19 -0800 Subject: [llvm-commits] [llvm] r64812 - /llvm/trunk/tools/gold/gold-plugin.cpp In-Reply-To: <200902172108.n1HL8Mk5019285@zion.cs.uiuc.edu> References: <200902172108.n1HL8Mk5019285@zion.cs.uiuc.edu> Message-ID: <499B8797.70306@mxc.ca> Rafael Espindola wrote: > Author: rafael > Date: Tue Feb 17 15:08:21 2009 > New Revision: 64812 > > URL: http://llvm.org/viewvc/llvm-project?rev=64812&view=rev > Log: > tools like nm and ar only need register_claim_file and add_symbols. Don't abort > if other hooks are missing. :-) > Modified: > llvm/trunk/tools/gold/gold-plugin.cpp > > Modified: llvm/trunk/tools/gold/gold-plugin.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=64812&r1=64811&r2=64812&view=diff > > ============================================================================== > --- llvm/trunk/tools/gold/gold-plugin.cpp (original) > +++ llvm/trunk/tools/gold/gold-plugin.cpp Tue Feb 17 15:08:21 2009 > @@ -142,11 +142,16 @@ > } > } > > - if (!registeredClaimFile || !registeredAllSymbolsRead || !registeredCleanup || > - !add_symbols || !get_symbols || !add_input_file) { > - (*message)(LDPL_ERROR, "Not all hooks registered for LLVMgold."); > - return LDPS_ERR; > - } > + if (!registeredClaimFile) > + { > + (*message)(LDPL_ERROR, "register_claim_file not passed to LLVMgold."); > + return LDPS_ERR; > + } > + if (!add_symbols) > + { > + (*message)(LDPL_ERROR, "add_symbols not passed to LLVMgold."); > + return LDPS_ERR; > + } Please follow the LLVM style for gold-plugin.cc. Notably, we put the open brace on the same line at the if statement. Nick > > return LDPS_OK; > } > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > From eli.friedman at gmail.com Tue Feb 17 22:16:36 2009 From: eli.friedman at gmail.com (Eli Friedman) Date: Tue, 17 Feb 2009 20:16:36 -0800 Subject: [llvm-commits] [llvm] r64877 - in /llvm/trunk: lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp test/CodeGen/X86/cstring.ll In-Reply-To: References: <200902180219.n1I2JrjZ030169@zion.cs.uiuc.edu> Message-ID: On Tue, Feb 17, 2009 at 7:48 PM, Chris Lattner wrote: > > On Feb 17, 2009, at 6:19 PM, Evan Cheng wrote: > >> Author: evancheng >> Date: Tue Feb 17 20:19:52 2009 >> New Revision: 64877 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=64877&view=rev >> Log: >> GV with null value initializer shouldn't go to BSS if it's meant for >> a mergeable strings section. Currently it only checks for Darwin. >> Someone else please check if it should apply to other targets as well. > > Evan, this seems like the wrong fix. What *requires* an empty string > to go into the cstring section? If there is some semantics that > require it, then whatever produces the llvm global should set the > section of the global to the cstring section explicitly. I don't know for sure, but I'm assuming it's this "ObjC strings must go into some specific section" thing that we've been going back and forth on for the past few months. -Eli From gohman at apple.com Tue Feb 17 22:25:08 2009 From: gohman at apple.com (Dan Gohman) Date: Wed, 18 Feb 2009 04:25:08 -0000 Subject: [llvm-commits] [llvm] r64883 - /llvm/trunk/test/Transforms/InstCombine/enforce-known-alignment.ll Message-ID: <200902180425.n1I4P8s9010629@zion.cs.uiuc.edu> Author: djg Date: Tue Feb 17 22:25:04 2009 New Revision: 64883 URL: http://llvm.org/viewvc/llvm-project?rev=64883&view=rev Log: Change the argument type in this test to something less convoluted, since it isn't actually used. Modified: llvm/trunk/test/Transforms/InstCombine/enforce-known-alignment.ll Modified: llvm/trunk/test/Transforms/InstCombine/enforce-known-alignment.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/enforce-known-alignment.ll?rev=64883&r1=64882&r2=64883&view=diff ============================================================================== --- llvm/trunk/test/Transforms/InstCombine/enforce-known-alignment.ll (original) +++ llvm/trunk/test/Transforms/InstCombine/enforce-known-alignment.ll Tue Feb 17 22:25:04 2009 @@ -2,7 +2,7 @@ target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" target triple = "i386-apple-darwin9.6" -define void @foo(<{ { [4 x i32] }, i32, i32, i32, i8, i8, i8, i8, i8, [3 x i8], { i8, i8, i8, i8, [4 x i32], [4 x i32], [4 x i32], i8, i8, i8, i8, i8, i8 }*, <{ i8, i8, i8, i8, i8, i8, [2 x i8], i32, [4 x i8], <{ [16 x { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } }], i8, [15 x i8] }>, { i8, i8, [16 x i8], [4 x i8], [16 x i8], [4 x i8] }, [2 x i8], i32, i32, i32, i32, i32, i32, i32, i32, [2 x [16 x [3 x i32]]], [2 x [16 x [3 x i32]]], [2 x [16 x [16 x [3 x i32]]]], [1 x i32] }>*, <{ <{ { [16 x i16] }, { [256 x i16] } }>, <{ { [64 x i16] }, { [64 x i16] }, { [8 x i16] } }> }>*, i8*, { [2 x { { i32 } }], [2 x i8], i8, [2 x i32], i32, i32, i32 }*, { [2 x { { i32 } }], [2 x i8], i8, [2 x i32], i32, i32, i32 }*, { [2 x { { i32 } }], [2 x i8], i8, [2 x i32], i32, i32, i32 }*, i32, i32, i32, i32, i32, i32, { [34 x <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*]! , [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{ { <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i3! 2, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, i32, i! 8*, i32, i32, i32, i32, i16*, i16, i16, i16, i16, float, i8*, i32*, i32, i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32, i16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i32, i32, i32, double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>*], [34 x <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i3! 2, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{ { <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i32, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, ! i32, i8*, i32, i32, i32, i32, i16*, i16, i16, i16, i16, float,! i8*, i3 2*, i32, i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32, i16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i32, i32, i32, double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>*], [34 x i32], [34 x i32], [2 x i32], [2 x i32], <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32! , i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{ { <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i32, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, i32, i8*, i32, i! 32, i32, i32, i16*, i16, i16, i16, i16, float, i8*, i32*, i32,! i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32, i16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i32, i32, i32, double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>* }*, i32**, opaque*, [5 x <{ i32, [7 x i32], <{ { [16 x i8] } }>, <{ { [16 x i8] } }>, i8, [15 x i8], <{ { [16 x i8] }, [4 x i8], [4 x i8], [2 x i32] }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, { i8, i8, i8, i8, i8, i8, i8, [16 x i8], i8, i8, i64, [2 x [16 x [! 2 x i16]]], [2 x [16 x i8]], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, i32 }, [16 x i32] }>*], <{ i32, [7 x i32], <{ { [16 x i8] } }>, <{ { [16 x i8] } }>, i8, [15 x i8], <{ { [16 x i8] }, [4 x i8], [4 x i8], [2 x i32] }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, { i8, i8, i8, i8, i8, i8, i8, [16 x i8], i8, i8, i64, [2 x [16 x [2 x i16]]], [2 x [16 x i8]], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, i32 }, [16 x i32] }>*, i8, i8, i8, i8, i8, [3 x i8], i8*, i8*, i8*, <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [! 21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{ { <{ { ! { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i32, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, i32, i8*, i32, i32, i32, i32, i16*, i16, i16, i16, i16, float, i8*, i32*, i32, i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32, i! 16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i32, i32, i32, double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>*, [2 x <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{ { *, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i32, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, i32, i8*, i32, i32, i32, i32, i16*, i16, i16, i16, i16, float, i8*, i32*, i32, i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32, i16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, {! i32, i32, i32, double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>**], [2 x i32], [2 x i32], [33 x i8]*, [41 x i8]*, <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{ { <{ { { [2 x { { ! i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { ! [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i32, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, i32, i8*, i32, i32, i32, i32, i16*, i16, i16, i16, i16, float, i8*, i32*, i32, i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32, i16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i32, i32, i32,! double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>*, { <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, i32, i32, i32, i32, i32*, { { i32, i32 }, i8, i8, i8, i8, [17 x <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32],! [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{ { <{ ! { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i32, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, i32, i8*, i32, i32, i32, i32, i16*, i16, i16, i16, i16, float, i8*, i32*, i32, i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32,! i16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i32, i32, i32, double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>*], [17 x <{ i8, i8, i8, i8, i8, [3 x i8], i8*, i32, opaque*, opaque*, i32, opaque*, opaque*, [12 x i8], <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>, <{! { <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, ! i8 } } } >*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* }**, i32, i32, [4 x i8], <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>**, [3 x i32] }>, { i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, \3, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, { i8 } }, i32, { i16, i16, i32, i32, i32*, i32*, i32, i32, i32*, i32, i32, i32, i32, i32, i8*, i32, i32, i32, i32, i16*, i16, i16, i16, i16, float, i8*, i32*, i32, i32, i8 }, { i32, i32, { i32, i32, i32, i32, [16 x { i32, { { i16 } }, i32, i32, [2 x { { i32 } }], [2 x i8], i16 }] }*, i32, i32, i32, i32, i32 }, { i32, i32, i32, { [2 x i8], [2 x { { i32 } }], i8, [3 x { i32, i16, i16 }] }*, { i8, i8, i8, i8, i8, i8, i8, i8, i8, i! 8, { i32, i32, i32, double }, { i32, i32, i32, double } }*, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8 }, { i32, float, i8, i8 }, { i8, i8, i32, i8, i8, float }, { i32, i32, i32, i32, { i32, i32, i32, [5 x i32], [3 x i32], [4 x i32], [3 x i32] }, { i32, i32, i32, i32, [5 x i32], [3 x i32], [4 x [4 x i32]], [4 x i32], i32, { { i32 } }, { { i32 } } } }, { i8, i8, i32, double, i8, float, i8, float, i8, i8, i8, i8, i8 }, [1 x i32] }>*] }*, i32, opaque*, i16*, <{ i8, i8, i8, i8, i8, i8, i8, i8, i8*, i8*, i32, [4 x i8*], [4 x i8*], [2 x [4 x i32]], [2 x [4 x i32]], { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i8*, i8, i8, i32, i8* }, opaque*, [16 x i16], [16 x i16], [12 x i8], { [4 x i32] }, { [4 x i32] }, { [21 x i32], [21 x i32], [4 x [21 x i32]] }, <{ i16 }>*, i32* }>*, i8*, i8*, i8*, i8*, i8*, { [16 x i8], [16 x i8] }*, opaque*, i8*, i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i! 8 }*, double, [16 x { i32, i32, i32, { i16* }, { [1 x i16*], [! 2 x i16* ], [2 x i16*], [4 x i16*], [8 x i16*], [8 x i16*], [16 x i16*] }, i32, [64 x { { { i32 } }, i8 }], { i16* }, [64 x { [1 x i16*], [2 x i16*], [2 x i16*], [4 x i16*], [8 x i16*], [8 x i16*], [16 x i16*] }], { i16* }, { i16* }, i32, [20 x { { i8, { { i16 } }, { { i32 } } }, i32, { { i32 } } }] }], [16 x { i32, i32, i32, { i16* }, { [1 x i16*], [2 x i16*], [2 x i16*], [4 x i16*], [8 x i16*], [8 x i16*], [16 x i16*] }, i32, [64 x { { { i32 } }, i8 }], { i16* }, [64 x { [1 x i16*], [2 x i16*], [2 x i16*], [4 x i16*], [8 x i16*], [8 x i16*], [16 x i16*] }], { i16* }, { i16* }, i32, [20 x { { i8, { { i16 } }, { { i32 } } }, i32, { { i32 } } }] }], { i8* }, { i8* }, i8, i8, [6 x [16 x i8]], [2 x [64 x i8]], [6 x [16 x i8]], [2 x [64 x i8]], [2 x i8], { i8* }, { i8* }, <{ i8, [15 x i8], [4 x <{ [16 x i8], <{ i8 }>, [3 x i8], i32, i32, [4 x i8], { [256 x i8] }, { [256 x i16] }, { [256 x i16] }, <{ <{ { [16 x i16] }, { [256 x i16] } }>, <{ { [64 x i16] }, { [64 x i16] }, { [8 x i16] } }! > }> }>] }>*, <{ i8, [15 x i8], [2 x <{ i8, <{ i8 }>, i8, i8, i32, i32, [4 x i8], { [128 x i8] }, { [128 x i16] }, { [128 x i16] }, <{ { [64 x i16] }, { [64 x i16] }, { [8 x i16] } }> }>] }>*, { i32, i32, i32, double }, { i32, i32, i32, double }, <{ [16 x i8], <{ i8 }>, [3 x i8], i32, i32, [4 x i8], { [256 x i8] }, { [256 x i16] }, { [256 x i16] }, <{ <{ { [16 x i16] }, { [256 x i16] } }>, <{ { [64 x i16] }, { [64 x i16] }, { [8 x i16] } }> }> }>*, <{ i8, <{ i8 }>, i8, i8, i32, i32, [4 x i8], { [128 x i8] }, { [128 x i16] }, { [128 x i16] }, <{ { [64 x i16] }, { [64 x i16] }, { [8 x i16] } }> }>*, <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*, i32, i32, i32, i32, i32, i32, i32 }>*) { +define void @foo(i32) { %2 = alloca [3 x <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>], align 16 ; <[3 x <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>]*> [#uses=1] %3 = getelementptr [3 x <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>]* %2, i32 0, i32 0 ; <<{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*> [#uses=1] %4 = getelementptr <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* %3, i32 0, i32 0 ; <{ { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } }*> [#uses=1] From evan.cheng at apple.com Tue Feb 17 22:52:50 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 17 Feb 2009 20:52:50 -0800 Subject: [llvm-commits] [llvm] r64877 - in /llvm/trunk: lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp test/CodeGen/X86/cstring.ll In-Reply-To: References: <200902180219.n1I2JrjZ030169@zion.cs.uiuc.edu> Message-ID: <3C282F1A-29E3-4412-827D-473C0C637C7F@apple.com> On Feb 17, 2009, at 7:48 PM, Chris Lattner wrote: > > On Feb 17, 2009, at 6:19 PM, Evan Cheng wrote: > >> Author: evancheng >> Date: Tue Feb 17 20:19:52 2009 >> New Revision: 64877 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=64877&view=rev >> Log: >> GV with null value initializer shouldn't go to BSS if it's meant for >> a mergeable strings section. Currently it only checks for Darwin. >> Someone else please check if it should apply to other targets as >> well. > > Evan, this seems like the wrong fix. What *requires* an empty string > to go into the cstring section? If there is some semantics that > require it, then whatever produces the llvm global should set the > section of the global to the cstring section explicitly. I don't see why this is wrong/ Per revision 63142,target asm info has already decided this particular GV should go into cstring. But the asm printer then decided to put it in BSS (which means it cannot be coalesced) because the initializer is empty. This patch makes sure asm printer doesn't try to out smart itself. Evan > > > -Chris > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090217/bd462e56/attachment.html From clattner at apple.com Tue Feb 17 22:53:48 2009 From: clattner at apple.com (Chris Lattner) Date: Tue, 17 Feb 2009 20:53:48 -0800 Subject: [llvm-commits] [llvm] r64877 - in /llvm/trunk: lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp test/CodeGen/X86/cstring.ll In-Reply-To: <3C282F1A-29E3-4412-827D-473C0C637C7F@apple.com> References: <200902180219.n1I2JrjZ030169@zion.cs.uiuc.edu> <3C282F1A-29E3-4412-827D-473C0C637C7F@apple.com> Message-ID: <27A4E95A-B7DA-4385-9739-6239A4837A40@apple.com> On Feb 17, 2009, at 8:52 PM, Evan Cheng wrote: > > On Feb 17, 2009, at 7:48 PM, Chris Lattner wrote: > >> >> On Feb 17, 2009, at 6:19 PM, Evan Cheng wrote: >> >>> Author: evancheng >>> Date: Tue Feb 17 20:19:52 2009 >>> New Revision: 64877 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=64877&view=rev >>> Log: >>> GV with null value initializer shouldn't go to BSS if it's meant for >>> a mergeable strings section. Currently it only checks for Darwin. >>> Someone else please check if it should apply to other targets as >>> well. >> >> Evan, this seems like the wrong fix. What *requires* an empty string >> to go into the cstring section? If there is some semantics that >> require it, then whatever produces the llvm global should set the >> section of the global to the cstring section explicitly. > > I don't see why this is wrong/ Per revision 63142,target asm info > has already decided this particular GV should go into cstring. But > the asm printer then decided to put it in BSS (which means it cannot > be coalesced) because the initializer is empty. This patch makes > sure asm printer doesn't try to out smart itself. Why is this important? -Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090217/5c794034/attachment.html From gohman at apple.com Tue Feb 17 23:09:20 2009 From: gohman at apple.com (Dan Gohman) Date: Wed, 18 Feb 2009 05:09:20 -0000 Subject: [llvm-commits] [llvm] r64888 - in /llvm/trunk: docs/WritingAnLLVMPass.html include/llvm/Analysis/LoopInfo.h include/llvm/Analysis/LoopVR.h include/llvm/CodeGen/MachineLoopInfo.h include/llvm/PassManagers.h include/llvm/Target/TargetData.h lib/CodeGen/GCMetadata.cpp lib/CodeGen/GCStrategy.cpp lib/CodeGen/MachineDominators.cpp lib/Transforms/Scalar/DCE.cpp lib/VMCore/PrintModulePass.cpp tools/bugpoint/TestPasses.cpp tools/opt/AnalysisWrappers.cpp tools/opt/GraphPrinters.cpp tools/opt/PrintSCC.cpp tools/opt/opt.cpp Message-ID: <200902180509.n1I59L5X016928@zion.cs.uiuc.edu> Author: djg Date: Tue Feb 17 23:09:16 2009 New Revision: 64888 URL: http://llvm.org/viewvc/llvm-project?rev=64888&view=rev Log: Eliminate several more unnecessary intptr_t casts. Modified: llvm/trunk/docs/WritingAnLLVMPass.html llvm/trunk/include/llvm/Analysis/LoopInfo.h llvm/trunk/include/llvm/Analysis/LoopVR.h llvm/trunk/include/llvm/CodeGen/MachineLoopInfo.h llvm/trunk/include/llvm/PassManagers.h llvm/trunk/include/llvm/Target/TargetData.h llvm/trunk/lib/CodeGen/GCMetadata.cpp llvm/trunk/lib/CodeGen/GCStrategy.cpp llvm/trunk/lib/CodeGen/MachineDominators.cpp llvm/trunk/lib/Transforms/Scalar/DCE.cpp llvm/trunk/lib/VMCore/PrintModulePass.cpp llvm/trunk/tools/bugpoint/TestPasses.cpp llvm/trunk/tools/opt/AnalysisWrappers.cpp llvm/trunk/tools/opt/GraphPrinters.cpp llvm/trunk/tools/opt/PrintSCC.cpp llvm/trunk/tools/opt/opt.cpp Modified: llvm/trunk/docs/WritingAnLLVMPass.html URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/WritingAnLLVMPass.html?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/docs/WritingAnLLVMPass.html (original) +++ llvm/trunk/docs/WritingAnLLVMPass.html Tue Feb 17 23:09:16 2009 @@ -265,7 +265,7 @@
      static char ID;
-     Hello() : FunctionPass((intptr_t)&ID) {}
+     Hello() : FunctionPass(&ID) {}
 

This declares pass identifier used by LLVM to identify pass. This allows LLVM to @@ -319,7 +319,7 @@ struct Hello : public FunctionPass { static char ID; - Hello() : FunctionPass((intptr_t)&ID) {} + Hello() : FunctionPass(&ID) {} virtual bool runOnFunction(Function &F) { llvm::cerr << "Hello: " << F.getName() << "\n"; Modified: llvm/trunk/include/llvm/Analysis/LoopInfo.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopInfo.h?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/LoopInfo.h (original) +++ llvm/trunk/include/llvm/Analysis/LoopInfo.h Tue Feb 17 23:09:16 2009 @@ -937,7 +937,7 @@ public: static char ID; // Pass identification, replacement for typeid - LoopInfo() : FunctionPass(intptr_t(&ID)) { + LoopInfo() : FunctionPass(&ID) { LI = new LoopInfoBase(); } Modified: llvm/trunk/include/llvm/Analysis/LoopVR.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopVR.h?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/LoopVR.h (original) +++ llvm/trunk/include/llvm/Analysis/LoopVR.h Tue Feb 17 23:09:16 2009 @@ -30,7 +30,7 @@ public: static char ID; // Class identification, replacement for typeinfo - LoopVR() : FunctionPass(intptr_t(&ID)) {} + LoopVR() : FunctionPass(&ID) {} bool runOnFunction(Function &F); virtual void print(std::ostream &os, const Module *) const; Modified: llvm/trunk/include/llvm/CodeGen/MachineLoopInfo.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineLoopInfo.h?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/include/llvm/CodeGen/MachineLoopInfo.h (original) +++ llvm/trunk/include/llvm/CodeGen/MachineLoopInfo.h Tue Feb 17 23:09:16 2009 @@ -77,7 +77,7 @@ public: static char ID; // Pass identification, replacement for typeid - MachineLoopInfo() : MachineFunctionPass(intptr_t(&ID)) { + MachineLoopInfo() : MachineFunctionPass(&ID) { LI = new LoopInfoBase(); } Modified: llvm/trunk/include/llvm/PassManagers.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassManagers.h?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/include/llvm/PassManagers.h (original) +++ llvm/trunk/include/llvm/PassManagers.h Tue Feb 17 23:09:16 2009 @@ -384,7 +384,7 @@ public: static char ID; explicit FPPassManager(int Depth) - : ModulePass(intptr_t(&ID)), PMDataManager(Depth) { } + : ModulePass(&ID), PMDataManager(Depth) { } /// run - Execute all of the passes scheduled for execution. Keep track of /// whether any of the passes modifies the module, and if so, return true. Modified: llvm/trunk/include/llvm/Target/TargetData.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetData.h?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/include/llvm/Target/TargetData.h (original) +++ llvm/trunk/include/llvm/Target/TargetData.h Tue Feb 17 23:09:16 2009 @@ -109,7 +109,7 @@ /// /// @note This has to exist, because this is a pass, but it should never be /// used. - TargetData() : ImmutablePass(intptr_t(&ID)) { + TargetData() : ImmutablePass(&ID) { assert(0 && "ERROR: Bad TargetData ctor used. " "Tool did not specify a TargetData to use?"); abort(); @@ -117,7 +117,7 @@ /// Constructs a TargetData from a specification string. See init(). explicit TargetData(const std::string &TargetDescription) - : ImmutablePass(intptr_t(&ID)) { + : ImmutablePass(&ID) { init(TargetDescription); } @@ -125,7 +125,7 @@ explicit TargetData(const Module *M); TargetData(const TargetData &TD) : - ImmutablePass(intptr_t(&ID)), + ImmutablePass(&ID), LittleEndian(TD.isLittleEndian()), PointerMemSize(TD.PointerMemSize), PointerABIAlign(TD.PointerABIAlign), Modified: llvm/trunk/lib/CodeGen/GCMetadata.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GCMetadata.cpp?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/GCMetadata.cpp (original) +++ llvm/trunk/lib/CodeGen/GCMetadata.cpp Tue Feb 17 23:09:16 2009 @@ -129,7 +129,7 @@ } Printer::Printer(std::ostream &OS) - : FunctionPass(intptr_t(&ID)), OS(OS) {} + : FunctionPass(&ID), OS(OS) {} const char *Printer::getPassName() const { return "Print Garbage Collector Information"; @@ -189,7 +189,7 @@ return new Deleter(); } -Deleter::Deleter() : FunctionPass(intptr_t(&ID)) {} +Deleter::Deleter() : FunctionPass(&ID) {} const char *Deleter::getPassName() const { return "Delete Garbage Collector Information"; Modified: llvm/trunk/lib/CodeGen/GCStrategy.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GCStrategy.cpp?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/GCStrategy.cpp (original) +++ llvm/trunk/lib/CodeGen/GCStrategy.cpp Tue Feb 17 23:09:16 2009 @@ -313,7 +313,7 @@ char MachineCodeAnalysis::ID = 0; MachineCodeAnalysis::MachineCodeAnalysis() - : MachineFunctionPass(intptr_t(&ID)) {} + : MachineFunctionPass(&ID) {} const char *MachineCodeAnalysis::getPassName() const { return "Analyze Machine Code For Garbage Collection"; Modified: llvm/trunk/lib/CodeGen/MachineDominators.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineDominators.cpp?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/MachineDominators.cpp (original) +++ llvm/trunk/lib/CodeGen/MachineDominators.cpp Tue Feb 17 23:09:16 2009 @@ -39,7 +39,7 @@ } MachineDominatorTree::MachineDominatorTree() - : MachineFunctionPass(intptr_t(&ID)) { + : MachineFunctionPass(&ID) { DT = new DominatorTreeBase(false); } Modified: llvm/trunk/lib/Transforms/Scalar/DCE.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/DCE.cpp?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/DCE.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/DCE.cpp Tue Feb 17 23:09:16 2009 @@ -36,7 +36,7 @@ // struct VISIBILITY_HIDDEN DeadInstElimination : public BasicBlockPass { static char ID; // Pass identification, replacement for typeid - DeadInstElimination() : BasicBlockPass(intptr_t(&ID)) {} + DeadInstElimination() : BasicBlockPass(&ID) {} virtual bool runOnBasicBlock(BasicBlock &BB) { bool Changed = false; for (BasicBlock::iterator DI = BB.begin(); DI != BB.end(); ) { Modified: llvm/trunk/lib/VMCore/PrintModulePass.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/PrintModulePass.cpp?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/lib/VMCore/PrintModulePass.cpp (original) +++ llvm/trunk/lib/VMCore/PrintModulePass.cpp Tue Feb 17 23:09:16 2009 @@ -27,10 +27,10 @@ bool DeleteStream; // Delete the ostream in our dtor? public: static char ID; - PrintModulePass() : ModulePass(intptr_t(&ID)), Out(&errs()), + PrintModulePass() : ModulePass(&ID), Out(&errs()), DeleteStream(false) {} PrintModulePass(raw_ostream *o, bool DS) - : ModulePass(intptr_t(&ID)), Out(o), DeleteStream(DS) {} + : ModulePass(&ID), Out(o), DeleteStream(DS) {} ~PrintModulePass() { if (DeleteStream) delete Out; @@ -53,10 +53,10 @@ bool DeleteStream; // Delete the ostream in our dtor? public: static char ID; - PrintFunctionPass() : FunctionPass(intptr_t(&ID)), Banner(""), Out(&errs()), + PrintFunctionPass() : FunctionPass(&ID), Banner(""), Out(&errs()), DeleteStream(false) {} PrintFunctionPass(const std::string &B, raw_ostream *o, bool DS) - : FunctionPass(intptr_t(&ID)), Banner(B), Out(o), DeleteStream(DS) {} + : FunctionPass(&ID), Banner(B), Out(o), DeleteStream(DS) {} inline ~PrintFunctionPass() { if (DeleteStream) delete Out; Modified: llvm/trunk/tools/bugpoint/TestPasses.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/TestPasses.cpp?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/tools/bugpoint/TestPasses.cpp (original) +++ llvm/trunk/tools/bugpoint/TestPasses.cpp Tue Feb 17 23:09:16 2009 @@ -27,7 +27,7 @@ class CrashOnCalls : public BasicBlockPass { public: static char ID; // Pass ID, replacement for typeid - CrashOnCalls() : BasicBlockPass((intptr_t)&ID) {} + CrashOnCalls() : BasicBlockPass(&ID) {} private: virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); @@ -54,7 +54,7 @@ class DeleteCalls : public BasicBlockPass { public: static char ID; // Pass ID, replacement for typeid - DeleteCalls() : BasicBlockPass((intptr_t)&ID) {} + DeleteCalls() : BasicBlockPass(&ID) {} private: bool runOnBasicBlock(BasicBlock &BB) { for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) Modified: llvm/trunk/tools/opt/AnalysisWrappers.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/AnalysisWrappers.cpp?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/tools/opt/AnalysisWrappers.cpp (original) +++ llvm/trunk/tools/opt/AnalysisWrappers.cpp Tue Feb 17 23:09:16 2009 @@ -31,7 +31,7 @@ /// or handle in alias analyses. struct ExternalFunctionsPassedConstants : public ModulePass { static char ID; // Pass ID, replacement for typeid - ExternalFunctionsPassedConstants() : ModulePass((intptr_t)&ID) {} + ExternalFunctionsPassedConstants() : ModulePass(&ID) {} virtual bool runOnModule(Module &M) { for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) if (I->isDeclaration()) { @@ -70,7 +70,7 @@ struct CallGraphPrinter : public ModulePass { static char ID; // Pass ID, replacement for typeid - CallGraphPrinter() : ModulePass((intptr_t)&ID) {} + CallGraphPrinter() : ModulePass(&ID) {} virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); Modified: llvm/trunk/tools/opt/GraphPrinters.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/GraphPrinters.cpp?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/tools/opt/GraphPrinters.cpp (original) +++ llvm/trunk/tools/opt/GraphPrinters.cpp Tue Feb 17 23:09:16 2009 @@ -62,7 +62,7 @@ namespace { struct CallGraphPrinter : public ModulePass { static char ID; // Pass ID, replacement for typeid - CallGraphPrinter() : ModulePass((intptr_t)&ID) {} + CallGraphPrinter() : ModulePass(&ID) {} virtual bool runOnModule(Module &M) { WriteGraphToFile(std::cerr, "callgraph", &getAnalysis()); @@ -91,7 +91,7 @@ class DomInfoPrinter : public FunctionPass { public: static char ID; // Pass identification, replacement for typeid - DomInfoPrinter() : FunctionPass((intptr_t)&ID) {} + DomInfoPrinter() : FunctionPass(&ID) {} virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); Modified: llvm/trunk/tools/opt/PrintSCC.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/PrintSCC.cpp?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/tools/opt/PrintSCC.cpp (original) +++ llvm/trunk/tools/opt/PrintSCC.cpp Tue Feb 17 23:09:16 2009 @@ -36,7 +36,7 @@ namespace { struct CFGSCC : public FunctionPass { static char ID; // Pass identification, replacement for typeid - CFGSCC() : FunctionPass((intptr_t)&ID) {} + CFGSCC() : FunctionPass(&ID) {} bool runOnFunction(Function& func); void print(std::ostream &O, const Module* = 0) const { } @@ -48,7 +48,7 @@ struct CallGraphSCC : public ModulePass { static char ID; // Pass identification, replacement for typeid - CallGraphSCC() : ModulePass((intptr_t)&ID) {} + CallGraphSCC() : ModulePass(&ID) {} // run - Print out SCCs in the call graph for the specified module. bool runOnModule(Module &M); Modified: llvm/trunk/tools/opt/opt.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=64888&r1=64887&r2=64888&view=diff ============================================================================== --- llvm/trunk/tools/opt/opt.cpp (original) +++ llvm/trunk/tools/opt/opt.cpp Tue Feb 17 23:09:16 2009 @@ -122,7 +122,7 @@ static char ID; const PassInfo *PassToPrint; CallGraphSCCPassPrinter(const PassInfo *PI) : - CallGraphSCCPass((intptr_t)&ID), PassToPrint(PI) {} + CallGraphSCCPass(&ID), PassToPrint(PI) {} virtual bool runOnSCC(const std::vector&SCC) { if (!Quiet) { @@ -151,7 +151,7 @@ struct ModulePassPrinter : public ModulePass { static char ID; const PassInfo *PassToPrint; - ModulePassPrinter(const PassInfo *PI) : ModulePass((intptr_t)&ID), + ModulePassPrinter(const PassInfo *PI) : ModulePass(&ID), PassToPrint(PI) {} virtual bool runOnModule(Module &M) { @@ -176,7 +176,7 @@ struct FunctionPassPrinter : public FunctionPass { const PassInfo *PassToPrint; static char ID; - FunctionPassPrinter(const PassInfo *PI) : FunctionPass((intptr_t)&ID), + FunctionPassPrinter(const PassInfo *PI) : FunctionPass(&ID), PassToPrint(PI) {} virtual bool runOnFunction(Function &F) { @@ -203,7 +203,7 @@ static char ID; const PassInfo *PassToPrint; LoopPassPrinter(const PassInfo *PI) : - LoopPass((intptr_t)&ID), PassToPrint(PI) {} + LoopPass(&ID), PassToPrint(PI) {} virtual bool runOnLoop(Loop *L, LPPassManager &LPM) { if (!Quiet) { @@ -229,7 +229,7 @@ const PassInfo *PassToPrint; static char ID; BasicBlockPassPrinter(const PassInfo *PI) - : BasicBlockPass((intptr_t)&ID), PassToPrint(PI) {} + : BasicBlockPass(&ID), PassToPrint(PI) {} virtual bool runOnBasicBlock(BasicBlock &BB) { if (!Quiet) { From gohman at apple.com Tue Feb 17 23:45:51 2009 From: gohman at apple.com (Dan Gohman) Date: Wed, 18 Feb 2009 05:45:51 -0000 Subject: [llvm-commits] [llvm] r64891 - in /llvm/trunk: include/llvm/CodeGen/MachineInstrBuilder.h lib/Target/ARM/ARMInstrInfo.cpp lib/Target/Alpha/AlphaInstrInfo.cpp lib/Target/CellSPU/SPUInstrInfo.cpp lib/Target/IA64/IA64InstrInfo.cpp lib/Target/Mips/MipsInstrInfo.cpp lib/Target/PowerPC/PPCInstrInfo.cpp lib/Target/Sparc/SparcInstrInfo.cpp lib/Target/X86/X86InstrInfo.cpp Message-ID: <200902180545.n1I5jphQ018146@zion.cs.uiuc.edu> Author: djg Date: Tue Feb 17 23:45:50 2009 New Revision: 64891 URL: http://llvm.org/viewvc/llvm-project?rev=64891&view=rev Log: Factor out the code to add a MachineOperand to a MachineInstrBuilder. Modified: llvm/trunk/include/llvm/CodeGen/MachineInstrBuilder.h llvm/trunk/lib/Target/ARM/ARMInstrInfo.cpp llvm/trunk/lib/Target/Alpha/AlphaInstrInfo.cpp llvm/trunk/lib/Target/CellSPU/SPUInstrInfo.cpp llvm/trunk/lib/Target/IA64/IA64InstrInfo.cpp llvm/trunk/lib/Target/Mips/MipsInstrInfo.cpp llvm/trunk/lib/Target/PowerPC/PPCInstrInfo.cpp llvm/trunk/lib/Target/Sparc/SparcInstrInfo.cpp llvm/trunk/lib/Target/X86/X86InstrInfo.cpp Modified: llvm/trunk/include/llvm/CodeGen/MachineInstrBuilder.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineInstrBuilder.h?rev=64891&r1=64890&r2=64891&view=diff ============================================================================== --- llvm/trunk/include/llvm/CodeGen/MachineInstrBuilder.h (original) +++ llvm/trunk/include/llvm/CodeGen/MachineInstrBuilder.h Tue Feb 17 23:45:50 2009 @@ -38,9 +38,10 @@ const MachineInstrBuilder &addReg(unsigned RegNo, bool isDef = false, bool isImp = false, bool isKill = false, - bool isDead = false, unsigned SubReg = 0) const { + bool isDead = false, unsigned SubReg = 0, + bool isEarlyClobber = false) const { MI->addOperand(MachineOperand::CreateReg(RegNo, isDef, isImp, isKill, - isDead, SubReg)); + isDead, SubReg, isEarlyClobber)); return *this; } @@ -93,6 +94,28 @@ MI->addMemOperand(*MI->getParent()->getParent(), MMO); return *this; } + + const MachineInstrBuilder &addOperand(const MachineOperand &MO) const { + if (MO.isReg()) + return addReg(MO.getReg(), MO.isDef(), MO.isImplicit(), + MO.isKill(), MO.isDead(), MO.getSubReg(), + MO.isEarlyClobber()); + if (MO.isImm()) + return addImm(MO.getImm()); + if (MO.isFI()) + return addFrameIndex(MO.getIndex()); + if (MO.isGlobal()) + return addGlobalAddress(MO.getGlobal(), MO.getOffset()); + if (MO.isCPI()) + return addConstantPoolIndex(MO.getIndex(), MO.getOffset()); + if (MO.isSymbol()) + return addExternalSymbol(MO.getSymbolName()); + if (MO.isJTI()) + return addJumpTableIndex(MO.getIndex()); + + assert(0 && "Unknown operand for MachineInstrBuilder::AddOperand!"); + return *this; + } }; /// BuildMI - Builder interface. Specify how to create the initial instruction Modified: llvm/trunk/lib/Target/ARM/ARMInstrInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMInstrInfo.cpp?rev=64891&r1=64890&r2=64891&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMInstrInfo.cpp (original) +++ llvm/trunk/lib/Target/ARM/ARMInstrInfo.cpp Tue Feb 17 23:45:50 2009 @@ -509,20 +509,6 @@ return true; } -static const MachineInstrBuilder &ARMInstrAddOperand(MachineInstrBuilder &MIB, - MachineOperand &MO) { - if (MO.isReg()) - MIB = MIB.addReg(MO.getReg(), MO.isDef(), MO.isImplicit()); - else if (MO.isImm()) - MIB = MIB.addImm(MO.getImm()); - else if (MO.isFI()) - MIB = MIB.addFrameIndex(MO.getIndex()); - else - assert(0 && "Unknown operand for ARMInstrAddOperand!"); - - return MIB; -} - void ARMInstrInfo:: storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, unsigned SrcReg, bool isKill, int FI, @@ -567,7 +553,7 @@ MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc)).addReg(SrcReg, false, false, isKill); for (unsigned i = 0, e = Addr.size(); i != e; ++i) - MIB = ARMInstrAddOperand(MIB, Addr[i]); + MIB.addOperand(Addr[i]); NewMIs.push_back(MIB); return; } @@ -582,7 +568,7 @@ MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc)).addReg(SrcReg, false, false, isKill); for (unsigned i = 0, e = Addr.size(); i != e; ++i) - MIB = ARMInstrAddOperand(MIB, Addr[i]); + MIB.addOperand(Addr[i]); AddDefaultPred(MIB); NewMIs.push_back(MIB); return; @@ -626,7 +612,7 @@ Opc = Addr[0].isFI() ? ARM::tRestore : ARM::tLDR; MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg); for (unsigned i = 0, e = Addr.size(); i != e; ++i) - MIB = ARMInstrAddOperand(MIB, Addr[i]); + MIB.addOperand(Addr[i]); NewMIs.push_back(MIB); return; } @@ -640,7 +626,7 @@ MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg); for (unsigned i = 0, e = Addr.size(); i != e; ++i) - MIB = ARMInstrAddOperand(MIB, Addr[i]); + MIB.addOperand(Addr[i]); AddDefaultPred(MIB); NewMIs.push_back(MIB); return; Modified: llvm/trunk/lib/Target/Alpha/AlphaInstrInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Alpha/AlphaInstrInfo.cpp?rev=64891&r1=64890&r2=64891&view=diff ============================================================================== --- llvm/trunk/lib/Target/Alpha/AlphaInstrInfo.cpp (original) +++ llvm/trunk/lib/Target/Alpha/AlphaInstrInfo.cpp Tue Feb 17 23:45:50 2009 @@ -218,13 +218,8 @@ DebugLoc DL = DebugLoc::getUnknownLoc(); MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc)).addReg(SrcReg, false, false, isKill); - for (unsigned i = 0, e = Addr.size(); i != e; ++i) { - MachineOperand &MO = Addr[i]; - if (MO.isReg()) - MIB.addReg(MO.getReg(), MO.isDef(), MO.isImplicit()); - else - MIB.addImm(MO.getImm()); - } + for (unsigned i = 0, e = Addr.size(); i != e; ++i) + MIB.addOperand(Addr[i]); NewMIs.push_back(MIB); } @@ -267,13 +262,8 @@ DebugLoc DL = DebugLoc::getUnknownLoc(); MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg); - for (unsigned i = 0, e = Addr.size(); i != e; ++i) { - MachineOperand &MO = Addr[i]; - if (MO.isReg()) - MIB.addReg(MO.getReg(), MO.isDef(), MO.isImplicit()); - else - MIB.addImm(MO.getImm()); - } + for (unsigned i = 0, e = Addr.size(); i != e; ++i) + MIB.addOperand(Addr[i]); NewMIs.push_back(MIB); } Modified: llvm/trunk/lib/Target/CellSPU/SPUInstrInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CellSPU/SPUInstrInfo.cpp?rev=64891&r1=64890&r2=64891&view=diff ============================================================================== --- llvm/trunk/lib/Target/CellSPU/SPUInstrInfo.cpp (original) +++ llvm/trunk/lib/Target/CellSPU/SPUInstrInfo.cpp Tue Feb 17 23:45:50 2009 @@ -352,15 +352,8 @@ DebugLoc DL = DebugLoc::getUnknownLoc(); MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc)) .addReg(SrcReg, false, false, isKill); - for (unsigned i = 0, e = Addr.size(); i != e; ++i) { - MachineOperand &MO = Addr[i]; - if (MO.isReg()) - MIB.addReg(MO.getReg()); - else if (MO.isImm()) - MIB.addImm(MO.getImm()); - else - MIB.addFrameIndex(MO.getIndex()); - } + for (unsigned i = 0, e = Addr.size(); i != e; ++i) + MIB.addOperand(Addr[i]); NewMIs.push_back(MIB); } } @@ -434,15 +427,8 @@ } DebugLoc DL = DebugLoc::getUnknownLoc(); MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg); - for (unsigned i = 0, e = Addr.size(); i != e; ++i) { - MachineOperand &MO = Addr[i]; - if (MO.isReg()) - MIB.addReg(MO.getReg()); - else if (MO.isImm()) - MIB.addImm(MO.getImm()); - else - MIB.addFrameIndex(MO.getIndex()); - } + for (unsigned i = 0, e = Addr.size(); i != e; ++i) + MIB.addOperand(Addr[i]); NewMIs.push_back(MIB); } } Modified: llvm/trunk/lib/Target/IA64/IA64InstrInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/IA64/IA64InstrInfo.cpp?rev=64891&r1=64890&r2=64891&view=diff ============================================================================== --- llvm/trunk/lib/Target/IA64/IA64InstrInfo.cpp (original) +++ llvm/trunk/lib/Target/IA64/IA64InstrInfo.cpp Tue Feb 17 23:45:50 2009 @@ -134,15 +134,8 @@ DebugLoc DL = DebugLoc::getUnknownLoc(); MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc)); - for (unsigned i = 0, e = Addr.size(); i != e; ++i) { - MachineOperand &MO = Addr[i]; - if (MO.isReg()) - MIB.addReg(MO.getReg()); - else if (MO.isImm()) - MIB.addImm(MO.getImm()); - else - MIB.addFrameIndex(MO.getIndex()); - } + for (unsigned i = 0, e = Addr.size(); i != e; ++i) + MIB.addOperand(Addr[i]); MIB.addReg(SrcReg, false, false, isKill); NewMIs.push_back(MIB); return; @@ -193,15 +186,8 @@ DebugLoc DL = DebugLoc::getUnknownLoc(); MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg); - for (unsigned i = 0, e = Addr.size(); i != e; ++i) { - MachineOperand &MO = Addr[i]; - if (MO.isReg()) - MIB.addReg(MO.getReg()); - else if (MO.isImm()) - MIB.addImm(MO.getImm()); - else - MIB.addFrameIndex(MO.getIndex()); - } + for (unsigned i = 0, e = Addr.size(); i != e; ++i) + MIB.addOperand(Addr[i]); NewMIs.push_back(MIB); return; } Modified: llvm/trunk/lib/Target/Mips/MipsInstrInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsInstrInfo.cpp?rev=64891&r1=64890&r2=64891&view=diff ============================================================================== --- llvm/trunk/lib/Target/Mips/MipsInstrInfo.cpp (original) +++ llvm/trunk/lib/Target/Mips/MipsInstrInfo.cpp Tue Feb 17 23:45:50 2009 @@ -228,15 +228,8 @@ DebugLoc DL = DebugLoc::getUnknownLoc(); MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc)) .addReg(SrcReg, false, false, isKill); - for (unsigned i = 0, e = Addr.size(); i != e; ++i) { - MachineOperand &MO = Addr[i]; - if (MO.isReg()) - MIB.addReg(MO.getReg()); - else if (MO.isImm()) - MIB.addImm(MO.getImm()); - else - MIB.addFrameIndex(MO.getIndex()); - } + for (unsigned i = 0, e = Addr.size(); i != e; ++i) + MIB.addOperand(Addr[i]); NewMIs.push_back(MIB); return; } @@ -281,15 +274,8 @@ DebugLoc DL = DebugLoc::getUnknownLoc(); MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg); - for (unsigned i = 0, e = Addr.size(); i != e; ++i) { - MachineOperand &MO = Addr[i]; - if (MO.isReg()) - MIB.addReg(MO.getReg()); - else if (MO.isImm()) - MIB.addImm(MO.getImm()); - else - MIB.addFrameIndex(MO.getIndex()); - } + for (unsigned i = 0, e = Addr.size(); i != e; ++i) + MIB.addOperand(Addr[i]); NewMIs.push_back(MIB); return; } Modified: llvm/trunk/lib/Target/PowerPC/PPCInstrInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCInstrInfo.cpp?rev=64891&r1=64890&r2=64891&view=diff ============================================================================== --- llvm/trunk/lib/Target/PowerPC/PPCInstrInfo.cpp (original) +++ llvm/trunk/lib/Target/PowerPC/PPCInstrInfo.cpp Tue Feb 17 23:45:50 2009 @@ -511,15 +511,8 @@ } MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc)) .addReg(SrcReg, false, false, isKill); - for (unsigned i = 0, e = Addr.size(); i != e; ++i) { - MachineOperand &MO = Addr[i]; - if (MO.isReg()) - MIB.addReg(MO.getReg()); - else if (MO.isImm()) - MIB.addImm(MO.getImm()); - else - MIB.addFrameIndex(MO.getIndex()); - } + for (unsigned i = 0, e = Addr.size(); i != e; ++i) + MIB.addOperand(Addr[i]); NewMIs.push_back(MIB); return; } @@ -650,15 +643,8 @@ } DebugLoc DL = DebugLoc::getUnknownLoc(); MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg); - for (unsigned i = 0, e = Addr.size(); i != e; ++i) { - MachineOperand &MO = Addr[i]; - if (MO.isReg()) - MIB.addReg(MO.getReg()); - else if (MO.isImm()) - MIB.addImm(MO.getImm()); - else - MIB.addFrameIndex(MO.getIndex()); - } + for (unsigned i = 0, e = Addr.size(); i != e; ++i) + MIB.addOperand(Addr[i]); NewMIs.push_back(MIB); return; } Modified: llvm/trunk/lib/Target/Sparc/SparcInstrInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/SparcInstrInfo.cpp?rev=64891&r1=64890&r2=64891&view=diff ============================================================================== --- llvm/trunk/lib/Target/Sparc/SparcInstrInfo.cpp (original) +++ llvm/trunk/lib/Target/Sparc/SparcInstrInfo.cpp Tue Feb 17 23:45:50 2009 @@ -179,17 +179,8 @@ else assert(0 && "Can't load this register"); MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc)); - for (unsigned i = 0, e = Addr.size(); i != e; ++i) { - MachineOperand &MO = Addr[i]; - if (MO.isReg()) - MIB.addReg(MO.getReg()); - else if (MO.isImm()) - MIB.addImm(MO.getImm()); - else { - assert(MO.isFI()); - MIB.addFrameIndex(MO.getIndex()); - } - } + for (unsigned i = 0, e = Addr.size(); i != e; ++i) + MIB.addOperand(Addr[i]); MIB.addReg(SrcReg, false, false, isKill); NewMIs.push_back(MIB); return; @@ -227,17 +218,8 @@ assert(0 && "Can't load this register"); DebugLoc DL = DebugLoc::getUnknownLoc(); MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg); - for (unsigned i = 0, e = Addr.size(); i != e; ++i) { - MachineOperand &MO = Addr[i]; - if (MO.isReg()) - MIB.addReg(MO.getReg()); - else if (MO.isImm()) - MIB.addImm(MO.getImm()); - else { - assert(MO.isFI()); - MIB.addFrameIndex(MO.getIndex()); - } - } + for (unsigned i = 0, e = Addr.size(); i != e; ++i) + MIB.addOperand(Addr[i]); NewMIs.push_back(MIB); return; } Modified: llvm/trunk/lib/Target/X86/X86InstrInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrInfo.cpp?rev=64891&r1=64890&r2=64891&view=diff ============================================================================== --- llvm/trunk/lib/Target/X86/X86InstrInfo.cpp (original) +++ llvm/trunk/lib/Target/X86/X86InstrInfo.cpp Tue Feb 17 23:45:50 2009 @@ -1603,29 +1603,6 @@ return Count; } -static const MachineInstrBuilder &X86InstrAddOperand(MachineInstrBuilder &MIB, - const MachineOperand &MO) { - if (MO.isReg()) - MIB = MIB.addReg(MO.getReg(), MO.isDef(), MO.isImplicit(), - MO.isKill(), MO.isDead(), MO.getSubReg()); - else if (MO.isImm()) - MIB = MIB.addImm(MO.getImm()); - else if (MO.isFI()) - MIB = MIB.addFrameIndex(MO.getIndex()); - else if (MO.isGlobal()) - MIB = MIB.addGlobalAddress(MO.getGlobal(), MO.getOffset()); - else if (MO.isCPI()) - MIB = MIB.addConstantPoolIndex(MO.getIndex(), MO.getOffset()); - else if (MO.isJTI()) - MIB = MIB.addJumpTableIndex(MO.getIndex()); - else if (MO.isSymbol()) - MIB = MIB.addExternalSymbol(MO.getSymbolName()); - else - assert(0 && "Unknown operand for X86InstrAddOperand!"); - - return MIB; -} - unsigned X86InstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, @@ -1855,7 +1832,7 @@ DebugLoc DL = DebugLoc::getUnknownLoc(); MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc)); for (unsigned i = 0, e = Addr.size(); i != e; ++i) - MIB = X86InstrAddOperand(MIB, Addr[i]); + MIB.addOperand(Addr[i]); MIB.addReg(SrcReg, false, false, isKill); NewMIs.push_back(MIB); } @@ -1921,7 +1898,7 @@ DebugLoc DL = DebugLoc::getUnknownLoc(); MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg); for (unsigned i = 0, e = Addr.size(); i != e; ++i) - MIB = X86InstrAddOperand(MIB, Addr[i]); + MIB.addOperand(Addr[i]); NewMIs.push_back(MIB); } @@ -1981,7 +1958,7 @@ MachineInstrBuilder MIB(NewMI); unsigned NumAddrOps = MOs.size(); for (unsigned i = 0; i != NumAddrOps; ++i) - MIB = X86InstrAddOperand(MIB, MOs[i]); + MIB.addOperand(MOs[i]); if (NumAddrOps < 4) // FrameIndex only MIB.addImm(1).addReg(0).addImm(0); @@ -1989,11 +1966,11 @@ unsigned NumOps = MI->getDesc().getNumOperands()-2; for (unsigned i = 0; i != NumOps; ++i) { MachineOperand &MO = MI->getOperand(i+2); - MIB = X86InstrAddOperand(MIB, MO); + MIB.addOperand(MO); } for (unsigned i = NumOps+2, e = MI->getNumOperands(); i != e; ++i) { MachineOperand &MO = MI->getOperand(i); - MIB = X86InstrAddOperand(MIB, MO); + MIB.addOperand(MO); } return MIB; } @@ -2012,11 +1989,11 @@ assert(MO.isReg() && "Expected to fold into reg operand!"); unsigned NumAddrOps = MOs.size(); for (unsigned i = 0; i != NumAddrOps; ++i) - MIB = X86InstrAddOperand(MIB, MOs[i]); + MIB.addOperand(MOs[i]); if (NumAddrOps < 4) // FrameIndex only MIB.addImm(1).addReg(0).addImm(0); } else { - MIB = X86InstrAddOperand(MIB, MO); + MIB.addOperand(MO); } } return MIB; @@ -2030,7 +2007,7 @@ unsigned NumAddrOps = MOs.size(); for (unsigned i = 0; i != NumAddrOps; ++i) - MIB = X86InstrAddOperand(MIB, MOs[i]); + MIB.addOperand(MOs[i]); if (NumAddrOps < 4) // FrameIndex only MIB.addImm(1).addReg(0).addImm(0); return MIB.addImm(0); @@ -2343,11 +2320,11 @@ if (FoldedStore) MIB.addReg(Reg, true); for (unsigned i = 0, e = BeforeOps.size(); i != e; ++i) - MIB = X86InstrAddOperand(MIB, BeforeOps[i]); + MIB.addOperand(BeforeOps[i]); if (FoldedLoad) MIB.addReg(Reg); for (unsigned i = 0, e = AfterOps.size(); i != e; ++i) - MIB = X86InstrAddOperand(MIB, AfterOps[i]); + MIB.addOperand(AfterOps[i]); for (unsigned i = 0, e = ImpOps.size(); i != e; ++i) { MachineOperand &MO = ImpOps[i]; MIB.addReg(MO.getReg(), MO.isDef(), true, MO.isKill(), MO.isDead()); From evan.cheng at apple.com Tue Feb 17 23:55:35 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 17 Feb 2009 21:55:35 -0800 Subject: [llvm-commits] [llvm] r64877 - in /llvm/trunk: lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp test/CodeGen/X86/cstring.ll In-Reply-To: <27A4E95A-B7DA-4385-9739-6239A4837A40@apple.com> References: <200902180219.n1I2JrjZ030169@zion.cs.uiuc.edu> <3C282F1A-29E3-4412-827D-473C0C637C7F@apple.com> <27A4E95A-B7DA-4385-9739-6239A4837A40@apple.com> Message-ID: <67EABC6B-468D-48DD-BACC-12C0783416CD@apple.com> On Feb 17, 2009, at 8:53 PM, Chris Lattner wrote: > > On Feb 17, 2009, at 8:52 PM, Evan Cheng wrote: > >> >> On Feb 17, 2009, at 7:48 PM, Chris Lattner wrote: >> >>> >>> On Feb 17, 2009, at 6:19 PM, Evan Cheng wrote: >>> >>>> Author: evancheng >>>> Date: Tue Feb 17 20:19:52 2009 >>>> New Revision: 64877 >>>> >>>> URL: http://llvm.org/viewvc/llvm-project?rev=64877&view=rev >>>> Log: >>>> GV with null value initializer shouldn't go to BSS if it's meant >>>> for >>>> a mergeable strings section. Currently it only checks for Darwin. >>>> Someone else please check if it should apply to other targets as >>>> well. >>> >>> Evan, this seems like the wrong fix. What *requires* an empty >>> string >>> to go into the cstring section? If there is some semantics that >>> require it, then whatever produces the llvm global should set the >>> section of the global to the cstring section explicitly. >> >> I don't see why this is wrong/ Per revision 63142,target asm info >> has already decided this particular GV should go into cstring. But >> the asm printer then decided to put it in BSS (which means it >> cannot be coalesced) because the initializer is empty. This patch >> makes sure asm printer doesn't try to out smart itself. > > Why is this important? rdar://6479858. It's a minor size win, but more importantly it avoids linker warning. That means fewer complaints about llvm-gcc (and it has been reported at least twice so far at Apple). Evan > > -Chris > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090217/6c236ae7/attachment.html From clattner at apple.com Wed Feb 18 00:07:37 2009 From: clattner at apple.com (Chris Lattner) Date: Tue, 17 Feb 2009 22:07:37 -0800 Subject: [llvm-commits] [llvm] r64877 - in /llvm/trunk: lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp test/CodeGen/X86/cstring.ll In-Reply-To: <67EABC6B-468D-48DD-BACC-12C0783416CD@apple.com> References: <200902180219.n1I2JrjZ030169@zion.cs.uiuc.edu> <3C282F1A-29E3-4412-827D-473C0C637C7F@apple.com> <27A4E95A-B7DA-4385-9739-6239A4837A40@apple.com> <67EABC6B-468D-48DD-BACC-12C0783416CD@apple.com> Message-ID: On Feb 17, 2009, at 9:55 PM, Evan Cheng wrote: >>>> Evan, this seems like the wrong fix. What *requires* an empty >>>> string >>>> to go into the cstring section? If there is some semantics that >>>> require it, then whatever produces the llvm global should set the >>>> section of the global to the cstring section explicitly. >>> >>> I don't see why this is wrong/ Per revision 63142,target asm info >>> has already decided this particular GV should go into cstring. But >>> the asm printer then decided to put it in BSS (which means it >>> cannot be coalesced) because the initializer is empty. This patch >>> makes sure asm printer doesn't try to out smart itself. >> >> Why is this important? > > rdar://6479858. It's a minor size win, but more importantly it > avoids linker warning. That means fewer complaints about llvm-gcc > (and it has been reported at least twice so far at Apple). Then this is not an optimization, this is a semantic property. Whatever is creating that literal string should pin it in the section that it requires it to be in. -Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090217/f815e850/attachment.html From evan.cheng at apple.com Wed Feb 18 01:08:43 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 17 Feb 2009 23:08:43 -0800 Subject: [llvm-commits] [llvm] r64877 - in /llvm/trunk: lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp test/CodeGen/X86/cstring.ll In-Reply-To: References: <200902180219.n1I2JrjZ030169@zion.cs.uiuc.edu> <3C282F1A-29E3-4412-827D-473C0C637C7F@apple.com> <27A4E95A-B7DA-4385-9739-6239A4837A40@apple.com> <67EABC6B-468D-48DD-BACC-12C0783416CD@apple.com> Message-ID: On Feb 17, 2009, at 10:07 PM, Chris Lattner wrote: > On Feb 17, 2009, at 9:55 PM, Evan Cheng wrote: >>>>> Evan, this seems like the wrong fix. What *requires* an empty >>>>> string >>>>> to go into the cstring section? If there is some semantics that >>>>> require it, then whatever produces the llvm global should set the >>>>> section of the global to the cstring section explicitly. >>>> >>>> I don't see why this is wrong/ Per revision 63142,target asm info >>>> has already decided this particular GV should go into cstring. >>>> But the asm printer then decided to put it in BSS (which means it >>>> cannot be coalesced) because the initializer is empty. This patch >>>> makes sure asm printer doesn't try to out smart itself. >>> >>> Why is this important? >> >> rdar://6479858. It's a minor size win, but more importantly it >> avoids linker warning. That means fewer complaints about llvm-gcc >> (and it has been reported at least twice so far at Apple). > > Then this is not an optimization, this is a semantic property. > Whatever is creating that literal string should pin it in the > section that it requires it to be in. I don't understand your objection. What's wrong with putting constant array of i8 terminated with zero into cstring sections? Do we need to have the frontend pre-determine the sections for all of these strings? Evan > > -Chris > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090217/dc3d0d59/attachment.html From baldrick at free.fr Wed Feb 18 01:30:11 2009 From: baldrick at free.fr (Duncan Sands) Date: Wed, 18 Feb 2009 08:30:11 +0100 Subject: [llvm-commits] =?iso-8859-1?q?=5Bllvm=5D_r64827_-_in_/llvm/trunk?= =?iso-8859-1?q?=3A_include/llvm/CodeGen/SelectionDAG=2Eh=09include/llvm/C?= =?iso-8859-1?q?odeGen/SelectionDAGNodes=2Eh_lib/CodeGen/SelectionDAG/DAGC?= =?iso-8859-1?q?ombiner=2Ecpp_lib/CodeGen/SelectionDAG/LegalizeDAG=2Ecpp_l?= =?iso-8859-1?q?ib/CodeGen/SelectionDAG/LegalizeIntegerTypes=2Ecpp_lib/Cod?= =?iso-8859-1?q?eGen/SelectionDAG/LegalizeVectorTypes=2Ecpp_lib/CodeGen/Se?= =?iso-8859-1?q?lectionDAG/SelectionDAG=2Ecpp_lib/CodeGen/SelectionDAG/Sel?= =?iso-8859-1?q?ectionDAGBuild=2Ecpp_lib/Target/PowerPC/PPCISelLowering=2E?= =?iso-8859-1?q?cpp=09lib/Target/X86/X86ISelLowering=2Ecpp?= In-Reply-To: <60C9CCC9-2E35-43C1-8782-514D4C522D8C@apple.com> References: <200902172215.n1HMF5P2022402@zion.cs.uiuc.edu> <200902172320.33140.baldrick@free.fr> <60C9CCC9-2E35-43C1-8782-514D4C522D8C@apple.com> Message-ID: <200902180830.12229.baldrick@free.fr> Hi Dale, > > the last time I read the subversion book, it recommended not doing > > this. > > They instead advised having a script that rejects a commit if it > > introduces > > trailing whitespace. > > Whoa! There is absolutely no reason (except pedantry) to disallow > this, and everybody's time would be better spent working on things > that actually matter. from the subversion manual: "While hook scripts can do almost anything, there is one dimension in which hook script authors should show restraint: do not modify a commit transaction using hook scripts. While it might be tempting to use hook scripts to automatically correct errors, shortcomings, or policy violations present in the files being committed, doing so can cause problems. Subversion keeps client-side caches of certain bits of repository data, and if you change a commit transaction in this way, those caches become indetectably stale. This inconsistency can lead to surprising and unexpected behavior. Instead of modifying the transaction, you should simply validate the transaction in the pre-commit hook and reject the commit if it does not meet the desired requirements. As a bonus, your users will learn the value of careful, compliance-minded work habits." Ciao, Duncan. From nicholas at mxc.ca Wed Feb 18 01:40:13 2009 From: nicholas at mxc.ca (Nick Lewycky) Date: Tue, 17 Feb 2009 23:40:13 -0800 Subject: [llvm-commits] make utils/GenLibDeps.pl ignore 'D' lines from nm In-Reply-To: <200902161127.41418.baldrick@free.fr> References: <4997D42C.9060900@mxc.ca> <200902151004.12829.baldrick@free.fr> <4998A27E.1090905@mxc.ca> <200902161127.41418.baldrick@free.fr> Message-ID: <499BBB5D.2030604@mxc.ca> Duncan Sands wrote: > Hi Nick, > >>> How about just ignoring __dso_handle? This might be enough to work >>> around the gold bug. I don't much like the idea of ignoring all 'D' >>> symbols (externally visible globals with initial value). >> That works for me. I've attached the patch, let me know if it works for >> you and I'll commit it! > > thanks for doing this. On my system I also have to ignore > '__stack_chk_fail_local'. Revised patch attached. Erk! I don't really like playing whack-a-mole. Just to be clear, this is all just a work-around the fact that gold is miscompiling (well, mislinking) the binaries, right? Nick From resistor at mac.com Wed Feb 18 01:50:22 2009 From: resistor at mac.com (Owen Anderson) Date: Wed, 18 Feb 2009 07:50:22 -0000 Subject: [llvm-commits] [llvm] r64904 - /llvm/trunk/test/Transforms/GVN/2009-02-17-LoadPRECrash.ll Message-ID: <200902180750.n1I7oMWF022640@zion.cs.uiuc.edu> Author: resistor Date: Wed Feb 18 01:50:22 2009 New Revision: 64904 URL: http://llvm.org/viewvc/llvm-project?rev=64904&view=rev Log: Add a test for r61358, which I forgot to add way back when. Added: llvm/trunk/test/Transforms/GVN/2009-02-17-LoadPRECrash.ll Added: llvm/trunk/test/Transforms/GVN/2009-02-17-LoadPRECrash.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/2009-02-17-LoadPRECrash.ll?rev=64904&view=auto ============================================================================== --- llvm/trunk/test/Transforms/GVN/2009-02-17-LoadPRECrash.ll (added) +++ llvm/trunk/test/Transforms/GVN/2009-02-17-LoadPRECrash.ll Wed Feb 18 01:50:22 2009 @@ -0,0 +1,193 @@ +; RUN: llvm-as < %s | opt -gvn -enable-load-pre -disable-output + + %struct.VEC_rtx_base = type { i32, i32, [1 x %struct.rtx_def*] } + %struct.VEC_rtx_gc = type { %struct.VEC_rtx_base } + %struct.block_symbol = type { [3 x %struct.cgraph_rtl_info], %struct.object_block*, i64 } + %struct.cgraph_rtl_info = type { i32 } + %struct.object_block = type { %struct.section*, i32, i64, %struct.VEC_rtx_gc*, %struct.VEC_rtx_gc* } + %struct.rtvec_def = type { i32, [1 x %struct.rtx_def*] } + %struct.rtx_def = type { i16, i8, i8, %struct.u } + %struct.section = type { %struct.unnamed_section } + %struct.u = type { %struct.block_symbol } + %struct.unnamed_section = type { %struct.cgraph_rtl_info, void (i8*)*, i8*, %struct.section* } + +declare %struct.rtvec_def* @gen_rtvec(i32, ...) + +declare %struct.rtx_def* @plus_constant(%struct.rtx_def*, i64) + +declare %struct.rtx_def* @gen_rtx_fmt_Ei(i32, i32, %struct.rtvec_def*, i32) + +declare i32 @local_symbolic_operand(%struct.rtx_def*, i32) + +define %struct.rtx_def* @legitimize_pic_address(%struct.rtx_def* %orig, %struct.rtx_def* %reg) nounwind { +entry: + %addr = alloca %struct.rtx_def* ; <%struct.rtx_def**> [#uses=5] + %iftmp.1532 = alloca %struct.rtx_def* ; <%struct.rtx_def**> [#uses=3] + store %struct.rtx_def* %orig, %struct.rtx_def** null + %0 = load %struct.rtx_def** null, align 4 ; <%struct.rtx_def*> [#uses=0] + br i1 false, label %bb96, label %bb59 + +bb59: ; preds = %entry + %1 = load %struct.rtx_def** %addr, align 4 ; <%struct.rtx_def*> [#uses=1] + %2 = call i32 @local_symbolic_operand(%struct.rtx_def* %1, i32 0) nounwind ; [#uses=0] + br i1 false, label %bb96, label %bb63 + +bb63: ; preds = %bb59 + br i1 false, label %bb64, label %bb74 + +bb64: ; preds = %bb63 + br i1 false, label %bb72, label %bb65 + +bb65: ; preds = %bb64 + br label %bb72 + +bb72: ; preds = %bb65, %bb64 + br label %bb74 + +bb74: ; preds = %bb72, %bb63 + br i1 false, label %bb75, label %bb76 + +bb75: ; preds = %bb74 + br label %bb76 + +bb76: ; preds = %bb75, %bb74 + br i1 false, label %bb77, label %bb84 + +bb77: ; preds = %bb76 + %3 = getelementptr [1 x %struct.cgraph_rtl_info]* null, i32 0, i32 0 ; <%struct.cgraph_rtl_info*> [#uses=0] + unreachable + +bb84: ; preds = %bb76 + br i1 false, label %bb85, label %bb86 + +bb85: ; preds = %bb84 + br label %bb87 + +bb86: ; preds = %bb84 + br label %bb87 + +bb87: ; preds = %bb86, %bb85 + %4 = call %struct.rtx_def* @gen_rtx_fmt_Ei(i32 16, i32 0, %struct.rtvec_def* null, i32 1) nounwind ; <%struct.rtx_def*> [#uses=0] + br i1 false, label %bb89, label %bb90 + +bb89: ; preds = %bb87 + br label %bb91 + +bb90: ; preds = %bb87 + br label %bb91 + +bb91: ; preds = %bb90, %bb89 + br i1 false, label %bb92, label %bb93 + +bb92: ; preds = %bb91 + br label %bb94 + +bb93: ; preds = %bb91 + br label %bb94 + +bb94: ; preds = %bb93, %bb92 + unreachable + +bb96: ; preds = %bb59, %entry + %5 = load %struct.rtx_def** %addr, align 4 ; <%struct.rtx_def*> [#uses=1] + %6 = getelementptr %struct.rtx_def* %5, i32 0, i32 0 ; [#uses=1] + %7 = load i16* %6, align 2 ; [#uses=0] + br i1 false, label %bb147, label %bb97 + +bb97: ; preds = %bb96 + %8 = load %struct.rtx_def** %addr, align 4 ; <%struct.rtx_def*> [#uses=0] + br i1 false, label %bb147, label %bb99 + +bb99: ; preds = %bb97 + unreachable + +bb147: ; preds = %bb97, %bb96 + %9 = load %struct.rtx_def** %addr, align 4 ; <%struct.rtx_def*> [#uses=1] + %10 = getelementptr %struct.rtx_def* %9, i32 0, i32 0 ; [#uses=1] + %11 = load i16* %10, align 2 ; [#uses=0] + br i1 false, label %bb164, label %bb148 + +bb148: ; preds = %bb147 + br i1 false, label %bb164, label %bb149 + +bb149: ; preds = %bb148 + br i1 false, label %bb150, label %bb152 + +bb150: ; preds = %bb149 + unreachable + +bb152: ; preds = %bb149 + br label %bb164 + +bb164: ; preds = %bb152, %bb148, %bb147 + %12 = getelementptr [1 x %struct.cgraph_rtl_info]* null, i32 0, i32 1 ; <%struct.cgraph_rtl_info*> [#uses=0] + br i1 false, label %bb165, label %bb166 + +bb165: ; preds = %bb164 + br label %bb167 + +bb166: ; preds = %bb164 + br label %bb167 + +bb167: ; preds = %bb166, %bb165 + br i1 false, label %bb211, label %bb168 + +bb168: ; preds = %bb167 + br i1 false, label %bb211, label %bb170 + +bb170: ; preds = %bb168 + br i1 false, label %bb172, label %bb181 + +bb172: ; preds = %bb170 + br i1 false, label %bb179, label %bb174 + +bb174: ; preds = %bb172 + br i1 false, label %bb177, label %bb175 + +bb175: ; preds = %bb174 + br i1 false, label %bb177, label %bb176 + +bb176: ; preds = %bb175 + br label %bb178 + +bb177: ; preds = %bb175, %bb174 + br label %bb178 + +bb178: ; preds = %bb177, %bb176 + br label %bb180 + +bb179: ; preds = %bb172 + br label %bb180 + +bb180: ; preds = %bb179, %bb178 + br label %bb181 + +bb181: ; preds = %bb180, %bb170 + %13 = call %struct.rtvec_def* (i32, ...)* @gen_rtvec(i32 1, %struct.rtx_def* null) nounwind ; <%struct.rtvec_def*> [#uses=0] + unreachable + +bb211: ; preds = %bb168, %bb167 + %14 = load %struct.rtx_def** %addr, align 4 ; <%struct.rtx_def*> [#uses=0] + %15 = getelementptr [1 x %struct.cgraph_rtl_info]* null, i32 0, i32 0 ; <%struct.cgraph_rtl_info*> [#uses=0] + store %struct.rtx_def* null, %struct.rtx_def** null, align 4 + br i1 false, label %bb212, label %bb213 + +bb212: ; preds = %bb211 + store %struct.rtx_def* null, %struct.rtx_def** %iftmp.1532, align 4 + br label %bb214 + +bb213: ; preds = %bb211 + store %struct.rtx_def* null, %struct.rtx_def** %iftmp.1532, align 4 + br label %bb214 + +bb214: ; preds = %bb213, %bb212 + %16 = bitcast %struct.block_symbol* null to [1 x %struct.cgraph_rtl_info]* ; <[1 x %struct.cgraph_rtl_info]*> [#uses=1] + %17 = getelementptr [1 x %struct.cgraph_rtl_info]* %16, i32 0, i32 1 ; <%struct.cgraph_rtl_info*> [#uses=0] + %18 = load %struct.rtx_def** %iftmp.1532, align 4 ; <%struct.rtx_def*> [#uses=0] + %19 = getelementptr %struct.rtx_def* null, i32 0, i32 3 ; <%struct.u*> [#uses=1] + %20 = getelementptr %struct.u* %19, i32 0, i32 0 ; <%struct.block_symbol*> [#uses=1] + %21 = bitcast %struct.block_symbol* %20 to [1 x i64]* ; <[1 x i64]*> [#uses=1] + %22 = getelementptr [1 x i64]* %21, i32 0, i32 0 ; [#uses=0] + %23 = call %struct.rtx_def* @plus_constant(%struct.rtx_def* null, i64 0) nounwind ; <%struct.rtx_def*> [#uses=0] + unreachable +} From baldrick at free.fr Wed Feb 18 01:50:18 2009 From: baldrick at free.fr (Duncan Sands) Date: Wed, 18 Feb 2009 08:50:18 +0100 Subject: [llvm-commits] make utils/GenLibDeps.pl ignore 'D' lines from nm In-Reply-To: <499BBB5D.2030604@mxc.ca> References: <4997D42C.9060900@mxc.ca> <200902161127.41418.baldrick@free.fr> <499BBB5D.2030604@mxc.ca> Message-ID: <200902180850.19139.baldrick@free.fr> > Just to be clear, this is all just a work-around the fact that gold is > miscompiling (well, mislinking) the binaries, right? Yes. It's possible that the gold people think it's not a bug of course, but they haven't said so yet. Ciao, Duncan. From rafael.espindola at gmail.com Wed Feb 18 02:30:19 2009 From: rafael.espindola at gmail.com (Rafael Espindola) Date: Wed, 18 Feb 2009 08:30:19 -0000 Subject: [llvm-commits] [llvm] r64905 - /llvm/trunk/tools/gold/gold-plugin.cpp Message-ID: <200902180830.n1I8UJhE024107@zion.cs.uiuc.edu> Author: rafael Date: Wed Feb 18 02:30:15 2009 New Revision: 64905 URL: http://llvm.org/viewvc/llvm-project?rev=64905&view=rev Log: fix style Modified: llvm/trunk/tools/gold/gold-plugin.cpp Modified: llvm/trunk/tools/gold/gold-plugin.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=64905&r1=64904&r2=64905&view=diff ============================================================================== --- llvm/trunk/tools/gold/gold-plugin.cpp (original) +++ llvm/trunk/tools/gold/gold-plugin.cpp Wed Feb 18 02:30:15 2009 @@ -142,13 +142,11 @@ } } - if (!registeredClaimFile) - { + if (!registeredClaimFile) { (*message)(LDPL_ERROR, "register_claim_file not passed to LLVMgold."); return LDPS_ERR; } - if (!add_symbols) - { + if (!add_symbols) { (*message)(LDPL_ERROR, "add_symbols not passed to LLVMgold."); return LDPS_ERR; } From natebegeman at mac.com Wed Feb 18 02:31:03 2009 From: natebegeman at mac.com (Nate Begeman) Date: Wed, 18 Feb 2009 08:31:03 -0000 Subject: [llvm-commits] [llvm] r64906 - in /llvm/trunk: include/llvm/CodeGen/MachineCodeEmitter.h include/llvm/ExecutionEngine/ExecutionEngine.h include/llvm/ExecutionEngine/JITMemoryManager.h include/llvm/Target/TargetJITInfo.h lib/CodeGen/ELFWriter.cpp lib/CodeGen/MachOWriter.cpp lib/ExecutionEngine/ExecutionEngine.cpp lib/ExecutionEngine/JIT/JIT.cpp lib/ExecutionEngine/JIT/JIT.h lib/ExecutionEngine/JIT/JITEmitter.cpp lib/ExecutionEngine/JIT/JITMemoryManager.cpp lib/Target/X86/X86JITInfo.cpp lib/Target/X86/X86JITInfo.h Message-ID: <200902180831.n1I8V36s024152@zion.cs.uiuc.edu> Author: sampo Date: Wed Feb 18 02:31:02 2009 New Revision: 64906 URL: http://llvm.org/viewvc/llvm-project?rev=64906&view=rev Log: Add support to the JIT for true non-lazy operation. When a call to a function that has not been JIT'd yet, the callee is put on a list of pending functions to JIT. The call is directed through a stub, which is updated with the address of the function after it has been JIT'd. A new interface for allocating and updating empty stubs is provided. Add support for removing the ModuleProvider the JIT was created with, which would otherwise invalidate the JIT's PassManager, which is initialized with the ModuleProvider's Module. Add support under a new ExecutionEngine flag for emitting the infomration necessary to update Function and GlobalVariable stubs after JITing them, by recording the address of the stub and the name of the GlobalValue. This allows code to be copied from one address space to another, where libraries may live at different virtual addresses, and have the stubs updated with their new correct target addresses. Modified: llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h llvm/trunk/include/llvm/ExecutionEngine/JITMemoryManager.h llvm/trunk/include/llvm/Target/TargetJITInfo.h llvm/trunk/lib/CodeGen/ELFWriter.cpp llvm/trunk/lib/CodeGen/MachOWriter.cpp llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp llvm/trunk/lib/ExecutionEngine/JIT/JIT.h llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp llvm/trunk/lib/Target/X86/X86JITInfo.cpp llvm/trunk/lib/Target/X86/X86JITInfo.h Modified: llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h?rev=64906&r1=64905&r2=64906&view=diff ============================================================================== --- llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h (original) +++ llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h Wed Feb 18 02:31:02 2009 @@ -82,6 +82,13 @@ virtual void startGVStub(const GlobalValue* GV, unsigned StubSize, unsigned Alignment = 1) = 0; + /// startGVStub - This callback is invoked when the JIT needs the address of a + /// GV (e.g. function) that has not been code generated yet. Buffer points to + /// memory already allocated for this stub. + /// + virtual void startGVStub(const GlobalValue* GV, void *Buffer, + unsigned StubSize) = 0; + /// finishGVStub - This callback is invoked to terminate a GV stub. /// virtual void *finishGVStub(const GlobalValue* F) = 0; Modified: llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h?rev=64906&r1=64905&r2=64906&view=diff ============================================================================== --- llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h (original) +++ llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h Wed Feb 18 02:31:02 2009 @@ -66,6 +66,7 @@ bool LazyCompilationDisabled; bool GVCompilationDisabled; bool SymbolSearchingDisabled; + bool DlsymStubsEnabled; protected: /// Modules - This is a list of ModuleProvider's that we are JIT'ing from. We @@ -288,6 +289,13 @@ return SymbolSearchingDisabled; } + /// EnableDlsymStubs - + void EnableDlsymStubs(bool Enabled = true) { + DlsymStubsEnabled = Enabled; + } + bool areDlsymStubsEnabled() const { + return DlsymStubsEnabled; + } /// InstallLazyFunctionCreator - If an unknown function is needed, the /// specified function pointer is invoked to create it. If it returns null, Modified: llvm/trunk/include/llvm/ExecutionEngine/JITMemoryManager.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/JITMemoryManager.h?rev=64906&r1=64905&r2=64906&view=diff ============================================================================== --- llvm/trunk/include/llvm/ExecutionEngine/JITMemoryManager.h (original) +++ llvm/trunk/include/llvm/ExecutionEngine/JITMemoryManager.h Wed Feb 18 02:31:02 2009 @@ -62,6 +62,17 @@ /// return a pointer to its base. virtual unsigned char *getGOTBase() const = 0; + /// SetDlsymTable - If the JIT must be able to relocate stubs after they have + /// been emitted, potentially because they are being copied to a process + /// where external symbols live at different addresses than in the JITing + /// process, allocate a table with sufficient information to do so. + virtual void SetDlsymTable(void *ptr) = 0; + + /// getDlsymTable - If this is managing a table of entries so that stubs to + /// external symbols can be later relocated, this method should return a + /// pointer to it. + virtual void *getDlsymTable() const = 0; + /// NeedsExactSize - If the memory manager requires to know the size of the /// objects to be emitted bool NeedsExactSize() const { Modified: llvm/trunk/include/llvm/Target/TargetJITInfo.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetJITInfo.h?rev=64906&r1=64905&r2=64906&view=diff ============================================================================== --- llvm/trunk/include/llvm/Target/TargetJITInfo.h (original) +++ llvm/trunk/include/llvm/Target/TargetJITInfo.h Wed Feb 18 02:31:02 2009 @@ -56,6 +56,14 @@ assert(0 && "This target doesn't implement emitFunctionStub!"); return 0; } + + /// emitFunctionStubAtAddr - Use the specified MachineCodeEmitter object to + /// emit a small native function that simply calls Fn. Emit the stub into + /// the supplied buffer. + virtual void emitFunctionStubAtAddr(const Function* F, void *Fn, + void *Buffer, MachineCodeEmitter &MCE) { + assert(0 && "This target doesn't implement emitFunctionStubAtAddr!"); + } /// getPICJumpTableEntry - Returns the value of the jumptable entry for the /// specific basic block. Modified: llvm/trunk/lib/CodeGen/ELFWriter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ELFWriter.cpp?rev=64906&r1=64905&r2=64906&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/ELFWriter.cpp (original) +++ llvm/trunk/lib/CodeGen/ELFWriter.cpp Wed Feb 18 02:31:02 2009 @@ -121,6 +121,10 @@ assert(0 && "JIT specific function called!"); abort(); } + void startGVStub(const GlobalValue* F, void *Buffer, unsigned StubSize) { + assert(0 && "JIT specific function called!"); + abort(); + } void *finishGVStub(const GlobalValue *F) { assert(0 && "JIT specific function called!"); abort(); Modified: llvm/trunk/lib/CodeGen/MachOWriter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachOWriter.cpp?rev=64906&r1=64905&r2=64906&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/MachOWriter.cpp (original) +++ llvm/trunk/lib/CodeGen/MachOWriter.cpp Wed Feb 18 02:31:02 2009 @@ -147,6 +147,11 @@ assert(0 && "JIT specific function called!"); abort(); } + virtual void startGVStub(const GlobalValue* F, void *Buffer, + unsigned StubSize) { + assert(0 && "JIT specific function called!"); + abort(); + } virtual void *finishGVStub(const GlobalValue* F) { assert(0 && "JIT specific function called!"); abort(); Modified: llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp?rev=64906&r1=64905&r2=64906&view=diff ============================================================================== --- llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp (original) +++ llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp Wed Feb 18 02:31:02 2009 @@ -42,6 +42,7 @@ LazyCompilationDisabled = false; GVCompilationDisabled = false; SymbolSearchingDisabled = false; + DlsymStubsEnabled = false; Modules.push_back(P); assert(P && "ModuleProvider is null?"); } Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp?rev=64906&r1=64905&r2=64906&view=diff ============================================================================== --- llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp (original) +++ llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp Wed Feb 18 02:31:02 2009 @@ -289,11 +289,28 @@ Module *result = ExecutionEngine::removeModuleProvider(MP, E); MutexGuard locked(lock); - if (Modules.empty()) { + + if (jitstate->getMP() == MP) { delete jitstate; jitstate = 0; } + if (!jitstate && !Modules.empty()) { + jitstate = new JITState(Modules[0]); + + FunctionPassManager &PM = jitstate->getPM(locked); + PM.add(new TargetData(*TM.getTargetData())); + + // Turn the machine code intermediate representation into bytes in memory + // that may be executed. + if (TM.addPassesToEmitMachineCode(PM, *MCE, false /*fast*/)) { + cerr << "Target does not support machine code emission!\n"; + abort(); + } + + // Initialize passes. + PM.doInitialization(); + } return result; } @@ -304,10 +321,28 @@ ExecutionEngine::deleteModuleProvider(MP, E); MutexGuard locked(lock); - if (Modules.empty()) { + + if (jitstate->getMP() == MP) { delete jitstate; jitstate = 0; } + + if (!jitstate && !Modules.empty()) { + jitstate = new JITState(Modules[0]); + + FunctionPassManager &PM = jitstate->getPM(locked); + PM.add(new TargetData(*TM.getTargetData())); + + // Turn the machine code intermediate representation into bytes in memory + // that may be executed. + if (TM.addPassesToEmitMachineCode(PM, *MCE, false /*fast*/)) { + cerr << "Target does not support machine code emission!\n"; + abort(); + } + + // Initialize passes. + PM.doInitialization(); + } } /// run - Start execution with the specified function and arguments. @@ -488,14 +523,26 @@ jitstate->getPM(locked).run(*F); isAlreadyCodeGenerating = false; - // If the function referred to a global variable that had not yet been - // emitted, it allocates memory for the global, but doesn't emit it yet. Emit - // all of these globals now. - while (!jitstate->getPendingGlobals(locked).empty()) { - const GlobalVariable *GV = jitstate->getPendingGlobals(locked).back(); - jitstate->getPendingGlobals(locked).pop_back(); - EmitGlobalVariable(GV); + // If the function referred to another function that had not yet been + // read from bitcode, but we are jitting non-lazily, emit it now. + while (!jitstate->getPendingFunctions(locked).empty()) { + Function *PF = jitstate->getPendingFunctions(locked).back(); + jitstate->getPendingFunctions(locked).pop_back(); + + // JIT the function + isAlreadyCodeGenerating = true; + jitstate->getPM(locked).run(*PF); + isAlreadyCodeGenerating = false; + + // Now that the function has been jitted, ask the JITEmitter to rewrite + // the stub with real address of the function. + updateFunctionStub(PF); } + + // If the JIT is configured to emit info so that dlsym can be used to + // rewrite stubs to external globals, do so now. + if (areDlsymStubsEnabled() && isLazyCompilationDisabled()) + updateDlsymStubTable(); } /// getPointerToFunction - This method is used to get the address of the @@ -644,3 +691,8 @@ return new char[GVSize]; } } + +void JIT::addPendingFunction(Function *F) { + MutexGuard locked(lock); + jitstate->getPendingFunctions(locked).push_back(F); +} Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JIT.h?rev=64906&r1=64905&r2=64906&view=diff ============================================================================== --- llvm/trunk/lib/ExecutionEngine/JIT/JIT.h (original) +++ llvm/trunk/lib/ExecutionEngine/JIT/JIT.h Wed Feb 18 02:31:02 2009 @@ -20,8 +20,6 @@ namespace llvm { class Function; -class GlobalValue; -class Constant; class TargetMachine; class TargetJITInfo; class MachineCodeEmitter; @@ -29,21 +27,22 @@ class JITState { private: FunctionPassManager PM; // Passes to compile a function + ModuleProvider *MP; // ModuleProvider used to create the PM - /// PendingGlobals - Global variables which have had memory allocated for them - /// while a function was code generated, but which have not been initialized - /// yet. - std::vector PendingGlobals; + /// PendingFunctions - Functions which have not been code generated yet, but + /// were called from a function being code generated. + std::vector PendingFunctions; public: - explicit JITState(ModuleProvider *MP) : PM(MP) {} + explicit JITState(ModuleProvider *MP) : PM(MP), MP(MP) {} FunctionPassManager &getPM(const MutexGuard &L) { return PM; } - - std::vector &getPendingGlobals(const MutexGuard &L) { - return PendingGlobals; + + ModuleProvider *getMP() const { return MP; } + std::vector &getPendingFunctions(const MutexGuard &L) { + return PendingFunctions; } }; @@ -139,6 +138,12 @@ /// void freeMachineCodeForFunction(Function *F); + /// addPendingFunction - while jitting non-lazily, a called but non-codegen'd + /// function was encountered. Add it to a pending list to be processed after + /// the current function. + /// + void addPendingFunction(Function *F); + /// getCodeEmitter - Return the code emitter this JIT is emitting into. MachineCodeEmitter *getCodeEmitter() const { return MCE; } @@ -149,7 +154,9 @@ static MachineCodeEmitter *createEmitter(JIT &J, JITMemoryManager *JMM); void runJITOnFunction(Function *F); void runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked); - + void updateFunctionStub(Function *F); + void updateDlsymStubTable(); + protected: /// getMemoryforGV - Allocate memory for a global variable. Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp?rev=64906&r1=64905&r2=64906&view=diff ============================================================================== --- llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp (original) +++ llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp Wed Feb 18 02:31:02 2009 @@ -36,6 +36,7 @@ #include "llvm/System/Memory.h" #include "llvm/Target/TargetInstrInfo.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include #ifndef NDEBUG @@ -120,8 +121,9 @@ void *getFunctionStubIfAvailable(Function *F); /// getFunctionStub - This returns a pointer to a function stub, creating - /// one on demand as needed. - void *getFunctionStub(Function *F); + /// one on demand as needed. If empty is true, create a function stub + /// pointing at address 0, to be filled in later. + void *getFunctionStub(Function *F, bool empty = false); /// getExternalFunctionStub - Return a stub for the function at the /// specified address, created lazily on demand. @@ -140,6 +142,9 @@ state.getStubToFunctionMap(locked)[Location] = F; return (void*)(intptr_t)LazyResolverFn; } + + void getRelocatableGVs(SmallVectorImpl &GVs, + SmallVectorImpl &Ptrs); /// getGOTIndexForAddress - Return a new or existing index in the GOT for /// an address. This function only manages slots, it does not manage the @@ -167,7 +172,7 @@ /// getFunctionStub - This returns a pointer to a function stub, creating /// one on demand as needed. -void *JITResolver::getFunctionStub(Function *F) { +void *JITResolver::getFunctionStub(Function *F, bool empty) { MutexGuard locked(TheJIT->lock); // If we already have a stub for this function, recycle it. @@ -176,7 +181,7 @@ // Call the lazy resolver function unless we already KNOW it is an external // function, in which case we just skip the lazy resolution step. - void *Actual = (void*)(intptr_t)LazyResolverFn; + void *Actual = empty ? (void*)0 : (void*)(intptr_t)LazyResolverFn; if (F->isDeclaration() && !F->hasNotBeenReadFromBitcode()) { Actual = TheJIT->getPointerToFunction(F); @@ -203,6 +208,12 @@ // Finally, keep track of the stub-to-Function mapping so that the // JITCompilerFn knows which function to compile! state.getStubToFunctionMap(locked)[Stub] = F; + + // If this is an "empty" stub, then inform the JIT that it will need to + // JIT the function so an address can be provided. + if (empty) + TheJIT->addPendingFunction(F); + return Stub; } @@ -250,6 +261,28 @@ return idx; } +void JITResolver::getRelocatableGVs(SmallVectorImpl &GVs, + SmallVectorImpl &Ptrs) { + MutexGuard locked(TheJIT->lock); + + std::map &FM = state.getFunctionToStubMap(locked); + std::map &GM = state.getGlobalToIndirectSymMap(locked); + + for (std::map::iterator i = FM.begin(), e = FM.end(); + i != e; ++i) { + Function *F = i->first; + if (F->isDeclaration() && F->hasExternalLinkage()) { + GVs.push_back(i->first); + Ptrs.push_back(i->second); + } + } + for (std::map::iterator i = GM.begin(), e = GM.end(); + i != e; ++i) { + GVs.push_back(i->first); + Ptrs.push_back(i->second); + } +} + /// JITCompilerFn - This function is called when a lazy compilation stub has /// been entered. It looks up which function this stub corresponds to, compiles /// it if necessary, then returns the resultant function pointer. @@ -399,8 +432,7 @@ JitSymbolEntry *OldSymbols = SymTabPtr->Symbols; // Copy the old entries over. - memcpy(NewSymbols, OldSymbols, - SymTabPtr->NumSymbols*sizeof(OldSymbols[0])); + memcpy(NewSymbols, OldSymbols, SymTabPtr->NumSymbols*sizeof(OldSymbols[0])); // Swap the new symbols in, delete the old ones. SymTabPtr->Symbols = NewSymbols; @@ -538,6 +570,8 @@ virtual void startGVStub(const GlobalValue* GV, unsigned StubSize, unsigned Alignment = 1); + virtual void startGVStub(const GlobalValue* GV, void *Buffer, + unsigned StubSize); virtual void* finishGVStub(const GlobalValue *GV); /// allocateSpace - Reserves space in the current block if any, or @@ -591,6 +625,8 @@ void setMemoryExecutable(void) { MemMgr->setMemoryExecutable(); } + + JITMemoryManager *getMemMgr(void) const { return MemMgr; } private: void *getPointerToGlobal(GlobalValue *GV, void *Reference, bool NoNeedStub); @@ -605,11 +641,9 @@ void *JITEmitter::getPointerToGlobal(GlobalValue *V, void *Reference, bool DoesntNeedStub) { - if (GlobalVariable *GV = dyn_cast(V)) { - /// FIXME: If we straightened things out, this could actually emit the - /// global immediately instead of queuing it for codegen later! + if (GlobalVariable *GV = dyn_cast(V)) return TheJIT->getOrEmitGlobalVariable(GV); - } + if (GlobalAlias *GA = dyn_cast(V)) return TheJIT->getPointerToGlobal(GA->resolveAliasedGlobal(false)); @@ -623,15 +657,18 @@ ResultPtr = TheJIT->getPointerToGlobalIfAvailable(F); if (ResultPtr) return ResultPtr; - if (F->isDeclaration() && !F->hasNotBeenReadFromBitcode()) { - // If this is an external function pointer, we can force the JIT to - // 'compile' it, which really just adds it to the map. - if (DoesntNeedStub) - return TheJIT->getPointerToFunction(F); - - return Resolver.getFunctionStub(F); - } - + // If this is an external function pointer, we can force the JIT to + // 'compile' it, which really just adds it to the map. + if (F->isDeclaration() && !F->hasNotBeenReadFromBitcode() && DoesntNeedStub) + return TheJIT->getPointerToFunction(F); + + // If we are jitting non-lazily but encounter a function that has not been + // jitted yet, we need to allocate a blank stub to call the function + // once we JIT it and its address is known. + if (TheJIT->isLazyCompilationDisabled()) + if (!F->isDeclaration() || F->hasNotBeenReadFromBitcode()) + return Resolver.getFunctionStub(F, true); + // Okay, the function has not been compiled yet, if the target callback // mechanism is capable of rewriting the instruction directly, prefer to do // that instead of emitting a stub. @@ -1175,6 +1212,16 @@ BufferEnd = BufferBegin+StubSize+1; } +void JITEmitter::startGVStub(const GlobalValue* GV, void *Buffer, + unsigned StubSize) { + SavedBufferBegin = BufferBegin; + SavedBufferEnd = BufferEnd; + SavedCurBufferPtr = CurBufferPtr; + + BufferBegin = CurBufferPtr = (unsigned char *)Buffer; + BufferEnd = BufferBegin+StubSize+1; +} + void *JITEmitter::finishGVStub(const GlobalValue* GV) { NumBytes += getCurrentPCOffset(); std::swap(SavedBufferBegin, BufferBegin); @@ -1248,6 +1295,74 @@ return JE->getJITResolver().getFunctionStub(F); } +void JIT::updateFunctionStub(Function *F) { + // Get the empty stub we generated earlier. + assert(isa(MCE) && "Unexpected MCE?"); + JITEmitter *JE = cast(getCodeEmitter()); + void *Stub = JE->getJITResolver().getFunctionStub(F); + + // Tell the target jit info to rewrite the stub at the specified address, + // rather than creating a new one. + void *Addr = getPointerToGlobalIfAvailable(F); + getJITInfo().emitFunctionStubAtAddr(F, Addr, Stub, *getCodeEmitter()); +} + +/// updateDlsymStubTable - Emit the data necessary to relocate the stubs +/// that were emitted during code generation. +/// +void JIT::updateDlsymStubTable() { + assert(isa(MCE) && "Unexpected MCE?"); + JITEmitter *JE = cast(getCodeEmitter()); + + SmallVector GVs; + SmallVector Ptrs; + + JE->getJITResolver().getRelocatableGVs(GVs, Ptrs); + + // If there are no relocatable stubs, return. + if (GVs.empty()) + return; + + // If there are no new relocatable stubs, return. + void *CurTable = JE->getMemMgr()->getDlsymTable(); + if (CurTable && (*(unsigned *)CurTable == GVs.size())) + return; + + // Calculate the size of the stub info + unsigned offset = 4 + 4 * GVs.size(); + + SmallVector Offsets; + for (unsigned i = 0; i != GVs.size(); ++i) { + Offsets.push_back(offset); + offset += GVs[i]->getName().length() + 1; + } + + // FIXME: This currently allocates new space every time it's called. A + // different data structure could be used to make this unnecessary. + JE->startGVStub(0, offset, 4); + + // Emit the number of records + MCE->emitInt32(GVs.size()); + + // Emit the string offsets + for (unsigned i = 0; i != GVs.size(); ++i) + MCE->emitInt32(Offsets[i]); + + // Emit the pointers + for (unsigned i = 0; i != GVs.size(); ++i) + if (sizeof(void *) == 8) + MCE->emitInt64((intptr_t)Ptrs[i]); + else + MCE->emitInt32((intptr_t)Ptrs[i]); + + // Emit the strings + for (unsigned i = 0; i != GVs.size(); ++i) + MCE->emitString(GVs[i]->getName()); + + // Tell the JIT memory manager where it is. + JE->getMemMgr()->SetDlsymTable(JE->finishGVStub(0)); +} + /// freeMachineCodeForFunction - release machine code memory for given Function. /// void JIT::freeMachineCodeForFunction(Function *F) { Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp?rev=64906&r1=64905&r2=64906&view=diff ============================================================================== --- llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp (original) +++ llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp Wed Feb 18 02:31:02 2009 @@ -258,6 +258,7 @@ unsigned char *CurStubPtr, *StubBase; unsigned char *GOTBase; // Target Specific reserved memory + void *DlsymTable; // Stub external symbol information // Centralize memory block allocation. sys::MemoryBlock getNewMemoryBlock(unsigned size); @@ -269,7 +270,8 @@ ~DefaultJITMemoryManager(); void AllocateGOT(); - + void SetDlsymTable(void *); + unsigned char *allocateStub(const GlobalValue* F, unsigned StubSize, unsigned Alignment); @@ -343,6 +345,10 @@ return GOTBase; } + void *getDlsymTable() const { + return DlsymTable; + } + /// deallocateMemForFunction - Deallocate all memory for the specified /// function body. void deallocateMemForFunction(const Function *F) { @@ -463,6 +469,7 @@ FreeMemoryList = Mem0; GOTBase = NULL; + DlsymTable = NULL; } void DefaultJITMemoryManager::AllocateGOT() { @@ -471,6 +478,9 @@ HasGOT = true; } +void DefaultJITMemoryManager::SetDlsymTable(void *ptr) { + DlsymTable = ptr; +} DefaultJITMemoryManager::~DefaultJITMemoryManager() { for (unsigned i = 0, e = Blocks.size(); i != e; ++i) Modified: llvm/trunk/lib/Target/X86/X86JITInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86JITInfo.cpp?rev=64906&r1=64905&r2=64906&view=diff ============================================================================== --- llvm/trunk/lib/Target/X86/X86JITInfo.cpp (original) +++ llvm/trunk/lib/Target/X86/X86JITInfo.cpp Wed Feb 18 02:31:02 2009 @@ -490,6 +490,21 @@ return MCE.finishGVStub(F); } +void X86JITInfo::emitFunctionStubAtAddr(const Function* F, void *Fn, void *Stub, + MachineCodeEmitter &MCE) { + // Note, we cast to intptr_t here to silence a -pedantic warning that + // complains about casting a function pointer to a normal pointer. + MCE.startGVStub(F, Stub, 5); + MCE.emitByte(0xE9); +#if defined (X86_64_JIT) + assert(((((intptr_t)Fn-MCE.getCurrentPCValue()-5) << 32) >> 32) == + ((intptr_t)Fn-MCE.getCurrentPCValue()-5) + && "PIC displacement does not fit in displacement field!"); +#endif + MCE.emitWordLE((intptr_t)Fn-MCE.getCurrentPCValue()-4); + MCE.finishGVStub(F); +} + /// getPICJumpTableEntry - Returns the value of the jumptable entry for the /// specific basic block. uintptr_t X86JITInfo::getPICJumpTableEntry(uintptr_t BB, uintptr_t Entry) { Modified: llvm/trunk/lib/Target/X86/X86JITInfo.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86JITInfo.h?rev=64906&r1=64905&r2=64906&view=diff ============================================================================== --- llvm/trunk/lib/Target/X86/X86JITInfo.h (original) +++ llvm/trunk/lib/Target/X86/X86JITInfo.h Wed Feb 18 02:31:02 2009 @@ -49,6 +49,12 @@ virtual void *emitFunctionStub(const Function* F, void *Fn, MachineCodeEmitter &MCE); + /// emitFunctionStubAtAddr - Use the specified MachineCodeEmitter object to + /// emit a small native function that simply calls Fn. Emit the stub into + /// the supplied buffer. + virtual void emitFunctionStubAtAddr(const Function* F, void *Fn, + void *Buffer, MachineCodeEmitter &MCE); + /// getPICJumpTableEntry - Returns the value of the jumptable entry for the /// specific basic block. virtual uintptr_t getPICJumpTableEntry(uintptr_t BB, uintptr_t JTBase); From isanbard at gmail.com Wed Feb 18 02:32:18 2009 From: isanbard at gmail.com (Bill Wendling) Date: Wed, 18 Feb 2009 08:32:18 -0000 Subject: [llvm-commits] [llvm] r64907 - /llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp Message-ID: <200902180832.n1I8WITv024330@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 02:32:17 2009 New Revision: 64907 URL: http://llvm.org/viewvc/llvm-project?rev=64907&view=rev Log: Merge r64600 into Dib: On 64bit we may have a personality function which requires 64 bits to be encoded. Modified: llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp Modified: llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp?rev=64907&r1=64906&r2=64907&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp (original) +++ llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp Wed Feb 18 02:32:17 2009 @@ -519,14 +519,20 @@ MCE->emitByte(RI->getDwarfRegNum(RI->getRARegister(), true)); if (Personality) { - MCE->emitULEB128Bytes(7); + // Augmentation Size: 3 small ULEBs of one byte each, and the personality + // function which size is PointerSize. + MCE->emitULEB128Bytes(3 + PointerSize); - // Direct encoding, because we use the function pointer. Not relative, - // because the current PC value may be bigger than the personality - // function pointer. - MCE->emitByte(dwarf::DW_EH_PE_sdata4); - - MCE->emitInt32(((intptr_t)Jit.getPointerToGlobal(Personality))); + // We set the encoding of the personality as direct encoding because we use + // the function pointer. The encoding is not relative because the current + // PC value may be bigger than the personality function pointer. + if (PointerSize == 4) { + MCE->emitByte(dwarf::DW_EH_PE_sdata4); + MCE->emitInt32(((intptr_t)Jit.getPointerToGlobal(Personality))); + } else { + MCE->emitByte(dwarf::DW_EH_PE_sdata8); + MCE->emitInt64(((intptr_t)Jit.getPointerToGlobal(Personality))); + } MCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4); MCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4); From isanbard at gmail.com Wed Feb 18 02:34:09 2009 From: isanbard at gmail.com (Bill Wendling) Date: Wed, 18 Feb 2009 08:34:09 -0000 Subject: [llvm-commits] [llvm] r64908 - in /llvm/branches/Apple/Dib: lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp test/CodeGen/X86/cstring.ll Message-ID: <200902180834.n1I8Y9vh024395@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 02:34:09 2009 New Revision: 64908 URL: http://llvm.org/viewvc/llvm-project?rev=64908&view=rev Log: Pull r64877 into Dib: GV with null value initializer shouldn't go to BSS if it's meant for a mergeable strings section. Currently it only checks for Darwin. Someone else please check if it should apply to other targets as well. Added: llvm/branches/Apple/Dib/test/CodeGen/X86/cstring.ll - copied unchanged from r64877, llvm/trunk/test/CodeGen/X86/cstring.ll Modified: llvm/branches/Apple/Dib/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp llvm/branches/Apple/Dib/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Modified: llvm/branches/Apple/Dib/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp?rev=64908&r1=64907&r2=64908&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp (original) +++ llvm/branches/Apple/Dib/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp Wed Feb 18 02:34:09 2009 @@ -835,7 +835,9 @@ if (Subtarget->isTargetELF()) O << "\t.type " << name << ",%object\n"; - if (C->isNullValue() && !GVar->hasSection() && !GVar->isThreadLocal()) { + if (C->isNullValue() && !GVar->hasSection() && !GVar->isThreadLocal() && + !(isDarwin && + TAI->SectionKindForGlobal(GVar) == SectionKind::RODataMergeStr)) { // FIXME: This seems to be pretty darwin-specific if (GVar->hasExternalLinkage()) { Modified: llvm/branches/Apple/Dib/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp?rev=64908&r1=64907&r2=64908&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp (original) +++ llvm/branches/Apple/Dib/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp Wed Feb 18 02:34:09 2009 @@ -915,7 +915,8 @@ if (C->isNullValue() && /* FIXME: Verify correct */ !GVar->hasSection() && (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() || - GVar->mayBeOverridden())) { + GVar->mayBeOverridden()) && + TAI->SectionKindForGlobal(GVar) != SectionKind::RODataMergeStr) { if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. if (GVar->hasExternalLinkage()) { Modified: llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp?rev=64908&r1=64907&r2=64908&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp (original) +++ llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Wed Feb 18 02:34:09 2009 @@ -799,7 +799,9 @@ SwitchToSection(TAI->SectionForGlobal(GVar)); - if (C->isNullValue() && !GVar->hasSection()) { + if (C->isNullValue() && !GVar->hasSection() && + !(Subtarget->isTargetDarwin() && + TAI->SectionKindForGlobal(GVar) == SectionKind::RODataMergeStr)) { // FIXME: This seems to be pretty darwin-specific if (GVar->hasExternalLinkage()) { if (const char *Directive = TAI->getZeroFillDirective()) { From isanbard at gmail.com Wed Feb 18 02:36:20 2009 From: isanbard at gmail.com (Bill Wendling) Date: Wed, 18 Feb 2009 08:36:20 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64909 - in /llvm-gcc-4.2/branches/Apple/Dib/gcc: tree-inline.c tree-optimize.c Message-ID: <200902180836.n1I8aKT8024462@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 02:36:20 2009 New Revision: 64909 URL: http://llvm.org/viewvc/llvm-project?rev=64909&view=rev Log: Pull r64878 into Dib: Turns out 64819 isn't safe. It can trigger verify_cgraph_node failure later. gcc is relying on some optimization pass to clear certain states. Nice. This fixes that and just disable -Winline warnings instead. Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-inline.c llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-optimize.c Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-inline.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-inline.c?rev=64909&r1=64908&r2=64909&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-inline.c (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-inline.c Wed Feb 18 02:36:20 2009 @@ -2037,6 +2037,8 @@ inlining. */ if (!cgraph_inline_p (cg_edge, &reason)) { +/* LLVM LOCAL begin */ +#ifndef ENABLE_LLVM if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) /* Avoid warnings during early inline pass. */ && (!flag_unit_at_a_time || cgraph_global_info_ready)) @@ -2057,6 +2059,8 @@ fn, reason); warning (OPT_Winline, "called from here"); } +#endif +/* LLVM LOCAL end */ goto egress; } fn = cg_edge->callee->decl; Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-optimize.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-optimize.c?rev=64909&r1=64908&r2=64909&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-optimize.c (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/tree-optimize.c Wed Feb 18 02:36:20 2009 @@ -439,8 +439,6 @@ cfun->x_dont_save_pending_sizes_p = 1; cfun->after_inlining = true; -/* LLVM LOCAL begin */ -#ifndef ENABLE_LLVM if (flag_inline_trees) { struct cgraph_edge *e; @@ -454,8 +452,6 @@ timevar_pop (TV_INTEGRATION); } } -#endif -/* LLVM LOCAL end */ /* In non-unit-at-a-time we must mark all referenced functions as needed. */ if (!flag_unit_at_a_time) From isanbard at gmail.com Wed Feb 18 02:40:26 2009 From: isanbard at gmail.com (Bill Wendling) Date: Wed, 18 Feb 2009 08:40:26 -0000 Subject: [llvm-commits] [llvm] r64910 - /llvm/branches/Apple/Dib/test/Transforms/GVN/2009-02-17-LoadPRECrash.ll Message-ID: <200902180840.n1I8eQI8025525@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 02:40:25 2009 New Revision: 64910 URL: http://llvm.org/viewvc/llvm-project?rev=64910&view=rev Log: Pull r64904 into Dib. Added: llvm/branches/Apple/Dib/test/Transforms/GVN/2009-02-17-LoadPRECrash.ll - copied unchanged from r64904, llvm/trunk/test/Transforms/GVN/2009-02-17-LoadPRECrash.ll From isanbard at gmail.com Wed Feb 18 02:43:30 2009 From: isanbard at gmail.com (Bill Wendling) Date: Wed, 18 Feb 2009 08:43:30 -0000 Subject: [llvm-commits] [llvm] r64911 - in /llvm/branches/Apple/Dib: lib/Transforms/Scalar/LoopStrengthReduce.cpp test/Transforms/LoopStrengthReduce/pr3571.ll Message-ID: <200902180843.n1I8hUv3026213@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 02:43:29 2009 New Revision: 64911 URL: http://llvm.org/viewvc/llvm-project?rev=64911&view=rev Log: Merge r64789 from release_25 branch: Fix pr3571: If stride is a value defined by an instruction, make sure it dominates the loop preheader. When IV users are strength reduced, the stride is inserted into the preheader. It could create a use before def situation. Added: llvm/branches/Apple/Dib/test/Transforms/LoopStrengthReduce/pr3571.ll - copied unchanged from r64789, llvm/branches/release_25/test/Transforms/LoopStrengthReduce/pr3571.ll Modified: llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopStrengthReduce.cpp Modified: llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopStrengthReduce.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=64911&r1=64910&r2=64911&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original) +++ llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopStrengthReduce.cpp Wed Feb 18 02:43:29 2009 @@ -400,7 +400,7 @@ /// outer loop of the current loop. static bool getSCEVStartAndStride(const SCEVHandle &SH, Loop *L, SCEVHandle &Start, SCEVHandle &Stride, - ScalarEvolution *SE) { + ScalarEvolution *SE, DominatorTree *DT) { SCEVHandle TheAddRec = Start; // Initialize to zero. // If the outer level is an AddExpr, the operands are all start values except @@ -437,9 +437,21 @@ Start = SE->getAddExpr(Start, AddRec->getOperand(0)); - if (!isa(AddRec->getOperand(1))) + if (!isa(AddRec->getOperand(1))) { + // If stride is an instruction, make sure it dominates the loop header. + // Otherwise we could end up with a use before def situation. + if (SCEVUnknown *SU = dyn_cast(AddRec->getOperand(1))) { + if (Instruction *I = dyn_cast(SU->getValue())) { + BasicBlock *StrideBB = I->getParent(); + BasicBlock *Preheader = L->getLoopPreheader(); + if (!DT->dominates(StrideBB, Preheader)) + return false; + } + } + DOUT << "[" << L->getHeader()->getName() << "] Variable stride: " << *AddRec << "\n"; + } Stride = AddRec->getOperand(1); return true; @@ -547,7 +559,7 @@ // Get the start and stride for this expression. SCEVHandle Start = SE->getIntegerSCEV(0, ISE->getType()); SCEVHandle Stride = Start; - if (!getSCEVStartAndStride(ISE, L, Start, Stride, SE)) + if (!getSCEVStartAndStride(ISE, L, Start, Stride, SE, DT)) return false; // Non-reducible symbolic expression, bail out. std::vector IUsers; From isanbard at gmail.com Wed Feb 18 02:45:52 2009 From: isanbard at gmail.com (Bill Wendling) Date: Wed, 18 Feb 2009 08:45:52 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64912 - in /llvm-gcc-4.2/branches/Apple/Dib/gcc: fortran/decl.c fortran/intrinsic.c fortran/match.c fortran/matchexp.c fortran/module.c fortran/primary.c fortran/symbol.c stub-c.c Message-ID: <200902180845.n1I8jq9X026863@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 02:45:51 2009 New Revision: 64912 URL: http://llvm.org/viewvc/llvm-project?rev=64912&view=rev Log: Merge r64814 from release_25 into Dib: Provide some default return values for the functions. This silences the warning and thus unbreaks apple-style build (which is -Werror) Fix format strings weirdness of fortran f.e. This caused warnings and thus broke apple-style build (which is -Werror) Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/decl.c llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/intrinsic.c llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/match.c llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/matchexp.c llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/module.c llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/primary.c llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/symbol.c llvm-gcc-4.2/branches/Apple/Dib/gcc/stub-c.c Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/decl.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/decl.c?rev=64912&r1=64911&r2=64912&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/decl.c (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/decl.c Wed Feb 18 02:45:51 2009 @@ -367,7 +367,7 @@ gfc_free_expr (expr); if (msg != NULL) { - gfc_error (msg); + gfc_error ("%s", msg); return MATCH_ERROR; } tail->repeat = tmp; @@ -1450,7 +1450,7 @@ msg = gfc_extract_int (e, &ts->kind); if (msg != NULL) { - gfc_error (msg); + gfc_error ("%s", msg); m = MATCH_ERROR; goto no_match; } Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/intrinsic.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/intrinsic.c?rev=64912&r1=64911&r2=64912&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/intrinsic.c (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/intrinsic.c Wed Feb 18 02:45:51 2009 @@ -126,7 +126,7 @@ sprintf (name, "__convert_%c%d_%c%d", gfc_type_letter (from->type), from->kind, gfc_type_letter (to->type), to->kind); - return gfc_get_string (name); + return gfc_get_string ("%s", name); } @@ -249,11 +249,11 @@ break; case SZ_NOTHING: - next_sym->name = gfc_get_string (name); + next_sym->name = gfc_get_string ("%s", name); strcpy (buf, "_gfortran_"); strcat (buf, name); - next_sym->lib_name = gfc_get_string (buf); + next_sym->lib_name = gfc_get_string ("%s", buf); next_sym->elemental = elemental; next_sym->actual_ok = actual_ok; @@ -871,7 +871,7 @@ case SZ_NOTHING: next_sym[0] = next_sym[-1]; - next_sym->name = gfc_get_string (name); + next_sym->name = gfc_get_string ("%s", name); next_sym++; break; Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/match.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/match.c?rev=64912&r1=64911&r2=64912&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/match.c (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/match.c Wed Feb 18 02:45:51 2009 @@ -212,7 +212,7 @@ if (p != NULL) { - gfc_error (p); + gfc_error ("%s", p); m = MATCH_ERROR; } Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/matchexp.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/matchexp.c?rev=64912&r1=64911&r2=64912&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/matchexp.c (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/matchexp.c Wed Feb 18 02:45:51 2009 @@ -198,7 +198,7 @@ return MATCH_YES; syntax: - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); return MATCH_ERROR; } @@ -493,7 +493,7 @@ m = match_ext_add_operand (&e); if (m == MATCH_NO) { - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); m = MATCH_ERROR; } } @@ -532,7 +532,7 @@ m = match_ext_add_operand (&e); if (m == MATCH_NO) - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); if (m != MATCH_YES) { gfc_free_expr (all); @@ -583,7 +583,7 @@ m = match_level_2 (&e); if (m == MATCH_NO) { - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); gfc_free_expr (all); } if (m != MATCH_YES) @@ -641,7 +641,7 @@ m = match_level_3 (&right); if (m == MATCH_NO) - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); if (m != MATCH_YES) { gfc_free_expr (left); @@ -744,7 +744,7 @@ m = match_and_operand (&e); if (m == MATCH_NO) - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); if (m != MATCH_YES) { gfc_free_expr (all); @@ -787,7 +787,7 @@ m = match_or_operand (&e); if (m == MATCH_NO) - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); if (m != MATCH_YES) { gfc_free_expr (all); @@ -841,7 +841,7 @@ m = match_equiv_operand (&e); if (m == MATCH_NO) - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); if (m != MATCH_YES) { gfc_free_expr (all); @@ -900,7 +900,7 @@ m = match_level_5 (&e); if (m == MATCH_NO) - gfc_error (expression_syntax); + gfc_error ("%s", expression_syntax); if (m != MATCH_YES) { gfc_free_expr (all); Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/module.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/module.c?rev=64912&r1=64911&r2=64912&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/module.c (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/module.c Wed Feb 18 02:45:51 2009 @@ -716,9 +716,9 @@ gfc_symbol sym; int c; - sym.name = gfc_get_string (name); + sym.name = gfc_get_string ("%s", name); if (module != NULL) - sym.module = gfc_get_string (module); + sym.module = gfc_get_string ("%s", module); else sym.module = NULL; t.sym = &sym; @@ -1404,7 +1404,7 @@ else { require_atom (ATOM_STRING); - *stringp = atom_string[0] == '\0' ? NULL : gfc_get_string (atom_string); + *stringp = atom_string[0] == '\0' ? NULL : gfc_get_string ("%s", atom_string); gfc_free (atom_string); } } @@ -2617,7 +2617,7 @@ else { require_atom (ATOM_STRING); - e->value.function.name = gfc_get_string (atom_string); + e->value.function.name = gfc_get_string ("%s", atom_string); gfc_free (atom_string); mio_integer (&flag); @@ -3198,7 +3198,7 @@ } sym = gfc_new_symbol (p->u.rsym.true_name, ns); - sym->module = gfc_get_string (p->u.rsym.module); + sym->module = gfc_get_string ("%s", p->u.rsym.module); associate_integer_pointer (p, sym); } @@ -3420,7 +3420,7 @@ gfc_new_symbol (info->u.rsym.true_name, gfc_current_ns); - sym->module = gfc_get_string (info->u.rsym.module); + sym->module = gfc_get_string ("%s", info->u.rsym.module); } st->n.sym = sym; @@ -3656,7 +3656,7 @@ sym = st->n.sym; if (sym->module == NULL) - sym->module = gfc_get_string (module_name); + sym->module = gfc_get_string ("%s", module_name); if (sym->attr.flavor == FL_PROCEDURE && sym->attr.generic && !sym->attr.subroutine && !sym->attr.function) @@ -3735,7 +3735,7 @@ return; if (sym->module == NULL) - sym->module = gfc_get_string (module_name); + sym->module = gfc_get_string ("%s", module_name); mio_symbol_interface (&sym->name, &sym->module, &sym->generic); } Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/primary.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/primary.c?rev=64912&r1=64911&r2=64912&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/primary.c (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/primary.c Wed Feb 18 02:45:51 2009 @@ -254,7 +254,7 @@ msg = gfc_extract_int (e, &num); if (msg != NULL) { - gfc_error (msg); + gfc_error ("%s", msg); goto cleanup; } if (num == 0) @@ -925,7 +925,7 @@ q = gfc_extract_int (sym->value, &kind); if (q != NULL) { - gfc_error (q); + gfc_error ("%s", q); return MATCH_ERROR; } } @@ -1432,7 +1432,7 @@ } } - actual->name = gfc_get_string (name); + actual->name = gfc_get_string ("%s", name); return MATCH_YES; cleanup: Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/symbol.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/symbol.c?rev=64912&r1=64911&r2=64912&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/symbol.c (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/fortran/symbol.c Wed Feb 18 02:45:51 2009 @@ -1327,7 +1327,7 @@ else tail->next = p; - p->name = gfc_get_string (name); + p->name = gfc_get_string ("%s", name); p->loc = gfc_current_locus; *component = p; @@ -1788,7 +1788,7 @@ gfc_symtree *st; st = gfc_getmem (sizeof (gfc_symtree)); - st->name = gfc_get_string (name); + st->name = gfc_get_string ("%s", name); gfc_insert_bbt (root, st, compare_symtree); return st; @@ -1804,7 +1804,7 @@ st0 = gfc_find_symtree (*root, name); - st.name = gfc_get_string (name); + st.name = gfc_get_string ("%s", name); gfc_delete_bbt (root, &st, compare_symtree); gfc_free (st0); @@ -1849,7 +1849,7 @@ st = gfc_new_symtree (&gfc_current_ns->uop_root, name); uop = st->n.uop = gfc_getmem (sizeof (gfc_user_op)); - uop->name = gfc_get_string (name); + uop->name = gfc_get_string ("%s", name); uop->access = ACCESS_UNKNOWN; uop->ns = gfc_current_ns; @@ -1919,7 +1919,7 @@ if (strlen (name) > GFC_MAX_SYMBOL_LEN) gfc_internal_error ("new_symbol(): Symbol name too long"); - p->name = gfc_get_string (name); + p->name = gfc_get_string ("%s", name); return p; } @@ -2702,7 +2702,7 @@ s = gfc_getmem (sizeof (gfc_gsymbol)); s->type = GSYM_UNKNOWN; - s->name = gfc_get_string (name); + s->name = gfc_get_string ("%s", name); gfc_insert_bbt (&gfc_gsym_root, s, gsym_compare); Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/stub-c.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/stub-c.c?rev=64912&r1=64911&r2=64912&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/stub-c.c (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/stub-c.c Wed Feb 18 02:45:51 2009 @@ -40,6 +40,7 @@ tree iasm_addr (tree e ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } @@ -49,6 +50,7 @@ tree v2 ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } @@ -80,6 +82,7 @@ bool iasm_is_pseudo (const char *opcode ATTRIBUTE_UNUSED) { gcc_assert(0); + return false; } @@ -105,6 +108,7 @@ tree rhs ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } @@ -113,6 +117,7 @@ tree decl_constant_value (tree decl ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } @@ -122,6 +127,7 @@ tree params ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } @@ -130,6 +136,7 @@ tree build_stmt (enum tree_code code ATTRIBUTE_UNUSED, ...) { gcc_assert(0); + return NULL; } @@ -138,6 +145,7 @@ tree lookup_name (tree name ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } @@ -148,6 +156,7 @@ tree intop ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } @@ -168,6 +177,7 @@ size_t * numUniChars ATTRIBUTE_UNUSED) { gcc_assert(0); + return false; } tree create_init_utf16_var (const unsigned char *, size_t, @@ -179,4 +189,5 @@ size_t * numUniChars ATTRIBUTE_UNUSED) { gcc_assert(0); + return NULL; } From isanbard at gmail.com Wed Feb 18 02:52:34 2009 From: isanbard at gmail.com (Bill Wendling) Date: Wed, 18 Feb 2009 00:52:34 -0800 Subject: [llvm-commits] [llvm] r64904 - /llvm/trunk/test/Transforms/GVN/2009-02-17-LoadPRECrash.ll In-Reply-To: <200902180750.n1I7oMWF022640@zion.cs.uiuc.edu> References: <200902180750.n1I7oMWF022640@zion.cs.uiuc.edu> Message-ID: <8FB74314-4293-49F9-A6EA-65F6B5974EE1@gmail.com> On Feb 17, 2009, at 11:50 PM, Owen Anderson wrote: > Author: resistor > Date: Wed Feb 18 01:50:22 2009 > New Revision: 64904 > > URL: http://llvm.org/viewvc/llvm-project?rev=64904&view=rev > Log: > Add a test for r61358, which I forgot to add way back when. > Thanks, Owen! -bw From zhousheng00 at gmail.com Wed Feb 18 08:54:57 2009 From: zhousheng00 at gmail.com (Zhou Sheng) Date: Wed, 18 Feb 2009 22:54:57 +0800 Subject: [llvm-commits] [llvm] - Patch to update the line number information in pass -mem2reg (review only) Message-ID: <8abe0dc60902180654o53127c6bi3be839a4e01476cb@mail.gmail.com> Attached is the patch to update the line number information in pass -mem2reg. Currently this pass will delete the variable declaration info, and keep the line number info. But the kept line number info is not updated, and some is redundant or not correct, this patch just updates those info. Just for review. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090218/fd86799b/attachment.html -------------- next part -------------- A non-text attachment was scrubbed... Name: Mem2Reg.cpp.patch Type: application/octet-stream Size: 3299 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090218/fd86799b/attachment.obj From gohman at apple.com Wed Feb 18 10:37:45 2009 From: gohman at apple.com (Dan Gohman) Date: Wed, 18 Feb 2009 16:37:45 -0000 Subject: [llvm-commits] [llvm] r64915 - in /llvm/trunk: include/llvm/ADT/SmallVector.h lib/Target/Sparc/FPMover.cpp lib/Transforms/IPO/ArgumentPromotion.cpp utils/TableGen/AsmWriterEmitter.cpp utils/TableGen/DAGISelEmitter.h Message-ID: <200902181637.n1IGbkw2018715@zion.cs.uiuc.edu> Author: djg Date: Wed Feb 18 10:37:45 2009 New Revision: 64915 URL: http://llvm.org/viewvc/llvm-project?rev=64915&view=rev Log: Add explicit keywords. Modified: llvm/trunk/include/llvm/ADT/SmallVector.h llvm/trunk/lib/Target/Sparc/FPMover.cpp llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp llvm/trunk/utils/TableGen/DAGISelEmitter.h Modified: llvm/trunk/include/llvm/ADT/SmallVector.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=64915&r1=64914&r2=64915&view=diff ============================================================================== --- llvm/trunk/include/llvm/ADT/SmallVector.h (original) +++ llvm/trunk/include/llvm/ADT/SmallVector.h Wed Feb 18 10:37:45 2009 @@ -75,7 +75,7 @@ // Space after 'FirstEl' is clobbered, do not add any instance vars after it. public: // Default ctor - Initialize to empty. - SmallVectorImpl(unsigned N) + explicit SmallVectorImpl(unsigned N) : Begin(reinterpret_cast(&FirstEl)), End(reinterpret_cast(&FirstEl)), Capacity(reinterpret_cast(&FirstEl)+N) { Modified: llvm/trunk/lib/Target/Sparc/FPMover.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/FPMover.cpp?rev=64915&r1=64914&r2=64915&view=diff ============================================================================== --- llvm/trunk/lib/Target/Sparc/FPMover.cpp (original) +++ llvm/trunk/lib/Target/Sparc/FPMover.cpp Wed Feb 18 10:37:45 2009 @@ -33,7 +33,7 @@ TargetMachine &TM; static char ID; - FPMover(TargetMachine &tm) + explicit FPMover(TargetMachine &tm) : MachineFunctionPass(&ID), TM(tm) { } virtual const char *getPassName() const { Modified: llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp?rev=64915&r1=64914&r2=64915&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp (original) +++ llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp Wed Feb 18 10:37:45 2009 @@ -66,8 +66,8 @@ virtual bool runOnSCC(const std::vector &SCC); static char ID; // Pass identification, replacement for typeid - ArgPromotion(unsigned maxElements = 3) : CallGraphSCCPass(&ID), - maxElements(maxElements) {} + explicit ArgPromotion(unsigned maxElements = 3) + : CallGraphSCCPass(&ID), maxElements(maxElements) {} /// A vector used to hold the indices of a single GEP instruction typedef std::vector IndicesVector; Modified: llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp?rev=64915&r1=64914&r2=64915&view=diff ============================================================================== --- llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp (original) +++ llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp Wed Feb 18 10:37:45 2009 @@ -48,7 +48,7 @@ // To make VS STL happy AsmWriterOperand():OperandType(isLiteralTextOperand) {} - AsmWriterOperand(const std::string &LitStr) + explicit AsmWriterOperand(const std::string &LitStr) : OperandType(isLiteralTextOperand), Str(LitStr) {} AsmWriterOperand(const std::string &Printer, unsigned OpNo, Modified: llvm/trunk/utils/TableGen/DAGISelEmitter.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelEmitter.h?rev=64915&r1=64914&r2=64915&view=diff ============================================================================== --- llvm/trunk/utils/TableGen/DAGISelEmitter.h (original) +++ llvm/trunk/utils/TableGen/DAGISelEmitter.h Wed Feb 18 10:37:45 2009 @@ -27,7 +27,7 @@ RecordKeeper &Records; CodeGenDAGPatterns CGP; public: - DAGISelEmitter(RecordKeeper &R) : Records(R), CGP(R) {} + explicit DAGISelEmitter(RecordKeeper &R) : Records(R), CGP(R) {} // run - Output the isel, returning true on failure. void run(std::ostream &OS); From gohman at apple.com Wed Feb 18 10:43:19 2009 From: gohman at apple.com (Dan Gohman) Date: Wed, 18 Feb 2009 16:43:19 -0000 Subject: [llvm-commits] [llvm] r64916 - /llvm/trunk/include/llvm/Analysis/LoopInfo.h Message-ID: <200902181643.n1IGhJAb018946@zion.cs.uiuc.edu> Author: djg Date: Wed Feb 18 10:43:19 2009 New Revision: 64916 URL: http://llvm.org/viewvc/llvm-project?rev=64916&view=rev Log: Clarify the definition of "latch block" in a comment. Modified: llvm/trunk/include/llvm/Analysis/LoopInfo.h Modified: llvm/trunk/include/llvm/Analysis/LoopInfo.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopInfo.h?rev=64916&r1=64915&r2=64916&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/LoopInfo.h (original) +++ llvm/trunk/include/llvm/Analysis/LoopInfo.h Wed Feb 18 10:43:19 2009 @@ -307,10 +307,10 @@ return Out; } - /// getLoopLatch - If there is a latch block for this loop, return it. A - /// latch block is the canonical backedge for a loop. A loop header in normal - /// form has two edges into it: one from a preheader and one from a latch - /// block. + /// getLoopLatch - If there is a single latch block for this loop, return it. + /// A latch block is a block that contains a branch back to the header. + /// A loop header in normal form has two edges into it: one from a preheader + /// and one from a latch block. BlockT *getLoopLatch() const { BlockT *Header = getHeader(); typedef GraphTraits > InvBlockTraits; From gohman at apple.com Wed Feb 18 10:54:33 2009 From: gohman at apple.com (Dan Gohman) Date: Wed, 18 Feb 2009 16:54:33 -0000 Subject: [llvm-commits] [llvm] r64917 - /llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Message-ID: <200902181654.n1IGsXWd019327@zion.cs.uiuc.edu> Author: djg Date: Wed Feb 18 10:54:33 2009 New Revision: 64917 URL: http://llvm.org/viewvc/llvm-project?rev=64917&view=rev Log: Simplify by using dyn_cast instead of isa and cast. Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=64917&r1=64916&r2=64917&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Wed Feb 18 10:54:33 2009 @@ -582,18 +582,17 @@ // For now, only analyze loops with a constant start value, so that // we can easily determine if the start value is not a maximum value // which would wrap on the first iteration. - const Value *InitialVal = PN->getIncomingValue(IncomingEdge); - if (!isa(InitialVal)) + const ConstantInt *InitialVal = + dyn_cast(PN->getIncomingValue(IncomingEdge)); + if (!InitialVal) return 0; // The original induction variable will start at some non-max value, // it counts up by one, and the loop iterates only while it remans // less than some value in the same type. As such, it will never wrap. - if (isSigned && - !cast(InitialVal)->getValue().isMaxSignedValue()) + if (isSigned && !InitialVal->getValue().isMaxSignedValue()) NoSignedWrap = true; - else if (!isSigned && - !cast(InitialVal)->getValue().isMaxValue()) + else if (!isSigned && !InitialVal->getValue().isMaxValue()) NoUnsignedWrap = true; return PN; } From tonic at nondot.org Wed Feb 18 11:02:14 2009 From: tonic at nondot.org (Tanya Lattner) Date: Wed, 18 Feb 2009 11:02:14 -0600 Subject: [llvm-commits] CVS: llvm-www/www-index.html Message-ID: <200902181702.n1IH2E3x019632@zion.cs.uiuc.edu> Changes in directory llvm-www: www-index.html updated: 1.174 -> 1.175 --- Log message: Update release schedule. Still fighting regressions. --- Diffs of the changes: (+3 -3) www-index.html | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) Index: llvm-www/www-index.html diff -u llvm-www/www-index.html:1.174 llvm-www/www-index.html:1.175 --- llvm-www/www-index.html:1.174 Mon Feb 2 23:37:37 2009 +++ llvm-www/www-index.html Wed Feb 18 11:01:16 2009 @@ -109,9 +109,9 @@

  • Feb 2 - Code Freeze/Branch Creation (9PM PST).
  • Feb 5 - Pre-release 1 testing begins.
  • Feb 12 - Pre-release 1 testing ends.
  • -
  • Feb 16 - Pre-release 2 testing begins.
  • -
  • Feb 23 - Pre-release 2 testing ends.
  • -
  • Feb 25 - Release.
  • +
  • Feb 20 - Pre-release 2 testing begins.
  • +
  • Feb 28 - Pre-release 2 testing ends.
  • +
  • Mar 2 - Release.
  • From gohman at apple.com Wed Feb 18 11:22:43 2009 From: gohman at apple.com (Dan Gohman) Date: Wed, 18 Feb 2009 17:22:43 -0000 Subject: [llvm-commits] [llvm] r64918 - in /llvm/trunk: include/llvm/Analysis/ScalarEvolution.h lib/Analysis/ScalarEvolution.cpp lib/Transforms/Scalar/IndVarSimplify.cpp test/Transforms/IndVarSimplify/preserve-signed-wrap.ll test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll test/Transforms/IndVarSimplify/signed-trip-count.ll Message-ID: <200902181722.n1IHMiaX020433@zion.cs.uiuc.edu> Author: djg Date: Wed Feb 18 11:22:41 2009 New Revision: 64918 URL: http://llvm.org/viewvc/llvm-project?rev=64918&view=rev Log: Use a sign-extend instead of a zero-extend when promoting a trip count value when the original loop iteration condition is signed and the canonical induction variable won't undergo signed overflow. This isn't required for correctness; it just preserves more information about original loop iteration values. Add a getTruncateOrSignExtend method to ScalarEvolution, following getTruncateOrZeroExtend. Added: llvm/trunk/test/Transforms/IndVarSimplify/signed-trip-count.ll Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolution.h llvm/trunk/lib/Analysis/ScalarEvolution.cpp llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll llvm/trunk/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolution.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolution.h?rev=64918&r1=64917&r2=64918&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/ScalarEvolution.h (original) +++ llvm/trunk/include/llvm/Analysis/ScalarEvolution.h Wed Feb 18 11:22:41 2009 @@ -264,6 +264,11 @@ /// extended, it is zero extended. SCEVHandle getTruncateOrZeroExtend(const SCEVHandle &V, const Type *Ty); + /// getTruncateOrSignExtend - Return a SCEV corresponding to a conversion + /// of the input value to the specified type. If the type must be + /// extended, it is sign extended. + SCEVHandle getTruncateOrSignExtend(const SCEVHandle &V, const Type *Ty); + /// getIntegerSCEV - Given an integer or FP type, create a constant for the /// specified signed integer value and return a SCEV for the constant. SCEVHandle getIntegerSCEV(int Val, const Type *Ty); Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=64918&r1=64917&r2=64918&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original) +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Wed Feb 18 11:22:41 2009 @@ -755,6 +755,21 @@ return getZeroExtendExpr(V, Ty); } +/// getTruncateOrSignExtend - Return a SCEV corresponding to a conversion +/// of the input value to the specified type. If the type must be +/// extended, it is sign extended. +SCEVHandle ScalarEvolution::getTruncateOrSignExtend(const SCEVHandle &V, + const Type *Ty) { + const Type *SrcTy = V->getType(); + assert(SrcTy->isInteger() && Ty->isInteger() && + "Cannot truncate or sign extend with non-integer arguments!"); + if (SrcTy->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits()) + return V; // No conversion + if (SrcTy->getPrimitiveSizeInBits() > Ty->getPrimitiveSizeInBits()) + return getTruncateExpr(V, Ty); + return getSignExtendExpr(V, Ty); +} + // get - Get a canonical add expression, or something simpler if possible. SCEVHandle ScalarEvolution::getAddExpr(std::vector &Ops) { assert(!Ops.empty() && "Cannot get empty add!"); Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=64918&r1=64917&r2=64918&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Wed Feb 18 11:22:41 2009 @@ -96,7 +96,8 @@ Value *IndVar, BasicBlock *ExitingBlock, BranchInst *BI, - SCEVExpander &Rewriter); + SCEVExpander &Rewriter, + bool SignExtendTripCount); void RewriteLoopExitValues(Loop *L, SCEV *IterationCount); void DeleteTriviallyDeadInstructions(SmallPtrSet &Insts); @@ -235,7 +236,8 @@ Value *IndVar, BasicBlock *ExitingBlock, BranchInst *BI, - SCEVExpander &Rewriter) { + SCEVExpander &Rewriter, + bool SignExtendTripCount) { // If the exiting block is not the same as the backedge block, we must compare // against the preincremented value, otherwise we prefer to compare against // the post-incremented value. @@ -253,11 +255,18 @@ if ((isa(N) && !N->isZero()) || SE->isLoopGuardedByCond(L, ICmpInst::ICMP_NE, N, Zero)) { // No overflow. Cast the sum. - IterationCount = SE->getTruncateOrZeroExtend(N, IndVar->getType()); + if (SignExtendTripCount) + IterationCount = SE->getTruncateOrSignExtend(N, IndVar->getType()); + else + IterationCount = SE->getTruncateOrZeroExtend(N, IndVar->getType()); } else { // Potential overflow. Cast before doing the add. - IterationCount = SE->getTruncateOrZeroExtend(IterationCount, - IndVar->getType()); + if (SignExtendTripCount) + IterationCount = SE->getTruncateOrSignExtend(IterationCount, + IndVar->getType()); + else + IterationCount = SE->getTruncateOrZeroExtend(IterationCount, + IndVar->getType()); IterationCount = SE->getAddExpr(IterationCount, SE->getIntegerSCEV(1, IndVar->getType())); @@ -269,8 +278,12 @@ CmpIndVar = L->getCanonicalInductionVariableIncrement(); } else { // We have to use the preincremented value... - IterationCount = SE->getTruncateOrZeroExtend(IterationCount, - IndVar->getType()); + if (SignExtendTripCount) + IterationCount = SE->getTruncateOrSignExtend(IterationCount, + IndVar->getType()); + else + IterationCount = SE->getTruncateOrZeroExtend(IterationCount, + IndVar->getType()); CmpIndVar = IndVar; } @@ -464,10 +477,13 @@ /// TestOrigIVForWrap - Analyze the original induction variable /// that controls the loop's iteration to determine whether it -/// would ever undergo signed or unsigned overflow. +/// would ever undergo signed or unsigned overflow. Also, check +/// whether an induction variable in the same type that starts +/// at 0 would undergo signed overflow. /// -/// In addition to setting the NoSignedWrap and NoUnsignedWrap -/// variables, return the PHI for this induction variable. +/// In addition to setting the NoSignedWrap, NoUnsignedWrap, and +/// SignExtendTripCount variables, return the PHI for this induction +/// variable. /// /// TODO: This duplicates a fair amount of ScalarEvolution logic. /// Perhaps this can be merged with ScalarEvolution::getIterationCount @@ -477,7 +493,8 @@ const BranchInst *BI, const Instruction *OrigCond, bool &NoSignedWrap, - bool &NoUnsignedWrap) { + bool &NoUnsignedWrap, + bool &SignExtendTripCount) { // Verify that the loop is sane and find the exit condition. const ICmpInst *Cmp = dyn_cast(OrigCond); if (!Cmp) return 0; @@ -590,9 +607,13 @@ // The original induction variable will start at some non-max value, // it counts up by one, and the loop iterates only while it remans // less than some value in the same type. As such, it will never wrap. - if (isSigned && !InitialVal->getValue().isMaxSignedValue()) + if (isSigned && !InitialVal->getValue().isMaxSignedValue()) { NoSignedWrap = true; - else if (!isSigned && !InitialVal->getValue().isMaxValue()) + // If the original induction variable starts at zero or greater, + // the trip count can be considered signed. + if (InitialVal->getValue().isNonNegative()) + SignExtendTripCount = true; + } else if (!isSigned && !InitialVal->getValue().isMaxValue()) NoUnsignedWrap = true; return PN; } @@ -678,6 +699,7 @@ // using it. We can currently only handle loops with a single exit. bool NoSignedWrap = false; bool NoUnsignedWrap = false; + bool SignExtendTripCount = false; const PHINode *OrigControllingPHI = 0; if (!isa(IterationCount) && ExitingBlock) // Can't rewrite non-branch yet. @@ -686,14 +708,16 @@ // Determine if the OrigIV will ever undergo overflow. OrigControllingPHI = TestOrigIVForWrap(L, BI, OrigCond, - NoSignedWrap, NoUnsignedWrap); + NoSignedWrap, NoUnsignedWrap, + SignExtendTripCount); // We'll be replacing the original condition, so it'll be dead. DeadInsts.insert(OrigCond); } LinearFunctionTestReplace(L, IterationCount, IndVar, - ExitingBlock, BI, Rewriter); + ExitingBlock, BI, Rewriter, + SignExtendTripCount); } // Now that we have a canonical induction variable, we can rewrite any Modified: llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll?rev=64918&r1=64917&r2=64918&view=diff ============================================================================== --- llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll (original) +++ llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll Wed Feb 18 11:22:41 2009 @@ -1,5 +1,6 @@ ; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t -; RUN: grep sext %t | count 1 +; RUN: grep sext %t | count 2 +; RUN: grep { = sext i32 %n to i64} %t ; RUN: grep phi %t | count 1 ; RUN: grep {phi i64} %t Modified: llvm/trunk/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll?rev=64918&r1=64917&r2=64918&view=diff ============================================================================== --- llvm/trunk/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll (original) +++ llvm/trunk/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll Wed Feb 18 11:22:41 2009 @@ -1,6 +1,7 @@ -; RUN: llvm-as < %s | opt -indvars | llvm-dis | not grep sext - -target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128" +; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t +; RUN: grep sext %t | count 2 +; RUN: grep { = sext i16 %N to i64} %t +; RUN: grep { = sext i32 %count to i64} %t define i64 @test(i64* nocapture %first, i32 %count) nounwind readonly { entry: Added: llvm/trunk/test/Transforms/IndVarSimplify/signed-trip-count.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/signed-trip-count.ll?rev=64918&view=auto ============================================================================== --- llvm/trunk/test/Transforms/IndVarSimplify/signed-trip-count.ll (added) +++ llvm/trunk/test/Transforms/IndVarSimplify/signed-trip-count.ll Wed Feb 18 11:22:41 2009 @@ -0,0 +1,31 @@ +; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t +; RUN: grep { = sext i32 %n} %t +; RUN: grep phi %t | count 1 +; RUN: not grep zext %t + +define void @foo(i64* nocapture %x, i32 %n) nounwind { +entry: + %tmp102 = icmp sgt i32 %n, 0 ; [#uses=1] + br i1 %tmp102, label %bb.nph, label %return + +bb.nph: ; preds = %entry + br label %bb + +bb: ; preds = %bb7, %bb.nph + %i.01 = phi i32 [ %tmp6, %bb7 ], [ 0, %bb.nph ] ; [#uses=3] + %tmp1 = sext i32 %i.01 to i64 ; [#uses=1] + %tmp4 = getelementptr i64* %x, i32 %i.01 ; [#uses=1] + store i64 %tmp1, i64* %tmp4, align 8 + %tmp6 = add i32 %i.01, 1 ; [#uses=2] + br label %bb7 + +bb7: ; preds = %bb + %tmp10 = icmp slt i32 %tmp6, %n ; [#uses=1] + br i1 %tmp10, label %bb, label %bb7.return_crit_edge + +bb7.return_crit_edge: ; preds = %bb7 + br label %return + +return: ; preds = %bb7.return_crit_edge, %entry + ret void +} From dpatel at apple.com Wed Feb 18 11:29:39 2009 From: dpatel at apple.com (Devang Patel) Date: Wed, 18 Feb 2009 17:29:39 -0000 Subject: [llvm-commits] [llvm] r64920 - in /llvm/trunk: lib/CodeGen/AsmPrinter/DwarfWriter.cpp test/DebugInfo/2009-02-18-DefaultScope-Crash.ll Message-ID: <200902181729.n1IHTdXU020676@zion.cs.uiuc.edu> Author: dpatel Date: Wed Feb 18 11:29:38 2009 New Revision: 64920 URL: http://llvm.org/viewvc/llvm-project?rev=64920&view=rev Log: The subprogram die may not exist while creating "default" scope. Added: llvm/trunk/test/DebugInfo/2009-02-18-DefaultScope-Crash.ll Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp?rev=64920&r1=64919&r2=64920&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp (original) +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Wed Feb 18 11:29:38 2009 @@ -2125,7 +2125,10 @@ // Get the subprogram die. DIE *SPDie = Unit->getDieMapSlotFor(SPD.getGV()); - assert(SPDie && "Missing subprogram descriptor"); + if (!SPDie) + /* A subprogram die may not exist if the corresponding function + does not have any debug info. */ + continue; // Add the function bounds. AddLabel(SPDie, DW_AT_low_pc, DW_FORM_addr, Added: llvm/trunk/test/DebugInfo/2009-02-18-DefaultScope-Crash.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/2009-02-18-DefaultScope-Crash.ll?rev=64920&view=auto ============================================================================== --- llvm/trunk/test/DebugInfo/2009-02-18-DefaultScope-Crash.ll (added) +++ llvm/trunk/test/DebugInfo/2009-02-18-DefaultScope-Crash.ll Wed Feb 18 11:29:38 2009 @@ -0,0 +1,31 @@ +; RUN: llvm-as < %s | llc -f -o /dev/null + %llvm.dbg.anchor.type = type { i32, i32 } + %llvm.dbg.basictype.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, i32 } + %llvm.dbg.compile_unit.type = type { i32, { }*, i32, i8*, i8*, i8*, i1, i1, i8* } + %llvm.dbg.composite.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, { }*, { }* } + %llvm.dbg.subprogram.type = type { i32, { }*, { }*, i8*, i8*, i8*, { }*, i32, { }*, i1, i1 } + at llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { i32 458752, i32 17 }, section "llvm.metadata" ; <%llvm.dbg.anchor.type*> [#uses=1] + at .str = internal constant [4 x i8] c"a.c\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1] + at .str1 = internal constant [5 x i8] c"/tmp\00", section "llvm.metadata" ; <[5 x i8]*> [#uses=1] + at .str2 = internal constant [57 x i8] c"4.2.1 (Based on Apple Inc. build 5636) (LLVM build 2098)\00", section "llvm.metadata" ; <[57 x i8]*> [#uses=1] + at llvm.dbg.compile_unit = internal constant %llvm.dbg.compile_unit.type { i32 458769, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.compile_units to { }*), i32 1, i8* getelementptr ([4 x i8]* @.str, i32 0, i32 0), i8* getelementptr ([5 x i8]* @.str1, i32 0, i32 0), i8* getelementptr ([57 x i8]* @.str2, i32 0, i32 0), i1 true, i1 false, i8* null }, section "llvm.metadata" ; <%llvm.dbg.compile_unit.type*> [#uses=1] + at .str3 = internal constant [4 x i8] c"int\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1] + at llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type { i32 458788, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([4 x i8]* @.str3, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 32, i64 32, i64 0, i32 0, i32 5 }, section "llvm.metadata" ; <%llvm.dbg.basictype.type*> [#uses=1] + at llvm.dbg.array = internal constant [1 x { }*] [ { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*) ], section "llvm.metadata" ; <[1 x { }*]*> [#uses=1] + at llvm.dbg.composite = internal constant %llvm.dbg.composite.type { i32 458773, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 0, i64 0, i64 0, i32 0, { }* null, { }* bitcast ([1 x { }*]* @llvm.dbg.array to { }*) }, section "llvm.metadata" ; <%llvm.dbg.composite.type*> [#uses=1] + at llvm.dbg.subprograms = linkonce constant %llvm.dbg.anchor.type { i32 458752, i32 46 }, section "llvm.metadata" ; <%llvm.dbg.anchor.type*> [#uses=1] + at .str4 = internal constant [4 x i8] c"foo\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1] + at llvm.dbg.subprogram = internal constant %llvm.dbg.subprogram.type { i32 458798, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.subprograms to { }*), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([4 x i8]* @.str4, i32 0, i32 0), i8* getelementptr ([4 x i8]* @.str4, i32 0, i32 0), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 2, { }* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite to { }*), i1 false, i1 false }, section "llvm.metadata" ; <%llvm.dbg.subprogram.type*> [#uses=1] + + at llvm.dbg.array1 = internal constant [1 x { }*] [ { }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram to { }*) ], section "llvm.metadata" + +define i32 @foo() nounwind ssp { +entry: + ret i32 42 +} + +declare void @llvm.dbg.func.start({ }*) nounwind + +declare void @llvm.dbg.stoppoint(i32, i32, { }*) nounwind + +declare void @llvm.dbg.region.end({ }*) nounwind From rafael.espindola at gmail.com Wed Feb 18 11:49:06 2009 From: rafael.espindola at gmail.com (Rafael Espindola) Date: Wed, 18 Feb 2009 17:49:06 -0000 Subject: [llvm-commits] [llvm] r64923 - /llvm/trunk/tools/gold/gold-plugin.cpp Message-ID: <200902181749.n1IHn6xV021377@zion.cs.uiuc.edu> Author: rafael Date: Wed Feb 18 11:49:06 2009 New Revision: 64923 URL: http://llvm.org/viewvc/llvm-project?rev=64923&view=rev Log: really fix style Modified: llvm/trunk/tools/gold/gold-plugin.cpp Modified: llvm/trunk/tools/gold/gold-plugin.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=64923&r1=64922&r2=64923&view=diff ============================================================================== --- llvm/trunk/tools/gold/gold-plugin.cpp (original) +++ llvm/trunk/tools/gold/gold-plugin.cpp Wed Feb 18 11:49:06 2009 @@ -143,13 +143,13 @@ } if (!registeredClaimFile) { - (*message)(LDPL_ERROR, "register_claim_file not passed to LLVMgold."); - return LDPS_ERR; - } + (*message)(LDPL_ERROR, "register_claim_file not passed to LLVMgold."); + return LDPS_ERR; + } if (!add_symbols) { - (*message)(LDPL_ERROR, "add_symbols not passed to LLVMgold."); - return LDPS_ERR; - } + (*message)(LDPL_ERROR, "add_symbols not passed to LLVMgold."); + return LDPS_ERR; + } return LDPS_OK; } From baldrick at free.fr Wed Feb 18 11:55:38 2009 From: baldrick at free.fr (Duncan Sands) Date: Wed, 18 Feb 2009 17:55:38 -0000 Subject: [llvm-commits] [llvm] r64926 - /llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Message-ID: <200902181755.n1IHtcXf021645@zion.cs.uiuc.edu> Author: baldrick Date: Wed Feb 18 11:55:38 2009 New Revision: 64926 URL: http://llvm.org/viewvc/llvm-project?rev=64926&view=rev Log: In theory the aliasee may have dead constant users here. Since we only do the transform if there is one use, strip off any such users in the hope of making the transform fire more often. Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=64926&r1=64925&r2=64926&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original) +++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Wed Feb 18 11:55:38 2009 @@ -2383,6 +2383,7 @@ Constant *Aliasee = J->getAliasee(); GlobalValue *Target = cast(Aliasee->stripPointerCasts()); + Target->removeDeadConstantUsers(); bool hasOneUse = Target->hasOneUse() && Aliasee->hasOneUse(); // Make all users of the alias use the aliasee instead. From clattner at apple.com Wed Feb 18 12:07:49 2009 From: clattner at apple.com (Chris Lattner) Date: Wed, 18 Feb 2009 10:07:49 -0800 Subject: [llvm-commits] [llvm] r64918 - in /llvm/trunk: include/llvm/Analysis/ScalarEvolution.h lib/Analysis/ScalarEvolution.cpp lib/Transforms/Scalar/IndVarSimplify.cpp test/Transforms/IndVarSimplify/preserve-signed-wrap.ll test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll test/Transforms/IndVarSimplify/signed-trip-count.ll In-Reply-To: <200902181722.n1IHMiaX020433@zion.cs.uiuc.edu> References: <200902181722.n1IHMiaX020433@zion.cs.uiuc.edu> Message-ID: On Feb 18, 2009, at 9:22 AM, Dan Gohman wrote: > Author: djg > Date: Wed Feb 18 11:22:41 2009 > New Revision: 64918 > > URL: http://llvm.org/viewvc/llvm-project?rev=64918&view=rev > Log: > Use a sign-extend instead of a zero-extend when promoting a > trip count value when the original loop iteration condition is > signed and the canonical induction variable won't undergo signed > overflow. This isn't required for correctness; it just preserves > more information about original loop iteration values. Dan, I'm concerned about this. Sign extensions are generally more expensive than zero extensions, and much of the optimizer canonicalizes sign extends to zero extends. -Chris > > > Add a getTruncateOrSignExtend method to ScalarEvolution, > following getTruncateOrZeroExtend. > > Added: > llvm/trunk/test/Transforms/IndVarSimplify/signed-trip-count.ll > Modified: > llvm/trunk/include/llvm/Analysis/ScalarEvolution.h > llvm/trunk/lib/Analysis/ScalarEvolution.cpp > llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp > llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll > llvm/trunk/test/Transforms/IndVarSimplify/promote-iv-to-eliminate- > casts.ll > > Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolution.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolution.h?rev=64918&r1=64917&r2=64918&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- llvm/trunk/include/llvm/Analysis/ScalarEvolution.h (original) > +++ llvm/trunk/include/llvm/Analysis/ScalarEvolution.h Wed Feb 18 > 11:22:41 2009 > @@ -264,6 +264,11 @@ > /// extended, it is zero extended. > SCEVHandle getTruncateOrZeroExtend(const SCEVHandle &V, const > Type *Ty); > > + /// getTruncateOrSignExtend - Return a SCEV corresponding to a > conversion > + /// of the input value to the specified type. If the type must > be > + /// extended, it is sign extended. > + SCEVHandle getTruncateOrSignExtend(const SCEVHandle &V, const > Type *Ty); > + > /// getIntegerSCEV - Given an integer or FP type, create a > constant for the > /// specified signed integer value and return a SCEV for the > constant. > SCEVHandle getIntegerSCEV(int Val, const Type *Ty); > > Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=64918&r1=64917&r2=64918&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original) > +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Wed Feb 18 11:22:41 > 2009 > @@ -755,6 +755,21 @@ > return getZeroExtendExpr(V, Ty); > } > > +/// getTruncateOrSignExtend - Return a SCEV corresponding to a > conversion > +/// of the input value to the specified type. If the type must be > +/// extended, it is sign extended. > +SCEVHandle ScalarEvolution::getTruncateOrSignExtend(const > SCEVHandle &V, > + const Type *Ty) { > + const Type *SrcTy = V->getType(); > + assert(SrcTy->isInteger() && Ty->isInteger() && > + "Cannot truncate or sign extend with non-integer > arguments!"); > + if (SrcTy->getPrimitiveSizeInBits() == Ty- > >getPrimitiveSizeInBits()) > + return V; // No conversion > + if (SrcTy->getPrimitiveSizeInBits() > Ty->getPrimitiveSizeInBits()) > + return getTruncateExpr(V, Ty); > + return getSignExtendExpr(V, Ty); > +} > + > // get - Get a canonical add expression, or something simpler if > possible. > SCEVHandle ScalarEvolution::getAddExpr(std::vector &Ops) { > assert(!Ops.empty() && "Cannot get empty add!"); > > Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=64918&r1=64917&r2=64918&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original) > +++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Wed Feb 18 > 11:22:41 2009 > @@ -96,7 +96,8 @@ > Value *IndVar, > BasicBlock *ExitingBlock, > BranchInst *BI, > - SCEVExpander &Rewriter); > + SCEVExpander &Rewriter, > + bool SignExtendTripCount); > void RewriteLoopExitValues(Loop *L, SCEV *IterationCount); > > void DeleteTriviallyDeadInstructions(SmallPtrSet 16> &Insts); > @@ -235,7 +236,8 @@ > Value *IndVar, > BasicBlock *ExitingBlock, > BranchInst *BI, > - SCEVExpander &Rewriter) { > + SCEVExpander &Rewriter, > + bool SignExtendTripCount) { > // If the exiting block is not the same as the backedge block, we > must compare > // against the preincremented value, otherwise we prefer to > compare against > // the post-incremented value. > @@ -253,11 +255,18 @@ > if ((isa(N) && !N->isZero()) || > SE->isLoopGuardedByCond(L, ICmpInst::ICMP_NE, N, Zero)) { > // No overflow. Cast the sum. > - IterationCount = SE->getTruncateOrZeroExtend(N, IndVar- > >getType()); > + if (SignExtendTripCount) > + IterationCount = SE->getTruncateOrSignExtend(N, IndVar- > >getType()); > + else > + IterationCount = SE->getTruncateOrZeroExtend(N, IndVar- > >getType()); > } else { > // Potential overflow. Cast before doing the add. > - IterationCount = SE->getTruncateOrZeroExtend(IterationCount, > - IndVar- > >getType()); > + if (SignExtendTripCount) > + IterationCount = SE->getTruncateOrSignExtend(IterationCount, > + IndVar- > >getType()); > + else > + IterationCount = SE->getTruncateOrZeroExtend(IterationCount, > + IndVar- > >getType()); > IterationCount = > SE->getAddExpr(IterationCount, > SE->getIntegerSCEV(1, IndVar->getType())); > @@ -269,8 +278,12 @@ > CmpIndVar = L->getCanonicalInductionVariableIncrement(); > } else { > // We have to use the preincremented value... > - IterationCount = SE->getTruncateOrZeroExtend(IterationCount, > - IndVar->getType()); > + if (SignExtendTripCount) > + IterationCount = SE->getTruncateOrSignExtend(IterationCount, > + IndVar- > >getType()); > + else > + IterationCount = SE->getTruncateOrZeroExtend(IterationCount, > + IndVar- > >getType()); > CmpIndVar = IndVar; > } > > @@ -464,10 +477,13 @@ > > /// TestOrigIVForWrap - Analyze the original induction variable > /// that controls the loop's iteration to determine whether it > -/// would ever undergo signed or unsigned overflow. > +/// would ever undergo signed or unsigned overflow. Also, check > +/// whether an induction variable in the same type that starts > +/// at 0 would undergo signed overflow. > /// > -/// In addition to setting the NoSignedWrap and NoUnsignedWrap > -/// variables, return the PHI for this induction variable. > +/// In addition to setting the NoSignedWrap, NoUnsignedWrap, and > +/// SignExtendTripCount variables, return the PHI for this induction > +/// variable. > /// > /// TODO: This duplicates a fair amount of ScalarEvolution logic. > /// Perhaps this can be merged with ScalarEvolution::getIterationCount > @@ -477,7 +493,8 @@ > const BranchInst *BI, > const Instruction *OrigCond, > bool &NoSignedWrap, > - bool &NoUnsignedWrap) { > + bool &NoUnsignedWrap, > + bool &SignExtendTripCount) { > // Verify that the loop is sane and find the exit condition. > const ICmpInst *Cmp = dyn_cast(OrigCond); > if (!Cmp) return 0; > @@ -590,9 +607,13 @@ > // The original induction variable will start at some non-max value, > // it counts up by one, and the loop iterates only while it remans > // less than some value in the same type. As such, it will never > wrap. > - if (isSigned && !InitialVal->getValue().isMaxSignedValue()) > + if (isSigned && !InitialVal->getValue().isMaxSignedValue()) { > NoSignedWrap = true; > - else if (!isSigned && !InitialVal->getValue().isMaxValue()) > + // If the original induction variable starts at zero or greater, > + // the trip count can be considered signed. > + if (InitialVal->getValue().isNonNegative()) > + SignExtendTripCount = true; > + } else if (!isSigned && !InitialVal->getValue().isMaxValue()) > NoUnsignedWrap = true; > return PN; > } > @@ -678,6 +699,7 @@ > // using it. We can currently only handle loops with a single exit. > bool NoSignedWrap = false; > bool NoUnsignedWrap = false; > + bool SignExtendTripCount = false; > const PHINode *OrigControllingPHI = 0; > if (!isa(IterationCount) && ExitingBlock) > // Can't rewrite non-branch yet. > @@ -686,14 +708,16 @@ > // Determine if the OrigIV will ever undergo overflow. > OrigControllingPHI = > TestOrigIVForWrap(L, BI, OrigCond, > - NoSignedWrap, NoUnsignedWrap); > + NoSignedWrap, NoUnsignedWrap, > + SignExtendTripCount); > > // We'll be replacing the original condition, so it'll be > dead. > DeadInsts.insert(OrigCond); > } > > LinearFunctionTestReplace(L, IterationCount, IndVar, > - ExitingBlock, BI, Rewriter); > + ExitingBlock, BI, Rewriter, > + SignExtendTripCount); > } > > // Now that we have a canonical induction variable, we can rewrite > any > > Modified: llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed- > wrap.ll > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll?rev=64918&r1=64917&r2=64918&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed- > wrap.ll (original) > +++ llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed- > wrap.ll Wed Feb 18 11:22:41 2009 > @@ -1,5 +1,6 @@ > ; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t > -; RUN: grep sext %t | count 1 > +; RUN: grep sext %t | count 2 > +; RUN: grep { = sext i32 %n to i64} %t > ; RUN: grep phi %t | count 1 > ; RUN: grep {phi i64} %t > > > Modified: llvm/trunk/test/Transforms/IndVarSimplify/promote-iv-to- > eliminate-casts.ll > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll?rev=64918&r1=64917&r2=64918&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- llvm/trunk/test/Transforms/IndVarSimplify/promote-iv-to- > eliminate-casts.ll (original) > +++ llvm/trunk/test/Transforms/IndVarSimplify/promote-iv-to- > eliminate-casts.ll Wed Feb 18 11:22:41 2009 > @@ -1,6 +1,7 @@ > -; RUN: llvm-as < %s | opt -indvars | llvm-dis | not grep sext > - > -target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32- > i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64- > s0:64:64-f80:128:128" > +; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t > +; RUN: grep sext %t | count 2 > +; RUN: grep { = sext i16 %N to i64} %t > +; RUN: grep { = sext i32 %count to i64} %t > > define i64 @test(i64* nocapture %first, i32 %count) nounwind > readonly { > entry: > > Added: llvm/trunk/test/Transforms/IndVarSimplify/signed-trip-count.ll > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/signed-trip-count.ll?rev=64918&view=auto > > = > = > = > = > = > = > = > = > ====================================================================== > --- llvm/trunk/test/Transforms/IndVarSimplify/signed-trip-count.ll > (added) > +++ llvm/trunk/test/Transforms/IndVarSimplify/signed-trip-count.ll > Wed Feb 18 11:22:41 2009 > @@ -0,0 +1,31 @@ > +; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t > +; RUN: grep { = sext i32 %n} %t > +; RUN: grep phi %t | count 1 > +; RUN: not grep zext %t > + > +define void @foo(i64* nocapture %x, i32 %n) nounwind { > +entry: > + %tmp102 = icmp sgt i32 %n, 0 ; [#uses=1] > + br i1 %tmp102, label %bb.nph, label %return > + > +bb.nph: ; preds = %entry > + br label %bb > + > +bb: ; preds = %bb7, %bb.nph > + %i.01 = phi i32 [ %tmp6, %bb7 ], [ 0, %bb.nph ] ; [#uses=3] > + %tmp1 = sext i32 %i.01 to i64 ; [#uses=1] > + %tmp4 = getelementptr i64* %x, i32 %i.01 ; [#uses=1] > + store i64 %tmp1, i64* %tmp4, align 8 > + %tmp6 = add i32 %i.01, 1 ; [#uses=2] > + br label %bb7 > + > +bb7: ; preds = %bb > + %tmp10 = icmp slt i32 %tmp6, %n ; [#uses=1] > + br i1 %tmp10, label %bb, label %bb7.return_crit_edge > + > +bb7.return_crit_edge: ; preds = %bb7 > + br label %return > + > +return: ; preds = %bb7.return_crit_edge, %entry > + ret void > +} > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits From evan.cheng at apple.com Wed Feb 18 12:38:24 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Wed, 18 Feb 2009 18:38:24 -0000 Subject: [llvm-commits] [test-suite] r64931 - /test-suite/trunk/Makefile.programs Message-ID: <200902181838.n1IIcOG1005354@zion.cs.uiuc.edu> Author: evancheng Date: Wed Feb 18 12:38:24 2009 New Revision: 64931 URL: http://llvm.org/viewvc/llvm-project?rev=64931&view=rev Log: Switch ppc llcbeta to -regalloc=local -fast. Modified: test-suite/trunk/Makefile.programs Modified: test-suite/trunk/Makefile.programs URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/Makefile.programs?rev=64931&r1=64930&r2=64931&view=diff ============================================================================== --- test-suite/trunk/Makefile.programs (original) +++ test-suite/trunk/Makefile.programs Wed Feb 18 12:38:24 2009 @@ -211,10 +211,10 @@ endif#DISABLE_DIFFS ifeq ($(ARCH),PowerPC) -LLCBETAOPTION := --enable-ppc-preinc +LLCBETAOPTION := -regalloc=local -fast +#--enable-ppc-preinc #-aggressive-remat #--enable-tail-merge -#-regalloc=local -fast endif ifeq ($(ARCH),Alpha) LLCBETAOPTION := -sched=list-td From baldrick at free.fr Wed Feb 18 12:48:40 2009 From: baldrick at free.fr (Duncan Sands) Date: Wed, 18 Feb 2009 18:48:40 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64933 - in /llvm-gcc-4.2/trunk/gcc: llvm-backend.cpp llvm-convert.cpp llvm-internal.h Message-ID: <200902181848.n1IImec0005740@zion.cs.uiuc.edu> Author: baldrick Date: Wed Feb 18 12:48:40 2009 New Revision: 64933 URL: http://llvm.org/viewvc/llvm-project?rev=64933&view=rev Log: Rename changeLLVMValue to changeLLVMConstant (since that's all it can change) and make it update all the relevant maps that constants get cached in. Previously various places were doing this to different extents. While there, it struck me that the DECL_LLVM handling logic would be more naturally at home in llvm-backend, so I've moved it there. Finally, I changed the StaticCtors and StaticDtors containers to hold constants and not just functions (this is needed for future work on the LLVM one-definition-rule). Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp llvm-gcc-4.2/trunk/gcc/llvm-internal.h Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=64933&r1=64932&r2=64933&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Wed Feb 18 12:48:40 2009 @@ -92,7 +92,7 @@ /// optimizations off. static cl::opt DisableLLVMOptimizations("disable-llvm-optzns"); -std::vector > StaticCtors, StaticDtors; +std::vector > StaticCtors, StaticDtors; SmallSetVector AttributeUsedGlobals; std::vector AttributeAnnotateGlobals; @@ -107,6 +107,203 @@ static void createPerModuleOptimizationPasses(); static void destroyOptimizationPasses(); +//===----------------------------------------------------------------------===// +// Matching LLVM Values with GCC DECL trees +//===----------------------------------------------------------------------===// +// +// LLVMValues is a vector of LLVM Values. GCC tree nodes keep track of LLVM +// Values using this vector's index. It is easier to save and restore the index +// than the LLVM Value pointer while using PCH. + +// Collection of LLVM Values +static std::vector LLVMValues; +typedef DenseMap LLVMValuesMapTy; +static LLVMValuesMapTy LLVMValuesMap; + +/// LocalLLVMValueIDs - This is the set of local IDs we have in our mapping, +/// this allows us to efficiently identify and remove them. Local IDs are IDs +/// for values that are local to the current function being processed. These do +/// not need to go into the PCH file, but DECL_LLVM still needs a valid index +/// while converting the function. Using "Local IDs" allows the IDs for +/// function-local decls to be recycled after the function is done. +static std::vector LocalLLVMValueIDs; + +// Remember the LLVM value for GCC tree node. +void llvm_set_decl(tree Tr, Value *V) { + + // If there is not any value then do not add new LLVMValues entry. + // However clear Tr index if it is non zero. + if (!V) { + if (GET_DECL_LLVM_INDEX(Tr)) + SET_DECL_LLVM_INDEX(Tr, 0); + return; + } + + unsigned &ValueSlot = LLVMValuesMap[V]; + if (ValueSlot) { + // Already in map + SET_DECL_LLVM_INDEX(Tr, ValueSlot); + return; + } + + LLVMValues.push_back(V); + unsigned Index = LLVMValues.size(); + SET_DECL_LLVM_INDEX(Tr, Index); + LLVMValuesMap[V] = Index; + + // Remember local values. + if (!isa(V)) + LocalLLVMValueIDs.push_back(Index); +} + +// Return TRUE if there is a LLVM Value associate with GCC tree node. +bool llvm_set_decl_p(tree Tr) { + unsigned Index = GET_DECL_LLVM_INDEX(Tr); + if (Index == 0) + return false; + + return LLVMValues[Index - 1] != 0; +} + +// Get LLVM Value for the GCC tree node based on LLVMValues vector index. +// If there is not any value associated then use make_decl_llvm() to +// make LLVM value. When GCC tree node is initialized, it has 0 as the +// index value. This is why all recorded indices are offset by 1. +Value *llvm_get_decl(tree Tr) { + + unsigned Index = GET_DECL_LLVM_INDEX(Tr); + if (Index == 0) { + make_decl_llvm(Tr); + Index = GET_DECL_LLVM_INDEX(Tr); + + // If there was an error, we may have disabled creating LLVM values. + if (Index == 0) return 0; + } + assert((Index - 1) < LLVMValues.size() && "Invalid LLVM value index"); + assert(LLVMValues[Index - 1] && "Trying to use deleted LLVM value!"); + + return LLVMValues[Index - 1]; +} + +/// changeLLVMConstant - Replace Old with New everywhere, updating all maps +/// (except for AttributeAnnotateGlobals, which is a different kind of animal). +/// At this point we know that New is not in any of these maps. +void changeLLVMConstant(Constant *Old, Constant *New) { + assert(Old->use_empty() && "Old value has uses!"); + + if (AttributeUsedGlobals.count(Old)) { + AttributeUsedGlobals.remove(Old); + AttributeUsedGlobals.insert(New); + } + + for (unsigned i = 0, e = StaticCtors.size(); i != e; ++i) { + if (StaticCtors[i].first == Old) + StaticCtors[i].first = New; + } + + for (unsigned i = 0, e = StaticDtors.size(); i != e; ++i) { + if (StaticDtors[i].first == Old) + StaticDtors[i].first = New; + } + + assert(!LLVMValuesMap.count(New) && "New cannot be in the LLVMValues map!"); + + // Find Old in the table. + LLVMValuesMapTy::iterator I = LLVMValuesMap.find(Old); + if (I == LLVMValuesMap.end()) return; + + unsigned Idx = I->second-1; + assert(Idx < LLVMValues.size() && "Out of range index!"); + assert(LLVMValues[Idx] == Old && "Inconsistent LLVMValues mapping!"); + + LLVMValues[Idx] = New; + + // Remove the old value from the value map. + LLVMValuesMap.erase(I); + + // Insert the new value into the value map. We know that it can't already + // exist in the mapping. + if (New) + LLVMValuesMap[New] = Idx+1; +} + +// Read LLVM Types string table +void readLLVMValues() { + GlobalValue *V = TheModule->getNamedGlobal("llvm.pch.values"); + if (!V) + return; + + GlobalVariable *GV = cast(V); + ConstantStruct *ValuesFromPCH = cast(GV->getOperand(0)); + + for (unsigned i = 0; i < ValuesFromPCH->getNumOperands(); ++i) { + Value *Va = ValuesFromPCH->getOperand(i); + + if (!Va) { + // If V is empty then insert NULL to represent empty entries. + LLVMValues.push_back(Va); + continue; + } + if (ConstantArray *CA = dyn_cast(Va)) { + std::string Str = CA->getAsString(); + Va = TheModule->getValueSymbolTable().lookup(Str); + } + assert (Va != NULL && "Invalid Value in LLVMValues string table"); + LLVMValues.push_back(Va); + } + + // Now, llvm.pch.values is not required so remove it from the symbol table. + GV->eraseFromParent(); +} + +// GCC tree's uses LLVMValues vector's index to reach LLVM Values. +// Create a string table to hold these LLVM Values' names. This string +// table will be used to recreate LTypes vector after loading PCH. +void writeLLVMValues() { + if (LLVMValues.empty()) + return; + + std::vector ValuesForPCH; + for (std::vector::iterator I = LLVMValues.begin(), + E = LLVMValues.end(); I != E; ++I) { + if (Constant *C = dyn_cast_or_null(*I)) + ValuesForPCH.push_back(C); + else + // Non constant values, e.g. arguments, are not at global scope. + // When PCH is read, only global scope values are used. + ValuesForPCH.push_back(Constant::getNullValue(Type::Int32Ty)); + } + + // Create string table. + Constant *LLVMValuesTable = ConstantStruct::get(ValuesForPCH, false); + + // Create variable to hold this string table. + new GlobalVariable(LLVMValuesTable->getType(), true, + GlobalValue::ExternalLinkage, + LLVMValuesTable, + "llvm.pch.values", TheModule); +} + +/// eraseLocalLLVMValues - drop all non-global values from the LLVM values map. +void eraseLocalLLVMValues() { + // Erase all the local values, these are stored in LocalLLVMValueIDs. + while (!LocalLLVMValueIDs.empty()) { + unsigned Idx = LocalLLVMValueIDs.back()-1; + LocalLLVMValueIDs.pop_back(); + + if (Value *V = LLVMValues[Idx]) { + assert(!isa(V) && "Found global value"); + LLVMValuesMap.erase(V); + } + + if (Idx == LLVMValues.size()-1) + LLVMValues.pop_back(); + else + LLVMValues[Idx] = 0; + } +} + + // Forward decl visibility style to global. void handleVisibility(tree decl, GlobalValue *GV) { // If decl has visibility specified explicitely (via attribute) - honour @@ -598,7 +795,7 @@ /// ConvertStructorsList - Convert a list of static ctors/dtors to an /// initializer suitable for the llvm.global_[cd]tors globals. -static void CreateStructorsList(std::vector > &Tors, +static void CreateStructorsList(std::vector > &Tors, const char *Name) { std::vector InitList; std::vector StructInit; @@ -641,7 +838,7 @@ // Add an llvm.global_dtors global if needed. if (!StaticDtors.empty()) CreateStructorsList(StaticDtors, "llvm.global_dtors"); - + if (!AttributeUsedGlobals.empty()) { std::vector AUGs; const Type *SBP= PointerType::getUnqual(Type::Int8Ty); @@ -653,7 +850,7 @@ ArrayType *AT = ArrayType::get(SBP, AUGs.size()); Constant *Init = ConstantArray::get(AT, AUGs); - GlobalValue *gv = new GlobalVariable(AT, false, + GlobalValue *gv = new GlobalVariable(AT, false, GlobalValue::AppendingLinkage, Init, "llvm.used", TheModule); gv->setSection("llvm.metadata"); @@ -662,19 +859,17 @@ // Add llvm.global.annotations if (!AttributeAnnotateGlobals.empty()) { - Constant *Array = - ConstantArray::get(ArrayType::get(AttributeAnnotateGlobals[0]->getType(), + ConstantArray::get(ArrayType::get(AttributeAnnotateGlobals[0]->getType(), AttributeAnnotateGlobals.size()), AttributeAnnotateGlobals); - GlobalValue *gv = new GlobalVariable(Array->getType(), false, - GlobalValue::AppendingLinkage, Array, - "llvm.global.annotations", TheModule); + GlobalValue *gv = new GlobalVariable(Array->getType(), false, + GlobalValue::AppendingLinkage, Array, + "llvm.global.annotations", TheModule); gv->setSection("llvm.metadata"); AttributeAnnotateGlobals.clear(); - } - + // Finish off the per-function pass. if (PerFunctionPasses) PerFunctionPasses->doFinalization(); @@ -876,7 +1071,7 @@ return; } - changeLLVMValue(V, GA); + changeLLVMConstant(V, GA); GA->takeName(V); if (GlobalVariable *GV = dyn_cast(V)) GV->eraseFromParent(); @@ -1018,11 +1213,7 @@ GV->getName(), TheModule); NGV->setVisibility(GV->getVisibility()); GV->replaceAllUsesWith(TheFolder->CreateBitCast(NGV, GV->getType())); - if (AttributeUsedGlobals.count(GV)) { - AttributeUsedGlobals.remove(GV); - AttributeUsedGlobals.insert(NGV); - } - changeLLVMValue(GV, NGV); + changeLLVMConstant(GV, NGV); delete GV; SET_DECL_LLVM(decl, NGV); GV = NGV; @@ -1090,11 +1281,7 @@ GlobalValue::ExternalLinkage, 0, GV->getName(), TheModule); GV->replaceAllUsesWith(TheFolder->CreateBitCast(NGV, GV->getType())); - if (AttributeUsedGlobals.count(GV)) { - AttributeUsedGlobals.remove(GV); - AttributeUsedGlobals.insert(NGV); - } - changeLLVMValue(GV, NGV); + changeLLVMConstant(GV, NGV); delete GV; SET_DECL_LLVM(decl, NGV); GV = NGV; @@ -1327,14 +1514,14 @@ if (FnEntry->getName() != Name) { GlobalVariable *G = TheModule->getGlobalVariable(Name, true); assert(G && G->isDeclaration() && "A global turned into a function?"); - + // Replace any uses of "G" with uses of FnEntry. - Value *GInNewType = TheFolder->CreateBitCast(FnEntry, G->getType()); + Constant *GInNewType = TheFolder->CreateBitCast(FnEntry, G->getType()); G->replaceAllUsesWith(GInNewType); - + // Update the decl that points to G. - changeLLVMValue(G, GInNewType); - + changeLLVMConstant(G, GInNewType); + // Now we can give GV the proper name. FnEntry->takeName(G); @@ -1393,11 +1580,11 @@ assert(F && F->isDeclaration() && "A function turned into a global?"); // Replace any uses of "F" with uses of GV. - Value *FInNewType = TheFolder->CreateBitCast(GV, F->getType()); + Constant *FInNewType = TheFolder->CreateBitCast(GV, F->getType()); F->replaceAllUsesWith(FInNewType); - + // Update the decl that points to F. - changeLLVMValue(F, FInNewType); + changeLLVMConstant(F, FInNewType); // Now we can give GV the proper name. GV->takeName(F); @@ -1474,11 +1661,11 @@ // void llvm_emit_ctor_dtor(tree FnDecl, int InitPrio, int isCtor) { mark_decl_referenced(FnDecl); // Inform cgraph that we used the global. - + if (errorcount || sorrycount) return; - - Function *F = cast_or_null(DECL_LLVM(FnDecl)); - (isCtor ? &StaticCtors:&StaticDtors)->push_back(std::make_pair(F, InitPrio)); + + Constant *C = cast(DECL_LLVM(FnDecl)); + (isCtor ? &StaticCtors:&StaticDtors)->push_back(std::make_pair(C, InitPrio)); } void llvm_emit_typedef(tree decl) { Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=64933&r1=64932&r2=64933&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Wed Feb 18 12:48:40 2009 @@ -78,186 +78,6 @@ TREE_CODE(DECL_INITIAL(exp)) == CONSTRUCTOR && \ !TREE_TYPE(DECL_INITIAL(exp))) -//===----------------------------------------------------------------------===// -// Matching LLVM Values with GCC DECL trees -//===----------------------------------------------------------------------===// -// -// LLVMValues is a vector of LLVM Values. GCC tree nodes keep track of LLVM -// Values using this vector's index. It is easier to save and restore the index -// than the LLVM Value pointer while using PCH. - -// Collection of LLVM Values -static std::vector LLVMValues; -typedef DenseMap LLVMValuesMapTy; -static LLVMValuesMapTy LLVMValuesMap; - -/// LocalLLVMValueIDs - This is the set of local IDs we have in our mapping, -/// this allows us to efficiently identify and remove them. Local IDs are IDs -/// for values that are local to the current function being processed. These do -/// not need to go into the PCH file, but DECL_LLVM still needs a valid index -/// while converting the function. Using "Local IDs" allows the IDs for -/// function-local decls to be recycled after the function is done. -static std::vector LocalLLVMValueIDs; - -// Remember the LLVM value for GCC tree node. -void llvm_set_decl(tree Tr, Value *V) { - - // If there is not any value then do not add new LLVMValues entry. - // However clear Tr index if it is non zero. - if (!V) { - if (GET_DECL_LLVM_INDEX(Tr)) - SET_DECL_LLVM_INDEX(Tr, 0); - return; - } - - unsigned &ValueSlot = LLVMValuesMap[V]; - if (ValueSlot) { - // Already in map - SET_DECL_LLVM_INDEX(Tr, ValueSlot); - return; - } - - LLVMValues.push_back(V); - unsigned Index = LLVMValues.size(); - SET_DECL_LLVM_INDEX(Tr, Index); - LLVMValuesMap[V] = Index; - - // Remember local values. - if (!isa(V)) - LocalLLVMValueIDs.push_back(Index); -} - -// Return TRUE if there is a LLVM Value associate with GCC tree node. -bool llvm_set_decl_p(tree Tr) { - unsigned Index = GET_DECL_LLVM_INDEX(Tr); - if (Index == 0) - return false; - - return LLVMValues[Index - 1] != 0; -} - -// Get LLVM Value for the GCC tree node based on LLVMValues vector index. -// If there is not any value associated then use make_decl_llvm() to -// make LLVM value. When GCC tree node is initialized, it has 0 as the -// index value. This is why all recorded indices are offset by 1. -Value *llvm_get_decl(tree Tr) { - - unsigned Index = GET_DECL_LLVM_INDEX(Tr); - if (Index == 0) { - make_decl_llvm(Tr); - Index = GET_DECL_LLVM_INDEX(Tr); - - // If there was an error, we may have disabled creating LLVM values. - if (Index == 0) return 0; - } - assert((Index - 1) < LLVMValues.size() && "Invalid LLVM value index"); - assert(LLVMValues[Index - 1] && "Trying to use deleted LLVM value!"); - - return LLVMValues[Index - 1]; -} - -/// changeLLVMValue - If Old exists in the LLVMValues map, rewrite it to New. -/// At this point we know that New is not in the map. -void changeLLVMValue(Value *Old, Value *New) { - assert(isa(Old) && isa(New) && - "Cannot change local values"); - assert(!LLVMValuesMap.count(New) && "New cannot be in the map!"); - - // Find Old in the table. - LLVMValuesMapTy::iterator I = LLVMValuesMap.find(Old); - if (I == LLVMValuesMap.end()) return; - - unsigned Idx = I->second-1; - assert(Idx < LLVMValues.size() && "Out of range index!"); - assert(LLVMValues[Idx] == Old && "Inconsistent LLVMValues mapping!"); - - LLVMValues[Idx] = New; - - // Remove the old value from the value map. - LLVMValuesMap.erase(I); - - // Insert the new value into the value map. We know that it can't already - // exist in the mapping. - if (New) - LLVMValuesMap[New] = Idx+1; -} - -// Read LLVM Types string table -void readLLVMValues() { - GlobalValue *V = TheModule->getNamedGlobal("llvm.pch.values"); - if (!V) - return; - - GlobalVariable *GV = cast(V); - ConstantStruct *ValuesFromPCH = cast(GV->getOperand(0)); - - for (unsigned i = 0; i < ValuesFromPCH->getNumOperands(); ++i) { - Value *Va = ValuesFromPCH->getOperand(i); - - if (!Va) { - // If V is empty then insert NULL to represent empty entries. - LLVMValues.push_back(Va); - continue; - } - if (ConstantArray *CA = dyn_cast(Va)) { - std::string Str = CA->getAsString(); - Va = TheModule->getValueSymbolTable().lookup(Str); - } - assert (Va != NULL && "Invalid Value in LLVMValues string table"); - LLVMValues.push_back(Va); - } - - // Now, llvm.pch.values is not required so remove it from the symbol table. - GV->eraseFromParent(); -} - -// GCC tree's uses LLVMValues vector's index to reach LLVM Values. -// Create a string table to hold these LLVM Values' names. This string -// table will be used to recreate LTypes vector after loading PCH. -void writeLLVMValues() { - if (LLVMValues.empty()) - return; - - std::vector ValuesForPCH; - for (std::vector::iterator I = LLVMValues.begin(), - E = LLVMValues.end(); I != E; ++I) { - if (Constant *C = dyn_cast_or_null(*I)) - ValuesForPCH.push_back(C); - else - // Non constant values, e.g. arguments, are not at global scope. - // When PCH is read, only global scope values are used. - ValuesForPCH.push_back(Constant::getNullValue(Type::Int32Ty)); - } - - // Create string table. - Constant *LLVMValuesTable = ConstantStruct::get(ValuesForPCH, false); - - // Create variable to hold this string table. - new GlobalVariable(LLVMValuesTable->getType(), true, - GlobalValue::ExternalLinkage, - LLVMValuesTable, - "llvm.pch.values", TheModule); -} - -/// eraseLocalLLVMValues - drop all non-global values from the LLVM values map. -void eraseLocalLLVMValues() { - // Erase all the local values, these are stored in LocalLLVMValueIDs. - while (!LocalLLVMValueIDs.empty()) { - unsigned Idx = LocalLLVMValueIDs.back()-1; - LocalLLVMValueIDs.pop_back(); - - if (Value *V = LLVMValues[Idx]) { - assert(!isa(V) && "Found global value"); - LLVMValuesMap.erase(V); - } - - if (Idx == LLVMValues.size()-1) - LLVMValues.pop_back(); - else - LLVMValues[Idx] = 0; - } -} - /// isGimpleTemporary - Return true if this is a gimple temporary that we can /// directly compile into an LLVM temporary. This saves us from creating an /// alloca and creating loads/stores of that alloca (a compile-time win). We @@ -628,7 +448,7 @@ FnEntry->replaceAllUsesWith( Builder.getFolder().CreateBitCast(Fn, FnEntry->getType()) ); - changeLLVMValue(FnEntry, Fn); + changeLLVMConstant(FnEntry, Fn); FnEntry->eraseFromParent(); } SET_DECL_LLVM(FnDecl, Fn); Modified: llvm-gcc-4.2/trunk/gcc/llvm-internal.h URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-internal.h?rev=64933&r1=64932&r2=64933&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-internal.h (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-internal.h Wed Feb 18 12:48:40 2009 @@ -93,10 +93,6 @@ /// extern llvm::OStream *AsmOutFile; -/// StaticCtors/StaticDtors - The static constructors and destructors that we -/// need to emit. -extern std::vector > StaticCtors, StaticDtors; - /// AttributeUsedGlobals - The list of globals that are marked attribute(used). extern SmallSetVector AttributeUsedGlobals; @@ -106,11 +102,12 @@ /// annotate attribute to a vector to be emitted later. extern void AddAnnotateAttrsToGlobal(GlobalValue *GV, union tree_node* decl); -void changeLLVMValue(Value *Old, Value *New); +void changeLLVMConstant(Constant *Old, Constant *New); void readLLVMTypesStringTable(); void writeLLVMTypesStringTable(); void readLLVMValues(); void writeLLVMValues(); +void eraseLocalLLVMValues(); void clearTargetBuiltinCache(); const char* extractRegisterName(union tree_node*); void handleVisibility(union tree_node* decl, GlobalValue *GV); From evan.cheng at apple.com Wed Feb 18 12:55:59 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Wed, 18 Feb 2009 18:55:59 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64938 - /llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Message-ID: <200902181855.n1IItxxb006089@zion.cs.uiuc.edu> Author: evancheng Date: Wed Feb 18 12:55:59 2009 New Revision: 64938 URL: http://llvm.org/viewvc/llvm-project?rev=64938&view=rev Log: If FullPath is null, use main_input_filename. This avoids initializing a std::string with null. Modified: llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Modified: llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp?rev=64938&r1=64937&r2=64938&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Wed Feb 18 12:55:59 2009 @@ -828,9 +828,10 @@ /// getOrCreateCompileUnit - Get the compile unit from the cache or /// create a new one if necessary. DICompileUnit DebugInfo::getOrCreateCompileUnit(const char *FullPath, - bool isMain){ - - GlobalVariable *&CU = CUCache[FullPath ? FullPath : main_input_filename]; + bool isMain) { + if (!FullPath) + FullPath = main_input_filename; + GlobalVariable *&CU = CUCache[FullPath]; if (CU) return DICompileUnit(CU); From isanbard at gmail.com Wed Feb 18 13:28:05 2009 From: isanbard at gmail.com (Bill Wendling) Date: Wed, 18 Feb 2009 19:28:05 -0000 Subject: [llvm-commits] [llvm] r64942 - in /llvm/branches/Apple/Dib: include/llvm/CodeGen/ include/llvm/ExecutionEngine/ include/llvm/Target/ lib/CodeGen/ lib/ExecutionEngine/ lib/ExecutionEngine/JIT/ lib/Target/X86/ Message-ID: <200902181928.n1IJS6qN007353@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 13:28:05 2009 New Revision: 64942 URL: http://llvm.org/viewvc/llvm-project?rev=64942&view=rev Log: --- Merging r63965 into '.': U lib/ExecutionEngine/JIT/JIT.cpp U lib/ExecutionEngine/JIT/JIT.h Split the locking out of JIT::runJITOnFunction so that callers that already hold the lock can call an entry point that doesn't re-acquire the lock. --- Merging r64906 into '.': U include/llvm/Target/TargetJITInfo.h U include/llvm/ExecutionEngine/ExecutionEngine.h U include/llvm/ExecutionEngine/JITMemoryManager.h U include/llvm/CodeGen/MachineCodeEmitter.h U lib/CodeGen/ELFWriter.cpp U lib/CodeGen/MachOWriter.cpp U lib/Target/X86/X86JITInfo.h U lib/Target/X86/X86JITInfo.cpp U lib/ExecutionEngine/JIT/JITEmitter.cpp G lib/ExecutionEngine/JIT/JIT.cpp U lib/ExecutionEngine/JIT/JITMemoryManager.cpp G lib/ExecutionEngine/JIT/JIT.h U lib/ExecutionEngine/ExecutionEngine.cpp Add support to the JIT for true non-lazy operation. When a call to a function that has not been JIT'd yet, the callee is put on a list of pending functions to JIT. The call is directed through a stub, which is updated with the address of the function after it has been JIT'd. A new interface for allocating and updating empty stubs is provided. Add support for removing the ModuleProvider the JIT was created with, which would otherwise invalidate the JIT's PassManager, which is initialized with the ModuleProvider's Module. Add support under a new ExecutionEngine flag for emitting the infomration necessary to update Function and GlobalVariable stubs after JITing them, by recording the address of the stub and the name of the GlobalValue. This allows code to be copied from one address space to another, where libraries may live at different virtual addresses, and have the stubs updated with their new correct target addresses. Modified: llvm/branches/Apple/Dib/include/llvm/CodeGen/MachineCodeEmitter.h llvm/branches/Apple/Dib/include/llvm/ExecutionEngine/ExecutionEngine.h llvm/branches/Apple/Dib/include/llvm/ExecutionEngine/JITMemoryManager.h llvm/branches/Apple/Dib/include/llvm/Target/TargetJITInfo.h llvm/branches/Apple/Dib/lib/CodeGen/ELFWriter.cpp llvm/branches/Apple/Dib/lib/CodeGen/MachOWriter.cpp llvm/branches/Apple/Dib/lib/ExecutionEngine/ExecutionEngine.cpp llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JIT.cpp llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JIT.h llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITEmitter.cpp llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITMemoryManager.cpp llvm/branches/Apple/Dib/lib/Target/X86/X86JITInfo.cpp llvm/branches/Apple/Dib/lib/Target/X86/X86JITInfo.h Modified: llvm/branches/Apple/Dib/include/llvm/CodeGen/MachineCodeEmitter.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/CodeGen/MachineCodeEmitter.h?rev=64942&r1=64941&r2=64942&view=diff ============================================================================== --- llvm/branches/Apple/Dib/include/llvm/CodeGen/MachineCodeEmitter.h (original) +++ llvm/branches/Apple/Dib/include/llvm/CodeGen/MachineCodeEmitter.h Wed Feb 18 13:28:05 2009 @@ -82,6 +82,13 @@ virtual void startGVStub(const GlobalValue* GV, unsigned StubSize, unsigned Alignment = 1) = 0; + /// startGVStub - This callback is invoked when the JIT needs the address of a + /// GV (e.g. function) that has not been code generated yet. Buffer points to + /// memory already allocated for this stub. + /// + virtual void startGVStub(const GlobalValue* GV, void *Buffer, + unsigned StubSize) = 0; + /// finishGVStub - This callback is invoked to terminate a GV stub. /// virtual void *finishGVStub(const GlobalValue* F) = 0; Modified: llvm/branches/Apple/Dib/include/llvm/ExecutionEngine/ExecutionEngine.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/ExecutionEngine/ExecutionEngine.h?rev=64942&r1=64941&r2=64942&view=diff ============================================================================== --- llvm/branches/Apple/Dib/include/llvm/ExecutionEngine/ExecutionEngine.h (original) +++ llvm/branches/Apple/Dib/include/llvm/ExecutionEngine/ExecutionEngine.h Wed Feb 18 13:28:05 2009 @@ -66,6 +66,7 @@ bool LazyCompilationDisabled; bool GVCompilationDisabled; bool SymbolSearchingDisabled; + bool DlsymStubsEnabled; protected: /// Modules - This is a list of ModuleProvider's that we are JIT'ing from. We @@ -288,6 +289,13 @@ return SymbolSearchingDisabled; } + /// EnableDlsymStubs - + void EnableDlsymStubs(bool Enabled = true) { + DlsymStubsEnabled = Enabled; + } + bool areDlsymStubsEnabled() const { + return DlsymStubsEnabled; + } /// InstallLazyFunctionCreator - If an unknown function is needed, the /// specified function pointer is invoked to create it. If it returns null, Modified: llvm/branches/Apple/Dib/include/llvm/ExecutionEngine/JITMemoryManager.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/ExecutionEngine/JITMemoryManager.h?rev=64942&r1=64941&r2=64942&view=diff ============================================================================== --- llvm/branches/Apple/Dib/include/llvm/ExecutionEngine/JITMemoryManager.h (original) +++ llvm/branches/Apple/Dib/include/llvm/ExecutionEngine/JITMemoryManager.h Wed Feb 18 13:28:05 2009 @@ -62,6 +62,17 @@ /// return a pointer to its base. virtual unsigned char *getGOTBase() const = 0; + /// SetDlsymTable - If the JIT must be able to relocate stubs after they have + /// been emitted, potentially because they are being copied to a process + /// where external symbols live at different addresses than in the JITing + /// process, allocate a table with sufficient information to do so. + virtual void SetDlsymTable(void *ptr) = 0; + + /// getDlsymTable - If this is managing a table of entries so that stubs to + /// external symbols can be later relocated, this method should return a + /// pointer to it. + virtual void *getDlsymTable() const = 0; + /// NeedsExactSize - If the memory manager requires to know the size of the /// objects to be emitted bool NeedsExactSize() const { Modified: llvm/branches/Apple/Dib/include/llvm/Target/TargetJITInfo.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/Target/TargetJITInfo.h?rev=64942&r1=64941&r2=64942&view=diff ============================================================================== --- llvm/branches/Apple/Dib/include/llvm/Target/TargetJITInfo.h (original) +++ llvm/branches/Apple/Dib/include/llvm/Target/TargetJITInfo.h Wed Feb 18 13:28:05 2009 @@ -56,6 +56,14 @@ assert(0 && "This target doesn't implement emitFunctionStub!"); return 0; } + + /// emitFunctionStubAtAddr - Use the specified MachineCodeEmitter object to + /// emit a small native function that simply calls Fn. Emit the stub into + /// the supplied buffer. + virtual void emitFunctionStubAtAddr(const Function* F, void *Fn, + void *Buffer, MachineCodeEmitter &MCE) { + assert(0 && "This target doesn't implement emitFunctionStubAtAddr!"); + } /// getPICJumpTableEntry - Returns the value of the jumptable entry for the /// specific basic block. Modified: llvm/branches/Apple/Dib/lib/CodeGen/ELFWriter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/ELFWriter.cpp?rev=64942&r1=64941&r2=64942&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/CodeGen/ELFWriter.cpp (original) +++ llvm/branches/Apple/Dib/lib/CodeGen/ELFWriter.cpp Wed Feb 18 13:28:05 2009 @@ -121,6 +121,10 @@ assert(0 && "JIT specific function called!"); abort(); } + void startGVStub(const GlobalValue* F, void *Buffer, unsigned StubSize) { + assert(0 && "JIT specific function called!"); + abort(); + } void *finishGVStub(const GlobalValue *F) { assert(0 && "JIT specific function called!"); abort(); Modified: llvm/branches/Apple/Dib/lib/CodeGen/MachOWriter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/MachOWriter.cpp?rev=64942&r1=64941&r2=64942&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/CodeGen/MachOWriter.cpp (original) +++ llvm/branches/Apple/Dib/lib/CodeGen/MachOWriter.cpp Wed Feb 18 13:28:05 2009 @@ -147,6 +147,11 @@ assert(0 && "JIT specific function called!"); abort(); } + virtual void startGVStub(const GlobalValue* F, void *Buffer, + unsigned StubSize) { + assert(0 && "JIT specific function called!"); + abort(); + } virtual void *finishGVStub(const GlobalValue* F) { assert(0 && "JIT specific function called!"); abort(); Modified: llvm/branches/Apple/Dib/lib/ExecutionEngine/ExecutionEngine.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/ExecutionEngine/ExecutionEngine.cpp?rev=64942&r1=64941&r2=64942&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/ExecutionEngine/ExecutionEngine.cpp (original) +++ llvm/branches/Apple/Dib/lib/ExecutionEngine/ExecutionEngine.cpp Wed Feb 18 13:28:05 2009 @@ -42,6 +42,7 @@ LazyCompilationDisabled = false; GVCompilationDisabled = false; SymbolSearchingDisabled = false; + DlsymStubsEnabled = false; Modules.push_back(P); assert(P && "ModuleProvider is null?"); } Modified: llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JIT.cpp?rev=64942&r1=64941&r2=64942&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JIT.cpp (original) +++ llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JIT.cpp Wed Feb 18 13:28:05 2009 @@ -289,11 +289,28 @@ Module *result = ExecutionEngine::removeModuleProvider(MP, E); MutexGuard locked(lock); - if (Modules.empty()) { + + if (jitstate->getMP() == MP) { delete jitstate; jitstate = 0; } + if (!jitstate && !Modules.empty()) { + jitstate = new JITState(Modules[0]); + + FunctionPassManager &PM = jitstate->getPM(locked); + PM.add(new TargetData(*TM.getTargetData())); + + // Turn the machine code intermediate representation into bytes in memory + // that may be executed. + if (TM.addPassesToEmitMachineCode(PM, *MCE, false /*fast*/)) { + cerr << "Target does not support machine code emission!\n"; + abort(); + } + + // Initialize passes. + PM.doInitialization(); + } return result; } @@ -304,10 +321,28 @@ ExecutionEngine::deleteModuleProvider(MP, E); MutexGuard locked(lock); - if (Modules.empty()) { + + if (jitstate->getMP() == MP) { delete jitstate; jitstate = 0; } + + if (!jitstate && !Modules.empty()) { + jitstate = new JITState(Modules[0]); + + FunctionPassManager &PM = jitstate->getPM(locked); + PM.add(new TargetData(*TM.getTargetData())); + + // Turn the machine code intermediate representation into bytes in memory + // that may be executed. + if (TM.addPassesToEmitMachineCode(PM, *MCE, false /*fast*/)) { + cerr << "Target does not support machine code emission!\n"; + abort(); + } + + // Initialize passes. + PM.doInitialization(); + } } /// run - Start execution with the specified function and arguments. @@ -475,9 +510,12 @@ /// GlobalAddress[F] with the address of F's machine code. /// void JIT::runJITOnFunction(Function *F) { - static bool isAlreadyCodeGenerating = false; - MutexGuard locked(lock); + runJITOnFunctionUnlocked(F, locked); +} + +void JIT::runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked) { + static bool isAlreadyCodeGenerating = false; assert(!isAlreadyCodeGenerating && "Error: Recursive compilation detected!"); // JIT the function @@ -485,14 +523,26 @@ jitstate->getPM(locked).run(*F); isAlreadyCodeGenerating = false; - // If the function referred to a global variable that had not yet been - // emitted, it allocates memory for the global, but doesn't emit it yet. Emit - // all of these globals now. - while (!jitstate->getPendingGlobals(locked).empty()) { - const GlobalVariable *GV = jitstate->getPendingGlobals(locked).back(); - jitstate->getPendingGlobals(locked).pop_back(); - EmitGlobalVariable(GV); + // If the function referred to another function that had not yet been + // read from bitcode, but we are jitting non-lazily, emit it now. + while (!jitstate->getPendingFunctions(locked).empty()) { + Function *PF = jitstate->getPendingFunctions(locked).back(); + jitstate->getPendingFunctions(locked).pop_back(); + + // JIT the function + isAlreadyCodeGenerating = true; + jitstate->getPM(locked).run(*PF); + isAlreadyCodeGenerating = false; + + // Now that the function has been jitted, ask the JITEmitter to rewrite + // the stub with real address of the function. + updateFunctionStub(PF); } + + // If the JIT is configured to emit info so that dlsym can be used to + // rewrite stubs to external globals, do so now. + if (areDlsymStubsEnabled() && isLazyCompilationDisabled()) + updateDlsymStubTable(); } /// getPointerToFunction - This method is used to get the address of the @@ -537,7 +587,7 @@ return Addr; } - runJITOnFunction(F); + runJITOnFunctionUnlocked(F, locked); void *Addr = getPointerToGlobalIfAvailable(F); assert(Addr && "Code generation didn't add function to GlobalAddress table!"); @@ -641,3 +691,8 @@ return new char[GVSize]; } } + +void JIT::addPendingFunction(Function *F) { + MutexGuard locked(lock); + jitstate->getPendingFunctions(locked).push_back(F); +} Modified: llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JIT.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JIT.h?rev=64942&r1=64941&r2=64942&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JIT.h (original) +++ llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JIT.h Wed Feb 18 13:28:05 2009 @@ -20,8 +20,6 @@ namespace llvm { class Function; -class GlobalValue; -class Constant; class TargetMachine; class TargetJITInfo; class MachineCodeEmitter; @@ -29,21 +27,22 @@ class JITState { private: FunctionPassManager PM; // Passes to compile a function + ModuleProvider *MP; // ModuleProvider used to create the PM - /// PendingGlobals - Global variables which have had memory allocated for them - /// while a function was code generated, but which have not been initialized - /// yet. - std::vector PendingGlobals; + /// PendingFunctions - Functions which have not been code generated yet, but + /// were called from a function being code generated. + std::vector PendingFunctions; public: - explicit JITState(ModuleProvider *MP) : PM(MP) {} + explicit JITState(ModuleProvider *MP) : PM(MP), MP(MP) {} FunctionPassManager &getPM(const MutexGuard &L) { return PM; } - - std::vector &getPendingGlobals(const MutexGuard &L) { - return PendingGlobals; + + ModuleProvider *getMP() const { return MP; } + std::vector &getPendingFunctions(const MutexGuard &L) { + return PendingFunctions; } }; @@ -139,6 +138,12 @@ /// void freeMachineCodeForFunction(Function *F); + /// addPendingFunction - while jitting non-lazily, a called but non-codegen'd + /// function was encountered. Add it to a pending list to be processed after + /// the current function. + /// + void addPendingFunction(Function *F); + /// getCodeEmitter - Return the code emitter this JIT is emitting into. MachineCodeEmitter *getCodeEmitter() const { return MCE; } @@ -147,7 +152,10 @@ private: static MachineCodeEmitter *createEmitter(JIT &J, JITMemoryManager *JMM); - void runJITOnFunction (Function *F); + void runJITOnFunction(Function *F); + void runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked); + void updateFunctionStub(Function *F); + void updateDlsymStubTable(); protected: Modified: llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITEmitter.cpp?rev=64942&r1=64941&r2=64942&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITEmitter.cpp (original) +++ llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITEmitter.cpp Wed Feb 18 13:28:05 2009 @@ -36,6 +36,7 @@ #include "llvm/System/Memory.h" #include "llvm/Target/TargetInstrInfo.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include #ifndef NDEBUG @@ -120,8 +121,9 @@ void *getFunctionStubIfAvailable(Function *F); /// getFunctionStub - This returns a pointer to a function stub, creating - /// one on demand as needed. - void *getFunctionStub(Function *F); + /// one on demand as needed. If empty is true, create a function stub + /// pointing at address 0, to be filled in later. + void *getFunctionStub(Function *F, bool empty = false); /// getExternalFunctionStub - Return a stub for the function at the /// specified address, created lazily on demand. @@ -140,6 +142,9 @@ state.getStubToFunctionMap(locked)[Location] = F; return (void*)(intptr_t)LazyResolverFn; } + + void getRelocatableGVs(SmallVectorImpl &GVs, + SmallVectorImpl &Ptrs); /// getGOTIndexForAddress - Return a new or existing index in the GOT for /// an address. This function only manages slots, it does not manage the @@ -167,7 +172,7 @@ /// getFunctionStub - This returns a pointer to a function stub, creating /// one on demand as needed. -void *JITResolver::getFunctionStub(Function *F) { +void *JITResolver::getFunctionStub(Function *F, bool empty) { MutexGuard locked(TheJIT->lock); // If we already have a stub for this function, recycle it. @@ -176,7 +181,7 @@ // Call the lazy resolver function unless we already KNOW it is an external // function, in which case we just skip the lazy resolution step. - void *Actual = (void*)(intptr_t)LazyResolverFn; + void *Actual = empty ? (void*)0 : (void*)(intptr_t)LazyResolverFn; if (F->isDeclaration() && !F->hasNotBeenReadFromBitcode()) { Actual = TheJIT->getPointerToFunction(F); @@ -203,6 +208,12 @@ // Finally, keep track of the stub-to-Function mapping so that the // JITCompilerFn knows which function to compile! state.getStubToFunctionMap(locked)[Stub] = F; + + // If this is an "empty" stub, then inform the JIT that it will need to + // JIT the function so an address can be provided. + if (empty) + TheJIT->addPendingFunction(F); + return Stub; } @@ -250,6 +261,28 @@ return idx; } +void JITResolver::getRelocatableGVs(SmallVectorImpl &GVs, + SmallVectorImpl &Ptrs) { + MutexGuard locked(TheJIT->lock); + + std::map &FM = state.getFunctionToStubMap(locked); + std::map &GM = state.getGlobalToIndirectSymMap(locked); + + for (std::map::iterator i = FM.begin(), e = FM.end(); + i != e; ++i) { + Function *F = i->first; + if (F->isDeclaration() && F->hasExternalLinkage()) { + GVs.push_back(i->first); + Ptrs.push_back(i->second); + } + } + for (std::map::iterator i = GM.begin(), e = GM.end(); + i != e; ++i) { + GVs.push_back(i->first); + Ptrs.push_back(i->second); + } +} + /// JITCompilerFn - This function is called when a lazy compilation stub has /// been entered. It looks up which function this stub corresponds to, compiles /// it if necessary, then returns the resultant function pointer. @@ -399,8 +432,7 @@ JitSymbolEntry *OldSymbols = SymTabPtr->Symbols; // Copy the old entries over. - memcpy(NewSymbols, OldSymbols, - SymTabPtr->NumSymbols*sizeof(OldSymbols[0])); + memcpy(NewSymbols, OldSymbols, SymTabPtr->NumSymbols*sizeof(OldSymbols[0])); // Swap the new symbols in, delete the old ones. SymTabPtr->Symbols = NewSymbols; @@ -538,6 +570,8 @@ virtual void startGVStub(const GlobalValue* GV, unsigned StubSize, unsigned Alignment = 1); + virtual void startGVStub(const GlobalValue* GV, void *Buffer, + unsigned StubSize); virtual void* finishGVStub(const GlobalValue *GV); /// allocateSpace - Reserves space in the current block if any, or @@ -591,6 +625,8 @@ void setMemoryExecutable(void) { MemMgr->setMemoryExecutable(); } + + JITMemoryManager *getMemMgr(void) const { return MemMgr; } private: void *getPointerToGlobal(GlobalValue *GV, void *Reference, bool NoNeedStub); @@ -605,11 +641,9 @@ void *JITEmitter::getPointerToGlobal(GlobalValue *V, void *Reference, bool DoesntNeedStub) { - if (GlobalVariable *GV = dyn_cast(V)) { - /// FIXME: If we straightened things out, this could actually emit the - /// global immediately instead of queuing it for codegen later! + if (GlobalVariable *GV = dyn_cast(V)) return TheJIT->getOrEmitGlobalVariable(GV); - } + if (GlobalAlias *GA = dyn_cast(V)) return TheJIT->getPointerToGlobal(GA->resolveAliasedGlobal(false)); @@ -623,15 +657,18 @@ ResultPtr = TheJIT->getPointerToGlobalIfAvailable(F); if (ResultPtr) return ResultPtr; - if (F->isDeclaration() && !F->hasNotBeenReadFromBitcode()) { - // If this is an external function pointer, we can force the JIT to - // 'compile' it, which really just adds it to the map. - if (DoesntNeedStub) - return TheJIT->getPointerToFunction(F); - - return Resolver.getFunctionStub(F); - } - + // If this is an external function pointer, we can force the JIT to + // 'compile' it, which really just adds it to the map. + if (F->isDeclaration() && !F->hasNotBeenReadFromBitcode() && DoesntNeedStub) + return TheJIT->getPointerToFunction(F); + + // If we are jitting non-lazily but encounter a function that has not been + // jitted yet, we need to allocate a blank stub to call the function + // once we JIT it and its address is known. + if (TheJIT->isLazyCompilationDisabled()) + if (!F->isDeclaration() || F->hasNotBeenReadFromBitcode()) + return Resolver.getFunctionStub(F, true); + // Okay, the function has not been compiled yet, if the target callback // mechanism is capable of rewriting the instruction directly, prefer to do // that instead of emitting a stub. @@ -1175,6 +1212,16 @@ BufferEnd = BufferBegin+StubSize+1; } +void JITEmitter::startGVStub(const GlobalValue* GV, void *Buffer, + unsigned StubSize) { + SavedBufferBegin = BufferBegin; + SavedBufferEnd = BufferEnd; + SavedCurBufferPtr = CurBufferPtr; + + BufferBegin = CurBufferPtr = (unsigned char *)Buffer; + BufferEnd = BufferBegin+StubSize+1; +} + void *JITEmitter::finishGVStub(const GlobalValue* GV) { NumBytes += getCurrentPCOffset(); std::swap(SavedBufferBegin, BufferBegin); @@ -1248,6 +1295,74 @@ return JE->getJITResolver().getFunctionStub(F); } +void JIT::updateFunctionStub(Function *F) { + // Get the empty stub we generated earlier. + assert(isa(MCE) && "Unexpected MCE?"); + JITEmitter *JE = cast(getCodeEmitter()); + void *Stub = JE->getJITResolver().getFunctionStub(F); + + // Tell the target jit info to rewrite the stub at the specified address, + // rather than creating a new one. + void *Addr = getPointerToGlobalIfAvailable(F); + getJITInfo().emitFunctionStubAtAddr(F, Addr, Stub, *getCodeEmitter()); +} + +/// updateDlsymStubTable - Emit the data necessary to relocate the stubs +/// that were emitted during code generation. +/// +void JIT::updateDlsymStubTable() { + assert(isa(MCE) && "Unexpected MCE?"); + JITEmitter *JE = cast(getCodeEmitter()); + + SmallVector GVs; + SmallVector Ptrs; + + JE->getJITResolver().getRelocatableGVs(GVs, Ptrs); + + // If there are no relocatable stubs, return. + if (GVs.empty()) + return; + + // If there are no new relocatable stubs, return. + void *CurTable = JE->getMemMgr()->getDlsymTable(); + if (CurTable && (*(unsigned *)CurTable == GVs.size())) + return; + + // Calculate the size of the stub info + unsigned offset = 4 + 4 * GVs.size(); + + SmallVector Offsets; + for (unsigned i = 0; i != GVs.size(); ++i) { + Offsets.push_back(offset); + offset += GVs[i]->getName().length() + 1; + } + + // FIXME: This currently allocates new space every time it's called. A + // different data structure could be used to make this unnecessary. + JE->startGVStub(0, offset, 4); + + // Emit the number of records + MCE->emitInt32(GVs.size()); + + // Emit the string offsets + for (unsigned i = 0; i != GVs.size(); ++i) + MCE->emitInt32(Offsets[i]); + + // Emit the pointers + for (unsigned i = 0; i != GVs.size(); ++i) + if (sizeof(void *) == 8) + MCE->emitInt64((intptr_t)Ptrs[i]); + else + MCE->emitInt32((intptr_t)Ptrs[i]); + + // Emit the strings + for (unsigned i = 0; i != GVs.size(); ++i) + MCE->emitString(GVs[i]->getName()); + + // Tell the JIT memory manager where it is. + JE->getMemMgr()->SetDlsymTable(JE->finishGVStub(0)); +} + /// freeMachineCodeForFunction - release machine code memory for given Function. /// void JIT::freeMachineCodeForFunction(Function *F) { Modified: llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITMemoryManager.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITMemoryManager.cpp?rev=64942&r1=64941&r2=64942&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITMemoryManager.cpp (original) +++ llvm/branches/Apple/Dib/lib/ExecutionEngine/JIT/JITMemoryManager.cpp Wed Feb 18 13:28:05 2009 @@ -258,6 +258,7 @@ unsigned char *CurStubPtr, *StubBase; unsigned char *GOTBase; // Target Specific reserved memory + void *DlsymTable; // Stub external symbol information // Centralize memory block allocation. sys::MemoryBlock getNewMemoryBlock(unsigned size); @@ -269,7 +270,8 @@ ~DefaultJITMemoryManager(); void AllocateGOT(); - + void SetDlsymTable(void *); + unsigned char *allocateStub(const GlobalValue* F, unsigned StubSize, unsigned Alignment); @@ -343,6 +345,10 @@ return GOTBase; } + void *getDlsymTable() const { + return DlsymTable; + } + /// deallocateMemForFunction - Deallocate all memory for the specified /// function body. void deallocateMemForFunction(const Function *F) { @@ -463,6 +469,7 @@ FreeMemoryList = Mem0; GOTBase = NULL; + DlsymTable = NULL; } void DefaultJITMemoryManager::AllocateGOT() { @@ -471,6 +478,9 @@ HasGOT = true; } +void DefaultJITMemoryManager::SetDlsymTable(void *ptr) { + DlsymTable = ptr; +} DefaultJITMemoryManager::~DefaultJITMemoryManager() { for (unsigned i = 0, e = Blocks.size(); i != e; ++i) Modified: llvm/branches/Apple/Dib/lib/Target/X86/X86JITInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Target/X86/X86JITInfo.cpp?rev=64942&r1=64941&r2=64942&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Target/X86/X86JITInfo.cpp (original) +++ llvm/branches/Apple/Dib/lib/Target/X86/X86JITInfo.cpp Wed Feb 18 13:28:05 2009 @@ -474,6 +474,21 @@ return MCE.finishGVStub(F); } +void X86JITInfo::emitFunctionStubAtAddr(const Function* F, void *Fn, void *Stub, + MachineCodeEmitter &MCE) { + // Note, we cast to intptr_t here to silence a -pedantic warning that + // complains about casting a function pointer to a normal pointer. + MCE.startGVStub(F, Stub, 5); + MCE.emitByte(0xE9); +#if defined (X86_64_JIT) + assert(((((intptr_t)Fn-MCE.getCurrentPCValue()-5) << 32) >> 32) == + ((intptr_t)Fn-MCE.getCurrentPCValue()-5) + && "PIC displacement does not fit in displacement field!"); +#endif + MCE.emitWordLE((intptr_t)Fn-MCE.getCurrentPCValue()-4); + MCE.finishGVStub(F); +} + /// getPICJumpTableEntry - Returns the value of the jumptable entry for the /// specific basic block. uintptr_t X86JITInfo::getPICJumpTableEntry(uintptr_t BB, uintptr_t Entry) { Modified: llvm/branches/Apple/Dib/lib/Target/X86/X86JITInfo.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Target/X86/X86JITInfo.h?rev=64942&r1=64941&r2=64942&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Target/X86/X86JITInfo.h (original) +++ llvm/branches/Apple/Dib/lib/Target/X86/X86JITInfo.h Wed Feb 18 13:28:05 2009 @@ -49,6 +49,12 @@ virtual void *emitFunctionStub(const Function* F, void *Fn, MachineCodeEmitter &MCE); + /// emitFunctionStubAtAddr - Use the specified MachineCodeEmitter object to + /// emit a small native function that simply calls Fn. Emit the stub into + /// the supplied buffer. + virtual void emitFunctionStubAtAddr(const Function* F, void *Fn, + void *Buffer, MachineCodeEmitter &MCE); + /// getPICJumpTableEntry - Returns the value of the jumptable entry for the /// specific basic block. virtual uintptr_t getPICJumpTableEntry(uintptr_t BB, uintptr_t JTBase); From isanbard at gmail.com Wed Feb 18 13:40:54 2009 From: isanbard at gmail.com (Bill Wendling) Date: Wed, 18 Feb 2009 19:40:54 -0000 Subject: [llvm-commits] [llvm] r64943 - in /llvm/branches/Apple/Dib: lib/CodeGen/AsmPrinter/DwarfWriter.cpp test/DebugInfo/2009-02-18-DefaultScope-Crash.ll Message-ID: <200902181940.n1IJes7h007784@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 13:40:54 2009 New Revision: 64943 URL: http://llvm.org/viewvc/llvm-project?rev=64943&view=rev Log: --- Merging r64920 into '.': A test/DebugInfo/2009-02-18-DefaultScope-Crash.ll U lib/CodeGen/AsmPrinter/DwarfWriter.cpp The subprogram die may not exist while creating "default" scope. Added: llvm/branches/Apple/Dib/test/DebugInfo/2009-02-18-DefaultScope-Crash.ll - copied unchanged from r64920, llvm/trunk/test/DebugInfo/2009-02-18-DefaultScope-Crash.ll Modified: llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Modified: llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp?rev=64943&r1=64942&r2=64943&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp (original) +++ llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Wed Feb 18 13:40:54 2009 @@ -2122,7 +2122,10 @@ // Get the subprogram die. DIE *SPDie = Unit->getDieMapSlotFor(SPD.getGV()); - assert(SPDie && "Missing subprogram descriptor"); + if (!SPDie) + /* A subprogram die may not exist if the corresponding function + does not have any debug info. */ + continue; // Add the function bounds. AddLabel(SPDie, DW_AT_low_pc, DW_FORM_addr, From baldrick at free.fr Wed Feb 18 14:22:28 2009 From: baldrick at free.fr (Duncan Sands) Date: Wed, 18 Feb 2009 20:22:28 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64948 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Message-ID: <200902182022.n1IKMSaF009188@zion.cs.uiuc.edu> Author: baldrick Date: Wed Feb 18 14:22:28 2009 New Revision: 64948 URL: http://llvm.org/viewvc/llvm-project?rev=64948&view=rev Log: Remove the assumption that a function is returned here (rather than an alias, for example). Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=64948&r1=64947&r2=64948&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Wed Feb 18 14:22:28 2009 @@ -3083,14 +3083,10 @@ case Type::FP128TyID: Name = "fabsl"; break; } - Function *F = cast(TheModule->getOrInsertFunction(Name, - Op->getType(), - Op->getType(), - NULL)); - CallInst *Call = Builder.CreateCall(F, Op); - F->setDoesNotThrow(); + Value *V = TheModule->getOrInsertFunction(Name, Op->getType(), Op->getType(), + NULL); + CallInst *Call = Builder.CreateCall(V, Op); Call->setDoesNotThrow(); - F->setDoesNotAccessMemory(); Call->setDoesNotAccessMemory(); return Call; } From baldrick at free.fr Wed Feb 18 14:24:19 2009 From: baldrick at free.fr (Duncan Sands) Date: Wed, 18 Feb 2009 20:24:19 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64949 - /llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Message-ID: <200902182024.n1IKOJHg009252@zion.cs.uiuc.edu> Author: baldrick Date: Wed Feb 18 14:24:18 2009 New Revision: 64949 URL: http://llvm.org/viewvc/llvm-project?rev=64949&view=rev Log: Align this line properly. Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=64949&r1=64948&r2=64949&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Wed Feb 18 14:24:18 2009 @@ -1506,7 +1506,7 @@ TARGET_ADJUST_LLVM_LINKAGE(FnEntry,decl); #endif /* TARGET_ADJUST_LLVM_LINKAGE */ - handleVisibility(decl, FnEntry); + handleVisibility(decl, FnEntry); // If FnEntry got renamed, then there is already an object with this name // in the symbol table. If this happens, the old one must be a forward From isanbard at gmail.com Wed Feb 18 15:45:48 2009 From: isanbard at gmail.com (Bill Wendling) Date: Wed, 18 Feb 2009 21:45:48 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64952 - /llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Message-ID: <200902182145.n1ILjmsD012242@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 15:45:48 2009 New Revision: 64952 URL: http://llvm.org/viewvc/llvm-project?rev=64952&view=rev Log: --- Merging r64938 into '.': U gcc/llvm-debug.cpp If FullPath is null, use main_input_filename. This avoids initializing a std::string with null. Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp?rev=64952&r1=64951&r2=64952&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Wed Feb 18 15:45:48 2009 @@ -826,9 +826,10 @@ /// getOrCreateCompileUnit - Get the compile unit from the cache or /// create a new one if necessary. DICompileUnit DebugInfo::getOrCreateCompileUnit(const char *FullPath, - bool isMain){ - - GlobalVariable *&CU = CUCache[FullPath ? FullPath : main_input_filename]; + bool isMain) { + if (!FullPath) + FullPath = main_input_filename; + GlobalVariable *&CU = CUCache[FullPath]; if (CU) return DICompileUnit(CU); From sabre at nondot.org Wed Feb 18 15:48:14 2009 From: sabre at nondot.org (Chris Lattner) Date: Wed, 18 Feb 2009 21:48:14 -0000 Subject: [llvm-commits] [llvm] r64953 - in /llvm/trunk: lib/AsmParser/LLParser.cpp lib/VMCore/AsmWriter.cpp test/Assembler/anon-functions.ll Message-ID: <200902182148.n1ILmExV012416@zion.cs.uiuc.edu> Author: lattner Date: Wed Feb 18 15:48:13 2009 New Revision: 64953 URL: http://llvm.org/viewvc/llvm-project?rev=64953&view=rev Log: add proper asmwriter and asmparser support for anonymous functions. Added: llvm/trunk/test/Assembler/anon-functions.ll Modified: llvm/trunk/lib/AsmParser/LLParser.cpp llvm/trunk/lib/VMCore/AsmWriter.cpp Modified: llvm/trunk/lib/AsmParser/LLParser.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=64953&r1=64952&r2=64953&view=diff ============================================================================== --- llvm/trunk/lib/AsmParser/LLParser.cpp (original) +++ llvm/trunk/lib/AsmParser/LLParser.cpp Wed Feb 18 15:48:13 2009 @@ -2094,11 +2094,21 @@ isa(RetType)) return Error(RetTypeLoc, "invalid function return type"); - if (Lex.getKind() != lltok::GlobalVar) + LocTy NameLoc = Lex.getLoc(); + + std::string FunctionName; + if (Lex.getKind() == lltok::GlobalVar) { + FunctionName = Lex.getStrVal(); + } else if (Lex.getKind() == lltok::GlobalID) { // @42 is ok. + unsigned NameID = Lex.getUIntVal(); + + if (NameID != NumberedVals.size()) + return TokError("function expected to be numbered '%" + + utostr(NumberedVals.size()) + "'"); + } else { return TokError("expected function name"); + } - LocTy NameLoc = Lex.getLoc(); - std::string FunctionName = Lex.getStrVal(); Lex.Lex(); if (Lex.getKind() != lltok::lparen) Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=64953&r1=64952&r2=64953&view=diff ============================================================================== --- llvm/trunk/lib/VMCore/AsmWriter.cpp (original) +++ llvm/trunk/lib/VMCore/AsmWriter.cpp Wed Feb 18 15:48:13 2009 @@ -1240,10 +1240,7 @@ printType(F->getFunctionType()); Out << "* "; - if (F->hasName()) - PrintLLVMName(Out, F); - else - Out << "@\"\""; + WriteAsOperandInternal(Out, F, TypeNames, &Machine); } else if (const GlobalAlias *GA = dyn_cast(Aliasee)) { printType(GA->getType()); Out << " "; @@ -1310,10 +1307,7 @@ Out << Attribute::getAsString(Attrs.getRetAttributes()) << ' '; printType(F->getReturnType()); Out << ' '; - if (F->hasName()) - PrintLLVMName(Out, F); - else - Out << "@\"\""; + WriteAsOperandInternal(Out, F, TypeNames, &Machine); Out << '('; Machine.incorporateFunction(F); Added: llvm/trunk/test/Assembler/anon-functions.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/anon-functions.ll?rev=64953&view=auto ============================================================================== --- llvm/trunk/test/Assembler/anon-functions.ll (added) +++ llvm/trunk/test/Assembler/anon-functions.ll Wed Feb 18 15:48:13 2009 @@ -0,0 +1,26 @@ +; RUN: llvm-as < %s |llvm-dis | llvm-as | llvm-dis +; PR3611 + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128" +target triple = "x86_64-unknown-linux-gnu" + + at f = alias void ()* @0 ; [#uses=0] + at g = alias void ()* @1 ; [#uses=0] + at h = external global void ()* ; [#uses=0] + +define internal void @0() nounwind { +entry: + store void()* @0, void()** @h + br label %return + +return: ; preds = %entry + ret void +} + +define internal void @1() nounwind { +entry: + br label %return + +return: ; preds = %entry + ret void +} From mburke at ea.com Wed Feb 18 16:13:20 2009 From: mburke at ea.com (Burke, Max) Date: Wed, 18 Feb 2009 14:13:20 -0800 Subject: [llvm-commits] PATCH: Use modules data layout over subtarget data layout, if it exists. Message-ID: I was finding that setting the data layout in the IR didn't actually propagate to the target back ends which was a little confusing :). If the modules data layout isn't specified then it uses the subtarget data layout. ==== //depot/llvm/lib/Target/CellSPU/SPUTargetMachine.cpp#5 (text) ==== 68c68,69 < DataLayout(Subtarget.getTargetDataString()), --- > DataLayout(!M.getDataLayout().empty() ? M.getDataLayout() : > Subtarget.getTargetDataString()), ==== //depot/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp#6 (text) ==== 104c104,106 < DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this), --- > DataLayout(!M.getDataLayout().empty() ? > M.getDataLayout() : Subtarget.getTargetDataString()), > InstrInfo(*this), ==== //depot/llvm/lib/Target/X86/X86TargetMachine.cpp#5 (text) ==== 133c133,134 < DataLayout(Subtarget.getDataLayout()), --- > DataLayout(!M.getDataLayout().empty() ? > M.getDataLayout() : Subtarget.getDataLayout()), From clattner at apple.com Wed Feb 18 16:18:03 2009 From: clattner at apple.com (Chris Lattner) Date: Wed, 18 Feb 2009 14:18:03 -0800 Subject: [llvm-commits] PATCH: Use modules data layout over subtarget data layout, if it exists. In-Reply-To: References: Message-ID: <46031997-4F5F-4207-B903-87AE5AB0E7B2@apple.com> On Feb 18, 2009, at 2:13 PM, Burke, Max wrote: > I was finding that setting the data layout in the IR didn't actually > propagate to the target back ends which was a little confusing :). If > the modules data layout isn't specified then it uses the subtarget > data > layout. Hi Max, What are you trying to accomplish here? Changing the target data layout arbitrarily can cause serious problems. Also, please send patches as an attachment. -Chris > > > > > ==== //depot/llvm/lib/Target/CellSPU/SPUTargetMachine.cpp#5 (text) > ==== > > 68c68,69 > < DataLayout(Subtarget.getTargetDataString()), > --- >> DataLayout(!M.getDataLayout().empty() ? M.getDataLayout() : >> Subtarget.getTargetDataString()), > > ==== //depot/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp#6 (text) > ==== > > 104c104,106 > < DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this), > --- >> DataLayout(!M.getDataLayout().empty() ? >> M.getDataLayout() : Subtarget.getTargetDataString()), >> InstrInfo(*this), > > ==== //depot/llvm/lib/Target/X86/X86TargetMachine.cpp#5 (text) ==== > > 133c133,134 > < DataLayout(Subtarget.getDataLayout()), > --- >> DataLayout(!M.getDataLayout().empty() ? >> M.getDataLayout() : Subtarget.getDataLayout()), > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits From anton at korobeynikov.info Wed Feb 18 16:27:49 2009 From: anton at korobeynikov.info (Anton Korobeynikov) Date: Thu, 19 Feb 2009 01:27:49 +0300 Subject: [llvm-commits] PATCH: Use modules data layout over subtarget data layout, if it exists. In-Reply-To: <46031997-4F5F-4207-B903-87AE5AB0E7B2@apple.com> References: <46031997-4F5F-4207-B903-87AE5AB0E7B2@apple.com> Message-ID: > > What are you trying to accomplish here? Changing the target data > layout arbitrarily can cause serious problems. Also, please send > patches as an attachment. And using unified diff :) PS: If you really want to increase the default alignment for some subtarget you should provide new default TD string. --- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090219/997c325f/attachment.html From mburke at ea.com Wed Feb 18 16:31:16 2009 From: mburke at ea.com (Burke, Max) Date: Wed, 18 Feb 2009 14:31:16 -0800 Subject: [llvm-commits] PATCH: Use modules data layout over subtargetdata layout, if it exists. In-Reply-To: <46031997-4F5F-4207-B903-87AE5AB0E7B2@apple.com> References: <46031997-4F5F-4207-B903-87AE5AB0E7B2@apple.com> Message-ID: Re patches, will do. I'm trying to fix interop between code that LLVM generates and that generated by a few other compilers on a handful of platforms which have differing alignments than what LLVM specifies, without hard coding the permutations into the backends. -----Original Message----- From: llvm-commits-bounces at cs.uiuc.edu [mailto:llvm-commits-bounces at cs.uiuc.edu] On Behalf Of Chris Lattner Sent: Wednesday, February 18, 2009 2:18 PM To: Commit Messages and Patches for LLVM Subject: Re: [llvm-commits] PATCH: Use modules data layout over subtargetdata layout, if it exists. Hi Max, What are you trying to accomplish here? Changing the target data layout arbitrarily can cause serious problems. Also, please send patches as an attachment. From dpatel at apple.com Wed Feb 18 17:01:49 2009 From: dpatel at apple.com (Devang Patel) Date: Wed, 18 Feb 2009 23:01:49 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64976 - /llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Message-ID: <200902182301.n1IN1nes015822@zion.cs.uiuc.edu> Author: dpatel Date: Wed Feb 18 17:01:48 2009 New Revision: 64976 URL: http://llvm.org/viewvc/llvm-project?rev=64976&view=rev Log: Fix Objective-C runtime version encoding. flag_objc_abi is initiailzed as -1; where -1 is not yet set to any value. Modified: llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Modified: llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp?rev=64976&r1=64975&r2=64976&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Wed Feb 18 17:01:48 2009 @@ -871,11 +871,14 @@ // flag_objc_abi represents Objective-C runtime version number. It is zero // for all other language. + unsigned ObjcRunTimeVer = 0; + if (flag_objc_abi != 0 && flag_objc_abi != -1) + ObjcRunTimeVer = flag_objc_abi; DICompileUnit NewCU = DebugFactory.CreateCompileUnit(LangTag, FileName, Directory, version_string, isMain, optimize, Flags, - flag_objc_abi); + ObjcRunTimeVer); CU = NewCU.getGV(); return NewCU; } From isanbard at gmail.com Wed Feb 18 17:08:53 2009 From: isanbard at gmail.com (Bill Wendling) Date: Wed, 18 Feb 2009 23:08:53 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64977 - /llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Message-ID: <200902182308.n1IN8rZ1016062@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 17:08:53 2009 New Revision: 64977 URL: http://llvm.org/viewvc/llvm-project?rev=64977&view=rev Log: --- Merging r64976 into '.': U gcc/llvm-debug.cpp Fix Objective-C runtime version encoding. flag_objc_abi is initiailzed as -1; where -1 is not yet set to any value. Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp?rev=64977&r1=64976&r2=64977&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Wed Feb 18 17:08:53 2009 @@ -869,11 +869,14 @@ // flag_objc_abi represents Objective-C runtime version number. It is zero // for all other language. + unsigned ObjcRunTimeVer = 0; + if (flag_objc_abi != 0 && flag_objc_abi != -1) + ObjcRunTimeVer = flag_objc_abi; DICompileUnit NewCU = DebugFactory.CreateCompileUnit(LangTag, FileName, Directory, version_string, isMain, optimize, Flags, - flag_objc_abi); + ObjcRunTimeVer); CU = NewCU.getGV(); return NewCU; } From clattner at apple.com Wed Feb 18 17:11:25 2009 From: clattner at apple.com (Chris Lattner) Date: Wed, 18 Feb 2009 15:11:25 -0800 Subject: [llvm-commits] PATCH: Use modules data layout over subtargetdata layout, if it exists. In-Reply-To: References: <46031997-4F5F-4207-B903-87AE5AB0E7B2@apple.com> Message-ID: On Feb 18, 2009, at 2:31 PM, Burke, Max wrote: > Re patches, will do. > > I'm trying to fix interop between code that LLVM generates and that > generated by a few other compilers on a handful of platforms which > have > differing alignments than what LLVM specifies, without hard coding the > permutations into the backends. Ok, currently that is considered a front-end problem. :) A silly example, say your C compile expects double to be 8-byte aligned, and you have the following struct: struct { int X; double D; }; This will get codegen'd by llvm-gcc to { i32, i32, double }, not to {i32, double} on targets where the llvm backend thinks that double is 4-byte aligned. -Chris From isanbard at gmail.com Wed Feb 18 17:12:06 2009 From: isanbard at gmail.com (Bill Wendling) Date: Wed, 18 Feb 2009 23:12:06 -0000 Subject: [llvm-commits] [llvm] r64978 - in /llvm/trunk: include/llvm/CodeGen/AsmPrinter.h lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp lib/Target/IA64/IA64AsmPrinter.cpp lib/Target/Mips/MipsAsmPrinter.cpp lib/Target/PIC16/PIC16AsmPrinter.cpp lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp utils/TableGen/AsmWriterEmitter.cpp Message-ID: <200902182312.n1INC6Jd016170@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 17:12:06 2009 New Revision: 64978 URL: http://llvm.org/viewvc/llvm-project?rev=64978&view=rev Log: Put code that generates debug labels into TableGen so that it can be used by everyone. Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h llvm/trunk/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp llvm/trunk/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp llvm/trunk/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=64978&r1=64977&r2=64978&view=diff ============================================================================== --- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original) +++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Wed Feb 18 17:12:06 2009 @@ -51,17 +51,17 @@ /// unsigned FunctionNumber; - /// DW -This is needed because printDeclare() has to insert - /// DbgVariable entries into the dwarf table. This is a short term hack - /// that ought be fixed soon. - DwarfWriter *DW; - // GCMetadataPrinters - The garbage collection metadata printer table. typedef DenseMap gcp_map_type; typedef gcp_map_type::iterator gcp_iterator; gcp_map_type GCMetadataPrinters; protected: + /// DW -This is needed because printDeclare() has to insert + /// DbgVariable entries into the dwarf table. This is a short term hack + /// that ought be fixed soon. + DwarfWriter *DW; + // Necessary for external weak linkage support std::set ExtWeakSymbols; Modified: llvm/trunk/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp?rev=64978&r1=64977&r2=64978&view=diff ============================================================================== --- llvm/trunk/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp (original) +++ llvm/trunk/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp Wed Feb 18 17:12:06 2009 @@ -20,6 +20,7 @@ #include "llvm/Type.h" #include "llvm/Assembly/Writer.h" #include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/Target/TargetAsmInfo.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Support/Compiler.h" Modified: llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp?rev=64978&r1=64977&r2=64978&view=diff ============================================================================== --- llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp (original) +++ llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp Wed Feb 18 17:12:06 2009 @@ -22,6 +22,7 @@ #include "llvm/Module.h" #include "llvm/Type.h" #include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/Target/TargetAsmInfo.h" #include "llvm/Target/TargetMachine.h" Modified: llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp?rev=64978&r1=64977&r2=64978&view=diff ============================================================================== --- llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp (original) +++ llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp Wed Feb 18 17:12:06 2009 @@ -23,6 +23,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/Module.h" #include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/CodeGen/MachineFrameInfo.h" Modified: llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp?rev=64978&r1=64977&r2=64978&view=diff ============================================================================== --- llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp (original) +++ llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp Wed Feb 18 17:12:06 2009 @@ -14,12 +14,13 @@ #include "PIC16AsmPrinter.h" #include "PIC16TargetAsmInfo.h" -#include "llvm/Support/raw_ostream.h" -#include "llvm/Support/Mangler.h" +#include "llvm/DerivedTypes.h" #include "llvm/Function.h" #include "llvm/Module.h" +#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/CodeGen/MachineFrameInfo.h" -#include "llvm/DerivedTypes.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/Mangler.h" using namespace llvm; Modified: llvm/trunk/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp?rev=64978&r1=64977&r2=64978&view=diff ============================================================================== --- llvm/trunk/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp (original) +++ llvm/trunk/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp Wed Feb 18 17:12:06 2009 @@ -19,6 +19,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/Module.h" #include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/CodeGen/MachineInstr.h" Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp?rev=64978&r1=64977&r2=64978&view=diff ============================================================================== --- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp (original) +++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Wed Feb 18 17:12:06 2009 @@ -26,6 +26,7 @@ #include "llvm/Type.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/CodeGen/MachineJumpTableInfo.h" #include "llvm/Support/Mangler.h" #include "llvm/Support/raw_ostream.h" @@ -725,23 +726,6 @@ void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) { ++EmittedInsts; - if (TAI->doesSupportDebugInformation()) { - const Function *F = MF->getFunction(); - - // FIXME: Support more than '-Os'. - if (F->hasFnAttr(Attribute::OptimizeForSize)) { - static DebugLoc PrevDL = DebugLoc::getUnknownLoc(); - DebugLoc CurDL = MI->getDebugLoc(); - - if (!CurDL.isUnknown() && PrevDL != CurDL) { - DebugLocTuple DLT = MF->getDebugLocTuple(CurDL); - printLabel(DW->RecordSourceLine(DLT.Line, DLT.Col, DLT.Src)); - } - - PrevDL = CurDL; - } - } - // Call the autogenerated instruction printer routines. printInstruction(MI); } Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp?rev=64978&r1=64977&r2=64978&view=diff ============================================================================== --- llvm/trunk/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp (original) +++ llvm/trunk/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp Wed Feb 18 17:12:06 2009 @@ -25,6 +25,7 @@ #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Assembly/Writer.h" +#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/Support/Mangler.h" #include "llvm/Target/TargetAsmInfo.h" #include "llvm/Target/TargetOptions.h" Modified: llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp?rev=64978&r1=64977&r2=64978&view=diff ============================================================================== --- llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp (original) +++ llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp Wed Feb 18 17:12:06 2009 @@ -640,6 +640,17 @@ } O << "\";\n\n"; + O << " {\n" + << " const MachineFunction *MF = MI->getParent()->getParent();\n" + << " static DebugLoc PrevDL = DebugLoc::getUnknownLoc();\n" + << " DebugLoc CurDL = MI->getDebugLoc();\n\n" + << " if (!CurDL.isUnknown() && PrevDL != CurDL) {\n" + << " DebugLocTuple DLT = MF->getDebugLocTuple(CurDL);\n" + << " printLabel(DW->RecordSourceLine(DLT.Line, DLT.Col, DLT.Src));\n" + << " }\n\n" + << " PrevDL = CurDL;\n" + << " }\n"; + O << " if (MI->getOpcode() == TargetInstrInfo::INLINEASM) {\n" << " O << \"\\t\";\n" << " printInlineAsm(MI);\n" From isanbard at gmail.com Wed Feb 18 17:14:12 2009 From: isanbard at gmail.com (Bill Wendling) Date: Wed, 18 Feb 2009 23:14:12 -0000 Subject: [llvm-commits] [llvm] r64979 - in /llvm/branches/Apple/Dib: include/llvm/CodeGen/AsmPrinter.h lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp lib/Target/IA64/IA64AsmPrinter.cpp lib/Target/Mips/MipsAsmPrinter.cpp lib/Target/PIC16/PIC16AsmPrinter.cpp lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp utils/TableGen/AsmWriterEmitter.cpp Message-ID: <200902182314.n1INECqI016248@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 17:14:11 2009 New Revision: 64979 URL: http://llvm.org/viewvc/llvm-project?rev=64979&view=rev Log: --- Merging r64978 into '.': U include/llvm/CodeGen/AsmPrinter.h U utils/TableGen/AsmWriterEmitter.cpp U lib/Target/PIC16/PIC16AsmPrinter.cpp U lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp U lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp U lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp U lib/Target/IA64/IA64AsmPrinter.cpp U lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp U lib/Target/Mips/MipsAsmPrinter.cpp Put code that generates debug labels into TableGen so that it can be used by everyone. Modified: llvm/branches/Apple/Dib/include/llvm/CodeGen/AsmPrinter.h llvm/branches/Apple/Dib/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp llvm/branches/Apple/Dib/lib/Target/IA64/IA64AsmPrinter.cpp llvm/branches/Apple/Dib/lib/Target/Mips/MipsAsmPrinter.cpp llvm/branches/Apple/Dib/lib/Target/PIC16/PIC16AsmPrinter.cpp llvm/branches/Apple/Dib/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp llvm/branches/Apple/Dib/utils/TableGen/AsmWriterEmitter.cpp Modified: llvm/branches/Apple/Dib/include/llvm/CodeGen/AsmPrinter.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/CodeGen/AsmPrinter.h?rev=64979&r1=64978&r2=64979&view=diff ============================================================================== --- llvm/branches/Apple/Dib/include/llvm/CodeGen/AsmPrinter.h (original) +++ llvm/branches/Apple/Dib/include/llvm/CodeGen/AsmPrinter.h Wed Feb 18 17:14:11 2009 @@ -51,17 +51,17 @@ /// unsigned FunctionNumber; - /// DW -This is needed because printDeclare() has to insert - /// DbgVariable entries into the dwarf table. This is a short term hack - /// that ought be fixed soon. - DwarfWriter *DW; - // GCMetadataPrinters - The garbage collection metadata printer table. typedef DenseMap gcp_map_type; typedef gcp_map_type::iterator gcp_iterator; gcp_map_type GCMetadataPrinters; protected: + /// DW -This is needed because printDeclare() has to insert + /// DbgVariable entries into the dwarf table. This is a short term hack + /// that ought be fixed soon. + DwarfWriter *DW; + // Necessary for external weak linkage support std::set ExtWeakSymbols; Modified: llvm/branches/Apple/Dib/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp?rev=64979&r1=64978&r2=64979&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp (original) +++ llvm/branches/Apple/Dib/lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp Wed Feb 18 17:14:11 2009 @@ -20,6 +20,7 @@ #include "llvm/Type.h" #include "llvm/Assembly/Writer.h" #include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/Target/TargetAsmInfo.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Support/Compiler.h" Modified: llvm/branches/Apple/Dib/lib/Target/IA64/IA64AsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Target/IA64/IA64AsmPrinter.cpp?rev=64979&r1=64978&r2=64979&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Target/IA64/IA64AsmPrinter.cpp (original) +++ llvm/branches/Apple/Dib/lib/Target/IA64/IA64AsmPrinter.cpp Wed Feb 18 17:14:11 2009 @@ -22,6 +22,7 @@ #include "llvm/Module.h" #include "llvm/Type.h" #include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/Target/TargetAsmInfo.h" #include "llvm/Target/TargetMachine.h" Modified: llvm/branches/Apple/Dib/lib/Target/Mips/MipsAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Target/Mips/MipsAsmPrinter.cpp?rev=64979&r1=64978&r2=64979&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Target/Mips/MipsAsmPrinter.cpp (original) +++ llvm/branches/Apple/Dib/lib/Target/Mips/MipsAsmPrinter.cpp Wed Feb 18 17:14:11 2009 @@ -23,6 +23,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/Module.h" #include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/CodeGen/MachineFrameInfo.h" Modified: llvm/branches/Apple/Dib/lib/Target/PIC16/PIC16AsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Target/PIC16/PIC16AsmPrinter.cpp?rev=64979&r1=64978&r2=64979&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Target/PIC16/PIC16AsmPrinter.cpp (original) +++ llvm/branches/Apple/Dib/lib/Target/PIC16/PIC16AsmPrinter.cpp Wed Feb 18 17:14:11 2009 @@ -14,12 +14,13 @@ #include "PIC16AsmPrinter.h" #include "PIC16TargetAsmInfo.h" -#include "llvm/Support/raw_ostream.h" -#include "llvm/Support/Mangler.h" +#include "llvm/DerivedTypes.h" #include "llvm/Function.h" #include "llvm/Module.h" +#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/CodeGen/MachineFrameInfo.h" -#include "llvm/DerivedTypes.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/Mangler.h" using namespace llvm; Modified: llvm/branches/Apple/Dib/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp?rev=64979&r1=64978&r2=64979&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp (original) +++ llvm/branches/Apple/Dib/lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp Wed Feb 18 17:14:11 2009 @@ -19,6 +19,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/Module.h" #include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/CodeGen/MachineInstr.h" Modified: llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp?rev=64979&r1=64978&r2=64979&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp (original) +++ llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Wed Feb 18 17:14:11 2009 @@ -26,6 +26,7 @@ #include "llvm/Type.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/CodeGen/MachineJumpTableInfo.h" #include "llvm/Support/Mangler.h" #include "llvm/Support/raw_ostream.h" @@ -725,23 +726,6 @@ void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) { ++EmittedInsts; - if (TAI->doesSupportDebugInformation()) { - const Function *F = MF->getFunction(); - - // FIXME: Support more than '-Os'. - if (F->hasFnAttr(Attribute::OptimizeForSize)) { - static DebugLoc PrevDL = DebugLoc::getUnknownLoc(); - DebugLoc CurDL = MI->getDebugLoc(); - - if (!CurDL.isUnknown() && PrevDL != CurDL) { - DebugLocTuple DLT = MF->getDebugLocTuple(CurDL); - printLabel(DW->RecordSourceLine(DLT.Line, DLT.Col, DLT.Src)); - } - - PrevDL = CurDL; - } - } - // Call the autogenerated instruction printer routines. printInstruction(MI); } Modified: llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp?rev=64979&r1=64978&r2=64979&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp (original) +++ llvm/branches/Apple/Dib/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp Wed Feb 18 17:14:11 2009 @@ -25,6 +25,7 @@ #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Assembly/Writer.h" +#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/Support/Mangler.h" #include "llvm/Target/TargetAsmInfo.h" #include "llvm/Target/TargetOptions.h" Modified: llvm/branches/Apple/Dib/utils/TableGen/AsmWriterEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/utils/TableGen/AsmWriterEmitter.cpp?rev=64979&r1=64978&r2=64979&view=diff ============================================================================== --- llvm/branches/Apple/Dib/utils/TableGen/AsmWriterEmitter.cpp (original) +++ llvm/branches/Apple/Dib/utils/TableGen/AsmWriterEmitter.cpp Wed Feb 18 17:14:11 2009 @@ -640,6 +640,17 @@ } O << "\";\n\n"; + O << " {\n" + << " const MachineFunction *MF = MI->getParent()->getParent();\n" + << " static DebugLoc PrevDL = DebugLoc::getUnknownLoc();\n" + << " DebugLoc CurDL = MI->getDebugLoc();\n\n" + << " if (!CurDL.isUnknown() && PrevDL != CurDL) {\n" + << " DebugLocTuple DLT = MF->getDebugLocTuple(CurDL);\n" + << " printLabel(DW->RecordSourceLine(DLT.Line, DLT.Col, DLT.Src));\n" + << " }\n\n" + << " PrevDL = CurDL;\n" + << " }\n"; + O << " if (MI->getOpcode() == TargetInstrInfo::INLINEASM) {\n" << " O << \"\\t\";\n" << " printInlineAsm(MI);\n" From evan.cheng at apple.com Wed Feb 18 17:29:55 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Wed, 18 Feb 2009 23:29:55 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64981 - in /llvm-gcc-4.2/trunk/gcc: llvm-convert.cpp llvm-debug.cpp llvm-internal.h Message-ID: <200902182329.n1INTtvT016808@zion.cs.uiuc.edu> Author: evancheng Date: Wed Feb 18 17:29:54 2009 New Revision: 64981 URL: http://llvm.org/viewvc/llvm-project?rev=64981&view=rev Log: llvm-debug should not bother to check for constant folding overflow. Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp llvm-gcc-4.2/trunk/gcc/llvm-internal.h Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=64981&r1=64980&r2=64981&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Wed Feb 18 17:29:54 2009 @@ -102,7 +102,7 @@ /// getINTEGER_CSTVal - Return the specified INTEGER_CST value as a uint64_t. /// -static uint64_t getINTEGER_CSTVal(tree exp) { +uint64_t getINTEGER_CSTVal(tree exp) { unsigned HOST_WIDE_INT HI = (unsigned HOST_WIDE_INT)TREE_INT_CST_HIGH(exp); unsigned HOST_WIDE_INT LO = (unsigned HOST_WIDE_INT)TREE_INT_CST_LOW(exp); if (HOST_BITS_PER_WIDE_INT == 64) { Modified: llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp?rev=64981&r1=64980&r2=64981&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Wed Feb 18 17:29:54 2009 @@ -88,14 +88,14 @@ if (TYPE_SIZE(Node) == NULL_TREE) return 0; else if (isInt64(TYPE_SIZE(Node), 1)) - return getInt64(TYPE_SIZE(Node), 1); + return getINTEGER_CSTVal(TYPE_SIZE(Node)); else return TYPE_ALIGN(Node); } else if (DECL_P(Node)) { if (DECL_SIZE(Node) == NULL_TREE) return 0; else if (isInt64(DECL_SIZE(Node), 1)) - return getInt64(DECL_SIZE(Node), 1); + return getINTEGER_CSTVal(DECL_SIZE(Node)); else return DECL_ALIGN(Node); } @@ -477,8 +477,8 @@ tree MaxValue = TYPE_MAX_VALUE(Domain); if (MinValue && MaxValue && isInt64(MinValue, 0) && isInt64(MaxValue, 0)) { - uint64_t Low = getInt64(MinValue, 0); - uint64_t Hi = getInt64(MaxValue, 0); + uint64_t Low = getINTEGER_CSTVal(MinValue); + uint64_t Hi = getINTEGER_CSTVal(MaxValue); Subscripts.push_back(DebugFactory.GetOrCreateSubrange(Low, Hi)); } } @@ -505,7 +505,7 @@ if (TYPE_SIZE(type)) { for (tree Link = TYPE_VALUES(type); Link; Link = TREE_CHAIN(Link)) { tree EnumValue = TREE_VALUE(Link); - int64_t Value = getInt64(EnumValue, tree_int_cst_sgn(EnumValue) > 0); + int64_t Value = getINTEGER_CSTVal(EnumValue); const char *EnumName = IDENTIFIER_POINTER(TREE_PURPOSE(Link)); Elements.push_back(DebugFactory.CreateEnumerator(EnumName, Value)); } @@ -599,7 +599,7 @@ findRegion(type),"", getOrCreateCompileUnit(Loc.file), 0,0,0, - getInt64(BINFO_OFFSET(BInfo), 0), + getINTEGER_CSTVal(BINFO_OFFSET(BInfo)), 0, BaseClass); EltTys.push_back(DTy); } Modified: llvm-gcc-4.2/trunk/gcc/llvm-internal.h URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-internal.h?rev=64981&r1=64980&r2=64981&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-internal.h (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-internal.h Wed Feb 18 17:29:54 2009 @@ -190,6 +190,10 @@ return TheTypeConverter->GetFieldIndex(field_decl); } +/// getINTEGER_CSTVal - Return the specified INTEGER_CST value as a uint64_t. +/// +uint64_t getINTEGER_CSTVal(tree_node *exp); + /// isInt64 - Return true if t is an INTEGER_CST that fits in a 64 bit integer. /// If Unsigned is false, returns whether it fits in a int64_t. If Unsigned is /// true, returns whether the value is non-negative and fits in a uint64_t. From kremenek at apple.com Wed Feb 18 17:33:32 2009 From: kremenek at apple.com (Ted Kremenek) Date: Wed, 18 Feb 2009 23:33:32 -0000 Subject: [llvm-commits] [llvm] r64982 - /llvm/tags/checker/checker-0.159/ Message-ID: <200902182333.n1INXWtt016948@zion.cs.uiuc.edu> Author: kremenek Date: Wed Feb 18 17:33:32 2009 New Revision: 64982 URL: http://llvm.org/viewvc/llvm-project?rev=64982&view=rev Log: Tagging checker-0.159. Added: llvm/tags/checker/checker-0.159/ - copied from r64981, llvm/trunk/ From isanbard at gmail.com Wed Feb 18 18:11:39 2009 From: isanbard at gmail.com (Bill Wendling) Date: Thu, 19 Feb 2009 00:11:39 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64986 - in /llvm-gcc-4.2/branches/Apple/Dib/gcc/config: arm/arm.h rs6000/rs6000.h Message-ID: <200902190011.n1J0BdIg018314@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 18:11:38 2009 New Revision: 64986 URL: http://llvm.org/viewvc/llvm-project?rev=64986&view=rev Log: --- Merging r64544 into '.': U gcc/config/rs6000/rs6000.h U gcc/config/arm/arm.h Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/config/arm/arm.h llvm-gcc-4.2/branches/Apple/Dib/gcc/config/rs6000/rs6000.h Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/config/arm/arm.h URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/config/arm/arm.h?rev=64986&r1=64985&r2=64986&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/config/arm/arm.h (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/config/arm/arm.h Wed Feb 18 18:11:38 2009 @@ -2923,7 +2923,7 @@ (TARGET_THUMB ? "thumb" : "") #define LLVM_SET_MACHINE_OPTIONS(argvec) \ - if (TARGET_SOFT_FLAT) \ + if (TARGET_SOFT_FLOAT) \ argvec.push_back("-soft-float"); /* Doing struct copy by partial-word loads and stores is not a good idea on ARM. */ Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/config/rs6000/rs6000.h URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/config/rs6000/rs6000.h?rev=64986&r1=64985&r2=64986&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/config/rs6000/rs6000.h (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/config/rs6000/rs6000.h Wed Feb 18 18:11:38 2009 @@ -3465,7 +3465,7 @@ } #define LLVM_SET_MACHINE_OPTIONS(argvec) \ - if (TARGET_SOFT_FLAT) \ + if (TARGET_SOFT_FLOAT) \ argvec.push_back("-soft-float"); /* When -m64 is specified, set the architecture to powerpc64-os-blah even if the From isanbard at gmail.com Wed Feb 18 18:13:55 2009 From: isanbard at gmail.com (Bill Wendling) Date: Thu, 19 Feb 2009 00:13:55 -0000 Subject: [llvm-commits] [llvm] r64987 - /llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp Message-ID: <200902190013.n1J0DtwA018437@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 18:13:55 2009 New Revision: 64987 URL: http://llvm.org/viewvc/llvm-project?rev=64987&view=rev Log: Temporarily XFAIL this test. Modified: llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp Modified: llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FrontendC%2B%2B/2006-11-06-StackTrace.cpp?rev=64987&r1=64986&r2=64987&view=diff ============================================================================== --- llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp (original) +++ llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp Wed Feb 18 18:13:55 2009 @@ -11,6 +11,7 @@ // Only works on ppc, x86 and x86_64. Should generalize? // XFAIL: alpha|ia64|arm +// XFAIL: * #include From isanbard at gmail.com Wed Feb 18 18:14:36 2009 From: isanbard at gmail.com (Bill Wendling) Date: Thu, 19 Feb 2009 00:14:36 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r64988 - in /llvm-gcc-4.2/branches/Apple/Dib/gcc: llvm-convert.cpp llvm-debug.cpp llvm-internal.h Message-ID: <200902190014.n1J0EbLW018479@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 18:14:36 2009 New Revision: 64988 URL: http://llvm.org/viewvc/llvm-project?rev=64988&view=rev Log: --- Merging r64981 into '.': U gcc/llvm-convert.cpp U gcc/llvm-internal.h U gcc/llvm-debug.cpp llvm-debug should not bother to check for constant folding overflow. Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-internal.h Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp?rev=64988&r1=64987&r2=64988&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp Wed Feb 18 18:14:36 2009 @@ -282,7 +282,7 @@ /// getINTEGER_CSTVal - Return the specified INTEGER_CST value as a uint64_t. /// -static uint64_t getINTEGER_CSTVal(tree exp) { +uint64_t getINTEGER_CSTVal(tree exp) { unsigned HOST_WIDE_INT HI = (unsigned HOST_WIDE_INT)TREE_INT_CST_HIGH(exp); unsigned HOST_WIDE_INT LO = (unsigned HOST_WIDE_INT)TREE_INT_CST_LOW(exp); if (HOST_BITS_PER_WIDE_INT == 64) { Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp?rev=64988&r1=64987&r2=64988&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-debug.cpp Wed Feb 18 18:14:36 2009 @@ -88,14 +88,14 @@ if (TYPE_SIZE(Node) == NULL_TREE) return 0; else if (isInt64(TYPE_SIZE(Node), 1)) - return getInt64(TYPE_SIZE(Node), 1); + return getINTEGER_CSTVal(TYPE_SIZE(Node)); else return TYPE_ALIGN(Node); } else if (DECL_P(Node)) { if (DECL_SIZE(Node) == NULL_TREE) return 0; else if (isInt64(DECL_SIZE(Node), 1)) - return getInt64(DECL_SIZE(Node), 1); + return getINTEGER_CSTVal(DECL_SIZE(Node)); else return DECL_ALIGN(Node); } @@ -475,8 +475,8 @@ tree MaxValue = TYPE_MAX_VALUE(Domain); if (MinValue && MaxValue && isInt64(MinValue, 0) && isInt64(MaxValue, 0)) { - uint64_t Low = getInt64(MinValue, 0); - uint64_t Hi = getInt64(MaxValue, 0); + uint64_t Low = getINTEGER_CSTVal(MinValue); + uint64_t Hi = getINTEGER_CSTVal(MaxValue); Subscripts.push_back(DebugFactory.GetOrCreateSubrange(Low, Hi)); } } @@ -503,7 +503,7 @@ if (TYPE_SIZE(type)) { for (tree Link = TYPE_VALUES(type); Link; Link = TREE_CHAIN(Link)) { tree EnumValue = TREE_VALUE(Link); - int64_t Value = getInt64(EnumValue, tree_int_cst_sgn(EnumValue) > 0); + int64_t Value = getINTEGER_CSTVal(EnumValue); const char *EnumName = IDENTIFIER_POINTER(TREE_PURPOSE(Link)); Elements.push_back(DebugFactory.CreateEnumerator(EnumName, Value)); } @@ -597,7 +597,7 @@ findRegion(type),"", getOrCreateCompileUnit(Loc.file), 0,0,0, - getInt64(BINFO_OFFSET(BInfo), 0), + getINTEGER_CSTVal(BINFO_OFFSET(BInfo)), 0, BaseClass); EltTys.push_back(DTy); } Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-internal.h URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-internal.h?rev=64988&r1=64987&r2=64988&view=diff ============================================================================== --- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-internal.h (original) +++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-internal.h Wed Feb 18 18:14:36 2009 @@ -197,6 +197,10 @@ return TheTypeConverter->GetFieldIndex(field_decl); } +/// getINTEGER_CSTVal - Return the specified INTEGER_CST value as a uint64_t. +/// +uint64_t getINTEGER_CSTVal(tree_node *exp); + /// isInt64 - Return true if t is an INTEGER_CST that fits in a 64 bit integer. /// If Unsigned is false, returns whether it fits in a int64_t. If Unsigned is /// true, returns whether the value is non-negative and fits in a uint64_t. From echeng at apple.com Wed Feb 18 18:45:51 2009 From: echeng at apple.com (Evan Cheng) Date: Wed, 18 Feb 2009 16:45:51 -0800 Subject: [llvm-commits] [llvm] r64987 - /llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp In-Reply-To: <200902190013.n1J0DtwA018437@zion.cs.uiuc.edu> References: <200902190013.n1J0DtwA018437@zion.cs.uiuc.edu> Message-ID: <4574B3B1-DEF8-47AC-BADA-2B5344EF9453@apple.com> Why xfail it? What broke? Evan On Feb 18, 2009, at 4:13 PM, Bill Wendling wrote: > Author: void > Date: Wed Feb 18 18:13:55 2009 > New Revision: 64987 > > URL: http://llvm.org/viewvc/llvm-project?rev=64987&view=rev > Log: > Temporarily XFAIL this test. > > Modified: > llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp > > Modified: llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FrontendC%2B%2B/2006-11-06-StackTrace.cpp?rev=64987&r1=64986&r2=64987&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp (original) > +++ llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp Wed Feb 18 > 18:13:55 2009 > @@ -11,6 +11,7 @@ > > // Only works on ppc, x86 and x86_64. Should generalize? > // XFAIL: alpha|ia64|arm > +// XFAIL: * > > #include > > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits From kremenek at apple.com Wed Feb 18 19:50:21 2009 From: kremenek at apple.com (Ted Kremenek) Date: Thu, 19 Feb 2009 01:50:21 -0000 Subject: [llvm-commits] [llvm] r64995 - /llvm/tags/checker/checker-0.159/ Message-ID: <200902190150.n1J1oLCV021440@zion.cs.uiuc.edu> Author: kremenek Date: Wed Feb 18 19:50:21 2009 New Revision: 64995 URL: http://llvm.org/viewvc/llvm-project?rev=64995&view=rev Log: Removing checker-0.159. Removed: llvm/tags/checker/checker-0.159/ From clattner at apple.com Wed Feb 18 19:52:11 2009 From: clattner at apple.com (Chris Lattner) Date: Wed, 18 Feb 2009 17:52:11 -0800 Subject: [llvm-commits] [llvm] r64877 - in /llvm/trunk: lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp test/CodeGen/X86/cstring.ll In-Reply-To: References: <200902180219.n1I2JrjZ030169@zion.cs.uiuc.edu> <3C282F1A-29E3-4412-827D-473C0C637C7F@apple.com> <27A4E95A-B7DA-4385-9739-6239A4837A40@apple.com> <67EABC6B-468D-48DD-BACC-12C0783416CD@apple.com> Message-ID: <4CC992DF-6EF3-4FF3-8B81-7F3777E1BD3E@apple.com> On Feb 17, 2009, at 11:08 PM, Evan Cheng wrote: >>> rdar://6479858. It's a minor size win, but more importantly it >>> avoids linker warning. That means fewer complaints about llvm-gcc >>> (and it has been reported at least twice so far at Apple). >> >> Then this is not an optimization, this is a semantic property. >> Whatever is creating that literal string should pin it in the >> section that it requires it to be in. > > I don't understand your objection. What's wrong with putting > constant array of i8 terminated with zero into cstring sections? Do > we need to have the frontend pre-determine the sections for all of > these strings? > Evan and I discussed this offline. The result is that I agree that there is nothing wrong with this patch, but that there is another underlying bug that this is being used to hide. The problem is that darwin really needs the STRING_CST to be emitted to a specific section. The "right" answer is to change darwin_build_constant_cfstring in config/darwin.c to tag the node as needing to be in the cstring section, and then the codegen will do the right thing. The problem is that DECL_SECTION cannot be used on STRING_CST. Does anyone know a good solution for this? This is easy to fix in clang, but it would be nice for llvm-gcc to not rely on subtle behavior of the code generator for its correctness. -Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090218/09c6a4a3/attachment.html From dalej at apple.com Wed Feb 18 20:16:01 2009 From: dalej at apple.com (Dale Johannesen) Date: Wed, 18 Feb 2009 18:16:01 -0800 Subject: [llvm-commits] [llvm] r64877 - in /llvm/trunk: lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp test/CodeGen/X86/cstring.ll In-Reply-To: <4CC992DF-6EF3-4FF3-8B81-7F3777E1BD3E@apple.com> References: <200902180219.n1I2JrjZ030169@zion.cs.uiuc.edu> <3C282F1A-29E3-4412-827D-473C0C637C7F@apple.com> <27A4E95A-B7DA-4385-9739-6239A4837A40@apple.com> <67EABC6B-468D-48DD-BACC-12C0783416CD@apple.com> <4CC992DF-6EF3-4FF3-8B81-7F3777E1BD3E@apple.com> Message-ID: <58EA4AC3-53A7-43DB-937A-E49FBA733FA4@apple.com> On Feb 18, 2009, at 5:52 PMPST, Chris Lattner wrote: > On Feb 17, 2009, at 11:08 PM, Evan Cheng wrote: >>>> rdar://6479858. It's a minor size win, but more importantly it >>>> avoids linker warning. That means fewer complaints about llvm-gcc >>>> (and it has been reported at least twice so far at Apple). >>> >>> Then this is not an optimization, this is a semantic property. >>> Whatever is creating that literal string should pin it in the >>> section that it requires it to be in. >> >> I don't understand your objection. What's wrong with putting >> constant array of i8 terminated with zero into cstring sections? Do >> we need to have the frontend pre-determine the sections for all of >> these strings? >> > > Evan and I discussed this offline. The result is that I agree that > there is nothing wrong with this patch, but that there is another > underlying bug that this is being used to hide. > > The problem is that darwin really needs the STRING_CST to be emitted > to a specific section. The "right" answer is to change > darwin_build_constant_cfstring in config/darwin.c to tag the node as > needing to be in the cstring section, and then the codegen will do > the right thing. > > The problem is that DECL_SECTION cannot be used on STRING_CST. Does > anyone know a good solution for this? This is easy to fix in clang, > but it would be nice for llvm-gcc to not rely on subtle behavior of > the code generator for its correctness. The most straightforward would be add a section_name field to the STRING_CST node (struct tree_string in tree.h). -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090218/683b614e/attachment.html From gohman at apple.com Wed Feb 18 20:40:17 2009 From: gohman at apple.com (Dan Gohman) Date: Thu, 19 Feb 2009 02:40:17 -0000 Subject: [llvm-commits] [llvm] r64997 - /llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp Message-ID: <200902190240.n1J2eIqC023043@zion.cs.uiuc.edu> Author: djg Date: Wed Feb 18 20:40:15 2009 New Revision: 64997 URL: http://llvm.org/viewvc/llvm-project?rev=64997&view=rev Log: Reapply r57340. VMKit does not presently rely on materializeFunction being called with the lock released, and this fixes a race condition in the JIT as used by lli. Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp?rev=64997&r1=64996&r2=64997&view=diff ============================================================================== --- llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp (original) +++ llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp Wed Feb 18 20:40:15 2009 @@ -553,6 +553,8 @@ if (void *Addr = getPointerToGlobalIfAvailable(F)) return Addr; // Check if function already code gen'd + MutexGuard locked(lock); + // Make sure we read in the function if it exists in this Module. if (F->hasNotBeenReadFromBitcode()) { // Determine the module provider this function is provided by. @@ -578,8 +580,6 @@ return Addr; } - MutexGuard locked(lock); - if (F->isDeclaration()) { bool AbortOnFailure = F->getLinkage() != GlobalValue::ExternalWeakLinkage; void *Addr = getPointerToNamedFunction(F->getName(), AbortOnFailure); From gohman at apple.com Wed Feb 18 20:55:18 2009 From: gohman at apple.com (Dan Gohman) Date: Thu, 19 Feb 2009 02:55:18 -0000 Subject: [llvm-commits] [llvm] r64999 - /llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp Message-ID: <200902190255.n1J2tJaf023459@zion.cs.uiuc.edu> Author: djg Date: Wed Feb 18 20:55:18 2009 New Revision: 64999 URL: http://llvm.org/viewvc/llvm-project?rev=64999&view=rev Log: Fix the logic in this assertion to properly validate the number of arguments. Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp?rev=64999&r1=64998&r2=64999&view=diff ============================================================================== --- llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp (original) +++ llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp Wed Feb 18 20:55:18 2009 @@ -356,8 +356,9 @@ const FunctionType *FTy = F->getFunctionType(); const Type *RetTy = FTy->getReturnType(); - assert((FTy->getNumParams() <= ArgValues.size() || FTy->isVarArg()) && - "Too many arguments passed into function!"); + assert((FTy->getNumParams() == ArgValues.size() || + (FTy->isVarArg() && FTy->getNumParams() <= ArgValues.size())) && + "Wrong number of arguments passed into function!"); assert(FTy->getNumParams() == ArgValues.size() && "This doesn't support passing arguments through varargs (yet)!"); From isanbard at gmail.com Wed Feb 18 21:46:54 2009 From: isanbard at gmail.com (Bill Wendling) Date: Thu, 19 Feb 2009 03:46:54 -0000 Subject: [llvm-commits] [llvm] r65001 - /llvm/branches/Apple/Dib/lib/Transforms/Scalar/IndVarSimplify.cpp Message-ID: <200902190346.n1J3ksOE025015@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 21:46:53 2009 New Revision: 65001 URL: http://llvm.org/viewvc/llvm-project?rev=65001&view=rev Log: Merging r64530 U lib/Transforms/Scalar/IndVarSimplify.cpp Merging r64531 G lib/Transforms/Scalar/IndVarSimplify.cpp Merging r64532 U test/Transforms/IndVarsSimplify/promote-iv-to-eliminate-casts.ll G lib/Transforms/Scalar/IndVarSimplify.cpp Merging r64625 G lib/Transforms/Scalar/IndVarSimplify.cpp Merging r64702 G lib/Transforms/Scalar/IndVarSimplify.cpp Merging r64766 G lib/Transforms/Scalar/IndVarSimplify.cpp Merging r64784 G lib/Transforms/Scalar/IndVarSimplify.cpp Bring IndVarSimplify.cpp up to TOT. Merging r64866 Skipped missing target: 'test/Transforms/IndVarSimplify/preserve-signed-wrap.ll' Skipped missing target: 'test/Transforms/IndVarSimplify' G lib/Transforms/Scalar/IndVarSimplify.cpp Fix a corner case in the new indvars promotion logic: if there are multiple IV's in a loop, some of them may under go signed or unsigned wrapping even if the IV that's used in the loop exit condition doesn't. Restrict sign-extension-elimination and zero-extension-elimination to only those that operate on the original loop-controlling IV. Modified: llvm/branches/Apple/Dib/lib/Transforms/Scalar/IndVarSimplify.cpp Modified: llvm/branches/Apple/Dib/lib/Transforms/Scalar/IndVarSimplify.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=65001&r1=65000&r2=65001&view=diff ============================================================================== --- llvm/branches/Apple/Dib/lib/Transforms/Scalar/IndVarSimplify.cpp (original) +++ llvm/branches/Apple/Dib/lib/Transforms/Scalar/IndVarSimplify.cpp Wed Feb 18 21:46:53 2009 @@ -90,7 +90,8 @@ void EliminatePointerRecurrence(PHINode *PN, BasicBlock *Preheader, SmallPtrSet &DeadInsts); - void LinearFunctionTestReplace(Loop *L, SCEVHandle IterationCount, Value *IndVar, + void LinearFunctionTestReplace(Loop *L, SCEVHandle IterationCount, + Value *IndVar, BasicBlock *ExitingBlock, BranchInst *BI, SCEVExpander &Rewriter); @@ -98,7 +99,7 @@ void DeleteTriviallyDeadInstructions(SmallPtrSet &Insts); - void HandleFloatingPointIV(Loop *L, PHINode *PH, + void HandleFloatingPointIV(Loop *L, PHINode *PH, SmallPtrSet &DeadInsts); }; } @@ -146,7 +147,7 @@ if (GEPI->getOperand(0) == PN) { assert(GEPI->getNumOperands() == 2 && "GEP types must match!"); DOUT << "INDVARS: Eliminating pointer recurrence: " << *GEPI; - + // Okay, we found a pointer recurrence. Transform this pointer // recurrence into an integer recurrence. Compute the value that gets // added to the pointer at every iteration. @@ -190,7 +191,7 @@ Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[1] = NewAdd; GetElementPtrInst *NGEPI = GetElementPtrInst::Create( - NCE, Idx, Idx + 2, + NCE, Idx, Idx + 2, GEPI->getName(), GEPI); SE->deleteValueFromRecords(GEPI); GEPI->replaceAllUsesWith(NGEPI); @@ -286,7 +287,7 @@ DOUT << "INDVARS: Rewriting loop exit condition to:\n" << " LHS:" << *CmpIndVar // includes a newline << " op:\t" - << (Opcode == ICmpInst::ICMP_NE ? "!=" : "=") << "\n" + << (Opcode == ICmpInst::ICMP_NE ? "!=" : "==") << "\n" << " RHS:\t" << *IterationCount << "\n"; Value *Cond = new ICmpInst(Opcode, CmpIndVar, ExitCnt, "exitcond", BI); @@ -328,18 +329,18 @@ // the exit blocks of the loop to find them. for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) { BasicBlock *ExitBB = ExitBlocks[i]; - + // If there are no PHI nodes in this exit block, then no values defined // inside the loop are used on this path, skip it. PHINode *PN = dyn_cast(ExitBB->begin()); if (!PN) continue; - + unsigned NumPreds = PN->getNumIncomingValues(); - + // Iterate over all of the PHI nodes. BasicBlock::iterator BBI = ExitBB->begin(); while ((PN = dyn_cast(BBI++))) { - + // Iterate over all of the values in all the PHI nodes. for (unsigned i = 0; i != NumPreds; ++i) { // If the value being merged in is not integer or is not defined @@ -351,14 +352,14 @@ continue; // If this pred is for a subloop, not L itself, skip it. - if (LI->getLoopFor(PN->getIncomingBlock(i)) != L) + if (LI->getLoopFor(PN->getIncomingBlock(i)) != L) continue; // The Block is in a subloop, skip it. // Check that InVal is defined in the loop. Instruction *Inst = cast(InVal); if (!L->contains(Inst->getParent())) continue; - + // We require that this value either have a computable evolution or that // the loop have a constant iteration count. In the case where the loop // has a constant iteration count, we can sometimes force evaluation of @@ -366,7 +367,7 @@ SCEVHandle SH = SE->getSCEV(Inst); if (!SH->hasComputableLoopEvolution(L) && !HasConstantItCount) continue; // Cannot get exit evolution for the loop value. - + // Okay, this instruction has a user outside of the current loop // and varies predictably *inside* the loop. Evaluate the value it // contains when the loop exits, if possible. @@ -377,22 +378,22 @@ Changed = true; ++NumReplaced; - + // See if we already computed the exit value for the instruction, if so, // just reuse it. Value *&ExitVal = ExitValues[Inst]; if (!ExitVal) ExitVal = Rewriter.expandCodeFor(ExitValue, InsertPt); - + DOUT << "INDVARS: RLEV: AfterLoopVal = " << *ExitVal << " LoopVal = " << *Inst << "\n"; PN->setIncomingValue(i, ExitVal); - + // If this instruction is dead now, schedule it to be removed. if (Inst->use_empty()) InstructionsToDelete.insert(Inst); - + // See if this is a single-entry LCSSA PHI node. If so, we can (and // have to) remove // the PHI entirely. This is safe, because the NewVal won't be variant @@ -406,7 +407,7 @@ } } } - + DeleteTriviallyDeadInstructions(InstructionsToDelete); } @@ -458,33 +459,101 @@ return Ty; } -/// isOrigIVAlwaysNonNegative - Analyze the original induction variable -/// in the loop to determine whether it would ever have a negative -/// value. +/// TestOrigIVForWrap - Analyze the original induction variable +/// that controls the loop's iteration to determine whether it +/// would ever undergo signed or unsigned overflow. +/// +/// In addition to setting the NoSignedWrap and NoUnsignedWrap +/// variables, return the PHI for this induction variable. /// /// TODO: This duplicates a fair amount of ScalarEvolution logic. -/// Perhaps this can be merged with ScalarEvolution::getIterationCount. +/// Perhaps this can be merged with ScalarEvolution::getIterationCount +/// and/or ScalarEvolution::get{Sign,Zero}ExtendExpr. /// -static bool isOrigIVAlwaysNonNegative(const Loop *L, - const Instruction *OrigCond) { +static const PHINode *TestOrigIVForWrap(const Loop *L, + const BranchInst *BI, + const Instruction *OrigCond, + bool &NoSignedWrap, + bool &NoUnsignedWrap) { // Verify that the loop is sane and find the exit condition. const ICmpInst *Cmp = dyn_cast(OrigCond); - if (!Cmp) return false; + if (!Cmp) return 0; - // For now, analyze only SLT loops for signed overflow. - if (Cmp->getPredicate() != ICmpInst::ICMP_SLT) return false; + const Value *CmpLHS = Cmp->getOperand(0); + const Value *CmpRHS = Cmp->getOperand(1); + const BasicBlock *TrueBB = BI->getSuccessor(0); + const BasicBlock *FalseBB = BI->getSuccessor(1); + ICmpInst::Predicate Pred = Cmp->getPredicate(); + + // Canonicalize a constant to the RHS. + if (isa(CmpLHS)) { + Pred = ICmpInst::getSwappedPredicate(Pred); + std::swap(CmpLHS, CmpRHS); + } + // Canonicalize SLE to SLT. + if (Pred == ICmpInst::ICMP_SLE) + if (const ConstantInt *CI = dyn_cast(CmpRHS)) + if (!CI->getValue().isMaxSignedValue()) { + CmpRHS = ConstantInt::get(CI->getValue() + 1); + Pred = ICmpInst::ICMP_SLT; + } + // Canonicalize SGT to SGE. + if (Pred == ICmpInst::ICMP_SGT) + if (const ConstantInt *CI = dyn_cast(CmpRHS)) + if (!CI->getValue().isMaxSignedValue()) { + CmpRHS = ConstantInt::get(CI->getValue() + 1); + Pred = ICmpInst::ICMP_SGE; + } + // Canonicalize SGE to SLT. + if (Pred == ICmpInst::ICMP_SGE) { + std::swap(TrueBB, FalseBB); + Pred = ICmpInst::ICMP_SLT; + } + // Canonicalize ULE to ULT. + if (Pred == ICmpInst::ICMP_ULE) + if (const ConstantInt *CI = dyn_cast(CmpRHS)) + if (!CI->getValue().isMaxValue()) { + CmpRHS = ConstantInt::get(CI->getValue() + 1); + Pred = ICmpInst::ICMP_ULT; + } + // Canonicalize UGT to UGE. + if (Pred == ICmpInst::ICMP_UGT) + if (const ConstantInt *CI = dyn_cast(CmpRHS)) + if (!CI->getValue().isMaxValue()) { + CmpRHS = ConstantInt::get(CI->getValue() + 1); + Pred = ICmpInst::ICMP_UGE; + } + // Canonicalize UGE to ULT. + if (Pred == ICmpInst::ICMP_UGE) { + std::swap(TrueBB, FalseBB); + Pred = ICmpInst::ICMP_ULT; + } + // For now, analyze only LT loops for signed overflow. + if (Pred != ICmpInst::ICMP_SLT && Pred != ICmpInst::ICMP_ULT) + return 0; - // Get the increment instruction. Look past SExtInsts if we will + bool isSigned = Pred == ICmpInst::ICMP_SLT; + + // Get the increment instruction. Look past casts if we will // be able to prove that the original induction variable doesn't - // undergo signed overflow. - const Value *OrigIncrVal = Cmp->getOperand(0); - const Value *IncrVal = OrigIncrVal; - if (SExtInst *SI = dyn_cast(Cmp->getOperand(0))) { - if (!isa(Cmp->getOperand(1)) || - !cast(Cmp->getOperand(1))->getValue() - .isSignedIntN(IncrVal->getType()->getPrimitiveSizeInBits())) - return false; - IncrVal = SI->getOperand(0); + // undergo signed or unsigned overflow, respectively. + const Value *IncrVal = CmpLHS; + if (isSigned) { + if (const SExtInst *SI = dyn_cast(CmpLHS)) { + if (!isa(CmpRHS) || + !cast(CmpRHS)->getValue() + .isSignedIntN(IncrVal->getType()->getPrimitiveSizeInBits())) + return 0; + IncrVal = SI->getOperand(0); + } + } else { + if (const ZExtInst *ZI = dyn_cast(CmpLHS)) { + if (!isa(CmpRHS) || + !cast(CmpRHS)->getValue() + .isIntN(IncrVal->getType()->getPrimitiveSizeInBits())) + return 0; + IncrVal = ZI->getOperand(0); + } } // For now, only analyze induction variables that have simple increments. @@ -493,32 +562,37 @@ IncrOp->getOpcode() != Instruction::Add || !isa(IncrOp->getOperand(1)) || !cast(IncrOp->getOperand(1))->equalsInt(1)) - return false; + return 0; // Make sure the PHI looks like a normal IV. const PHINode *PN = dyn_cast(IncrOp->getOperand(0)); if (!PN || PN->getNumIncomingValues() != 2) - return false; + return 0; unsigned IncomingEdge = L->contains(PN->getIncomingBlock(0)); unsigned BackEdge = !IncomingEdge; if (!L->contains(PN->getIncomingBlock(BackEdge)) || PN->getIncomingValue(BackEdge) != IncrOp) - return false; + return 0; + if (!L->contains(TrueBB)) + return 0; // For now, only analyze loops with a constant start value, so that - // we can easily determine if the start value is non-negative and - // not a maximum value which would wrap on the first iteration. + // we can easily determine if the start value is not a maximum value + // which would wrap on the first iteration. const Value *InitialVal = PN->getIncomingValue(IncomingEdge); - if (!isa(InitialVal) || - cast(InitialVal)->getValue().isNegative() || - cast(InitialVal)->getValue().isMaxSignedValue()) - return false; + if (!isa(InitialVal)) + return 0; - // The original induction variable will start at some non-negative - // non-max value, it counts up by one, and the loop iterates only - // while it remans less than (signed) some value in the same type. - // As such, it will always be non-negative. - return true; + // The original induction variable will start at some non-max value, + // it counts up by one, and the loop iterates only while it remans + // less than some value in the same type. As such, it will never wrap. + if (isSigned && + !cast(InitialVal)->getValue().isMaxSignedValue()) + NoSignedWrap = true; + else if (!isSigned && + !cast(InitialVal)->getValue().isMaxValue()) + NoUnsignedWrap = true; + return PN; } bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { @@ -551,15 +625,14 @@ PHINode *PN = cast(I); if (PN->getType()->isInteger()) { // FIXME: when we have fast-math, enable! SCEVHandle SCEV = SE->getSCEV(PN); - if (SCEV->hasComputableLoopEvolution(L)) - // FIXME: It is an extremely bad idea to indvar substitute anything more - // complex than affine induction variables. Doing so will put expensive - // polynomial evaluations inside of the loop, and the str reduction pass - // currently can only reduce affine polynomials. For now just disable - // indvar subst on anything more complex than an affine addrec. - if (SCEVAddRecExpr *AR = dyn_cast(SCEV)) - if (AR->isAffine()) - IndVars.push_back(std::make_pair(PN, SCEV)); + // FIXME: It is an extremely bad idea to indvar substitute anything more + // complex than affine induction variables. Doing so will put expensive + // polynomial evaluations inside of the loop, and the str reduction pass + // currently can only reduce affine polynomials. For now just disable + // indvar subst on anything more complex than an affine addrec. + if (SCEVAddRecExpr *AR = dyn_cast(SCEV)) + if (AR->getLoop() == L && AR->isAffine()) + IndVars.push_back(std::make_pair(PN, SCEV)); } } @@ -597,13 +670,17 @@ // If we have a trip count expression, rewrite the loop's exit condition // using it. We can currently only handle loops with a single exit. - bool OrigIVAlwaysNonNegative = false; + bool NoSignedWrap = false; + bool NoUnsignedWrap = false; + const PHINode *OrigControllingPHI = 0; if (!isa(IterationCount) && ExitingBlock) // Can't rewrite non-branch yet. if (BranchInst *BI = dyn_cast(ExitingBlock->getTerminator())) { if (Instruction *OrigCond = dyn_cast(BI->getCondition())) { - // Determine if the OrigIV will ever have a non-zero sign bit. - OrigIVAlwaysNonNegative = isOrigIVAlwaysNonNegative(L, OrigCond); + // Determine if the OrigIV will ever undergo overflow. + OrigControllingPHI = + TestOrigIVForWrap(L, BI, OrigCond, + NoSignedWrap, NoUnsignedWrap); // We'll be replacing the original condition, so it'll be dead. DeadInsts.insert(OrigCond); @@ -635,27 +712,47 @@ // variable. while (!IndVars.empty()) { PHINode *PN = IndVars.back().first; - Value *NewVal = Rewriter.expandCodeFor(IndVars.back().second, InsertPt); - DOUT << "INDVARS: Rewrote IV '" << *IndVars.back().second << "' " << *PN + SCEVAddRecExpr *AR = cast(IndVars.back().second); + Value *NewVal = Rewriter.expandCodeFor(AR, InsertPt); + DOUT << "INDVARS: Rewrote IV '" << *AR << "' " << *PN << " into = " << *NewVal << "\n"; NewVal->takeName(PN); /// If the new canonical induction variable is wider than the original, /// and the original has uses that are casts to wider types, see if the /// truncate and extend can be omitted. - if (isa(NewVal)) + if (PN == OrigControllingPHI && PN->getType() != LargestType) for (Value::use_iterator UI = PN->use_begin(), UE = PN->use_end(); - UI != UE; ++UI) - if (isa(UI) || - (isa(UI) && OrigIVAlwaysNonNegative)) { - Value *TruncIndVar = IndVar; - if (TruncIndVar->getType() != UI->getType()) - TruncIndVar = new TruncInst(IndVar, UI->getType(), "truncindvar", - InsertPt); + UI != UE; ++UI) { + if (isa(UI) && NoSignedWrap) { + SCEVHandle ExtendedStart = + SE->getSignExtendExpr(AR->getStart(), LargestType); + SCEVHandle ExtendedStep = + SE->getSignExtendExpr(AR->getStepRecurrence(*SE), LargestType); + SCEVHandle ExtendedAddRec = + SE->getAddRecExpr(ExtendedStart, ExtendedStep, L); + if (LargestType != UI->getType()) + ExtendedAddRec = SE->getTruncateExpr(ExtendedAddRec, UI->getType()); + Value *TruncIndVar = Rewriter.expandCodeFor(ExtendedAddRec, InsertPt); + UI->replaceAllUsesWith(TruncIndVar); + if (Instruction *DeadUse = dyn_cast(*UI)) + DeadInsts.insert(DeadUse); + } + if (isa(UI) && NoUnsignedWrap) { + SCEVHandle ExtendedStart = + SE->getZeroExtendExpr(AR->getStart(), LargestType); + SCEVHandle ExtendedStep = + SE->getZeroExtendExpr(AR->getStepRecurrence(*SE), LargestType); + SCEVHandle ExtendedAddRec = + SE->getAddRecExpr(ExtendedStart, ExtendedStep, L); + if (LargestType != UI->getType()) + ExtendedAddRec = SE->getTruncateExpr(ExtendedAddRec, UI->getType()); + Value *TruncIndVar = Rewriter.expandCodeFor(ExtendedAddRec, InsertPt); UI->replaceAllUsesWith(TruncIndVar); if (Instruction *DeadUse = dyn_cast(*UI)) DeadInsts.insert(DeadUse); } + } // Replace the old PHI Node with the inserted computation. PN->replaceAllUsesWith(NewVal); @@ -665,32 +762,6 @@ Changed = true; } -#if 0 - // Now replace all derived expressions in the loop body with simpler - // expressions. - for (LoopInfo::block_iterator I = L->block_begin(), E = L->block_end(); - I != E; ++I) { - BasicBlock *BB = *I; - if (LI->getLoopFor(BB) == L) { // Not in a subloop... - for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) - if (I->getType()->isInteger() && // Is an integer instruction - !I->use_empty() && - !Rewriter.isInsertedInstruction(I)) { - SCEVHandle SH = SE->getSCEV(I); - Value *V = Rewriter.expandCodeFor(SH, I, I->getType()); - if (V != I) { - if (isa(V)) - V->takeName(I); - I->replaceAllUsesWith(V); - DeadInsts.insert(I); - ++NumRemoved; - Changed = true; - } - } - } - } -#endif - DeleteTriviallyDeadInstructions(DeadInsts); assert(L->isLCSSAForm()); return Changed; @@ -701,14 +772,14 @@ static bool useSIToFPInst(ConstantFP &InitV, ConstantFP &ExitV, uint64_t intIV, uint64_t intEV) { - if (InitV.getValueAPF().isNegative() || ExitV.getValueAPF().isNegative()) + if (InitV.getValueAPF().isNegative() || ExitV.getValueAPF().isNegative()) return true; // If the iteration range can be handled by SIToFPInst then use it. APInt Max = APInt::getSignedMaxValue(32); if (Max.getZExtValue() > static_cast(abs(intEV - intIV))) return true; - + return false; } @@ -718,11 +789,11 @@ bool isExact = false; if (&APF.getSemantics() == &APFloat::PPCDoubleDouble) return false; - if (APF.convertToInteger(intVal, 32, APF.isNegative(), + if (APF.convertToInteger(intVal, 32, APF.isNegative(), APFloat::rmTowardZero, &isExact) != APFloat::opOK) return false; - if (!isExact) + if (!isExact) return false; return true; @@ -737,12 +808,12 @@ /// for(int i = 0; i < 10000; ++i) /// bar((double)i); /// -void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PH, +void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PH, SmallPtrSet &DeadInsts) { unsigned IncomingEdge = L->contains(PH->getIncomingBlock(0)); unsigned BackEdge = IncomingEdge^1; - + // Check incoming value. ConstantFP *InitValue = dyn_cast(PH->getIncomingValue(IncomingEdge)); if (!InitValue) return; @@ -752,7 +823,7 @@ // Check IV increment. Reject this PH if increement operation is not // an add or increment value can not be represented by an integer. - BinaryOperator *Incr = + BinaryOperator *Incr = dyn_cast(PH->getIncomingValue(BackEdge)); if (!Incr) return; if (Incr->getOpcode() != Instruction::Add) return; @@ -765,7 +836,7 @@ uint64_t newIncrValue = Type::Int32Ty->getPrimitiveSizeInBits(); if (!convertToInt(IncrValue->getValueAPF(), &newIncrValue)) return; - + // Check Incr uses. One user is PH and the other users is exit condition used // by the conditional terminator. Value::use_iterator IncrUse = Incr->use_begin(); @@ -773,7 +844,7 @@ if (IncrUse == Incr->use_end()) return; Instruction *U2 = cast(IncrUse++); if (IncrUse != Incr->use_end()) return; - + // Find exit condition. FCmpInst *EC = dyn_cast(U1); if (!EC) @@ -796,7 +867,7 @@ uint64_t intEV = Type::Int32Ty->getPrimitiveSizeInBits(); if (!convertToInt(EV->getValueAPF(), &intEV)) return; - + // Find new predicate for integer comparison. CmpInst::Predicate NewPred = CmpInst::BAD_ICMP_PREDICATE; switch (EC->getPredicate()) { @@ -824,15 +895,15 @@ break; } if (NewPred == CmpInst::BAD_ICMP_PREDICATE) return; - + // Insert new integer induction variable. PHINode *NewPHI = PHINode::Create(Type::Int32Ty, PH->getName()+".int", PH); NewPHI->addIncoming(ConstantInt::get(Type::Int32Ty, newInitValue), PH->getIncomingBlock(IncomingEdge)); - Value *NewAdd = BinaryOperator::CreateAdd(NewPHI, - ConstantInt::get(Type::Int32Ty, + Value *NewAdd = BinaryOperator::CreateAdd(NewPHI, + ConstantInt::get(Type::Int32Ty, newIncrValue), Incr->getName()+".int", Incr); NewPHI->addIncoming(NewAdd, PH->getIncomingBlock(BackEdge)); @@ -840,25 +911,25 @@ ConstantInt *NewEV = ConstantInt::get(Type::Int32Ty, intEV); Value *LHS = (EVIndex == 1 ? NewPHI->getIncomingValue(BackEdge) : NewEV); Value *RHS = (EVIndex == 1 ? NewEV : NewPHI->getIncomingValue(BackEdge)); - ICmpInst *NewEC = new ICmpInst(NewPred, LHS, RHS, EC->getNameStart(), + ICmpInst *NewEC = new ICmpInst(NewPred, LHS, RHS, EC->getNameStart(), EC->getParent()->getTerminator()); - + // Delete old, floating point, exit comparision instruction. EC->replaceAllUsesWith(NewEC); DeadInsts.insert(EC); - + // Delete old, floating point, increment instruction. Incr->replaceAllUsesWith(UndefValue::get(Incr->getType())); DeadInsts.insert(Incr); - + // Replace floating induction variable. Give SIToFPInst preference over // UIToFPInst because it is faster on platforms that are widely used. if (useSIToFPInst(*InitValue, *EV, newInitValue, intEV)) { - SIToFPInst *Conv = new SIToFPInst(NewPHI, PH->getType(), "indvar.conv", + SIToFPInst *Conv = new SIToFPInst(NewPHI, PH->getType(), "indvar.conv", PH->getParent()->getFirstNonPHI()); PH->replaceAllUsesWith(Conv); } else { - UIToFPInst *Conv = new UIToFPInst(NewPHI, PH->getType(), "indvar.conv", + UIToFPInst *Conv = new UIToFPInst(NewPHI, PH->getType(), "indvar.conv", PH->getParent()->getFirstNonPHI()); PH->replaceAllUsesWith(Conv); } From isanbard at gmail.com Wed Feb 18 21:51:41 2009 From: isanbard at gmail.com (Bill Wendling) Date: Thu, 19 Feb 2009 03:51:41 -0000 Subject: [llvm-commits] [llvm] r65002 - in /llvm/branches/Apple/Dib/test/Transforms: IndVarSimplify/ IndVarSimplify/preserve-signed-wrap.ll IndVarsSimplify/ Message-ID: <200902190351.n1J3pfn6025169@zion.cs.uiuc.edu> Author: void Date: Wed Feb 18 21:51:41 2009 New Revision: 65002 URL: http://llvm.org/viewvc/llvm-project?rev=65002&view=rev Log: Rename IndVarsSimplify to IndVarSimplify. Add preserve-signed-wrap.ll. Added: llvm/branches/Apple/Dib/test/Transforms/IndVarSimplify/ - copied from r65001, llvm/branches/Apple/Dib/test/Transforms/IndVarsSimplify/ llvm/branches/Apple/Dib/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll Removed: llvm/branches/Apple/Dib/test/Transforms/IndVarsSimplify/ Added: llvm/branches/Apple/Dib/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll?rev=65002&view=auto ============================================================================== --- llvm/branches/Apple/Dib/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll (added) +++ llvm/branches/Apple/Dib/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll Wed Feb 18 21:51:41 2009 @@ -0,0 +1,39 @@ +; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t +; RUN: grep sext %t | count 2 +; RUN: grep { = sext i32 %n to i64} %t +; RUN: grep phi %t | count 1 +; RUN: grep {phi i64} %t + +; Indvars should insert a 64-bit induction variable to eliminate the +; sext for the addressing, however it shouldn't eliminate the sext +; on the other phi, since that value undergoes signed wrapping. + +define void @foo(i32* nocapture %d, i32 %n) nounwind { +entry: + %0 = icmp sgt i32 %n, 0 ; [#uses=1] + br i1 %0, label %bb.nph, label %return + +bb.nph: ; preds = %entry + br label %bb + +bb: ; preds = %bb1, %bb.nph + %i.02 = phi i32 [ %5, %bb1 ], [ 0, %bb.nph ] ; [#uses=2] + %p.01 = phi i8 [ %4, %bb1 ], [ -1, %bb.nph ] ; [#uses=2] + %1 = sext i8 %p.01 to i32 ; [#uses=1] + %2 = sext i32 %i.02 to i64 ; [#uses=1] + %3 = getelementptr i32* %d, i64 %2 ; [#uses=1] + store i32 %1, i32* %3, align 4 + %4 = add i8 %p.01, 1 ; [#uses=1] + %5 = add i32 %i.02, 1 ; [#uses=2] + br label %bb1 + +bb1: ; preds = %bb + %6 = icmp slt i32 %5, %n ; [#uses=1] + br i1 %6, label %bb, label %bb1.return_crit_edge + +bb1.return_crit_edge: ; preds = %bb1 + br label %return + +return: ; preds = %bb1.return_crit_edge, %entry + ret void +} From clattner at apple.com Wed Feb 18 22:05:07 2009 From: clattner at apple.com (Chris Lattner) Date: Wed, 18 Feb 2009 20:05:07 -0800 Subject: [llvm-commits] [llvm] r64877 - in /llvm/trunk: lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp test/CodeGen/X86/cstring.ll In-Reply-To: <58EA4AC3-53A7-43DB-937A-E49FBA733FA4@apple.com> References: <200902180219.n1I2JrjZ030169@zion.cs.uiuc.edu> <3C282F1A-29E3-4412-827D-473C0C637C7F@apple.com> <27A4E95A-B7DA-4385-9739-6239A4837A40@apple.com> <67EABC6B-468D-48DD-BACC-12C0783416CD@apple.com> <4CC992DF-6EF3-4FF3-8B81-7F3777E1BD3E@apple.com> <58EA4AC3-53A7-43DB-937A-E49FBA733FA4@apple.com> Message-ID: On Feb 18, 2009, at 6:16 PM, Dale Johannesen wrote: > > On Feb 18, 2009, at 5:52 PMPST, Chris Lattner wrote: > >> On Feb 17, 2009, at 11:08 PM, Evan Cheng wrote: >>>>> rdar://6479858. It's a minor size win, but more importantly it >>>>> avoids linker warning. That means fewer complaints about llvm- >>>>> gcc (and it has been reported at least twice so far at Apple). >>>> >>>> Then this is not an optimization, this is a semantic property. >>>> Whatever is creating that literal string should pin it in the >>>> section that it requires it to be in. >>> >>> I don't understand your objection. What's wrong with putting >>> constant array of i8 terminated with zero into cstring sections? >>> Do we need to have the frontend pre-determine the sections for all >>> of these strings? >>> >> >> Evan and I discussed this offline. The result is that I agree that >> there is nothing wrong with this patch, but that there is another >> underlying bug that this is being used to hide. >> >> The problem is that darwin really needs the STRING_CST to be >> emitted to a specific section. The "right" answer is to change >> darwin_build_constant_cfstring in config/darwin.c to tag the node >> as needing to be in the cstring section, and then the codegen will >> do the right thing. >> >> The problem is that DECL_SECTION cannot be used on STRING_CST. >> Does anyone know a good solution for this? This is easy to fix in >> clang, but it would be nice for llvm-gcc to not rely on subtle >> behavior of the code generator for its correctness. > > The most straightforward would be add a section_name field to the > STRING_CST node (struct tree_string in tree.h). Another option that occurred to me: we could just setSection() on *all* STRING_CSTs. Duncan, what do you think about that? -Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090218/329fe139/attachment.html From kremenek at apple.com Wed Feb 18 22:45:07 2009 From: kremenek at apple.com (Ted Kremenek) Date: Thu, 19 Feb 2009 04:45:07 -0000 Subject: [llvm-commits] [llvm] r65007 - /llvm/tags/checker/checker-0.159/ Message-ID: <200902190445.n1J4j7hI027137@zion.cs.uiuc.edu> Author: kremenek Date: Wed Feb 18 22:45:07 2009 New Revision: 65007 URL: http://llvm.org/viewvc/llvm-project?rev=65007&view=rev Log: Tagging checker-0.159. Added: llvm/tags/checker/checker-0.159/ - copied from r65006, llvm/trunk/ From kremenek at apple.com Wed Feb 18 22:54:01 2009 From: kremenek at apple.com (Ted Kremenek) Date: Thu, 19 Feb 2009 04:54:01 -0000 Subject: [llvm-commits] [llvm] r65010 - /llvm/tags/checker/checker-0.159/ Message-ID: <200902190454.n1J4s1AT027504@zion.cs.uiuc.edu> Author: kremenek Date: Wed Feb 18 22:54:01 2009 New Revision: 65010 URL: http://llvm.org/viewvc/llvm-project?rev=65010&view=rev Log: Removing checker-0.159. Removed: llvm/tags/checker/checker-0.159/ From kremenek at apple.com Wed Feb 18 22:58:44 2009 From: kremenek at apple.com (Ted Kremenek) Date: Thu, 19 Feb 2009 04:58:44 -0000 Subject: [llvm-commits] [llvm] r65015 - /llvm/tags/checker/checker-0.159/ Message-ID: <200902190458.n1J4wiI2027702@zion.cs.uiuc.edu> Author: kremenek Date: Wed Feb 18 22:58:44 2009 New Revision: 65015 URL: http://llvm.org/viewvc/llvm-project?rev=65015&view=rev Log: Tagging checker-0.159. Added: llvm/tags/checker/checker-0.159/ - copied from r65014, llvm/trunk/ From echristo at apple.com Wed Feb 18 23:02:54 2009 From: echristo at apple.com (Eric Christopher) Date: Wed, 18 Feb 2009 21:02:54 -0800 Subject: [llvm-commits] [llvm] r64877 - in /llvm/trunk: lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp test/CodeGen/X86/cstring.ll In-Reply-To: References: <200902180219.n1I2JrjZ030169@zion.cs.uiuc.edu> <3C282F1A-29E3-4412-827D-473C0C637C7F@apple.com> <27A4E95A-B7DA-4385-9739-6239A4837A40@apple.com> <67EABC6B-468D-48DD-BACC-12C0783416CD@apple.com> <4CC992DF-6EF3-4FF3-8B81-7F3777E1BD3E@apple.com> <58EA4AC3-53A7-43DB-937A-E49FBA733FA4@apple.com> Message-ID: <1406969C-B080-4FB1-8FAF-C2988B7E0182@apple.com> On Feb 18, 2009, at 8:05 PM, Chris Lattner wrote: >> >> The most straightforward would be add a section_name field to the >> STRING_CST node (struct tree_string in tree.h). > > Another option that occurred to me: we could just setSection() on > *all* STRING_CSTs. Duncan, what do you think about that? > This is effectively what gcc does on this sort of thing. Probably do it similarly to emit_global_to_llvm? -eric From sabre at nondot.org Wed Feb 18 23:34:35 2009 From: sabre at nondot.org (Chris Lattner) Date: Thu, 19 Feb 2009 05:34:35 -0000 Subject: [llvm-commits] [llvm] r65017 - /llvm/trunk/lib/System/Unix/Path.inc Message-ID: <200902190534.n1J5YaVY028969@zion.cs.uiuc.edu> Author: lattner Date: Wed Feb 18 23:34:35 2009 New Revision: 65017 URL: http://llvm.org/viewvc/llvm-project?rev=65017&view=rev Log: If an executable is run through a symlink, dladdr will return the symlink. We really want the ultimate executable being run, not the symlink. This lets clang find its headers when invoked through a symlink. rdar://6602012 Modified: llvm/trunk/lib/System/Unix/Path.inc Modified: llvm/trunk/lib/System/Unix/Path.inc URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Unix/Path.inc?rev=65017&r1=65016&r2=65017&view=diff ============================================================================== --- llvm/trunk/lib/System/Unix/Path.inc (original) +++ llvm/trunk/lib/System/Unix/Path.inc Wed Feb 18 23:34:35 2009 @@ -117,7 +117,7 @@ } Path -Path::GetTemporaryDirectory(std::string* ErrMsg ) { +Path::GetTemporaryDirectory(std::string *ErrMsg) { #if defined(HAVE_MKDTEMP) // The best way is with mkdtemp but that's not available on many systems, // Linux and FreeBSD have it. Others probably won't. @@ -280,8 +280,13 @@ // Use dladdr to get executable path if available. Dl_info DLInfo; int err = dladdr(MainAddr, &DLInfo); - if (err != 0) - return Path(std::string(DLInfo.dli_fname)); + if (err == 0) + return Path(); + + // If the filename is a symlink, we need to resolve and return the location of + // the actual executable. + char link_path[MAXPATHLEN]; + return Path(std::string(realpath(DLInfo.dli_fname, link_path))); #endif return Path(); } From isanbard at gmail.com Thu Feb 19 00:12:30 2009 From: isanbard at gmail.com (Bill Wendling) Date: Wed, 18 Feb 2009 22:12:30 -0800 Subject: [llvm-commits] [llvm] r64987 - /llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp In-Reply-To: <4574B3B1-DEF8-47AC-BADA-2B5344EF9453@apple.com> References: <200902190013.n1J0DtwA018437@zion.cs.uiuc.edu> <4574B3B1-DEF8-47AC-BADA-2B5344EF9453@apple.com> Message-ID: <88DA3C3A-8BEB-434C-B85A-FEC27E97F620@gmail.com> I have to investigate a debugging thing. I think it's due to one of my patches. -bw On Feb 18, 2009, at 4:45 PM, Evan Cheng wrote: > Why xfail it? What broke? > > Evan > > On Feb 18, 2009, at 4:13 PM, Bill Wendling wrote: > >> Author: void >> Date: Wed Feb 18 18:13:55 2009 >> New Revision: 64987 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=64987&view=rev >> Log: >> Temporarily XFAIL this test. >> >> Modified: >> llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp >> >> Modified: llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp >> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FrontendC%2B%2B/2006-11-06-StackTrace.cpp?rev=64987&r1=64986&r2=64987&view=diff >> >> = >> = >> = >> = >> = >> = >> = >> = >> = >> ===================================================================== >> --- llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp (original) >> +++ llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp Wed Feb 18 >> 18:13:55 2009 >> @@ -11,6 +11,7 @@ >> >> // Only works on ppc, x86 and x86_64. Should generalize? >> // XFAIL: alpha|ia64|arm >> +// XFAIL: * >> >> #include >> >> >> >> _______________________________________________ >> llvm-commits mailing list >> llvm-commits at cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits From echeng at apple.com Thu Feb 19 00:13:03 2009 From: echeng at apple.com (Evan Cheng) Date: Wed, 18 Feb 2009 22:13:03 -0800 Subject: [llvm-commits] [llvm] r64987 - /llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp In-Reply-To: <88DA3C3A-8BEB-434C-B85A-FEC27E97F620@gmail.com> References: <200902190013.n1J0DtwA018437@zion.cs.uiuc.edu> <4574B3B1-DEF8-47AC-BADA-2B5344EF9453@apple.com> <88DA3C3A-8BEB-434C-B85A-FEC27E97F620@gmail.com> Message-ID: Ok. Thanks! Evan On Feb 18, 2009, at 10:12 PM, Bill Wendling wrote: > I have to investigate a debugging thing. I think it's due to one of my > patches. > > -bw > > On Feb 18, 2009, at 4:45 PM, Evan Cheng wrote: > >> Why xfail it? What broke? >> >> Evan >> >> On Feb 18, 2009, at 4:13 PM, Bill Wendling wrote: >> >>> Author: void >>> Date: Wed Feb 18 18:13:55 2009 >>> New Revision: 64987 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=64987&view=rev >>> Log: >>> Temporarily XFAIL this test. >>> >>> Modified: >>> llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp >>> >>> Modified: llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp >>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FrontendC%2B%2B/2006-11-06-StackTrace.cpp?rev=64987&r1=64986&r2=64987&view=diff >>> >>> = >>> = >>> = >>> = >>> = >>> = >>> = >>> = >>> = >>> = >>> ==================================================================== >>> --- llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp (original) >>> +++ llvm/trunk/test/FrontendC++/2006-11-06-StackTrace.cpp Wed Feb 18 >>> 18:13:55 2009 >>> @@ -11,6 +11,7 @@ >>> >>> // Only works on ppc, x86 and x86_64. Should generalize? >>> // XFAIL: alpha|ia64|arm >>> +// XFAIL: * >>> >>> #include >>> >>> >>> >>> _______________________________________________ >>> llvm-commits mailing list >>> llvm-commits at cs.uiuc.edu >>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits >> >> _______________________________________________ >> llvm-commits mailing list >> llvm-commits at cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits From nicholas at mxc.ca Thu Feb 19 00:18:26 2009 From: nicholas at mxc.ca (Nick Lewycky) Date: Thu, 19 Feb 2009 06:18:26 -0000 Subject: [llvm-commits] [llvm] r65019 - /llvm/trunk/autoconf/configure.ac Message-ID: <200902190618.n1J6IRIg019643@zion.cs.uiuc.edu> Author: nicholas Date: Thu Feb 19 00:18:24 2009 New Revision: 65019 URL: http://llvm.org/viewvc/llvm-project?rev=65019&view=rev Log: Default to building with position independent code. This may increase LLVM's run time but will make LLVM easier to use as a library. Modified: llvm/trunk/autoconf/configure.ac Modified: llvm/trunk/autoconf/configure.ac URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/autoconf/configure.ac?rev=65019&r1=65018&r2=65019&view=diff ============================================================================== --- llvm/trunk/autoconf/configure.ac (original) +++ llvm/trunk/autoconf/configure.ac Thu Feb 19 00:18:24 2009 @@ -363,15 +363,15 @@ esac AC_DEFINE_UNQUOTED([ENABLE_THREADS],$ENABLE_THREADS,[Define if threads enabled]) -dnl Allow building with position independent code +dnl Allow building without position independent code AC_ARG_ENABLE(pic, AS_HELP_STRING([--enable-pic], - [Build LLVM with Position Independent Code (default is NO)]),, + [Build LLVM with Position Independent Code (default is YES)]),, enableval=default) case "$enableval" in yes) AC_SUBST(ENABLE_PIC,[1]) ;; no) AC_SUBST(ENABLE_PIC,[0]) ;; - default) AC_SUBST(ENABLE_PIC,[0]) ;; + default) AC_SUBST(ENABLE_PIC,[1]) ;; *) AC_MSG_ERROR([Invalid setting for --enable-pic. Use "yes" or "no"]) ;; esac AC_DEFINE_UNQUOTED([ENABLE_PIC],$ENABLE_PIC, From nicholas at mxc.ca Thu Feb 19 00:18:56 2009 From: nicholas at mxc.ca (Nick Lewycky) Date: Thu, 19 Feb 2009 06:18:56 -0000 Subject: [llvm-commits] [llvm] r65020 - /llvm/trunk/configure Message-ID: <200902190618.n1J6Iv91019674@zion.cs.uiuc.edu> Author: nicholas Date: Thu Feb 19 00:18:56 2009 New Revision: 65020 URL: http://llvm.org/viewvc/llvm-project?rev=65020&view=rev Log: Regenerate. Modified: llvm/trunk/configure Modified: llvm/trunk/configure URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/configure?rev=65020&r1=65019&r2=65020&view=diff ============================================================================== --- llvm/trunk/configure (original) +++ llvm/trunk/configure Thu Feb 19 00:18:56 2009 @@ -1547,7 +1547,7 @@ --enable-doxygen Build doxygen documentation (default is NO) --enable-threads Use threads if available (default is YES) --enable-pic Build LLVM with Position Independent Code (default - is NO) + is YES) --enable-targets Build specific host targets: all,host-only,{target-name} (default=all) --enable-cbe-printf-a Enable C Backend output with hex floating point via @@ -4878,7 +4878,7 @@ ;; no) ENABLE_PIC=0 ;; - default) ENABLE_PIC=0 + default) ENABLE_PIC=1 ;; *) { { echo "$as_me:$LINENO: error: Invalid setting for --enable-pic. Use \"yes\" or \"no\"" >&5 echo "$as_me: error: Invalid setting for --enable-pic. Use \"yes\" or \"no\"" >&2;} From isanbard at gmail.com Thu Feb 19 02:06:13 2009 From: isanbard at gmail.com (Bill Wendling) Date: Thu, 19 Feb 2009 08:06:13 -0000 Subject: [llvm-commits] [llvm] r65034 - /llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp Message-ID: <200902190806.n1J86EHA023890@zion.cs.uiuc.edu> Author: void Date: Thu Feb 19 02:06:12 2009 New Revision: 65034 URL: http://llvm.org/viewvc/llvm-project?rev=65034&view=rev Log: Forgot to check that debug information is supported. Modified: llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp Modified: llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp?rev=65034&r1=65033&r2=65034&view=diff ============================================================================== --- llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp (original) +++ llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp Thu Feb 19 02:06:12 2009 @@ -640,7 +640,7 @@ } O << "\";\n\n"; - O << " {\n" + O << " if (TAI->doesSupportDebugInformation()) {\n" << " const MachineFunction *MF = MI->getParent()->getParent();\n" << " static DebugLoc PrevDL = DebugLoc::getUnknownLoc();\n" << " DebugLoc CurDL = MI->getDebugLoc();\n\n" @@ -649,7 +649,7 @@ << " printLabel(DW->RecordSourceLine(DLT.Line, DLT.Col, DLT.Src));\n" << " }\n\n" << " PrevDL = CurDL;\n" - << " }\n"; + << " }\n\n"; O << " if (MI->getOpcode() == TargetInstrInfo::INLINEASM) {\n" << " O << \"\\t\";\n" From isanbard at gmail.com Thu Feb 19 03:16:39 2009 From: isanbard at gmail.com (Bill Wendling) Date: Thu, 19 Feb 2009 09:16:39 -0000 Subject: [llvm-commits] [llvm] r65039 - in /llvm/trunk: include/llvm/CodeGen/DebugLoc.h utils/TableGen/AsmWriterEmitter.cpp Message-ID: <200902190916.n1J9Gd04003878@zion.cs.uiuc.edu> Author: void Date: Thu Feb 19 03:16:38 2009 New Revision: 65039 URL: http://llvm.org/viewvc/llvm-project?rev=65039&view=rev Log: Print out a new label only if the debug location *tuple* is different. The debug locations may change, but the tuples may be the same. Modified: llvm/trunk/include/llvm/CodeGen/DebugLoc.h llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp Modified: llvm/trunk/include/llvm/CodeGen/DebugLoc.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/DebugLoc.h?rev=65039&r1=65038&r2=65039&view=diff ============================================================================== --- llvm/trunk/include/llvm/CodeGen/DebugLoc.h (original) +++ llvm/trunk/include/llvm/CodeGen/DebugLoc.h Thu Feb 19 03:16:38 2009 @@ -27,6 +27,13 @@ DebugLocTuple(unsigned s, unsigned l, unsigned c) : Src(s), Line(l), Col(c) {}; + + bool operator==(const DebugLocTuple &DLT) const { + return Src == DLT.Src && Line == DLT.Line && Col == DLT.Col; + } + bool operator!=(const DebugLocTuple &DLT) const { + return !(*this == DLT); + } }; /// DebugLoc - Debug location id. This is carried by SDNode and MachineInstr Modified: llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp?rev=65039&r1=65038&r2=65039&view=diff ============================================================================== --- llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp (original) +++ llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp Thu Feb 19 03:16:38 2009 @@ -642,13 +642,16 @@ O << " if (TAI->doesSupportDebugInformation()) {\n" << " const MachineFunction *MF = MI->getParent()->getParent();\n" - << " static DebugLoc PrevDL = DebugLoc::getUnknownLoc();\n" << " DebugLoc CurDL = MI->getDebugLoc();\n\n" - << " if (!CurDL.isUnknown() && PrevDL != CurDL) {\n" - << " DebugLocTuple DLT = MF->getDebugLocTuple(CurDL);\n" - << " printLabel(DW->RecordSourceLine(DLT.Line, DLT.Col, DLT.Src));\n" - << " }\n\n" - << " PrevDL = CurDL;\n" + << " if (!CurDL.isUnknown()) {\n" + << " static DebugLocTuple PrevDLT(~0U, ~0U, ~0U);\n" + << " DebugLocTuple CurDLT = MF->getDebugLocTuple(CurDL);\n\n" + << " if (PrevDLT != CurDLT) {\n" + << " printLabel(DW->RecordSourceLine(CurDLT.Line, CurDLT.Col,\n" + << " CurDLT.Src));\n" + << " PrevDLT = CurDLT;\n" + << " }\n" + << " }\n" << " }\n\n"; O << " if (MI->getOpcode() == TargetInstrInfo::INLINEASM) {\n" From edwintorok at gmail.com Thu Feb 19 06:03:00 2009 From: edwintorok at gmail.com (Torok Edwin) Date: Thu, 19 Feb 2009 12:03:00 -0000 Subject: [llvm-commits] [test-suite] r65042 - in /test-suite/trunk/MultiSource/Benchmarks/PAQ8p: ./ Makefile file1.in paq8p.cpp readme.txt Message-ID: <200902191203.n1JC31JX013216@zion.cs.uiuc.edu> Author: edwin Date: Thu Feb 19 06:02:53 2009 New Revision: 65042 URL: http://llvm.org/viewvc/llvm-project?rev=65042&view=rev Log: Add PAQ8p (arithmetic compression program) as benchmark. Although not seen from the test reports, gcc -O2 is about 15%-35% faster than gcc at -O3, or llvm-gcc at -O2 or -O3. See PR3534. Added: test-suite/trunk/MultiSource/Benchmarks/PAQ8p/ test-suite/trunk/MultiSource/Benchmarks/PAQ8p/Makefile test-suite/trunk/MultiSource/Benchmarks/PAQ8p/file1.in (with props) test-suite/trunk/MultiSource/Benchmarks/PAQ8p/paq8p.cpp test-suite/trunk/MultiSource/Benchmarks/PAQ8p/readme.txt Added: test-suite/trunk/MultiSource/Benchmarks/PAQ8p/Makefile URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/PAQ8p/Makefile?rev=65042&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/PAQ8p/Makefile (added) +++ test-suite/trunk/MultiSource/Benchmarks/PAQ8p/Makefile Thu Feb 19 06:02:53 2009 @@ -0,0 +1,11 @@ +LEVEL = ../../../ + +PROG = paq8p +CPPFLAGS += -DNOASM -DLLVM +LDFLAGS = -lstdc++ -lm +ifdef SMALL_PROBLEM_SIZE +RUN_OPTIONS = -1 file1.in +else +RUN_OPTIONS = -4 file1.in +endif +include $(LEVEL)/MultiSource/Makefile.multisrc Added: test-suite/trunk/MultiSource/Benchmarks/PAQ8p/file1.in URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/PAQ8p/file1.in?rev=65042&view=auto ============================================================================== Binary file - no diff available. Propchange: test-suite/trunk/MultiSource/Benchmarks/PAQ8p/file1.in ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: test-suite/trunk/MultiSource/Benchmarks/PAQ8p/paq8p.cpp URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/PAQ8p/paq8p.cpp?rev=65042&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/PAQ8p/paq8p.cpp (added) +++ test-suite/trunk/MultiSource/Benchmarks/PAQ8p/paq8p.cpp Thu Feb 19 06:02:53 2009 @@ -0,0 +1,4494 @@ +/* paq8p file compressor/archiver. Release by Andreas Morphis, Aug. 22, 2008 + + Copyright (C) 2008 Matt Mahoney, Serge Osnach, Alexander Ratushnyak, + Bill Pettis, Przemyslaw Skibinski, Matthew Fite, wowtiger, Andrew Paterson, + Jan Ondrus, Andreas Morphis, Pavel L. Holoborodko, KZ. + + LICENSE + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details at + Visit . + +To install and use in Windows: + +- To install, put paq8p.exe or a shortcut to it on your desktop. +- To compress a file or folder, drop it on the paq8p icon. +- To decompress, drop a .paq8p file on the icon. + +A .paq8p extension is added for compression, removed for decompression. +The output will go in the same folder as the input. + +While paq8p is working, a command window will appear and report +progress. When it is done you can close the window by pressing +ENTER or clicking [X]. + + +COMMAND LINE INTERFACE + +- To install, put paq8p.exe somewhere in your PATH. +- To compress: paq8p [-N] file1 [file2...] +- To decompress: paq8p [-d] file1.paq8p [dir2] +- To view contents: more < file1.paq8p + +The compressed output file is named by adding ".paq8p" extension to +the first named file (file1.paq8p). Each file that exists will be +added to the archive and its name will be stored without a path. +The option -N specifies a compression level ranging from -0 +(fastest) to -9 (smallest). The default is -5. If there is +no option and only one file, then the program will pause when +finished until you press the ENTER key (to support drag and drop). +If file1.paq8p exists then it is overwritten. + +If the first named file ends in ".paq8p" then it is assumed to be +an archive and the files within are extracted to the same directory +as the archive unless a different directory (dir2) is specified. +The -d option forces extraction even if there is not a ".paq8p" +extension. If any output file already exists, then it is compared +with the archive content and the first byte that differs is reported. +No files are overwritten or deleted. If there is only one argument +(no -d or dir2) then the program will pause when finished until +you press ENTER. + +For compression, if any named file is actually a directory, then all +files and subdirectories are compressed, preserving the directory +structure, except that empty directories are not stored, and file +attributes (timestamps, permissions, etc.) are not preserved. +During extraction, directories are created as needed. For example: + + paq8p -4 c:\tmp\foo bar + +compresses foo and bar (if they exist) to c:\tmp\foo.paq8p at level 4. + + paq8p -d c:\tmp\foo.paq8p . + +extracts foo and compares bar in the current directory. If foo and bar +are directories then their contents are extracted/compared. + +There are no commands to update an existing archive or to extract +part of an archive. Files and archives larger than 2GB are not +supported (but might work on 64-bit machines, not tested). +File names with nonprintable characters are not supported (spaces +are OK). + + +TO COMPILE + +There are 2 files: paq8p.cpp (C++) and paq7asm.asm (NASM/YASM). +paq7asm.asm is the same as in paq7 and paq8x. paq8p.cpp recognizes the +following compiler options: + + -DWINDOWS (to compile in Windows) + -DUNIX (to compile in Unix, Linux, Solairs, MacOS/Darwin, etc) + -DNOASM (to replace paq7asm.asm with equivalent C++) + -DDEFAULT_OPTION=N (to change the default compression level from 5 to N). + +If you compile without -DWINDOWS or -DUNIX, you can still compress files, +but you cannot compress directories or create them during extraction. +You can extract directories if you manually create the empty directories +first. + +Use -DEFAULT_OPTION=N to change the default compression level to support +drag and drop on machines with less than 256 MB of memory. Use +-DDEFAULT_OPTION=4 for 128 MB, 3 for 64 MB, 2 for 32 MB, etc. + +Use -DNOASM for non x86-32 machines, or older than a Pentium-MMX (about +1997), or if you don't have NASM or YASM to assemble paq7asm.asm. The +program will still work but it will be slower. For NASM in Windows, +use the options "--prefix _" and either "-f win32" or "-f obj" depending +on your C++ compiler. In Linux, use "-f elf". + +Recommended compiler commands and optimizations: + + MINGW g++: + nasm paq7asm.asm -f win32 --prefix _ + g++ paq8p.cpp -DWINDOWS -O2 -Os -s -march=pentiumpro -fomit-frame-pointer -o paq8p.exe paq7asm.obj + + Borland: + nasm paq7asm.asm -f obj --prefix _ + bcc32 -DWINDOWS -O -w-8027 paq8p.cpp paq7asm.obj + + Mars: + nasm paq7asm.asm -f obj --prefix _ + dmc -DWINDOWS -Ae -O paq8p.cpp paq7asm.obj + + UNIX/Linux (PC): + nasm -f elf paq7asm.asm + g++ paq8p.cpp -DUNIX -O2 -Os -s -march=pentiumpro -fomit-frame-pointer -o paq8p paq7asm.o + + Non PC (e.g. PowerPC under MacOS X) + g++ paq8p.cpp -O2 -DUNIX -DNOASM -s -o paq8p + +MinGW produces faster executables than Borland or Mars, but Intel 9 +is about 4% faster than MinGW). + + +ARCHIVE FILE FORMAT + +An archive has the following format. It is intended to be both +human and machine readable. The header ends with CTRL-Z (Windows EOF) +so that the binary compressed data is not displayed on the screen. + + paq8p -N CR LF + size TAB filename CR LF + size TAB filename CR LF + ... + CTRL-Z + compressed binary data + +-N is the option (-0 to -9), even if a default was used. +Plain file names are stored without a path. Files in compressed +directories are stored with path relative to the compressed directory +(using UNIX style forward slashes "/"). For example, given these files: + + 123 C:\dir1\file1.txt + 456 C:\dir2\file2.txt + +Then + + paq8p archive \dir1\file1.txt \dir2 + +will create archive.paq8p with the header: + + paq8p -5 + 123 file1.txt + 456 dir2/file2.txt + +The command: + + paq8p archive.paq8p C:\dir3 + +will create the files: + + C:\dir3\file1.txt + C:\dir3\dir2\file2.txt + +Decompression will fail if the first 7 bytes are not "paq8p -". Sizes +are stored as decimal numbers. CR, LF, TAB, CTRL-Z are ASCII codes +13, 10, 9, 26 respectively. + + +ARITHMETIC CODING + +The binary data is arithmetic coded as the shortest base 256 fixed point +number x = SUM_i x_i 256^-1-i such that p(= 16. + + The primaty output is t_i := stretch(sm(n0,n1,h)), where sm(.) is + a stationary map with K = 1/256, initiaized to + sm(n0,n1,h) = (n1+(1/64))/(n+2/64). Four additional inputs are also + be computed to improve compression slightly: + + p1_i = sm(n0,n1,h) + p0_i = 1 - p1_i + t_i := stretch(p_1) + t_i+1 := K1 (p1_i - p0_i) + t_i+2 := K2 stretch(p1) if n0 = 0, -K2 stretch(p1) if n1 = 0, else 0 + t_i+3 := K3 (-p0_i if n1 = 0, p1_i if n0 = 0, else 0) + t_i+4 := K3 (-p0_i if n0 = 0, p1_i if n1 = 0, else 0) + + where K1..K4 are ad-hoc constants. + + h is updated as follows: + If n < 4, append y_j to h. + Else if n <= 16, set h := y_j. + Else h = 0. + + The update rule is biased toward newer data in a way that allows + n0 or n1, but not both, to grow large by discarding counts of the + opposite bit. Large counts are incremented probabilistically. + Specifically, when y_j = 0 then the update rule is: + + n0 := n0 + 1, n < 29 + n0 + 1 with probability 2^(27-n0)/2 else n0, 29 <= n0 < 41 + n0, n = 41. + n1 := n1, n1 <= 5 + round(8/3 lg n1), if n1 > 5 + + swapping (n0,n1) when y_j = 1. + + Furthermore, to allow an 8 bit representation for (n0,n1,h), states + exceeding the following values of n0 or n1 are replaced with the + state with the closest ratio n0:n1 obtained by decrementing the + smaller count: (41,0,h), (40,1,h), (12,2,h), (5,3,h), (4,4,h), + (3,5,h), (2,12,h), (1,40,h), (0,41,h). For example: + (12,2,1) 0-> (7,1,0) because there is no state (13,2,0). + +- Match Model. The state is (c,b), initially (0,0), where c is 1 if + the context was previously seen, else 0, and b is the next bit in + this context. The prediction is: + + t_i := (2b - 1)Kc log(m + 1) + + where m is the length of the context. The update rule is c := 1, + b := y_j. A match model can be implemented efficiently by storing + input in a buffer and storing pointers into the buffer into a hash + table indexed by context. Then c is indicated by a hash table entry + and b can be retrieved from the buffer. + + +CONTEXTS + +High compression is achieved by combining a large number of contexts. +Most (not all) contexts start on a byte boundary and end on the bit +immediately preceding the predicted bit. The contexts below are +modeled with both a run map and a nonstationary map unless indicated. + +- Order n. The last n bytes, up to about 16. For general purpose data. + Most of the compression occurs here for orders up to about 6. + An order 0 context includes only the 0-7 bits of the partially coded + byte and the number of these bits (255 possible values). + +- Sparse. Usually 1 or 2 of the last 8 bytes preceding the byte containing + the predicted bit, e.g (2), (3),..., (8), (1,3), (1,4), (1,5), (1,6), + (2,3), (2,4), (3,6), (4,8). The ordinary order 1 and 2 context, (1) + or (1,2) are included above. Useful for binary data. + +- Text. Contexts consists of whole words (a-z, converted to lower case + and skipping other values). Contexts may be sparse, e.g (0,2) meaning + the current (partially coded) word and the second word preceding the + current one. Useful contexts are (0), (0,1), (0,1,2), (0,2), (0,3), + (0,4). The preceding byte may or may not be included as context in the + current word. + +- Formatted text. The column number (determined by the position of + the last linefeed) is combined with other contexts: the charater to + the left and the character above it. + +- Fixed record length. The record length is determined by searching for + byte sequences with a uniform stride length. Once this is found, then + the record length is combined with the context of the bytes immediately + preceding it and the corresponding byte locations in the previous + one or two records (as with formatted text). + +- Context gap. The distance to the previous occurrence of the order 1 + or order 2 context is combined with other low order (1-2) contexts. + +- FAX. For 2-level bitmapped images. Contexts are the surrounding + pixels already seen. Image width is assumed to be 1728 bits (as + in calgary/pic). + +- Image. For uncompressed 24-bit color BMP and TIFF images. Contexts + are the high order bits of the surrounding pixels and linear + combinations of those pixels, including other color planes. The + image width is detected from the file header. When an image is + detected, other models are turned off to improve speed. + +- JPEG. Files are further compressed by partially uncompressing back + to the DCT coefficients to provide context for the next Huffman code. + Only baseline DCT-Huffman coded files are modeled. (This ia about + 90% of images, the others are usually progresssive coded). JPEG images + embedded in other files (quite common) are detected by headers. The + baseline JPEG coding process is: + - Convert to grayscale and 2 chroma colorspace. + - Sometimes downsample the chroma images 2:1 or 4:1 in X and/or Y. + - Divide each of the 3 images into 8x8 blocks. + - Convert using 2-D discrete cosine transform (DCT) to 64 12-bit signed + coefficients. + - Quantize the coefficients by integer division (lossy). + - Split the image into horizontal slices coded independently, separated + by restart codes. + - Scan each block starting with the DC (0,0) coefficient in zigzag order + to the (7,7) coefficient, interleaving the 3 color components in + order to scan the whole image left to right starting at the top. + - Subtract the previous DC component from the current in each color. + - Code the coefficients using RS codes, where R is a run of R zeros (0-15) + and S indicates 0-11 bits of a signed value to follow. (There is a + special RS code (EOB) to indicate the rest of the 64 coefficients are 0). + - Huffman code the RS symbol, followed by S literal bits. + The most useful contexts are the current partially coded Huffman code + (including S following bits) combined with the coefficient position + (0-63), color (0-2), and last few RS codes. + +- Match. When a context match of 400 bytes or longer is detected, + the next bit of the match is predicted and other models are turned + off to improve speed. + +- Exe. When a x86 file (.exe, .obj, .dll) is detected, sparse contexts + with gaps of 1-12 selecting only the prefix, opcode, and the bits + of the modR/M byte that are relevant to parsing are selected. + This model is turned off otherwise. + +- Indirect. The history of the last 1-3 bytes in the context of the + last 1-2 bytes is combined with this 1-2 byte context. + +- DMC. A bitwise n-th order context is built from a state machine using + DMC, described in http://plg.uwaterloo.ca/~ftp/dmc/dmc.c + The effect is to extend a single context, one bit at a time and predict + the next bit based on the history in this context. The model here differs + in that two predictors are used. One is a pair of counts as in the original + DMC. The second predictor is a bit history state mapped adaptively to + a probability as as in a Nonstationary Map. + +ARCHITECTURE + +The context models are mixed by several of several hundred neural networks +selected by a low-order context. The outputs of these networks are +combined using a second neural network, then fed through several stages of +adaptive probability maps (APM) before arithmetic coding. + +For images, only one neural network is used and its context is fixed. + +An APM is a stationary map combining a context and an input probability. +The input probability is stretched and divided into 32 segments to +combine with other contexts. The output is interpolated between two +adjacent quantized values of stretch(p1). There are 2 APM stages in series: + + p1 := (p1 + 3 APM(order 0, p1)) / 4. + p1 := (APM(order 1, p1) + 2 APM(order 2, p1) + APM(order 3, p1)) / 4. + +PREPROCESSING + +paq8p uses preprocessing transforms on certain data types to improve +compression. To improve reliability, the decoding transform is +tested during compression to ensure that the input file can be +restored. If the decoder output is not identical to the input file +due to a bug, then the transform is abandoned and the data is compressed +without a transform so that it will still decompress correctly. + +The input is split into blocks with the format +where is 1 byte (0 = no transform), is the size +of the data after decoding, which may be different than the size of . +Blocks do not span file boundaries, and have a maximum size of 4MB to +2GB depending on compression level. Large files are split into blocks +of this size. The preprocessor has 3 parts: + +- Detector. Splits the input into smaller blocks depending on data type. + +- Coder. Input is a block to be compressed. Output is a temporary + file. The coder determines whether a transform is to be applied + based on file type, and if so, which one. A coder may use lots + of resources (memory, time) and make multiple passes through the + input file. The file type is stored (as one byte) during compression. + +- Decoder. Performs the inverse transform of the coder. It uses few + resorces (fast, low memory) and runs in a single pass (stream oriented). + It takes input either from a file or the arithmetic decoder. Each call + to the decoder returns a single decoded byte. + +The following transforms are used: + +- EXE: CALL (0xE8) and JMP (0xE9) address operands are converted from + relative to absolute address. The transform is to replace the sequence + E8/E9 xx xx xx 00/FF by adding file offset modulo 2^25 (signed range, + little-endian format). Data to transform is identified by trying the + transform and applying a crude compression test: testing whether the + byte following the E8/E8 (LSB of the address) occurred more recently + in the transformed data than the original and within 4KB 4 times in + a row. The block ends when this does not happen for 4KB. + +- JPEG: detected by SOI and SOF and ending with EOI or any nondecodable + data. No transform is applied. The purpose is to separate images + embedded in execuables to block the EXE transform, and for a future + place to insert a transform. + + +IMPLEMENTATION + +Hash tables are designed to minimize cache misses, which consume most +of the CPU time. + +Most of the memory is used by the nonstationary context models. +Contexts are represented by 32 bits, possibly a hash. These are +mapped to a bit history, represented by 1 byte. The hash table is +organized into 64-byte buckets on cache line boundaries. Each bucket +contains 7 x 7 bit histories, 7 16-bit checksums, and a 2 element LRU +queue packed into one byte. Each 7 byte element represents 7 histories +for a context ending on a 3-bit boundary plus 0-2 more bits. One +element (for bits 0-1, which have 4 unused bytes) also contains a run model +consisting of the last byte seen and a count (as 1 byte each). + +Run models use 4 byte hash elements consisting of a 2 byte checksum, a +repeat count (0-255) and the byte value. The count also serves as +a priority. + +Stationary models are most appropriate for small contexts, so the +context is used as a direct table lookup without hashing. + +The match model maintains a pointer to the last match until a mismatching +bit is found. At the start of the next byte, the hash table is referenced +to find another match. The hash table of pointers is updated after each +whole byte. There is no checksum. Collisions are detected by comparing +the current and matched context in a rotating buffer. + +The inner loops of the neural network prediction (1) and training (2) +algorithms are implemented in MMX assembler, which computes 4 elements +at a time. Using assembler is 8 times faster than C++ for this code +and 1/3 faster overall. (However I found that SSE2 code on an AMD-64, +which computes 8 elements at a time, is not any faster). + + +DIFFERENCES FROM PAQ7 + +An .exe model and filter are added. Context maps are improved using 16-bit +checksums to reduce collisions. The state table uses probabilistic updates +for large counts, more states that remember the last bit, and decreased +discounting of the opposite count. It is implemented as a fixed table. +There are also many minor changes. + +DIFFERENCES FROM PAQ8A + +The user interface supports directory compression and drag and drop. +The preprocessor segments the input into blocks and uses more robust +EXE detection. An indirect context model was added. There is no +dictionary preprocesor like PAQ8B/C/D/E. + +DIFFERENCES FROM PAQ8F + +Different models, usually from paq8hp*. Also changed rate from 8 to 7. A bug +in Array was fixed that caused the program to silently crash upon exit. + +DIFFERENCES FROM PAQ8J + +1) Slightly improved sparse model. +2) Added new family of sparse contexts. Each byte mapped to 3-bit value, where +different values corresponds to different byte classes. For example, input +byte 0x00 transformed into 0, all bytes that less then 16 -- into 5, all +punctuation marks (ispunct(c)!=0) -- into 2 etc. Then this flags from 11 +previous bytes combined into 32-bit pseudo-context. + +All this improvements gives only 62 byte on BOOK1, but on binaries archive size +reduced on 1-2%. + +DIFFERENCES FROM PAQ8JA + +Introduced distance model. Distance model uses distance to last occurence +of some anchor char ( 0x00, space, newline, 0xff ), combined with previous +charactes as context. This slightly improves compression of files with +variable-width record data. + +DIFFERENCES FROM PAQ8JB + +Restored recordModel(), broken in paq8hp*. Slightly tuned indirectModel(). + +DIFFERENCES FROM PAQ8JC + +Changed the APMs in the Predictor. Up to a 0.2% improvement for some files. + +DIFFERENCES FROM PAQ8JD + +Added DMCModel. Removed some redundant models from SparseModel and other +minor tuneups. Changes introduced in PAQ8K were not carried over. + +PAQ8L v.2 + +Changed Mixer::p() to p() to fix a compiler error in Linux +(patched by Indrek Kruusa, Apr. 15, 2007). + +DIFFERENCES FROM PAQ8L, PAQ8M + +Modified JPEG model by Jan Ondrus (paq8fthis2). The new model improves +compression by using decoded pixel values of current and adjacent blocks +as context. PAQ8M was an earlier version of the new JPEG model +(from paq8fthis). + +DIFFERENCES FROM PAQ8N + +Improved bmp model. Slightly faster. + +DIFFERENCES FROM PAQ8O + +Modified JPEG model by Jan Ondrus (paq8fthis4). +Added PGM (grayscale image) model form PAQ8I. +Added grayscale BMP model to PGM model. +Ver. 2 can be compiled using either old or new "for" loop scoping rules. +Added APM and StateMap from LPAQ1 +Code optimizations from Enrico Zeidler +Detection of BMP 4,8,24 bit and PGM 8 bit images before compress +On non BMP,PGM,JPEG data mem is lower +Fixed bug in BMP 8-bit detection in other files like .exe +15. oct 2007 +Updates JPEG model by Jan Ondrus +PGM detection bug fix +22. oct 2007 +improved JPEG model by Jan Ondrus +16. feb 2008 +fixed bmp detection bug +added .rgb file support (uncompressed grayscale) + +DIFFERENCES FROM PAQ8O9 + +Added wav Model. Slightly improved bmp model. +*/ + +#define PROGNAME "paq8p" // Please change this if you change the program. + +#ifdef LLVM +#include +#include +#endif +#include +#include +#include +#include +#include +#include +#define NDEBUG // remove for debugging (turns on Array bound checks) +#include + +#ifdef UNIX +#include +#include +#include +#include +#endif + +#ifdef WINDOWS +#include +#endif + +#ifndef DEFAULT_OPTION +#define DEFAULT_OPTION 5 +#endif + +// 8, 16, 32 bit unsigned types (adjust as appropriate) +typedef unsigned char U8; +typedef unsigned short U16; +typedef unsigned int U32; + +// min, max functions +#ifndef WINDOWS +inline int min(int a, int b) {return a='A'&&c1<='Z') c1+='a'-'A'; + int c2=*b; + if (c2>='A'&&c2<='Z') c2+='a'-'A'; + if (c1!=c2) return 0; + ++a; + ++b; + } + return *a==*b; +} + +//////////////////////// Program Checker ///////////////////// + +// Track time and memory used +class ProgramChecker { + int memused; // bytes allocated by Array now + int maxmem; // most bytes allocated ever + clock_t start_time; // in ticks +public: + void alloc(int n) { // report memory allocated, may be negative + memused+=n; + if (memused>maxmem) maxmem=memused; + } + ProgramChecker(): memused(0), maxmem(0) { + start_time=clock(); + assert(sizeof(U8)==1); + assert(sizeof(U16)==2); + assert(sizeof(U32)==4); + assert(sizeof(short)==2); + assert(sizeof(int)==4); + } + void print() const { // print time and memory used +#ifdef LLVM + printf("used %d bytes of memory\n", + maxmem); +#else + printf("Time %1.2f sec, used %d bytes of memory\n", + double(clock()-start_time)/CLOCKS_PER_SEC, maxmem); +#endif + } +} programChecker; + +//////////////////////////// Array //////////////////////////// + +// Array a(n); creates n elements of T initialized to 0 bits. +// Constructors for T are not called. +// Indexing is bounds checked if assertions are on. +// a.size() returns n. +// a.resize(n) changes size to n, padding with 0 bits or truncating. +// a.push_back(x) appends x and increases size by 1, reserving up to size*2. +// a.pop_back() decreases size by 1, does not free memory. +// Copy and assignment are not supported. +// Memory is aligned on a ALIGN byte boundary (power of 2), default is none. + +template class Array { +private: + int n; // user size + int reserved; // actual size + char *ptr; // allocated memory, zeroed + T* data; // start of n elements of aligned data + void create(int i); // create with size i +public: + explicit Array(int i=0) {create(i);} + ~Array(); + T& operator[](int i) { +#ifndef NDEBUG + if (i<0 || i>=n) fprintf(stderr, "%d out of bounds %d\n", i, n), quit(); +#endif + return data[i]; + } + const T& operator[](int i) const { +#ifndef NDEBUG + if (i<0 || i>=n) fprintf(stderr, "%d out of bounds %d\n", i, n), quit(); +#endif + return data[i]; + } + int size() const {return n;} + void resize(int i); // change size to i + void pop_back() {if (n>0) --n;} // decrement size + void push_back(const T& x); // increment size, append x +private: + Array(const Array&); // no copy or assignment + Array& operator=(const Array&); +}; + +template void Array::resize(int i) { + if (i<=reserved) { + n=i; + return; + } + char *saveptr=ptr; + T *savedata=data; + int saven=n; + create(i); + if (saveptr) { + if (savedata) { + memcpy(data, savedata, sizeof(T)*min(i, saven)); + programChecker.alloc(-ALIGN-n*sizeof(T)); + } + free(saveptr); + } +} + +template void Array::create(int i) { + n=reserved=i; + if (i<=0) { + data=0; + ptr=0; + return; + } + const int sz=ALIGN+n*sizeof(T); + programChecker.alloc(sz); + ptr = (char*)calloc(sz, 1); + if (!ptr) quit("Out of memory"); + data = (ALIGN ? (T*)(ptr+ALIGN-(((long)ptr)&(ALIGN-1))) : (T*)ptr); + assert((char*)data>=ptr && (char*)data<=ptr+ALIGN); +} + +template Array::~Array() { + programChecker.alloc(-ALIGN-n*sizeof(T)); + free(ptr); +} + +template void Array::push_back(const T& x) { + if (n==reserved) { + int saven=n; + resize(max(1, n*2)); + n=saven; + } + data[n++]=x; +} + +/////////////////////////// String ///////////////////////////// + +// A tiny subset of std::string +// size() includes NUL terminator. + +class String: public Array { +public: + const char* c_str() const {return &(*this)[0];} + void operator=(const char* s) { + resize(strlen(s)+1); + strcpy(&(*this)[0], s); + } + void operator+=(const char* s) { + assert(s); + pop_back(); + while (*s) push_back(*s++); + push_back(0); + } + String(const char* s=""): Array(1) { + (*this)+=s; + } +}; + + +//////////////////////////// rnd /////////////////////////////// + +// 32-bit pseudo random number generator +class Random{ + Array table; + int i; +public: + Random(): table(64) { + table[0]=123456789; + table[1]=987654321; + for(int j=0; j<62; j++) table[j+2]=table[j+1]*11+table[j]*23/16; + i=0; + } + U32 operator()() { + return ++i, table[i&63]=table[i-24&63]^table[i-55&63]; + } +} rnd; + +////////////////////////////// Buf ///////////////////////////// + +// Buf(n) buf; creates an array of n bytes (must be a power of 2). +// buf[i] returns a reference to the i'th byte with wrap (no out of bounds). +// buf(i) returns i'th byte back from pos (i > 0) +// buf.size() returns n. + +int pos; // Number of input bytes in buf (not wrapped) + +class Buf { + Array b; +public: + Buf(int i=0): b(i) {} + void setsize(int i) { + if (!i) return; + assert(i>0 && (i&(i-1))==0); + b.resize(i); + } + U8& operator[](int i) { + return b[i&b.size()-1]; + } + int operator()(int i) const { + assert(i>0); + return b[pos-i&b.size()-1]; + } + int size() const { + return b.size(); + } +}; + +// IntBuf(n) is a buffer of n int (must be a power of 2). +// intBuf[i] returns a reference to i'th element with wrap. + +class IntBuf { + Array b; +public: + IntBuf(int i=0): b(i) {} + int& operator[](int i) { + return b[i&b.size()-1]; + } +}; + +/////////////////////// Global context ///////////////////////// + +int level=DEFAULT_OPTION; // Compression level 0 to 9 +#define MEM (0x10000< t; +public: + int operator()(U16 x) const {return t[x];} + Ilog(); +} ilog; + +// Compute lookup table by numerical integration of 1/x +Ilog::Ilog(): t(65536) { + U32 x=14155776; + for (int i=2; i<65536; ++i) { + x+=774541002/(i*2-1); // numerator is 2^29/ln 2 + t[i]=x>>24; + } +} + +// llog(x) accepts 32 bits +inline int llog(U32 x) { + if (x>=0x1000000) + return 256+ilog(x>>16); + else if (x>=0x10000) + return 128+ilog(x>>8); + else + return ilog(x); +} + +///////////////////////// state table //////////////////////// + +// State table: +// nex(state, 0) = next state if bit y is 0, 0 <= state < 256 +// nex(state, 1) = next state if bit y is 1 +// nex(state, 2) = number of zeros in bit history represented by state +// nex(state, 3) = number of ones represented +// +// States represent a bit history within some context. +// State 0 is the starting state (no bits seen). +// States 1-30 represent all possible sequences of 1-4 bits. +// States 31-252 represent a pair of counts, (n0,n1), the number +// of 0 and 1 bits respectively. If n0+n1 < 16 then there are +// two states for each pair, depending on if a 0 or 1 was the last +// bit seen. +// If n0 and n1 are too large, then there is no state to represent this +// pair, so another state with about the same ratio of n0/n1 is substituted. +// Also, when a bit is observed and the count of the opposite bit is large, +// then part of this count is discarded to favor newer data over old. + +#if 1 // change to #if 0 to generate this table at run time (4% slower) +static const U8 State_table[256][4]={ + { 1, 2, 0, 0},{ 3, 5, 1, 0},{ 4, 6, 0, 1},{ 7, 10, 2, 0}, // 0-3 + { 8, 12, 1, 1},{ 9, 13, 1, 1},{ 11, 14, 0, 2},{ 15, 19, 3, 0}, // 4-7 + { 16, 23, 2, 1},{ 17, 24, 2, 1},{ 18, 25, 2, 1},{ 20, 27, 1, 2}, // 8-11 + { 21, 28, 1, 2},{ 22, 29, 1, 2},{ 26, 30, 0, 3},{ 31, 33, 4, 0}, // 12-15 + { 32, 35, 3, 1},{ 32, 35, 3, 1},{ 32, 35, 3, 1},{ 32, 35, 3, 1}, // 16-19 + { 34, 37, 2, 2},{ 34, 37, 2, 2},{ 34, 37, 2, 2},{ 34, 37, 2, 2}, // 20-23 + { 34, 37, 2, 2},{ 34, 37, 2, 2},{ 36, 39, 1, 3},{ 36, 39, 1, 3}, // 24-27 + { 36, 39, 1, 3},{ 36, 39, 1, 3},{ 38, 40, 0, 4},{ 41, 43, 5, 0}, // 28-31 + { 42, 45, 4, 1},{ 42, 45, 4, 1},{ 44, 47, 3, 2},{ 44, 47, 3, 2}, // 32-35 + { 46, 49, 2, 3},{ 46, 49, 2, 3},{ 48, 51, 1, 4},{ 48, 51, 1, 4}, // 36-39 + { 50, 52, 0, 5},{ 53, 43, 6, 0},{ 54, 57, 5, 1},{ 54, 57, 5, 1}, // 40-43 + { 56, 59, 4, 2},{ 56, 59, 4, 2},{ 58, 61, 3, 3},{ 58, 61, 3, 3}, // 44-47 + { 60, 63, 2, 4},{ 60, 63, 2, 4},{ 62, 65, 1, 5},{ 62, 65, 1, 5}, // 48-51 + { 50, 66, 0, 6},{ 67, 55, 7, 0},{ 68, 57, 6, 1},{ 68, 57, 6, 1}, // 52-55 + { 70, 73, 5, 2},{ 70, 73, 5, 2},{ 72, 75, 4, 3},{ 72, 75, 4, 3}, // 56-59 + { 74, 77, 3, 4},{ 74, 77, 3, 4},{ 76, 79, 2, 5},{ 76, 79, 2, 5}, // 60-63 + { 62, 81, 1, 6},{ 62, 81, 1, 6},{ 64, 82, 0, 7},{ 83, 69, 8, 0}, // 64-67 + { 84, 71, 7, 1},{ 84, 71, 7, 1},{ 86, 73, 6, 2},{ 86, 73, 6, 2}, // 68-71 + { 44, 59, 5, 3},{ 44, 59, 5, 3},{ 58, 61, 4, 4},{ 58, 61, 4, 4}, // 72-75 + { 60, 49, 3, 5},{ 60, 49, 3, 5},{ 76, 89, 2, 6},{ 76, 89, 2, 6}, // 76-79 + { 78, 91, 1, 7},{ 78, 91, 1, 7},{ 80, 92, 0, 8},{ 93, 69, 9, 0}, // 80-83 + { 94, 87, 8, 1},{ 94, 87, 8, 1},{ 96, 45, 7, 2},{ 96, 45, 7, 2}, // 84-87 + { 48, 99, 2, 7},{ 48, 99, 2, 7},{ 88,101, 1, 8},{ 88,101, 1, 8}, // 88-91 + { 80,102, 0, 9},{103, 69,10, 0},{104, 87, 9, 1},{104, 87, 9, 1}, // 92-95 + {106, 57, 8, 2},{106, 57, 8, 2},{ 62,109, 2, 8},{ 62,109, 2, 8}, // 96-99 + { 88,111, 1, 9},{ 88,111, 1, 9},{ 80,112, 0,10},{113, 85,11, 0}, // 100-103 + {114, 87,10, 1},{114, 87,10, 1},{116, 57, 9, 2},{116, 57, 9, 2}, // 104-107 + { 62,119, 2, 9},{ 62,119, 2, 9},{ 88,121, 1,10},{ 88,121, 1,10}, // 108-111 + { 90,122, 0,11},{123, 85,12, 0},{124, 97,11, 1},{124, 97,11, 1}, // 112-115 + {126, 57,10, 2},{126, 57,10, 2},{ 62,129, 2,10},{ 62,129, 2,10}, // 116-119 + { 98,131, 1,11},{ 98,131, 1,11},{ 90,132, 0,12},{133, 85,13, 0}, // 120-123 + {134, 97,12, 1},{134, 97,12, 1},{136, 57,11, 2},{136, 57,11, 2}, // 124-127 + { 62,139, 2,11},{ 62,139, 2,11},{ 98,141, 1,12},{ 98,141, 1,12}, // 128-131 + { 90,142, 0,13},{143, 95,14, 0},{144, 97,13, 1},{144, 97,13, 1}, // 132-135 + { 68, 57,12, 2},{ 68, 57,12, 2},{ 62, 81, 2,12},{ 62, 81, 2,12}, // 136-139 + { 98,147, 1,13},{ 98,147, 1,13},{100,148, 0,14},{149, 95,15, 0}, // 140-143 + {150,107,14, 1},{150,107,14, 1},{108,151, 1,14},{108,151, 1,14}, // 144-147 + {100,152, 0,15},{153, 95,16, 0},{154,107,15, 1},{108,155, 1,15}, // 148-151 + {100,156, 0,16},{157, 95,17, 0},{158,107,16, 1},{108,159, 1,16}, // 152-155 + {100,160, 0,17},{161,105,18, 0},{162,107,17, 1},{108,163, 1,17}, // 156-159 + {110,164, 0,18},{165,105,19, 0},{166,117,18, 1},{118,167, 1,18}, // 160-163 + {110,168, 0,19},{169,105,20, 0},{170,117,19, 1},{118,171, 1,19}, // 164-167 + {110,172, 0,20},{173,105,21, 0},{174,117,20, 1},{118,175, 1,20}, // 168-171 + {110,176, 0,21},{177,105,22, 0},{178,117,21, 1},{118,179, 1,21}, // 172-175 + {110,180, 0,22},{181,115,23, 0},{182,117,22, 1},{118,183, 1,22}, // 176-179 + {120,184, 0,23},{185,115,24, 0},{186,127,23, 1},{128,187, 1,23}, // 180-183 + {120,188, 0,24},{189,115,25, 0},{190,127,24, 1},{128,191, 1,24}, // 184-187 + {120,192, 0,25},{193,115,26, 0},{194,127,25, 1},{128,195, 1,25}, // 188-191 + {120,196, 0,26},{197,115,27, 0},{198,127,26, 1},{128,199, 1,26}, // 192-195 + {120,200, 0,27},{201,115,28, 0},{202,127,27, 1},{128,203, 1,27}, // 196-199 + {120,204, 0,28},{205,115,29, 0},{206,127,28, 1},{128,207, 1,28}, // 200-203 + {120,208, 0,29},{209,125,30, 0},{210,127,29, 1},{128,211, 1,29}, // 204-207 + {130,212, 0,30},{213,125,31, 0},{214,137,30, 1},{138,215, 1,30}, // 208-211 + {130,216, 0,31},{217,125,32, 0},{218,137,31, 1},{138,219, 1,31}, // 212-215 + {130,220, 0,32},{221,125,33, 0},{222,137,32, 1},{138,223, 1,32}, // 216-219 + {130,224, 0,33},{225,125,34, 0},{226,137,33, 1},{138,227, 1,33}, // 220-223 + {130,228, 0,34},{229,125,35, 0},{230,137,34, 1},{138,231, 1,34}, // 224-227 + {130,232, 0,35},{233,125,36, 0},{234,137,35, 1},{138,235, 1,35}, // 228-231 + {130,236, 0,36},{237,125,37, 0},{238,137,36, 1},{138,239, 1,36}, // 232-235 + {130,240, 0,37},{241,125,38, 0},{242,137,37, 1},{138,243, 1,37}, // 236-239 + {130,244, 0,38},{245,135,39, 0},{246,137,38, 1},{138,247, 1,38}, // 240-243 + {140,248, 0,39},{249,135,40, 0},{250, 69,39, 1},{ 80,251, 1,39}, // 244-247 + {140,252, 0,40},{249,135,41, 0},{250, 69,40, 1},{ 80,251, 1,40}, // 248-251 + {140,252, 0,41}}; // 252, 253-255 are reserved + +#define nex(state,sel) State_table[state][sel] + +// The code used to generate the above table at run time (4% slower). +// To print the table, uncomment the 4 lines of print statements below. +// In this code x,y = n0,n1 is the number of 0,1 bits represented by a state. +#else + +class StateTable { + Array ns; // state*4 -> next state if 0, if 1, n0, n1 + enum {B=5, N=64}; // sizes of b, t + static const int b[B]; // x -> max y, y -> max x + static U8 t[N][N][2]; // x,y -> state number, number of states + int num_states(int x, int y); // compute t[x][y][1] + void discount(int& x); // set new value of x after 1 or y after 0 + void next_state(int& x, int& y, int b); // new (x,y) after bit b +public: + int operator()(int state, int sel) {return ns[state*4+sel];} + StateTable(); +} nex; + +const int StateTable::b[B]={42,41,13,6,5}; // x -> max y, y -> max x +U8 StateTable::t[N][N][2]; + +int StateTable::num_states(int x, int y) { + if (x=N || y>=N || y>=B || x>=b[y]) return 0; + + // States 0-30 are a history of the last 0-4 bits + if (x+y<=4) { // x+y choose x = (x+y)!/x!y! + int r=1; + for (int i=x+1; i<=x+y; ++i) r*=i; + for (int i=2; i<=y; ++i) r/=i; + return r; + } + + // States 31-255 represent a 0,1 count and possibly the last bit + // if the state is reachable by either a 0 or 1. + else + return 1+(y>0 && x+y<16); +} + +// New value of count x if the opposite bit is observed +void StateTable::discount(int& x) { + if (x>2) x=ilog(x)/6-1; +} + +// compute next x,y (0 to N) given input b (0 or 1) +void StateTable::next_state(int& x, int& y, int b) { + if (x next if 0, next if 1, x, y +StateTable::StateTable(): ns(1024) { + + // Assign states + int state=0; + for (int i=0; i<256; ++i) { + for (int y=0; y<=i; ++y) { + int x=i-y; + int n=num_states(x, y); + if (n) { + t[x][y][0]=state; + t[x][y][1]=n; + state+=n; + } + } + } + + // Print/generate next state table + state=0; + for (int i=0; i0) ns1+=t[x-1][y+1][1]; + ns[state*4]=ns0; + ns[state*4+1]=ns1; + ns[state*4+2]=x; + ns[state*4+3]=y; + } + else if (t[x][y][1]) { + next_state(x0, y0, 0); + next_state(x1, y1, 1); + ns[state*4]=ns0=t[x0][y0][0]; + ns[state*4+1]=ns1=t[x1][y1][0]+(t[x1][y1][1]>1); + ns[state*4+2]=x; + ns[state*4+3]=y; + } + // uncomment to print table above +// printf("{%3d,%3d,%2d,%2d},", ns[state*4], ns[state*4+1], +// ns[state*4+2], ns[state*4+3]); +// if (state%4==3) printf(" // %d-%d\n ", state-3, state); + assert(state>=0 && state<256); + assert(t[x][y][1]>0); + assert(t[x][y][0]<=state); + assert(t[x][y][0]+t[x][y][1]>state); + assert(t[x][y][1]<=6); + assert(t[x0][y0][1]>0); + assert(t[x1][y1][1]>0); + assert(ns0-t[x0][y0][0]=0); + assert(ns1-t[x1][y1][0]=0); + ++state; + } + } + } +// printf("%d states\n", state); exit(0); // uncomment to print table above +} + +#endif + +///////////////////////////// Squash ////////////////////////////// + +// return p = 1/(1 + exp(-d)), d scaled by 8 bits, p scaled by 12 bits +int squash(int d) { + static const int t[33]={ + 1,2,3,6,10,16,27,45,73,120,194,310,488,747,1101, + 1546,2047,2549,2994,3348,3607,3785,3901,3975,4022, + 4050,4068,4079,4085,4089,4092,4093,4094}; + if (d>2047) return 4095; + if (d<-2047) return 0; + int w=d&127; + d=(d>>7)+16; + return (t[d]*(128-w)+t[(d+1)]*w+64) >> 7; +} + +//////////////////////////// Stretch /////////////////////////////// + +// Inverse of squash. d = ln(p/(1-p)), d scaled by 8 bits, p by 12 bits. +// d has range -2047 to 2047 representing -8 to 8. p has range 0 to 4095. + +class Stretch { + Array t; +public: + Stretch(); + int operator()(int p) const { + assert(p>=0 && p<4096); + return t[p]; + } +} stretch; + +Stretch::Stretch(): t(4096) { + int pi=0; + for (int x=-2047; x<=2047; ++x) { // invert squash() + int i=squash(x); + for (int j=pi; j<=i; ++j) + t[j]=x; + pi=i+1; + } + t[4095]=2047; +} + +//////////////////////////// Mixer ///////////////////////////// + +// Mixer m(N, M, S=1, w=0) combines models using M neural networks with +// N inputs each, of which up to S may be selected. If S > 1 then +// the outputs of these neural networks are combined using another +// neural network (with parameters S, 1, 1). If S = 1 then the +// output is direct. The weights are initially w (+-32K). +// It is used as follows: +// m.update() trains the network where the expected output is the +// last bit (in the global variable y). +// m.add(stretch(p)) inputs prediction from one of N models. The +// prediction should be positive to predict a 1 bit, negative for 0, +// nominally +-256 to +-2K. The maximum allowed value is +-32K but +// using such large values may cause overflow if N is large. +// m.set(cxt, range) selects cxt as one of 'range' neural networks to +// use. 0 <= cxt < range. Should be called up to S times such +// that the total of the ranges is <= M. +// m.p() returns the output prediction that the next bit is 1 as a +// 12 bit number (0 to 4095). + +// dot_product returns dot product t*w of n elements. n is rounded +// up to a multiple of 8. Result is scaled down by 8 bits. +#ifdef NOASM // no assembly language +int dot_product(short *t, short *w, int n) { + int sum=0; + n=(n+7)&-8; + for (int i=0; i> 8; + return sum; +} +#else // The NASM version uses MMX and is about 8 times faster. +extern "C" int dot_product(short *t, short *w, int n); // in NASM +#endif + +// Train neural network weights w[n] given inputs t[n] and err. +// w[i] += t[i]*err, i=0..n-1. t, w, err are signed 16 bits (+- 32K). +// err is scaled 16 bits (representing +- 1/2). w[i] is clamped to +- 32K +// and rounded. n is rounded up to a multiple of 8. +#ifdef NOASM +void train(short *t, short *w, int n, int err) { + n=(n+7)&-8; + for (int i=0; i>16)+1>>1); + if (wt<-32768) wt=-32768; + if (wt>32767) wt=32767; + w[i]=wt; + } +} +#else +extern "C" void train(short *t, short *w, int n, int err); // in NASM +#endif + +class Mixer { + const int N, M, S; // max inputs, max contexts, max context sets + Array tx; // N inputs from add() + Array wx; // N*M weights + Array cxt; // S contexts + int ncxt; // number of contexts (0 to S) + int base; // offset of next context + int nx; // Number of inputs in tx, 0 to N + Array pr; // last result (scaled 12 bits) + Mixer* mp; // points to a Mixer to combine results +public: + Mixer(int n, int m, int s=1, int w=0); + + // Adjust weights to minimize coding cost of last prediction + void update() { + for (int i=0; i=-32768 && err<32768); + if (err) train(&tx[0], &wx[cxt[i]*N], nx, err); + } + nx=base=ncxt=0; + } + + // Input x (call up to N times) + void add(int x) { + assert(nx=0); + assert(ncxt=0); + assert(base+cxupdate(); + for (int i=0; i>5); + mp->add(stretch(pr[i])); + } + mp->set(0, 1); + return mp->p(); + } + else { // S=1 context + return pr[0]=squash(dot_product(&tx[0], &wx[0], nx)>>8); + } + } + ~Mixer(); +}; + +Mixer::~Mixer() { + delete mp; +} + + +Mixer::Mixer(int n, int m, int s, int w): + N((n+7)&-8), M(m), S(s), tx(N), wx(N*M), + cxt(S), ncxt(0), base(0), nx(0), pr(S), mp(0) { + assert(n>0 && N>0 && (N&7)==0 && M>0); + int i; + for ( i=0; i1) mp=new Mixer(S, 1, 1, 0x7fff); +} + +//////////////////////////// APM1 ////////////////////////////// + +// APM1 maps a probability and a context into a new probability +// that bit y will next be 1. After each guess it updates +// its state to improve future guesses. Methods: +// +// APM1 a(N) creates with N contexts, uses 66*N bytes memory. +// a.p(pr, cx, rate=7) returned adjusted probability in context cx (0 to +// N-1). rate determines the learning rate (smaller = faster, default 7). +// Probabilities are scaled 12 bits (0-4095). + +class APM1 { + int index; // last p, context + const int N; // number of contexts + Array t; // [N][33]: p, context -> p +public: + APM1(int n); + int p(int pr=2048, int cxt=0, int rate=7) { + assert(pr>=0 && pr<4096 && cxt>=0 && cxt0 && rate<32); + pr=stretch(pr); + int g=(y<<16)+(y<> rate; + t[index+1] += g-t[index+1] >> rate; + const int w=pr&127; // interpolation weight (33 points) + index=(pr+2048>>7)+cxt*33; + return t[index]*(128-w)+t[index+1]*w >> 11; + } +}; + +// maps p, cxt -> p initially +APM1::APM1(int n): index(0), N(n), t(n*33) { + for (int i=0; i 16K/(i+3) + +class StateMap { +protected: + const int N; // Number of contexts + int cxt; // Context of last prediction + Array t; // cxt -> prediction in high 22 bits, count in low 10 bits + inline void update(int limit) { + assert(cxt>=0 && cxt>10; // count, prediction + if (n>3)*dt[n]&0xfffffc00; + p[0]=p0; + } + +public: + StateMap(int n=256); + + // update bit y (0..1), predict next bit in context cx + int p(int cx, int limit=1023) { + assert(cx>=0 && cx0 && limit<1024); + update(limit); + return t[cxt=cx]>>20; + } +}; + +StateMap::StateMap(int n): N(n), cxt(0), t(n) { + for (int i=0; i>1==0); + assert(pr>=0 && pr<4096); + assert(cx>=0 && cx0 && limit<1024); + update(limit); + pr=(stretch(pr)+2048)*23; + int wt=pr&0xfff; // interpolation weight of next element + cx=cx*24+(pr>>12); + assert(cx>=0 && cx>11); + pr=(t[cx]>>13)*(0x1000-wt)+(t[cx+1]>>13)*wt>>19; + return pr; + } +}; + +APM::APM(int n): StateMap(n*24) { + for (int i=0; i>9^a>>2^b>>3^c>>4^d>>5^e>>6; +} + +///////////////////////////// BH //////////////////////////////// + +// A BH maps a 32 bit hash to an array of B bytes (checksum and B-2 values) +// +// BH bh(N); creates N element table with B bytes each. +// N must be a power of 2. The first byte of each element is +// reserved for a checksum to detect collisions. The remaining +// B-1 bytes are values, prioritized by the first value. This +// byte is 0 to mark an unused element. +// +// bh[i] returns a pointer to the i'th element, such that +// bh[i][0] is a checksum of i, bh[i][1] is the priority, and +// bh[i][2..B-1] are other values (0-255). +// The low lg(n) bits as an index into the table. +// If a collision is detected, up to M nearby locations in the same +// cache line are tested and the first matching checksum or +// empty element is returned. +// If no match or empty element is found, then the lowest priority +// element is replaced. + +// 2 byte checksum with LRU replacement (except last 2 by priority) +template class BH { + enum {M=8}; // search limit + Array t; // elements + U32 n; // size-1 +public: + BH(int i): t(i*B), n(i-1) { + assert(B>=2 && i>0 && (i&(i-1))==0); // size a power of 2? + } + U8* operator[](U32 i); +}; + +template +inline U8* BH::operator[](U32 i) { + int chk=(i>>16^i)&0xffff; + i=i*M&n; + U8 *p; + U16 *cp; + int j; + for (j=0; j2 && t[(i+j)*B+2]>t[(i+j-1)*B+2]) --j; + } + else memcpy(tmp, cp, B); + memmove(&t[(i+1)*B], &t[i*B], j*B); + memcpy(&t[i*B], tmp, B); + return &t[i*B+1]; +} + +/////////////////////////// ContextMap ///////////////////////// +// +// A ContextMap maps contexts to a bit histories and makes predictions +// to a Mixer. Methods common to all classes: +// +// ContextMap cm(M, C); creates using about M bytes of memory (a power +// of 2) for C contexts. +// cm.set(cx); sets the next context to cx, called up to C times +// cx is an arbitrary 32 bit value that identifies the context. +// It should be called before predicting the first bit of each byte. +// cm.mix(m) updates Mixer m with the next prediction. Returns 1 +// if context cx is found, else 0. Then it extends all the contexts with +// global bit y. It should be called for every bit: +// +// if (bpos==0) +// for (int i=0; i= 1. Context need not be hashed. + +// Predict to mixer m from bit history state s, using sm to map s to +// a probability. +inline int mix2(Mixer& m, int s, StateMap& sm) { + int p1=sm.p(s); + int n0=-!nex(s,2); + int n1=-!nex(s,3); + int st=stretch(p1)>>2; + m.add(st); + p1>>=4; + int p0=255-p1; + m.add(p1-p0); + m.add(st*(n1-n0)); + m.add((p1&n0)-(p0&n1)); + m.add((p1&n1)-(p0&n0)); + return s>0; +} + +// A RunContextMap maps a context into the next byte and a repeat +// count up to M. Size should be a power of 2. Memory usage is 3M/4. +class RunContextMap { + BH<4> t; + U8* cp; +public: + RunContextMap(int m): t(m/4) {cp=t[0]+1;} + void set(U32 cx) { // update count + if (cp[0]==0 || cp[1]!=buf(1)) cp[0]=1, cp[1]=buf(1); + else if (cp[0]<255) ++cp[0]; + cp=t[cx]+1; + } + int p() { // predict next bit + if (cp[1]+256>>8-bpos==c0) + return ((cp[1]>>7-bpos&1)*2-1)*ilog(cp[0]+1)*8; + else + return 0; + } + int mix(Mixer& m) { // return run length + m.add(p()); + return cp[0]!=0; + } +}; + +// Context is looked up directly. m=size is power of 2 in bytes. +// Context should be < m/512. High bits are discarded. +class SmallStationaryContextMap { + Array t; + int cxt; + U16 *cp; +public: + SmallStationaryContextMap(int m): t(m/2), cxt(0) { + assert((m/2&m/2-1)==0); // power of 2? + for (int i=0; i> rate; + cp=&t[cxt+c0]; + m.add(stretch(*cp>>4)); + } +}; + +// Context map for large contexts. Most modeling uses this type of context +// map. It includes a built in RunContextMap to predict the last byte seen +// in the same context, and also bit-level contexts that map to a bit +// history state. +// +// Bit histories are stored in a hash table. The table is organized into +// 64-byte buckets alinged on cache page boundaries. Each bucket contains +// a hash chain of 7 elements, plus a 2 element queue (packed into 1 byte) +// of the last 2 elements accessed for LRU replacement. Each element has +// a 2 byte checksum for detecting collisions, and an array of 7 bit history +// states indexed by the last 0 to 2 bits of context. The buckets are indexed +// by a context ending after 0, 2, or 5 bits of the current byte. Thus, each +// byte modeled results in 3 main memory accesses per context, with all other +// accesses to cache. +// +// On bits 0, 2 and 5, the context is updated and a new bucket is selected. +// The most recently accessed element is tried first, by comparing the +// 16 bit checksum, then the 7 elements are searched linearly. If no match +// is found, then the element with the lowest priority among the 5 elements +// not in the LRU queue is replaced. After a replacement, the queue is +// emptied (so that consecutive misses favor a LFU replacement policy). +// In all cases, the found/replaced element is put in the front of the queue. +// +// The priority is the state number of the first element (the one with 0 +// additional bits of context). The states are sorted by increasing n0+n1 +// (number of bits seen), implementing a LFU replacement policy. +// +// When the context ends on a byte boundary (bit 0), only 3 of the 7 bit +// history states are used. The remaining 4 bytes implement a run model +// as follows: where is the last byte +// seen, possibly repeated. is a 7 bit count and a 1 bit +// flag (represented by count * 2 + d). If d=0 then = 1..127 is the +// number of repeats of and no other bytes have been seen. If d is 1 then +// other byte values have been seen in this context prior to the last +// copies of . +// +// As an optimization, the last two hash elements of each byte (representing +// contexts with 2-7 bits) are not updated until a context is seen for +// a second time. This is indicated by = <1,0> (2). After update, +// is updated to <2,0> or <1,1> (4 or 3). + +class ContextMap { + const int C; // max number of contexts + class E { // hash element, 64 bytes + U16 chk[7]; // byte context checksums + U8 last; // last 2 accesses (0-6) in low, high nibble + public: + U8 bh[7][7]; // byte context, 3-bit context -> bit history state + // bh[][0] = 1st bit, bh[][1,2] = 2nd bit, bh[][3..6] = 3rd bit + // bh[][0] is also a replacement priority, 0 = empty + U8* get(U16 chk); // Find element (0-6) matching checksum. + // If not found, insert or replace lowest priority (not last). + }; + Array t; // bit histories for bits 0-1, 2-4, 5-7 + // For 0-1, also contains a run count in bh[][4] and value in bh[][5] + // and pending update count in bh[7] + Array cp; // C pointers to current bit history + Array cp0; // First element of 7 element array containing cp[i] + Array cxt; // C whole byte contexts (hashes) + Array runp; // C [0..3] = count, value, unused, unused + StateMap *sm; // C maps of state -> p + int cn; // Next context to set by set() + void update(U32 cx, int c); // train model that context cx predicts c + int mix1(Mixer& m, int cc, int bp, int c1, int y1); + // mix() with global context passed as arguments to improve speed. +public: + ContextMap(int m, int c=1); // m = memory in bytes, a power of 2, C = c + ~ContextMap(); + void set(U32 cx, int next=-1); // set next whole byte context to cx + // if next is 0 then set order does not matter + int mix(Mixer& m) {return mix1(m, c0, bpos, buf(1), y);} +}; + +// Find or create hash element matching checksum ch +inline U8* ContextMap::E::get(U16 ch) { + if (chk[last&15]==ch) return &bh[last&15][0]; + int b=0xffff, bi=0; + for (int i=0; i<7; ++i) { + if (chk[i]==ch) return last=last<<4|i, (U8*)&bh[i][0]; + int pri=bh[i][0]; + if (pri>4!=i) b=pri, bi=i; + } + return last=0xf0|bi, chk[bi]=ch, (U8*)memset(&bh[bi][0], 0, 7); +} + +// Construct using m bytes of memory for c contexts +ContextMap::ContextMap(int m, int c): C(c), t(m>>6), cp(c), cp0(c), + cxt(c), runp(c), cn(0) { + assert(m>=64 && (m&m-1)==0); // power of 2? + assert(sizeof(E)==64); + sm=new StateMap[C]; + for (int i=0; i=0 && i>16; + cxt[i]=cx*123456791+i; +} + +// Update the model with bit y1, and predict next bit to mixer m. +// Context: cc=c0, bp=bpos, c1=buf(1), y1=y. +int ContextMap::mix1(Mixer& m, int cc, int bp, int c1, int y1) { + + // Update model with y + int result=0; + for (int i=0; i=&t[0].bh[0][0] && cp[i]<=&t[t.size()-1].bh[6][6]); + assert((long(cp[i])&63)>=15); + int ns=nex(*cp[i], y1); + if (ns>=204 && rnd() << (452-ns>>3)) ns-=4; // probabilistic increment + *cp[i]=ns; + } + + // Update context pointers + if (bpos>1 && runp[i][0]==0) + { + cp[i]=0; + } + else + { + switch(bpos) + { + case 1: case 3: case 6: cp[i]=cp0[i]+1+(cc&1); break; + case 4: case 7: cp[i]=cp0[i]+3+(cc&3); break; + case 2: case 5: cp0[i]=cp[i]=t[cxt[i]+cc&t.size()-1].get(cxt[i]>>16); break; + default: + { + cp0[i]=cp[i]=t[cxt[i]+cc&t.size()-1].get(cxt[i]>>16); + // Update pending bit histories for bits 2-7 + if (cp0[i][3]==2) { + const int c=cp0[i][4]+256; + U8 *p=t[cxt[i]+(c>>6)&t.size()-1].get(cxt[i]>>16); + p[0]=1+((c>>5)&1); + p[1+((c>>5)&1)]=1+((c>>4)&1); + p[3+((c>>4)&3)]=1+((c>>3)&1); + p=t[cxt[i]+(c>>3)&t.size()-1].get(cxt[i]>>16); + p[0]=1+((c>>2)&1); + p[1+((c>>2)&1)]=1+((c>>1)&1); + p[3+((c>>1)&3)]=1+(c&1); + cp0[i][6]=0; + } + // Update run count of previous context + if (runp[i][0]==0) // new context + runp[i][0]=2, runp[i][1]=c1; + else if (runp[i][1]!=c1) // different byte in context + runp[i][0]=1, runp[i][1]=c1; + else if (runp[i][0]<254) // same byte in context + runp[i][0]+=2; + else if (runp[i][0]==255) + runp[i][0]=128; + runp[i]=cp0[i]+3; + } break; + } + } + + // predict from last byte in context + if (runp[i][1]+256>>8-bp==cc) { + int rc=runp[i][0]; // count*2, +1 if 2 different bytes seen + int b=(runp[i][1]>>7-bp&1)*2-1; // predicted bit + for 1, - for 0 + int c=ilog(rc+1)<<2+(~rc&1); + m.add(b*c); + } + else + m.add(0); + + // predict from bit context + if(cp[i]) + { + result+=mix2(m, *cp[i], sm[i]); + } + else + { + mix2(m, 0, sm[i]); + } + + + } + if (bp==7) cn=0; + return result; +} + +//////////////////////////// Models ////////////////////////////// + +// All of the models below take a Mixer as a parameter and write +// predictions to it. + +//////////////////////////// matchModel /////////////////////////// + +// matchModel() finds the longest matching context and returns its length + +int matchModel(Mixer& m) { + const int MAXLEN=65534; // longest allowed match + 1 + static Array t(MEM); // hash table of pointers to contexts + static int h=0; // hash of last 7 bytes + static int ptr=0; // points to next byte of match if any + static int len=0; // length of match, or 0 if no match + static int result=0; + + static SmallStationaryContextMap scm1(0x20000); + + if (!bpos) { + h=h*997*8+buf(1)+1&t.size()-1; // update context hash + if (len) ++len, ++ptr; + else { // find match + ptr=t[h]; + if (ptr && pos-ptr0 && !(result&0xfff)) printf("pos=%d len=%d ptr=%d\n", pos, len, ptr); + scm1.set(pos); + } + + // predict + if (len) + { + if (buf(1)==buf[ptr-1] && c0==buf[ptr]+256>>8-bpos) + { + if (len>MAXLEN) len=MAXLEN; + if (buf[ptr]>>7-bpos&1) + { + m.add(ilog(len)<<2); + m.add(min(len, 32)<<6); + } + else + { + m.add(-(ilog(len)<<2)); + m.add(-(min(len, 32)<<6)); + } + } + else + { + len=0; + m.add(0); + m.add(0); + } + } + else + { + m.add(0); + m.add(0); + } + + scm1.mix(m); + return result; +} + +//////////////////////////// picModel ////////////////////////// + +// Model a 1728 by 2376 2-color CCITT bitmap image, left to right scan, +// MSB first (216 bytes per row, 513216 bytes total). Insert predictions +// into m. + +void picModel(Mixer& m) { + static U32 r0, r1, r2, r3; // last 4 rows, bit 8 is over current pixel + static Array t(0x10200); // model: cxt -> state + const int N=3; // number of contexts + static int cxt[N]; // contexts + static StateMap sm[N]; + + // update the model + int i; + for ( i=0; i>(7-bpos))&1); + r2+=r2+((buf(431)>>(7-bpos))&1); + r3+=r3+((buf(647)>>(7-bpos))&1); + cxt[0]=r0&0x7|r1>>4&0x38|r2>>3&0xc0; + cxt[1]=0x100+(r0&1|r1>>4&0x3e|r2>>2&0x40|r3>>1&0x80); + cxt[2]=0x200+(r0&0x3f^r1&0x3ffe^r2<<2&0x7f00^r3<<5&0xf800); + + // predict + for ( i=0; i='A' && c<='Z') + c+='a'-'A'; + if (c>='a' && c<='z' || c>=128) { + word0=word0*263*32+c; + text0=text0*997*16+c; + } + else if (word0) { + word5=word4*23; + word4=word3*19; + word3=word2*17; + word2=word1*13; + word1=word0*11; + word0=0; + } + if (c==10) nl1=nl, nl=pos-1; + int col=min(255, pos-nl), above=buf[nl1+col]; // text column context + U32 h=word0*271+buf(1); + + cm.set(h); + cm.set(word0); + cm.set(h+word1); + cm.set(word0+word1*31); + cm.set(h+word1+word2*29); + cm.set(text0&0xffffff); + cm.set(text0&0xfffff); + + cm.set(h+word2); + cm.set(h+word3); + cm.set(h+word4); + cm.set(h+word5); + cm.set(buf(1)|buf(3)<<8|buf(5)<<16); + cm.set(buf(2)|buf(4)<<8|buf(6)<<16); + + cm.set(h+word1+word3); + cm.set(h+word2+word3); + + // Text column models + cm.set(col<<16|buf(1)<<8|above); + cm.set(buf(1)<<8|above); + cm.set(col<<8|buf(1)); + cm.set(col); + } + cm.mix(m); +} + +//////////////////////////// recordModel /////////////////////// + +// Model 2-D data with fixed record length. Also order 1-2 models +// that include the distance to the last match. + +void recordModel(Mixer& m) { + static int cpos1[256] , cpos2[256], cpos3[256], cpos4[256]; + static int wpos1[0x10000]; // buf(1..2) -> last position + static int rlen=2, rlen1=3, rlen2=4; // run length and 2 candidates + static int rcount1=0, rcount2=0; // candidate counts + static ContextMap cm(32768, 3), cn(32768/2, 3), co(32768*2, 3), cp(MEM, 3); + + // Find record length + if (!bpos) { + int w=c4&0xffff, c=w&255, d=w>>8; +#if 1 + int r=pos-cpos1[c]; + if (r>1 && r==cpos1[c]-cpos2[c] + && r==cpos2[c]-cpos3[c] && r==cpos3[c]-cpos4[c] + && (r>15 || (c==buf(r*5+1)) && c==buf(r*6+1))) { + if (r==rlen1) ++rcount1; + else if (r==rlen2) ++rcount2; + else if (rcount1>rcount2) rlen2=r, rcount2=1; + else rlen1=r, rcount1=1; + } + if (rcount1>15 && rlen!=rlen1) rlen=rlen1, rcount1=rcount2=0; + if (rcount2>15 && rlen!=rlen2) rlen=rlen2, rcount1=rcount2=0; + + // Set 2 dimensional contexts + assert(rlen>0); +#endif + cm.set(c<<8| (min(255, pos-cpos1[c])/4) ); + cm.set(w<<9| llog(pos-wpos1[w])>>2); + + cm.set(rlen|buf(rlen)<<10|buf(rlen*2)<<18); + cn.set(w|rlen<<8); + cn.set(d|rlen<<16); + cn.set(c|rlen<<8); + + co.set(buf(1)<<8|min(255, pos-cpos1[buf(1)])); + co.set(buf(1)<<17|buf(2)<<9|llog(pos-wpos1[w])>>2); + int col=pos%rlen; + co.set(buf(1)<<8|buf(rlen)); + + //cp.set(w*16); + //cp.set(d*32); + //cp.set(c*64); + cp.set(rlen|buf(rlen)<<10|col<<18); + cp.set(rlen|buf(1)<<10|col<<18); + cp.set(col|rlen<<12); + + // update last context positions + cpos4[c]=cpos3[c]; + cpos3[c]=cpos2[c]; + cpos2[c]=cpos1[c]; + cpos1[c]=pos; + wpos1[w]=pos; + } + cm.mix(m); + cn.mix(m); + co.mix(m); + cp.mix(m); +} + + +//////////////////////////// sparseModel /////////////////////// + +// Model order 1-2 contexts with gaps. + +void sparseModel(Mixer& m, int seenbefore, int howmany) { + static ContextMap cm(MEM*2, 48); + static int mask = 0; + + if (bpos==0) { + + cm.set( c4&0x00f0f0f0); + cm.set((c4&0xf0f0f0f0)+1); + cm.set((c4&0x00f8f8f8)+2); + cm.set((c4&0xf8f8f8f8)+3); + cm.set((c4&0x00e0e0e0)+4); + cm.set((c4&0xe0e0e0e0)+5); + cm.set((c4&0x00f0f0ff)+6); + + cm.set(seenbefore); + cm.set(howmany); + cm.set(c4&0x00ff00ff); + cm.set(c4&0xff0000ff); + cm.set(buf(1)|buf(5)<<8); + cm.set(buf(1)|buf(6)<<8); + cm.set(buf(3)|buf(6)<<8); + cm.set(buf(4)|buf(8)<<8); + + for (int i=1; i<8; ++i) { + cm.set((buf(i+1)<<8)|buf(i+2)); + cm.set((buf(i+1)<<8)|buf(i+3)); + cm.set(seenbefore|buf(i)<<8); + } + + int fl = 0; + if( c4&0xff != 0 ){ + if( isalpha( c4&0xff ) ) fl = 1; + else if( ispunct( c4&0xff ) ) fl = 2; + else if( isspace( c4&0xff ) ) fl = 3; + else if( c4&0xff == 0xff ) fl = 4; + else if( c4&0xff < 16 ) fl = 5; + else if( c4&0xff < 64 ) fl = 6; + else fl = 7; + } + mask = (mask<<3)|fl; + cm.set(mask); + cm.set(mask<<8|buf(1)); + cm.set(mask<<17|buf(2)<<8|buf(3)); + cm.set(mask&0x1ff|((c4&0xf0f0f0f0)<<9)); + } + cm.mix(m); +} + +//////////////////////////// distanceModel /////////////////////// + +// Model for modelling distances between symbols + +void distanceModel(Mixer& m) { + static ContextMap cr(MEM, 3); + if( bpos == 0 ){ + static int pos00=0,pos20=0,posnl=0; + int c=c4&0xff; + if(c==0x00)pos00=pos; + if(c==0x20)pos20=pos; + if(c==0xff||c=='\r'||c=='\n')posnl=pos; + cr.set(min(pos-pos00,255)|(c<<8)); + cr.set(min(pos-pos20,255)|(c<<8)); + cr.set(min(pos-posnl,255)|(c<<8)+234567); + } + cr.mix(m); +} + +//////////////////////////// bmpModel ///////////////////////////////// + +// Model a 24-bit color uncompressed .bmp or .tif file. Return +// width in pixels if an image file is detected, else 0. + +// 32-bit little endian number at buf(i)..buf(i-3) +inline U32 i4(int i) { + assert(i>3); + return buf(i)+256*buf(i-1)+65536*buf(i-2)+16777216*buf(i-3); +} + +// 16-bit +inline int i2(int i) { + assert(i>1); + return buf(i)+256*buf(i-1); +} + +// Square buf(i) +inline int sqrbuf(int i) { + assert(i>0); + return buf(i)*buf(i); +} + +int bmpModel(Mixer& m) { + static int w=0; // width of image in bytes (pixels * 3) + static int eoi=0; // end of image + static U32 tiff=0; // offset of tif header + const int SC=0x20000; + static SmallStationaryContextMap scm1(SC), scm2(SC), + scm3(SC), scm4(SC), scm5(SC), scm6(SC), scm7(SC), scm8(SC), scm9(SC*2), scm10(SC); + static ContextMap cm(MEM*4, 13); + + // Detect .bmp file header (24 bit color, not compressed) + if (!bpos && buf(54)=='B' && buf(53)=='M' + && i4(44)==54 && i4(40)==40 && i4(24)==0) { + w=(i4(36)+3&-4)*3; // image width + const int height=i4(32); + eoi=pos; + if (w<0x30000 && height<0x10000) { + eoi=pos+w*height; // image size in bytes + printf("BMP %dx%d ", w/3, height); + } + else + eoi=pos; + } + + // Detect .tif file header (24 bit color, not compressed). + // Parsing is crude, won't work with weird formats. + if (!bpos) { + if (c4==0x49492a00) tiff=pos; // Intel format only + if (pos-tiff==4 && c4!=0x08000000) tiff=0; // 8=normal offset to directory + if (tiff && pos-tiff==200) { // most of directory should be read by now + int dirsize=i2(pos-tiff-4); // number of 12-byte directory entries + w=0; + int bpp=0, compression=0, width=0, height=0; + for (int i=tiff+6; i0; i+=12) { + int tag=i2(pos-i); // 256=width, 257==height, 259: 1=no compression + // 277=3 samples/pixel + int tagfmt=i2(pos-i-2); // 3=short, 4=long + int taglen=i4(pos-i-4); // number of elements in tagval + int tagval=i4(pos-i-8); // 1 long, 1-2 short, or points to array + if ((tagfmt==3||tagfmt==4) && taglen==1) { + if (tag==256) width=tagval; + if (tag==257) height=tagval; + if (tag==259) compression=tagval; // 1 = no compression + if (tag==277) bpp=tagval; // should be 3 + } + } + if (width>0 && height>0 && width*height>50 && compression==1 + && (bpp==1||bpp==3)) + eoi=tiff+width*height*bpp, w=width*bpp; + if (eoi>pos) + printf("TIFF %dx%dx%d ", width, height, bpp); + else + tiff=w=0; + } + } + if (pos>eoi) return w=0; + + // Select nearby pixels as context + if (!bpos) { + assert(w>3); + int color=pos%3; + int mean=buf(3)+buf(w-3)+buf(w)+buf(w+3); + const int var=sqrbuf(3)+sqrbuf(w-3)+sqrbuf(w)+sqrbuf(w+3)-mean*mean/4>>2; + mean>>=2; + const int logvar=ilog(var); + int i=0; + cm.set(hash(++i, buf(3), color)); + cm.set(hash(++i, buf(3), buf(1), color)); + cm.set(hash(++i, buf(3), buf(1)>>2, buf(2)>>6, color)); + cm.set(hash(++i, buf(w), color)); + cm.set(hash(++i, buf(w), buf(1), color)); + cm.set(hash(++i, buf(w), buf(1)>>2, buf(2)>>6, color)); + cm.set(hash(++i, buf(3)+buf(w)>>3, buf(1)>>5, buf(2)>>5, color)); + cm.set(hash(++i, buf(1), buf(2), color)); + cm.set(hash(++i, buf(3), buf(1)-buf(4), color)); + cm.set(hash(++i, buf(3)+buf(1)-buf(4), color)); + cm.set(hash(++i, buf(w), buf(1)-buf(w+1), color)); + cm.set(hash(++i, buf(w)+buf(1)-buf(w+1), color)); + cm.set(hash(++i, mean, logvar>>5, color)); + scm1.set(buf(3)+buf(w)-buf(w+3)); + scm2.set(buf(3)+buf(w-3)-buf(w)); + scm3.set(buf(3)*2-buf(6)); + scm4.set(buf(w)*2-buf(w*2)); + scm5.set(buf(w+3)*2-buf(w*2+6)); + scm6.set(buf(w-3)*2-buf(w*2-6)); + scm7.set(buf(w-3)+buf(1)-buf(w-2)); + scm8.set(buf(w)+buf(w-3)-buf(w*2-3)); + scm9.set(mean>>1|logvar<<1&0x180); + } + + // Predict next bit + scm1.mix(m); + scm2.mix(m); + scm3.mix(m); + scm4.mix(m); + scm5.mix(m); + scm6.mix(m); + scm7.mix(m); + scm8.mix(m); + scm9.mix(m); + scm10.mix(m); + cm.mix(m); + return w; +} + +void model8bit(Mixer& m, int w) { + const int SC=0x20000; + static SmallStationaryContextMap scm1(SC), scm2(SC), + scm3(SC), scm4(SC), scm5(SC), scm6(SC*2),scm7(SC); + static ContextMap cm(MEM*4, 32); + + // Select nearby pixels as context + if (!bpos) { + assert(w>3); + int mean=buf(1)+buf(w-1)+buf(w)+buf(w+1); + const int var=sqrbuf(1)+sqrbuf(w-1)+sqrbuf(w)+sqrbuf(w+1)-mean*mean/4>>2; + mean>>=2; + const int logvar=ilog(var); + int i=0; + // 2 x + cm.set(hash(++i, buf(1)>>2, buf(w)>>2)); + cm.set(hash(++i, buf(1)>>2, buf(2)>>2)); + cm.set(hash(++i, buf(w)>>2, buf(w*2)>>2)); + cm.set(hash(++i, buf(1)>>2, buf(w-1)>>2)); + cm.set(hash(++i, buf(w)>>2, buf(w+1)>>2)); + cm.set(hash(++i, buf(w+1)>>2, buf(w+2)>>2)); + cm.set(hash(++i, buf(w+1)>>2, buf(w*2+2)>>2)); + cm.set(hash(++i, buf(w-1)>>2, buf(w*2-2)>>2)); + cm.set(hash(++i, buf(1)+buf(w)>>1)); + cm.set(hash(++i, buf(1)+buf(2)>>1)); + cm.set(hash(++i, buf(w)+buf(w*2)>>1)); + cm.set(hash(++i, buf(1)+buf(w-1)>>1)); + cm.set(hash(++i, buf(w)+buf(w+1)>>1)); + cm.set(hash(++i, buf(w+1)+buf(w+2)>>1)); + cm.set(hash(++i, buf(w+1)+buf(w*2+2)>>1)); + cm.set(hash(++i, buf(w-1)+buf(w*2-2)>>1)); + + // 3 x + cm.set(hash(++i, buf(w)>>2, buf(1)>>2, buf(w-1)>>2)); + cm.set(hash(++i, buf(w-1)>>2, buf(w)>>2, buf(w+1)>>2)); + cm.set(hash(++i, buf(1)>>2, buf(w-1)>>2, buf(w*2-1)>>2)); + + // mixed + cm.set(hash(++i, buf(3)+buf(w)>>1, buf(1)>>2, buf(2)>>2)); + cm.set(hash(++i, buf(2)+buf(1)>>1,buf(w)+buf(w*2)>>1,buf(w-1)>>2)); + cm.set(hash(++i, buf(2)+buf(1)>>2,buf(w-1)+buf(w)>>2)); + cm.set(hash(++i, buf(2)+buf(1)>>1,buf(w)+buf(w*2)>>1)); + cm.set(hash(++i, buf(2)+buf(1)>>1,buf(w-1)+buf(w*2-2)>>1)); + cm.set(hash(++i, buf(2)+buf(1)>>1,buf(w+1)+buf(w*2+2)>>1)); + cm.set(hash(++i, buf(w)+buf(w*2)>>1,buf(w-1)+buf(w*2+2)>>1)); + cm.set(hash(++i, buf(w-1)+buf(w)>>1,buf(w)+buf(w+1)>>1)); + cm.set(hash(++i, buf(1)+buf(w-1)>>1,buf(w)+buf(w*2)>>1)); + cm.set(hash(++i, buf(1)+buf(w-1)>>2,buf(w)+buf(w+1)>>2)); + + cm.set(hash(++i, (buf(1)-buf(w-1)>>1)+buf(w)>>2)); + cm.set(hash(++i, (buf(w-1)-buf(w)>>1)+buf(1)>>2)); + cm.set(hash(++i, -buf(1)+buf(w-1)+buf(w)>>2)); + + scm1.set(buf(1)+buf(w)>>1); + scm2.set(buf(1)+buf(w)-buf(w+1)>>1); + scm3.set(buf(1)*2-buf(2)>>1); + scm4.set(buf(w)*2-buf(w*2)>>1); + scm5.set(buf(1)+buf(w)-buf(w-1)>>1); + scm6.set(mean>>1|logvar<<1&0x180); + } + + // Predict next bit + scm1.mix(m); + scm2.mix(m); + scm3.mix(m); + scm4.mix(m); + scm5.mix(m); + scm6.mix(m); + scm7.mix(m); // Amazingly but improves compression! + cm.mix(m); + //return w; +} + +//////////////////////////// pgmModel ///////////////////////////////// + +// Model a 8-bit grayscale uncompressed binary .pgm and 8-bit color +// uncompressed .bmp images. Return width in pixels if an image file +// is detected, else 0. + +#define ISWHITESPACE(i) (buf(i) == ' ' || buf(i) == '\t' || buf(i) == '\n' || buf(i) == '\r') +#define ISCRLF(i) (buf(i) == '\n' || buf(i) == '\r') + +int pgmModel(Mixer& m) { + static int h = 0; // height of image in bytes (pixels) + static int w = 0; // width of image in bytes (pixels) + static int eoi = 0; // end of image + static int pgm = 0; // offset of pgm header + static int pgm_hdr[3]; // 0 - Width, 1 - Height, 2 - Max value + static int pgm_ptr; // which record in header should be parsed next + int isws; // is white space + char v_buf[32]; + int v_ptr; + if (!bpos) + { + if(buf(3)=='P' && buf(2)=='5' && ISWHITESPACE(1)) // Detect PGM file + { + pgm = pos; + pgm_ptr = 0; + return w = 0; // PGM header just detected, not enough info to get header yet + }else + if(pgm && pgm_ptr!=3) // PGM detected, let's parse header records + { + for (int i = pgm; i0 && pgm_hdr[1]>0) + { + w = pgm_hdr[0]; + h = pgm_hdr[1]; + eoi = pos+w*h; + printf("PGM %dx%d",w,h); + } + } + } + } + if (pos>eoi) return w=0; + model8bit(m,w); + static int col=0; + if (++col>=8) col=0; // reset after every 24 columns? + m.set(2, 8); + m.set(col, 8); + m.set(buf(w)+buf(1)>>4, 32); + m.set(c0, 256); + return w; +} + +int bmpModel8(Mixer& m) { + static int h = 0; // height of image in bytes (pixels) + static int w = 0; // width of image in bytes (pixels) + static int eoi = 0; // end of image + static int col = 0; + static int ibmp=0,w1=0; + if (bpos==0) { + // 8-bit .bmp images data offset windows bmp compression bpp + if (/*buf(54)=='B' && buf(53)=='M' && */(i4(44)< 1079) && i4(40)==40 && i4(24)==0 && (buf(26)==8 /*| buf(26)==4)*/)){ + /* if (buf(26)==4) + w1=i4(36)/2; // image width + else*/ + w1=i4(36); // image width 8453632 -> 2079974 + h=i4(32); // image height + ibmp=pos+i4(44)-54; + } + if (ibmp==pos) { + w=w1; + eoi=pos+w*h; + printf("BMP(8-bit) %dx%d",w,h); + ibmp=0; + } + } + if (pos>eoi) return w=0; + model8bit(m,w); + if (++col>=8) col=0; // reset after every 24 columns? + m.set(2, 8); + m.set(col, 8); + m.set(buf(w)+buf(1)>>4, 32); + m.set(c0, 256); + return w; +} + +int rgbModel8(Mixer& m) { + int h = 0; // height of image in bytes (pixels) + static int w = 0; // width of image in bytes (pixels) + static int eoi = 0; // end of image + static int col = 0; + // for .rgb gray images + if (bpos==0) { + if (buf(507)==1 && buf(506)==218 && buf(505)==0 && i2(496)==1) + { + w=(buf(501)&255)*256|(buf(500)&255); // image width + h=(buf(499)&255)*256|(buf(498)&255); // image height + eoi=pos+w*h; + printf("RGB(8-bit) %dx%d",w,h); + } + } + if (pos>eoi) return w=0; + model8bit(m,w); + if (++col>=8) col=0; // reset after every 24 columns? + m.set(2, 8); + m.set(col, 8); + m.set(buf(w)+buf(1)>>4, 32); + m.set(c0, 256); + return w; +} + +//////////////////////////// jpegModel ///////////////////////// + +// Model JPEG. Return 1-257 if a JPEG file is detected or else 0. +// Only the baseline and 8 bit extended Huffman coded DCT modes are +// supported. The model partially decodes the JPEG image to provide +// context for the Huffman coded symbols. + +// Print a JPEG segment at buf[p...] for debugging +void dump(const char* msg, int p) { + printf("%s:", msg); + int len=buf[p+2]*256+buf[p+3]; + for (int i=0; i+2) {k1++;k2=0;} +} + +int jpegModel(Mixer& m) { + + // State of parser + enum {SOF0=0xc0, SOF1, SOF2, SOF3, DHT, RST0=0xd0, SOI=0xd8, EOI, SOS, DQT, + DNL, DRI, APP0=0xe0, COM=0xfe, FF}; // Second byte of 2 byte codes + static int jpeg=0; // 1 if JPEG is header detected, 2 if image data + static int next_jpeg=0; // updated with jpeg on next byte boundary + static int app; // Bytes remaining to skip in APPx or COM field + static int sof=0, sos=0, data=0; // pointers to buf + static Array ht(8); // pointers to Huffman table headers + static int htsize=0; // number of pointers in ht + + // Huffman decode state + static U32 huffcode=0; // Current Huffman code including extra bits + static int huffbits=0; // Number of valid bits in huffcode + static int huffsize=0; // Number of bits without extra bits + static int rs=-1; // Decoded huffcode without extra bits. It represents + // 2 packed 4-bit numbers, r=run of zeros, s=number of extra bits for + // first nonzero code. huffcode is complete when rs >= 0. + // rs is -1 prior to decoding incomplete huffcode. + static int mcupos=0; // position in MCU (0-639). The low 6 bits mark + // the coefficient in zigzag scan order (0=DC, 1-63=AC). The high + // bits mark the block within the MCU, used to select Huffman tables. + + // Decoding tables + static Array huf(128); // Tc*64+Th*16+m -> min, max, val + static int mcusize=0; // number of coefficients in an MCU + static int linesize=0; // width of image in MCU + static int hufsel[2][10]; // DC/AC, mcupos/64 -> huf decode table + static Array hbuf(2048); // Tc*1024+Th*256+hufcode -> RS + + // Image state + static Array color(10); // block -> component (0-3) + static Array pred(4); // component -> last DC value + static int dc=0; // DC value of the current block + static int width=0; // Image width in MCU + static int row=0, column=0; // in MCU (column 0 to width-1) + static Buf cbuf(0x20000); // Rotating buffer of coefficients, coded as: + // DC: level shifted absolute value, low 4 bits discarded, i.e. + // [-1023...1024] -> [0...255]. + // AC: as an RS code: a run of R (0-15) zeros followed by an S (0-15) + // bit number, or 00 for end of block (in zigzag order). + // However if R=0, then the format is ssss11xx where ssss is S, + // xx is the first 2 extra bits, and the last 2 bits are 1 (since + // this never occurs in a valid RS code). + static int cpos=0; // position in cbuf + static U32 huff1=0, huff2=0, huff3=0, huff4=0; // hashes of last codes + static int rs1, rs2, rs3, rs4; // last 4 RS codes + static int ssum=0, ssum1=0, ssum2=0, ssum3=0, ssum4=0; + // sum of S in RS codes in block and last 4 values + + static IntBuf cbuf2(0x20000); + static Array adv_pred(7), sumu(8), sumv(8); + static Array ls(10); // block -> distance to previous block + static Array lcp(4), zpos(64); + + //for parsing Quantization tables + static int dqt_state = -1, dqt_end = 0, qnum = 0; + static Array qtab(256); // table + static Array qmap(10); // block -> table number + + const static U8 zzu[64]={ // zigzag coef -> u,v + 0,1,0,0,1,2,3,2,1,0,0,1,2,3,4,5,4,3,2,1,0,0,1,2,3,4,5,6,7,6,5,4, + 3,2,1,0,1,2,3,4,5,6,7,7,6,5,4,3,2,3,4,5,6,7,7,6,5,4,5,6,7,7,6,7}; + const static U8 zzv[64]={ + 0,0,1,2,1,0,0,1,2,3,4,3,2,1,0,0,1,2,3,4,5,6,5,4,3,2,1,0,0,1,2,3, + 4,5,6,7,7,6,5,4,3,2,1,2,3,4,5,6,7,7,6,5,4,3,4,5,6,7,7,6,5,6,7,7}; + + // Be sure to quit on a byte boundary + if (!bpos) next_jpeg=jpeg>1; + if (bpos && !jpeg) return next_jpeg; + if (!bpos && app>0) --app; + if (app>0) return next_jpeg; + if (!bpos) { + + // Parse. Baseline DCT-Huffman JPEG syntax is: + // SOI APPx... misc... SOF0 DHT... SOS data EOI + // SOI (= FF D8) start of image. + // APPx (= FF Ex) len ... where len is always a 2 byte big-endian length + // including the length itself but not the 2 byte preceding code. + // Application data is ignored. There may be more than one APPx. + // misc codes are DQT, DNL, DRI, COM (ignored). + // SOF0 (= FF C0) len 08 height width Nf [C HV Tq]... + // where len, height, width (in pixels) are 2 bytes, Nf is the repeat + // count (1 byte) of [C HV Tq], where C is a component identifier + // (color, 0-3), HV is the horizontal and vertical dimensions + // of the MCU (high, low bits, packed), and Tq is the quantization + // table ID (not used). An MCU (minimum compression unit) consists + // of 64*H*V DCT coefficients for each color. + // DHT (= FF C4) len [TcTh L1...L16 V1,1..V1,L1 ... V16,1..V16,L16]... + // defines Huffman table Th (1-4) for Tc (0=DC (first coefficient) + // 1=AC (next 63 coefficients)). L1..L16 are the number of codes + // of length 1-16 (in ascending order) and Vx,y are the 8-bit values. + // A V code of RS means a run of R (0-15) zeros followed by S (0-15) + // additional bits to specify the next nonzero value, negative if + // the first additional bit is 0 (e.g. code x63 followed by the + // 3 bits 1,0,1 specify 7 coefficients: 0, 0, 0, 0, 0, 0, 5. + // Code 00 means end of block (remainder of 63 AC coefficients is 0). + // SOS (= FF DA) len Ns [Cs TdTa]... 0 3F 00 + // Start of scan. TdTa specifies DC/AC Huffman tables (0-3, packed + // into one byte) for component Cs matching C in SOF0, repeated + // Ns (1-4) times. + // EOI (= FF D9) is end of image. + // Huffman coded data is between SOI and EOI. Codes may be embedded: + // RST0-RST7 (= FF D0 to FF D7) mark the start of an independently + // compressed region. + // DNL (= FF DC) 04 00 height + // might appear at the end of the scan (ignored). + // FF 00 is interpreted as FF (to distinguish from RSTx, DNL, EOI). + + // Detect JPEG (SOI, APPx) + if (!jpeg && buf(4)==FF && buf(3)==SOI && buf(2)==FF && buf(1)>>4==0xe) { + jpeg=1; + app=sos=sof=htsize=data=mcusize=linesize=0; + huffcode=huffbits=huffsize=mcupos=cpos=0, rs=-1; + memset(&huf[0], 0, huf.size()*sizeof(HUF)); + memset(&pred[0], 0, pred.size()*sizeof(int)); + } + + // Detect end of JPEG when data contains a marker other than RSTx + // or byte stuff (00). + if (jpeg && data && buf(2)==FF && buf(1) && (buf(1)&0xf8)!=RST0) { + jassert(buf(1)==EOI); + jpeg=0; + } + if (!jpeg) return next_jpeg; + + // Detect APPx or COM field + if (!data && !app && buf(4)==FF && (buf(3)>>4==0xe || buf(3)==COM)) + app=buf(2)*256+buf(1)+2; + + // Save pointers to sof, ht, sos, data, + if (buf(5)==FF && buf(4)==SOS) { + int len=buf(3)*256+buf(2); + if (len==6+2*buf(1) && buf(1) && buf(1)<=4) // buf(1) is Ns + sos=pos-5, data=sos+len+2, jpeg=2; + } + if (buf(4)==FF && buf(3)==DHT && htsize<8) ht[htsize++]=pos-4; + if (buf(4)==FF && buf(3)==SOF0) sof=pos-4; + + // Parse Quantizazion tables + if (buf(4)==FF && buf(3)==DQT) + dqt_end=pos+buf(2)*256+buf(1)-1, dqt_state=0; + else if (dqt_state>=0) { + if (pos>=dqt_end) + dqt_state = -1; + else { + if (dqt_state%65==0) + qnum = buf(1); + else { + jassert(buf(1)>0); + jassert(qnum>=0 && qnum<4); + qtab[qnum*64+((dqt_state%65)-1)]=buf(1)-1; + } + dqt_state++; + } + } + + // Restart + if (buf(2)==FF && (buf(1)&0xf8)==RST0) { + huffcode=huffbits=huffsize=mcupos=0, rs=-1; + memset(&pred[0], 0, pred.size()*sizeof(int)); + } + } + + { + // Build Huffman tables + // huf[Tc][Th][m] = min, max+1 codes of length m, pointer to byte values + if (pos==data && bpos==1) { + jassert(htsize>0); + int i; + for ( i=0; i>4, th=buf[p]&15; + if (tc>=2 || th>=4) break; + jassert(tc>=0 && tc<2 && th>=0 && th<4); + HUF* h=&huf[tc*64+th*16]; // [tc][th][0]; + int val=p+17; // pointer to values + int hval=tc*1024+th*256; // pointer to RS values in hbuf + int j; + for ( j=0; j<256; ++j) // copy RS codes + hbuf[hval+j]=buf[val+j]; + int code=0; + for ( j=0; j<16; ++j) { + h[j].min=code; + h[j].max=code+=buf[p+j+1]; + h[j].val=hval; + val+=buf[p+j+1]; + hval+=buf[p+j+1]; + code*=2; + } + p=val; + jassert(hval>=0 && hval<2048); + } + jassert(p==end); + } + huffcode=huffbits=huffsize=0, rs=-1; + + // Build Huffman table selection table (indexed by mcupos). + // Get image width. + if (!sof && sos) return next_jpeg; + int ns=buf[sos+4]; + int nf=buf[sof+9]; + jassert(ns<=4 && nf<=4); + mcusize=0; // blocks per MCU + int hmax=0; // MCU horizontal dimension + for ( i=0; i>4>hmax) hmax=hv>>4; + hv=(hv&15)*(hv>>4); // number of blocks in component C + jassert(hv>=1 && hv+mcusize<=10); + while (hv) { + jassert(mcusize<10); + hufsel[0][mcusize]=buf[sos+2*i+6]>>4&15; + hufsel[1][mcusize]=buf[sos+2*i+6]&15; + jassert (hufsel[0][mcusize]<4 && hufsel[1][mcusize]<4); + color[mcusize]=i; + int tq=buf[sof+3*j+12]; // quantization table index (0..3) + jassert(tq>=0 && tq<4); + qmap[mcusize]=tq; // quantizazion table mapping + --hv; + ++mcusize; + } + } + } + } + jassert(hmax>=1 && hmax<=10); + int j; + for ( j=0; j0); + mcusize*=64; // coefficients per MCU + row=column=0; + } + } + + + // Decode Huffman + { + if (mcusize && buf(1+(!bpos))!=FF) { // skip stuffed byte + jassert(huffbits<=32); + huffcode+=huffcode+y; + ++huffbits; + if (rs<0) { + jassert(huffbits>=1 && huffbits<=16); + const int ac=(mcupos&63)>0; + jassert(mcupos>=0 && (mcupos>>6)<10); + jassert(ac==0 || ac==1); + const int sel=hufsel[ac][mcupos>>6]; + jassert(sel>=0 && sel<4); + const int i=huffbits-1; + jassert(i>=0 && i<16); + const HUF *h=&huf[ac*64+sel*16]; // [ac][sel]; + jassert(h[i].min<=h[i].max && h[i].val<2048 && huffbits>0); + if (huffcode=h[i].min); + int k=h[i].val+huffcode-h[i].min; + jassert(k>=0 && k<2048); + rs=hbuf[k]; + huffsize=huffbits; + } + } + if (rs>=0) { + if (huffsize+(rs&15)==huffbits) { // done decoding + huff4=huff3; + huff3=huff2; + huff2=huff1; + huff1=hash(huffcode, huffbits); + rs4=rs3; + rs3=rs2; + rs2=rs1; + rs1=rs; + int x=0; // decoded extra bits + if (mcupos&63) { // AC + if (rs==0) { // EOB + mcupos=mcupos+63&-64; + jassert(mcupos>=0 && mcupos<=mcusize && mcupos<=640); + while (cpos&63) { + cbuf2[cpos]=0; + cbuf[cpos++]=0; + } + } + else { // rs = r zeros + s extra bits for the next nonzero value + // If first extra bit is 0 then value is negative. + jassert((rs&15)<=10); + const int r=rs>>4; + const int s=rs&15; + jassert(mcupos>>6==mcupos+r>>6); + mcupos+=r+1; + x=huffcode&(1<>s-1)) x-=(1<=1; --i) { + cbuf2[cpos]=0; + cbuf[cpos++]=i<<4|s; + } + cbuf2[cpos]=x; + cbuf[cpos++]=s<<4|huffcode<<2>>s&3|12; + ssum+=s; + } + } + else { // DC: rs = 0S, s<12 + jassert(rs<12); + ++mcupos; + x=huffcode&(1<>rs-1)) x-=(1<=0 && mcupos>>6<10); + const int comp=color[mcupos>>6]; + jassert(comp>=0 && comp<4); + dc=pred[comp]+=x; + jassert((cpos&63)==0); + cbuf2[cpos]=dc; + cbuf[cpos++]=dc+1023>>3; + ssum4=ssum3; + ssum3=ssum2; + ssum2=ssum1; + ssum1=ssum; + ssum=rs; + } + jassert(mcupos>=0 && mcupos<=mcusize); + if (mcupos>=mcusize) { + mcupos=0; + if (++column==width) column=0, ++row; + } + huffcode=huffsize=huffbits=0, rs=-1; + + + // UPDATE_ADV_PRED !!!! + { + const int acomp=mcupos>>6, q=64*qmap[acomp]; + const int zz=mcupos&63, cpos_dc=cpos-zz; + const static int we[8]={181, 282, 353, 456, 568, 671, 742, 767}; + static int sumu2[8], sumv2[8], sumu3[8], sumv3[8], kx[32]; + if (zz == 0) { + for (int i=0; i<8; i++) { + update_k(sumv2[i], sumv3[i], kx[i], kx[i+16]); + update_k(sumu2[i], sumu3[i], kx[i+8], kx[i+24]); + sumu2[i]=sumv2[i]=sumu3[i]=sumv3[i]=0; + } + int cpos_dc_ls_acomp = cpos_dc-ls[acomp]; + int cpos_dc_mcusize_width = cpos_dc-mcusize*width; + for (int i=0; i<64; i++) { + sumu2[zzu[i]]+=we[zzv[i]]*(zzv[i]&1?-1:+1)*(qtab[q+i]+1)*cbuf2[cpos_dc_mcusize_width+i]; + sumv2[zzv[i]]+=we[zzu[i]]*(zzu[i]&1?-1:+1)*(qtab[q+i]+1)*cbuf2[cpos_dc_ls_acomp+i]; + sumu3[zzu[i]]+=(zzv[i]?(zzv[i]&1?-256:256):181)*(qtab[q+i]+1)*cbuf2[cpos_dc_mcusize_width+i]; + sumv3[zzv[i]]+=(zzu[i]?(zzu[i]&1?-256:256):181)*(qtab[q+i]+1)*cbuf2[cpos_dc_ls_acomp+i]; + } + } else { + sumu2[zzu[zz-1]]-=we[zzv[zz-1]]*(qtab[q+zz-1]+1)*cbuf2[cpos-1]; + sumv2[zzv[zz-1]]-=we[zzu[zz-1]]*(qtab[q+zz-1]+1)*cbuf2[cpos-1]; + sumu3[zzu[zz-1]]-=(zzv[zz-1]?256:181)*(qtab[q+zz-1]+1)*cbuf2[cpos-1]; + sumv3[zzv[zz-1]]-=(zzu[zz-1]?256:181)*(qtab[q+zz-1]+1)*cbuf2[cpos-1]; + } + for (int i=0; i<8; ++i) { + int k=kx[i]; + sumv[i]=(sumv2[i]*k+sumv3[i]*(8-k))/8; + k=kx[i+8]; + sumu[i]=(sumu2[i]*k+sumu3[i]*(8-k))/8; + } + + for (int i=0; i<3; ++i) + for (int st=0; st<8; ++st) { + const int zz2 = min(zz+st, 63); + int p=(sumu[zzu[zz2]]*i+sumv[zzv[zz2]]*(2-i))/2; + p/=(qtab[q+zz2]+1)*181; + if (zz2==0) p-=cbuf2[cpos_dc-ls[acomp]], p=(p<0?-1:+1)*ilog(14*abs(p)+1)/10; + else p=(p<0?-1:+1)*ilog(10*abs(p)+1)/10; + if (st==0) { + adv_pred[i]=p; + adv_pred[i+4]=p/4; + } + else if (abs(p)>abs(adv_pred[i])+1) { + adv_pred[i]+=st*2+(p>0)<<6; + if (abs(p/4)>abs(adv_pred[i+4])+1) adv_pred[i+4]+=st*2+(p>0)<<6; + break; + } + } + x=2*sumu[zzu[zz]]+2*sumv[zzv[zz]]; + for (int i=0; i<8; ++i) { + if (zzu[zz] t(MEM); // context hash -> bit history + // As a cache optimization, the context does not include the last 1-2 + // bits of huffcode if the length (huffbits) is not a multiple of 3. + // The 7 mapped values are for context+{"", 0, 00, 01, 1, 10, 11}. + static Array cxt(N); // context hashes + static Array cp(N); // context pointers + static StateMap sm[N]; + static Mixer m1(32, 770, 3); + static APM a1(0x8000), a2(0x10000); + + + // Update model + if (cp[N-1]) { + for (int i=0; i>6]; + const int coef=(mcupos&63)|comp<<6; + const int hc=(huffcode*2+(comp==0))|1<<(huffbits+1); + static int hbcount=2; + if (++hbcount>2 || huffbits==0) hbcount=0; + jassert(coef>=0 && coef<256); + const int zu=zzu[mcupos&63], zv=zzv[mcupos&63]; + if (hbcount==0) { + int n=0; + cxt[0]=hash(++n, hc, coef, adv_pred[2]); + cxt[1]=hash(++n, hc, coef, adv_pred[0]); + cxt[2]=hash(++n, hc, coef, adv_pred[1]); + cxt[3]=hash(++n, hc, rs1, adv_pred[2]); + cxt[4]=hash(++n, hc, rs1, adv_pred[0]); + cxt[5]=hash(++n, hc, rs1, adv_pred[1]); + cxt[6]=hash(++n, hc, adv_pred[2], adv_pred[0]); + cxt[7]=hash(++n, hc, cbuf[cpos-width*mcusize], adv_pred[3]); + cxt[8]=hash(++n, hc, cbuf[cpos-ls[mcupos>>6]], adv_pred[3]); + cxt[9]=hash(++n, hc, lcp[0], lcp[1], adv_pred[1]); + cxt[10]=hash(++n, hc, lcp[0], lcp[1], coef); + cxt[11]=hash(++n, hc, zu, lcp[0], lcp[2]/3); + cxt[12]=hash(++n, hc, zv, lcp[1], lcp[3]/3); + cxt[13]=hash(++n, hc, mcupos>>2, min(3, mcupos&63)); + cxt[14]=hash(++n, hc, coef, column>>1); + cxt[15]=hash(++n, hc, column>>2, lcp[0]+256*(lcp[2]/3), lcp[1]+256*(lcp[3]/3)); + cxt[16]=hash(++n, hc, ssum>>4, coef); + cxt[17]=hash(++n, hc, rs1, coef); + cxt[18]=hash(++n, hc, mcupos>>3, ssum3>>3, adv_pred[3]); + cxt[19]=hash(++n, hc, lcp[0]/3, lcp[1]/3, adv_pred[5]); + cxt[20]=hash(++n, hc, cbuf[cpos-width*mcusize], adv_pred[6]); + cxt[21]=hash(++n, hc, cbuf[cpos-ls[mcupos>>6]], adv_pred[4]); + cxt[22]=hash(++n, hc, adv_pred[2]); + cxt[23]=hash(n, hc, adv_pred[0]); + cxt[24]=hash(n, hc, adv_pred[1]); + cxt[25]=hash(++n, hc, zv, lcp[1], adv_pred[6]); + cxt[26]=hash(++n, hc, zu, lcp[0], adv_pred[4]); + cxt[27]=hash(++n, hc, lcp[0], lcp[1], adv_pred[3]); + } + + // Predict next bit + m1.add(128); + assert(hbcount<=2); + switch(hbcount) + { + case 0: for (int i=0; i>(8-b); + if (i2) c=c<>(8-b); + if (i3) c=c<>(8-b); + if (i4) c=c<>(8-b); + return c; + } + +inline int s2(int i) { + return int(short(buf(i)+256*buf(i-1))); +} + +inline int X(int i, int j) { + if (wmode==18) { + if (i<=S) return s2(i+j<<2); else return s2((i+j-S<<2)-2); + } + else if (wmode==17) return s2(i+j<<1); + else if (wmode==10) { + if (i<=S) return buf(i+j<<1); else return buf((i+j-S<<1)-1); + } + else return buf(i+j); +} + +int wavModel(Mixer& m) { + static int channels; // number of channels + static int bits; // bits per sample + static int bytes; // bytes per sample + static int eof=0; // end of wav + static int s=0; // size in bytes + static int w,K=128>>(level-1); + static int pr[4][2], n[2], counter[2]; + int chn,ch,msb,j,k,l,i=0; + double sum,a=0.996; + double F[49][49][2],L[49][49]; + const int SC=0x20000; + static SmallStationaryContextMap scm1(SC), scm2(SC), scm3(SC), scm4(SC), scm5(SC), scm6(SC), scm7(SC), scm8(SC); + static ContextMap cm(MEM*4, 10); + + // Detect .wav file header + if (!bpos && buf(8)=='d' && buf(7)=='a' && buf(6)=='t' && buf(5)=='a') { + for (int i=32; i<=1000; i++) + if (buf(i)=='f' && buf(i-1)=='m' && buf(i-2)=='t' && buf(i-3)==' ' && (i2(i-8)==1||i2(i-8)==65534)) { + bits=buf(i-22); + bytes=bits+7>>3; + channels=buf(i-10); + w=channels*bytes; + s=i4(4); + if ((channels==1 || channels==2) && (bits==8 || bits==16)) { + eof=pos+s; + for (int j=0; jeof) return bits=channels=0; + + // Select previous samples and predicted sample as context + if (!bpos) { + msb=(pos+s-eof)%bytes; + ch=(pos+s-eof)%w; + chn=ch/bytes; + if (!msb) { + for (l=0; l<=S+D; l++) if (l=0&&l-S-10) { + L[i][i]=sqrt(sum); + for (j=(i+1); j<=S+D; j++) { + sum=F[i][j][chn]; + for (k=1; kS+D && counter[chn]>S+1) { + for (k=1; k<=S+D; k++) { + F[k][0][chn]=F[0][k][chn]; + for (j=1; j0; k--) { + for (j=k+1; j<=S+D; j++) F[k][0][chn]-=L[j][k]*F[j][0][chn]; + F[k][0][chn]/=L[k][k]; + } + } + n[chn]=0; + } + sum=0; + for (l=1; l<=S+D; l++) sum+=F[l][0][chn]*X(l,0); + pr[3][chn]=pr[2][chn]; + pr[2][chn]=pr[1][chn]; + pr[1][chn]=pr[0][chn]; + pr[0][chn]=int(floor(sum)); + counter[chn]++; + i=0; + cm.set(hash(++i, buf(1), ch)); + cm.set(hash(++i, buf(1), buf(2), ch)); + cm.set(hash(++i, buf(1), buf(2)>>3, buf(3), ch)); + cm.set(hash(++i, s2(4)+s2(2)-s2(6)&0xff, ch)); + cm.set(hash(++i, pr[0][chn]&0xff, ch)); + cm.set(hash(++i, pr[0][chn]+s2(w)-pr[1][chn]&0xff ,ch)); + cm.set(hash(++i, pr[0][chn]&0xff, (s2(w)-pr[1][chn]+s2(w*2)-pr[2][chn]>>1)&0xff, ch)); + cm.set(hash(++i, pr[0][chn]+s2(w)*2-pr[1][chn]*2-s2(w*2)+pr[2][chn]&0xff, ch)); + scm1.set(s2(w)&0x1ff); + scm2.set(s2(w)*2-s2(w*2)&0x1ff); + scm3.set(s2(w)*3-s2(w*2)*3+s2(w*3)&0x1ff); + } + else { + cm.set(hash(++i, buf(1), ch)); + cm.set(hash(++i, buf(1)>>7, buf(2), buf(3)>>7, ch)); + cm.set(hash(++i, c(7, w,w*2,w*3,w*4), ch)); + cm.set(hash(++i, c(5, w,w*2,w*3,w*4), c(5, w*5,w*6), ch)); + cm.set(hash(++i, c(4, w,w*2,w*3,w*4), c(3, w*5,w*6,w*7,w*8), c(2, w*9,w*10,w*11,w*12), ch)); + cm.set(hash(++i, c(2, w,w*2,w*3,w*4)<<8|c(2, w*5,w*6,w*7,w*8), c(2, w*9,w*10,w*11,w*12)<<8|c(2, w*13,w*14,w*15,w*16), c(2, w*17,w*18,w*19,w*20)<<8|c(2, w*21,w*22,w*23,w*24), ch)); + cm.set(hash(++i, pr[0][chn]>>8, ch)); + cm.set(hash(++i, pr[0][chn]+s2(w+1)-pr[1][chn]>>8 ,ch)); + cm.set(hash(++i, pr[0][chn]>>8, s2(w+1)-pr[1][chn]+s2(w*2+1)-pr[2][chn]>>9, ch)); + cm.set(hash(++i, pr[0][chn]+s2(w+1)*2-pr[1][chn]*2-s2(w*2+1)+pr[2][chn]>>8, ch)); + scm1.set(s2(5)+s2(3)-s2(7)-buf(1)+pr[0][chn]>>9); + scm2.set(s2(w+1)-buf(1)+pr[0][chn]>>9); + scm3.set(s2(w+1)*2-s2(w*2+1)-buf(1)+pr[0][chn]>>8); + scm4.set(s2(w+1)*3-s2(w*2+1)*3+s2(w*3+1)-buf(1)>>7); + scm5.set(s2(w-1)+s2(w+1)-buf(1)+pr[0][chn]*2>>10); + scm7.set(s2(w+1)*4-s2(w*2+1)*6+s2(w*3+1)*4-s2(w*4+1)-buf(1)>>7); + scm8.set(s2(w+1)*5-s2(w*2+1)*10+s2(w*3+1)*10-s2(w*4+1)*5+s2(w*5+1)-buf(1)+pr[0][chn]>>9); + } + } + + // Predict next bit + scm1.mix(m); + scm2.mix(m); + scm3.mix(m); + scm4.mix(m); + scm5.mix(m); + scm6.mix(m); + scm7.mix(m); + scm8.mix(m); + cm.mix(m); + return channels<<8|bits; +} + +//////////////////////////// exeModel ///////////////////////// + +// Model x86 code. The contexts are sparse containing only those +// bits relevant to parsing (2 prefixes, opcode, and mod and r/m fields +// of modR/M byte). + +// Get context at buf(i) relevant to parsing 32-bit x86 code +U32 execxt(int i, int x=0) { + int prefix=(buf(i+2)==0x0f)+2*(buf(i+2)==0x66)+3*(buf(i+2)==0x67) + +4*(buf(i+3)==0x0f)+8*(buf(i+3)==0x66)+12*(buf(i+3)==0x67); + int opcode=buf(i+1); + int modrm=i ? buf(i)&0xc7 : 0; + return prefix|opcode<<4|modrm<<12|x<<20; +} + +void exeModel(Mixer& m) { + const int N=12; + static ContextMap cm(MEM, N); + if (!bpos) { + for (int i=0; i4))); + } + cm.mix(m); +} + +//////////////////////////// indirectModel ///////////////////// + +// The context is a byte string history that occurs within a +// 1 or 2 byte context. + +void indirectModel(Mixer& m) { + static ContextMap cm(MEM, 6); + static U32 t1[256]; + static U16 t2[0x10000]; + + if (!bpos) { + U32 d=c4&0xffff, c=d&255; + U32& r1=t1[d>>8]; + r1=r1<<8|c; + U16& r2=t2[c4>>8&0xffff]; + r2=r2<<8|c; + U32 t=c|t1[c]<<8; + cm.set(t&0xffff); + cm.set(t&0xffffff); + cm.set(t); + cm.set(t&0xff00); + t=d|t2[d]<<16; + cm.set(t&0xffffff); + cm.set(t); + + } + cm.mix(m); +} + +//////////////////////////// dmcModel ////////////////////////// + +// Model using DMC. The bitwise context is represented by a state graph, +// initilaized to a bytewise order 1 model as in +// http://plg.uwaterloo.ca/~ftp/dmc/dmc.c but with the following difference: +// - It uses integer arithmetic. +// - The threshold for cloning a state increases as memory is used up. +// - Each state maintains both a 0,1 count and a bit history (as in a +// context model). The 0,1 count is best for stationary data, and the +// bit history for nonstationary data. The bit history is mapped to +// a probability adaptively using a StateMap. The two computed probabilities +// are combined. +// - When memory is used up the state graph is reinitialized to a bytewise +// order 1 context as in the original DMC. However, the bit histories +// are not cleared. + +struct DMCNode { // 12 bytes + unsigned int nx[2]; // next pointers + U8 state; // bit history + unsigned int c0:12, c1:12; // counts * 256 +}; + +void dmcModel(Mixer& m) { + static int top=0, curr=0; // allocated, current node + static Array t(MEM*2); // state graph + static StateMap sm; + static int threshold=256; + + // clone next state + if (top>0 && top=threshold*2 && nn-n>=threshold*3) { + int r=n*4096/nn; + assert(r>=0 && r<=4096); + t[next].c0 -= t[top].c0 = t[next].c0*r>>12; + t[next].c1 -= t[top].c1 = t[next].c1*r>>12; + t[top].nx[0]=t[next].nx[0]; + t[top].nx[1]=t[next].nx[1]; + t[top].state=t[next].state; + t[curr].nx[y]=top; + ++top; + if (top==MEM*2) threshold=512; + if (top==MEM*3) threshold=768; + } + } + + // Initialize to a bytewise order 1 model at startup or when flushing memory + if (top==t.size() && bpos==1) top=0; + if (top==0) { + assert(t.size()>=65536); + for (int i=0; i<256; ++i) { + for (int j=0; j<256; ++j) { + if (i<127) { + t[j*256+i].nx[0]=j*256+i*2+1; + t[j*256+i].nx[1]=j*256+i*2+2; + } + else { + t[j*256+i].nx[0]=(i-127)*256; + t[j*256+i].nx[1]=(i+1)*256; + } + t[j*256+i].c0=128; + t[j*256+i].c1=128; + } + } + top=65536; + curr=0; + threshold=256; + } + + // update count, state + if (y) { + if (t[curr].c1<3800) t[curr].c1+=256; + } + else if (t[curr].c0<3800) t[curr].c0+=256; + t[curr].state=nex(t[curr].state, y); + curr=t[curr].nx[y]; + + // predict + const int pr1=sm.p(t[curr].state); + const int n1=t[curr].c1; + const int n0=t[curr].c0; + const int pr2=(n1+5)*4096/(n0+n1+10); + m.add(stretch(pr1)); + m.add(stretch(pr2)); +} + +//////////////////////////// contextModel ////////////////////// + +typedef enum {DEFAULT, JPEG, BMPFILE4, BMPFILE8, BMPFILE24, TIFFFILE, + PGMFILE, RGBFILE, EXE, TEXT} Filetype; + +// This combines all the context models with a Mixer. + +int contextModel2() { + static ContextMap cm(MEM*32, 9); + static RunContextMap rcm7(MEM), rcm9(MEM), rcm10(MEM); + static Mixer m(800, 3088, 7, 128); + static U32 cxt[16]; // order 0-11 contexts + static Filetype filetype=DEFAULT; + static int size=0; // bytes remaining in block +// static const char* typenames[4]={"", "jpeg ", "exe ", "text "}; + + // Parse filetype and size + if (bpos==0) { + --size; + if (size==-1) filetype=(Filetype)buf(1); + if (size==-5) { + size=buf(4)<<24|buf(3)<<16|buf(2)<<8|buf(1); +// if (filetype<=3) printf("(%s%d)", typenames[filetype], size); + if (filetype==EXE) size+=8; + } + } + + m.update(); + m.add(256); + + // Test for special file types + int ismatch=ilog(matchModel(m)); // Length of longest matching context + int iswav=wavModel(m); // number of channels and bits per sample if WAV is detected, else 0 + if (filetype==JPEG){ + int isjpeg=jpegModel(m); // 1-257 if JPEG is detected, else 0 + if (isjpeg) { + m.set(1, 8); + m.set(isjpeg-1, 257); + m.set(buf(1), 256); + return m.p(); + } + } + if (filetype==BMPFILE24 || filetype==TIFFFILE){ + int isbmp=bmpModel(m); // Image width (bytes) if BMP or TIFF detected, or 0 + if (isbmp>0) { + static int col=0; + if (++col>=24) col=0; + m.set(2, 8); + m.set(col, 24); + m.set(buf(isbmp)+buf(3)>>4, 32); + m.set(c0, 256); + return m.p(); + } + } + if (filetype==PGMFILE){ + if (pgmModel(m)>0) return m.p(); // Image width (bytes) if PGM (P5,PGM_MAXVAL = 255) detected, or 0 + } + if (filetype==BMPFILE8){ + if (bmpModel8(m)>0) return m.p(); // Image width (bytes) if BMP8 detected, or 0 + } +if (filetype==RGBFILE){ + if (rgbModel8(m)>0) return m.p(); // Image width (bytes) if RGB8 detected, or 0 + } + if (iswav>0) { + int bits=iswav&0xff; + int tbits=(iswav>>8)*bits; + static int col=0; + if (++col>=tbits) col=0; + if (tbits!=bits) m.set(col, tbits); + m.set(col, bits); + m.set(c0, 256); + return m.p(); + } + + // Normal model + if (bpos==0) { + int i; + for ( i=15; i>0; --i) // update order 0-11 context hashes + cxt[i]=cxt[i-1]*257+(c4&255)+1; + for ( i=0; i<7; ++i) + cm.set(cxt[i]); + rcm7.set(cxt[7]); + cm.set(cxt[8]); + rcm9.set(cxt[10]); + rcm10.set(cxt[12]); + cm.set(cxt[14]); + } + int order=cm.mix(m); + + rcm7.mix(m); + rcm9.mix(m); + rcm10.mix(m); + + if (level>=4) { + sparseModel(m,ismatch,order); + distanceModel(m); + picModel(m); + recordModel(m); + wordModel(m); + indirectModel(m); + dmcModel(m); + if (filetype==EXE) exeModel(m); + } + + + + order = order-2; + if(order<0) order=0; + + U32 c1=buf(1), c2=buf(2), c3=buf(3), c; + + m.set(c1+8, 264); + m.set(c0, 256); + m.set(order+8*(c4>>5&7)+64*(c1==c2)+128*(filetype==EXE), 256); + m.set(c2, 256); + m.set(c3, 256); + m.set(ismatch, 256); + + if(bpos) + { + c=c0<<(8-bpos); if(bpos==1)c+=c3/2; + c=(min(bpos,5))*256+c1/32+8*(c2/32)+(c&192); + } + else c=c3/128+(c4>>31)*2+4*(c2/64)+(c1&240); + m.set(c, 1536); + int pr=m.p(); + return pr; +} + + +//////////////////////////// Predictor ///////////////////////// + +// A Predictor estimates the probability that the next bit of +// uncompressed data is 1. Methods: +// p() returns P(1) as a 12 bit number (0-4095). +// update(y) trains the predictor with the actual bit (0 or 1). + +class Predictor { + int pr; // next prediction +public: + Predictor(); + int p() const {assert(pr>=0 && pr<4096); return pr;} + void update(); +}; + +Predictor::Predictor(): pr(2048) {} + +void Predictor::update() { + static APM1 a(256), a1(0x10000), a2(0x10000), a3(0x10000), + a4(0x10000), a5(0x10000), a6(0x10000); + + // Update global context: pos, bpos, c0, c4, buf + c0+=c0+y; + if (c0>=256) { + buf[pos++]=c0; + c4=(c4<<8)+c0-256; + c0=1; + } + bpos=(bpos+1)&7; + + // Filter the context model with APMs + int pr0=contextModel2(); + + pr=a.p(pr0, c0); + + int pr1=a1.p(pr0, c0+256*buf(1)); + int pr2=a2.p(pr0, c0^hash(buf(1), buf(2))&0xffff); + int pr3=a3.p(pr0, c0^hash(buf(1), buf(2), buf(3))&0xffff); + pr0=pr0+pr1+pr2+pr3+2>>2; + + pr1=a4.p(pr, c0+256*buf(1)); + pr2=a5.p(pr, c0^hash(buf(1), buf(2))&0xffff); + pr3=a6.p(pr, c0^hash(buf(1), buf(2), buf(3))&0xffff); + pr=pr+pr1+pr2+pr3+2>>2; + + pr=pr+pr0+1>>1; +} + +//////////////////////////// Encoder //////////////////////////// + +// An Encoder does arithmetic encoding. Methods: +// Encoder(COMPRESS, f) creates encoder for compression to archive f, which +// must be open past any header for writing in binary mode. +// Encoder(DECOMPRESS, f) creates encoder for decompression from archive f, +// which must be open past any header for reading in binary mode. +// code(i) in COMPRESS mode compresses bit i (0 or 1) to file f. +// code() in DECOMPRESS mode returns the next decompressed bit from file f. +// Global y is set to the last bit coded or decoded by code(). +// compress(c) in COMPRESS mode compresses one byte. +// decompress() in DECOMPRESS mode decompresses and returns one byte. +// flush() should be called exactly once after compression is done and +// before closing f. It does nothing in DECOMPRESS mode. +// size() returns current length of archive +// setFile(f) sets alternate source to FILE* f for decompress() in COMPRESS +// mode (for testing transforms). +// If level (global) is 0, then data is stored without arithmetic coding. + +typedef enum {COMPRESS, DECOMPRESS} Mode; +class Encoder { +private: + Predictor predictor; + const Mode mode; // Compress or decompress? + FILE* archive; // Compressed data file + U32 x1, x2; // Range, initially [0, 1), scaled by 2^32 + U32 x; // Decompress mode: last 4 input bytes of archive + FILE *alt; // decompress() source in COMPRESS mode + + // Compress bit y or return decompressed bit + int code(int i=0) { + int p=predictor.p(); + assert(p>=0 && p<4096); + p+=p<2048; + U32 xmid=x1 + (x2-x1>>12)*p + ((x2-x1&0xfff)*p>>12); + assert(xmid>=x1 && xmid>24, archive); + x1<<=8; + x2=(x2<<8)+255; + if (mode==DECOMPRESS) x=(x<<8)+(getc(archive)&255); // EOF is OK + } + return y; + } + +public: + Encoder(Mode m, FILE* f); + Mode getMode() const {return mode;} + long size() const {return ftell(archive);} // length of archive so far + void flush(); // call this when compression is finished + void setFile(FILE* f) {alt=f;} + + // Compress one byte + void compress(int c) { + assert(mode==COMPRESS); + if (level==0) + putc(c, archive); + else + for (int i=7; i>=0; --i) + code((c>>i)&1); + } + + // Decompress and return one byte + int decompress() { + if (mode==COMPRESS) { + assert(alt); + return getc(alt); + } + else if (level==0) + return getc(archive); + else { + int c=0; + for (int i=0; i<8; ++i) + c+=c+code(); + return c; + } + } +}; + +Encoder::Encoder(Mode m, FILE* f): + mode(m), archive(f), x1(0), x2(0xffffffff), x(0), alt(0) { + if (level>0 && mode==DECOMPRESS) { // x = first 4 bytes of archive + for (int i=0; i<4; ++i) + x=(x<<8)+(getc(archive)&255); + } + for (int i=0; i<1024; ++i) + dt[i]=16384/(i+i+3); + +} + +void Encoder::flush() { + if (mode==COMPRESS && level>0) + putc(x1>>24, archive); // Flush first unequal byte of range +} + +/////////////////////////// Filters ///////////////////////////////// +// +// Before compression, data is encoded in blocks with the following format: +// +// +// +// Type is 1 byte (type Filetype): DEFAULT=0, JPEG, EXE +// Size is 4 bytes in big-endian format. +// Encoded-data decodes to bytes. The encoded size might be +// different. Encoded data is designed to be more compressible. +// +// void encode(FILE* in, FILE* out, int n); +// +// Reads n bytes of in (open in "rb" mode) and encodes one or +// more blocks to temporary file out (open in "wb+" mode). +// The file pointer of in is advanced n bytes. The file pointer of +// out is positioned after the last byte written. +// +// en.setFile(FILE* out); +// int decode(Encoder& en); +// +// Decodes and returns one byte. Input is from en.decompress(), which +// reads from out if in COMPRESS mode. During compression, n calls +// to decode() must exactly match n bytes of in, or else it is compressed +// as type 0 without encoding. +// +// Filetype detect(FILE* in, int n, Filetype type); +// +// Reads n bytes of in, and detects when the type changes to +// something else. If it does, then the file pointer is repositioned +// to the start of the change and the new type is returned. If the type +// does not change, then it repositions the file pointer n bytes ahead +// and returns the old type. +// +// For each type X there are the following 2 functions: +// +// void encode_X(FILE* in, FILE* out, int n, ...); +// +// encodes n bytes from in to out. +// +// int decode_X(Encoder& en); +// +// decodes one byte from en and returns it. decode() and decode_X() +// maintain state information using static variables. +#define bswap(x) \ ++ ((((x) & 0xff000000) >> 24) | \ ++ (((x) & 0x00ff0000) >> 8) | \ ++ (((x) & 0x0000ff00) << 8) | \ ++ (((x) & 0x000000ff) << 24)) + +// Detect EXE or JPEG data +Filetype detect(FILE* in, int n, Filetype type) { + U32 buf1=0, buf0=0; // last 8 bytes + long start=ftell(in); + + // For EXE detection + Array abspos(256), // CALL/JMP abs. addr. low byte -> last offset + relpos(256); // CALL/JMP relative addr. low byte -> last offset + int e8e9count=0; // number of consecutive CALL/JMPs + int e8e9pos=0; // offset of first CALL or JMP instruction + int e8e9last=0; // offset of most recent CALL or JMP + // For BMP detection + int bmp=0,bmp0=0,bsize=0,imgbpp=0,bmpx=0,bmpy=0,bmpimgoff=0,imgcomp=-1; + // For PGM detection + int pgm=0,psize=0,pgmcomment=0,pgmw=0,pgmh=0,pgmsize=0,pgm_ptr=0,pgmc=0; + char pgm_buf[32]; + // For JPEG detection + int soi=0, sof=0, sos=0, app=0; // position where found + // For .RGB detection + int rgbi=0,rgbSTORAGE=-1,rgbBPC=0,rgbDIMENSION=0,rgbZSIZE=0,rgbXSIZE=0,rgbYSIZE=0,rgbsize=0; + for (int i=0; i>24; + buf0=buf0<<8|c; + + // Detect JPEG by code SOI APPx (FF D8 FF Ex) followed by + // SOF0 (FF C0 xx xx 08) and SOS (FF DA) within a reasonable distance. + // Detect end by any code other than RST0-RST7 (FF D9-D7) or + // a byte stuff (FF 00). + + if (!soi && i>=3 && (buf0&0xfffffff0)==0xffd8ffe0) soi=i, app=i+2; + if (soi) { + if (app==i && ((buf0&0xfff00000)==0xffe00000 || (buf0&0xffff0000)==0xfffe0000)) + app=i+(buf0&0xffff)+2; + if (appsoi && i-soi<0x10000 && i-sof<0x1000 + && (buf0&0xffff)==0xffda) { + sos=i; + if (type!=JPEG) return fseek(in, start+soi-3, SEEK_SET), JPEG; + } + } + if (type==JPEG && sos && i>sos && (buf0&0xff00)==0xff00 + && (buf0&0xff)!=0 && (buf0&0xf8)!=0xd0) + return DEFAULT; + + // Detect .bmp image + + if ((buf0&0xFFFF)==16973) bmp=i; //possible 'BM' + if (bmp){ + if ((i-bmp)==4) bsize=bswap(buf0); //image size + if ((i-bmp)==12) bmpimgoff=bswap(buf0); + if ((i-bmp)==16 && buf0!=0x28000000) bmp=imgbpp=bsize=0,imgcomp=-1; //if windows bmp + if ((i-bmp)==20){ + bmpx=bswap(buf0); //image x size + if (bmpx==0) bmp=imgbpp=bsize=0,imgcomp=-1; // Test big size? + } + if ((i-bmp)==24){ + bmpy=bswap(buf0); //image y size + if (bmpy==0) bmp=imgbpp=bsize=0,imgcomp=-1; + } + if ((i-bmp)==27) imgbpp=c; //image bpp + if ((i-bmp)==31){ + imgcomp=buf0; //image compression 0=none, 1=RLE-8, 2=RLE-4 + if (imgcomp!=0) bmp=imgbpp=bsize=0,imgcomp=-1;} + if ((type==BMPFILE4 || type==BMPFILE8 || type==BMPFILE24 ) && (imgbpp==4 || imgbpp==8 || imgbpp==24) && imgcomp==0){ + int tbsize=0; + if (imgbpp==4) + if (bsize !=(tbsize=((bmpx*bmpy>>1)+bmpimgoff))) bsize=tbsize; + if (imgbpp==8) + if (bsize !=(tbsize=(bmpx*bmpy+bmpimgoff))) bsize=tbsize; + if (imgbpp==24) + if (bsize !=(tbsize=(bmpx*bmpy*3+bmpimgoff))) bsize=tbsize; + return fseek(in, start+bsize, SEEK_SET),DEFAULT; + } + if (imgbpp==4 && imgcomp==0){ + return fseek(in, start+bmp-1, SEEK_SET),BMPFILE4; + } + if (imgbpp==8 && imgcomp==0){ + return fseek(in, start+bmp-1, SEEK_SET),BMPFILE8; + } + if (imgbpp==24 && imgcomp==0){ + return fseek(in, start+bmp-1, SEEK_SET),BMPFILE24; + } + } + // Detect .pgm image + if ((buf0&0xFFFFFF)==0x50350A) pgm=i; //possible 'P5 ' + if (pgm){ + if ((i-pgm)==1 && c==0x23) pgmcomment=1; //pgm comment + //not tested without comment + if (!pgmcomment && c==0x20 && !pgmw && pgm_ptr) { + pgm_buf[pgm_ptr++]=0; + pgmw=atoi(pgm_buf); + if (pgmw==0) pgm=pgm_ptr=pgmw=pgmh=pgmc=pgmcomment=0; + pgm_ptr=0; + } + if (!pgmcomment && c==0x0a && !pgmh && pgm_ptr){ + pgm_buf[pgm_ptr++]=0; + pgmh=atoi(pgm_buf); + if (pgmh==0) pgm=pgm_ptr=pgmw=pgmh=pgmc=pgmcomment=0; + pgm_ptr=0; + } + if (!pgmcomment && c==0x0a && !pgmc && pgm_ptr){ + pgm_buf[pgm_ptr++]=0; + pgmc=atoi(pgm_buf); + pgm_ptr=0; + } + if (!pgmcomment) pgm_buf[pgm_ptr++]=c; + if (pgm_ptr>=32) pgm=pgm_ptr=pgmw=pgmh=pgmc=pgmcomment=0; + if (pgmcomment && c==0x0a) pgmcomment=0; + if (type==PGMFILE && pgmw && pgmh && pgmc){ + pgmsize=pgmw *pgmh +pgm+i-1; + return fseek(in, start+pgmsize, SEEK_SET),DEFAULT; + } + if (pgmw && pgmh && pgmc){ + return fseek(in, start+pgm-2, SEEK_SET),PGMFILE; + } + } + // Detect .rgb image + if ((buf0&0xFFFF)==0x01DA) rgbi=i; + if (rgbi){ + if ((i-rgbi)==1) + if (c==0 || c==1) + rgbSTORAGE=c; //0 uncompressed, 1 RLE compressed + else + rgbi=rgbBPC=rgbDIMENSION=rgbZSIZE=rgbXSIZE=rgbYSIZE=0,rgbSTORAGE=-1; + if ((i-rgbi)==2) + if (c==1 || c==2) + rgbBPC=c; + else + rgbi=rgbBPC=rgbDIMENSION=rgbZSIZE=rgbXSIZE=rgbYSIZE=0,rgbSTORAGE=-1; + if ((i-rgbi)==4) + if ((buf0&0xFFFF)==1 || (buf0&0xFFFF)==2 || (buf0&0xFFFF)==3) + rgbDIMENSION=buf0&0xFFFF; + else + rgbi=rgbBPC=rgbDIMENSION=rgbZSIZE=rgbXSIZE=rgbYSIZE=0,rgbSTORAGE=-1; + if ((i-rgbi)==6) + if ((buf0&0xFFFF)>0) + rgbXSIZE=buf0&0xFFFF; + else + rgbi=rgbBPC=rgbDIMENSION=rgbZSIZE=rgbXSIZE=rgbYSIZE=0,rgbSTORAGE=-1; + if ((i-rgbi)==8) + if ((buf0&0xFFFF)>0) + rgbYSIZE=buf0&0xFFFF,rgbsize=rgbYSIZE*rgbXSIZE+512; + else + rgbi=rgbBPC=rgbDIMENSION=rgbZSIZE=rgbXSIZE=rgbYSIZE=0,rgbSTORAGE=-1; + if ((i-rgbi)==10) + if ((buf0&0xFFFF)==1 || (buf0&0xFFFF)==3 || (buf0&0xFFFF)==4) // 1 indicates greyscale + // 3 indicates RGB + // 4 indicates RGB and Alpha + rgbZSIZE=buf0&0xFFFF; + else + rgbi=rgbBPC=rgbDIMENSION=rgbZSIZE=rgbXSIZE=rgbYSIZE=0,rgbSTORAGE=-1; + if (rgbsize != 0 && (i-rgbi)>0 && ((i-rgbi)>rgbsize)){ + if (type==RGBFILE && rgbZSIZE==1 && rgbSTORAGE==0 ){ //uncompressed greyscale + return fseek(in, start+rgbsize, SEEK_SET),DEFAULT; + } + if (rgbZSIZE==1 && rgbSTORAGE==0){ + return fseek(in, start+rgbi-1, SEEK_SET),RGBFILE; + } + } + } + //TIFF support needed + // Detect .tiff file + + + // Detect EXE if the low order byte (little-endian) XX is more + // recently seen (and within 4K) if a relative to absolute address + // conversion is done in the context CALL/JMP (E8/E9) XX xx xx 00/FF + // 4 times in a row. Detect end of EXE at the last + // place this happens when it does not happen for 64KB. + + if ((buf1&0xfe)==0xe8 && (buf0+1&0xfe)==0) { + int r=buf0>>24; // relative address low 8 bits + int a=(buf0>>24)+i&0xff; // absolute address low 8 bits + int rdist=i-relpos[r]; + int adist=i-abspos[a]; + if (adist5) { + e8e9last=i; + ++e8e9count; + if (e8e9pos==0 || e8e9pos>abspos[a]) e8e9pos=abspos[a]; + } + else e8e9count=0; + if (type!=EXE && e8e9count>=4 && e8e9pos>5) + return fseek(in, start+e8e9pos-5, SEEK_SET), EXE; + abspos[a]=i; + relpos[r]=i; + } + if (type==EXE && i-e8e9last>0x1000) + return fseek(in, start+e8e9last, SEEK_SET), DEFAULT; + } + return type; +} + +// Default encoding as self +void encode_default(FILE* in, FILE* out, int len) { + while (len--) putc(getc(in), out); +} + +int decode_default(Encoder& en) { + return en.decompress(); +} + +// JPEG encode as self. The purpose is to shield jpegs from exe transform. +void encode_jpeg(FILE* in, FILE* out, int len) { + while (len--) putc(getc(in), out); +} + +int decode_jpeg(Encoder& en) { + return en.decompress(); +} +// BMP encode as self. +void encode_bmp(FILE* in, FILE* out, int len) { + while (len--) putc(getc(in), out); +} + +int decode_bmp(Encoder& en) { + return en.decompress(); +} + +// PGM encode as self. +void encode_pgm(FILE* in, FILE* out, int len) { + while (len--) putc(getc(in), out); +} + +int decode_pgm(Encoder& en) { + return en.decompress(); +} + +// RGB encode as self. +void encode_rgb(FILE* in, FILE* out, int len) { + while (len--) putc(getc(in), out); +} + +int decode_rgb(Encoder& en) { + return en.decompress(); +} + +// EXE transform: ... +// Encoded-size is 4 bytes, MSB first. +// begin is the offset of the start of the input file, 4 bytes, MSB first. +// Each block applies the e8e9 transform to strings falling entirely +// within the block starting from the end and working backwards. +// The 5 byte pattern is E8/E9 xx xx xx 00/FF (x86 CALL/JMP xxxxxxxx) +// where xxxxxxxx is a relative address LSB first. The address is +// converted to an absolute address by adding the offset mod 2^25 +// (in range +-2^24). + +void encode_exe(FILE* in, FILE* out, int len, int begin) { + const int BLOCK=0x10000; + Array blk(BLOCK); + fprintf(out, "%c%c%c%c", len>>24, len>>16, len>>8, len); // size, MSB first + fprintf(out, "%c%c%c%c", begin>>24, begin>>16, begin>>8, begin); + + // Transform + for (int offset=0; offset=4; --i) { + if ((blk[i-4]==0xe8||blk[i-4]==0xe9) && (blk[i]==0||blk[i]==0xff)) { + int a=(blk[i-3]|blk[i-2]<<8|blk[i-1]<<16|blk[i]<<24)+offset+begin+i+1; + a<<=7; + a>>=7; + blk[i]=a>>24; + blk[i-1]=a>>16; + blk[i-2]=a>>8; + blk[i-3]=a; + } + } + fwrite(&blk[0], 1, bytesRead, out); + } +} + +int decode_exe(Encoder& en) { + const int BLOCK=0x10000; // block size + static int offset=0, q=0; // decode state: file offset, queue size + static int size=0; // where to stop coding + static int begin=0; // offset in file + static U8 c[5]; // queue of last 5 bytes, c[0] at front + + // Read size from first 4 bytes, MSB first + while (offset==size && q==0) { + offset=0; + size=en.decompress()<<24; + size|=en.decompress()<<16; + size|=en.decompress()<<8; + size|=en.decompress(); + begin=en.decompress()<<24; + begin|=en.decompress()<<16; + begin|=en.decompress()<<8; + begin|=en.decompress(); + } + + // Fill queue + while (offset subtract location from x + if (q==5 && (c[4]==0xe8||c[4]==0xe9) && (c[0]==0||c[0]==0xff) + && ((offset-1^offset-5)&-BLOCK)==0) { // not crossing block boundary + int a=(c[3]|c[2]<<8|c[1]<<16|c[0]<<24)-offset-begin; + a<<=7; + a>>=7; + c[3]=a; + c[2]=a>>8; + c[1]=a>>16; + c[0]=a>>24; + } + + // return oldest byte in queue + assert(q>0 && q<=5); + return c[--q]; +} + + + +// Split n bytes into blocks by type. For each block, output +// and call encode_X to convert to type X. +void encode(FILE* in, FILE* out, int n) { + Filetype type=DEFAULT; + long begin=ftell(in); + while (n>0) { + Filetype nextType=detect(in, n, type); + long end=ftell(in); + fseek(in, begin, SEEK_SET); + int len=int(end-begin); + if (len>0) { + fprintf(out, "%c%c%c%c%c", type, len>>24, len>>16, len>>8, len); + switch(type) { + case JPEG: encode_jpeg(in, out, len); break; + case BMPFILE4: + case BMPFILE8: + case BMPFILE24: + encode_bmp(in, out, len); break; + case PGMFILE: encode_pgm(in, out, len); break; + case RGBFILE: encode_rgb(in, out, len); break; + case EXE: encode_exe(in, out, len, begin); break; + default: encode_default(in, out, len); break; + } + } + n-=len; + type=nextType; + begin=end; + } +} + +// Decode ... +int decode(Encoder& en) { + static Filetype type=DEFAULT; + static int len=0; + while (len==0) { + type=(Filetype)en.decompress(); + len=en.decompress()<<24; + len|=en.decompress()<<16; + len|=en.decompress()<<8; + len|=en.decompress(); + if (len<0) len=1; + } + --len; + switch (type) { + case JPEG: return decode_jpeg(en); + case BMPFILE4: + case BMPFILE8: + case BMPFILE24: + return decode_bmp(en); + case PGMFILE: return decode_pgm(en); + case RGBFILE: return decode_rgb(en); + case EXE: return decode_exe(en); + default: return decode_default(en); + } +} + +//////////////////// Compress, Decompress //////////////////////////// + +// Print progress: n is the number of bytes compressed or decompressed +void printStatus(int n) { + if (n>0 && !(n&0x0fff)) + printf("%12d\b\b\b\b\b\b\b\b\b\b\b\b", n), fflush(stdout); +} + +// Compress a file +void compress(const char* filename, long filesize, Encoder& en) { + assert(en.getMode()==COMPRESS); + assert(filename && filename[0]); + FILE *f=fopen(filename, "rb"); + if (!f) perror(filename), quit(); + long start=en.size(); + printf("%s %ld -> ", filename, filesize); + + // Transform and test in blocks + const int BLOCK=MEM*64; + for (int i=0; filesize>0; i+=BLOCK) { + int size=BLOCK; + if (size>filesize) size=filesize; + FILE* tmp=tmpfile(); + if (!tmp) perror("tmpfile"), quit(); + long savepos=ftell(f); + encode(f, tmp, size); + + // Test transform + rewind(tmp); + en.setFile(tmp); + fseek(f, savepos, SEEK_SET); + long j; + int c1=0, c2=0; + for (j=0; j>24); + en.compress(size>>16); + en.compress(size>>8); + en.compress(size); + fseek(f, savepos, SEEK_SET); + for (int j=0; j ", filename, filesize); + bool found=false; // mismatch? + for (int i=0; i ", filename, filesize); + for (int i=0; i ", filename, filesize); + for (int i=0; i=s.size()) s.resize(len*2+1); + if (c!='\r') s[len++]=c; + } + if (len>=s.size()) s.resize(len+1); + s[len]=0; + if (c==EOF || c==26) + return 0; + else + return s.c_str(); +} + +// int expand(String& archive, String& s, const char* fname, int base) { +// Given file name fname, print its length and base name (beginning +// at fname+base) to archive in format "%ld\t%s\r\n" and append the +// full name (including path) to String s in format "%s\n". If fname +// is a directory then substitute all of its regular files and recursively +// expand any subdirectories. Base initially points to the first +// character after the last / in fname, but in subdirectories includes +// the path from the topmost directory. Return the number of files +// whose names are appended to s and archive. + +// Same as expand() except fname is an ordinary file +int putsize(String& archive, String& s, const char* fname, int base) { + int result=0; + FILE *f=fopen(fname, "rb"); + if (f) { + fseek(f, 0, SEEK_END); + long len=ftell(f); + if (len>=0) { + static char blk[24]; + sprintf(blk, "%ld\t", len); + archive+=blk; + archive+=(fname+base); + archive+="\r\n"; + s+=fname; + s+="\n"; + ++result; + } + fclose(f); + } + return result; +} + +#ifdef WINDOWS + +int expand(String& archive, String& s, const char* fname, int base) { + int result=0; + DWORD attr=GetFileAttributes(fname); + if ((attr != 0xFFFFFFFF) && (attr & FILE_ATTRIBUTE_DIRECTORY)) { + WIN32_FIND_DATA ffd; + String fdir(fname); + fdir+="/*"; + HANDLE h=FindFirstFile(fdir.c_str(), &ffd); + while (h!=INVALID_HANDLE_VALUE) { + if (!equals(ffd.cFileName, ".") && !equals(ffd.cFileName, "..")) { + String d(fname); + d+="/"; + d+=ffd.cFileName; + result+=expand(archive, s, d.c_str(), base); + } + if (FindNextFile(h, &ffd)!=TRUE) break; + } + FindClose(h); + } + else // ordinary file + result=putsize(archive, s, fname, base); + return result; +} + +#else +#ifdef UNIX + +int expand(String& archive, String& s, const char* fname, int base) { + int result=0; + struct stat sb; + if (stat(fname, &sb)<0) return 0; + + // If a regular file and readable, get file size + if (sb.st_mode & S_IFREG && sb.st_mode & 0400) + result+=putsize(archive, s, fname, base); + + // If a directory with read and execute permission, traverse it + else if (sb.st_mode & S_IFDIR && sb.st_mode & 0400 && sb.st_mode & 0100) { + DIR *dirp=opendir(fname); + if (!dirp) { + perror("opendir"); + return result; + } + dirent *dp; + while(errno=0, (dp=readdir(dirp))!=0) { + if (!equals(dp->d_name, ".") && !equals(dp->d_name, "..")) { + String d(fname); + d+="/"; + d+=dp->d_name; + result+=expand(archive, s, d.c_str(), base); + } + } + if (errno) perror("readdir"); + closedir(dirp); + } + else printf("%s is not a readable file or directory\n", fname); + return result; +} + +#else // Not WINDOWS or UNIX, ignore directories + +int expand(String& archive, String& s, const char* fname, int base) { + return putsize(archive, s, fname, base); +} + +#endif +#endif + + +// To compress to file1.paq8p: paq8p [-n] file1 [file2...] +// To decompress: paq8p file1.paq8p [output_dir] +int paqmain(int argc, char** argv) { + bool pause=argc<=2; // Pause when done? + try { + + // Get option + bool doExtract=false; // -d option + if (argc>1 && argv[1][0]=='-' && argv[1][1] && !argv[1][2]) { + if (argv[1][1]>='0' && argv[1][1]<='9') + level=argv[1][1]-'0'; + else if (argv[1][1]=='d') + doExtract=true; + else + quit("Valid options are -0 through -9 or -d\n"); + --argc; + ++argv; + pause=false; + } + + // Print help message + if (argc<2) { + printf(PROGNAME " archiver (C) 2008, Matt Mahoney et al.\n" + "Free under GPL, http://www.gnu.org/licenses/gpl.txt\n\n" +#ifdef WINDOWS + "To compress or extract, drop a file or folder on the " + PROGNAME " icon.\n" + "The output will be put in the same folder as the input.\n" + "\n" + "Or from a command window: " +#endif + "To compress:\n" + " " PROGNAME " -level file (compresses to file." PROGNAME ")\n" + " " PROGNAME " -level archive files... (creates archive." PROGNAME ")\n" + " " PROGNAME " file (level -%d, pause when done)\n" + "level: -0 = store, -1 -2 -3 = faster (uses 35, 48, 59 MB)\n" + "-4 -5 -6 -7 -8 = smaller (uses 133, 233, 435, 837, 1643 MB)\n" +#if defined(WINDOWS) || defined (UNIX) + "You may also compress directories.\n" +#endif + "\n" + "To extract or compare:\n" + " " PROGNAME " -d dir1/archive." PROGNAME " (extract to dir1)\n" + " " PROGNAME " -d dir1/archive." PROGNAME " dir2 (extract to dir2)\n" + " " PROGNAME " archive." PROGNAME " (extract, pause when done)\n" + "\n" + "To view contents: more < archive." PROGNAME "\n" + "\n", + DEFAULT_OPTION); + quit(); + } + + FILE* archive=0; // compressed file + int files=0; // number of files to compress/decompress + Array fname(1); // file names (resized to files) + Array fsize(1); // file lengths (resized to files) + + // Compress or decompress? Get archive name + Mode mode=COMPRESS; + String archiveName(argv[1]); + { + const int prognamesize=strlen(PROGNAME); + const int arg1size=strlen(argv[1]); + if (arg1size>prognamesize+1 && argv[1][arg1size-prognamesize-1]=='.' + && equals(PROGNAME, argv[1]+arg1size-prognamesize)) { + mode=DECOMPRESS; + } + else if (doExtract) + mode=DECOMPRESS; + else { + archiveName+="."; + archiveName+=PROGNAME; + } + } + + // Compress: write archive header, get file names and sizes + String filenames; + if (mode==COMPRESS) { + + // Expand filenames to read later. Write their base names and sizes + // to archive. + String header_string; + int i; + for ( i=1; i0 && name[len-1]=='/') // remove trailing / + name[--len]=0; + int base=len-1; + while (base>=0 && name[base]!='/') --base; // find last / + ++base; + if (base==0 && len>=2 && name[1]==':') base=2; // chop "C:" + int expanded=expand(header_string, filenames, name.c_str(), base); + if (!expanded && (i>1||argc==2)) + printf("%s: not found, skipping...\n", name.c_str()); + files+=expanded; + } + + // If archive doesn't exist and there is at least one file to compress + // then create the archive header. + if (files<1) quit("Nothing to compress\n"); +// archive=fopen(archiveName.c_str(), "rb"); +// if (archive) +// printf("%s already exists\n", archiveName.c_str()), quit(); + archive=fopen(archiveName.c_str(), "wb+"); + if (!archive) perror(archiveName.c_str()), quit(); + fprintf(archive, PROGNAME " -%d\r\n%s\x1A", + level, header_string.c_str()); + printf("Creating archive %s with %d file(s)...\n", + archiveName.c_str(), files); + + // Fill fname[files], fsize[files] with input filenames and sizes + fname.resize(files); + fsize.resize(files); + char *p=&filenames[0]; + rewind(archive); + getline(archive); + for ( i=0; i=0); + fname[i]=p; + while (*p!='\n') ++p; + assert(p-filenames.c_str()9) level=DEFAULT_OPTION; + + // Fill fname[files], fsize[files] with output file names and sizes + while (getline(archive)) ++files; // count files + printf("Extracting %d file(s) from %s -%d\n", files, + archiveName.c_str(), level); + long header_size=ftell(archive); + filenames.resize(header_size+4); // copy of header + rewind(archive); + fread(&filenames[0], 1, header_size, archive); + fname.resize(files); + fsize.resize(files); + char* p=&filenames[0]; + while (*p && *p!='\r') ++p; // skip first line + ++p; + for (int i=0; i=0 && level<=9); + buf.setsize(MEM*8); + + // Compress or decompress files + assert(fname.size()==files); + assert(fsize.size()==files); + long total_size=0; // sum of file sizes + for (int i=0; i %ld\n", total_size, en.size()); + } + + // Decompress files to dir2: paq8p -d dir1/archive.paq8p dir2 + // If there is no dir2, then extract to dir1 + // If there is no dir1, then extract to . + else { + assert(argc>=2); + String dir(argc>2?argv[2]:argv[1]); + if (argc==2) { // chop "/archive.paq8p" + int i; + for (i=dir.size()-2; i>=0; --i) { + if (dir[i]=='/' || dir[i]=='\\') { + dir[i]=0; + break; + } + if (i==1 && dir[i]==':') { // leave "C:" + dir[i+1]=0; + break; + } + } + if (i==-1) dir="."; // "/" not found + } + dir=dir.c_str(); + if (dir[0] && (dir.size()!=3 || dir[1]!=':')) dir+="/"; + for (int i=0; i. + +See http://cs.fit.edu/~mmahoney/compression/ for the latest PAQ version. + +Contents: + + readme.txt - This file. + paq8p.exe - Win32 executable (Intel compile for Pentium-MMX or higher) + paq8p.cpp - C++ source code. + paq7asm.asm - NASM source code for 32 bit x86 (Pentium-MMX or higher). + paq7asm-x86_64.asm - YASM source code for x86-64. + paq7asmsse.asm - NASM/YASM for Pentium 4 (SSE2) or higher in 32 bit mode. + +Added Jan. 9, 2009: + + paq7asmsse2.asm - above, but optimized by Dark Shikari. + paq8p_sse2.exe - 32 bit Windows g++ compile with above for Pentium 4+. + +paq8p +added wav Model +minor improvements to bmp Model + +See paq8p.cpp source comments for usage and compiling instructions. From edwintorok at gmail.com Thu Feb 19 06:38:03 2009 From: edwintorok at gmail.com (Torok Edwin) Date: Thu, 19 Feb 2009 12:38:03 -0000 Subject: [llvm-commits] [test-suite] r65043 [1/2] - in /test-suite/trunk/MultiSource/Benchmarks: ./ mafft/ Message-ID: <200902191238.n1JCc6Da014432@zion.cs.uiuc.edu> Author: edwin Date: Thu Feb 19 06:37:59 2009 New Revision: 65043 URL: http://llvm.org/viewvc/llvm-project?rev=65043&view=rev Log: Add mafft to testsuite (PR3533). Also enable PAQ8p and mafft in Makefile. Added: test-suite/trunk/MultiSource/Benchmarks/mafft/ test-suite/trunk/MultiSource/Benchmarks/mafft/Calignm1.c test-suite/trunk/MultiSource/Benchmarks/mafft/DNA.h test-suite/trunk/MultiSource/Benchmarks/mafft/Falign.c test-suite/trunk/MultiSource/Benchmarks/mafft/Galign11.c test-suite/trunk/MultiSource/Benchmarks/mafft/Halignmm.c test-suite/trunk/MultiSource/Benchmarks/mafft/JTT.c test-suite/trunk/MultiSource/Benchmarks/mafft/Lalign11.c test-suite/trunk/MultiSource/Benchmarks/mafft/Lalignmm.c test-suite/trunk/MultiSource/Benchmarks/mafft/MSalign11.c test-suite/trunk/MultiSource/Benchmarks/mafft/MSalignmm.c test-suite/trunk/MultiSource/Benchmarks/mafft/Makefile test-suite/trunk/MultiSource/Benchmarks/mafft/Qalignmm.c test-suite/trunk/MultiSource/Benchmarks/mafft/Ralignmm.c test-suite/trunk/MultiSource/Benchmarks/mafft/SAalignmm.c test-suite/trunk/MultiSource/Benchmarks/mafft/Salignmm.c test-suite/trunk/MultiSource/Benchmarks/mafft/blosum.c test-suite/trunk/MultiSource/Benchmarks/mafft/blosum.h test-suite/trunk/MultiSource/Benchmarks/mafft/constants.c test-suite/trunk/MultiSource/Benchmarks/mafft/defs.c test-suite/trunk/MultiSource/Benchmarks/mafft/dp.h test-suite/trunk/MultiSource/Benchmarks/mafft/fft.c test-suite/trunk/MultiSource/Benchmarks/mafft/fft.h test-suite/trunk/MultiSource/Benchmarks/mafft/fftFunctions.c test-suite/trunk/MultiSource/Benchmarks/mafft/functions.h test-suite/trunk/MultiSource/Benchmarks/mafft/genGalign11.c test-suite/trunk/MultiSource/Benchmarks/mafft/genalign11.c test-suite/trunk/MultiSource/Benchmarks/mafft/io.c test-suite/trunk/MultiSource/Benchmarks/mafft/license test-suite/trunk/MultiSource/Benchmarks/mafft/miyata.h test-suite/trunk/MultiSource/Benchmarks/mafft/miyata5.h test-suite/trunk/MultiSource/Benchmarks/mafft/mltaln.h test-suite/trunk/MultiSource/Benchmarks/mafft/mltaln9.c test-suite/trunk/MultiSource/Benchmarks/mafft/mtxutl.c test-suite/trunk/MultiSource/Benchmarks/mafft/mtxutl.h test-suite/trunk/MultiSource/Benchmarks/mafft/pairlocalalign.c test-suite/trunk/MultiSource/Benchmarks/mafft/partQalignmm.c test-suite/trunk/MultiSource/Benchmarks/mafft/partSalignmm.c test-suite/trunk/MultiSource/Benchmarks/mafft/pyruvate_decarboxylase.fasta test-suite/trunk/MultiSource/Benchmarks/mafft/readme test-suite/trunk/MultiSource/Benchmarks/mafft/rna.c test-suite/trunk/MultiSource/Benchmarks/mafft/share.h test-suite/trunk/MultiSource/Benchmarks/mafft/suboptalign11.c test-suite/trunk/MultiSource/Benchmarks/mafft/tddis.c Modified: test-suite/trunk/MultiSource/Benchmarks/Makefile Modified: test-suite/trunk/MultiSource/Benchmarks/Makefile URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/Makefile?rev=65043&r1=65042&r2=65043&view=diff ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/Makefile (original) +++ test-suite/trunk/MultiSource/Benchmarks/Makefile Thu Feb 19 06:37:59 2009 @@ -5,6 +5,6 @@ McCat Olden OptimizerEval Ptrdist llubenchmark \ sim FreeBench MallocBench Prolangs-C Prolangs-C++ SciMark2-C\ mediabench ASCI_Purple MiBench Trimaran VersaBench tramp3d-v4 NPB-serial\ - BitBench ASC_Sequoia + BitBench ASC_Sequoia PAQ8p mafft include $(LEVEL)/Makefile.programs Added: test-suite/trunk/MultiSource/Benchmarks/mafft/Calignm1.c URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/Calignm1.c?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/Calignm1.c (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/Calignm1.c Thu Feb 19 06:37:59 2009 @@ -0,0 +1,598 @@ +#include "mltaln.h" +#include "dp.h" + +#define DEBUG 0 + +void tracking( char **nseq, char **aseq, char *seq, int **ijp, int icyc ) +{ + int i, k, l; + int iin, ifi, jin, jfi; + int lgth = strlen( aseq[0] ); + int lgth1 = strlen( seq ); + char gap[] = "-"; + + for( i=0; i<=icyc+1; i++ ) + { + nseq[i] += lgth+lgth1; + *nseq[i] = 0; + } + + iin = lgth; jin = lgth1; + for( k=0; k<=lgth+lgth1; ) + { + if( ijp[iin][jin] < 0 ) + { + ifi = iin-1; jfi = jin+ijp[iin][jin]; + } + else if( ijp[iin][jin] > 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + /* + if( ifi < 0 ) jfi = -1; + if( jfi < 0 ) ifi = -1; + */ + } + for( l=1; l 0 && orlgth1 > 0 ) for( i=0; i orlgth || lgth1 > orlgth1 ) + { + int ll1, ll2; + + if( orlgth > 0 && orlgth1 > 0 ) + { + FreeFloatMtx( v ); + + FreeFloatCub( g ); + FreeFloatTri( gl ); + FreeFloatTri( gs ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + +#if 0 + FreeCharMtx( nseq ); +#endif + FreeCharMtx( mseq ); + + FreeFloatVec( gvsa ); + FreeFloatMtx( scmx ); + } + + ll1 = MAX( (int)(1.1*lgth), orlgth ); + ll2 = MAX( (int)(1.1*lgth1), orlgth1 ); + ll1 = MAX( ll1, ll2 ); + +#if DEBUG + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + + v = AllocateFloatMtx( ll1+2, ll2+2 ); + + g = AllocateFloatCub( ll1+2, 3, 3 ); + + gl = AllocateFloatTri( MAX( ll1, ll2 ) + 3 ); + gs = AllocateFloatTri( MAX( ll1, ll2 ) + 3 ); + + m = AllocateFloatVec( ll1+2 ); + mp = AllocateIntVec( ll1+2 ); + + mseq = AllocateCharMtx( njob+1, 1 ); + nseq = AllocateCharMtx( njob+1, ll1+ll2 ); + for( i=0; i commonAlloc1 || orlgth1 > commonAlloc2 ) + { + int ll1, ll2; + + if( commonAlloc1 && commonAlloc2 ) + { + FreeIntMtx( commonIP ); + } + + ll1 = MAX( commonAlloc1, orlgth ); + ll2 = MAX( commonAlloc2, orlgth1 ); + +#if DEBUG + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + + commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + +#if DEBUG + fprintf( stderr, "succeeded\n\n" ); +#endif + + commonAlloc1 = ll1; + commonAlloc2 = ll2; + } + + ijp = commonIP; + + scmx_calc( icyc, aseq, effarr, scmx ); + + for( i=0; i0; j-- ) + gl[i][j] += gl[i][j+1]; + } + +/* + for( i=0; i 1 ) + { + x = w[i-1][j-2] + g[i-0][0][2] + n_dis[24][0] * totaleff; + mi += g[i-1][2][2] + n_dis[24][0] * totaleff; + if( mi < x ) + { + mi = x; + mpi = j-2; + } + } + else + { + mi = w[i-1][0] + g[i-0][0][2]/* + n_dis[24][0] * totaleff */; /* 0.0? */ + /* + fprintf( stderr, " i == %d j == 1, w[i][0] == %f, mi == %f, g[i][0][2] == %f\n", i, w[i][0], mi, g[i][0][2] ); + */ + /* + mi = 0.0 + g[i-0][0][2]; * 0.0? * + */ + mpi = 0; + } + + if( i > 1 ) + { + x = w[i-2][j-1] + g[i-1][0][1] + gvsa[i-1]; + m[j] += g[i-1][1][1] + gl[i-2][i-mp[j]-2] + gvsa[i-1]; /* ??? */ + if( m[j] < x ) + { + m[j] = x; + mp[j] = i-2; + } + + } + else + { + m[j] = w[0][j-1]+ g[i][0][1]/* + gvsa[1] */; /* 0.0? */ + mp[j] = 0; + } + + wmax = w[i-1][j-1] + g[i][0][0]; + /* + ip[i][j]=i-1; + jp[i][j]=j-1; + */ + ijp[i][j] = 0; + + x = mi + g[i][2][0]; + if( x > wmax ) + { + wmax = x; + /* + ip[i][j] = i-1; + jp[i][j] = mpi; + */ + ijp[i][j] = -( j - mpi ); /* ijp[][] < 0 -> j ni gap */ + } + + x = m[j] + g[i][1][0] + gs[i][i-mp[j]]; + if( x > wmax ) + { + wmax = x; + /* + ip[i][j] = mp[j]; + jp[i][j] = j-1; + */ + ijp[i][j] = +( i - mp[j] ); + } + w[i][j] += wmax; + } + } + if( cnst ) + { + w[lgth][lgth1] = w[lgth-1][lgth1-1] + g[lgth][0][0]; + /* + ip[lgth][lgth1] = lgth-1; + jp[lgth][lgth1] = lgth1-1; + */ + ijp[lgth][lgth1] = 0; + } + + *wm = w[lgth][lgth1]; + + for( i=0; i 0 ) + { + gb1 = ( seq[i][k-1] == '-' ); + gb2 = ( seq[ex][k-1] == '-' ); + } + else + { + gb1 = 0; + gb2 = 0; + } + + if( gb1 ) glen1[i]++; else glen1[i] = 0; + if( gb2 ) glen2[i]++; else glen2[i] = 0; + + gc1 = ( seq[i][k] == '-' ); + gc2 = ( seq[ex][k] == '-' ); + + if( glen1[i] >= glen2[i] ) tmp1 = 1; else tmp1 = 0; + if( glen1[i] <= glen2[i] ) tmp2 = 1; else tmp2 = 0; + cob = + !gb1 * gc1 + * !gb2 * !gc2 + + + !gb1 * !gc1 + * !gb2 * gc2 + + + !gb1 * gc1 + * gb2 * !gc2 + + + gb1 * !gc1 + * !gb2 * gc2 + + + gb1 * !gc1 + * gb2 * gc2 * tmp1 + + + gb1 * gc1 + * gb2 * !gc2 * tmp2 + ; + + pen += (double)cob * penalty * efficient; + tmpscore += (double)amino_dis[(int)seq[i][k]][(int)seq[ex][k]] * efficient; + /* + nglen += ( !gc1 * !gc2 ); + */ + /* + if( k == 0 ) + { + printf( "%c<->%c * %f = %f\n", seq[ex][k], seq[i][k], efficient, amino_dis[seq[i][k]][seq[ex][k]] * efficient ); + } + */ + } + score += tmpscore; + score += pen; + /* + if( 1 ) fprintf( stdout, "%c %f ", seq[ex][k], score / (locnjob-1) ); + if( 1 ) fprintf( stdout, "penalty %f\n", (double)pen / (locnjob - 1 ) ); + */ + } + /* + fprintf( stdout, "in Cscore_m_1 %f\n", score ); + */ + /* + fprintf( stdout, "%s\n", seq[ex] ); + */ + free( glen1 ); + free( glen2 ); + return( (double)score /*/ nglen + 400.0*/ ); +} + Added: test-suite/trunk/MultiSource/Benchmarks/mafft/DNA.h URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/DNA.h?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/DNA.h (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/DNA.h Thu Feb 19 06:37:59 2009 @@ -0,0 +1,210 @@ +#define DEFAULTGOP_N -1530 +#define DEFAULTGEP_N 0 +#define DEFAULTOFS_N -123 +#define DEFAULTPAMN 200 + +#define DEFAULTRNAGOP_N -1530 +#define DEFAULTRNAGEP_N 0 +#define DEFAULTRNATHR_N 0 + +// -h 0.11150 -> all positive + +double ribosum4[4][4] = +{ +// a g c t +{ 2.22, -1.46, -1.86, -1.39, }, // a +{ -1.46, 1.03, -2.48, -1.74, }, // g +{ -1.86, -2.48, 1.16, -1.05, }, // c +{ -1.39, -1.74, -1.05, 1.65, }, // t +}; + +double ribosum16[16][16] = +{ +// aa ag ac at ga gg gc gt ca cg cc ct ta tg tc tt +{ -2.49, -8.24, -7.04, -4.32, -6.86, -8.39, -5.03, -5.84, -8.84, -4.68, -14.37, -12.64, -4.01, -6.16, -11.32, -9.05, }, // aa +{ -8.24, -0.80, -8.89, -5.13, -8.61, -5.38, -5.77, -6.60, -10.41, -4.57, -14.53, -10.14, -5.43, -5.94, -8.87, -11.07, }, // ag +{ -7.04, -8.89, -2.11, -2.04, -9.73, -11.05, -3.81, -4.72, -9.37, -5.86, -9.08, -10.45, -5.33, -6.93, -8.67, -7.83, }, // ac +{ -4.32, -5.13, -2.04, 4.49, -5.33, -5.61, 2.70, 0.59, -5.56, 1.67, -6.71, -5.17, 1.61, -0.51, -4.81, -2.98, }, // at +{ -6.86, -8.61, -9.73, -5.33, -1.05, -8.67, -4.88, -6.10, -7.98, -6.00, -12.43, -7.71, -5.85, -7.55, -6.63, -11.54, }, // ga +{ -8.39, -5.38, -11.05, -5.61, -8.67, -1.98, -4.13, -5.77, -11.36, -4.66, -12.58, -13.69, -5.75, -4.27, -12.01, -10.79, }, // gg +{ -5.03, -5.77, -3.81, 2.70, -4.88, -4.13, 5.62, 1.21, -5.95, 2.11, -3.70, -5.84, 1.60, -0.08, -4.49, -3.90, }, // gc +{ -5.84, -6.60, -4.72, 0.59, -6.10, -5.77, 1.21, 3.47, -7.93, -0.27, -7.88, -5.61, -0.57, -2.09, -5.30, -4.45, }, // gt +{ -8.84, -10.41, -9.37, -5.56, -7.98, -11.36, -5.95, -7.93, -5.13, -3.57, -10.45, -8.49, -2.42, -5.63, -7.08, -8.39, }, // ca +{ -4.68, -4.57, -5.86, 1.67, -6.00, -4.66, 2.11, -0.27, -3.57, 5.36, -5.71, -4.96, 2.75, 1.32, -4.91, -3.67, }, // cg +{ -14.37, -14.53, -9.08, -6.71, -12.43, -12.58, -3.70, -7.88, -10.45, -5.71, -3.59, -5.77, -6.88, -8.41, -7.40, -5.41, }, // cc +{ -12.64, -10.14, -10.45, -5.17, -7.71, -13.69, -5.84, -5.61, -8.49, -4.96, -5.77, -2.28, -4.72, -7.36, -3.83, -5.21, }, // ct +{ -4.01, -5.43, -5.33, 1.61, -5.85, -5.75, 1.60, -0.57, -2.42, 2.75, -6.88, -4.72, 4.97, 1.14, -2.98, -3.39, }, // ta +{ -6.16, -5.94, -6.93, -0.51, -7.55, -4.27, -0.08, -2.09, -5.63, 1.32, -8.41, -7.36, 1.14, 3.36, -4.76, -4.28, }, // tg +{ -11.32, -8.87, -8.67, -4.81, -6.63, -12.01, -4.49, -5.30, -7.08, -4.91, -7.40, -3.83, -2.98, -4.76, -3.21, -5.97, }, // tc +{ -9.05, -11.07, -7.83, -2.98, -11.54, -10.79, -3.90, -4.45, -8.39, -3.67, -5.41, -5.21, -3.39, -4.28, -5.97, -0.02, }, // tt +}; + +int locpenaltyn = -1750; +char locaminon[] = "agctuAGCTUnNbdhkmnrsvwyx-O"; +char locgrpn[] = +{ + 0, 1, 2, 3, 3, 0, 1, 2, 3, 3, + 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5 +}; +int exgpn = +00; +int locn_disn[26][26] = +/* u ha constants.c no nakade shori */ +/* 0 - 4 dake yomareru. */ + { + { + 1000, 600, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 600, 1000, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 1000, 600, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 600, 1000, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 500, 500, 0, 0, 0, 500, 500, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -500, + }, + + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + }, + + { + -500, -500, -500, -500, -500, -500, -500, -500, -500, -500, + -500, -500, -500, -500, -500, -500, -500, -500, -500, -500, + -500, -500, -500, -500, 0, 500, + }, + }; Added: test-suite/trunk/MultiSource/Benchmarks/mafft/Falign.c URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/Falign.c?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/Falign.c (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/Falign.c Thu Feb 19 06:37:59 2009 @@ -0,0 +1,2981 @@ +#include "mltaln.h" + +#if 0 +static FILE *fftfp; +#endif +static int n20or4or2; + +#define KEIKA 0 +#define RND 0 +#define DEBUG 0 + +#if RND // by D.Mathog +static void generateRndSeq( char *seq, int len ) +{ + while( len-- ) +#if 1 + *seq++ = (int)( rnd() * n20or4or2 ); +#else + *seq++ = (int)1; +#endif +} +#endif + +static void vec_init( Fukusosuu *result, int nlen ) +{ + while( nlen-- ) + { + result->R = result->I = 0.0; + result++; + } +} + +#if 0 // by D.Mathog +static void vec_init2( Fukusosuu **result, char *seq, double eff, int st, int ed ) +{ + int i; + for( i=st; i= 0 ) result->R += incr * score[n]; +#if 0 + fprintf( stderr, "n=%d, score=%f, inc=%f R=%f\n",n, score[n], incr * score[n], result->R ); +#endif + } +} + +static void seq_vec_3( Fukusosuu **result, double incr, char *seq ) +{ + int i; + int n; + for( i=0; *seq; i++ ) + { + n = amino_n[(int)*seq++]; + if( n < n20or4or2 && n >= 0 ) result[n][i].R += incr; + } +} + +static void seq_vec_5( Fukusosuu *result, double *score1, double *score2, double incr, char *seq ) +{ + int n; + for( ; *seq; result++ ) + { + n = amino_n[(int)*seq++]; + if( n > 20 ) continue; + result->R += incr * score1[n]; + result->I += incr * score2[n]; +#if 0 + fprintf( stderr, "n=%d, score=%f, inc=%f R=%f\n",n, score[n], incr * score[n], result->R ); +#endif + } +} + + +static void seq_vec_4( Fukusosuu *result, double incr, char *seq ) +{ + char s; + for( ; *seq; result++ ) + { + s = *seq++; + if( s == 'a' ) + result->R += incr; + else if( s == 't' ) + result->R -= incr; + else if( s == 'g' ) + result->I += incr; + else if( s == 'c' ) + result->I -= incr; + } +} + +#if 0 // by D.Mathog +static void seq_vec( Fukusosuu *result, char query, double incr, char *seq ) +{ +#if 0 + int bk = nlen; +#endif + while( *seq ) + { + if( *seq++ == query ) result->R += incr; + result++; +#if 0 +fprintf( stderr, "i = %d result->R = %f\n", bk-nlen, (result-1)->R ); +#endif + } +} + +static int checkRepeat( int num, int *cutpos ) +{ + int tmp, buf; + + buf = *cutpos; + while( num-- ) + { + if( ( tmp = *cutpos++ ) < buf ) return( 1 ); + buf = tmp; + } + return( 0 ); +} + +static int segcmp( void *ptr1, void *ptr2 ) +{ + int diff; + Segment **seg1 = (Segment **)ptr1; + Segment **seg2 = (Segment **)ptr2; +#if 0 + return( (*seg1)->center - (*seg2)->center ); +#else + diff = (*seg1)->center - (*seg2)->center; + if( diff ) return( diff ); + + diff = (*seg1)->start - (*seg2)->start; + if( diff ) return( diff ); + + diff = (*seg1)->end - (*seg2)->end; + if( diff ) return( diff ); + + fprintf( stderr, "USE STABLE SORT !!\n" ); + exit( 1 ); + return( 0 ); +#endif +} +#endif + + +static void mymergesort( int first, int last, Segment **seg ) +{ + int middle; + static int i, j, k, p; + static int allo = 0; + static Segment **work = NULL; + if( last > allo ) + { + allo = last; + if( work ) free( work ); + work = (Segment **)calloc( allo / 2 + 1, sizeof( Segment *) ); + } + + if( first < last ) + { + middle = ( first + last ) / 2; + mymergesort( first, middle, seg ); + mymergesort( middle+1, last, seg ); + p = 0; + for( i=first; i<=middle; i++ ) work[p++] = seg[i]; + i = middle + 1; j = 0; k = first; + while( i <= last && j < p ) + { + if( work[j]->center <= seg[i]->center ) + seg[k++] = work[j++]; + else + seg[k++] = seg[i++]; + } + while( j < p ) seg[k++] = work[j++]; + } +} + + +double Fgetlag( char **seq1, char **seq2, + double *eff1, double *eff2, + int clus1, int clus2, + int alloclen ) +{ + int i, j, k, l, m; + int nlen, nlen2, nlen4; + static int crossscoresize = 0; + static char **tmpseq1 = NULL; + static char **tmpseq2 = NULL; + static char **tmpptr1 = NULL; + static char **tmpptr2 = NULL; + static char **tmpres1 = NULL; + static char **tmpres2 = NULL; + static char **result1 = NULL; + static char **result2 = NULL; +#if RND + static char **rndseq1 = NULL; + static char **rndseq2 = NULL; +#endif + static Fukusosuu **seqVector1 = NULL; + static Fukusosuu **seqVector2 = NULL; + static Fukusosuu **naiseki = NULL; + static Fukusosuu *naisekiNoWa = NULL; + static double *soukan = NULL; + static double **crossscore = NULL; + int nlentmp; + static int *kouho = NULL; + static Segment *segment = NULL; + static Segment *segment1 = NULL; + static Segment *segment2 = NULL; + static Segment **sortedseg1 = NULL; + static Segment **sortedseg2 = NULL; + static int *cut1 = NULL; + static int *cut2 = NULL; + static int localalloclen = 0; + int lag; + int tmpint; + int count, count0; + int len1, len2; + int totallen; + float dumfl = 0.0; + + len1 = strlen( seq1[0] ); + len2 = strlen( seq2[0] ); + nlentmp = MAX( len1, len2 ); + + nlen = 1; + while( nlentmp >= nlen ) nlen <<= 1; +#if 0 + fprintf( stderr, "### nlen = %d\n", nlen ); +#endif + + nlen2 = nlen/2; nlen4 = nlen2 / 2; + +#if DEBUG + fprintf( stderr, "len1 = %d, len2 = %d\n", len1, len2 ); + fprintf( stderr, "nlentmp = %d, nlen = %d\n", nlentmp, nlen ); +#endif + + if( !localalloclen ) + { + kouho = AllocateIntVec( NKOUHO ); + cut1 = AllocateIntVec( MAXSEG ); + cut2 = AllocateIntVec( MAXSEG ); + tmpptr1 = AllocateCharMtx( njob, 0 ); + tmpptr2 = AllocateCharMtx( njob, 0 ); + result1 = AllocateCharMtx( njob, alloclen ); + result2 = AllocateCharMtx( njob, alloclen ); + tmpres1 = AllocateCharMtx( njob, alloclen ); + tmpres2 = AllocateCharMtx( njob, alloclen ); +// crossscore = AllocateDoubleMtx( MAXSEG, MAXSEG ); + segment = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); + segment1 = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); + segment2 = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); + sortedseg1 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) ); + sortedseg2 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) ); + if( !( segment && segment1 && segment2 && sortedseg1 && sortedseg2 ) ) + ErrorExit( "Allocation error\n" ); + + if ( scoremtx == -1 ) n20or4or2 = 4; + else if( fftscore == 1 ) n20or4or2 = 2; + else n20or4or2 = 20; + } + if( localalloclen < nlen ) + { + if( localalloclen ) + { +#if 1 + FreeFukusosuuMtx ( seqVector1 ); + FreeFukusosuuMtx ( seqVector2 ); + FreeFukusosuuVec( naisekiNoWa ); + FreeFukusosuuMtx( naiseki ); + FreeDoubleVec( soukan ); + FreeCharMtx( tmpseq1 ); + FreeCharMtx( tmpseq2 ); +#endif +#if RND + FreeCharMtx( rndseq1 ); + FreeCharMtx( rndseq2 ); +#endif + } + + + tmpseq1 = AllocateCharMtx( njob, nlen ); + tmpseq2 = AllocateCharMtx( njob, nlen ); + naisekiNoWa = AllocateFukusosuuVec( nlen ); + naiseki = AllocateFukusosuuMtx( n20or4or2, nlen ); + seqVector1 = AllocateFukusosuuMtx( n20or4or2+1, nlen+1 ); + seqVector2 = AllocateFukusosuuMtx( n20or4or2+1, nlen+1 ); + soukan = AllocateDoubleVec( nlen+1 ); + +#if RND + rndseq1 = AllocateCharMtx( njob, nlen ); + rndseq2 = AllocateCharMtx( njob, nlen ); + for( i=0; i /dev/tty" ); +#endif + + if( fftkeika ) fprintf( stderr, " FFT ... " ); + + for( j=0; j /dev/tty" ); +#endif + + for( j=0; j /dev/tty" ); +#endif + + for( j=0; j /dev/tty" ); +#endif + + for( k=0; k /dev/tty " ); +#endif + + fft( -nlen, naisekiNoWa, 0 ); + + for( m=0; m<=nlen2; m++ ) + soukan[m] = naisekiNoWa[nlen2-m].R; + for( m=nlen2+1; m /dev/tty" ); +#if 0 +fftfp = fopen( "list.plot", "w" ); +fprintf( fftfp, "plot 'frt'\n pause +1" ); +fclose( fftfp ); +system( "/usr/bin/gnuplot list.plot" ); +#endif +#endif + + + getKouho( kouho, NKOUHO, soukan, nlen ); + +#if 0 + for( i=0; iCandidate No.%d lag = %d\n", k+1, lag ); + fprintf( fftfp, "%s\n", tmpptr1[0] ); + fprintf( fftfp, ">Candidate No.%d lag = %d\n", k+1, lag ); + fprintf( fftfp, "%s\n", tmpptr2[0] ); + fprintf( fftfp, ">\n", k+1, lag ); + fclose( fftfp ); +#endif + tmpint = alignableReagion( clus1, clus2, tmpptr1, tmpptr2, eff1, eff2, segment+count ); + + if( count+tmpint > MAXSEG -3 ) ErrorExit( "TOO MANY SEGMENTS.\n" ); + + + if( tmpint == 0 ) break; // 060430 iinoka ? + while( tmpint-- > 0 ) + { + if( lag > 0 ) + { + segment1[count].start = segment[count].start ; + segment1[count].end = segment[count].end ; + segment1[count].center = segment[count].center; + segment1[count].score = segment[count].score; + + segment2[count].start = segment[count].start + lag; + segment2[count].end = segment[count].end + lag; + segment2[count].center = segment[count].center + lag; + segment2[count].score = segment[count].score ; + } + else + { + segment1[count].start = segment[count].start - lag; + segment1[count].end = segment[count].end - lag; + segment1[count].center = segment[count].center - lag; + segment1[count].score = segment[count].score ; + + segment2[count].start = segment[count].start ; + segment2[count].end = segment[count].end ; + segment2[count].center = segment[count].center; + segment2[count].score = segment[count].score ; + } +#if 0 + fprintf( stderr, "Goukaku=%dko\n", tmpint ); + fprintf( stderr, "in 1 %d\n", segment1[count].center ); + fprintf( stderr, "in 2 %d\n", segment2[count].center ); +#endif + segment1[count].pair = &segment2[count]; + segment2[count].pair = &segment1[count]; + count++; +#if 0 + fprintf( stderr, "count=%d\n", count ); +#endif + } + } + +#if 1 + fprintf( stderr, "done. (%d anchors)\r", count ); +#endif + if( !count && fftNoAnchStop ) + ErrorExit( "Cannot detect anchor!" ); +#if 0 + fprintf( stdout, "RESULT before sort:\n" ); + for( l=0; lnumber = i; + for( i=0; inumber = i; + + if( crossscoresize < count+2 ) + { + crossscoresize = count+2; + fprintf( stderr, "####################################################################################################################################allocating crossscore, size = %d\n", crossscoresize ); + if( crossscore ) FreeDoubleMtx( crossscore ); + crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize ); + } + + for( i=0; inumber+1] = segment1[i].score; + cut1[i+1] = sortedseg1[i]->center; + cut2[i+1] = sortedseg2[i]->center; + } + +#if DEBUG + fprintf( stderr, "AFTER SORT\n" ); + for( i=0; i count ) + { + fprintf( stderr, "REPEAT!? \n" ); + if( fftRepeatStop ) exit( 1 ); + } +#if KEIKA + else + fprintf( stderr, "done\n" ); + fprintf( stderr, "done. (%d anchors)\n", count ); +#endif + } + +#if 0 + fftfp = fopen( "fft", "a" ); + fprintf( fftfp, "RESULT after sort:\n" ); + for( l=0; l alloclen ) ErrorExit( "LENGTH OVER in Falign\n " ); + for( j=0; j= nlen ) nlen <<= 1; +#if 0 + fprintf( stderr, "### nlen = %d\n", nlen ); +#endif + + nlen2 = nlen/2; nlen4 = nlen2 / 2; + +#if DEBUG + fprintf( stderr, "len1 = %d, len2 = %d\n", len1, len2 ); + fprintf( stderr, "nlentmp = %d, nlen = %d\n", nlentmp, nlen ); +#endif + + if( prevalloclen != alloclen ) // Falign_noudp mo kaeru + { + if( prevalloclen ) + { + FreeCharMtx( result1 ); + FreeCharMtx( result2 ); + FreeCharMtx( tmpres1 ); + FreeCharMtx( tmpres2 ); + } +// fprintf( stderr, "\n\n\nreallocating ...\n" ); + result1 = AllocateCharMtx( njob, alloclen ); + result2 = AllocateCharMtx( njob, alloclen ); + tmpres1 = AllocateCharMtx( njob, alloclen ); + tmpres2 = AllocateCharMtx( njob, alloclen ); + prevalloclen = alloclen; + } + if( !localalloclen ) + { + sgap1 = AllocateCharVec( njob ); + egap1 = AllocateCharVec( njob ); + sgap2 = AllocateCharVec( njob ); + egap2 = AllocateCharVec( njob ); + kouho = AllocateIntVec( NKOUHO ); + cut1 = AllocateIntVec( MAXSEG ); + cut2 = AllocateIntVec( MAXSEG ); + tmpptr1 = AllocateCharMtx( njob, 0 ); + tmpptr2 = AllocateCharMtx( njob, 0 ); +// crossscore = AllocateDoubleMtx( MAXSEG, MAXSEG ); + segment = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); + segment1 = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); + segment2 = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); + sortedseg1 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) ); + sortedseg2 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) ); + if( !( segment && segment1 && segment2 && sortedseg1 && sortedseg2 ) ) + ErrorExit( "Allocation error\n" ); + + if ( scoremtx == -1 ) n20or4or2 = 1; + else if( fftscore ) n20or4or2 = 1; + else n20or4or2 = 20; + } + if( localalloclen < nlen ) + { + if( localalloclen ) + { +#if 1 + if( !kobetsubunkatsu ) + { + FreeFukusosuuMtx ( seqVector1 ); + FreeFukusosuuMtx ( seqVector2 ); + FreeFukusosuuVec( naisekiNoWa ); + FreeFukusosuuMtx( naiseki ); + FreeDoubleVec( soukan ); + } + FreeCharMtx( tmpseq1 ); + FreeCharMtx( tmpseq2 ); +#endif +#if RND + FreeCharMtx( rndseq1 ); + FreeCharMtx( rndseq2 ); +#endif + } + + tmpseq1 = AllocateCharMtx( njob, nlen ); + tmpseq2 = AllocateCharMtx( njob, nlen ); + if( !kobetsubunkatsu ) + { + naisekiNoWa = AllocateFukusosuuVec( nlen ); + naiseki = AllocateFukusosuuMtx( n20or4or2, nlen ); + seqVector1 = AllocateFukusosuuMtx( n20or4or2+1, nlen+1 ); + seqVector2 = AllocateFukusosuuMtx( n20or4or2+1, nlen+1 ); + soukan = AllocateDoubleVec( nlen+1 ); + } +#if RND + rndseq1 = AllocateCharMtx( njob, nlen ); + rndseq2 = AllocateCharMtx( njob, nlen ); + for( i=0; i /dev/tty" ); +#endif + if( !kobetsubunkatsu ) + { + if( fftkeika ) fprintf( stderr, " FFT ... " ); + + for( j=0; j /dev/tty" ); +#endif + + for( j=0; j /dev/tty" ); +#endif + + for( j=0; j /dev/tty" ); +#endif + + for( k=0; k /dev/tty " ); +#endif + + fft( -nlen, naisekiNoWa, 0 ); + + for( m=0; m<=nlen2; m++ ) + soukan[m] = naisekiNoWa[nlen2-m].R; + for( m=nlen2+1; mCandidate No.%d lag = %d\n", k+1, lag ); + fprintf( fftfp, "%s\n", tmpptr1[0] ); + fprintf( fftfp, ">Candidate No.%d lag = %d\n", k+1, lag ); + fprintf( fftfp, "%s\n", tmpptr2[0] ); + fprintf( fftfp, ">\n", k+1, lag ); + fclose( fftfp ); +#endif + +// fprintf( stderr, "lag = %d\n", lag ); + tmpint = alignableReagion( clus1, clus2, tmpptr1, tmpptr2, eff1, eff2, segment+count ); + +// if( lag == -50 ) exit( 1 ); + + if( count+tmpint > MAXSEG -3 ) ErrorExit( "TOO MANY SEGMENTS.\n" ); + + + if( tmpint == 0 ) break; // 060430 iinoka ? + while( tmpint-- > 0 ) + { +#if 0 + if( segment[count].end - segment[count].start < fftWinSize ) + { + count++; + continue; + } +#endif + if( lag > 0 ) + { + segment1[count].start = segment[count].start ; + segment1[count].end = segment[count].end ; + segment1[count].center = segment[count].center; + segment1[count].score = segment[count].score; + + segment2[count].start = segment[count].start + lag; + segment2[count].end = segment[count].end + lag; + segment2[count].center = segment[count].center + lag; + segment2[count].score = segment[count].score ; + } + else + { + segment1[count].start = segment[count].start - lag; + segment1[count].end = segment[count].end - lag; + segment1[count].center = segment[count].center - lag; + segment1[count].score = segment[count].score ; + + segment2[count].start = segment[count].start ; + segment2[count].end = segment[count].end ; + segment2[count].center = segment[count].center; + segment2[count].score = segment[count].score ; + } +#if 0 + fprintf( stderr, "in 1 %d\n", segment1[count].center ); + fprintf( stderr, "in 2 %d\n", segment2[count].center ); +#endif + segment1[count].pair = &segment2[count]; + segment2[count].pair = &segment1[count]; + count++; + } + } +#if 0 + if( !kobetsubunkatsu && fftkeika ) + fprintf( stderr, "%d anchors found\r", count ); +#endif + if( !count && fftNoAnchStop ) + ErrorExit( "Cannot detect anchor!" ); +#if 0 + fprintf( stderr, "RESULT before sort:\n" ); + for( l=0; lnumber = i; + for( i=0; inumber = i; + + + if( kobetsubunkatsu ) + { + for( i=0; icenter; + cut2[i+1] = sortedseg2[i]->center; + } + cut1[0] = 0; + cut2[0] = 0; + cut1[count+1] = len1; + cut2[count+1] = len2; + count += 2; + } + else + { + if( crossscoresize < count+2 ) + { + crossscoresize = count+2; +#if 1 + if( fftkeika ) fprintf( stderr, "######allocating crossscore, size = %d\n", crossscoresize ); +#endif + if( crossscore ) FreeDoubleMtx( crossscore ); + crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize ); + } + for( i=0; inumber+1] = segment1[i].score; + cut1[i+1] = sortedseg1[i]->center; + cut2[i+1] = sortedseg2[i]->center; + } + +#if 0 + fprintf( stderr, "AFTER SORT\n" ); + for( i=0; i count ) + { +#if 0 + fprintf( stderr, "\7 REPEAT!? \n" ); +#else + fprintf( stderr, "REPEAT!? \n" ); +#endif + if( fftRepeatStop ) exit( 1 ); + } +#if KEIKA + else fprintf( stderr, "done\n" ); +#endif + } + } + +#if 0 + fftfp = fopen( "fft", "a" ); + fprintf( fftfp, "RESULT after sort:\n" ); + for( l=0; l%d of GROUP1\n", j ); + fprintf( stdout, "%s\n", tmpres1[j] ); + } + for( j=0; j%d of GROUP2\n", j ); + fprintf( stdout, "%s\n", tmpres2[j] ); + } + fflush( stdout ); +#endif + switch( alg ) + { + case( 'a' ): + totalscore += Aalign( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen ); + break; + case( 'M' ): + totalscore += MSalignmm( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2 ); + break; + case( 'A' ): + if( clus1 == 1 && clus2 == 1 ) + { + totalscore += G__align11( tmpres1, tmpres2, alloclen ); + } + else + totalscore += A__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumfl, sgap1, sgap2, egap1, egap2 ); + break; + case( 'H' ): + if( clus1 == 1 && clus2 == 1 ) + { + totalscore += G__align11( tmpres1, tmpres2, alloclen ); + } + else + totalscore += H__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumfl, sgap1, sgap2, egap1, egap2 ); + break; + case( 'Q' ): + if( clus1 == 1 && clus2 == 1 ) + { + totalscore += G__align11( tmpres1, tmpres2, alloclen ); + } + else + totalscore += Q__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumfl, sgap1, sgap2, egap1, egap2 ); + break; + default: + fprintf( stderr, "alg = %c\n", alg ); + ErrorExit( "ERROR IN SOURCE FILE Falign.c" ); + break; + } + + nlen = strlen( tmpres1[0] ); + if( totallen + nlen > alloclen ) + { + fprintf( stderr, "totallen=%d + nlen=%d > alloclen = %d\n", totallen, nlen, alloclen ); + ErrorExit( "LENGTH OVER in Falign\n " ); + } + for( j=0; j= nlen ) nlen <<= 1; +#if 0 + fprintf( stderr, "### nlen = %d\n", nlen ); +#endif + + nlen2 = nlen/2; nlen4 = nlen2 / 2; + +#if 0 + fprintf( stderr, "len1 = %d, len2 = %d\n", len1, len2 ); + fprintf( stderr, "nlentmp = %d, nlen = %d\n", nlentmp, nlen ); +#endif + + if( prevalloclen != alloclen ) // Falign_noudp mo kaeru + { + if( prevalloclen ) + { + FreeCharMtx( result1 ); + FreeCharMtx( result2 ); + FreeCharMtx( tmpres1 ); + FreeCharMtx( tmpres2 ); + } +// fprintf( stderr, "\n\n\nreallocating ...\n" ); + result1 = AllocateCharMtx( njob, alloclen ); + result2 = AllocateCharMtx( njob, alloclen ); + tmpres1 = AllocateCharMtx( njob, alloclen ); + tmpres2 = AllocateCharMtx( njob, alloclen ); + prevalloclen = alloclen; + } + + if( !localalloclen ) + { + sgap1 = AllocateCharVec( njob ); + egap1 = AllocateCharVec( njob ); + sgap2 = AllocateCharVec( njob ); + egap2 = AllocateCharVec( njob ); + kouho = AllocateIntVec( NKOUHO_LONG ); + cut1 = AllocateIntVec( MAXSEG ); + cut2 = AllocateIntVec( MAXSEG ); + tmpptr1 = AllocateCharMtx( njob, 0 ); + tmpptr2 = AllocateCharMtx( njob, 0 ); + segment = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); + segment1 = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); + segment2 = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); + sortedseg1 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) ); + sortedseg2 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) ); + if( !( segment && segment1 && segment2 && sortedseg1 && sortedseg2 ) ) + ErrorExit( "Allocation error\n" ); + + if ( scoremtx == -1 ) n20or4or2 = 1; + else if( fftscore ) n20or4or2 = 1; + else n20or4or2 = 20; + } + if( localalloclen < nlen ) + { + if( localalloclen ) + { +#if 1 + if( !kobetsubunkatsu ) + { + FreeFukusosuuMtx ( seqVector1 ); + FreeFukusosuuMtx ( seqVector2 ); + FreeFukusosuuVec( naisekiNoWa ); + FreeFukusosuuMtx( naiseki ); + FreeDoubleVec( soukan ); + } + FreeCharMtx( tmpseq1 ); + FreeCharMtx( tmpseq2 ); +#endif +#if RND + FreeCharMtx( rndseq1 ); + FreeCharMtx( rndseq2 ); +#endif + } + + + tmpseq1 = AllocateCharMtx( njob, nlen ); + tmpseq2 = AllocateCharMtx( njob, nlen ); + if( !kobetsubunkatsu ) + { + naisekiNoWa = AllocateFukusosuuVec( nlen ); + naiseki = AllocateFukusosuuMtx( n20or4or2, nlen ); + seqVector1 = AllocateFukusosuuMtx( n20or4or2, nlen+1 ); + seqVector2 = AllocateFukusosuuMtx( n20or4or2, nlen+1 ); + soukan = AllocateDoubleVec( nlen+1 ); + } +#if RND + rndseq1 = AllocateCharMtx( njob, nlen ); + rndseq2 = AllocateCharMtx( njob, nlen ); + for( i=0; i /dev/tty" ); +#endif + if( !kobetsubunkatsu ) + { + fprintf( stderr, " FFT ... " ); + + for( j=0; j /dev/tty" ); +#endif + + for( j=0; j /dev/tty" ); +#endif + + for( j=0; j /dev/tty" ); +#endif + + for( k=0; k /dev/tty " ); +#endif + + fft( -nlen, naisekiNoWa, 0 ); + + for( m=0; m<=nlen2; m++ ) + soukan[m] = naisekiNoWa[nlen2-m].R; + for( m=nlen2+1; mCandidate No.%d lag = %d\n", k+1, lag ); + fprintf( fftfp, "%s\n", tmpptr1[0] ); + fprintf( fftfp, ">Candidate No.%d lag = %d\n", k+1, lag ); + fprintf( fftfp, "%s\n", tmpptr2[0] ); + fprintf( fftfp, ">\n", k+1, lag ); + fclose( fftfp ); +#endif + +// fprintf( stderr, "lag = %d\n", lag ); + tmpint = alignableReagion( clus1, clus2, tmpptr1, tmpptr2, eff1, eff2, segment+count ); +// fprintf( stderr, "lag = %d, %d found\n", lag, tmpint ); + +// if( lag == -50 ) exit( 1 ); + + if( count+tmpint > MAXSEG -3 ) ErrorExit( "TOO MANY SEGMENTS.\n" ); + +// fprintf( stderr, "##### k=%d / %d\n", k, maxk ); + if( tmpint == 0 ) break; // 060430 iinoka ? + while( tmpint-- > 0 ) + { +#if 0 + if( segment[count].end - segment[count].start < fftWinSize ) + { + count++; + continue; + } +#endif + if( lag > 0 ) + { + segment1[count].start = segment[count].start ; + segment1[count].end = segment[count].end ; + segment1[count].center = segment[count].center; + segment1[count].score = segment[count].score; + + segment2[count].start = segment[count].start + lag; + segment2[count].end = segment[count].end + lag; + segment2[count].center = segment[count].center + lag; + segment2[count].score = segment[count].score ; + } + else + { + segment1[count].start = segment[count].start - lag; + segment1[count].end = segment[count].end - lag; + segment1[count].center = segment[count].center - lag; + segment1[count].score = segment[count].score ; + + segment2[count].start = segment[count].start ; + segment2[count].end = segment[count].end ; + segment2[count].center = segment[count].center; + segment2[count].score = segment[count].score ; + } +#if 0 + fprintf( stderr, "##### k=%d / %d\n", k, maxk ); + fprintf( stderr, "anchor %d, score = %f\n", count, segment1[count].score ); + fprintf( stderr, "in 1 %d\n", segment1[count].center ); + fprintf( stderr, "in 2 %d\n", segment2[count].center ); +#endif + segment1[count].pair = &segment2[count]; + segment2[count].pair = &segment1[count]; + count++; +#if 0 + fprintf( stderr, "count=%d\n", count ); +#endif + } + } +#if 1 + if( !kobetsubunkatsu ) + fprintf( stderr, "done. (%d anchors) ", count ); +#endif + if( !count && fftNoAnchStop ) + ErrorExit( "Cannot detect anchor!" ); +#if 0 + fprintf( stderr, "RESULT before sort:\n" ); + for( l=0; lnumber = i; + for( i=0; inumber = i; + + + + if( kobetsubunkatsu ) + { + for( i=0; icenter; + cut2[i+1] = sortedseg2[i]->center; + } + cut1[0] = 0; + cut2[0] = 0; + cut1[count+1] = len1; + cut2[count+1] = len2; + count += 2; + } + else + { + cut1[0] = 0; + cut2[0] = 0; + count0 = 0; + for( i=0; icenter, sortedseg1[i]->pair->center ); + if( sortedseg1[i]->center > cut1[count0] + && sortedseg1[i]->pair->center > cut2[count0] ) + { + count0++; + cut1[count0] = sortedseg1[i]->center; + cut2[count0] = sortedseg1[i]->pair->center; + } + else + { + if( i && sortedseg1[i]->score > sortedseg1[i-1]->score ) + { + if( sortedseg1[i]->center > cut1[count0-1] + && sortedseg1[i]->pair->center > cut2[count0-1] ) + { + cut1[count0] = sortedseg1[i]->center; + cut2[count0] = sortedseg1[i]->pair->center; + } + else + { +// count0--; + } + } + } + } +// if( count-count0 ) +// fprintf( stderr, "%d anchors unused\n", count-count0 ); + cut1[count0+1] = len1; + cut2[count0+1] = len2; + count = count0 + 2; + count0 = count; + + } + +// exit( 0 ); + +#if 0 + fftfp = fopen( "fft", "a" ); + fprintf( fftfp, "RESULT after sort:\n" ); + for( l=0; l%d of GROUP1\n", j ); + fprintf( stdout, "%s\n", tmpres1[j] ); + } + for( j=0; j%d of GROUP2\n", j ); + fprintf( stdout, "%s\n", tmpres2[j] ); + } + fflush( stdout ); +#endif + switch( alg ) + { + case( 'M' ): + totalscore += MSalignmm( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2 ); + break; + default: + fprintf( stderr, "alg = %c\n", alg ); + ErrorExit( "ERROR IN SOURCE FILE Falign.c" ); + break; + } + + nlen = strlen( tmpres1[0] ); + if( totallen + nlen > alloclen ) + { + fprintf( stderr, "totallen=%d + nlen=%d > alloclen = %d\n", totallen, nlen, alloclen ); + ErrorExit( "LENGTH OVER in Falign\n " ); + } + for( j=0; j= nlen ) nlen <<= 1; +#if 0 + fprintf( stderr, "### nlen = %d\n", nlen ); +#endif + + nlen2 = nlen/2; nlen4 = nlen2 / 2; + +#if 0 + fprintf( stderr, "len1 = %d, len2 = %d\n", len1, len2 ); + fprintf( stderr, "nlentmp = %d, nlen = %d\n", nlentmp, nlen ); +#endif + + if( prevalloclen != alloclen ) // Falign_noudp mo kaeru + { + if( prevalloclen ) + { + FreeCharMtx( result1 ); + FreeCharMtx( result2 ); + FreeCharMtx( tmpres1 ); + FreeCharMtx( tmpres2 ); + } +// fprintf( stderr, "\n\n\nreallocating ...\n" ); + result1 = AllocateCharMtx( njob, alloclen ); + result2 = AllocateCharMtx( njob, alloclen ); + tmpres1 = AllocateCharMtx( njob, alloclen ); + tmpres2 = AllocateCharMtx( njob, alloclen ); + prevalloclen = alloclen; + } + + if( !localalloclen ) + { + sgap1 = AllocateCharVec( njob ); + egap1 = AllocateCharVec( njob ); + sgap2 = AllocateCharVec( njob ); + egap2 = AllocateCharVec( njob ); + kouho = AllocateIntVec( NKOUHO_LONG ); + cut1 = AllocateIntVec( MAXSEG ); + cut2 = AllocateIntVec( MAXSEG ); + tmpptr1 = AllocateCharMtx( njob, 0 ); + tmpptr2 = AllocateCharMtx( njob, 0 ); + segment = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); + segment1 = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); + segment2 = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); + sortedseg1 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) ); + sortedseg2 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) ); + if( !( segment && segment1 && segment2 && sortedseg1 && sortedseg2 ) ) + ErrorExit( "Allocation error\n" ); + + if ( scoremtx == -1 ) n20or4or2 = 1; + else if( fftscore ) n20or4or2 = 1; + else n20or4or2 = 20; + } + if( localalloclen < nlen ) + { + if( localalloclen ) + { +#if 1 + if( !kobetsubunkatsu ) + { + FreeFukusosuuMtx ( seqVector1 ); + FreeFukusosuuMtx ( seqVector2 ); + FreeFukusosuuVec( naisekiNoWa ); + FreeFukusosuuMtx( naiseki ); + FreeDoubleVec( soukan ); + } + FreeCharMtx( tmpseq1 ); + FreeCharMtx( tmpseq2 ); +#endif +#if RND + FreeCharMtx( rndseq1 ); + FreeCharMtx( rndseq2 ); +#endif + } + + + tmpseq1 = AllocateCharMtx( njob, nlen ); + tmpseq2 = AllocateCharMtx( njob, nlen ); + if( !kobetsubunkatsu ) + { + naisekiNoWa = AllocateFukusosuuVec( nlen ); + naiseki = AllocateFukusosuuMtx( n20or4or2, nlen ); + seqVector1 = AllocateFukusosuuMtx( n20or4or2, nlen+1 ); + seqVector2 = AllocateFukusosuuMtx( n20or4or2, nlen+1 ); + soukan = AllocateDoubleVec( nlen+1 ); + } +#if RND + rndseq1 = AllocateCharMtx( njob, nlen ); + rndseq2 = AllocateCharMtx( njob, nlen ); + for( i=0; i /dev/tty" ); +#endif + if( !kobetsubunkatsu ) + { + fprintf( stderr, " FFT ... " ); + + for( j=0; j /dev/tty" ); +#endif + + for( j=0; j /dev/tty" ); +#endif + + for( j=0; j /dev/tty" ); +#endif + + for( k=0; k /dev/tty " ); +#endif + + fft( -nlen, naisekiNoWa, 0 ); + + for( m=0; m<=nlen2; m++ ) + soukan[m] = naisekiNoWa[nlen2-m].R; + for( m=nlen2+1; mCandidate No.%d lag = %d\n", k+1, lag ); + fprintf( fftfp, "%s\n", tmpptr1[0] ); + fprintf( fftfp, ">Candidate No.%d lag = %d\n", k+1, lag ); + fprintf( fftfp, "%s\n", tmpptr2[0] ); + fprintf( fftfp, ">\n", k+1, lag ); + fclose( fftfp ); +#endif + +// fprintf( stderr, "lag = %d\n", lag ); + tmpint = alignableReagion( clus1, clus2, tmpptr1, tmpptr2, eff1, eff2, segment+count ); +// fprintf( stderr, "lag = %d, %d found\n", lag, tmpint ); + +// if( lag == -50 ) exit( 1 ); + + if( count+tmpint > MAXSEG -3 ) ErrorExit( "TOO MANY SEGMENTS.\n" ); + +// fprintf( stderr, "##### k=%d / %d\n", k, maxk ); + if( tmpint == 0 ) break; // 060430 iinoka ? + while( tmpint-- > 0 ) + { +#if 0 + if( segment[count].end - segment[count].start < fftWinSize ) + { + count++; + continue; + } +#endif + if( lag > 0 ) + { + segment1[count].start = segment[count].start ; + segment1[count].end = segment[count].end ; + segment1[count].center = segment[count].center; + segment1[count].score = segment[count].score; + + segment2[count].start = segment[count].start + lag; + segment2[count].end = segment[count].end + lag; + segment2[count].center = segment[count].center + lag; + segment2[count].score = segment[count].score ; + } + else + { + segment1[count].start = segment[count].start - lag; + segment1[count].end = segment[count].end - lag; + segment1[count].center = segment[count].center - lag; + segment1[count].score = segment[count].score ; + + segment2[count].start = segment[count].start ; + segment2[count].end = segment[count].end ; + segment2[count].center = segment[count].center; + segment2[count].score = segment[count].score ; + } +#if 0 + fprintf( stderr, "##### k=%d / %d\n", k, maxk ); + fprintf( stderr, "anchor %d, score = %f\n", count, segment1[count].score ); + fprintf( stderr, "in 1 %d\n", segment1[count].center ); + fprintf( stderr, "in 2 %d\n", segment2[count].center ); +#endif + segment1[count].pair = &segment2[count]; + segment2[count].pair = &segment1[count]; + count++; +#if 0 + fprintf( stderr, "count=%d\n", count ); +#endif + } + } +#if 1 + if( !kobetsubunkatsu ) + fprintf( stderr, "done. (%d anchors) ", count ); +#endif + if( !count && fftNoAnchStop ) + ErrorExit( "Cannot detect anchor!" ); +#if 0 + fprintf( stderr, "RESULT before sort:\n" ); + for( l=0; lnumber = i; + for( i=0; inumber = i; + + + + if( kobetsubunkatsu ) + { + for( i=0; icenter; + cut2[i+1] = sortedseg2[i]->center; + } + cut1[0] = 0; + cut2[0] = 0; + cut1[count+1] = len1; + cut2[count+1] = len2; + count += 2; + } +#if 1 + + else + { + if( crossscoresize < count+2 ) + { + crossscoresize = count+2; +#if 1 + if( fftkeika ) fprintf( stderr, "######allocating crossscore, size = %d\n", crossscoresize ); +#endif + if( crossscore ) FreeDoubleMtx( crossscore ); + crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize ); + } + for( i=0; inumber+1] = segment1[i].score; + cut1[i+1] = sortedseg1[i]->center; + cut2[i+1] = sortedseg2[i]->center; + } + +#if 0 + fprintf( stderr, "AFTER SORT\n" ); + for( i=0; i count ) + { +#if 0 + fprintf( stderr, "\7 REPEAT!? \n" ); +#else + fprintf( stderr, "REPEAT!? \n" ); +#endif + if( fftRepeatStop ) exit( 1 ); + } +#if KEIKA + else fprintf( stderr, "done\n" ); +#endif + } + } + + +#else + else + { + cut1[0] = 0; + cut2[0] = 0; + count0 = 0; + for( i=0; icenter, sortedseg1[i]->pair->center ); + if( sortedseg1[i]->center > cut1[count0] + && sortedseg1[i]->pair->center > cut2[count0] ) + { + count0++; + cut1[count0] = sortedseg1[i]->center; + cut2[count0] = sortedseg1[i]->pair->center; + } + else + { + if( i && sortedseg1[i]->score > sortedseg1[i-1]->score ) + { + if( sortedseg1[i]->center > cut1[count0-1] + && sortedseg1[i]->pair->center > cut2[count0-1] ) + { + cut1[count0] = sortedseg1[i]->center; + cut2[count0] = sortedseg1[i]->pair->center; + } + else + { +// count0--; + } + } + } + } +// if( count-count0 ) +// fprintf( stderr, "%d anchors unused\n", count-count0 ); + cut1[count0+1] = len1; + cut2[count0+1] = len2; + count = count0 + 2; + count0 = count; + + } +#endif + +// exit( 0 ); + +#if 0 + fftfp = fopen( "fft", "a" ); + fprintf( fftfp, "RESULT after sort:\n" ); + for( l=0; l%d of GROUP1\n", j ); + fprintf( stdout, "%s\n", tmpres1[j] ); + } + for( j=0; j%d of GROUP2\n", j ); + fprintf( stdout, "%s\n", tmpres2[j] ); + } + fflush( stdout ); +#endif + switch( alg ) + { + case( 'M' ): + totalscore += MSalignmm( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2 ); + break; + default: + fprintf( stderr, "alg = %c\n", alg ); + ErrorExit( "ERROR IN SOURCE FILE Falign.c" ); + break; + } + + nlen = strlen( tmpres1[0] ); + if( totallen + nlen > alloclen ) + { + fprintf( stderr, "totallen=%d + nlen=%d > alloclen = %d\n", totallen, nlen, alloclen ); + ErrorExit( "LENGTH OVER in Falign\n " ); + } + for( j=0; j 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + *--mseq1[0] = seq1[0][ifi+l]; + *--mseq2[0] = *gap; + k++; + } + l= jin - jfi; + while( --l ) + { + *--mseq1[0] = *gap; + *--mseq2[0] = seq2[0][jfi+l]; + k++; + } + if( iin <= 0 || jin <= 0 ) break; + *--mseq1[0] = seq1[0][ifi]; + *--mseq2[0] = seq2[0][jfi]; + k++; + iin = ifi; jin = jfi; + } + return( 0.0 ); +} + + +float G__align11( char **seq1, char **seq2, int alloclen ) +/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ +{ +// int k; + register int i, j; + int lasti; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */ + int lgth1, lgth2; + int resultlen; + float wm; /* int ?????? */ + float g; + float *currentw, *previousw; + float fpenalty = (float)penalty; +#if USE_PENALTY_EX + float fpenalty_ex = (float)penalty_ex; +#endif +#if 1 + float *wtmp; + int *ijppt; + float *mjpt, *prept, *curpt; + int *mpjpt; +#endif + static float mi, *m; + static int **ijp; + static int mpi, *mp; + static float *w1, *w2; + static float *match; + static float *initverticalw; /* kufuu sureba iranai */ + static float *lastverticalw; /* kufuu sureba iranai */ + static char **mseq1; + static char **mseq2; + static char **mseq; + static int **intwork; + static float **floatwork; + static int orlgth1 = 0, orlgth2 = 0; + + wm = 0.0; + + if( orlgth1 == 0 ) + { + mseq1 = AllocateCharMtx( njob, 0 ); + mseq2 = AllocateCharMtx( njob, 0 ); + } + + + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); + + + + if( lgth1 <= 0 || lgth2 <= 0 ) + { + fprintf( stderr, "WARNING (g11): lgth1=%d, lgth2=%d\n", lgth1, lgth2 ); + } + + if( lgth1 > orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + + FreeCharMtx( mseq ); + + + + FreeFloatMtx( floatwork ); + FreeIntMtx( intwork ); + } + + ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100; + +#if DEBUG + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); +#endif + + w1 = AllocateFloatVec( ll2+2 ); + w2 = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + + m = AllocateFloatVec( ll2+2 ); + mp = AllocateIntVec( ll2+2 ); + + mseq = AllocateCharMtx( njob, ll1+ll2 ); + + + floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); + +#if DEBUG + fprintf( stderr, "succeeded\n" ); +#endif + + orlgth1 = ll1 - 100; + orlgth2 = ll2 - 100; + } + + + mseq1[0] = mseq[0]; + mseq2[0] = mseq[1]; + + + if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 ) + { + int ll1, ll2; + + if( commonAlloc1 && commonAlloc2 ) + { + FreeIntMtx( commonIP ); + } + + ll1 = MAX( orlgth1, commonAlloc1 ); + ll2 = MAX( orlgth2, commonAlloc2 ); + +#if DEBUG + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + + commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + +#if DEBUG + fprintf( stderr, "succeeded\n\n" ); +#endif + + commonAlloc1 = ll1; + commonAlloc2 = ll2; + } + ijp = commonIP; + + +#if 0 + for( i=0; i", wm ); +#endif +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( (g=mi+fpenalty) > wm ) + { + wm = g; + *ijppt = -( j - mpi ); + } + if( (g=*prept) >= mi ) + { + mi = g; + mpi = j-1; + } +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( (g=*mjpt + fpenalty) > wm ) + { + wm = g; + *ijppt = +( i - *mpjpt ); + } + if( (g=*prept) >= *mjpt ) + { + *mjpt = g; + *mpjpt = i-1; + } +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + *curpt++ += wm; + ijppt++; + mjpt++; + prept++; + mpjpt++; + } + lastverticalw[i] = currentw[lgth2-1]; // lgth2==0 no toki error + } + + Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp ); + + resultlen = strlen( mseq1[0] ); + if( alloclen < resultlen || resultlen > N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } + + + strcpy( seq1[0], mseq1[0] ); + strcpy( seq2[0], mseq2[0] ); +#if 0 + fprintf( stderr, "\n" ); + fprintf( stderr, ">\n%s\n", mseq1[0] ); + fprintf( stderr, ">\n%s\n", mseq2[0] ); + fprintf( stderr, "wm = %f\n", wm ); +#endif + + return( wm ); +} + +float G__align11_noalign( int scoremtx[0x80][0x80], int penal, int penal_ex, char **seq1, char **seq2, int alloclen ) +/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ +{ +// int k; + register int i, j; + int lasti; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */ + int lgth1, lgth2; +// int resultlen; + float wm; /* int ?????? */ + float g; + float *currentw, *previousw; + float fpenalty = (float)penal; +#if USE_PENALTY_EX + float fpenalty_ex = (float)penal_ex; +#endif +#if 1 + float *wtmp; + float *mjpt, *prept, *curpt; +// int *mpjpt; +#endif + static float mi, *m; + static float *w1, *w2; + static float *match; + static float *initverticalw; /* kufuu sureba iranai */ + static float *lastverticalw; /* kufuu sureba iranai */ + static int **intwork; + static float **floatwork; + static int orlgth1 = 0, orlgth2 = 0; + + wm = 0.0; + + + + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); + + + + if( lgth1 <= 0 || lgth2 <= 0 ) + { + fprintf( stderr, "WARNING (g11): lgth1=%d, lgth2=%d\n", lgth1, lgth2 ); + } + + if( lgth1 > orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); + + + + + FreeFloatMtx( floatwork ); + FreeIntMtx( intwork ); + } + + ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100; + +#if DEBUG + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); +#endif + + w1 = AllocateFloatVec( ll2+2 ); + w2 = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + + m = AllocateFloatVec( ll2+2 ); + + + + floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); + +#if DEBUG + fprintf( stderr, "succeeded\n" ); +#endif + + orlgth1 = ll1 - 100; + orlgth2 = ll2 - 100; + } + + + + + + +#if 0 + for( i=0; i", wm ); +#endif +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( (g=mi+fpenalty) > wm ) + { + wm = g; + } + if( (g=*prept) >= mi ) + { + mi = g; + } +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( (g=*mjpt + fpenalty) > wm ) + { + wm = g; + } + if( (g=*prept) >= *mjpt ) + { + *mjpt = g; + } +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + *curpt++ += wm; + mjpt++; + prept++; + } + lastverticalw[i] = currentw[lgth2-1]; // lgth2==0 no toki error + } + +#if 0 + fprintf( stderr, "\n" ); + fprintf( stderr, ">\n%s\n", mseq1[0] ); + fprintf( stderr, ">\n%s\n", mseq2[0] ); + fprintf( stderr, "wm = %f\n", wm ); +#endif + + return( wm ); +} Added: test-suite/trunk/MultiSource/Benchmarks/mafft/Halignmm.c URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/Halignmm.c?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/Halignmm.c (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/Halignmm.c Thu Feb 19 06:37:59 2009 @@ -0,0 +1,1419 @@ +#include "mltaln.h" +#include "dp.h" + +#define MACHIGAI 0 +#define OUTGAP0TRY 1 +#define DEBUG 0 +#define XXXXXXX 0 +#define USE_PENALTY_EX 0 +#define FASTMATCHCALC 1 + +static float **impmtx = NULL; + +#if 0 // by D.Mathog +static float countnocountxx( Gappat *pat1, float diaf1, Gappat *pat2, int offset1, int offset2 ) +{ +// return( 0.0 ); + float gclose; + float gmatch; + Gappat *pat1bk = pat1; + Gappat *pat2bk = pat2; + + gmatch = 0.0; + for( pat2=pat2bk+1; pat2->len != 0; pat2++ ) // excl. len=0 + { + if( pat2->len + offset2 == offset1 ) + { + gmatch = diaf1 * pat2->freq; + } + } + for( pat1=pat1bk+1; pat1->len != 0; pat1++ ) // excl. len=0 + { + for( pat2=pat2bk+1; pat2->len != 0; pat2++ ) // excl. len=0 + { + if( pat1->len + offset1 == pat2->len + offset2 ) + { + gmatch += pat1->freq * pat2->freq; +// if( r ) fprintf( stderr, "match1!!, len=%d, gmatch=%f * %f\n", pat2->len, pat1->freq, pat2->freq ); + } + } + } + return( gmatch ); +} +#endif + +static float countnocountmatchx( Gappat *pat1, Gappat *pat2, int offset1, int offset2, int r ) +{ + Gappat *pat1bk = pat1; + Gappat *pat2bk = pat2; + float val = 0.0; + // pat1[][0] ha total gap. + for( pat1=pat1bk+1; pat1->len != 0; pat1++ ) + { + for( pat2=pat2bk+1; pat2->len != 0; pat2++ ) + { + if( pat1->len + offset1 == pat2->len + offset2 ) + { + val += pat1->freq * pat2->freq; + if( r ) fprintf( stderr, "y %d-%d, len=%d,%d, val = %f\n", (int)(pat1-pat1bk), (int)(pat2-pat2bk), pat1->len, pat2->len, val ); // 070405 +// if( r ) fprintf( stderr, "y %d-%d, len=%d,%d, val = %f\n", pat1-pat1bk, pat2-pat2bk, pat1->len, pat2->len, val ); + } + } + } + if( r ) fprintf( stderr, "nocountmatch=%f\n", val ); + return( val ); +} + +#if 0 // by D.Mathog +static float countnocountmatch( Gappat *pat1, Gappat *pat2, int r ) +{ +// return( 0.0 ); + Gappat *pat1bk = pat1; + Gappat *pat2bk = pat2; + float val = 0.0; + // pat1[][0] ha total gap. + for( pat1=pat1bk+1; pat1->len != 0; pat1++ ) + { +// if( r ) fprintf( stderr, "b %d-%d, len=%d,%d\n", pat1-pat1bk, pat2-pat2bk, pat1->len, pat2->len ); + for( pat2=pat2bk+1; pat2->len != 0; pat2++ ) + { + if( pat1->len == pat2->len ) + { +// if( r ) fprintf( stderr, " x%d-%d, len=%d,%d\n", pat1-pat1bk, pat2-pat2bk, pat1->len, pat2->len ); + val += pat1->freq * pat2->freq; +// if( r ) fprintf( stderr, "y %d-%d, val = %f\n", pat1-pat1bk, pat2-pat2bk,val ); +// if( r ) fprintf( stderr, "z tsugi, %d-%d, len=%d,%d\n", pat1-pat1bk+1, pat2-pat2bk+1, (pat1+1)->len, (pat2+1)->len ); + } +// if( r ) fprintf( stderr, "a %d-%d, len=%d,%d\n", pat1-pat1bk, pat2-pat2bk, pat1->len, pat2->len ); + } + } +// fprintf( stderr, "nocountmatch=%f\n", val ); + return( val ); +} +#endif + +static float countnocountx( Gappat *pat1, float diaf1, Gappat *pat2, int offset1, int r ) +{ +// return( 0.0 ); + float gmatch; + Gappat *pat1bk = pat1; + Gappat *pat2bk = pat2; + + gmatch = 0.0; + for( pat2=pat2bk+1; pat2->len != 0; pat2++ ) // excl. len=0 + { + if( pat2->len == offset1 ) + { + gmatch = diaf1 * pat2->freq; +// if( r ) fprintf( stderr, "match0!!, len=%d, gmatch=%f * %f\n", pat2->len, diaf1, pat2->freq ); + } + } + for( pat1=pat1bk+1; pat1->len != 0; pat1++ ) // excl. len=0 + { + for( pat2=pat2bk+1; pat2->len != 0; pat2++ ) // excl. len=0 + { + if( pat1->len + offset1 == pat2->len ) + { + gmatch += pat1->freq * pat2->freq; +// if( r ) fprintf( stderr, "match1!!, len=%d, gmatch=%f * %f\n", pat2->len, pat1->freq, pat2->freq ); + } + } + } + return( gmatch ); +} + +#if 0 // by D.Mathog +static float countnocount( Gappat *pat1, Gappat *pat2, int offset1, int offset2 ) //osoi +{ +// return( 0.0 ); + Gappat *pat1bk = pat1; + Gappat *pat2bk = pat2; + float val = 0.0; + // pat1[][0] ha total gap. + for( pat1=pat1bk+1; pat1->len != -1; pat1++ ) + { + for( pat2=pat2bk+1; pat2->len != -1; pat2++ ) + { + if( pat1->len+offset1 == pat2->len+offset2 ) + { + val += pat1->freq * pat2->freq; + } + } + } +// fprintf( stderr, "nocount=%f\n", val ); + return( val ); +} +#endif + + + +#if 1 // tditeration +float imp_match_out_scH( int i1, int j1 ) +{ +// fprintf( stderr, "imp+match = %f\n", impmtx[i1][j1] * fastathreshold ); +// fprintf( stderr, "val = %f\n", impmtx[i1][j1] ); + return( impmtx[i1][j1] ); +} +#endif + +static void imp_match_out_veadH( float *imp, int i1, int lgth2 ) +{ +#if FASTMATCHCALC + float *pt = impmtx[i1]; + while( lgth2-- ) + *imp++ += *pt++; +#else + int j; + float *pt = impmtx[i1]; + for( j=0; jstart1 ); +// fprintf( stderr, "end1 = %d\n", tmpptr->end1 ); +// fprintf( stderr, "i = %d, seq1 = \n%s\n", i, seq1[i] ); +// fprintf( stderr, "j = %d, seq2 = \n%s\n", j, seq2[j] ); + pt = seq1[i]; + tmpint = -1; + while( *pt != 0 ) + { + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->start1 ) break; + } + start1 = pt - seq1[i] - 1; + + if( tmpptr->start1 == tmpptr->end1 ) end1 = start1; + else + { +#if MACHIGAI + while( *pt != 0 ) + { +// fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] ); + if( tmpint == tmpptr->end1 ) break; + if( *pt++ != '-' ) tmpint++; + } + end1 = pt - seq1[i] - 0; +#else + while( *pt != 0 ) + { +// fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] ); + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->end1 ) break; + } + end1 = pt - seq1[i] - 1; +#endif + } + + pt = seq2[j]; + tmpint = -1; + while( *pt != 0 ) + { + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->start2 ) break; + } + start2 = pt - seq2[j] - 1; + if( tmpptr->start2 == tmpptr->end2 ) end2 = start2; + else + { +#if MACHIGAI + while( *pt != 0 ) + { + if( tmpint == tmpptr->end2 ) break; + if( *pt++ != '-' ) tmpint++; + } + end2 = pt - seq2[j] - 0; +#else + while( *pt != 0 ) + { + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->end2 ) break; + } + end2 = pt - seq2[j] - 1; +#endif + } +// fprintf( stderr, "start1 = %d (%c), end1 = %d (%c), start2 = %d (%c), end2 = %d (%c)\n", start1, seq1[i][start1], end1, seq1[i][end1], start2, seq2[j][start2], end2, seq2[j][end2] ); +// fprintf( stderr, "step 0\n" ); + if( end1 - start1 != end2 - start2 ) + { +// fprintf( stderr, "CHUUI!!, start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 ); + } + +#if 1 + k1 = start1; k2 = start2; + pt1 = seq1[i] + k1; + pt2 = seq2[j] + k2; + while( *pt1 && *pt2 ) + { + if( *pt1 != '-' && *pt2 != '-' ) + { +// ?????????????????????????????????????????? +// impmtx[k1][k2] += tmpptr->wimportance * fastathreshold; +// impmtx[k1][k2] += tmpptr->importance * effij; + impmtx[k1][k2] += tmpptr->fimportance * effij; +// fprintf( stderr, "#### impmtx[k1][k2] = %f, tmpptr->fimportance=%f, effij=%f\n", impmtx[k1][k2], tmpptr->fimportance, effij ); +// fprintf( stderr, "mark, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); +// fprintf( stderr, "%d (%c) - %d (%c) - %f\n", k1, *pt1, k2, *pt2, tmpptr->fimportance * effij ); + k1++; k2++; + pt1++; pt2++; + } + else if( *pt1 != '-' && *pt2 == '-' ) + { +// fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); + k2++; pt2++; + } + else if( *pt1 == '-' && *pt2 != '-' ) + { +// fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); + k1++; pt1++; + } + else if( *pt1 == '-' && *pt2 == '-' ) + { +// fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); + k1++; pt1++; + k2++; pt2++; + } + if( k1 > end1 || k2 > end2 ) break; + } +#else + while( k1 <= end1 && k2 <= end2 ) + { + fprintf( stderr, "k1,k2=%d,%d - ", k1, k2 ); + if( !nocount1[k1] && !nocount2[k2] ) + { + impmtx[k1][k2] += tmpptr->wimportance * eff1[i] * eff2[j] * fastathreshold; + fprintf( stderr, "marked\n" ); + } + else + fprintf( stderr, "no count\n" ); + k1++; k2++; + } +#endif + tmpptr = tmpptr->next; + } + } + } +#if 0 + if( clus1 == 1 && clus2 == 6 ) + { + fprintf( stderr, "\n" ); + fprintf( stderr, "seq1[0] = %s\n", seq1[0] ); + fprintf( stderr, "seq2[0] = %s\n", seq2[0] ); + fprintf( stderr, "impmtx = \n" ); + for( k2=0; k2-1 ) + *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++; + matchpt++; + } + } +#else + int j, k, l; + float scarr[26]; + float **cpmxpd = floatwork; + int **cpmxpdn = intwork; +// simple + if( initialize ) + { + int count = 0; + for( j=0; j-1; k++ ) + match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j]; + } +#endif +} + +static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *lastverticalw, + char **seq1, char **seq2, + char **mseq1, char **mseq2, + float **cpmx1, float **cpmx2, + int **ijp, int icyc, int jcyc ) +{ + int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k; + float wm; + char *gaptable1, *gt1bk; + char *gaptable2, *gt2bk; + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); + gt1bk = AllocateCharVec( lgth1+lgth2+1 ); + gt2bk = AllocateCharVec( lgth1+lgth2+1 ); + +#if 0 + for( i=0; i= wm ) + { + wm = lastverticalw[i]; + iin = i; jin = lgth2-1; + ijp[lgth1][lgth2] = +( lgth1 - i ); + } + } + for( j=0; j= wm ) + { + wm = lasthorizontalw[j]; + iin = lgth1-1; jin = j; + ijp[lgth1][lgth2] = -( lgth2 - j ); + } + } + } + + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + } + if( iin == lgth1 || jin == lgth2 ) + ; + else + { + *impwmpt += imp_match_out_scH( iin, jin ); + +// fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] ); + } + if( iin <= 0 || jin <= 0 ) break; + *--gaptable1 = 'o'; + *--gaptable2 = 'o'; + k++; + iin = ifi; jin = jfi; + } + + for( i=0; i= wm ) + { + wm = lastverticalw[i]; + iin = i; jin = lgth2-1; + ijp[lgth1][lgth2] = +( lgth1 - i ); + } + } + for( j=0; j= wm ) + { + wm = lasthorizontalw[j]; + iin = lgth1-1; jin = j; + ijp[lgth1][lgth2] = -( lgth2 - j ); + } + } + } + + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + } + if( iin <= 0 || jin <= 0 ) break; + *--gaptable1 = 'o'; + *--gaptable2 = 'o'; + k++; + iin = ifi; jin = jfi; + } + + for( i=0; i lgth1, outgap == 1 -> lgth1+1 */ + int lgth1, lgth2; + int resultlen; + float wm = 0.0; /* int ?????? */ + float g; + float *currentw, *previousw; +// float fpenalty = (float)penalty; +#if USE_PENALTY_EX + float fpenalty_ex = (float)penalty_ex; +#endif +#if 1 + float *wtmp; + int *ijppt; + float *mjpt, *prept, *curpt; + int *mpjpt; +#endif + static float mi, *m; + static int **ijp; + static int mpi, *mp; + static float *w1, *w2; + static float *match; + static float *initverticalw; /* kufuu sureba iranai */ + static float *lastverticalw; /* kufuu sureba iranai */ + static char **mseq1; + static char **mseq2; + static char **mseq; + static Gappat **gappat1; + static Gappat **gappat2; + static float *digf1; + static float *digf2; + static float *diaf1; + static float *diaf2; + static float *gapz1; + static float *gapz2; + static float *gapf1; + static float *gapf2; + static float *ogcp1g; + static float *ogcp2g; + static float *fgcp1g; + static float *fgcp2g; + static float *ogcp1; + static float *ogcp2; + static float *fgcp1; + static float *fgcp2; + static float **cpmx1; + static float **cpmx2; + static int **intwork; + static float **floatwork; + static int orlgth1 = 0, orlgth2 = 0; + float fpenalty = (float)penalty; + float tmppenal; + float cumpenal; + float *fgcp2pt; + float *ogcp2pt; + float fgcp1va; + float ogcp1va; + int maegap; + + + +#if 0 + fprintf( stderr, "#### eff in SA+++align\n" ); + fprintf( stderr, "#### seq1[0] = %s\n", seq1[0] ); + fprintf( stderr, "#### strlen( seq1[0] ) = %d\n", strlen( seq1[0] ) ); + for( i=0; i orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + + FreeCharMtx( mseq ); + + free( gappat1 ); + free( gappat2 ); + FreeFloatVec( digf1 ); + FreeFloatVec( digf2 ); + FreeFloatVec( diaf1 ); + FreeFloatVec( diaf2 ); + FreeFloatVec( gapz1 ); + FreeFloatVec( gapz2 ); + FreeFloatVec( gapf1 ); + FreeFloatVec( gapf2 ); + FreeFloatVec( ogcp1 ); + FreeFloatVec( ogcp2 ); + FreeFloatVec( fgcp1 ); + FreeFloatVec( fgcp2 ); + FreeFloatVec( ogcp1g ); + FreeFloatVec( ogcp2g ); + FreeFloatVec( fgcp1g ); + FreeFloatVec( fgcp2g ); + + + FreeFloatMtx( cpmx1 ); + FreeFloatMtx( cpmx2 ); + + FreeFloatMtx( floatwork ); + FreeIntMtx( intwork ); + } + + ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100; + +#if DEBUG + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); +#endif + + w1 = AllocateFloatVec( ll2+2 ); + w2 = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + + m = AllocateFloatVec( ll2+2 ); + mp = AllocateIntVec( ll2+2 ); + + mseq = AllocateCharMtx( njob, ll1+ll2 ); + + digf1 = AllocateFloatVec( ll1+2 ); + digf2 = AllocateFloatVec( ll2+2 ); + diaf1 = AllocateFloatVec( ll1+2 ); + diaf2 = AllocateFloatVec( ll2+2 ); + gappat1 = (Gappat **)calloc( ll1+2, sizeof( Gappat * ) ); + gappat2 = (Gappat **)calloc( ll2+2, sizeof( Gappat * ) ); + gapz1 = AllocateFloatVec( ll1+2 ); + gapz2 = AllocateFloatVec( ll2+2 ); + gapf1 = AllocateFloatVec( ll1+2 ); + gapf2 = AllocateFloatVec( ll2+2 ); + ogcp1 = AllocateFloatVec( ll1+2 ); + ogcp2 = AllocateFloatVec( ll2+2 ); + fgcp1 = AllocateFloatVec( ll1+2 ); + fgcp2 = AllocateFloatVec( ll2+2 ); + ogcp1g = AllocateFloatVec( ll1+2 ); + ogcp2g = AllocateFloatVec( ll2+2 ); + fgcp1g = AllocateFloatVec( ll1+2 ); + fgcp2g = AllocateFloatVec( ll2+2 ); + + cpmx1 = AllocateFloatMtx( 26, ll1+2 ); + cpmx2 = AllocateFloatMtx( 26, ll2+2 ); + +#if FASTMATCHCALC + floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); + intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); +#else + floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); +#endif + +#if DEBUG + fprintf( stderr, "succeeded\n" ); +#endif + + orlgth1 = ll1 - 100; + orlgth2 = ll2 - 100; + } + + + for( i=0; i commonAlloc1 || orlgth2 > commonAlloc2 ) + { + int ll1, ll2; + + if( commonAlloc1 && commonAlloc2 ) + { + FreeIntMtx( commonIP ); + } + + ll1 = MAX( orlgth1, commonAlloc1 ); + ll2 = MAX( orlgth2, commonAlloc2 ); + +#if DEBUG + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + + commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + +#if DEBUG + fprintf( stderr, "succeeded\n\n" ); +#endif + + commonAlloc1 = ll1; + commonAlloc2 = ll2; + } + ijp = commonIP; + +#if 0 + { + float t = 0.0; + for( i=0; i tbfast.c + if( localhom ) + imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 ); + +#endif + + if( outgap == 1 ) + { +// if( g ) fprintf( stderr, "init-match penal1=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] ); +// initverticalw[0] += g; +// currentw[0] += g; + +// if( g ) fprintf( stderr, "init-match penal2=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] ); +// initverticalw[0] += g; +// currentw[0] += g; + + for( i=1; i", wm ); +#endif +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif +// tmppenal = fpenalty; + tmppenal = diaf2[j] * ( 1.0 - gapf1[i] ) * fpenalty; + if( gappat2[j][0].freq ) + { + tmppenal += ( gappat2[j][0].freq ) * ( 1.0 - gapf1[i] ) * fpenalty; +// tmppenal -= ( countnocountx( gappat1[i], diaf1[i], gappat2[j], j-mpi-1, 0 ) ) * fpenalty; + maegap = ijp[i-1][mpi]; + maegap = 0; + if( maegap == 0 ) + { + tmppenal -= ( countnocountx( gappat1[i], diaf1[i], gappat2[j], j-mpi-1, 0 ) ) * fpenalty; + } +#if 0 // attahouga yoi hazu + else if( maegap < 0 ) // i jump + { + maegap = -maegap; + tmppenal -= ( countnocountxx( gappat1[i], diaf1[i], gappat2[j], j-mpi-1+maegap, 0 ) ) * fpenalty; + } + else // j jump + { + tmppenal -= ( countnocountxx( gappat1[i], diaf1[i], gappat2[j], j-mpi-1, maegap ) ) * fpenalty; + } +#endif + } + if( (g=mi+tmppenal) > wm ) + { +// if( seq1[0][i] == 'A' && seq2[0][j] == 'A' ) fprintf( stderr, "jump i start=%f (i,j=%d,%d, *ijppt=%d, digf2[j]=%f, diaf2[j]=%f), %c-%c\n", g-mi, i, j, -(j-mpi), digf2[j], diaf2[j], seq1[0][i], seq2[0][j] ); + wm = g; + *ijppt = -( j - mpi ); + } + if( (g=*prept) >= mi ) + { +// fprintf( stderr, "jump i end=%f, %c-%c\n", g-*prept, seq1[0][i-1], seq2[0][j-1] ); + mi = g; + mpi = j-1; + } + else if( j != 1 ) + { +// mi += ( ogcp2g[j-0] + fgcp2g[j] ) * fpenalty * 0.5; +// fprintf( stderr, "%c%c/%c%c exp, og=%f,fg=%f\n", '=', '=', seq2[0][j-1], seq2[0][j], ogcp2g[j-0] * fpenalty*0.5, fgcp2g[j] * fpenalty*0.5 ); + } +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + +// tmppenal = fpenalty; + tmppenal = diaf1[i] * ( 1.0 - gapf2[j] ) * fpenalty; + if( gappat1[i][0].freq ) + { + tmppenal += ( gappat1[i][0].freq ) * ( 1.0 - gapf2[j] ) * fpenalty; +// tmppenal -= ( countnocountx( gappat2[j], diaf2[j], gappat1[i], i-*mpjpt-1, 1 ) ) * fpenalty; + maegap = ijp[*mpjpt][j-1]; + if( maegap == 0 ) + { + tmppenal -= ( countnocountx( gappat2[j], diaf2[j], gappat1[i], i-*mpjpt-1, 1 ) ) * fpenalty; + } +#if 0 // attahouga yoi hazu + else if( maegap > 0 ) // j jump + { + tmppenal -= ( countnocountxx( gappat2[j], diaf2[j], gappat1[i], i-*mpjpt-1+maegap, 0 ) ) * fpenalty; + } + else // i jump + { + maegap = -maegap; + tmppenal -= ( countnocountxx( gappat2[j], diaf2[j], gappat1[i], i-*mpjpt-1, maegap ) ) * fpenalty; + } +#endif + } + if( (g=*mjpt+tmppenal) > wm ) + { +// if( seq1[0][i] == 'S' && seq2[0][j] == 'S' ) fprintf( stderr, "jump j start at %d, %d, g=%f, %c-%c\n", i, j, g-*mjpt, seq1[0][i], seq2[0][j] ); + wm = g; + *ijppt = +( i - *mpjpt ); + } + if( (g=*prept) >= *mjpt ) + { +// fprintf( stderr, "jump j end=%f, %c-%c\n", g-*prept, seq1[0][i-1], seq2[0][j-1] ); + *mjpt = g; + *mpjpt = i-1; + } + else if( i != 1 ) + { +// m[j] += ( ogcp1g[i-0] + fgcp1g[i] ) * fpenalty * 0.5; +// fprintf( stderr, "%c%c/%c%c exp, og=%f,fg=%f\n", seq1[0][i-1], seq1[0][i], '=', '=', ogcp1g[i-0] * fpenalty*0.5, fgcp1g[i] * fpenalty*0.5 ); + } +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + *curpt++ += wm; + ijppt++; + mjpt++; + prept++; + mpjpt++; + fgcp2pt++; + ogcp2pt++; + } + lastverticalw[i] = currentw[lgth2-1]; + } + +// fprintf( stderr, "wm = %f\n", wm ); + +#if OUTGAP0TRY + if( !outgap ) + { + for( j=1; j" ); + for( i=0; i N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } + + + for( i=0; i -1 ) + *fpt2 += scarr[*ipt++] * *fpt++; + fpt2++,iptpt++,fptpt++; + } + } +#else + for( j=0; j-1; k++ ) + match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j]; + } +#endif +} +#endif + +static float Ltracking( float *lasthorizontalw, float *lastverticalw, + char **seq1, char **seq2, + char **mseq1, char **mseq2, + int **ijp, int *off1pt, int *off2pt, int endi, int endj ) +{ + int i, j, l, iin, jin, lgth1, lgth2, k, limk; + int ifi=0, jfi=0; // by D.Mathog, a guess + char gap[] = "-"; + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); + +#if 0 + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + *--mseq1[0] = seq1[0][ifi+l]; + *--mseq2[0] = *gap; + k++; + } + l= jin - jfi; + while( --l ) + { + *--mseq1[0] = *gap; + *--mseq2[0] = seq2[0][jfi+l]; + k++; + } + + if( iin <= 0 || jin <= 0 ) break; + *--mseq1[0] = seq1[0][ifi]; + *--mseq2[0] = seq2[0][jfi]; + if( ijp[ifi][jfi] == localstop ) break; + k++; + iin = ifi; jin = jfi; + } + if( ifi == -1 ) *off1pt = 0; else *off1pt = ifi; + if( jfi == -1 ) *off2pt = 0; else *off2pt = jfi; + +// fprintf( stderr, "ifn = %d, jfn = %d\n", ifi, jfi ); + + + return( 0.0 ); +} + + +float L__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt ) +/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ +{ +// int k; + register int i, j; + int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */ + int lgth1, lgth2; + int resultlen; + float wm = 0.0; /* int ?????? */ + float g; + float *currentw, *previousw; +#if 1 + float *wtmp; + int *ijppt; + float *mjpt, *prept, *curpt; + int *mpjpt; +#endif + static float mi, *m; + static int **ijp; + static int mpi, *mp; + static float *w1, *w2; + static float *match; + static float *initverticalw; /* kufuu sureba iranai */ + static float *lastverticalw; /* kufuu sureba iranai */ + static char **mseq1; + static char **mseq2; + static char **mseq; +// static int **intwork; +// static float **floatwork; + static int orlgth1 = 0, orlgth2 = 0; + float maxwm; + int endali = 0, endalj = 0; // by D.Mathog, a guess +// int endali, endalj; + float localthr = -offset; + float localthr2 = -offset; +// float localthr = 100; +// float localthr2 = 100; + float fpenalty = (float)penalty; + float fpenalty_ex = (float)penalty_ex; + + + if( orlgth1 == 0 ) + { + mseq1 = AllocateCharMtx( njob, 0 ); + mseq2 = AllocateCharMtx( njob, 0 ); + } + + + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); + + if( lgth1 > orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + + FreeCharMtx( mseq ); + + + +// FreeFloatMtx( floatwork ); +// FreeIntMtx( intwork ); + } + + ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100; + +#if DEBUG + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); +#endif + + w1 = AllocateFloatVec( ll2+2 ); + w2 = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + + m = AllocateFloatVec( ll2+2 ); + mp = AllocateIntVec( ll2+2 ); + + mseq = AllocateCharMtx( njob, ll1+ll2 ); + + +// floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); +// intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); + +#if DEBUG + fprintf( stderr, "succeeded\n" ); +#endif + + orlgth1 = ll1 - 100; + orlgth2 = ll2 - 100; + } + + + mseq1[0] = mseq[0]; + mseq2[0] = mseq[1]; + + + if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 ) + { + int ll1, ll2; + + if( commonAlloc1 && commonAlloc2 ) + { + FreeIntMtx( commonIP ); + } + + ll1 = MAX( orlgth1, commonAlloc1 ); + ll2 = MAX( orlgth2, commonAlloc2 ); + +#if DEBUG + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + + commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + +#if DEBUG + fprintf( stderr, "succeeded\n\n" ); +#endif + + commonAlloc1 = ll1; + commonAlloc2 = ll2; + } + ijp = commonIP; + + +#if 0 + for( i=0; i", wm ); +#endif +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( (g=mi+fpenalty) > wm ) + { + wm = g; + *ijppt = -( j - mpi ); + } + if( *prept > mi ) + { + mi = *prept; + mpi = j-1; + } + +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( (g=*mjpt+fpenalty) > wm ) + { + wm = g; + *ijppt = +( i - *mpjpt ); + } + if( *prept > *mjpt ) + { + *mjpt = *prept; + *mpjpt = i-1; + } +#if USE_PENALTY_EX + *mjpt += fpenalty_ex; +#endif + + if( maxwm < wm ) + { + maxwm = wm; + endali = i; + endalj = j; + } +#if 1 + if( wm < localthr ) + { +// fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt ); + *ijppt = localstop; + wm = localthr2; + } +#endif +#if 0 + fprintf( stderr, "%5.0f ", *curpt ); +#endif +#if DEBUG2 + fprintf( stderr, "%5.0f ", wm ); +// fprintf( stderr, "%c-%c *ijppt = %d, localstop = %d\n", seq1[0][i], seq2[0][j], *ijppt, localstop ); +#endif + + *curpt++ += wm; + ijppt++; + mjpt++; + prept++; + mpjpt++; + } +#if DEBUG2 + fprintf( stderr, "\n" ); +#endif + + lastverticalw[i] = currentw[lgth2-1]; + } + + +#if 0 + fprintf( stderr, "maxwm = %f\n", maxwm ); + fprintf( stderr, "endali = %d\n", endali ); + fprintf( stderr, "endalj = %d\n", endalj ); +#endif + + if( ijp[endali][endalj] == localstop ) + { + strcpy( seq1[0], "" ); + strcpy( seq2[0], "" ); + *off1pt = *off2pt = 0; + return( 0.0 ); + } + + Ltracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, off1pt, off2pt, endali, endalj ); + + + resultlen = strlen( mseq1[0] ); + if( alloclen < resultlen || resultlen > N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } + + + strcpy( seq1[0], mseq1[0] ); + strcpy( seq2[0], mseq2[0] ); + +#if 0 + fprintf( stderr, "wm=%f\n", wm ); + fprintf( stderr, ">\n%s\n", mseq1[0] ); + fprintf( stderr, ">\n%s\n", mseq2[0] ); + + fprintf( stderr, "maxwm = %f\n", maxwm ); + fprintf( stderr, " wm = %f\n", wm ); +#endif + + return( maxwm ); +} + Added: test-suite/trunk/MultiSource/Benchmarks/mafft/Lalignmm.c URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/Lalignmm.c?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/Lalignmm.c (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/Lalignmm.c Thu Feb 19 06:37:59 2009 @@ -0,0 +1,2685 @@ +#include "mltaln.h" +#include "dp.h" + +#define MEMSAVE 1 + +#define DEBUG 0 +#define USE_PENALTY_EX 0 +#define STOREWM 1 + +#define DPTANNI 10 + +#define LOCAL 0 + +static int reccycle = 0; + +static float localthr; + +static void match_ribosum( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize ) +{ + int j, k, l; + float scarr[38]; + float **cpmxpd = floatwork; + int **cpmxpdn = intwork; + int count = 0; + float *matchpt; + float **cpmxpdpt; + int **cpmxpdnpt; + int cpkd; + + if( initialize ) + { + for( j=0; j -1 ) + *fpt2 += scarr[*ipt++] * *fpt++; + fpt2++,iptpt++,fptpt++; + } + } + for( j=0; j-1; k++ ) + match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k]; + } +#else + matchpt = match; + cpmxpdnpt = cpmxpdn; + cpmxpdpt = cpmxpd; + while( lgth2-- ) + { + *matchpt = 0.0; + for( k=0; (cpkd=(*cpmxpdnpt)[k])>-1; k++ ) + *matchpt += scarr[cpkd] * (*cpmxpdpt)[k]; + matchpt++; + cpmxpdnpt++; + cpmxpdpt++; + } +#endif +} + +static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize ) +{ + int j, k, l; + float scarr[26]; + float **cpmxpd = floatwork; + int **cpmxpdn = intwork; + int count = 0; + float *matchpt; + float **cpmxpdpt; + int **cpmxpdnpt; + int cpkd; + + if( initialize ) + { + for( j=0; j -1 ) + *fpt2 += scarr[*ipt++] * *fpt++; + fpt2++,iptpt++,fptpt++; + } + } + for( j=0; j-1; k++ ) + match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k]; + } +#else + matchpt = match; + cpmxpdnpt = cpmxpdn; + cpmxpdpt = cpmxpd; + while( lgth2-- ) + { + *matchpt = 0.0; + for( k=0; (cpkd=(*cpmxpdnpt)[k])>-1; k++ ) + *matchpt += scarr[cpkd] * (*cpmxpdpt)[k]; + matchpt++; + cpmxpdnpt++; + cpmxpdpt++; + } +#endif +} + +#if 0 +static void match_add( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize ) +{ + int j, k, l; + float scarr[26]; + float **cpmxpd = floatwork; + int **cpmxpdn = intwork; + int count = 0; + float *matchpt; + float **cpmxpdpt; + int **cpmxpdnpt; + int cpkd; + + + if( initialize ) + { + for( j=0; j -1 ) + *fpt2 += scarr[*ipt++] * *fpt++; + fpt2++,iptpt++,fptpt++; + } + } + for( j=0; j-1; k++ ) + match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k]; + } +#else + matchpt = match; + cpmxpdnpt = cpmxpdn; + cpmxpdpt = cpmxpd; + while( lgth2-- ) + { +// *matchpt = 0.0; // add dakara + for( k=0; (cpkd=(*cpmxpdnpt)[k])>-1; k++ ) + *matchpt += scarr[cpkd] * (*cpmxpdpt)[k]; + matchpt++; + cpmxpdnpt++; + cpmxpdpt++; + } +#endif +} +#endif + +#if 0 +static float Atracking( + char **seq1, char **seq2, + char **mseq1, char **mseq2, + int **ijp, int icyc, int jcyc, + int ist, int ien, int jst, int jen ) +{ + int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim; + char *gaptable1, *gt1bk; + char *gaptable2, *gt2bk; + lgth1 = ien-ist+1; + lgth2 = jen-jst+1; + + gt1bk = AllocateCharVec( lgth1+lgth2+1 ); + gt2bk = AllocateCharVec( lgth1+lgth2+1 ); + +#if 0 + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + } + if( iin <= 0 || jin <= 0 ) break; + *--gaptable1 = 'o'; + *--gaptable2 = 'o'; + k++; + iin = ifi; jin = jfi; + + } + + for( i=0; i", wm ); +#endif + g = mi + fgcp2[j-1]; +// g = mi + fpenalty; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; +// *ijppt = -( j - mpi ); + } + g = *prept + ogcp2[j]; +// g = *prept; + if( g >= mi ) + { + mi = g; + mpi = j-1; + } +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + + g = *mjpt + fgcp1[i-1]; +// g = *mjpt + fpenalty; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; +// *ijppt = +( i - *mpjpt ); + } + + + g = *prept + ogcp1[i]; +// g = *prept; + if( g >= *mjpt ) + { + *mjpt = g; + *mpjpt = i-1; + } +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif +#if LOCAL + if( wm < localthr ) + { +// fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt ); + wm = 0; + } +#endif + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + *curpt += wm; + + +#if STOREWM + WMMTX[i][j] = *curpt; + WMMTX2[i][j] = *mjpt; +#endif + + if( i == imid ) //muda + { + jumpbackj[j] = *mpjpt; // muda atode matomeru + jumpbacki[j] = mpi; // muda atode matomeru +// fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt ); +// fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi ); + midw[j] = *curpt; + midm[j] = *mjpt; + midn[j] = mi; + } + +// fprintf( stderr, "m[%d] = %f\n", j, m[j] ); + mjpt++; + prept++; + mpjpt++; + curpt++; + + } + lastverticalw[i] = currentw[lgth2-1]; + +#if STOREWM + WMMTX2[i][lgth2] = m[lgth2-1]; +#endif + +#if 0 // ue + if( i == imid ) + { + for( j=0; j0; --j ) + { + m[j-1] = currentw[j] + fgcp2[lgth2-2]; +// m[j-1] = currentw[j]; + mp[j] = lgth1-1; + } + +// for( j=0; j=imid; i-- ) + firstm = -9999999.9; + firstmp = lgth1-1; + for( i=lgth1-2; i>-1; i-- ) + { + wtmp = previousw; + previousw = currentw; + currentw = wtmp; + previousw[lgth2-1] = initverticalw[i+1]; +// match_calc( currentw, seq1, seq2, i, lgth2 ); + match_ribosum( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 ); + + currentw[lgth2-1] = initverticalw[i]; + +// m[lgth2] = fgcp1[i]; +// WMMTX2[i][lgth2] += m[lgth2]; +// fprintf( stderr, "m[] = %f\n", m[lgth2] ); + + mi = previousw[lgth2-1] + fgcp2[lgth2-2]; +// mi = previousw[lgth2-1]; + mpi = lgth2 - 1; + + mjpt = m + lgth2 - 2; + prept = previousw + lgth2 - 1; + curpt = currentw + lgth2 - 2; + mpjpt = mp + lgth2 - 2; + + + for( j=lgth2-2; j>-1; j-- ) + { + wm = *prept; + ijpi = i+1; + ijpj = j+1; + + g = mi + ogcp2[j+1]; +// g = mi + fpenalty; + if( g > wm ) + { + wm = g; + ijpj = mpi; + ijpi = i+1; + } + + g = *prept + fgcp2[j]; +// g = *prept; + if( g >= mi ) + { +// fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 ); + mi = g; + mpi = j + 1; + } + +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +// fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt ); + g = *mjpt + ogcp1[i+1]; +// g = *mjpt + fpenalty; + if( g > wm ) + { + wm = g; + ijpi = *mpjpt; + ijpj = j+1; + } + +// if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j ); + g = *prept + fgcp1[i]; +// g = *prept; + if( g >= *mjpt ) + { + *mjpt = g; + *mpjpt = i + 1; + } + +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + + if( i == jumpi || i == imid - 1 ) + { + jumpforwi[j] = ijpi; //muda + jumpforwj[j] = ijpj; //muda +// fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi ); +// fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj ); + } + if( i == imid ) // muda + { + midw[j] += wm; +// midm[j+1] += *mjpt + fpenalty; //?????? + midm[j+1] += *mjpt; //?????? + } + if( i == imid - 1 ) + { +// midn[j] += mi + fpenalty; //???? + midn[j] += mi; //???? + } +#if LOCAL + if( wm < localthr ) + { +// fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt ); + wm = 0; + } +#endif + +#if STOREWM + WMMTX[i][j] += wm; +// WMMTX2[i][j+1] += *mjpt + fpenalty; + WMMTX2[i][j] += *curpt; +#endif + *curpt += wm; + + mjpt--; + prept--; + mpjpt--; + curpt--; + } +// fprintf( stderr, "adding *mjpt (=%f) to WMMTX2[%d][%d]\n", *mjpt, i, j+1 ); + g = *prept + fgcp1[i]; + if( firstm < g ) + { + firstm = g; + firstmp = i + 1; + } +#if STOREWM +// WMMTX2[i][j+1] += firstm; +#endif + if( i == imid ) midm[j+1] += firstm; + + if( i == imid - 1 ) + { + maxwm = midw[1]; + jmid = 0; +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + for( j=2; j maxwm ) + { + jmid = j; + maxwm = wm; + } +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + } + for( j=0; j maxwm ) + { + jmid = j; + maxwm = wm; + } +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + } + +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + + +// fprintf( stderr, "### imid=%d, jmid=%d\n", imid, jmid ); + wm = midw[jmid]; + jumpi = imid-1; + jumpj = jmid-1; + if( jmid > 0 && midn[jmid-1] > wm ) //060413 + { + jumpi = imid-1; + jumpj = jumpbacki[jmid]; + wm = midn[jmid-1]; +// fprintf( stderr, "rejump (n)\n" ); + } + if( midm[jmid] > wm ) + { + jumpi = jumpbackj[jmid]; + jumpj = jmid-1; + wm = midm[jmid]; +// fprintf( stderr, "rejump (m) jumpi=%d\n", jumpi ); + } + + +// fprintf( stderr, "--> imid=%d, jmid=%d\n", imid, jmid ); +// fprintf( stderr, "--> jumpi=%d, jumpj=%d\n", jumpi, jumpj ); +#if 0 + fprintf( stderr, "imid = %d\n", imid ); + fprintf( stderr, "midn = \n" ); + for( j=0; j= lgth2 ) + { +// fprintf( stderr, "CHUI1!\n" ); + jumpi=imid-1; jmid=lgth2; + jumpj = lgth2-1; + } +#endif + else + { + imid = jumpforwi[jumpj]; + jmid = jumpforwj[jumpj]; + } +#if 0 + fprintf( stderr, "jumpi -> %d\n", jumpi ); + fprintf( stderr, "jumpj -> %d\n", jumpj ); + fprintf( stderr, "imid -> %d\n", imid ); + fprintf( stderr, "jmid -> %d\n", jmid ); +#endif + +#if STOREWM +// break; +#else + break; +#endif + } + } +#if 0 + jumpi=0; jumpj=0; + imid=lgth1-1; jmid=lgth2-1; + } +#endif + +// fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi ); +// fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj ); + +// for( j=0; j amino_dis['a']['g'] -1 ) + fprintf( stdout, "%d %d %8.1f", i, j, WMMTX[i][j] ); + if( WMMTX[i][j] == maxwm ) + fprintf( stdout, "selected \n" ); + else + fprintf( stdout, "\n" ); + } + fprintf( stdout, "\n" ); + } +#endif + +#if 0 + + fprintf( stderr, "jumpbacki = \n" ); + for( j=0; j N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } +#endif + + + +#if 0 + fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid ); + fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid ); + + fprintf( stderr, "imid = %d\n", imid ); + fprintf( stderr, "jmid = %d\n", jmid ); +#endif + + + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + FreeFloatVec( midw ); + FreeFloatVec( midm ); + FreeFloatVec( midn ); + + FreeIntVec( jumpbacki ); + FreeIntVec( jumpbackj ); + FreeIntVec( jumpforwi ); + FreeIntVec( jumpforwj ); + FreeIntVec( jumpdummi ); + FreeIntVec( jumpdummj ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + + FreeFloatMtx( floatwork ); + FreeIntMtx( intwork ); + +#if STOREWM + FreeFloatMtx( WMMTX ); + FreeFloatMtx( WMMTX2 ); +#endif + + return( value ); + +} +static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, int depth, float **gapinfo, float **map ) +/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ +{ + int alnlen; + float value = 0.0; + register int i, j; + char **aseq1, **aseq2; + int ll1, ll2, l, len; + int lasti, lastj, imid, jmid=0; + float wm = 0.0; /* int ?????? */ + float g; + float *currentw, *previousw; +#if USE_PENALTY_EX + float fpenalty_ex = (float)RNApenalty_ex; +#endif +// float fpenalty = (float)penalty; + float *wtmp; +// short *ijppt; + int *mpjpt; +// short **ijp; + int *mp; + int mpi; + float *mjpt, *prept, *curpt; + float mi; + float *m; + float *w1, *w2; +// float *match; + float *initverticalw; /* kufuu sureba iranai */ + float *lastverticalw; /* kufuu sureba iranai */ + int **intwork; + float **floatwork; +// short **shortmtx; +#if STOREWM + float **WMMTX; + float **WMMTX2; +#endif + float *midw; + float *midm; + float *midn; + int lgth1, lgth2; + float maxwm = 0.0; + int *jumpforwi; + int *jumpforwj; + int *jumpbacki; + int *jumpbackj; + int *jumpdummi; //muda + int *jumpdummj; //muda + int jumpi, jumpj = 0; + char *gaps; + int ijpi, ijpj; + float *ogcp1; + float *fgcp1; + float *ogcp2; + float *fgcp2; + float firstm; + int firstmp; +#if 0 + static char ttt1[50000]; + static char ttt2[50000]; +#endif + + localthr = -offset + 500; // 0? + + ogcp1 = gapinfo[0] + ist; + fgcp1 = gapinfo[1] + ist; + ogcp2 = gapinfo[2] + jst; + fgcp2 = gapinfo[3] + jst; + + depth++; + reccycle++; + + lgth1 = ien-ist+1; + lgth2 = jen-jst+1; + +// if( lgth1 < 5 ) +// fprintf( stderr, "\nWARNING: lgth1 = %d\n", lgth1 ); +// if( lgth2 < 5 ) +// fprintf( stderr, "\nWARNING: lgth2 = %d\n", lgth2 ); +// + +#if 0 + fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen ); + strncpy( ttt1, seq1[0]+ist, lgth1 ); + strncpy( ttt2, seq2[0]+jst, lgth2 ); + ttt1[lgth1] = 0; + ttt2[lgth2] = 0; + fprintf( stderr, "seq1 = %s\n", ttt1 ); + fprintf( stderr, "seq2 = %s\n", ttt2 ); +#endif + if( lgth2 <= 0 ) // lgth1 <= 0 ha? + { +// fprintf( stderr, "\n\n==== jimei\n\n" ); +// exit( 1 ); + for( i=0; i", wm ); +#endif + g = mi + fgcp2[j-1]; +// g = mi + fpenalty; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; +// *ijppt = -( j - mpi ); + } + g = *prept + ogcp2[j]; +// g = *prept; + if( g >= mi ) + { + mi = g; + mpi = j-1; + } +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + + g = *mjpt + fgcp1[i-1]; +// g = *mjpt + fpenalty; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; +// *ijppt = +( i - *mpjpt ); + } + + + g = *prept + ogcp1[i]; +// g = *prept; + if( g >= *mjpt ) + { + *mjpt = g; + *mpjpt = i-1; + } +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif +#if LOCAL + if( wm < localthr ) + { +// fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt ); + wm = 0; + } +#endif + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + *curpt += wm; + + +#if STOREWM + WMMTX[i][j] = *curpt; + WMMTX2[i][j] = *mjpt; +#endif + + if( i == imid ) //muda + { + jumpbackj[j] = *mpjpt; // muda atode matomeru + jumpbacki[j] = mpi; // muda atode matomeru +// fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt ); +// fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi ); + midw[j] = *curpt; + midm[j] = *mjpt; + midn[j] = mi; + } + +// fprintf( stderr, "m[%d] = %f\n", j, m[j] ); + mjpt++; + prept++; + mpjpt++; + curpt++; + + } + lastverticalw[i] = currentw[lgth2-1]; + +#if STOREWM + WMMTX2[i][lgth2] = m[lgth2-1]; +#endif + +#if 0 // ue + if( i == imid ) + { + for( j=0; j0; --j ) + { + m[j-1] = currentw[j] + fgcp2[lgth2-2]; +// m[j-1] = currentw[j]; + mp[j] = lgth1-1; + } + +// for( j=0; j=imid; i-- ) + firstm = -9999999.9; + firstmp = lgth1-1; + for( i=lgth1-2; i>-1; i-- ) + { + wtmp = previousw; + previousw = currentw; + currentw = wtmp; + previousw[lgth2-1] = initverticalw[i+1]; +// match_calc( currentw, seq1, seq2, i, lgth2 ); + match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 ); + + currentw[lgth2-1] = initverticalw[i]; + +// m[lgth2] = fgcp1[i]; +// WMMTX2[i][lgth2] += m[lgth2]; +// fprintf( stderr, "m[] = %f\n", m[lgth2] ); + + mi = previousw[lgth2-1] + fgcp2[lgth2-2]; +// mi = previousw[lgth2-1]; + mpi = lgth2 - 1; + + mjpt = m + lgth2 - 2; + prept = previousw + lgth2 - 1; + curpt = currentw + lgth2 - 2; + mpjpt = mp + lgth2 - 2; + + + for( j=lgth2-2; j>-1; j-- ) + { + wm = *prept; + ijpi = i+1; + ijpj = j+1; + + g = mi + ogcp2[j+1]; +// g = mi + fpenalty; + if( g > wm ) + { + wm = g; + ijpj = mpi; + ijpi = i+1; + } + + g = *prept + fgcp2[j]; +// g = *prept; + if( g >= mi ) + { +// fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 ); + mi = g; + mpi = j + 1; + } + +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +// fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt ); + g = *mjpt + ogcp1[i+1]; +// g = *mjpt + fpenalty; + if( g > wm ) + { + wm = g; + ijpi = *mpjpt; + ijpj = j+1; + } + +// if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j ); + g = *prept + fgcp1[i]; +// g = *prept; + if( g >= *mjpt ) + { + *mjpt = g; + *mpjpt = i + 1; + } + +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + + if( i == jumpi || i == imid - 1 ) + { + jumpforwi[j] = ijpi; //muda + jumpforwj[j] = ijpj; //muda +// fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi ); +// fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj ); + } + if( i == imid ) // muda + { + midw[j] += wm; +// midm[j+1] += *mjpt + fpenalty; //?????? + midm[j+1] += *mjpt; //?????? + } + if( i == imid - 1 ) + { +// midn[j] += mi + fpenalty; //???? + midn[j] += mi; //???? + } +#if LOCAL + if( wm < localthr ) + { +// fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt ); + wm = 0; + } +#endif + +#if STOREWM + WMMTX[i][j] += wm; +// WMMTX2[i][j+1] += *mjpt + fpenalty; + WMMTX2[i][j] += *curpt; +#endif + *curpt += wm; + + mjpt--; + prept--; + mpjpt--; + curpt--; + } +// fprintf( stderr, "adding *mjpt (=%f) to WMMTX2[%d][%d]\n", *mjpt, i, j+1 ); + g = *prept + fgcp1[i]; + if( firstm < g ) + { + firstm = g; + firstmp = i + 1; + } +#if STOREWM +// WMMTX2[i][j+1] += firstm; +#endif + if( i == imid ) midm[j+1] += firstm; + + if( i == imid - 1 ) + { + maxwm = midw[1]; + jmid = 0; +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + for( j=2; j maxwm ) + { + jmid = j; + maxwm = wm; + } +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + } + for( j=0; j maxwm ) + { + jmid = j; + maxwm = wm; + } +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + } + +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + + +// fprintf( stderr, "### imid=%d, jmid=%d\n", imid, jmid ); + wm = midw[jmid]; + jumpi = imid-1; + jumpj = jmid-1; + if( jmid > 0 && midn[jmid-1] > wm ) //060413 + { + jumpi = imid-1; + jumpj = jumpbacki[jmid]; + wm = midn[jmid-1]; +// fprintf( stderr, "rejump (n)\n" ); + } + if( midm[jmid] > wm ) + { + jumpi = jumpbackj[jmid]; + jumpj = jmid-1; + wm = midm[jmid]; +// fprintf( stderr, "rejump (m) jumpi=%d\n", jumpi ); + } + + +// fprintf( stderr, "--> imid=%d, jmid=%d\n", imid, jmid ); +// fprintf( stderr, "--> jumpi=%d, jumpj=%d\n", jumpi, jumpj ); +#if 0 + fprintf( stderr, "imid = %d\n", imid ); + fprintf( stderr, "midn = \n" ); + for( j=0; j= lgth2 ) + { +// fprintf( stderr, "CHUI1!\n" ); + jumpi=imid-1; jmid=lgth2; + jumpj = lgth2-1; + } +#endif + else + { + imid = jumpforwi[jumpj]; + jmid = jumpforwj[jumpj]; + } +#if 0 + fprintf( stderr, "jumpi -> %d\n", jumpi ); + fprintf( stderr, "jumpj -> %d\n", jumpj ); + fprintf( stderr, "imid -> %d\n", imid ); + fprintf( stderr, "jmid -> %d\n", jmid ); +#endif + +#if STOREWM +// break; +#else + break; +#endif + } + } +#if 0 + jumpi=0; jumpj=0; + imid=lgth1-1; jmid=lgth2-1; + } +#endif + +// fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi ); +// fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj ); + +// for( j=0; j amino_dis['a']['g'] -1 ) + fprintf( stdout, "%d %d %8.1f", i, j, WMMTX[i][j] ); + if( WMMTX[i][j] == maxwm ) + fprintf( stdout, "selected \n" ); + else + fprintf( stdout, "\n" ); + } + fprintf( stdout, "\n" ); + } + exit( 1 ); +#endif + +#if 0 + + fprintf( stderr, "jumpbacki = \n" ); + for( j=0; j N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } +#endif + + + +#if 0 + fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid ); + fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid ); + + fprintf( stderr, "imid = %d\n", imid ); + fprintf( stderr, "jmid = %d\n", jmid ); +#endif + + + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + FreeFloatVec( midw ); + FreeFloatVec( midm ); + FreeFloatVec( midn ); + + FreeIntVec( jumpbacki ); + FreeIntVec( jumpbackj ); + FreeIntVec( jumpforwi ); + FreeIntVec( jumpforwj ); + FreeIntVec( jumpdummi ); + FreeIntVec( jumpdummj ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + + FreeFloatMtx( floatwork ); + FreeIntMtx( intwork ); + +#if STOREWM + FreeFloatMtx( WMMTX ); + FreeFloatMtx( WMMTX2 ); +#endif + + return( value ); + +// fprintf( stderr, "==== calling myself (first)\n" ); + +#if 0 + fprintf( stderr, "seq1[0] = %s\n", seq1[0] ); + fprintf( stderr, "seq2[0] = %s\n", seq2[0] ); +#endif + value = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, aseq1, aseq2, depth, gapinfo, map ); +#if 0 + fprintf( stderr, "aseq1[0] = %s\n", aseq1[0] ); + fprintf( stderr, "aseq2[0] = %s\n", aseq2[0] ); +#endif +#if MEMSAVE +#else + for( i=0; i 0 ) + { + for( i=0; i 0 ) + { + for( i=0; i 1 || maxwm - value > 1 ) + { + fprintf( stderr, "WARNING value = %f, but maxwm = %f\n", value, maxwm ); + for( i=0; i1-%d\n%s\n", i, mseq1[i] ); + fprintf( stderr, "%s\n", aseq1[i] ); + } + for( i=0; i2-%d\n%s\n", i, mseq2[i] ); + fprintf( stderr, "%s\n", aseq2[i] ); + } + +// exit( 1 ); + } + else + { + fprintf( stderr, "value = %.0f, maxwm = %.0f -> ok\n", value, maxwm ); + } +#endif + +#if MEMSAVE +#else + for( i=0; i%d of GROUP1\n", i ); + fprintf( stdout, "%s\n", seq1[i] ); + } + for( i=0; i%d of GROUP2\n", i ); + fprintf( stdout, "%s\n", seq2[i] ); + } + fflush( stdout ); +#endif + + wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo, map ); +#if DEBUG + fprintf( stderr, " seq1[0] = %s\n", seq1[0] ); + fprintf( stderr, " seq2[0] = %s\n", seq2[0] ); + fprintf( stderr, "mseq1[0] = %s\n", mseq1[0] ); + fprintf( stderr, "mseq2[0] = %s\n", mseq2[0] ); +#endif + +// fprintf( stderr, "wm = %f\n", wm ); + +#if 0 + + for( i=0; i%d of GROUP1\n", i ); + fprintf( stdout, "%s\n", seq1[i] ); + } + for( i=0; i%d of GROUP2\n", i ); + fprintf( stdout, "%s\n", seq2[i] ); + } + fflush( stdout ); +#endif + + wm = MSalign2m2m_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo, map ); +#if DEBUG + fprintf( stderr, " seq1[0] = %s\n", seq1[0] ); + fprintf( stderr, " seq2[0] = %s\n", seq2[0] ); + fprintf( stderr, "mseq1[0] = %s\n", mseq1[0] ); + fprintf( stderr, "mseq2[0] = %s\n", mseq2[0] ); +#endif + +// fprintf( stderr, "wm = %f\n", wm ); + +#if 0 + + for( i=0; i0 ) + { + *--mseq1[0] = seq1[0][i+l--]; + *--mseq2[0] = *gap; + } + l= prevhitj - j - 1; + fprintf( stderr, "l=%d\n", l ); + while( l>0 ) + { + *--mseq1[0] = *gap; + *--mseq2[0] = seq2[0][j+l--]; + } + if( i < 0 || j < 0 ) return; + *--mseq1[0] = seq1[0][i]; + *--mseq2[0] = seq2[0][j]; + fprintf( stderr, "added %c to mseq1, mseq1 = %s \n", seq1[0][i], mseq1[0] ); + fprintf( stderr, "added %c to mseq2, mseq2 = %s \n", seq2[0][j], mseq2[0] ); +} + +static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) +{ + char tmpc = s1[0][i1]; + char *seq2 = s2[0]; + + while( lgth2-- ) + *match++ = amino_dis[(int)tmpc][(int)*seq2++]; +} + +static float Atracking( float *lasthorizontalw, float *lastverticalw, + char **seq1, char **seq2, + char **mseq1, char **mseq2, + float **cpmx1, float **cpmx2, + int **ijp ) +{ + int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, limk; + char gap[] = "-"; + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); + + +#if 0 + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + *--mseq1[0] = seq1[0][ifi+l]; + *--mseq2[0] = *gap; + k++; + } + l= jin - jfi; + while( --l ) + { + *--mseq1[0] = *gap; + *--mseq2[0] = seq2[0][jfi+l]; + k++; + } + if( iin <= 0 || jin <= 0 ) break; + *--mseq1[0] = seq1[0][ifi]; + *--mseq2[0] = seq2[0][jfi]; + k++; + iin = ifi; jin = jfi; + } + return( 0.0 ); +} + +void backdp( float **WMMTX, float wmmax, float *maxinw, float *maxinh, int lgth1, int lgth2, int alloclen, float *w1, float *w2, float *initverticalw, float *m, int *mp, int iin, int jin, char **seq1, char **seq2, char **mseq1, char **mseq2 ) +{ + register int i, j; + int prevhiti, prevhitj; +// int lasti, lastj; + float g; + float fpenalty = (float)penalty; +#if USE_PENALTY_EX + float fpenalty_ex = (float)penalty_ex; +#endif + float *currentw, *previousw, *wtmp; + float mi; + int mpi; + int *mpjpt; + float *mjpt, *prept, *curpt; + float wm = 0.0; + float forwwm; + + currentw = w1; + previousw = w2; + + match_calc( initverticalw, seq2, seq1, lgth2-1, lgth1 ); + match_calc( currentw, seq1, seq2, lgth1-1, lgth2 ); + + + prevhiti = iin; + prevhitj = jin; + fprintf( stderr, "prevhiti = %d, lgth1 = %d\n", prevhiti, lgth1 ); + fprintf( stderr, "prevhitj = %d, lgth2 = %d\n", prevhitj, lgth2 ); + extendmseq( mseq1, mseq2, seq1, seq2, prevhiti, prevhitj, lgth1, lgth2 ); + + for( i=0; i0; --j ) + { + m[j-1] = currentw[j]; + mp[j] = 0; // iranai + } + + for( j=0; j-1; i-- ) + { + wtmp = previousw; + previousw = currentw; + currentw = wtmp; + + previousw[lgth2-1] = initverticalw[i+1]; + + match_calc( currentw, seq1, seq2, i, lgth2 ); + +#if 0 + fprintf( stderr, "i=%d, currentw = \n", i ); + for( j=0; j-1; j-- ) + { + +// fprintf( stderr, "i,j=%d,%d %c-%c ", i, j, seq1[0][i], seq2[0][j] ); + wm = *prept; + g = mi + fpenalty; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; + } + g = *prept; + if( g >= mi ) + { + mi = g; + mpi = j+1; //iranai + } +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + + g = *mjpt + fpenalty; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; + } + g = *prept; + if( g >= *mjpt ) + { + *mjpt = g; + *mpjpt = i-1; //iranai + } +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "*curpt = %5.0f \n", *curpt ); +#endif + +// forwwm = wm + MIN( maxinw[i], maxinh[j] ); + forwwm = wm + MIN( maxinw[i], maxinh[j] ); + WMMTX[i][j] = forwwm; + if( forwwm == wmmax && i orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + FreeFloatVec( maxinw ); + FreeFloatVec( maxinh ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + + FreeCharMtx( mseq ); + + + FreeFloatMtx( cpmx1 ); + FreeFloatMtx( cpmx2 ); + + FreeFloatMtx( floatwork ); + FreeIntMtx( intwork ); + } + + ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100; + +#if DEBUG + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); +#endif + + w1 = AllocateFloatVec( ll2+2 ); + w2 = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + maxinw = AllocateFloatVec( ll1+2 ); + + + m = AllocateFloatVec( ll2+2 ); + mp = AllocateIntVec( ll2+2 ); + maxinh = AllocateFloatVec( ll2+2 ); + + mseq = AllocateCharMtx( njob, ll1+ll2 ); + + cpmx1 = AllocateFloatMtx( 26, ll1+2 ); + cpmx2 = AllocateFloatMtx( 26, ll2+2 ); + + floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); + +#if DEBUG + fprintf( stderr, "succeeded\n" ); +#endif + + orlgth1 = ll1 - 100; + orlgth2 = ll2 - 100; + } + + + mseq1[0] = mseq[0]; + mseq2[0] = mseq[1]; + + + if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 ) + { + int ll1, ll2; + + if( commonAlloc1 && commonAlloc2 ) + { + FreeIntMtx( commonIP ); + FreeFloatMtx( WMMTX ); + } + + ll1 = MAX( orlgth1, commonAlloc1 ); + ll2 = MAX( orlgth2, commonAlloc2 ); + +#if DEBUG + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + + commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + WMMTX = AllocateFloatMtx( ll1+10, ll2+10 ); + +#if DEBUG + fprintf( stderr, "succeeded\n\n" ); +#endif + + commonAlloc1 = ll1; + commonAlloc2 = ll2; + } + ijp = commonIP; + + +#if 0 + for( i=0; i", wm ); +#endif + g = mi + fpenalty; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; + *ijppt = -( j - mpi ); + } + g = *prept; + if( g >= mi ) + { + mi = g; + mpi = j-1; + } +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + + g = *mjpt + fpenalty; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; + *ijppt = +( i - *mpjpt ); + } + g = *prept; + if( g >= *mjpt ) + { + *mjpt = g; + *mpjpt = i-1; + } +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + *curpt += wm; + + WMMTX[i][j] = *curpt; + + + if( j wmmax ) + { + wmmax = g; + iin = i; + jin = lgth2-1; + } + } + for( j=0; j wmmax ) + { + wmmax = g; + iin = lgth1-1; + jin = j; + } + } + + for( i=0; iMSres\n%s\n", mseq1[0] ); + fprintf( stderr, ">MSres\n%s\n", mseq2[0] ); +#endif + +#if 0 + for( i=0; i N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } + + + strcpy( seq1[0], mseq1[0] ); + strcpy( seq2[0], mseq2[0] ); +#if 1 + fprintf( stderr, "\n" ); + fprintf( stderr, ">\n%s\n", mseq1[0] ); + fprintf( stderr, ">\n%s\n", mseq2[0] ); +#endif + + + return( wm ); +} + Added: test-suite/trunk/MultiSource/Benchmarks/mafft/MSalignmm.c URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/MSalignmm.c?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/MSalignmm.c (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/MSalignmm.c Thu Feb 19 06:37:59 2009 @@ -0,0 +1,1530 @@ +#include "mltaln.h" +#include "dp.h" + +#define MEMSAVE 1 + +#define DEBUG 0 +#define USE_PENALTY_EX 0 +#define STOREWM 0 + +#define DPTANNI 100 + + +static int reccycle = 0; + + +static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize ) +{ + int j, k, l; + float scarr[26]; + float **cpmxpd = floatwork; + int **cpmxpdn = intwork; + int count = 0; + float *matchpt; + float **cpmxpdpt; + int **cpmxpdnpt; + int cpkd; + + if( initialize ) + { + for( j=0; j -1 ) + *fpt2 += scarr[*ipt++] * *fpt++; + fpt2++,iptpt++,fptpt++; + } + } + for( j=0; j-1; k++ ) + match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k]; + } +#else + matchpt = match; + cpmxpdnpt = cpmxpdn; + cpmxpdpt = cpmxpd; + while( lgth2-- ) + { + *matchpt = 0.0; + for( k=0; (cpkd=(*cpmxpdnpt)[k])>-1; k++ ) + *matchpt += scarr[cpkd] * (*cpmxpdpt)[k]; + matchpt++; + cpmxpdnpt++; + cpmxpdpt++; + } +#endif +} + +static float Atracking( + char **seq1, char **seq2, + char **mseq1, char **mseq2, + int **ijp, int icyc, int jcyc, + int ist, int ien, int jst, int jen ) +{ + int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim; + char *gaptable1, *gt1bk; + char *gaptable2, *gt2bk; + lgth1 = ien-ist+1; + lgth2 = jen-jst+1; + + gt1bk = AllocateCharVec( lgth1+lgth2+1 ); + gt2bk = AllocateCharVec( lgth1+lgth2+1 ); + +#if 0 + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + } + if( iin <= 0 || jin <= 0 ) break; + *--gaptable1 = 'o'; + *--gaptable2 = 'o'; + k++; + iin = ifi; jin = jfi; + + } + + for( i=0; i", wm ); +#endif + g = mi + fgcp2[j-1]; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; + *ijppt = -( j - mpi ); + } + g = *prept + ogcp2[j]; + if( g >= mi ) + { + mi = g; + mpi = j-1; + } +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + + g = *mjpt + fgcp1[i-1]; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; + *ijppt = +( i - *mpjpt ); + } + g = *prept + ogcp1[i]; + if( g >= *mjpt ) + { + *mjpt = g; + *mpjpt = i-1; + } +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + *curpt += wm; + + + ijppt++; + mjpt++; + prept++; + mpjpt++; + curpt++; + } + lastverticalw[i] = currentw[lgth2-1]; + } + +// fprintf( stderr, "wm = %f\n", wm ); + + Atracking( seq1, seq2, mseq1, mseq2, ijp, icyc, jcyc, ist, ien, jst, jen ); + +// for( i=0; i", wm ); +#endif + g = mi + fgcp2[j-1]; +// g = mi + fpenalty; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; +// *ijppt = -( j - mpi ); + } + g = *prept + ogcp2[j]; +// g = *prept; + if( g >= mi ) + { + mi = g; + mpi = j-1; + } +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + + g = *mjpt + fgcp1[i-1]; +// g = *mjpt + fpenalty; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; +// *ijppt = +( i - *mpjpt ); + } + + + g = *prept + ogcp1[i]; +// g = *prept; + if( g >= *mjpt ) + { + *mjpt = g; + *mpjpt = i-1; + } +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + *curpt += wm; + +#if STOREWM + WMMTX[i][j] = *curpt; + WMMTX2[i][j] = *mjpt; +#endif + + if( i == imid ) //muda + { + jumpbackj[j] = *mpjpt; // muda atode matomeru + jumpbacki[j] = mpi; // muda atode matomeru +// fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt ); +// fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi ); + midw[j] = *curpt; + midm[j] = *mjpt; + midn[j] = mi; + } + +// fprintf( stderr, "m[%d] = %f\n", j, m[j] ); + mjpt++; + prept++; + mpjpt++; + curpt++; + + } + lastverticalw[i] = currentw[lgth2-1]; + +#if STOREWM + WMMTX2[i][lgth2] = m[lgth2-1]; +#endif + +#if 0 // ue + if( i == imid ) + { + for( j=0; j0; --j ) + { + m[j-1] = currentw[j] + fgcp2[lgth2-2]; +// m[j-1] = currentw[j]; + mp[j] = lgth1-1; + } + +// for( j=0; j=imid; i-- ) + firstm = -9999999.9; + firstmp = lgth1-1; + for( i=lgth1-2; i>-1; i-- ) + { + wtmp = previousw; + previousw = currentw; + currentw = wtmp; + previousw[lgth2-1] = initverticalw[i+1]; +// match_calc( currentw, seq1, seq2, i, lgth2 ); + match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 ); + + currentw[lgth2-1] = initverticalw[i]; + +// m[lgth2] = fgcp1[i]; +// WMMTX2[i][lgth2] += m[lgth2]; +// fprintf( stderr, "m[] = %f\n", m[lgth2] ); + + mi = previousw[lgth2-1] + fgcp2[lgth2-2]; +// mi = previousw[lgth2-1]; + mpi = lgth2 - 1; + + mjpt = m + lgth2 - 2; + prept = previousw + lgth2 - 1; + curpt = currentw + lgth2 - 2; + mpjpt = mp + lgth2 - 2; + + + for( j=lgth2-2; j>-1; j-- ) + { + wm = *prept; + ijpi = i+1; + ijpj = j+1; + + g = mi + ogcp2[j+1]; +// g = mi + fpenalty; + if( g > wm ) + { + wm = g; + ijpj = mpi; + ijpi = i+1; + } + + g = *prept + fgcp2[j]; +// g = *prept; + if( g >= mi ) + { +// fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 ); + mi = g; + mpi = j + 1; + } + +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +// fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt ); + g = *mjpt + ogcp1[i+1]; +// g = *mjpt + fpenalty; + if( g > wm ) + { + wm = g; + ijpi = *mpjpt; + ijpj = j+1; + } + +// if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j ); + g = *prept + fgcp1[i]; +// g = *prept; + if( g >= *mjpt ) + { + *mjpt = g; + *mpjpt = i + 1; + } + +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + + if( i == jumpi || i == imid - 1 ) + { + jumpforwi[j] = ijpi; //muda + jumpforwj[j] = ijpj; //muda +// fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi ); +// fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj ); + } + if( i == imid ) // muda + { + midw[j] += wm; +// midm[j+1] += *mjpt + fpenalty; //?????? + midm[j+1] += *mjpt; //?????? + } + if( i == imid - 1 ) + { +// midn[j] += mi + fpenalty; //???? + midn[j] += mi; //???? + } +#if STOREWM + WMMTX[i][j] += wm; +// WMMTX2[i][j+1] += *mjpt + fpenalty; + WMMTX2[i][j+1] += *mjpt; +#endif + *curpt += wm; + + mjpt--; + prept--; + mpjpt--; + curpt--; + } +// fprintf( stderr, "adding *mjpt (=%f) to WMMTX2[%d][%d]\n", *mjpt, i, j+1 ); + g = *prept + fgcp1[i]; + if( firstm < g ) + { + firstm = g; + firstmp = i + 1; + } +#if STOREWM + WMMTX2[i][j+1] += firstm; +#endif + if( i == imid ) midm[j+1] += firstm; + + if( i == imid - 1 ) + { + maxwm = midw[1]; + jmid = 0; +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + for( j=2; j maxwm ) + { + jmid = j; + maxwm = wm; + } +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + } + for( j=0; j maxwm ) + { + jmid = j; + maxwm = wm; + } +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + } + +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + + +// fprintf( stderr, "### imid=%d, jmid=%d\n", imid, jmid ); + wm = midw[jmid]; + jumpi = imid-1; + jumpj = jmid-1; + if( jmid > 0 && midn[jmid-1] > wm ) //060413 + { + jumpi = imid-1; + jumpj = jumpbacki[jmid]; + wm = midn[jmid-1]; +// fprintf( stderr, "rejump (n)\n" ); + } + if( midm[jmid] > wm ) + { + jumpi = jumpbackj[jmid]; + jumpj = jmid-1; + wm = midm[jmid]; +// fprintf( stderr, "rejump (m) jumpi=%d\n", jumpi ); + } + + +// fprintf( stderr, "--> imid=%d, jmid=%d\n", imid, jmid ); +// fprintf( stderr, "--> jumpi=%d, jumpj=%d\n", jumpi, jumpj ); +#if STOREWM + fprintf( stderr, "imid = %d\n", imid ); + fprintf( stderr, "midn = \n" ); + for( j=0; j= lgth2 ) + { +// fprintf( stderr, "CHUI1!\n" ); + jumpi=imid-1; jmid=lgth2; + jumpj = lgth2-1; + } +#endif + else + { + imid = jumpforwi[jumpj]; + jmid = jumpforwj[jumpj]; + } +#if 0 + fprintf( stderr, "jumpi -> %d\n", jumpi ); + fprintf( stderr, "jumpj -> %d\n", jumpj ); + fprintf( stderr, "imid -> %d\n", imid ); + fprintf( stderr, "jmid -> %d\n", jmid ); +#endif + +#if STOREWM + break; +#else + break; +#endif + } + } +#if 0 + jumpi=0; jumpj=0; + imid=lgth1-1; jmid=lgth2-1; + } +#endif + +// fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi ); +// fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj ); + +// for( j=0; j N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } +#endif + + + +#if 0 + fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid ); + fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid ); + + fprintf( stderr, "imid = %d\n", imid ); + fprintf( stderr, "jmid = %d\n", jmid ); +#endif + + + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + FreeFloatVec( midw ); + FreeFloatVec( midm ); + FreeFloatVec( midn ); + + FreeIntVec( jumpbacki ); + FreeIntVec( jumpbackj ); + FreeIntVec( jumpforwi ); + FreeIntVec( jumpforwj ); + FreeIntVec( jumpdummi ); + FreeIntVec( jumpdummj ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + + FreeFloatMtx( floatwork ); + FreeIntMtx( intwork ); + +#if STOREWM + FreeFloatMtx( WMMTX ); + FreeFloatMtx( WMMTX2 ); +#endif + +// fprintf( stderr, "==== calling myself (first)\n" ); + +#if 0 + fprintf( stderr, "seq1[0] = %s\n", seq1[0] ); + fprintf( stderr, "seq2[0] = %s\n", seq2[0] ); +#endif + value = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, aseq1, aseq2, depth, gapinfo ); +#if 0 + fprintf( stderr, "aseq1[0] = %s\n", aseq1[0] ); + fprintf( stderr, "aseq2[0] = %s\n", aseq2[0] ); +#endif +#if MEMSAVE +#else + for( i=0; i 0 ) + { + for( i=0; i 0 ) + { + for( i=0; i 1 || maxwm - value > 1 ) + { + fprintf( stderr, "WARNING value = %f, but maxwm = %f\n", value, maxwm ); + for( i=0; i1-%d\n%s\n", i, mseq1[i] ); + fprintf( stderr, "%s\n", aseq1[i] ); + } + for( i=0; i2-%d\n%s\n", i, mseq2[i] ); + fprintf( stderr, "%s\n", aseq2[i] ); + } + +// exit( 1 ); + } + else + { + fprintf( stderr, "value = %.0f, maxwm = %.0f -> ok\n", value, maxwm ); + } +#endif + +#if MEMSAVE +#else + for( i=0; i%d of GROUP1\n", i ); + fprintf( stdout, "%s\n", seq1[i] ); + } + for( i=0; i%d of GROUP2\n", i ); + fprintf( stdout, "%s\n", seq2[i] ); + } + fflush( stdout ); +#endif + + wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo ); +#if DEBUG + fprintf( stderr, " seq1[0] = %s\n", seq1[0] ); + fprintf( stderr, " seq2[0] = %s\n", seq2[0] ); + fprintf( stderr, "mseq1[0] = %s\n", mseq1[0] ); + fprintf( stderr, "mseq2[0] = %s\n", mseq2[0] ); +#endif + +// fprintf( stderr, "wm = %f\n", wm ); + + + for( i=0; istart1 ); +// fprintf( stderr, "end1 = %d\n", tmpptr->end1 ); +// fprintf( stderr, "i = %d, seq1 = \n%s\n", i, seq1[i] ); +// fprintf( stderr, "j = %d, seq2 = \n%s\n", j, seq2[j] ); + pt = seq1[i]; + tmpint = -1; + while( *pt != 0 ) + { + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->start1 ) break; + } + start1 = pt - seq1[i] - 1; + + if( tmpptr->start1 == tmpptr->end1 ) end1 = start1; + else + { +#if MACHIGAI + while( *pt != 0 ) + { +// fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] ); + if( tmpint == tmpptr->end1 ) break; + if( *pt++ != '-' ) tmpint++; + } + end1 = pt - seq1[i] - 0; +#else + while( *pt != 0 ) + { +// fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] ); + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->end1 ) break; + } + end1 = pt - seq1[i] - 1; +#endif + } + + pt = seq2[j]; + tmpint = -1; + while( *pt != 0 ) + { + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->start2 ) break; + } + start2 = pt - seq2[j] - 1; + if( tmpptr->start2 == tmpptr->end2 ) end2 = start2; + else + { +#if MACHIGAI + while( *pt != 0 ) + { + if( tmpint == tmpptr->end2 ) break; + if( *pt++ != '-' ) tmpint++; + } + end2 = pt - seq2[j] - 0; +#else + while( *pt != 0 ) + { + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->end2 ) break; + } + end2 = pt - seq2[j] - 1; +#endif + } +// fprintf( stderr, "start1 = %d (%c), end1 = %d (%c), start2 = %d (%c), end2 = %d (%c)\n", start1, seq1[i][start1], end1, seq1[i][end1], start2, seq2[j][start2], end2, seq2[j][end2] ); +// fprintf( stderr, "step 0\n" ); + if( end1 - start1 != end2 - start2 ) + { +// fprintf( stderr, "CHUUI!!, start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 ); + } + +#if 1 + k1 = start1; k2 = start2; + pt1 = seq1[i] + k1; + pt2 = seq2[j] + k2; + while( *pt1 && *pt2 ) + { + if( *pt1 != '-' && *pt2 != '-' ) + { +// ?????????????????????????????????????????? +// impmtx[k1][k2] += tmpptr->wimportance * fastathreshold; +// impmtx[k1][k2] += tmpptr->importance * effij; + impmtx[k1][k2] += tmpptr->fimportance * effij; +// fprintf( stderr, "#### impmtx[k1][k2] = %f, tmpptr->fimportance=%f, effij=%f\n", impmtx[k1][k2], tmpptr->fimportance, effij ); +// fprintf( stderr, "mark, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); +// fprintf( stderr, "%d (%c) - %d (%c) - %f\n", k1, *pt1, k2, *pt2, tmpptr->fimportance * effij ); + k1++; k2++; + pt1++; pt2++; + } + else if( *pt1 != '-' && *pt2 == '-' ) + { +// fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); + k2++; pt2++; + } + else if( *pt1 == '-' && *pt2 != '-' ) + { +// fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); + k1++; pt1++; + } + else if( *pt1 == '-' && *pt2 == '-' ) + { +// fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); + k1++; pt1++; + k2++; pt2++; + } + if( k1 > end1 || k2 > end2 ) break; + } +#else + while( k1 <= end1 && k2 <= end2 ) + { + fprintf( stderr, "k1,k2=%d,%d - ", k1, k2 ); + if( !nocount1[k1] && !nocount2[k2] ) + { + impmtx[k1][k2] += tmpptr->wimportance * eff1[i] * eff2[j] * fastathreshold; + fprintf( stderr, "marked\n" ); + } + else + fprintf( stderr, "no count\n" ); + k1++; k2++; + } +#endif + tmpptr = tmpptr->next; + } + } + } +#if 0 + if( clus1 == 1 && clus2 == 6 ) + { + fprintf( stderr, "\n" ); + fprintf( stderr, "seq1[0] = %s\n", seq1[0] ); + fprintf( stderr, "seq2[0] = %s\n", seq2[0] ); + fprintf( stderr, "impmtx = \n" ); + for( k2=0; k2-1 ) + *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++; + matchpt++; + } + } +#else + int j, k, l; + float scarr[26]; + float **cpmxpd = floatwork; + int **cpmxpdn = intwork; +// simple + if( initialize ) + { + int count = 0; + for( j=0; j-1; k++ ) + match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j]; + } +#endif +} + +static void Atracking_localhom_gapmap( float *impwmpt, float *lasthorizontalw, float *lastverticalw, + char **seq1, char **seq2, + char **mseq1, char **mseq2, + float **cpmx1, float **cpmx2, + int **ijp, int icyc, int jcyc, + int *gapmap1, int *gapmap2 ) +{ + int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k; + char gap[] = "-"; + float wm; + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); + +#if 0 + for( i=0; i= wm ) + { + wm = lastverticalw[i]; + iin = i; jin = lgth2-1; + ijp[lgth1][lgth2] = +( lgth1 - i ); + } + } + for( j=0; j= wm ) + { + wm = lasthorizontalw[j]; + iin = lgth1-1; jin = j; + ijp[lgth1][lgth2] = -( lgth2 - j ); + } + } + } + + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + for( i=0; i= wm ) + { + wm = lastverticalw[i]; + iin = i; jin = lgth2-1; + ijp[lgth1][lgth2] = +( lgth1 - i ); + } + } + for( j=0; j= wm ) + { + wm = lasthorizontalw[j]; + iin = lgth1-1; jin = j; + ijp[lgth1][lgth2] = -( lgth2 - j ); + } + } + } + + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + } + if( iin == lgth1 || jin == lgth2 ) + ; + else + { + *impwmpt += imp_match_out_scQ( gapmap1[iin], gapmap2[jin] ); + +// fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] ); + } + if( iin <= 0 || jin <= 0 ) break; + *--gaptable1 = '-'; + *--gaptable2 = '-'; + k++; + iin = ifi; jin = jfi; + } + for( i=0; i= wm ) + { + wm = lastverticalw[i]; + iin = i; jin = lgth2-1; + ijp[lgth1][lgth2] = +( lgth1 - i ); + } + } + for( j=0; j= wm ) + { + wm = lasthorizontalw[j]; + iin = lgth1-1; jin = j; + ijp[lgth1][lgth2] = -( lgth2 - j ); + } + } + } + + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + } + if( iin == lgth1 || jin == lgth2 ) + ; + else + { + *impwmpt += imp_match_out_scQ( iin, jin ); + +// fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] ); + } + if( iin <= 0 || jin <= 0 ) break; + *--gaptable1 = 'o'; + *--gaptable2 = 'o'; + k++; + iin = ifi; jin = jfi; + } + + for( i=0; i= wm ) + { + wm = lastverticalw[i]; + iin = i; jin = lgth2-1; + ijp[lgth1][lgth2] = +( lgth1 - i ); + } + } + for( j=0; j= wm ) + { + wm = lasthorizontalw[j]; + iin = lgth1-1; jin = j; + ijp[lgth1][lgth2] = -( lgth2 - j ); + } + } + } + + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + } + if( iin <= 0 || jin <= 0 ) break; + *--gaptable1 = 'o'; + *--gaptable2 = 'o'; + k++; + iin = ifi; jin = jfi; + } + + for( i=0; i lgth1, outgap == 1 -> lgth1+1 */ + int lgth1, lgth2; + int resultlen; + float wm = 0.0; /* int ?????? */ + float g; + float *currentw, *previousw; +// float fpenalty = (float)penalty; +#if USE_PENALTY_EX + float fpenalty_ex = (float)penalty_ex; + fprintf( stderr, "fpenalty_ex = %f\n", fpenalty_ex ); +#endif +#if 1 + float *wtmp; + int *ijppt; + float *mjpt, *prept, *curpt; + int *mpjpt; +#endif + static float mi, *m; + static int **ijp; + static int mpi, *mp; + static float *w1, *w2; + static float *match; + static float *initverticalw; /* kufuu sureba iranai */ + static float *lastverticalw; /* kufuu sureba iranai */ + static char **mseq1; + static char **mseq2; + static char **mseq; + static float *digf1; + static float *digf2; + static float *diaf1; + static float *diaf2; + static float *gapz1; + static float *gapz2; + static float *gapf1; + static float *gapf2; + static float *ogcp1g; + static float *ogcp2g; + static float *fgcp1g; + static float *fgcp2g; + static float *og_h_dg_n1_p; + static float *og_h_dg_n2_p; + static float *fg_h_dg_n1_p; + static float *fg_h_dg_n2_p; + static float *og_t_fg_h_dg_n1_p; + static float *og_t_fg_h_dg_n2_p; + static float *fg_t_og_h_dg_n1_p; + static float *fg_t_og_h_dg_n2_p; + static float *gapz_n1; + static float *gapz_n2; + static float **cpmx1; + static float **cpmx2; + static int **intwork; + static float **floatwork; + static int orlgth1 = 0, orlgth2 = 0; + float tmppenal; + float *fg_t_og_h_dg_n2_p_pt; + float *og_t_fg_h_dg_n2_p_pt; + float *og_h_dg_n2_p_pt; + float *fg_h_dg_n2_p_pt; + float *gapz_n2_pt0; + float *gapz_n2_pt1; + float *fgcp2pt; + float *ogcp2pt; + float fg_t_og_h_dg_n1_p_va; + float og_t_fg_h_dg_n1_p_va; + float og_h_dg_n1_p_va; + float fg_h_dg_n1_p_va; + float gapz_n1_va0; + float gapz_n1_va1; + float fgcp1va; + float ogcp1va; + float kyokaipenal; +#if 1 + float fpenalty = (float)penalty; +#else + float fpenalty; + if( RNAscoremtx != 'r' ) fpenalty = (float)penalty; + else fpenalty = (float)penalty * 10; +#endif + +#if 0 + fprintf( stderr, "#### seq1[0] = %s\n", seq1[0] ); + fprintf( stderr, "#### seq2[0] = %s\n", seq2[0] ); +#endif + + + + if( orlgth1 == 0 ) + { + mseq1 = AllocateCharMtx( njob, 0 ); + mseq2 = AllocateCharMtx( njob, 0 ); + } + + + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); +#if 0 + if( lgth1 == 0 || lgth2 == 0 ) + { + fprintf( stderr, "WARNING (Aalignmm): lgth1=%d, lgth2=%d\n", lgth1, lgth2 ); + } +#endif + + if( lgth1 > orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + + FreeCharMtx( mseq ); + + FreeFloatVec( digf1 ); + FreeFloatVec( digf2 ); + FreeFloatVec( diaf1 ); + FreeFloatVec( diaf2 ); + FreeFloatVec( gapz1 ); + FreeFloatVec( gapz2 ); + FreeFloatVec( gapf1 ); + FreeFloatVec( gapf2 ); + FreeFloatVec( ogcp1g ); + FreeFloatVec( ogcp2g ); + FreeFloatVec( fgcp1g ); + FreeFloatVec( fgcp2g ); + FreeFloatVec( og_h_dg_n1_p ); + FreeFloatVec( og_h_dg_n2_p ); + FreeFloatVec( fg_h_dg_n1_p ); + FreeFloatVec( fg_h_dg_n2_p ); + FreeFloatVec( og_t_fg_h_dg_n1_p ); + FreeFloatVec( og_t_fg_h_dg_n2_p ); + FreeFloatVec( fg_t_og_h_dg_n1_p ); + FreeFloatVec( fg_t_og_h_dg_n2_p ); + FreeFloatVec( gapz_n1 ); + FreeFloatVec( gapz_n2 ); + + FreeFloatMtx( cpmx1 ); + FreeFloatMtx( cpmx2 ); + + FreeFloatMtx( floatwork ); + FreeIntMtx( intwork ); + } + + ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100; + +#if DEBUG + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); +#endif + + w1 = AllocateFloatVec( ll2+2 ); + w2 = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + + m = AllocateFloatVec( ll2+2 ); + mp = AllocateIntVec( ll2+2 ); + + mseq = AllocateCharMtx( njob, ll1+ll2 ); + + digf1 = AllocateFloatVec( ll1+2 ); + digf2 = AllocateFloatVec( ll2+2 ); + diaf1 = AllocateFloatVec( ll1+2 ); + diaf2 = AllocateFloatVec( ll2+2 ); + gapz1 = AllocateFloatVec( ll1+2 ); + gapz2 = AllocateFloatVec( ll2+2 ); + gapf1 = AllocateFloatVec( ll1+2 ); + gapf2 = AllocateFloatVec( ll2+2 ); + ogcp1g = AllocateFloatVec( ll1+2 ); + ogcp2g = AllocateFloatVec( ll2+2 ); + fgcp1g = AllocateFloatVec( ll1+2 ); + fgcp2g = AllocateFloatVec( ll2+2 ); + og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 ); + og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 ); + fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 ); + fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 ); + og_t_fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 ); + og_t_fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 ); + fg_t_og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 ); + fg_t_og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 ); + gapz_n1 = AllocateFloatVec( ll1+2 ); + gapz_n2 = AllocateFloatVec( ll2+2 ); + + cpmx1 = AllocateFloatMtx( 26, ll1+2 ); + cpmx2 = AllocateFloatMtx( 26, ll2+2 ); + +#if FASTMATCHCALC + floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); + intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); +#else + floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); +#endif + +#if DEBUG + fprintf( stderr, "succeeded\n" ); +#endif + + orlgth1 = ll1 - 100; + orlgth2 = ll2 - 100; + } + + + for( i=0; i commonAlloc1 || orlgth2 > commonAlloc2 ) + { + int ll1, ll2; + + if( commonAlloc1 && commonAlloc2 ) + { + FreeIntMtx( commonIP ); + } + + ll1 = MAX( orlgth1, commonAlloc1 ); + ll2 = MAX( orlgth2, commonAlloc2 ); + +#if DEBUG + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + + commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + +#if DEBUG + fprintf( stderr, "succeeded\n\n" ); +#endif + + commonAlloc1 = ll1; + commonAlloc2 = ll2; + } + ijp = commonIP; + +#if 0 + { + float t = 0.0; + for( i=0; i tbfast.c + if( localhom ) + imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 ); + +#endif + + + + kyokaipenal = 0.0; + if( outgap == 1 ) + { + g = 0.0; + + g += ogcp1g[0] * og_h_dg_n2_p[0]; +// g += ogcp1g[0] * ( 1.0-ogcp2g[0]-digf2[0] ) * fpenalty * 0.5; +// if( g ) fprintf( stderr, "init-match penal1=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] ); + + g += ogcp2g[0] * og_h_dg_n1_p[0]; +// g += ogcp2g[0] * ( 1.0-ogcp1g[0]-digf1[0] ) * fpenalty * 0.5; +// if( g ) fprintf( stderr, "init-match penal2=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] ); + + g += fgcp1g[0] * fg_h_dg_n2_p[0]; +// g += fgcp1g[0] * ( 1.0-fgcp2g[0]-digf2[0] ) * fpenalty * 0.5; +// if( g ) fprintf( stderr, "match penal1=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] ); + + g += fgcp2g[0] * fg_h_dg_n1_p[0]; +// g += fgcp2g[0] * ( 1.0-fgcp1g[0]-digf1[0] ) * fpenalty * 0.5; +// if( g ) fprintf( stderr, "match penal2=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] ); + + kyokaipenal = g; + initverticalw[0] += g; + currentw[0] += g; + + for( i=1; i", wm ); +#endif +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + tmppenal = gapz_n1_va1 * *fg_t_og_h_dg_n2_p_pt; +// tmppenal = gapz_n1[i+1] * fg_t_og_h_dg_n2_p[j]; +// tmppenal = ( (1.0-gapz1[i+1])*(1.0-fgcp2g[j]+ogcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada + if( (g=mi+tmppenal) > wm ) + { +// fprintf( stderr, "jump i start=%f (j=%d, fgcp2g[j]=%f, digf2[j]=%f, diaf2[j]=%f), %c-%c\n", g-mi, j, fgcp2g[j], digf2[j], diaf2[j], seq1[0][i], seq2[0][j] ); + wm = g; + *ijppt = -( j - mpi ); + } + tmppenal = gapz_n1_va0 * *og_t_fg_h_dg_n2_p_pt; +// tmppenal = gapz_n1[i] * og_t_fg_h_dg_n2_p[j]; +// tmppenal = ( (1.0-gapz1[i])*(1.0-ogcp2g[j]+fgcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada + if( (g=*prept+tmppenal) >= mi ) + { +// fprintf( stderr, "jump i end=%f, %c-%c\n", g-*prept, seq1[0][i-1], seq2[0][j-1] ); + mi = g; + mpi = j-1; + } + +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + tmppenal = *gapz_n2_pt1 * fg_t_og_h_dg_n1_p_va; +// tmppenal = gapz_n2[j+1] * fg_t_og_h_dg_n1_p[i]; +// tmppenal = ( (1.0-gapz2[j+1])*(1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada + if( (g=*mjpt+tmppenal) > wm ) + { + wm = g; + *ijppt = +( i - *mpjpt ); + } + tmppenal = *gapz_n2_pt0 * og_t_fg_h_dg_n1_p_va; +// tmppenal = gapz_n2[j] * og_t_fg_h_dg_n1_p[i]; +// tmppenal = ( (1.0-gapz2[j])*(1.0-ogcp1g[i]+fgcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada + if( (g=*prept+tmppenal) >= *mjpt ) + { + *mjpt = g; + *mpjpt = i-1; + } +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + + + + + + *curpt++ += wm; + ijppt++; + mjpt++; + prept++; + mpjpt++; + fg_t_og_h_dg_n2_p_pt++; + og_t_fg_h_dg_n2_p_pt++; + og_h_dg_n2_p_pt++; + fg_h_dg_n2_p_pt++; + gapz_n2_pt0++; + gapz_n2_pt1++; + fgcp2pt++; + ogcp2pt++; + } + lastverticalw[i] = currentw[lgth2-1]; + } + +// fprintf( stderr, "wm = %f\n", wm ); + +#if OUTGAP0TRY + if( !outgap ) + { + for( j=1; j" ); + for( i=0; i N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } + + + for( i=0; i lgth1, outgap == 1 -> lgth1+1 */ + int lgth1, lgth2; + int resultlen; + float wm = 0.0; /* int ?????? */ + float g; + float *currentw, *previousw; +// float fpenalty = (float)penalty; +#if USE_PENALTY_EX + float fpenalty_ex = (float)penalty_ex; + fprintf( stderr, "fpenalty_ex = %f\n", fpenalty_ex ); +#endif +#if 1 + float *wtmp; + int *ijppt; + float *mjpt, *prept, *curpt; + int *mpjpt; +#endif + static float mi, *m; + static int **ijp; + static int mpi, *mp; + static float *w1, *w2; + static float *match; + static float *initverticalw; /* kufuu sureba iranai */ + static float *lastverticalw; /* kufuu sureba iranai */ + static char **mseq1; + static char **mseq2; + static char **mseq; + static float *digf1; + static float *digf2; + static float *diaf1; + static float *diaf2; + static float *gapz1; + static float *gapz2; + static float *gapf1; + static float *gapf2; + static float *ogcp1g; + static float *ogcp2g; + static float *fgcp1g; + static float *fgcp2g; + static float *og_h_dg_n1_p; + static float *og_h_dg_n2_p; + static float *fg_h_dg_n1_p; + static float *fg_h_dg_n2_p; + static float *og_t_fg_h_dg_n1_p; + static float *og_t_fg_h_dg_n2_p; + static float *fg_t_og_h_dg_n1_p; + static float *fg_t_og_h_dg_n2_p; + static float *gapz_n1; + static float *gapz_n2; + static float **cpmx1; + static float **cpmx2; + static int **intwork; + static float **floatwork; + static int orlgth1 = 0, orlgth2 = 0; + float tmppenal; + float *fg_t_og_h_dg_n2_p_pt; + float *og_t_fg_h_dg_n2_p_pt; + float *og_h_dg_n2_p_pt; + float *fg_h_dg_n2_p_pt; + float *gapz_n2_pt0; + float *gapz_n2_pt1; + float *fgcp2pt; + float *ogcp2pt; + float fg_t_og_h_dg_n1_p_va; + float og_t_fg_h_dg_n1_p_va; + float og_h_dg_n1_p_va; + float fg_h_dg_n1_p_va; + float gapz_n1_va0; + float gapz_n1_va1; + float fgcp1va; + float ogcp1va; + float kyokaipenal; + float fpenalty = (float)penalty; + +#if 0 + fprintf( stderr, "#### seq1[0] = %s\n", seq1[0] ); + fprintf( stderr, "#### seq2[0] = %s\n", seq2[0] ); +#endif + + + + if( orlgth1 == 0 ) + { + mseq1 = AllocateCharMtx( njob, 0 ); + mseq2 = AllocateCharMtx( njob, 0 ); + } + + + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); +#if 0 + if( lgth1 == 0 || lgth2 == 0 ) + { + fprintf( stderr, "WARNING (Aalignmm): lgth1=%d, lgth2=%d\n", lgth1, lgth2 ); + } +#endif + + if( lgth1 > orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + + FreeCharMtx( mseq ); + + FreeFloatVec( digf1 ); + FreeFloatVec( digf2 ); + FreeFloatVec( diaf1 ); + FreeFloatVec( diaf2 ); + FreeFloatVec( gapz1 ); + FreeFloatVec( gapz2 ); + FreeFloatVec( gapf1 ); + FreeFloatVec( gapf2 ); + FreeFloatVec( ogcp1g ); + FreeFloatVec( ogcp2g ); + FreeFloatVec( fgcp1g ); + FreeFloatVec( fgcp2g ); + FreeFloatVec( og_h_dg_n1_p ); + FreeFloatVec( og_h_dg_n2_p ); + FreeFloatVec( fg_h_dg_n1_p ); + FreeFloatVec( fg_h_dg_n2_p ); + FreeFloatVec( og_t_fg_h_dg_n1_p ); + FreeFloatVec( og_t_fg_h_dg_n2_p ); + FreeFloatVec( fg_t_og_h_dg_n1_p ); + FreeFloatVec( fg_t_og_h_dg_n2_p ); + FreeFloatVec( gapz_n1 ); + FreeFloatVec( gapz_n2 ); + + FreeFloatMtx( cpmx1 ); + FreeFloatMtx( cpmx2 ); + + FreeFloatMtx( floatwork ); + FreeIntMtx( intwork ); + } + + ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100; + +#if DEBUG + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); +#endif + + w1 = AllocateFloatVec( ll2+2 ); + w2 = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + + m = AllocateFloatVec( ll2+2 ); + mp = AllocateIntVec( ll2+2 ); + + mseq = AllocateCharMtx( njob, ll1+ll2 ); + + digf1 = AllocateFloatVec( ll1+2 ); + digf2 = AllocateFloatVec( ll2+2 ); + diaf1 = AllocateFloatVec( ll1+2 ); + diaf2 = AllocateFloatVec( ll2+2 ); + gapz1 = AllocateFloatVec( ll1+2 ); + gapz2 = AllocateFloatVec( ll2+2 ); + gapf1 = AllocateFloatVec( ll1+2 ); + gapf2 = AllocateFloatVec( ll2+2 ); + ogcp1g = AllocateFloatVec( ll1+2 ); + ogcp2g = AllocateFloatVec( ll2+2 ); + fgcp1g = AllocateFloatVec( ll1+2 ); + fgcp2g = AllocateFloatVec( ll2+2 ); + og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 ); + og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 ); + fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 ); + fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 ); + og_t_fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 ); + og_t_fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 ); + fg_t_og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 ); + fg_t_og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 ); + gapz_n1 = AllocateFloatVec( ll1+2 ); + gapz_n2 = AllocateFloatVec( ll2+2 ); + + cpmx1 = AllocateFloatMtx( 26, ll1+2 ); + cpmx2 = AllocateFloatMtx( 26, ll2+2 ); + +#if FASTMATCHCALC + floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); + intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); +#else + floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); +#endif + +#if DEBUG + fprintf( stderr, "succeeded\n" ); +#endif + + orlgth1 = ll1 - 100; + orlgth2 = ll2 - 100; + } + + + for( i=0; i commonAlloc1 || orlgth2 > commonAlloc2 ) + { + int ll1, ll2; + + if( commonAlloc1 && commonAlloc2 ) + { + FreeIntMtx( commonIP ); + } + + ll1 = MAX( orlgth1, commonAlloc1 ); + ll2 = MAX( orlgth2, commonAlloc2 ); + +#if DEBUG + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + + commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + +#if DEBUG + fprintf( stderr, "succeeded\n\n" ); +#endif + + commonAlloc1 = ll1; + commonAlloc2 = ll2; + } + ijp = commonIP; + +#if 0 + { + float t = 0.0; + for( i=0; i tbfast.c + if( localhom ) + imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 ); + +#endif + + + + kyokaipenal = 0.0; + if( outgap == 1 ) + { + g = 0.0; + + g += ogcp1g[0] * og_h_dg_n2_p[0]; +// g += ogcp1g[0] * ( 1.0-ogcp2g[0]-digf2[0] ) * fpenalty * 0.5; +// if( g ) fprintf( stderr, "init-match penal1=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] ); + + g += ogcp2g[0] * og_h_dg_n1_p[0]; +// g += ogcp2g[0] * ( 1.0-ogcp1g[0]-digf1[0] ) * fpenalty * 0.5; +// if( g ) fprintf( stderr, "init-match penal2=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] ); + + g += fgcp1g[0] * fg_h_dg_n2_p[0]; +// g += fgcp1g[0] * ( 1.0-fgcp2g[0]-digf2[0] ) * fpenalty * 0.5; +// if( g ) fprintf( stderr, "match penal1=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] ); + + g += fgcp2g[0] * fg_h_dg_n1_p[0]; +// g += fgcp2g[0] * ( 1.0-fgcp1g[0]-digf1[0] ) * fpenalty * 0.5; +// if( g ) fprintf( stderr, "match penal2=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] ); + + kyokaipenal = g; + initverticalw[0] += g; + currentw[0] += g; + + for( i=1; i", wm ); +#endif +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + tmppenal = gapz_n1_va1 * *fg_t_og_h_dg_n2_p_pt; +// tmppenal = gapz_n1[i+1] * fg_t_og_h_dg_n2_p[j]; +// tmppenal = ( (1.0-gapz1[i+1])*(1.0-fgcp2g[j]+ogcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada + if( (g=mi+tmppenal) > wm ) + { +// fprintf( stderr, "jump i start=%f (j=%d, fgcp2g[j]=%f, digf2[j]=%f, diaf2[j]=%f), %c-%c\n", g-mi, j, fgcp2g[j], digf2[j], diaf2[j], seq1[0][i], seq2[0][j] ); + wm = g; + *ijppt = -( j - mpi ); + } + tmppenal = gapz_n1_va0 * *og_t_fg_h_dg_n2_p_pt; +// tmppenal = gapz_n1[i] * og_t_fg_h_dg_n2_p[j]; +// tmppenal = ( (1.0-gapz1[i])*(1.0-ogcp2g[j]+fgcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada + if( (g=*prept+tmppenal) >= mi ) + { +// fprintf( stderr, "jump i end=%f, %c-%c\n", g-*prept, seq1[0][i-1], seq2[0][j-1] ); + mi = g; + mpi = j-1; + } + +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + tmppenal = *gapz_n2_pt1 * fg_t_og_h_dg_n1_p_va; +// tmppenal = gapz_n2[j+1] * fg_t_og_h_dg_n1_p[i]; +// tmppenal = ( (1.0-gapz2[j+1])*(1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada + if( (g=*mjpt+tmppenal) > wm ) + { + wm = g; + *ijppt = +( i - *mpjpt ); + } + tmppenal = *gapz_n2_pt0 * og_t_fg_h_dg_n1_p_va; +// tmppenal = gapz_n2[j] * og_t_fg_h_dg_n1_p[i]; +// tmppenal = ( (1.0-gapz2[j])*(1.0-ogcp1g[i]+fgcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada + if( (g=*prept+tmppenal) >= *mjpt ) + { + *mjpt = g; + *mpjpt = i-1; + } +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + + + + + + *curpt++ += wm; + ijppt++; + mjpt++; + prept++; + mpjpt++; + fg_t_og_h_dg_n2_p_pt++; + og_t_fg_h_dg_n2_p_pt++; + og_h_dg_n2_p_pt++; + fg_h_dg_n2_p_pt++; + gapz_n2_pt0++; + gapz_n2_pt1++; + fgcp2pt++; + ogcp2pt++; + } + lastverticalw[i] = currentw[lgth2-1]; + } + +// fprintf( stderr, "wm = %f\n", wm ); + +#if OUTGAP0TRY + if( !outgap ) + { + for( j=1; j" ); + for( i=0; i N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } + + + for( i=0; istart1 ); +// fprintf( stderr, "end1 = %d\n", tmpptr->end1 ); +// fprintf( stderr, "i = %d, seq1 = \n%s\n", i, seq1[i] ); +// fprintf( stderr, "j = %d, seq2 = \n%s\n", j, seq2[j] ); + pt = seq1[i]; + tmpint = -1; + while( *pt != 0 ) + { + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->start1 ) break; + } + start1 = pt - seq1[i] - 1; + + if( tmpptr->start1 == tmpptr->end1 ) end1 = start1; + else + { +#if MACHIGAI + while( *pt != 0 ) + { +// fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] ); + if( tmpint == tmpptr->end1 ) break; + if( *pt++ != '-' ) tmpint++; + } + end1 = pt - seq1[i] - 0; +#else + while( *pt != 0 ) + { +// fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] ); + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->end1 ) break; + } + end1 = pt - seq1[i] - 1; +#endif + } + + pt = seq2[j]; + tmpint = -1; + while( *pt != 0 ) + { + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->start2 ) break; + } + start2 = pt - seq2[j] - 1; + if( tmpptr->start2 == tmpptr->end2 ) end2 = start2; + else + { +#if MACHIGAI + while( *pt != 0 ) + { + if( tmpint == tmpptr->end2 ) break; + if( *pt++ != '-' ) tmpint++; + } + end2 = pt - seq2[j] - 0; +#else + while( *pt != 0 ) + { + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->end2 ) break; + } + end2 = pt - seq2[j] - 1; +#endif + } +// fprintf( stderr, "start1 = %d (%c), end1 = %d (%c), start2 = %d (%c), end2 = %d (%c)\n", start1, seq1[i][start1], end1, seq1[i][end1], start2, seq2[j][start2], end2, seq2[j][end2] ); +// fprintf( stderr, "step 0\n" ); + if( end1 - start1 != end2 - start2 ) + { +// fprintf( stderr, "CHUUI!!, start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 ); + } + +#if 1 + k1 = start1; k2 = start2; + pt1 = seq1[i] + k1; + pt2 = seq2[j] + k2; + while( *pt1 && *pt2 ) + { + if( *pt1 != '-' && *pt2 != '-' ) + { +// ?????????????????????????????????????????? +// impmtx[k1][k2] += tmpptr->wimportance * fastathreshold; +// impmtx[k1][k2] += tmpptr->importance * effij; + impmtx[k1][k2] += tmpptr->fimportance * effij; +// fprintf( stderr, "#### impmtx[k1][k2] = %f, tmpptr->fimportance=%f, effij=%f\n", impmtx[k1][k2], tmpptr->fimportance, effij ); +// fprintf( stderr, "mark, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); +// fprintf( stderr, "%d (%c) - %d (%c) - %f\n", k1, *pt1, k2, *pt2, tmpptr->fimportance * effij ); + k1++; k2++; + pt1++; pt2++; + } + else if( *pt1 != '-' && *pt2 == '-' ) + { +// fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); + k2++; pt2++; + } + else if( *pt1 == '-' && *pt2 != '-' ) + { +// fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); + k1++; pt1++; + } + else if( *pt1 == '-' && *pt2 == '-' ) + { +// fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); + k1++; pt1++; + k2++; pt2++; + } + if( k1 > end1 || k2 > end2 ) break; + } +#else + while( k1 <= end1 && k2 <= end2 ) + { + fprintf( stderr, "k1,k2=%d,%d - ", k1, k2 ); + if( !nocount1[k1] && !nocount2[k2] ) + { + impmtx[k1][k2] += tmpptr->wimportance * eff1[i] * eff2[j] * fastathreshold; + fprintf( stderr, "marked\n" ); + } + else + fprintf( stderr, "no count\n" ); + k1++; k2++; + } +#endif + tmpptr = tmpptr->next; + } + } + } +#if 0 + if( clus1 == 1 && clus2 == 6 ) + { + fprintf( stderr, "\n" ); + fprintf( stderr, "seq1[0] = %s\n", seq1[0] ); + fprintf( stderr, "seq2[0] = %s\n", seq2[0] ); + fprintf( stderr, "impmtx = \n" ); + for( k2=0; k2-1 ) + *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++; + matchpt++; + } + } +#else + int j, k, l; + float scarr[26]; + float **cpmxpd = floatwork; + int **cpmxpdn = intwork; +// simple + if( initialize ) + { + int count = 0; + for( j=0; j-1; k++ ) + match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j]; + } +#endif +} + +static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *lastverticalw, + char **seq1, char **seq2, + char **mseq1, char **mseq2, + float **cpmx1, float **cpmx2, + int **ijp, int icyc, int jcyc ) +{ + int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k; + float wm; + char *gaptable1, *gt1bk; + char *gaptable2, *gt2bk; + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); + gt1bk = AllocateCharVec( lgth1+lgth2+1 ); + gt2bk = AllocateCharVec( lgth1+lgth2+1 ); + +#if 0 + for( i=0; i= wm ) + { + wm = lastverticalw[i]; + iin = i; jin = lgth2-1; + ijp[lgth1][lgth2] = +( lgth1 - i ); + } + } + for( j=0; j= wm ) + { + wm = lasthorizontalw[j]; + iin = lgth1-1; jin = j; + ijp[lgth1][lgth2] = -( lgth2 - j ); + } + } + } + + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + } + if( iin == lgth1 || jin == lgth2 ) + ; + else + { + *impwmpt += imp_match_out_scR( iin, jin ); + +// fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] ); + } + if( iin <= 0 || jin <= 0 ) break; + *--gaptable1 = 'o'; + *--gaptable2 = 'o'; + k++; + iin = ifi; jin = jfi; + } + + for( i=0; i= wm ) + { + wm = lastverticalw[i]; + iin = i; jin = lgth2-1; + ijp[lgth1][lgth2] = +( lgth1 - i ); + } + } + for( j=0; j= wm ) + { + wm = lasthorizontalw[j]; + iin = lgth1-1; jin = j; + ijp[lgth1][lgth2] = -( lgth2 - j ); + } + } + } + + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + } + if( iin <= 0 || jin <= 0 ) break; + *--gaptable1 = 'o'; + *--gaptable2 = 'o'; + k++; + iin = ifi; jin = jfi; + } + + for( i=0; i lgth1, outgap == 1 -> lgth1+1 */ + int lgth1, lgth2; + int resultlen; + float wm = 0.0; /* int ?????? */ + float g; + float *currentw, *previousw; +// float fpenalty = (float)penalty; +#if USE_PENALTY_EX + float fpenalty_ex = (float)penalty_ex; +#endif +#if 1 + float *wtmp; + int *ijppt; + float *mjpt, *prept, *curpt; + int *mpjpt; +#endif + static float mi, *m; + static int **ijp; + static int mpi, *mp; + static float *w1, *w2; + static float *match; + static float *initverticalw; /* kufuu sureba iranai */ + static float *lastverticalw; /* kufuu sureba iranai */ + static char **mseq1; + static char **mseq2; + static char **mseq; + static float *digf1; + static float *digf2; + static float *diaf1; + static float *diaf2; + static float *gapz1; + static float *gapz2; + static float *gapf1; + static float *gapf2; + static float *ogcp1g; + static float *ogcp2g; + static float *fgcp1g; + static float *fgcp2g; + static float *ogcp1; + static float *ogcp2; + static float *fgcp1; + static float *fgcp2; + static float **cpmx1; + static float **cpmx2; + static int **intwork; + static float **floatwork; + static int orlgth1 = 0, orlgth2 = 0; + float fpenalty = (float)penalty; + float tmppenal; + float cumpenal; + float *fgcp2pt; + float *ogcp2pt; + float fgcp1va; + float ogcp1va; + float kyokaipenal; + + + +#if 0 + fprintf( stderr, "#### seq1[0] = %s\n", seq1[0] ); + fprintf( stderr, "#### seq2[0] = %s\n", seq2[0] ); +#endif + if( orlgth1 == 0 ) + { + mseq1 = AllocateCharMtx( njob, 0 ); + mseq2 = AllocateCharMtx( njob, 0 ); + } + + + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); +#if 0 + if( lgth1 == 0 || lgth2 == 0 ) + { + fprintf( stderr, "WARNING (Aalignmm): lgth1=%d, lgth2=%d\n", lgth1, lgth2 ); + } +#endif + + if( lgth1 > orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + + FreeCharMtx( mseq ); + + FreeFloatVec( digf1 ); + FreeFloatVec( digf2 ); + FreeFloatVec( diaf1 ); + FreeFloatVec( diaf2 ); + FreeFloatVec( gapz1 ); + FreeFloatVec( gapz2 ); + FreeFloatVec( gapf1 ); + FreeFloatVec( gapf2 ); + FreeFloatVec( ogcp1 ); + FreeFloatVec( ogcp2 ); + FreeFloatVec( fgcp1 ); + FreeFloatVec( fgcp2 ); + FreeFloatVec( ogcp1g ); + FreeFloatVec( ogcp2g ); + FreeFloatVec( fgcp1g ); + FreeFloatVec( fgcp2g ); + + + FreeFloatMtx( cpmx1 ); + FreeFloatMtx( cpmx2 ); + + FreeFloatMtx( floatwork ); + FreeIntMtx( intwork ); + } + + ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100; + +#if DEBUG + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); +#endif + + w1 = AllocateFloatVec( ll2+2 ); + w2 = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + + m = AllocateFloatVec( ll2+2 ); + mp = AllocateIntVec( ll2+2 ); + + mseq = AllocateCharMtx( njob, ll1+ll2 ); + + digf1 = AllocateFloatVec( ll1+2 ); + digf2 = AllocateFloatVec( ll2+2 ); + diaf1 = AllocateFloatVec( ll1+2 ); + diaf2 = AllocateFloatVec( ll2+2 ); + gapz1 = AllocateFloatVec( ll1+2 ); + gapz2 = AllocateFloatVec( ll2+2 ); + gapf1 = AllocateFloatVec( ll1+2 ); + gapf2 = AllocateFloatVec( ll2+2 ); + ogcp1 = AllocateFloatVec( ll1+2 ); + ogcp2 = AllocateFloatVec( ll2+2 ); + fgcp1 = AllocateFloatVec( ll1+2 ); + fgcp2 = AllocateFloatVec( ll2+2 ); + ogcp1g = AllocateFloatVec( ll1+2 ); + ogcp2g = AllocateFloatVec( ll2+2 ); + fgcp1g = AllocateFloatVec( ll1+2 ); + fgcp2g = AllocateFloatVec( ll2+2 ); + + cpmx1 = AllocateFloatMtx( 26, ll1+2 ); + cpmx2 = AllocateFloatMtx( 26, ll2+2 ); + +#if FASTMATCHCALC + floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); + intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); +#else + floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); +#endif + +#if DEBUG + fprintf( stderr, "succeeded\n" ); +#endif + + orlgth1 = ll1 - 100; + orlgth2 = ll2 - 100; + } + + + for( i=0; i commonAlloc1 || orlgth2 > commonAlloc2 ) + { + int ll1, ll2; + + if( commonAlloc1 && commonAlloc2 ) + { + FreeIntMtx( commonIP ); + } + + ll1 = MAX( orlgth1, commonAlloc1 ); + ll2 = MAX( orlgth2, commonAlloc2 ); + +#if DEBUG + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + + commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + +#if DEBUG + fprintf( stderr, "succeeded\n\n" ); +#endif + + commonAlloc1 = ll1; + commonAlloc2 = ll2; + } + ijp = commonIP; + +#if 0 + { + float t = 0.0; + for( i=0; i tbfast.c + if( localhom ) + imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 ); + +#endif + + + + kyokaipenal = 0.0; + if( outgap == 1 ) + { + g = 0.0; + + g += ogcp1g[0] * ( 1.0-ogcp2g[0] ) * fpenalty * 0.5; +// if( g ) fprintf( stderr, "init-match penal1=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] ); + + g += ogcp2g[0] * ( 1.0-ogcp1g[0] ) * fpenalty * 0.5; +// if( g ) fprintf( stderr, "init-match penal2=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] ); + + g += fgcp1g[0] * ( 1.0-fgcp2g[0] ) * fpenalty * 0.5; +// if( g ) fprintf( stderr, "match penal1=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] ); + + g += fgcp2g[0] * ( 1.0-fgcp1g[0] ) * fpenalty * 0.5; +// if( g ) fprintf( stderr, "match penal2=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] ); + + kyokaipenal = g; + initverticalw[0] += g; + currentw[0] += g; + + cumpenal = 0.0; + for( i=1; i", wm ); +#endif +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif +// tmppenal = ( (1.0-gapz1[i+1])*(1.0-fgcp2g[j]+ogcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada +// tmppenal = ( (1.0-gapf1[i])*(1.0-fgcp2g[j]) + gapf1[i]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada + tmppenal = ( (1.0-gapz1[i+1])*(1.0-fgcp2g[j]+ogcp2g[j]) + gapz1[i+1]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada +// tmppenal = ( (1.0-gapf1[i])*(1.0-fgcp2g[j]+ogcp2g[j]) + gapf1[i]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada +// tmppenal = 0.5 * fpenalty; +// tmppenal -= ( (1.0-gapf1[i])*(1.0-diaf2[j]) + gapf1[i] ) * 0.5 * fpenalty; +// tmppenal -= ( (1.0-gapf1[i])*fgcp2g[j] + gapf1[i] ) * 0.5 * fpenalty; +// tmppenal = *fgcp2pt-fpenalty*0.5*gapf1[i]; +// tmppenal = *fgcp2pt; + if( (g=mi+tmppenal) > wm ) + { +// fprintf( stderr, "jump i start=%f (j=%d, fgcp2g[j]=%f, digf2[j]=%f, diaf2[j]=%f), %c-%c\n", g-mi, j, fgcp2g[j], digf2[j], diaf2[j], seq1[0][i], seq2[0][j] ); + wm = g; + *ijppt = -( j - mpi ); + } +// tmppenal = ( (1.0-gapz1[i])*(1.0-ogcp2g[j]+fgcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada + tmppenal = ( (1.0-gapz1[i])*(1.0-ogcp2g[j]+fgcp2g[j]) + gapz1[i]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada +// tmppenal = ( (1.0-gapf1[i-1])*(1.0-ogcp2g[j]+fgcp2g[j]) + gapf1[i-1]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada +// tmppenal = *ogcp2pt-fpenalty*0.5*(gapf2[j-1]+gapf1[i-1]); +// tmppenal = 0.5 * fpenalty; +// tmppenal -= ( (1.0-gapf1[i-1])*(1.0-diaf2[j]) + gapf1[i-1] ) * 0.5 * fpenalty; +// tmppenal -= ( (1.0-gapf1[i-1])*ogcp2g[j] + gapf1[i-1] ) * 0.5 * fpenalty; +// tmppenal = *prept+*ogcp2pt; + if( (g=*prept+tmppenal) >= mi ) + { +// fprintf( stderr, "jump i end=%f, %c-%c\n", g-*prept, seq1[0][i-1], seq2[0][j-1] ); + mi = g; + mpi = j-1; + } + else if( j != 1 ) + { + mi += ( ogcp2g[j-0] + fgcp2g[j] ) * fpenalty * 0.5; // CHUUI honto ha iru +// fprintf( stderr, "%c%c/%c%c exp, og=%f,fg=%f\n", '=', '=', seq2[0][j-1], seq2[0][j], ogcp2g[j-0] * fpenalty*0.5, fgcp2g[j] * fpenalty*0.5 ); + } +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif +// tmppenal = ( (1.0-gapz2[j+1])*(1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada + tmppenal = ( (1.0-gapz2[j+1])*(1.0-fgcp1g[i]+ogcp1g[i]) + gapz2[j+1]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada +// tmppenal = ( (1.0-gapf2[j])*(1.0-fgcp1g[i]+ogcp1g[i]) + gapf2[j]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada +// tmppenal = ( (1.0-gapf2[j])*(1.0-fgcp1g[i]) + gapf2[j]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada +// tmppenal = 0.5 * fpenalty; +// tmppenal -= ( (1.0-gapf2[j])*(1.0-diaf1[i]) + gapf2[j] ) * 0.5 * fpenalty; +// tmppenal -= ( (1.0-gapf2[j])*fgcp1g[i] + gapf2[j] ) * 0.5 * fpenalty; +// tmppenal = fgcp1va-fpenalty*0.5*gapf2[j]; +// tmppenal = fgcp1va; + if( (g=*mjpt+tmppenal) > wm ) + { +// if( seq1[0][i] == 'Y' && seq2[0][j] == 'B' ) +// fprintf( stderr, "jump j start=%f, %c-%c\n", g-*mjpt, seq1[0][i], seq2[0][j] ); + wm = g; + *ijppt = +( i - *mpjpt ); + } +// tmppenal = ( (1.0-gapz2[j])*(1.0-ogcp1g[i]+fgcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada + tmppenal = ( (1.0-gapz2[j])*(1.0-ogcp1g[i]+fgcp1g[i]) + gapz2[j]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada +// tmppenal = ( (1.0-gapf2[j-1])*(1.0-ogcp1g[i]+fgcp1g[i]) + gapf2[j-1]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada +// tmppenal = ( (1.0-gapf2[j-1])*(1.0-ogcp1g[i]) + gapf2[j-1]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada +// tmppenal = ogcp1va-fpenalty*0.5*(gapf1[i-1]+gapf2[j-1]); +// tmppenal = 0.5 * fpenalty; +// tmppenal -= ( (1.0-gapf2[j-1]) * (1.0-diaf1[i]) + gapf2[j-1] ) * 0.5 * fpenalty; +// tmppenal -= ( (1.0-gapf2[j-1]) * ogcp1g[i] + gapf2[j-1] ) * 0.5 * fpenalty; +// tmppenal = 0.5 * fpenalty - ( (1.0-gapf2[j-1]) * (ogcp1g[i]) + gapf2[j-1] ) * ( 0.5 * fpenalty ); +// tmppenal = ogcp1va-fpenalty*0.5*gapf2[j-1]; +// tmppenal = ogcp1va; + if( (g=*prept+tmppenal) >= *mjpt ) + { +// if( seq1[0][i] == 'T' && seq2[0][j] == 'T' ) +// fprintf( stderr, "jump j end=%f, %c-%c\n", g-*prept, seq1[0][i-1], seq2[0][j-1] ); + *mjpt = g; + *mpjpt = i-1; + } + else if( i != 1 ) + { + m[j] += ( ogcp1g[i-0] + fgcp1g[i] ) * fpenalty * 0.5; // CHUUI honto ha iru +// fprintf( stderr, "%c%c/%c%c exp, og=%f,fg=%f\n", seq1[0][i-1], seq1[0][i], '=', '=', ogcp1g[i-0] * fpenalty*0.5, fgcp1g[i] * fpenalty*0.5 ); + } +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + *curpt++ += wm; + ijppt++; + mjpt++; + prept++; + mpjpt++; + fgcp2pt++; + ogcp2pt++; + } + lastverticalw[i] = currentw[lgth2-1]; + } + +// fprintf( stderr, "wm = %f\n", wm ); + +#if OUTGAP0TRY + if( !outgap ) + { + for( j=1; j" ); + for( i=0; i N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } + + + for( i=0; i -1; k++ ) + match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j]; + } +} + +static float Atracking( float *lasthorizontalw, float *lastverticalw, + char **seq1, char **seq2, + char **mseq1, char **mseq2, + float **cpmx1, float **cpmx2, + int **ijp, int icyc, int jcyc ) +{ + int i, j, k, l, iin, jin, ifi, jfi, lgth1, lgth2; + char gap[] = "-"; + float wm; + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); + +#if DEBUG + for( i=0; i= wm ) + { + wm = lastverticalw[i]; + iin = i; jin = lgth2-1; + ijp[lgth1][lgth2] = +( lgth1 - i ); + } + } + for( j=0; j= wm ) + { + wm = lasthorizontalw[j]; + iin = lgth1-1; jin = j; + ijp[lgth1][lgth2] = -( lgth2 - j ); + } + } + } + + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + for( i=0; i lgth1, outgap == 1 -> lgth1+1 */ + int lgth1, lgth2; + int resultlen; + float wm = 0.0; /* int ?????? */ + float g; + float x; + static float mi, *m; + static int **ijp; + static int mpi, *mp; + static float *currentw; + static float *previousw; + static float *match; + static float *initverticalw; /* kufuu sureba iranai */ + static float *lastverticalw; /* kufuu sureba iranai */ + static char **mseq1; + static char **mseq2; + static char **mseq; + static float **cpmx1; + static float **cpmx2; + static int **intwork; + static float **floatwork; + static int orlgth1 = 0, orlgth2 = 0; + +#if DEBUG + fprintf( stderr, "eff in SA+++align\n" ); + for( i=0; i orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( currentw ); + FreeFloatVec( previousw ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + + FreeCharMtx( mseq ); + + FreeFloatMtx( cpmx1 ); + FreeFloatMtx( cpmx2 ); + + FreeFloatMtx( floatwork ); + FreeIntMtx( intwork ); + } + + ll1 = MAX( (int)(1.1*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.1*lgth2), orlgth2 ) + 100; + + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); + + currentw = AllocateFloatVec( ll2+2 ); + previousw = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + + m = AllocateFloatVec( ll2+2 ); + mp = AllocateIntVec( ll2+2 ); + + mseq = AllocateCharMtx( njob, ll1+ll2 ); + + cpmx1 = AllocateFloatMtx( 26, ll1+2 ); + cpmx2 = AllocateFloatMtx( 26, ll2+2 ); + + floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); + + fprintf( stderr, "succeeded\n" ); + + orlgth1 = ll1; + orlgth2 = ll2; + } + + for( i=0; i commonAlloc1 || orlgth2 > commonAlloc2 ) + { + int ll1, ll2; + + if( commonAlloc1 && commonAlloc2 ) + { + FreeIntMtx( commonIP ); + } + + ll1 = MAX( orlgth1, commonAlloc1 ); + ll2 = MAX( orlgth2, commonAlloc2 ); + + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); + + commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + + fprintf( stderr, "succeeded\n\n" ); + + commonAlloc1 = ll1; + commonAlloc2 = ll2; + } + ijp = commonIP; + + cpmx_calc( seq1, cpmx1, eff1, strlen( seq1[0] ), icyc ); + cpmx_calc( seq2, cpmx2, eff2, strlen( seq2[0] ), jcyc ); + + match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 ); + match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 ); + + if( outgap == 1 ) + { + for( i=1; i wm ) + { + wm = x; + ijp[i][j] = -( j - mpi ); + } + g = penalty * 0.5; + x = previousw[j-1] + g; + if( mi <= x ) + { + mi = x; + mpi = j-1; + } + + g = penalty * 0.5; + x = m[j] + g; + if( x > wm ) + { + wm = x; + ijp[i][j] = +( i - mp[j] ); + } + g = penalty * 0.5; + x = previousw[j-1] + g; + if( m[j] <= x ) + { + m[j] = x; + mp[j] = i-1; + } + currentw[j] += wm; + } + lastverticalw[i] = currentw[lgth2-1]; + } + /* + fprintf( stderr, "\n" ); + for( i=0; i" ); + for( i=0; i N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } + + for( i=0; istart1 ); +// fprintf( stderr, "end1 = %d\n", tmpptr->end1 ); +// fprintf( stderr, "i = %d, seq1 = \n%s\n", i, seq1[i] ); +// fprintf( stderr, "j = %d, seq2 = \n%s\n", j, seq2[j] ); + pt = seq1[i]; + tmpint = -1; + while( *pt != 0 ) + { + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->start1 ) break; + } + start1 = pt - seq1[i] - 1; + + if( tmpptr->start1 == tmpptr->end1 ) end1 = start1; + else + { +#if MACHIGAI + while( *pt != 0 ) + { +// fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] ); + if( tmpint == tmpptr->end1 ) break; + if( *pt++ != '-' ) tmpint++; + } + end1 = pt - seq1[i] - 0; +#else + while( *pt != 0 ) + { +// fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] ); + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->end1 ) break; + } + end1 = pt - seq1[i] - 1; +#endif + } + + pt = seq2[j]; + tmpint = -1; + while( *pt != 0 ) + { + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->start2 ) break; + } + start2 = pt - seq2[j] - 1; + if( tmpptr->start2 == tmpptr->end2 ) end2 = start2; + else + { +#if MACHIGAI + while( *pt != 0 ) + { + if( tmpint == tmpptr->end2 ) break; + if( *pt++ != '-' ) tmpint++; + } + end2 = pt - seq2[j] - 0; +#else + while( *pt != 0 ) + { + if( *pt++ != '-' ) tmpint++; + if( tmpint == tmpptr->end2 ) break; + } + end2 = pt - seq2[j] - 1; +#endif + } +// fprintf( stderr, "start1 = %d (%c), end1 = %d (%c), start2 = %d (%c), end2 = %d (%c)\n", start1, seq1[i][start1], end1, seq1[i][end1], start2, seq2[j][start2], end2, seq2[j][end2] ); +// fprintf( stderr, "step 0\n" ); + if( end1 - start1 != end2 - start2 ) + { +// fprintf( stderr, "CHUUI!!, start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 ); + } + +#if 1 + k1 = start1; k2 = start2; + pt1 = seq1[i] + k1; + pt2 = seq2[j] + k2; + while( *pt1 && *pt2 ) + { + if( *pt1 != '-' && *pt2 != '-' ) + { +// ?????????????????????????????????????????? +// impmtx[k1][k2] += tmpptr->wimportance * fastathreshold; +// impmtx[k1][k2] += tmpptr->importance * effij; + impmtx[k1][k2] += tmpptr->fimportance * effij; +// fprintf( stderr, "#### impmtx[k1][k2] = %f, tmpptr->fimportance=%f, effij=%f\n", impmtx[k1][k2], tmpptr->fimportance, effij ); +// fprintf( stderr, "mark, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); +// fprintf( stderr, "%d (%c) - %d (%c) - %f\n", k1, *pt1, k2, *pt2, tmpptr->fimportance * effij ); + k1++; k2++; + pt1++; pt2++; + } + else if( *pt1 != '-' && *pt2 == '-' ) + { +// fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); + k2++; pt2++; + } + else if( *pt1 == '-' && *pt2 != '-' ) + { +// fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); + k1++; pt1++; + } + else if( *pt1 == '-' && *pt2 == '-' ) + { +// fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); + k1++; pt1++; + k2++; pt2++; + } + if( k1 > end1 || k2 > end2 ) break; + } +#else + while( k1 <= end1 && k2 <= end2 ) + { + fprintf( stderr, "k1,k2=%d,%d - ", k1, k2 ); + if( !nocount1[k1] && !nocount2[k2] ) + { + impmtx[k1][k2] += tmpptr->wimportance * eff1[i] * eff2[j] * fastathreshold; + fprintf( stderr, "marked\n" ); + } + else + fprintf( stderr, "no count\n" ); + k1++; k2++; + } +#endif + tmpptr = tmpptr->next; + } + } + } + +#if 0 + if( clus1 == 1 && clus2 == 1 ) + { + fprintf( stderr, "writing impmtx\n" ); + fprintf( stderr, "\n" ); + fprintf( stderr, "seq1[0] = %s\n", seq1[0] ); + fprintf( stderr, "seq2[0] = %s\n", seq2[0] ); + fprintf( stderr, "impmtx = \n" ); + for( k2=0; k2start1 ); + fprintf( stderr, "end1 = %d\n", localhom[i][j]->end1 ); + fprintf( stderr, "j = %d, seq2 = %s\n", j, seq2[j] ); + pt = seq1[i]; + tmpint = -1; + while( *pt != 0 ) + { + if( *pt++ != '-' ) tmpint++; + if( tmpint == localhom[i][j]->start1 ) break; + } + start1 = pt - seq1[i] - 1; + + while( *pt != 0 ) + { +// fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, localhom[i][j].end1, pt-seq1[i] ); + if( *pt++ != '-' ) tmpint++; + if( tmpint == localhom[i][j]->end1 ) break; + } + end1 = pt - seq1[i] - 1; + + pt = seq2[j]; + tmpint = -1; + while( *pt != 0 ) + { + if( *pt++ != '-' ) tmpint++; + if( tmpint == localhom[i][j]->start2 ) break; + } + start2 = pt - seq2[j] - 1; + while( *pt != 0 ) + { + if( *pt++ != '-' ) tmpint++; + if( tmpint == localhom[i][j]->end2 ) break; + } + end2 = pt - seq2[j] - 1; +// fprintf( stderr, "start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 ); + k1 = start1; + k2 = start2; + fprintf( stderr, "step 0\n" ); + while( k1 <= end1 && k2 <= end2 ) + { +#if 0 + if( !nocount1[k1] && !nocount2[k2] ) + impmtx[k1][k2] += localhom[i][j].wimportance * eff1[i] * eff2[j]; + k1++; k2++; +#else + if( !nocount1[k1] && !nocount2[k2] ) + impmtx[k1][k2] += localhom[i][j]->wimportance * eff1[i] * eff2[j]; + k1++; k2++; +#endif + } + + dif = ( end1 - start1 ) - ( end2 - start2 ); + fprintf( stderr, "dif = %d\n", dif ); + if( dif > 0 ) + { + do + { + fprintf( stderr, "dif = %d\n", dif ); + k1 = start1; + k2 = start2 - dif; + while( k1 <= end1 && k2 <= end2 ) + { + if( 0 <= k2 && start2 <= k2 && !nocount1[k1] && !nocount2[k2] ) + impmtx[k1][k2] = localhom[i][j]->wimportance * eff1[i] * eff2[j]; + k1++; k2++; + } + } + while( dif-- ); + } + else + { + do + { + k1 = start1 + dif; + k2 = start2; + while( k1 <= end1 ) + { + if( k1 >= 0 && k1 >= start1 && !nocount1[k1] && !nocount2[k2] ) + impmtx[k1][k2] = localhom[i][j]->wimportance * eff1[i] * eff2[j]; + k1++; k2++; + } + } + while( dif++ ); + } + } + } +#if 0 + fprintf( stderr, "impmtx = \n" ); + for( k2=0; k2-1 ) + *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++; + matchpt++; + } + } +#else + int j, k, l; + float scarr[26]; + float **cpmxpd = floatwork; + int **cpmxpdn = intwork; +// simple + if( initialize ) + { + int count = 0; + for( j=0; j-1; k++ ) + match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j]; + } +#endif +} + +static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *lastverticalw, + char **seq1, char **seq2, + char **mseq1, char **mseq2, + float **cpmx1, float **cpmx2, + int **ijp, int icyc, int jcyc ) +{ + int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k; + float wm; + char *gaptable1, *gt1bk; + char *gaptable2, *gt2bk; + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); + gt1bk = AllocateCharVec( lgth1+lgth2+1 ); + gt2bk = AllocateCharVec( lgth1+lgth2+1 ); + +#if 0 + for( i=0; i= wm ) + { + wm = lastverticalw[i]; + iin = i; jin = lgth2-1; + ijp[lgth1][lgth2] = +( lgth1 - i ); + } + } + for( j=0; j= wm ) + { + wm = lasthorizontalw[j]; + iin = lgth1-1; jin = j; + ijp[lgth1][lgth2] = -( lgth2 - j ); + } + } + } + + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + } + if( iin == lgth1 || jin == lgth2 ) + ; + else + { + *impwmpt += imp_match_out_sc( iin, jin ); + +// fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] ); + } + if( iin <= 0 || jin <= 0 ) break; + *--gaptable1 = 'o'; + *--gaptable2 = 'o'; + k++; + iin = ifi; jin = jfi; + } + + for( i=0; i= wm ) + { + wm = lastverticalw[i]; + iin = i; jin = lgth2-1; + ijp[lgth1][lgth2] = +( lgth1 - i ); + } + } + for( j=0; j= wm ) + { + wm = lasthorizontalw[j]; + iin = lgth1-1; jin = j; + ijp[lgth1][lgth2] = -( lgth2 - j ); + } + } + } + + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + } + if( iin == lgth1 || jin == lgth2 ) + ; + else + { + *impwmpt += imp_match_out_sc( gapmap1[iin], gapmap2[jin] ); + +// fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] ); + } + if( iin <= 0 || jin <= 0 ) break; + *--gaptable1 = '-'; + *--gaptable2 = '-'; + k++; + iin = ifi; jin = jfi; + } + for( i=0; i= wm ) + { + wm = lastverticalw[i]; + iin = i; jin = lgth2-1; + ijp[lgth1][lgth2] = +( lgth1 - i ); + } + } + for( j=0; j= wm ) + { + wm = lasthorizontalw[j]; + iin = lgth1-1; jin = j; + ijp[lgth1][lgth2] = -( lgth2 - j ); + } + } + } + + for( i=0; i 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + } + if( iin <= 0 || jin <= 0 ) break; + *--gaptable1 = 'o'; + *--gaptable2 = 'o'; + k++; + iin = ifi; jin = jfi; + } + + for( i=0; i lgth1, outgap == 1 -> lgth1+1 */ + int lgth1, lgth2; + int resultlen; + float wm = 0.0; /* int ?????? */ + float g; + float *currentw, *previousw; +// float fpenalty = (float)penalty; +#if USE_PENALTY_EX + float fpenalty_ex = (float)penalty_ex; +#endif +#if 1 + float *wtmp; + int *ijppt; + float *mjpt, *prept, *curpt; + int *mpjpt; +#endif + static float mi, *m; + static int **ijp; + static int mpi, *mp; + static float *w1, *w2; + static float *match; + static float *initverticalw; /* kufuu sureba iranai */ + static float *lastverticalw; /* kufuu sureba iranai */ + static char **mseq1; + static char **mseq2; + static char **mseq; + static float *ogcp1; + static float *ogcp2; + static float *fgcp1; + static float *fgcp2; + static float **cpmx1; + static float **cpmx2; + static int **intwork; + static float **floatwork; + static int orlgth1 = 0, orlgth2 = 0; + float fpenalty = (float)penalty; + float *fgcp2pt; + float *ogcp2pt; + float fgcp1va; + float ogcp1va; + + + +#if 0 + fprintf( stderr, "#### eff in SA+++align\n" ); + fprintf( stderr, "#### seq1[0] = %s\n", seq1[0] ); + fprintf( stderr, "#### strlen( seq1[0] ) = %d\n", strlen( seq1[0] ) ); + for( i=0; i orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + + FreeCharMtx( mseq ); + + FreeFloatVec( ogcp1 ); + FreeFloatVec( ogcp2 ); + FreeFloatVec( fgcp1 ); + FreeFloatVec( fgcp2 ); + + + FreeFloatMtx( cpmx1 ); + FreeFloatMtx( cpmx2 ); + + FreeFloatMtx( floatwork ); + FreeIntMtx( intwork ); + } + + ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100; + +#if DEBUG + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); +#endif + + w1 = AllocateFloatVec( ll2+2 ); + w2 = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + + m = AllocateFloatVec( ll2+2 ); + mp = AllocateIntVec( ll2+2 ); + + mseq = AllocateCharMtx( njob, ll1+ll2 ); + + ogcp1 = AllocateFloatVec( ll1+2 ); + ogcp2 = AllocateFloatVec( ll2+2 ); + fgcp1 = AllocateFloatVec( ll1+2 ); + fgcp2 = AllocateFloatVec( ll2+2 ); + + cpmx1 = AllocateFloatMtx( 26, ll1+2 ); + cpmx2 = AllocateFloatMtx( 26, ll2+2 ); + +#if FASTMATCHCALC + floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); + intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); +#else + floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); +#endif + +#if DEBUG + fprintf( stderr, "succeeded\n" ); +#endif + + orlgth1 = ll1 - 100; + orlgth2 = ll2 - 100; + } + + + for( i=0; i commonAlloc1 || orlgth2 > commonAlloc2 ) + { + int ll1, ll2; + + if( commonAlloc1 && commonAlloc2 ) + { + FreeIntMtx( commonIP ); + } + + ll1 = MAX( orlgth1, commonAlloc1 ); + ll2 = MAX( orlgth2, commonAlloc2 ); + +#if DEBUG + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + + commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + +#if DEBUG + fprintf( stderr, "succeeded\n\n" ); +#endif + + commonAlloc1 = ll1; + commonAlloc2 = ll2; + } + ijp = commonIP; + +#if 0 + { + float t = 0.0; + for( i=0; i tbfast.c + if( localhom ) + imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 ); + +#endif + + if( outgap == 1 ) + { + for( i=1; i", wm ); +#endif +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( (g=mi+*fgcp2pt) > wm ) + { + wm = g; + *ijppt = -( j - mpi ); + } + if( (g=*prept+*ogcp2pt) >= mi ) + { + mi = g; + mpi = j-1; + } +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( (g=*mjpt+fgcp1va) > wm ) + { + wm = g; + *ijppt = +( i - *mpjpt ); + } + if( (g=*prept+ogcp1va) >= *mjpt ) + { + *mjpt = g; + *mpjpt = i-1; + } +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + *curpt++ += wm; + ijppt++; + mjpt++; + prept++; + mpjpt++; + fgcp2pt++; + ogcp2pt++; + } + lastverticalw[i] = currentw[lgth2-1]; + } + +// fprintf( stderr, "wm = %f\n", wm ); + +#if OUTGAP0TRY + if( !outgap ) + { + for( j=1; j" ); + for( i=0; i N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } + + + for( i=0; i lgth1, outgap == 1 -> lgth1+1 */ + int lgth1, lgth2; + int resultlen; + float wm = 0.0; /* int ?????? */ + float g; + float *currentw, *previousw; +// float fpenalty = (float)penalty; +#if USE_PENALTY_EX + float fpenalty_ex = (float)penalty_ex; +#endif +#if 1 + float *wtmp; + int *ijppt; + float *mjpt, *prept, *curpt; + int *mpjpt; +#endif + static float mi, *m; + static int **ijp; + static int mpi, *mp; + static float *w1, *w2; + static float *match; + static float *initverticalw; /* kufuu sureba iranai */ + static float *lastverticalw; /* kufuu sureba iranai */ + static char **mseq1; + static char **mseq2; + static char **mseq; + static float *ogcp1; + static float *ogcp2; + static float *fgcp1; + static float *fgcp2; + static float **cpmx1; + static float **cpmx2; + static int **intwork; + static float **floatwork; + static int orlgth1 = 0, orlgth2 = 0; + float *fgcp2pt; + float *ogcp2pt; + float fgcp1va; + float ogcp1va; + + +#if 0 + fprintf( stderr, "eff in SA+++align\n" ); + for( i=0; i orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + + FreeCharMtx( mseq ); + + FreeFloatVec( ogcp1 ); + FreeFloatVec( ogcp2 ); + FreeFloatVec( fgcp1 ); + FreeFloatVec( fgcp2 ); + + + FreeFloatMtx( cpmx1 ); + FreeFloatMtx( cpmx2 ); + + FreeFloatMtx( floatwork ); + FreeIntMtx( intwork ); + } + + ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100; + +#if DEBUG + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); +#endif + + w1 = AllocateFloatVec( ll2+2 ); + w2 = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + + m = AllocateFloatVec( ll2+2 ); + mp = AllocateIntVec( ll2+2 ); + + mseq = AllocateCharMtx( njob, ll1+ll2 ); + + ogcp1 = AllocateFloatVec( ll1+2 ); + ogcp2 = AllocateFloatVec( ll2+2 ); + fgcp1 = AllocateFloatVec( ll1+2 ); + fgcp2 = AllocateFloatVec( ll2+2 ); + + cpmx1 = AllocateFloatMtx( 26, ll1+2 ); + cpmx2 = AllocateFloatMtx( 26, ll2+2 ); + +#if FASTMATCHCALC + floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); + intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); +#else + floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( 27, MAX( ll1, ll2 )+2 ); +#endif + +#if DEBUG + fprintf( stderr, "succeeded\n" ); +#endif + + orlgth1 = ll1 - 100; + orlgth2 = ll2 - 100; + } + + + for( i=0; i commonAlloc1 || orlgth2 > commonAlloc2 ) + { + int ll1, ll2; + + if( commonAlloc1 && commonAlloc2 ) + { + FreeIntMtx( commonIP ); + } + + ll1 = MAX( orlgth1, commonAlloc1 ); + ll2 = MAX( orlgth2, commonAlloc2 ); + +#if DEBUG + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + + commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + +#if DEBUG + fprintf( stderr, "succeeded\n\n" ); +#endif + + commonAlloc1 = ll1; + commonAlloc2 = ll2; + } + ijp = commonIP; + + cpmx_calc_new( seq1, cpmx1, eff1, strlen( seq1[0] ), icyc ); + cpmx_calc_new( seq2, cpmx2, eff2, strlen( seq2[0] ), jcyc ); + + st_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 ); + st_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 ); + st_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 ); + st_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 ); + + for( i=0; i tbfast.c + if( localhom ) + imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 ); + +#endif + + if( outgap == 1 ) + { + for( i=1; i", wm ); +#endif + g = mi + *fgcp2pt; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; + *ijppt = -( j - mpi ); + } + g = *prept + *ogcp2pt; + if( g >= mi ) + { + mi = g; + mpi = j-1; + } +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + + g = *mjpt + fgcp1va; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; + *ijppt = +( i - *mpjpt ); + } + g = *prept + ogcp1va; + if( g >= *mjpt ) + { + *mjpt = g; + *mpjpt = i-1; + } +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + *curpt++ += wm; + ijppt++; + mjpt++; + prept++; + mpjpt++; + fgcp2pt++; + ogcp2pt++; + } + lastverticalw[i] = currentw[lgth2-1]; + } + +#if OUTGAP0TRY + if( !outgap ) + { + for( j=1; j" ); + for( i=0; i N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } + + + for( i=0; i N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } + for( i=0; i 0.0 ) out = ( (int)( in + 0.5 ) ); + else if( in == 0.0 ) out = ( 0 ); + else if( in < 0.0 ) out = ( (int)( in - 0.5 ) ); + else out = 0; + return( out ); +} + +static void calcfreq_nuc( int nseq, char **seq, double *datafreq ) +{ + int i, j, l; + int aan; + double total; + for( i=0; i<4; i++ ) + datafreq[i] = 0.0; + total = 0.0; + for( i=0; i= 0 && aan < 4 ) + { + datafreq[aan] += 1.0; + total += 1.0; + } + } + } + for( i=0; i<4; i++ ) + if( datafreq[i] < 0.0001 ) datafreq[i] = 0.0001; + +#if 0 + fprintf( stderr, "\ndatafreq = " ); + for( i=0; i<4; i++ ) + fprintf( stderr, "%10.0f ", datafreq[i] ); + fprintf( stderr, "\n" ); +#endif + + total = 0.0; for( i=0; i<4; i++ ) total += datafreq[i]; +// fprintf( stderr, "total = %f\n", total ); + for( i=0; i<4; i++ ) datafreq[i] /= (double)total; +} + +static void calcfreq( int nseq, char **seq, double *datafreq ) +{ + int i, j, l; + int aan; + double total; + for( i=0; i<20; i++ ) + datafreq[i] = 0.0; + total = 0.0; + for( i=0; i= 0 && aan < 20 ) + { + datafreq[aan] += 1.0; + total += 1.0; + } + } + } + for( i=0; i<20; i++ ) + if( datafreq[i] < 0.0001 ) datafreq[i] = 0.0001; + + fprintf( stderr, "datafreq = \n" ); + for( i=0; i<20; i++ ) + fprintf( stderr, "%f\n", datafreq[i] ); + + total = 0.0; for( i=0; i<20; i++ ) total += datafreq[i]; + fprintf( stderr, "total = %f\n", total ); + for( i=0; i<20; i++ ) datafreq[i] /= (double)total; +} + +void constants( int nseq, char **seq ) +{ + int i, j, x; +// double tmp; + + if( dorp == 'd' ) /* DNA */ + { + int k, m; + double average; + double **pamx = AllocateDoubleMtx( 11,11 ); + double **pam1 = AllocateDoubleMtx( 4, 4 ); + double *freq = AllocateDoubleVec( 4 ); + + + scoremtx = -1; + if( RNAppenalty == NOTSPECIFIED ) RNAppenalty = DEFAULTRNAGOP_N; + if( RNAppenalty_ex == NOTSPECIFIED ) RNAppenalty_ex = DEFAULTRNAGEP_N; + if( ppenalty == NOTSPECIFIED ) ppenalty = DEFAULTGOP_N; + if( ppenalty_OP == NOTSPECIFIED ) ppenalty_OP = DEFAULTGOP_N; + if( ppenalty_ex == NOTSPECIFIED ) ppenalty_ex = DEFAULTGEP_N; + if( ppenalty_EX == NOTSPECIFIED ) ppenalty_EX = DEFAULTGEP_N; + if( poffset == NOTSPECIFIED ) poffset = DEFAULTOFS_N; + if( RNApthr == NOTSPECIFIED ) RNApthr = DEFAULTRNATHR_N; + if( pamN == NOTSPECIFIED ) pamN = DEFAULTPAMN; + if( kimuraR == NOTSPECIFIED ) kimuraR = 2; + + RNApenalty = (int)( 3 * 600.0 / 1000.0 * RNAppenalty + 0.5 ); + RNApenalty_ex = (int)( 3 * 600.0 / 1000.0 * RNAppenalty_ex + 0.5 ); +// fprintf( stderr, "DEFAULTRNAGOP_N = %d\n", DEFAULTRNAGOP_N ); +// fprintf( stderr, "RNAppenalty = %d\n", RNAppenalty ); +// fprintf( stderr, "RNApenalty = %d\n", RNApenalty ); + + + RNAthr = (int)( 3 * 600.0 / 1000.0 * RNApthr + 0.5 ); + penalty = (int)( 3 * 600.0 / 1000.0 * ppenalty + 0.5); + penalty_OP = (int)( 3 * 600.0 / 1000.0 * ppenalty_OP + 0.5); + penalty_ex = (int)( 3 * 600.0 / 1000.0 * ppenalty_ex + 0.5); + penalty_EX = (int)( 3 * 600.0 / 1000.0 * ppenalty_EX + 0.5); + offset = (int)( 3 * 600.0 / 1000.0 * poffset + 0.5); + offsetFFT = (int)( 3 * 600.0 / 1000.0 * (-0) + 0.5); + offsetLN = (int)( 3 * 600.0 / 1000.0 * 100 + 0.5); + penaltyLN = (int)( 3 * 600.0 / 1000.0 * -2000 + 0.5); + penalty_exLN = (int)( 3 * 600.0 / 1000.0 * -100 + 0.5); + sprintf( modelname, "%s%d (%d), %6.3f (%6.3f), %6.3f (%6.3f)", rnakozo?"RNA":"DNA", pamN, kimuraR, + -(double)ppenalty*0.001, -(double)ppenalty*0.003, -(double)poffset*0.001, -(double)poffset*0.003 ); + + if( kimuraR == 9999 ) + { + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + pamx[i][j] = (double)locn_disn[i][j]; +#if NORMALIZE1 + average = 0.0; + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + average += pamx[i][j]; + average /= 16.0; + + if( disp ) + fprintf( stderr, "average = %f\n", average ); + + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + pamx[i][j] -= average; + + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + pamx[i][j] *= 600.0 / average; + + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + pamx[i][j] -= offset; +#endif + } + else + { + double f = 0.99; + double s = (double)kimuraR / ( 2 + kimuraR ) * 0.01; + double v = (double)1 / ( 2 + kimuraR ) * 0.01; + pam1[0][0] = f; pam1[0][1] = s; pam1[0][2] = v; pam1[0][3] = v; + pam1[1][0] = s; pam1[1][1] = f; pam1[1][2] = v; pam1[1][3] = v; + pam1[2][0] = v; pam1[2][1] = v; pam1[2][2] = f; pam1[2][3] = s; + pam1[3][0] = v; pam1[3][1] = v; pam1[3][2] = s; pam1[3][3] = f; + + fprintf( stderr, "generating %dPAM scoring matrix for nucleotides ... ", pamN ); + + if( disp ) + { + fprintf( stderr, " TPM \n" ); + for( i=0; i<4; i++ ) + { + for( j=0; j<4; j++ ) + fprintf( stderr, "%+#6.10f", pam1[i][j] ); + fprintf( stderr, "\n" ); + } + fprintf( stderr, "\n" ); + } + + + MtxuntDouble( pamx, 4 ); + for( x=0; x < pamN; x++ ) MtxmltDouble( pamx, pam1, 4 ); + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + pamx[i][j] /= 1.0 / 4.0; + + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + { + if( pamx[i][j] == 0.0 ) + { + fprintf( stderr, "WARNING: pamx[i][j] = 0.0 ?\n" ); + pamx[i][j] = 0.00001; /* by J. Thompson */ + } + pamx[i][j] = log10( pamx[i][j] ) * 1000.0; + } + + if( disp ) + { + fprintf( stderr, " after log\n" ); + for( i=0; i<4; i++ ) + { + for( j=0; j<4; j++ ) + fprintf( stderr, "%+#6.10f", pamx[i][j] ); + fprintf( stderr, "\n" ); + } + fprintf( stderr, "\n" ); + } + + +// ????? + for( i=0; i<26; i++ ) amino[i] = locaminon[i]; + for( i=0; i<0x80; i++ ) amino_n[i] = -1; + for( i=0; i<26; i++ ) amino_n[(int)amino[i]] = i; + if( fmodel == 1 ) + calcfreq_nuc( nseq, seq, freq ); + else + { + freq[0] = 0.25; + freq[1] = 0.25; + freq[2] = 0.25; + freq[3] = 0.25; + } +// fprintf( stderr, "a, freq[0] = %f\n", freq[0] ); +// fprintf( stderr, "g, freq[1] = %f\n", freq[1] ); +// fprintf( stderr, "c, freq[2] = %f\n", freq[2] ); +// fprintf( stderr, "t, freq[3] = %f\n", freq[3] ); + + + average = 0.0; + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + average += pamx[i][j] * freq[i] * freq[j]; + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + pamx[i][j] -= average; + + average = 0.0; + for( i=0; i<4; i++ ) + average += pamx[i][i] * 1.0 / 4.0; + + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + pamx[i][j] *= 600.0 / average; + + + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + pamx[i][j] -= offset; /* extending gap cost */ + + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + pamx[i][j] = shishagonyuu( pamx[i][j] ); + + if( disp ) + { + fprintf( stderr, " after shishagonyuu\n" ); + for( i=0; i<4; i++ ) + { + for( j=0; j<4; j++ ) + fprintf( stderr, "%+#6.10f", pamx[i][j] ); + fprintf( stderr, "\n" ); + } + fprintf( stderr, "\n" ); + } + fprintf( stderr, "done\n" ); + } + + for( i=0; i<5; i++ ) + { + pamx[4][i] = pamx[3][i]; + pamx[i][4] = pamx[i][3]; + } + + for( i=5; i<10; i++ ) for( j=5; j<10; j++ ) + { + pamx[i][j] = pamx[i-5][j-5]; + } + + if( disp ) + { + fprintf( stderr, " before dis\n" ); + for( i=0; i<4; i++ ) + { + for( j=0; j<4; j++ ) + fprintf( stderr, "%+#6.10f", pamx[i][j] ); + fprintf( stderr, "\n" ); + } + fprintf( stderr, "\n" ); + } + + if( disp ) + { + fprintf( stderr, " score matrix \n" ); + for( i=0; i<4; i++ ) + { + for( j=0; j<4; j++ ) + fprintf( stderr, "%+#6.10f", pamx[i][j] ); + fprintf( stderr, "\n" ); + } + fprintf( stderr, "\n" ); + } + + for( i=0; i<26; i++ ) amino[i] = locaminon[i]; + for( i=0; i<26; i++ ) amino_grp[(int)amino[i]] = locgrpn[i]; + for( i=0; i<26; i++ ) for( j=0; j<26; j++ ) n_dis[i][j] = 0; + for( i=0; i<10; i++ ) for( j=0; j<10; j++ ) n_dis[i][j] = shishagonyuu( pamx[i][j] ); + if( disp ) + { + fprintf( stderr, " score matrix \n" ); + for( i=0; i<26; i++ ) + { + for( j=0; j<26; j++ ) + fprintf( stderr, "%+6d", n_dis[i][j] ); + fprintf( stderr, "\n" ); + } + fprintf( stderr, "\n" ); + } + +// RIBOSUM +#if 1 + average = 0.0; + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + average += ribosum4[i][j] * freq[i] * freq[j]; + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + ribosum4[i][j] -= average; + + average = 0.0; + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) for( k=0; k<4; k++ ) for( m=0; m<4; m++ ) + { +// if( i%4==0&&j%4==3 || i%4==3&&j%4==0 || i%4==1&&j%4==2 || i%4==2&&j%4==1 || i%4==1&&j%4==3 || i%4==3&&j%4==1 ) +// if( k%4==0&&m%4==3 || k%4==3&&m%4==0 || k%4==1&&m%4==2 || k%4==2&&m%4==1 || k%4==1&&m%4==3 || k%4==3&&m%4==1 ) + average += ribosum16[i*4+j][k*4+m] * freq[i] * freq[j] * freq[k] * freq[m]; + } + for( i=0; i<16; i++ ) for( j=0; j<16; j++ ) + ribosum16[i][j] -= average; + + average = 0.0; + for( i=0; i<4; i++ ) + average += ribosum4[i][i] * freq[i]; + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + ribosum4[i][j] *= 600.0 / average; + + average = 0.0; + average += ribosum16[0*4+3][0*4+3] * freq[0] * freq[3]; // AU + average += ribosum16[3*4+0][3*4+0] * freq[3] * freq[0]; // UA + average += ribosum16[1*4+2][1*4+2] * freq[1] * freq[2]; // CG + average += ribosum16[2*4+1][2*4+1] * freq[2] * freq[1]; // GC + average += ribosum16[1*4+3][1*4+3] * freq[1] * freq[3]; // GU + average += ribosum16[3*4+1][3*4+1] * freq[3] * freq[1]; // UG + for( i=0; i<16; i++ ) for( j=0; j<16; j++ ) + ribosum16[i][j] *= 600.0 / average; + + +#if 1 + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + ribosum4[i][j] -= offset; /* extending gap cost ?????*/ + for( i=0; i<16; i++ ) for( j=0; j<16; j++ ) + ribosum16[i][j] -= offset; /* extending gap cost ?????*/ +#endif + + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) + ribosum4[i][j] = shishagonyuu( ribosum4[i][j] ); + for( i=0; i<16; i++ ) for( j=0; j<16; j++ ) + ribosum16[i][j] = shishagonyuu( ribosum16[i][j] ); + + if( disp ) + { + fprintf( stderr, "ribosum after shishagonyuu\n" ); + for( i=0; i<4; i++ ) + { + for( j=0; j<4; j++ ) + fprintf( stderr, "%+#6.10f", ribosum4[i][j] ); + fprintf( stderr, "\n" ); + } + fprintf( stderr, "\n" ); + fprintf( stderr, "ribosum16 after shishagonyuu\n" ); + for( i=0; i<16; i++ ) + { + for( j=0; j<16; j++ ) + fprintf( stderr, "%+#7.0f", ribosum16[i][j] ); + fprintf( stderr, "\n" ); + } + fprintf( stderr, "\n" ); + } + fprintf( stderr, "done\n" ); + +#if 1 + for( i=0; i<37; i++ ) for( j=0; j<37; j++ ) ribosumdis[i][j] = 0.0; //iru + for( m=0; m<9; m++ ) for( i=0; i<4; i++ ) // loop + for( k=0; k<9; k++ ) for( j=0; j<4; j++ ) ribosumdis[m*4+i][k*4+j] = ribosum4[i][j]; // loop-loop +// for( k=0; k<9; k++ ) for( j=0; j<4; j++ ) ribosumdis[m*4+i][k*4+j] = n_dis[i][j]; // loop-loop + + for( i=0; i<16; i++ ) for( j=0; j<16; j++ ) ribosumdis[i+4][j+4] = ribosum16[i][j]; // stem5-stem5 + for( i=0; i<16; i++ ) for( j=0; j<16; j++ ) ribosumdis[i+20][j+20] = ribosum16[i][j]; // stem5-stem5 +#else // do not use ribosum + for( i=0; i<37; i++ ) for( j=0; j<37; j++ ) ribosumdis[i][j] = 0.0; //iru + for( m=0; m<9; m++ ) for( i=0; i<4; i++ ) // loop + for( k=0; k<9; k++ ) for( j=0; j<4; j++ ) ribosumdis[m*4+i][k*4+j] = n_dis[i][j]; // loop-loop +#endif + + if( disp ) + { + fprintf( stderr, "ribosumdis\n" ); + for( i=0; i<37; i++ ) + { + for( j=0; j<37; j++ ) + fprintf( stderr, "%+5d", ribosumdis[i][j] ); + fprintf( stderr, "\n" ); + } + fprintf( stderr, "\n" ); + } + fprintf( stderr, "done\n" ); +#endif + + FreeDoubleMtx( pam1 ); + FreeDoubleMtx( pamx ); + free( freq ); + + } + else if( dorp == 'p' && scoremtx == 1 ) /* Blosum */ + { + double *freq; + double *freq1; + double *datafreq; + double average; +// double tmp; + double **n_distmp; + + n_distmp = AllocateDoubleMtx( 20, 20 ); + datafreq = AllocateDoubleVec( 20 ); + freq = AllocateDoubleVec( 20 ); + + if( ppenalty == NOTSPECIFIED ) ppenalty = DEFAULTGOP_B; + if( ppenalty_OP == NOTSPECIFIED ) ppenalty_OP = DEFAULTGOP_B; + if( ppenalty_ex == NOTSPECIFIED ) ppenalty_ex = DEFAULTGEP_B; + if( ppenalty_EX == NOTSPECIFIED ) ppenalty_EX = DEFAULTGEP_B; + if( poffset == NOTSPECIFIED ) poffset = DEFAULTOFS_B; + if( pamN == NOTSPECIFIED ) pamN = 0; + if( kimuraR == NOTSPECIFIED ) kimuraR = 1; + penalty = (int)( 600.0 / 1000.0 * ppenalty + 0.5 ); + penalty_OP = (int)( 600.0 / 1000.0 * ppenalty_OP + 0.5 ); + penalty_ex = (int)( 600.0 / 1000.0 * ppenalty_ex + 0.5 ); + penalty_EX = (int)( 600.0 / 1000.0 * ppenalty_EX + 0.5 ); + offset = (int)( 600.0 / 1000.0 * poffset + 0.5 ); + offsetFFT = (int)( 600.0 / 1000.0 * (-0) + 0.5); + offsetLN = (int)( 600.0 / 1000.0 * 100 + 0.5); + penaltyLN = (int)( 600.0 / 1000.0 * -2000 + 0.5); + penalty_exLN = (int)( 600.0 / 1000.0 * -100 + 0.5); + + BLOSUMmtx( nblosum, n_distmp, freq, amino, amino_grp ); + if( nblosum == -1 ) + sprintf( modelname, "User-defined, %6.3f, %+6.3f, %+6.3f", -(double)ppenalty/1000, -(double)poffset/1000, -(double)ppenalty_ex/1000 ); + else + sprintf( modelname, "BLOSUM%d, %6.3f, %+6.3f, %+6.3f", nblosum, -(double)ppenalty/1000, -(double)poffset/1000, -(double)ppenalty_ex/1000 ); +#if 0 + for( i=0; i<26; i++ ) amino[i] = locaminod[i]; + for( i=0; i<26; i++ ) amino_grp[(int)amino[i]] = locgrpd[i]; + for( i=0; i<0x80; i++ ) amino_n[i] = 0; + for( i=0; i<26; i++ ) amino_n[(int)amino[i]] = i; +#endif + for( i=0; i<0x80; i++ )amino_n[i] = -1; + for( i=0; i<26; i++) amino_n[(int)amino[i]] = i; + if( fmodel == 1 ) + { + calcfreq( nseq, seq, datafreq ); + freq1 = datafreq; + } + else + freq1 = freq; +#if TEST + fprintf( stderr, "raw scoreing matrix : \n" ); + for( i=0; i<20; i++ ) + { + for( j=0; j<20; j++ ) + { + fprintf( stdout, "%6.2f", n_distmp[i][j] ); + } + fprintf( stdout, "\n" ); + } +#endif + if( fmodel == -1 ) + average = 0.0; + else + { + for( i=0; i<20; i++ ) +#if TEST + fprintf( stdout, "freq[%c] = %f, datafreq[%c] = %f, freq1[] = %f\n", amino[i], freq[i], amino[i], datafreq[i], freq1[i] ); +#endif + average = 0.0; + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + average += n_distmp[i][j] * freq1[i] * freq1[j]; + } +#if TEST + fprintf( stdout, "####### average2 = %f\n", average ); +#endif + + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + n_distmp[i][j] -= average; +#if TEST + fprintf( stdout, "average2 = %f\n", average ); + fprintf( stdout, "after average substruction : \n" ); + for( i=0; i<20; i++ ) + { + for( j=0; j<20; j++ ) + { + fprintf( stdout, "%6.2f", n_distmp[i][j] ); + } + fprintf( stdout, "\n" ); + } +#endif + + average = 0.0; + for( i=0; i<20; i++ ) + average += n_distmp[i][i] * freq1[i]; +#if TEST + fprintf( stdout, "####### average1 = %f\n", average ); +#endif + + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + n_distmp[i][j] *= 600.0 / average; +#if TEST + fprintf( stdout, "after average division : \n" ); + for( i=0; i<20; i++ ) + { + for( j=0; j<=i; j++ ) + { + fprintf( stdout, "%7.1f", n_distmp[i][j] ); + } + fprintf( stdout, "\n" ); + } +#endif + + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + n_distmp[i][j] -= offset; +#if TEST + fprintf( stdout, "after offset substruction (offset = %d): \n", offset ); + for( i=0; i<20; i++ ) + { + for( j=0; j<=i; j++ ) + { + fprintf( stdout, "%7.1f", n_distmp[i][j] ); + } + fprintf( stdout, "\n" ); + } +#endif +#if 0 +/* ???? ???????????????????? */ + penalty -= offset; +#endif + + + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + n_distmp[i][j] = shishagonyuu( n_distmp[i][j] ); + + if( disp ) + { + fprintf( stdout, " scoring matrix \n" ); + for( i=0; i<20; i++ ) + { + fprintf( stdout, "%c ", amino[i] ); + for( j=0; j<20; j++ ) + fprintf( stdout, "%5.0f", n_distmp[i][j] ); + fprintf( stdout, "\n" ); + } + fprintf( stdout, " " ); + for( i=0; i<20; i++ ) + fprintf( stdout, " %c", amino[i] ); + + average = 0.0; + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + average += n_distmp[i][j] * freq1[i] * freq1[j]; + fprintf( stdout, "average = %f\n", average ); + + average = 0.0; + for( i=0; i<20; i++ ) + average += n_distmp[i][i] * freq1[i]; + fprintf( stdout, "itch average = %f\n", average ); + fprintf( stderr, "parameters: %d, %d, %d\n", penalty, penalty_ex, offset ); + + + exit( 1 ); + } + + for( i=0; i<26; i++ ) for( j=0; j<26; j++ ) n_dis[i][j] = 0; + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) n_dis[i][j] = (int)n_distmp[i][j]; + + FreeDoubleMtx( n_distmp ); + FreeDoubleVec( datafreq ); + FreeDoubleVec( freq ); + + fprintf( stderr, "done.\n" ); + + } + else if( dorp == 'p' && scoremtx == 2 ) /* Miyata-Yasunaga */ + { + fprintf( stderr, "Not supported\n" ); + exit( 1 ); + for( i=0; i<26; i++ ) for( j=0; j<26; j++ ) n_dis[i][j] = locn_dism[i][j]; + for( i=0; i<26; i++ ) if( i != 24 ) n_dis[i][24] = n_dis[24][i] = exgpm; + n_dis[24][24] = 0; + if( ppenalty == NOTSPECIFIED ) ppenalty = locpenaltym; + if( poffset == NOTSPECIFIED ) poffset = -20; + if( pamN == NOTSPECIFIED ) pamN = 0; + if( kimuraR == NOTSPECIFIED ) kimuraR = 1; + + penalty = ppenalty; + offset = poffset; + + sprintf( modelname, "Miyata-Yasunaga, %6.3f, %6.3f", -(double)ppenalty/1000, -(double)poffset/1000 ); + for( i=0; i<26; i++ ) amino[i] = locaminom[i]; + for( i=0; i<26; i++ ) amino_grp[(int)amino[i]] = locgrpm[i]; +#if DEBUG + fprintf( stdout, "scoreing matrix : \n" ); + for( i=0; i<26; i++ ) + { + for( j=0; j<26; j++ ) + { + fprintf( stdout, "%#5d", n_dis[i][j] ); + } + fprintf( stdout, "\n" ); + } +#endif + } + else /* JTT */ + { + double **rsr; + double **pam1; + double **pamx; + double *freq; + double *freq1; + double *mutab; + double *datafreq; + double average; + double tmp; + double delta; + + rsr = AllocateDoubleMtx( 20, 20 ); + pam1 = AllocateDoubleMtx( 20, 20 ); + pamx = AllocateDoubleMtx( 20, 20 ); + freq = AllocateDoubleVec( 20 ); + mutab = AllocateDoubleVec( 20 ); + datafreq = AllocateDoubleVec( 20 ); + + if( ppenalty == NOTSPECIFIED ) ppenalty = DEFAULTGOP_J; + if( ppenalty_OP == NOTSPECIFIED ) ppenalty_OP = DEFAULTGOP_J; + if( ppenalty_ex == NOTSPECIFIED ) ppenalty_ex = DEFAULTGEP_J; + if( ppenalty_EX == NOTSPECIFIED ) ppenalty_EX = DEFAULTGEP_J; + if( poffset == NOTSPECIFIED ) poffset = DEFAULTOFS_J; + if( pamN == NOTSPECIFIED ) pamN = DEFAULTPAMN; + if( kimuraR == NOTSPECIFIED ) kimuraR = 1; + + penalty = (int)( 600.0 / 1000.0 * ppenalty + 0.5 ); + penalty_OP = (int)( 600.0 / 1000.0 * ppenalty_OP + 0.5 ); + penalty_ex = (int)( 600.0 / 1000.0 * ppenalty_ex + 0.5 ); + penalty_EX = (int)( 600.0 / 1000.0 * ppenalty_EX + 0.5 ); + offset = (int)( 600.0 / 1000.0 * poffset + 0.5 ); + offsetFFT = (int)( 600.0 / 1000.0 * (-0) + 0.5 ); + offsetLN = (int)( 600.0 / 1000.0 * 100 + 0.5); + penaltyLN = (int)( 600.0 / 1000.0 * -2000 + 0.5); + penalty_exLN = (int)( 600.0 / 1000.0 * -100 + 0.5); + + sprintf( modelname, "%s %dPAM, %6.3f, %6.3f", (TMorJTT==TM)?"Transmembrane":"JTT", pamN, -(double)ppenalty/1000, -(double)poffset/1000 ); + + JTTmtx( rsr, freq, amino, amino_grp, (int)(TMorJTT==TM) ); + +#if TEST + fprintf( stdout, "rsr = \n" ); + for( i=0; i<20; i++ ) + { + for( j=0; j<20; j++ ) + { + fprintf( stdout, "%9.2f ", rsr[i][j] ); + } + fprintf( stdout, "\n" ); + } +#endif + + for( i=0; i<0x80; i++ ) amino_n[i] = -1; + for( i=0; i<26; i++ ) amino_n[(int)amino[i]] = i; + + if( fmodel == 1 ) + { + calcfreq( nseq, seq, datafreq ); + freq1 = datafreq; + } + else + freq1 = freq; + + fprintf( stderr, "generating %dPAM %s scoring matrix for amino acids ... ", pamN, (TMorJTT==TM)?"Transmembrane":"JTT" ); + + tmp = 0.0; + for( i=0; i<20; i++ ) + { + mutab[i] = 0.0; + for( j=0; j<20; j++ ) + mutab[i] += rsr[i][j] * freq[j]; + tmp += mutab[i] * freq[i]; + } +#if TEST + fprintf( stdout, "mutability = \n" ); + for( i=0; i<20; i++ ) + fprintf( stdout, "%5.3f\n", mutab[i] ); + + fprintf( stdout, "tmp = %f\n", tmp ); +#endif + delta = 0.01 / tmp; + for( i=0; i<20; i++ ) + { + for( j=0; j<20; j++ ) + { + if( i != j ) + pam1[i][j] = delta * rsr[i][j] * freq[i]; + else + pam1[i][j] = 1.0 - delta * mutab[i]; + } + } + + if( disp ) + { + fprintf( stdout, "pam1 = \n" ); + for( i=0; i<20; i++ ) + { + for( j=0; j<20; j++ ) + { + fprintf( stdout, "%9.6f ", pam1[i][j] ); + } + fprintf( stdout, "\n" ); + } + } + + MtxuntDouble( pamx, 20 ); + for( x=0; x < pamN; x++ ) MtxmltDouble( pamx, pam1, 20 ); + + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + pamx[i][j] /= freq[j]; + + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + { + if( pamx[i][j] == 0.0 ) + { + fprintf( stderr, "WARNING: pamx[%d][%d] = 0.0?\n", i, j ); + pamx[i][j] = 0.00001; /* by J. Thompson */ + } + pamx[i][j] = log10( pamx[i][j] ) * 1000.0; + } + +#if TEST + fprintf( stdout, "raw scoring matrix : \n" ); + for( i=0; i<20; i++ ) + { + for( j=0; j<20; j++ ) + { + fprintf( stdout, "%5.0f", pamx[i][j] ); + } + fprintf( stdout, "\n" ); + } + average = tmp = 0.0; + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + { + average += pamx[i][j] * freq1[i] * freq1[j]; + tmp += freq1[i] * freq1[j]; + } + average /= tmp; + fprintf( stdout, "Zenbu average = %f, tmp = %f \n", average, tmp ); + average = tmp = 0.0; + for( i=0; i<20; i++ ) for( j=i; j<20; j++ ) + { + average += pamx[i][j] * freq1[i] * freq1[j]; + tmp += freq1[i] * freq1[j]; + } + average /= tmp; + fprintf( stdout, "Zenbu average2 = %f, tmp = %f \n", average, tmp ); + average = tmp = 0.0; + for( i=0; i<20; i++ ) + { + average += pamx[i][i] * freq1[i]; + tmp += freq1[i]; + } + average /= tmp; + fprintf( stdout, "Itch average = %f, tmp = %f \n", average, tmp ); +#endif + +#if NORMALIZE1 + if( fmodel == -1 ) + average = 0.0; + else + { +#if TEST + for( i=0; i<20; i++ ) + fprintf( stdout, "freq[%c] = %f, datafreq[%c] = %f, freq1[] = %f\n", amino[i], freq[i], amino[i], datafreq[i], freq1[i] ); +#endif + average = 0.0; + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + average += pamx[i][j] * freq1[i] * freq1[j]; + } +#if TEST + fprintf( stdout, "####### average2 = %f\n", average ); +#endif + + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + pamx[i][j] -= average; +#if TEST + fprintf( stdout, "average2 = %f\n", average ); + fprintf( stdout, "after average substruction : \n" ); + for( i=0; i<20; i++ ) + { + for( j=0; j<20; j++ ) + { + fprintf( stdout, "%5.0f", pamx[i][j] ); + } + fprintf( stdout, "\n" ); + } +#endif + + average = 0.0; + for( i=0; i<20; i++ ) + average += pamx[i][i] * freq1[i]; +#if TEST + fprintf( stdout, "####### average1 = %f\n", average ); +#endif + + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + pamx[i][j] *= 600.0 / average; +#if TEST + fprintf( stdout, "after average division : \n" ); + for( i=0; i<20; i++ ) + { + for( j=0; j<=i; j++ ) + { + fprintf( stdout, "%5.0f", pamx[i][j] ); + } + fprintf( stdout, "\n" ); + } +#endif + + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + pamx[i][j] -= offset; +#if TEST + fprintf( stdout, "after offset substruction (offset = %d): \n", offset ); + for( i=0; i<20; i++ ) + { + for( j=0; j<=i; j++ ) + { + fprintf( stdout, "%5.0f", pamx[i][j] ); + } + fprintf( stdout, "\n" ); + } +#endif +#if 0 +/* ???? ???????????????????? */ + penalty -= offset; +#endif + + + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + pamx[i][j] = shishagonyuu( pamx[i][j] ); + +#else + + average = 0.0; + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + average += pamx[i][j]; + average /= 400.0; + + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + { + pamx[i][j] -= average; + pamx[i][j] = shishagonyuu( pamx[i][j] ); + } +#endif + if( disp ) + { + fprintf( stdout, " scoring matrix \n" ); + for( i=0; i<20; i++ ) + { + fprintf( stdout, "%c ", amino[i] ); + for( j=0; j<20; j++ ) + fprintf( stdout, "%5.0f", pamx[i][j] ); + fprintf( stdout, "\n" ); + } + fprintf( stdout, " " ); + for( i=0; i<20; i++ ) + fprintf( stdout, " %c", amino[i] ); + + average = 0.0; + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) + average += pamx[i][j] * freq1[i] * freq1[j]; + fprintf( stdout, "average = %f\n", average ); + + average = 0.0; + for( i=0; i<20; i++ ) + average += pamx[i][i] * freq1[i]; + fprintf( stdout, "itch average = %f\n", average ); + fprintf( stderr, "parameters: %d, %d, %d\n", penalty, penalty_ex, offset ); + + + exit( 1 ); + } + + for( i=0; i<26; i++ ) for( j=0; j<26; j++ ) n_dis[i][j] = 0; + for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) n_dis[i][j] = (int)pamx[i][j]; + + fprintf( stderr, "done.\n" ); + FreeDoubleMtx( rsr ); + FreeDoubleMtx( pam1 ); + FreeDoubleMtx( pamx ); + FreeDoubleVec( freq ); + FreeDoubleVec( mutab ); + FreeDoubleVec( datafreq ); + } + fprintf( stderr, "scoremtx = %d\n", scoremtx ); + +#if DEBUG + fprintf( stderr, "scoremtx = %d\n", scoremtx ); + fprintf( stderr, "amino[] = %s\n", amino ); +#endif + + for( i=0; i<0x80; i++ )amino_n[i] = -1; + for( i=0; i<26; i++) amino_n[(int)amino[i]] = i; + for( i=0; i<0x80; i++ ) for( j=0; j<0x80; j++ ) amino_dis[i][j] = 0; + for( i=0; i<0x80; i++ ) for( j=0; j<0x80; j++ ) amino_disLN[i][j] = 0; + for( i=0; i<0x80; i++ ) for( j=0; j<0x80; j++ ) amino_dis_consweight_multi[i][j] = 0.0; + for( i=0; i<26; i++) for( j=0; j<26; j++ ) + { + amino_dis[(int)amino[i]][(int)amino[j]] = n_dis[i][j]; + n_dis_consweight_multi[i][j] = (float)n_dis[i][j] * consweight_multi; + amino_dis_consweight_multi[(int)amino[i]][(int)amino[j]] = (double)n_dis[i][j] * consweight_multi; + } + + if( dorp == 'd' ) /* DNA */ + { + for( i=0; i<5; i++) for( j=0; j<5; j++ ) + amino_disLN[(int)amino[i]][(int)amino[j]] = n_dis[i][j] + offset - offsetLN; + for( i=5; i<10; i++) for( j=5; j<10; j++ ) + amino_disLN[(int)amino[i]][(int)amino[j]] = n_dis[i][j] + offset - offsetLN; + for( i=0; i<5; i++) for( j=0; j<5; j++ ) + n_disFFT[i][j] = n_dis[i][j] + offset - offsetFFT; + for( i=5; i<10; i++) for( j=5; j<10; j++ ) + n_disFFT[i][j] = n_dis[i][j] + offset - offsetFFT; + } + else // protein + { + for( i=0; i<20; i++) for( j=0; j<20; j++ ) + amino_disLN[(int)amino[i]][(int)amino[j]] = n_dis[i][j] + offset - offsetLN; + for( i=0; i<20; i++) for( j=0; j<20; j++ ) + n_disFFT[i][j] = n_dis[i][j] + offset - offsetFFT; + } + +#if 0 + fprintf( stderr, "amino_dis (offset = %d): \n", offset ); + for( i=0; i<20; i++ ) + { + for( j=0; j<20; j++ ) + { + fprintf( stderr, "%5d", amino_dis[(int)amino[i]][(int)amino[j]] ); + } + fprintf( stderr, "\n" ); + } + + fprintf( stderr, "amino_disLN (offsetLN = %d): \n", offsetLN ); + for( i=0; i<20; i++ ) + { + for( j=0; j<20; j++ ) + { + fprintf( stderr, "%5d", amino_disLN[(int)amino[i]][(int)amino[j]] ); + } + fprintf( stderr, "\n" ); + } + + fprintf( stderr, "n_dis (offset = %d): \n", offset ); + for( i=0; i<26; i++ ) + { + for( j=0; j<26; j++ ) + { + fprintf( stderr, "%5d", n_dis[i][j] ); + } + fprintf( stderr, "\n" ); + } + + fprintf( stderr, "n_disFFT (offsetFFT = %d): \n", offsetFFT ); + for( i=0; i<26; i++ ) + { + for( j=0; j<26; j++ ) + { + fprintf( stderr, "%5d", n_disFFT[i][j] ); + } + fprintf( stderr, "\n" ); + } +exit( 1 ); +#endif + + + ppid = 0; + + + if( fftThreshold == NOTSPECIFIED ) + { + fftThreshold = FFT_THRESHOLD; + } + if( fftWinSize == NOTSPECIFIED ) + { + if( dorp == 'd' ) + fftWinSize = FFT_WINSIZE_D; + else + fftWinSize = FFT_WINSIZE_P; + } + + + if( fftscore ) + { + double av, sd; + + for( i=0; i<20; i++ ) polarity[i] = polarity_[i]; + for( av=0.0, i=0; i<20; i++ ) av += polarity[i]; + av /= 20.0; + for( sd=0.0, i=0; i<20; i++ ) sd += ( polarity[i]-av ) * ( polarity[i]-av ); + sd /= 20.0; sd = sqrt( sd ); + for( i=0; i<20; i++ ) polarity[i] -= av; + for( i=0; i<20; i++ ) polarity[i] /= sd; + + for( i=0; i<20; i++ ) volume[i] = volume_[i]; + for( av=0.0, i=0; i<20; i++ ) av += volume[i]; + av /= 20.0; + for( sd=0.0, i=0; i<20; i++ ) sd += ( volume[i]-av ) * ( volume[i]-av ); + sd /= 20.0; sd = sqrt( sd ); + for( i=0; i<20; i++ ) volume[i] -= av; + for( i=0; i<20; i++ ) volume[i] /= sd; + +#if 0 + for( i=0; i<20; i++ ) fprintf( stdout, "amino=%c, pol = %f<-%f, vol = %f<-%f\n", amino[i], polarity[i], polarity_[i], volume[i], volume_[i] ); + for( i=0; i<20; i++ ) fprintf( stdout, "%c %+5.3f %+5.3f\n", amino[i], volume[i], polarity[i] ); +#endif + } +} Added: test-suite/trunk/MultiSource/Benchmarks/mafft/defs.c URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/defs.c?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/defs.c (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/defs.c Thu Feb 19 06:37:59 2009 @@ -0,0 +1,98 @@ +#include +#include "dp.h" +#include "mltaln.h" + +int commonAlloc1 = 0; +int commonAlloc2 = 0; +int **commonIP = NULL; +int **commonJP = NULL; + +char modelname[100]; +int njob, nlenmax; +int amino_n[0x80]; +char amino_grp[0x80]; +int amino_dis[0x80][0x80]; +int amino_disLN[0x80][0x80]; +double amino_dis_consweight_multi[0x80][0x80]; +int n_dis[26][26]; +int n_disFFT[26][26]; +float n_dis_consweight_multi[26][26]; +char amino[26]; +double polarity[20]; +double volume[20]; +int ribosumdis[37][37]; + +int ppid; +double thrinter; +double fastathreshold; +int pslocal, ppslocal; +int constraint; +int divpairscore; +int fmodel; // 1-> fmodel 0->default -1->raw +int nblosum; // 45, 50, 62, 80 +int kobetsubunkatsu; +int bunkatsu; +int dorp; +int niter; +int contin; +int calledByXced; +int devide; +int scmtd; +int weight; +int utree; +int tbutree; +int refine; +int check; +double cut; +int cooling; +int penalty, ppenalty, penaltyLN; +int RNApenalty, RNAppenalty; +int RNApenalty_ex, RNAppenalty_ex; +int penalty_ex, ppenalty_ex, penalty_exLN; +int penalty_EX, ppenalty_EX; +int penalty_OP, ppenalty_OP; +int RNAthr, RNApthr; +int offset, poffset, offsetLN, offsetFFT; +int scoremtx; +int TMorJTT; +char use_fft; +char force_fft; +int nevermemsave; +int fftscore; +int fftWinSize; +int fftThreshold; +int fftRepeatStop; +int fftNoAnchStop; +int divWinSize; +int divThreshold; +int disp; +int outgap; +char alg; +int cnst; +int mix; +int tbitr; +int tbweight; +int tbrweight; +int disopt; +int pamN; +int checkC; +float geta2; +int treemethod; +int kimuraR; +char *swopt; +int fftkeika; +int score_check; +int makedistmtx; +char *inputfile; +int rnakozo; +char rnaprediction; + +char *signalSM; +FILE *prep_g; +FILE *trap_g; +char **seq_g; +char **res_g; + +float consweight_multi = 1.0; +float consweight_rna = 0.0; +char RNAscoremtx = 'n'; Added: test-suite/trunk/MultiSource/Benchmarks/mafft/dp.h URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/dp.h?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/dp.h (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/dp.h Thu Feb 19 06:37:59 2009 @@ -0,0 +1,4 @@ +extern int commonAlloc1; +extern int commonAlloc2; +extern int **commonIP; +extern int **commonJP; Added: test-suite/trunk/MultiSource/Benchmarks/mafft/fft.c URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/fft.c?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/fft.c (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/fft.c Thu Feb 19 06:37:59 2009 @@ -0,0 +1,118 @@ +#include "mltaln.h" +#include "mtxutl.h" + +/* + {\tt fft()}. +*/ +static void make_sintbl(int n, float sintbl[]) +{ + int i, n2, n4, n8; + double c, s, dc, ds, t; + + n2 = n / 2; n4 = n / 4; n8 = n / 8; + t = sin(PI / n); + dc = 2 * t * t; ds = sqrt(dc * (2 - dc)); + t = 2 * dc; c = sintbl[n4] = 1; s = sintbl[0] = 0; + for (i = 1; i < n8; i++) { + c -= dc; dc += t * c; + s += ds; ds -= t * s; + sintbl[i] = s; sintbl[n4 - i] = c; + } + if (n8 != 0) sintbl[n8] = sqrt(0.5); + for (i = 0; i < n4; i++) + sintbl[n2 - i] = sintbl[i]; + for (i = 0; i < n2 + n4; i++) + sintbl[i + n2] = - sintbl[i]; +} +/* + {\tt fft()}. +*/ +static void make_bitrev(int n, int bitrev[]) +{ + int i, j, k, n2; + + n2 = n / 2; i = j = 0; + for ( ; ; ) { + bitrev[i] = j; + if (++i >= n) break; + k = n2; + while (k <= j) { j -= k; k /= 2; } + j += k; + } +} +/* +*/ +int fft(int n, Fukusosuu *x, int dum) +{ + static int last_n = 0; /* {\tt n} */ + static int *bitrev = NULL; /* */ + static float *sintbl = NULL; /* */ + int i, j, k, ik, h, d, k2, n4, inverse; + float t, s, c, dR, dI; + + /* */ + if (n < 0) { + n = -n; inverse = 1; /* */ + } else inverse = 0; + n4 = n / 4; + if (n != last_n || n == 0) { + last_n = n; +#if 0 + if (sintbl != NULL) { + free(sintbl); + sintbl = NULL; + } + if (bitrev != NULL) { + free(bitrev); + bitrev = NULL; + } + if (n == 0) return 0; /* */ + sintbl = (float *)malloc((n + n4) * sizeof(float)); + bitrev = (int *)malloc(n * sizeof(int)); +#else /* by T. Nishiyama */ + sintbl = realloc(sintbl, (n + n4) * sizeof(float)); + bitrev = realloc(bitrev, n * sizeof(int)); +#endif + if (sintbl == NULL || bitrev == NULL) { + fprintf(stderr, "\n"); return 1; + } + make_sintbl(n, sintbl); + make_bitrev(n, bitrev); + } + for (i = 0; i < n; i++) { /* */ + j = bitrev[i]; + if (i < j) { + t = x[i].R; x[i].R = x[j].R; x[j].R = t; + t = x[i].I; x[i].I = x[j].I; x[j].I = t; + } + } + for (k = 1; k < n; k = k2) { /* */ +#if 0 + fprintf( stderr, "%d / %d\n", k, n ); +#endif + h = 0; k2 = k + k; d = n / k2; + for (j = 0; j < k; j++) { +#if 0 + if( j % 1 == 0 ) + fprintf( stderr, "%d / %d\r", j, k ); +#endif + c = sintbl[h + n4]; + if (inverse) s = - sintbl[h]; + else s = sintbl[h]; + for (i = j; i < n; i += k2) { +#if 0 + if( k>=4194000 ) fprintf( stderr, "in loop %d - %d < %d, k2=%d\r", j, i, n, k2 ); +#endif + ik = i + k; + dR = s * x[ik].I + c * x[ik].R; + dI = c * x[ik].I - s * x[ik].R; + x[ik].R = x[i].R - dR; x[i].R += dR; + x[ik].I = x[i].I - dI; x[i].I += dI; + } + h += d; + } + } + if (! inverse) /* n */ + for (i = 0; i < n; i++) { x[i].R /= n; x[i].I /= n; } + return 0; /* */ +} Added: test-suite/trunk/MultiSource/Benchmarks/mafft/fft.h URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/fft.h?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/fft.h (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/fft.h Thu Feb 19 06:37:59 2009 @@ -0,0 +1,15 @@ +#include +#include +#include +#include +#include "mtxutl.h" + +#define PI 3.14159265358979323846 +#define END_OF_VEC -1 + +#define NKOUHO 20 +#define NKOUHO_LONG 100 + +#define MAX(X,Y) ( ((X)>(Y))?(X):(Y) ) +#define MIN(X,Y) ( ((X)<(Y))?(X):(Y) ) + Added: test-suite/trunk/MultiSource/Benchmarks/mafft/fftFunctions.c URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/fftFunctions.c?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/fftFunctions.c (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/fftFunctions.c Thu Feb 19 06:37:59 2009 @@ -0,0 +1,839 @@ +#include "mltaln.h" + +#define SEGMENTSIZE 150 +#define TMPTMPTMP 0 + +#define DEBUG 0 + +void keika( char *str, int current, int all ) +{ + if( current == 0 ) + fprintf( stderr, "%s : ", str ); + + fprintf( stderr, "\b\b\b\b\b\b\b\b" ); + fprintf( stderr, "%3d /%3d", current+1, all+1 ); + + if( current+1 == all ) + fprintf( stderr, "\b\b\b\b\b\b\b\bdone. \n" ); +} + +double maxItch( double *soukan, int size ) +{ + int i; + double value = 0.0; + double cand; + for( i=0; i value ) value = cand; + return( value ); +} + +void calcNaiseki( Fukusosuu *value, Fukusosuu *x, Fukusosuu *y ) +{ + value->R = x->R * y->R + x->I * y->I; + value->I = -x->R * y->I + x->I * y->R; +} + +Fukusosuu *AllocateFukusosuuVec( int l1 ) +{ + Fukusosuu *value; + value = (Fukusosuu *)calloc( l1, sizeof( Fukusosuu ) ); + if( !value ) + { + fprintf( stderr, "Cannot allocate %d FukusosuuVec\n", l1 ); + return( NULL ); + } + return( value ); +} + +Fukusosuu **AllocateFukusosuuMtx( int l1, int l2 ) +{ + Fukusosuu **value; + int j; +// fprintf( stderr, "allocating %d x %d FukusosuuMtx\n", l1, l2 ); + value = (Fukusosuu **)calloc( l1+1, sizeof( Fukusosuu * ) ); + if( !value ) + { + fprintf( stderr, "Cannot allocate %d x %d FukusosuuVecMtx\n", l1, l2 ); + exit( 1 ); + } + for( j=0; j max ) + { + ikouho = i; + max = tmp; + } + } +#if 0 + if( max < 0.15 ) + { + break; + } +#endif +#if 0 + fprintf( stderr, "Kouho No.%d, pos=%d, score=%f, lag=%d\n", j, ikouho, soukan[ikouho], ikouho-nlen4 ); +#endif + soukan[ikouho] = -9999.9; + kouho[j] = ( ikouho - nlen4 ); + } + return( j ); +} + +void zurasu2( int lag, int clus1, int clus2, + char **seq1, char **seq2, + char **aseq1, char **aseq2 ) +{ + int i; +#if 0 + fprintf( stderr, "### lag = %d\n", lag ); +#endif + if( lag > 0 ) + { + for( i=0; i 0 ) + { + for( i=0; i=0; j-- ) + { + if( prf1[j] ) + { + hat1[pre1] = j; + pre1 = j; + } + if( prf2[j] ) + { + hat2[pre2] = j; + pre2 = j; + } + } + hat1[pre1] = -1; + hat2[pre2] = -1; + + /* make site score */ + stra[i] = 0.0; + for( k=hat1[26]; k!=-1; k=hat1[k] ) + for( j=hat2[26]; j!=-1; j=hat2[j] ) +// stra[i] += n_dis[k][j] * prf1[k] * prf2[j]; + stra[i] += n_disFFT[k][j] * prf1[k] * prf2[j]; + stra[i] /= totaleff; + } + + (seg+0)->skipForeward = 0; + (seg+1)->skipBackward = 0; + status = 0; + cumscore = 0.0; + score = 0.0; + for( j=0; j threshold ) + { +#if 0 + seg->start = i; + seg->end = i; + seg->center = ( seg->start + seg->end + fftWinSize ) / 2 ; + seg->score = score; + status = 0; + value++; +#else + if( !status ) + { + status = 1; + starttmp = i; + length = 0; + cumscore = 0.0; + } + length++; + cumscore += score; +#endif + } + if( score <= threshold || length > SEGMENTSIZE ) + { + if( status ) + { + if( length > fftWinSize ) + { + seg->start = starttmp; + seg->end = i; + seg->center = ( seg->start + seg->end + fftWinSize ) / 2 ; + seg->score = cumscore; +#if 0 + fprintf( stderr, "%d-%d length = %d, score = %f, value = %d\n", seg->start, seg->end, length, cumscore, value ); +#endif + if( length > SEGMENTSIZE ) + { + (seg+0)->skipForeward = 1; + (seg+1)->skipBackward = 1; + } + else + { + (seg+0)->skipForeward = 0; + (seg+1)->skipBackward = 0; + } + value++; + seg++; + } + length = 0; + cumscore = 0.0; + status = 0; + starttmp = i; + if( value > MAXSEG - 3 ) ErrorExit( "TOO MANY SEGMENTS!"); + } + } + } + if( status && length > fftWinSize ) + { + seg->end = i; + seg->start = starttmp; + seg->center = ( starttmp + i + fftWinSize ) / 2 ; + seg->score = cumscore; +#if 0 +fprintf( stderr, "%d-%d length = %d\n", seg->start, seg->end, length ); +#endif + value++; + } +#if TMPTMPTMP + exit( 0 ); +#endif +// fprintf( stderr, "returning %d\n", value ); + return( value ); +} + +void blockAlign( int *cut1, int *cut2, double **ocrossscore, int *ncut ) +{ + int i, j, shift, cur1, cur2, count; + static int result1[MAXSEG], result2[MAXSEG]; + static int ocut1[MAXSEG], ocut2[MAXSEG]; + double maximum; + static double max[MAXSEG], maxi; + static double point[MAXSEG], pointi; + static double **crossscore = NULL; + static int **track = NULL; + + if( crossscore == NULL ) + { + crossscore = AllocateDoubleMtx( MAXSEG, MAXSEG ); + track = AllocateIntMtx( MAXSEG, MAXSEG ); + } + +#if 0 + for( i=0; i<*ncut; i++ ) + fprintf( stderr, "i=%d, cut1 = %d, cut2 = %d\n", i, cut1[i], cut2[i] ); + for( i=0; i<*ncut; i++ ) + { + for( j=0; j<*ncut; j++ ) + fprintf( stderr, "%#4.0f ", ocrossscore[i][j]/100 ); + fprintf( stderr, "\n" ); + } +#endif + + for( i=0; i<*ncut; i++ ) for( j=0; j<*ncut; j++ ) /* mudadanaa */ + crossscore[i][j] = ocrossscore[i][j]; + for( i=0; i<*ncut; i++ ) + { + ocut1[i] = cut1[i]; + ocut2[i] = cut2[i]; + } + + for( j=0; j<*ncut; j++ ) + { + max[j] = 0.0; + point[j] = 0; + } + + for( i=1; i<*ncut; i++ ) + { + maxi = 0.0; + pointi = 0; + for( j=1; j<*ncut; j++ ) + { + maximum = crossscore[i-1][j-1]; + track[i][j] = 0; + + if( maximum < max[j] + penalty ) + { + maximum = max[j] + penalty; + track[i][j] = point[j] - i; + } + if( maximum < maxi + penalty ) + { + maximum = maxi + penalty; + track[i][j] = j - pointi; + } + crossscore[i][j] += maximum; + + if( maxi < crossscore[i-1][j-1] ) + { + maxi = crossscore[i-1][j-1]; + pointi = j-1; + } + if( max[j] < crossscore[i-1][j-1] ) + { + max[j] = crossscore[i-1][j-1]; + point[j] = i-1; + } + } + } +#if 1 + for( i=0; i<*ncut; i++ ) + { + for( j=0; j<*ncut; j++ ) + fprintf( stderr, "%3d ", track[i][j] ); + fprintf( stderr, "\n" ); + } +#endif + + + result1[MAXSEG-1] = *ncut-1; + result2[MAXSEG-1] = *ncut-1; + + for( i=MAXSEG-1; i>=1; i-- ) + { + cur1 = result1[i]; + cur2 = result2[i]; + if( cur1 == 0 || cur2 == 0 ) break; + shift = track[cur1][cur2]; + if( shift == 0 ) + { + result1[i-1] = cur1 - 1; + result2[i-1] = cur2 - 1; + continue; + } + else if( shift > 0 ) + { + result1[i-1] = cur1 - 1; + result2[i-1] = cur2 - shift; + } + else if( shift < 0 ) + { + result1[i-1] = cur1 + shift; + result2[i-1] = cur2 - 1; + } + } + + count = 0; + for( j=i; j ocrossscore[result1[j-1]][result2[j-1]] ) + count--; + + cut1[count] = ocut1[result1[j]]; + cut2[count] = ocut2[result2[j]]; + count++; + } + + *ncut = count; +#if 0 + for( i=0; i<*ncut; i++ ) + fprintf( stderr, "i=%d, cut1 = %d, cut2 = %d\n", i, cut1[i], cut2[i] ); +#endif +} + +static int permit( Segment *seg1, Segment *seg2 ) +{ + return( 0 ); + if( seg1->end >= seg2->start ) return( 0 ); + if( seg1->pair->end >= seg2->pair->start ) return( 0 ); + else return( 1 ); +} + +void blockAlign2( int *cut1, int *cut2, Segment **seg1, Segment **seg2, double **ocrossscore, int *ncut ) +{ + int i, j, k, shift, cur1, cur2, count, klim; + static int crossscoresize = 0; + static int result1[MAXSEG], result2[MAXSEG]; + static int ocut1[MAXSEG], ocut2[MAXSEG]; + double maximum; + static double **crossscore = NULL; + static int **track = NULL; + static double maxj, maxi; + static int pointj, pointi; + + + if( crossscoresize < *ncut+2 ) + { + crossscoresize = *ncut+2; + if( fftkeika ) fprintf( stderr, "allocating crossscore and track, size = %d\n", crossscoresize ); + if( track ) FreeIntMtx( track ); + if( crossscore ) FreeDoubleMtx( crossscore ); + track = AllocateIntMtx( crossscoresize, crossscoresize ); + crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize ); + } + +#if 0 + for( i=0; i<*ncut-2; i++ ) + fprintf( stderr, "%d.start = %d, score = %f\n", i, seg1[i]->start, seg1[i]->score ); + + for( i=0; i<*ncut; i++ ) + fprintf( stderr, "i=%d, cut1 = %d, cut2 = %d\n", i, cut1[i], cut2[i] ); + for( i=0; i<*ncut; i++ ) + { + for( j=0; j<*ncut; j++ ) + fprintf( stderr, "%#4.0f ", ocrossscore[i][j] ); + fprintf( stderr, "\n" ); + } +#endif + + for( i=0; i<*ncut; i++ ) for( j=0; j<*ncut; j++ ) /* mudadanaa */ + crossscore[i][j] = ocrossscore[i][j]; + for( i=0; i<*ncut; i++ ) + { + ocut1[i] = cut1[i]; + ocut2[i] = cut2[i]; + } + + for( i=1; i<*ncut; i++ ) + { +#if 0 + fprintf( stderr, "### i=%d/%d\n", i,*ncut ); +#endif + for( j=1; j<*ncut; j++ ) + { + pointi = 0; maxi = 0.0; + klim = j-2; + for( k=0; k maxj ) + { + pointi = k; + maxi = crossscore[i-1][k]; + } + } + + pointj = 0; maxj = 0.0; + klim = i-2; + for( k=0; k maxj ) + { + pointj = k; + maxj = crossscore[k][j-1]; + } + } + + maxi += penalty; + maxj += penalty; + + maximum = crossscore[i-1][j-1]; + track[i][j] = 0; + + if( maximum < maxi ) + { + maximum = maxi ; + track[i][j] = j - pointi; + } + + if( maximum < maxj ) + { + maximum = maxj ; + track[i][j] = pointj - i; + } + + crossscore[i][j] += maximum; + } + } +#if 0 + for( i=0; i<*ncut; i++ ) + { + for( j=0; j<*ncut; j++ ) + fprintf( stderr, "%3d ", track[i][j] ); + fprintf( stderr, "\n" ); + } +#endif + + + result1[MAXSEG-1] = *ncut-1; + result2[MAXSEG-1] = *ncut-1; + + for( i=MAXSEG-1; i>=1; i-- ) + { + cur1 = result1[i]; + cur2 = result2[i]; + if( cur1 == 0 || cur2 == 0 ) break; + shift = track[cur1][cur2]; + if( shift == 0 ) + { + result1[i-1] = cur1 - 1; + result2[i-1] = cur2 - 1; + continue; + } + else if( shift > 0 ) + { + result1[i-1] = cur1 - 1; + result2[i-1] = cur2 - shift; + } + else if( shift < 0 ) + { + result1[i-1] = cur1 + shift; + result2[i-1] = cur2 - 1; + } + } + + count = 0; + for( j=i; j ocrossscore[result1[j-1]][result2[j-1]] ) + count--; + + cut1[count] = ocut1[result1[j]]; + cut2[count] = ocut2[result2[j]]; + + count++; + } + + *ncut = count; +#if 0 + for( i=0; i<*ncut; i++ ) + fprintf( stderr, "i=%d, cut1 = %d, cut2 = %d\n", i, cut1[i], cut2[i] ); +#endif +} +void blockAlign3( int *cut1, int *cut2, Segment **seg1, Segment **seg2, double **ocrossscore, int *ncut ) +// memory complexity = O(n^3), time complexity = O(n^2) +{ + int i, j, shift, cur1, cur2, count; + static int crossscoresize = 0; + static int jumpposi, *jumppos; + static double jumpscorei, *jumpscore; + static int result1[MAXSEG], result2[MAXSEG]; + static int ocut1[MAXSEG], ocut2[MAXSEG]; + double maximum; + static double **crossscore = NULL; + static int **track = NULL; + + if( crossscoresize < *ncut+2 ) + { + crossscoresize = *ncut+2; + if( fftkeika ) fprintf( stderr, "allocating crossscore and track, size = %d\n", crossscoresize ); + if( track ) FreeIntMtx( track ); + if( crossscore ) FreeDoubleMtx( crossscore ); + if( jumppos ) FreeIntVec( jumppos ); + if( jumpscore ) FreeDoubleVec( jumpscore ); + track = AllocateIntMtx( crossscoresize, crossscoresize ); + crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize ); + jumppos = AllocateIntVec( crossscoresize ); + jumpscore = AllocateDoubleVec( crossscoresize ); + } + +#if 0 + for( i=0; i<*ncut-2; i++ ) + fprintf( stderr, "%d.start = %d, score = %f\n", i, seg1[i]->start, seg1[i]->score ); + + for( i=0; i<*ncut; i++ ) + fprintf( stderr, "i=%d, cut1 = %d, cut2 = %d\n", i, cut1[i], cut2[i] ); + for( i=0; i<*ncut; i++ ) + { + for( j=0; j<*ncut; j++ ) + fprintf( stderr, "%#4.0f ", ocrossscore[i][j] ); + fprintf( stderr, "\n" ); + } +#endif + + for( i=0; i<*ncut; i++ ) for( j=0; j<*ncut; j++ ) /* mudadanaa */ + crossscore[i][j] = ocrossscore[i][j]; + for( i=0; i<*ncut; i++ ) + { + ocut1[i] = cut1[i]; + ocut2[i] = cut2[i]; + } + for( j=0; j<*ncut; j++ ) + { + jumpscore[j] = -999.999; + jumppos[j] = -1; + } + + for( i=1; i<*ncut; i++ ) + { + + jumpscorei = -999.999; + jumpposi = -1; + + for( j=1; j<*ncut; j++ ) + { +#if 1 + fprintf( stderr, "in blockalign3, ### i=%d, j=%d\n", i, j ); +#endif + + +#if 0 + for( k=0; k maxj ) + { + pointi = k; + maxi = crossscore[i-1][k]; + } + } + + pointj = 0; maxj = 0.0; + for( k=0; k maxj ) + { + pointj = k; + maxj = crossscore[k][j-1]; + } + } + + + maxi += penalty; + maxj += penalty; +#endif + maximum = crossscore[i-1][j-1]; + track[i][j] = 0; + + if( maximum < jumpscorei && permit( seg1[jumpposi], seg1[i] ) ) + { + maximum = jumpscorei; + track[i][j] = j - jumpposi; + } + + if( maximum < jumpscore[j] && permit( seg2[jumppos[j]], seg2[j] ) ) + { + maximum = jumpscore[j]; + track[i][j] = jumpscore[j] - i; + } + + crossscore[i][j] += maximum; + + if( jumpscorei < crossscore[i-1][j] ) + { + jumpscorei = crossscore[i-1][j]; + jumpposi = j; + } + + if( jumpscore[j] < crossscore[i][j-1] ) + { + jumpscore[j] = crossscore[i][j-1]; + jumppos[j] = i; + } + } + } +#if 0 + for( i=0; i<*ncut; i++ ) + { + for( j=0; j<*ncut; j++ ) + fprintf( stderr, "%3d ", track[i][j] ); + fprintf( stderr, "\n" ); + } +#endif + + + result1[MAXSEG-1] = *ncut-1; + result2[MAXSEG-1] = *ncut-1; + + for( i=MAXSEG-1; i>=1; i-- ) + { + cur1 = result1[i]; + cur2 = result2[i]; + if( cur1 == 0 || cur2 == 0 ) break; + shift = track[cur1][cur2]; + if( shift == 0 ) + { + result1[i-1] = cur1 - 1; + result2[i-1] = cur2 - 1; + continue; + } + else if( shift > 0 ) + { + result1[i-1] = cur1 - 1; + result2[i-1] = cur2 - shift; + } + else if( shift < 0 ) + { + result1[i-1] = cur1 + shift; + result2[i-1] = cur2 - 1; + } + } + + count = 0; + for( j=i; j ocrossscore[result1[j-1]][result2[j-1]] ) + count--; + + cut1[count] = ocut1[result1[j]]; + cut2[count] = ocut2[result2[j]]; + + count++; + } + + *ncut = count; +#if 0 + for( i=0; i<*ncut; i++ ) + fprintf( stderr, "i=%d, cut1 = %d, cut2 = %d\n", i, cut1[i], cut2[i] ); +#endif +} + Added: test-suite/trunk/MultiSource/Benchmarks/mafft/functions.h URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/functions.h?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/functions.h (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/functions.h Thu Feb 19 06:37:59 2009 @@ -0,0 +1,293 @@ +extern int intlen( int *num ); +extern char seqcheck( char **seq ); +extern void scmx_calc( int icyc, char **aseq, double *effarr, float **scmx ); +extern void exitall( char arr[] ); +extern void display( char **seq, int nseq ); +extern void intergroup_score( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len, double *value ); +extern void intergroup_score_gapnomi( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len, double *value ); +extern void intergroup_score_new( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len, double *value ); +extern double score_calc3( char **seq, int s, double **eff, int ex ); +extern double score_calc5( char **seq, int s, double **eff, int ex ); +extern double score_calc4( char **seq, int s, double **eff, int ex ); +extern void upg2( int nseq, double **eff, int ***topol, double **len ); +//extern void veryfastsupg_float_realloc_nobk_halfmtx( int njob, float **mtx, int ***topol, float **len ); +//extern void veryfastsupg_float_realloc_nobk( int njob, float **mtx, int ***topol, float **len ); +extern void veryfastsupg_int_realloc_nobk( int njob, int **mtx, int ***topol, double **len ); +extern void veryfastsupg( int nseq, double **oeff, int ***topol, double **len ); +extern void veryfastsupg_double( int nseq, double **oeff, int ***topol, double **len ); +extern void veryfastsupg_double_loadtree( int nseq, double **oeff, int ***topol, double **len ); +extern void veryfastsupg_double_loadtop( int nseq, double **oeff, int ***topol, double **len ); +extern void veryfastsupg_int( int nseq, int **oeff, int ***topol, double **len ); +extern void fastsupg( int nseq, double **oeff, int ***topol, double **len ); +extern void supg( int nseq, double **oeff, int ***topol, double **len ); +extern void spg( int nseq, double **oeff, int ***topol, double **len ); +extern double ipower( double x, int n ); +extern void countnode( int nseq, int ***topol, double **node ); +extern void countnode_int( int nseq, int ***topol, int **node ); +extern void counteff_simple( int nseq, int ***topol, double **len, double *node ); +extern void counteff_simple_float( int nseq, int ***topol, float **len, double *node ); +extern void counteff( int nseq, int ***topol, double **len, double **node ); +extern float score_calc1( char *seq1, char *seq2 ); +extern float score_calcp( char *seq1, char *seq2, int len ); +extern float substitution_nid( char *seq1, char *seq2 ); +extern float substitution_score( char *seq1, char *seq2 ); +extern float substitution_hosei( char *seq1, char *seq2 ); +extern float substitution( char *seq1, char *seq2 ); +extern void treeconstruction( char **seq, int nseq, int ***topol, double **len, double **eff ); +extern float bscore_calc( char **seq, int s, double **eff ); +extern void AllocateTmpSeqs( char ***mseq2pt, char **mseq1pt, int locnlenmax ); +extern void FreeTmpSeqs( char **mseq2, char *mseq1 ); +extern void gappick0( char *aseq, char *seq ); +extern void gappick( int nseq, int s, char **aseq, char **mseq2, + double **eff, double *effarr ); +extern void commongappick_record( int nseq, char **seq, int *map ); +extern void commongappick( int nseq, char **seq ); +extern double score_calc0( char **seq, int s, double **eff, int ex ); +extern void strins( char *str1, char *str2 ); +extern int isaligned( int nseq, char **seq ); +extern double score_calc_for_score( int nseq, char **seq ); +extern void floatncpy( float *vec1, float *vec2, int len ); +extern float score_calc_a( char **seq, int s, double **eff ); +extern float score_calc_s( char **seq, int s, double **eff ); +extern double score_calc_for_score_s( int s, char **seq ); +extern double SSPscore( int s, char **seq ); +extern double DSPscore( int s, char **seq ); +extern int searchAnchors( int nseq, char **seq, Segment *seg ); +extern char *progName( char *str ); +extern void dontcalcimportance( int nseq, double *eff, char **seq, LocalHom **localhom ); +extern void calcimportance( int nseq, double *eff, char **seq, LocalHom **localhom ); +extern void weightimportance2( int nseq, double *eff, LocalHom **localhom ); +extern void weightimportance4( int clus1, int clus2, double *eff1, double *eff2, LocalHom ***localhom ); +extern void extendlocalhom( int nseq, LocalHom **localhom ); +extern void extendlocalhom2( int nseq, LocalHom **localhom, double **mtx ); +extern int makelocal( char *s1, char *s2, int thr ); +extern void mdfymtx( char **pair, int s1, double **partialmtx, double **mtx ); +extern float score_calc( char **seq, int s ); +extern void cpmx_calc( char **seq, float **cpmx, double *eff, int lgth, int clus ); +extern void cpmx_calc_new( char **seq, float **cpmx, double *eff, int lgth, int clus ); +extern void MScpmx_calc_new( char **seq, float **cpmx, double *eff, int lgth, int clus ); +extern void mseqcat( char **seq1, char **seq2, double **eff, double *effarr1, double *effarr2, char name1[M][B], char name2[M][B], int clus1, int clus2 ); +extern void strnbcat( char *s1, char *s2, int m ); +extern int conjuctionforgaln( int s0, int s1, char **seq, char **aseq, double *peff, double *eff, char **name, char **aname, char *d ); +extern int fastconjuction( int *memlist, char **seq, char **aseq, double *peff, double *eff, char name[M][B], char aname[M][B], char *d ); +extern int fastconjuction_noname( int *memlist, char **seq, char **aseq, double *peff, double *eff, char *d ); +extern int fastconjuction_noweight( int *memlist, char **seq, char **aseq, double *peff, char *d ); +extern int conjuctionfortbfast( char **pair, int s, char **seq, char **aseq, double *peff, double *eff, char *d ); +extern int conjuction( char **pair, int s, char **seq, char **aseq, double *peff, double *eff, char name[M][B], char aname[M][B], char *d ); +extern void floatdelete( float **cpmx, int d, int len ); +extern void chardelete( char *seq, int d ); +extern int RootBranchNode( int nseq, int ***topol, int step, int branch ); +extern void BranchLeafNode( int nseq, int ***topol, int *node, int step, int branch ); +extern void RootLeafNode( int nseq, int ***topol, int *node ); +extern void nodeFromABranch( int nseq, int *result, int **pairwisenode, int ***topol, double **len, int step, int num ); +extern void OneClusterAndTheOther( int locnjob, char **pair, int *s1, int *s2, int ***topol, int step, int branch ); +extern void makeEffMtx( int nseq, double **mtx, double *vec ); +extern void node_eff( int nseq, double *eff, int *node ); +extern int shrinklocalhom( char **pair, int s1, int s2, LocalHom **localhom, LocalHom ***localhomshrink ); +extern int msshrinklocalhom( char **pair, int s1, int s2, LocalHom **localhom, LocalHom ***localhomshrink ); +extern int fastshrinklocalhom( int *mem1, int *mem2, LocalHom **localhom, LocalHom ***localhomshrink ); +extern int msfastshrinklocalhom( int *mem1, int *mem2, LocalHom **localhom, LocalHom ***localhomshrink ); +extern int TreeDependentIteration( int locnjob, char name[M][B], int nlen[M], char **aseq, char **bseq, int ***topol, double **len, int alloclen, LocalHom **localhomtable, RNApair ***single ); +extern void checkMinusLength( int nseq, double **len ); +extern void negativeMember2( int *mem, int *query, int locnseq ); +extern int *negativeMember( int *query, int locnseq ); +extern int IntExistsInVec( int query, int *vector ); +extern NodeInCub searchParent( int top, int ***topol, int Start, int End ); +extern void stopolInit( int n, Node *stopol ); +extern void treeCnv( Node *stopol, int locnseq, int ***topol, double **len, double **bw ); +extern int isLeaf( Node node ); +extern double syntheticLength( Node *ob, Node *oppositeNode ); +extern double calcW( Node *ob, Node *op ); +extern void calcBranchWeight( double **bw, int locnseq, Node *stopol, int ***topol, double **len ); +extern void branchWeightToPairWeight( int locnseq, int ***topol, double **pw, double **bw ); +extern void weightFromABranch_rec( double *result, Node *ob, Node *op ); +extern void weightFromABranch( int nseq, double *result, Node *stopol, int ***topol, int step, int LorR ); +extern void keika( char *str, int current, int all ); +extern double maxItch( double *soukan, int size ); +extern void calcNaiseki( Fukusosuu *value, Fukusosuu *x, Fukusosuu *y ); +extern Fukusosuu *AllocateFukusosuuVec( int l1 ); +extern Fukusosuu **AllocateFukusosuuMtx( int l1, int l2 ); +extern Fukusosuu ***AllocateFukusosuuCub( int l1, int l2, int l3 ); +extern void FreeFukusosuuVec( Fukusosuu *vec ); +extern void FreeFukusosuuMtx( Fukusosuu **mtx ); +extern int getKouho( int *kouho, int nkouho, double *soukan, int nlen2 ); +extern void zurasu2( int lag, int clus1, int clus2, char **seq1, char **seq2, char **aseq1, char **aseq2 ); +extern void zurasu( int lag, int clus1, int clus2, char **seq1, char **seq2, char **aseq1, char **aseq2 ); +extern int alignableReagion( int clus1, int clus2, char **seq1, char **seq2, double *eff1, double *eff2, Segment *seg ); +extern void blockAlign( int *cut1, int *cut2, double **ocrossscore, int *ncut ); +extern void blockAlign2( int *cut1, int *cut2, Segment **seg1, Segment **seg2, double **ocrossscore, int *ncut ); +extern void blockAlign3( int *cut1, int *cut2, Segment **seg1, Segment **seg2, double **ocrossscore, int *ncut ); +extern float A__align11( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch ); +extern float imp_match_out_scH( int i1, int j1 ); +extern void imp_match_init_strictH( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore ); +extern float imp_match_out_scQ( int i1, int j1 ); +extern float imp_match_out_scR( int i1, int j1 ); +extern void imp_match_init_strictQ( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore ); +extern void imp_match_init_strictR( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore ); +extern void imp_match_init( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom ); +extern float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *, char *, char *, char * ); +extern float Lalignmm_hmout( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *, char *, char *, char *, float **map ); +extern float Lalign2m2m_hmout( char **seq1, char **seq2, char **seq1r, char **seq2r, char *dir1, char *dir2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *, char *, char *, char *, float **map ); +extern float MSalign11( char **seq1, char **seq2, int alloclen ); +//extern float rnalocal( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, RNApair **pair ); +extern float A__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2 ); +extern float H__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2 ); +extern float Q__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2 ); +extern float Q__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2, int *gapmap1, int *gapmap2 ); +extern float R__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2 ); +extern float R__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2 ); +extern float A__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int *gapmap1, int *gapmap2 ); +extern float D__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int *gapmap1, int *gapmap2 ); +extern float translate_and_Calign( char **mseq1, char **mseq2, double *effarr1, double *effarr2, int clus1, int clus2, int alloclen ); +extern double Fgetlag( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int alloclen ); +extern float Falign( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int alloclen, int *fftlog ); +extern float Falign_udpari_long( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int alloclen, int *fftlog ); +extern float part_imp_match_out_sc( int i1, int j1 ); +extern float part_imp_match_out_scQ( int i1, int j1 ); +extern void part_imp_match_init_strict( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore ); +extern void part_imp_match_init_strictQ( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore ); +extern void part_imp_match_init( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom ); +extern float partA__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int start1, int end1, int start2, int end2, int *gapmap1, int *gapmap2, char *, char *, char *, char * ); +extern float partQ__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int start1, int end1, int start2, int end2, int *gapmap1, int *gapmap2, char *, char *, char *, char *); +//extern float MSalign11( char **seq1, char **seq2, int alloclen ); +extern float G__align11( char **seq1, char **seq2, int alloclen ); +extern float G__align11_noalign( int mtx[0x80][0x80], int penal, int penal_ex, char **seq1, char **seq2, int alloclen ); +extern float L__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt ); +extern float genL__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt ); +extern float genG__align11( char **seq1, char **seq2, int alloclen ); +extern float VAalign11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt, LocalHom *lhmpt ); +extern float suboptalign11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt, LocalHom *lhmpt ) +; +extern int fft(int n, Fukusosuu *x, int dum); +extern void topolcpy( int s1[], int s2[], int *mpt1, int *mpt2 ); +extern void topolcat( int s1[], int s2[], int *mpt1, int *mpt2 ); +extern void topolsort( int m, int s[] ); +extern void topolswap( int s1[], int s2[], int *mpt1, int *mpt2 ); +extern void reduc( double **mtx, int nseq, int im, int jm ); +extern void nj( int nseq, double **omtx, int ***topol, double **dis ); +extern void JTTmtx( double **rsr, double *freq, char locamino[26], char locgrp[26], int isTM ); +extern void BLOSUMmtx( int n, double **matrix, double *freq, char *amino, char *amino_grp ); +extern void putlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ); +extern void putlocalhom_ext( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ); +extern void putlocalhom3( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ); +extern void putlocalhom( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ); +extern char *cutal( char *al, int al_display_start, int start, int end ); +extern void ErrorExit( char *message ); +extern void strncpy_caseC( char *str1, char *str2, int len ); +extern void seqUpper( int nseq, char **seq ); +extern void seqLower( int nseq, char **seq ); +extern int getaline_fp_eof( char *s, int l, FILE *fp ); +extern int getaline_fp_eof_new(char s[], int l, FILE *fp); +extern int myfgets(char s[], int l, FILE *fp); +extern float input_new( FILE *fp, int d ); +extern void PreRead( FILE *fp, int *locnjob, int *locnlenmax ); +extern int allSpace( char *str ); +extern void Read( char name[M][B], int nlen[M], char **seq ); +extern void FRead( FILE *fp, char name[][B], int nlen[], char **seq ); +extern void kake2hiku( char *str ); +extern void readDataforgaln( FILE *fp, char **name, int *nlen, char **seq ); +extern void readData( FILE *fp, char name[][B], int nlen[], char **seq ); +extern void readData_pointer( FILE *fp, char **name, int *nlen, char **seq ); +extern void readData_varlen( FILE *fp, char **name, int *nlen, char **seq ); +extern int countATGC( char *s, int *total ); +extern void getnumlen( FILE *fp ); +extern void getnumlen_nogap( FILE *fp, int *nlenmin ); +extern void WriteGapFill( FILE *fp, int locnjob, char name[][B], int nlen[M], char **aseq ); +extern void writeDataforgaln( FILE *fp, int locnjob, char **name, int *nlen, char **aseq ); +extern void writeData( FILE *fp, int locnjob, char name[][B], int nlen[], char **aseq ); +extern void writeData_pointer( FILE *fp, int locnjob, char **name, int *nlen, char **aseq ); +extern void readhat2_floathalf( FILE *fp, int nseq, char name[M][B], float **mtx ); +extern void readhat2_floathalf_pointer( FILE *fp, int nseq, char **name, float **mtx ); +extern void readhat2_float( FILE *fp, int nseq, char name[M][B], float **mtx ); +extern void readhat2_int( FILE *fp, int nseq, char name[M][B], int **mtx ); +extern void readhat2( FILE *fp, int nseq, char name[M][B], double **mtx ); +extern void WriteFloatHat2( FILE *hat2p, int locnjob, char name[M][B], float **mtx ); +extern void WriteHat2_int( FILE *hat2p, int locnjob, char name[M][B], int **mtx ); +extern void WriteHat2( FILE *hat2p, int locnjob, char name[M][B], double **mtx ); +extern void WriteHat2plain( FILE *hat2p, int locnjob, double **mtx ); +extern int ReadFasta_sub( FILE *fp, double *dis, int nseq, char name[M][B] ); +extern int ReadSsearch( FILE *fp, double *dis, int nseq, char name[M][B] ); +extern int ReadBlastm7( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist ); +extern int ReadBlastm7_scoreonly( FILE *fp, double *dis, int nin ); +extern int ReadBlastm7_avscore( FILE *fp, double *dis, int nin ); +extern int ReadFasta34noalign( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist ); +extern int ReadFasta34m10_nuc( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist ); +extern int ReadFasta34m10( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist ); +extern int ReadFasta34m10_scoreonly_nuc( FILE *fp, double *dis, int nin ); +extern int ReadFasta34m10_scoreonly( FILE *fp, double *dis, int nin ); +extern int ReadFasta34( FILE *fp, double *dis, int nseq, char name[M][B], LocalHom *localhomlist ); +extern int ReadFasta3( FILE *fp, double *dis, int nseq, char name[M][B] ); +extern int ReadFasta( FILE *fp, double *dis, int nseq, char name[M][B] ); +extern int ReadOpt( FILE *fp, int opt[M], int nseq, char name[M][B] ); +extern int ReadOpt2( FILE *fp, int opt[M], int nseq, char name[M][B] ); +extern int writePre( int nseq, char name[][B], int nlen[M], char **aseq, int force ); +extern void readOtherOptions( int *ppidptr, int *fftThresholdptr, int *fftWinSizeptr ); +extern void initSignalSM( void ); +extern void initFiles( void ); +extern void WriteForFasta( FILE *fp, int locnjob, char name[][B], int nlen[M], char **aseq ); +extern void readlocalhomtable( FILE*fp, int njob, LocalHom **localhomtable ); +extern void readlocalhomtable2( FILE*fp, int njob, LocalHom **localhomtable ); +extern void outlocalhom( LocalHom **localhom, int nseq ); +extern void outlocalhompt( LocalHom ***localhom, int n1, int n2 ); +extern void FreeLocalHomTable( LocalHom **localhomtable, int n ) ; +extern void constants( int nseq, char **seq ); +extern void clustalout_pointer( FILE *fp, int nseq, int maxlen, char **seq, char **name, char *mark, char *comment, int *order ); +extern void writeData_reorder( FILE *fp, int locnjob, char name[][B], int nlen[], char **aseq, int *order ); +extern void writeData_reorder_pointer( FILE *fp, int locnjob, char **name, int *nlen, char **aseq, int *order ); + +extern void resetlocalhom( int, LocalHom ** ); +extern int load1SeqWithoutName_new( FILE *fpp, char *cbuf ); +extern char *load1SeqWithoutName_realloc( FILE *fpp ); +extern int disttbfast( char **in, int nlen[M], char name[M][B] ); +extern void searchKUorWA( FILE *fp ); +extern void gapireru( char *res, char *ori, char *gt ); +extern int seqlen( char *seq ); +extern void st_FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len ); +extern void st_OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len ); +extern void st_OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len ); +extern void st_FinalGapCount_zure( float *fgcp, int clus, char **seq, double *eff, int len ); +extern void getdiaminofreq_x( float *freq, int clus, char **seq, double *eff, int len ); +extern void new_FinalGapCount_zure( float *fgcp, int clus, char **seq, double *eff, int len, char *s, char *e ); +extern void new_FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len, char *g ); +extern void new_OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len, char *g ); +extern void new_OpeningGapCount_zure( float *ogcp, int clus, char **seq, double *eff, int len, char *s, char *e ); +extern void getGapPattern( float *fgcp, int clus, char **seq, double *eff, int len, char *g ); +extern void getgapfreq( float *freq, int clus, char **seq, double *eff, int len ); +extern void getgapfreq_zure( float *freq, int clus, char **seq, double *eff, int len ); +//extern void getgapfreq_zure_part( float *freq, int clus, char **seq, double *eff, int len, char *s ); +extern void getgapfreq_zure_part( float *freq, int clus, char **seq, double *eff, int len, char *s ); +extern void getdiaminofreq_part( float *freq, int clus, char **seq, double *eff, int len, char *s, char *e ); +extern void getdigapfreq_part( float *freq, int clus, char **seq, double *eff, int len, char *s, char *e ); +extern void getdiaminofreq_st( float *freq, int clus, char **seq, double *eff, int len ); +extern void getdigapfreq_st( float *freq, int clus, char **seq, double *eff, int len ); +extern void st_getGapPattern( Gappat **gpat, int clus, char **seq, double *eff, int len ); +extern void getkyokaigap( char *g, char **s, int pos, int n ); +extern double *loadaamtx( void ); +extern float naivepairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal ); +extern int naivepairscore11( char *seq1, char *seq2, int penal ); +extern float naiveQpairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal ); +extern float naiveRpairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal ); +extern float naiveHpairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal ); +extern void foldrna( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, float **impmtx, int *gapmap1, int *gapmap2, RNApair *pair ); +extern void foldrna_gappick( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, float **impmtx, int *gapmap1, int *gapmap2, RNApair *pair ); +extern void imp_rna( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair ); +extern void imp_rnaQ( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair ); +extern void part_imp_rnaQ( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair ); +extern void part_imp_rna( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair ); +extern void imp_rnaQ_gappick( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair ); +extern void foldalignedrna( int clus1, int clus2, char **mseq1, char **mseq2, double *effarr1, double *effarr2, RNApair *rnapairboth ); +void readmccaskill( FILE *fp, RNApair **pairprob, int length ); +void makegrouprna( RNApair ***group, RNApair ***all, int *memlist ); +void makegrouprnait( RNApair ***group, RNApair ***all, char **pair, int s ); +extern void fixed_musclesupg_float_realloc_nobk_halfmtx( int nseq, float **eff, int ***topol, float **len ); +extern void loadtree( int nseq, int ***topol, float **len, char **name, int *nlen ); +extern void loadtop( int nseq, float **eff, int ***topol, float **len ); +extern void fixed_musclesupg_float_realloc_nobk_halfmtx_treeout( int nseq, float **eff, int ***topol, float **len, char **name, int *nlen ); +extern void imp_match_init_strict( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore ); +extern void miyataout_reorder_pointer( FILE *fp, int locnjob, int nlenmax, char **name, int *nlen, char **aseq, int *order ); +extern void veryfastsupg_double_outtree( int nseq, double **eff, int ***topol, double **len, char name[][B] ); +extern void cpmx_ribosum( char **seq, char **seqr, char *dir, float **cpmx, double *eff, int lgth, int clus ); +extern void rnaalifoldcall( char **seq, int nseq, RNApair **pairprob ); +extern void readpairfoldalign( FILE *fp, char *seq1, char *seq2, char *aln1, char *aln2, int q1, int q2, int *of1, int *of2, int sumlen ); +extern void write1seq( FILE *fp, char *aseq ); + Added: test-suite/trunk/MultiSource/Benchmarks/mafft/genGalign11.c URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/genGalign11.c?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/genGalign11.c (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/genGalign11.c Thu Feb 19 06:37:59 2009 @@ -0,0 +1,484 @@ +#include "mltaln.h" +#include "dp.h" + +#define DEBUG 0 +#define XXXXXXX 0 +#define USE_PENALTY_EX 1 + + +#if 1 +static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) +{ + char *seq2 = s2[0]; + int *intptr = amino_dis[(int)s1[0][i1]]; + + while( lgth2-- ) + *match++ = intptr[(int)*seq2++]; +} +#else +static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) +{ + int j; + + for( j=0; j lgth1, outgap == 1 -> lgth1+1 */ + int lgth1, lgth2; + int resultlen; + float wm; /* int ?????? */ + float g; + float *currentw, *previousw; + float fpenalty = (float)penalty; + float fpenalty_OP = (float)penalty_OP; +#if USE_PENALTY_EX + float fpenalty_ex = (float)penalty_ex; +#endif +#if 1 + float *wtmp; + int *ijpipt; + int *ijpjpt; + float *mjpt, *Mjpt, *prept, *curpt; + int *mpjpt, *Mpjpt; +#endif + static float mi, *m; + static float Mi, *largeM; + static int **ijpi; + static int **ijpj; + static int mpi, *mp; + static int Mpi, *Mp; + static float *w1, *w2; + static float *match; + static float *initverticalw; /* kufuu sureba iranai */ + static float *lastverticalw; /* kufuu sureba iranai */ + static char **mseq1; + static char **mseq2; + static char **mseq; + static float **cpmx1; + static float **cpmx2; + static int **intwork; + static float **floatwork; + static int orlgth1 = 0, orlgth2 = 0; + float tbk; + int tbki, tbkj; + + wm = 0.0; + + if( orlgth1 == 0 ) + { + mseq1 = AllocateCharMtx( njob, 0 ); + mseq2 = AllocateCharMtx( njob, 0 ); + } + + + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); + + + + if( lgth1 <= 0 || lgth2 <= 0 ) + { + fprintf( stderr, "WARNING (g11): lgth1=%d, lgth2=%d\n", lgth1, lgth2 ); + } + + if( lgth1 > orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + FreeFloatVec( largeM ); + FreeIntVec( Mp ); + + FreeCharMtx( mseq ); + + + FreeFloatMtx( cpmx1 ); + FreeFloatMtx( cpmx2 ); + + FreeFloatMtx( floatwork ); + FreeIntMtx( intwork ); + } + + ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100; + +#if DEBUG + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); +#endif + + w1 = AllocateFloatVec( ll2+2 ); + w2 = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + + m = AllocateFloatVec( ll2+2 ); + mp = AllocateIntVec( ll2+2 ); + largeM = AllocateFloatVec( ll2+2 ); + Mp = AllocateIntVec( ll2+2 ); + + mseq = AllocateCharMtx( njob, ll1+ll2 ); + + cpmx1 = AllocateFloatMtx( 26, ll1+2 ); + cpmx2 = AllocateFloatMtx( 26, ll2+2 ); + + floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); + +#if DEBUG + fprintf( stderr, "succeeded\n" ); +#endif + + orlgth1 = ll1 - 100; + orlgth2 = ll2 - 100; + } + + + mseq1[0] = mseq[0]; + mseq2[0] = mseq[1]; + + + if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 ) + { + int ll1, ll2; + + if( commonAlloc1 && commonAlloc2 ) + { + FreeIntMtx( commonIP ); + FreeIntMtx( commonJP ); + } + + ll1 = MAX( orlgth1, commonAlloc1 ); + ll2 = MAX( orlgth2, commonAlloc2 ); + +#if DEBUG + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + + commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + commonJP = AllocateIntMtx( ll1+10, ll2+10 ); + +#if DEBUG + fprintf( stderr, "succeeded\n\n" ); +#endif + + commonAlloc1 = ll1; + commonAlloc2 = ll2; + } + ijpi = commonIP; + ijpj = commonJP; + + +#if 0 + for( i=0; i", wm ); +#endif +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( (g=mi+fpenalty) > wm ) + { + wm = g; +// *ijpipt = i - 1; // iranai + *ijpjpt = mpi; + } + if( (g=*prept) >= mi ) + { + mi = g; + mpi = j-1; + } +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( (g=*mjpt + fpenalty) > wm ) + { + wm = g; + *ijpipt = *mpjpt; + *ijpjpt = j - 1; //IRU! + } + if( (g=*prept) >= *mjpt ) + { + *mjpt = g; + *mpjpt = i-1; + } +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + +#if 1 + g = tbk + fpenalty_OP; + if( g > wm ) + { + wm = g; + *ijpipt = tbki; + *ijpjpt = tbkj; +// fprintf( stderr, "hit! i%d, j%d, ijpi = %d, ijpj = %d\n", i, j, *ijpipt, *ijpjpt ); + } + if( Mi > tbk ) + { + tbk = Mi; //error desu. + tbki = i-1; + tbkj = Mpi; + } + if( *Mjpt > tbk ) + { + tbk = *Mjpt; + tbki = *Mpjpt; + tbkj = j-1; + } + + if( *prept > *Mjpt ) + { + *Mjpt = *prept; + *Mpjpt = i-1; + } + if( *prept > Mi ) + { + Mi = *prept; + Mpi = j-1; + } + +#endif + + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + *curpt++ += wm; + ijpipt++; + ijpjpt++; + mjpt++; + Mjpt++; + prept++; + mpjpt++; + Mpjpt++; + } + lastverticalw[i] = currentw[lgth2-1]; // lgth2==0 no toki error + } +#if 0 + for( i=0; i N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } + + + strcpy( seq1[0], mseq1[0] ); + strcpy( seq2[0], mseq2[0] ); +#if 0 + fprintf( stderr, "\n" ); + fprintf( stderr, ">\n%s\n", mseq1[0] ); + fprintf( stderr, ">\n%s\n", mseq2[0] ); + fprintf( stderr, "wm = %f\n", wm ); +#endif + + return( wm ); +} + Added: test-suite/trunk/MultiSource/Benchmarks/mafft/genalign11.c URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/genalign11.c?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/genalign11.c (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/genalign11.c Thu Feb 19 06:37:59 2009 @@ -0,0 +1,627 @@ +#include "mltaln.h" +#include "dp.h" + +#define DEBUG 0 +#define DEBUG2 0 +#define XXXXXXX 0 +#define USE_PENALTY_EX 1 + +static int localstop; + +#if 1 +static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) +{ + char tmpc = s1[0][i1]; + char *seq2 = s2[0]; + + while( lgth2-- ) + *match++ = amino_dis[(int)tmpc][(int)*seq2++]; +} +#else +static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) +{ + int j; + + for( j=0; j -1 ) + *fpt2 += scarr[*ipt++] * *fpt++; + fpt2++,iptpt++,fptpt++; + } + } +#else + for( j=0; j-1; k++ ) + match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j]; + } +#endif +} +#endif + +static float gentracking( float *lasthorizontalw, float *lastverticalw, + char **seq1, char **seq2, + char **mseq1, char **mseq2, + float **cpmx1, float **cpmx2, + int **ijpi, int **ijpj, int *off1pt, int *off2pt, int endi, int endj ) +{ + int i, j, l, iin, jin, lgth1, lgth2, k, limk; + int ifi=0, jfi=0; // by D.Mathog + char gap[] = "-"; + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); + +#if 0 + for( i=0; i orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + FreeFloatVec( largeM ); + FreeIntVec( Mp ); + + FreeCharMtx( mseq ); + + FreeFloatMtx( cpmx1 ); + FreeFloatMtx( cpmx2 ); + + FreeFloatMtx( floatwork ); + FreeIntMtx( intwork ); + } + + ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100; + +#if DEBUG + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); +#endif + + w1 = AllocateFloatVec( ll2+2 ); + w2 = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + + m = AllocateFloatVec( ll2+2 ); + mp = AllocateIntVec( ll2+2 ); + largeM = AllocateFloatVec( ll2+2 ); + Mp = AllocateIntVec( ll2+2 ); + + mseq = AllocateCharMtx( njob, ll1+ll2 ); + + cpmx1 = AllocateFloatMtx( 26, ll1+2 ); + cpmx2 = AllocateFloatMtx( 26, ll2+2 ); + + floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); + +#if DEBUG + fprintf( stderr, "succeeded\n" ); +#endif + + orlgth1 = ll1 - 100; + orlgth2 = ll2 - 100; + } + + + mseq1[0] = mseq[0]; + mseq2[0] = mseq[1]; + + + if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 ) + { + int ll1, ll2; + + if( commonAlloc1 && commonAlloc2 ) + { + FreeIntMtx( commonIP ); + FreeIntMtx( commonJP ); + } + + ll1 = MAX( orlgth1, commonAlloc1 ); + ll2 = MAX( orlgth2, commonAlloc2 ); + +#if DEBUG + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + + commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + commonJP = AllocateIntMtx( ll1+10, ll2+10 ); + +#if DEBUG + fprintf( stderr, "succeeded\n\n" ); +#endif + + commonAlloc1 = ll1; + commonAlloc2 = ll2; + } + ijpi = commonIP; + ijpj = commonJP; + + +#if 0 + for( i=0; i", wm ); +#endif + g = mi + fpenalty; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; +// *ijpipt = i - 1; + *ijpjpt = mpi; + } + g = *prept; + if( g > mi ) + { + mi = g; + mpi = j-1; + } + +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f->", wm ); +#endif + g = *mjpt + fpenalty; +#if 0 + fprintf( stderr, "m%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; + *ijpipt = *mpjpt; + *ijpjpt = j - 1; //IRU! + } + g = *prept; + if( g > *mjpt ) + { + *mjpt = g; + *mpjpt = i-1; + } +#if USE_PENALTY_EX + *mjpt += fpenalty_ex; +#endif + + + g = tbk + fpenalty_OP; +// g = tbk; + if( g > wm ) + { + wm = g; + *ijpipt = tbki; + *ijpjpt = tbkj; +// fprintf( stderr, "hit! i%d, j%d, ijpi = %d, ijpj = %d\n", i, j, *ijpipt, *ijpjpt ); + } +// g = Mi; + if( Mi > tbk ) + { + tbk = Mi; //error desu. + tbki = i-1; + tbkj = Mpi; + } +// g = *Mjpt; + if( *Mjpt > tbk ) + { + tbk = *Mjpt; + tbki = *Mpjpt; + tbkj = j-1; + } +// tbk += fpenalty_EX;// + foffset; + +// g = *prept; + if( *prept > *Mjpt ) + { + *Mjpt = *prept; + *Mpjpt = i-1; + } +// *Mjpt += fpenalty_EX;// + foffset; + +// g = *prept; + if( *prept > Mi ) + { + Mi = *prept; + Mpi = j-1; + } +// Mi += fpenalty_EX;// + foffset; + + +// fprintf( stderr, "wm=%f, tbk=%f(%c-%c), mi=%f, *mjpt=%f\n", wm, tbk, seq1[0][tbki], seq2[0][tbkj], mi, *mjpt ); +// fprintf( stderr, "ijp = %c,%c\n", seq1[0][abs(*ijpipt)], seq2[0][abs(*ijpjpt)] ); + + + if( maxwm < wm ) + { + maxwm = wm; + endali = i; + endalj = j; + } +#if 1 + if( wm < localthr ) + { +// fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt ); + *ijpipt = localstop; +// *ijpjpt = localstop; + wm = localthr2; + } +#endif +#if 0 + fprintf( stderr, "%5.0f ", *curpt ); +#endif +#if DEBUG2 + fprintf( stderr, "%5.0f ", wm ); +// fprintf( stderr, "%c-%c *ijppt = %d, localstop = %d\n", seq1[0][i], seq2[0][j], *ijppt, localstop ); +#endif + + *curpt += wm; + ijpipt++; + ijpjpt++; + mjpt++; + Mjpt++; + prept++; + mpjpt++; + Mpjpt++; + curpt++; + } +#if DEBUG2 + fprintf( stderr, "\n" ); +#endif + + lastverticalw[i] = currentw[lgth2-1]; + } + + +#if DEBUG2 + fprintf( stderr, "maxwm = %f\n", maxwm ); + fprintf( stderr, "endali = %d\n", endali ); + fprintf( stderr, "endalj = %d\n", endalj ); +#endif + + if( ijpi[endali][endalj] == localstop ) // && ijpj[endali][endalj] == localstop ) + { + strcpy( seq1[0], "" ); + strcpy( seq2[0], "" ); + *off1pt = *off2pt = 0; + return( 0.0 ); + } + + + gentracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijpi, ijpj, off1pt, off2pt, endali, endalj ); + +// fprintf( stderr, "### impmatch = %f\n", *impmatch ); + + resultlen = strlen( mseq1[0] ); + if( alloclen < resultlen || resultlen > N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } + + + strcpy( seq1[0], mseq1[0] ); + strcpy( seq2[0], mseq2[0] ); + +#if 0 + fprintf( stderr, "\n" ); + fprintf( stderr, ">\n%s\n", mseq1[0] ); + fprintf( stderr, ">\n%s\n", mseq2[0] ); +#endif + + + return( maxwm ); +} + Added: test-suite/trunk/MultiSource/Benchmarks/mafft/io.c URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/io.c?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/io.c (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/io.c Thu Feb 19 06:37:59 2009 @@ -0,0 +1,3813 @@ +#include "mltaln.h" + +static int upperCase = 0; + +#define DEBUG 0 +#define IODEBUG 0 + +#if 0 + +static int addlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, int skip ) +{ + int pos1, pos2, start1, start2, end1, end2; + char *pt1, *pt2; + int iscore; + int isumscore; + int sumoverlap; + LocalHom *tmppt; + int st; + int nlocalhom = 0; + pt1 = al1; pt2 = al2; + pos1 = off1; pos2 = off2; + + isumscore = 0; + sumoverlap = 0; + +#if 0 + fprintf( stderr, "nlocalhom = %d in addlocalhom\n", nlocalhom ); + fprintf( stderr, "al1 = %s, al2 = %s\n", al1, al2 ); + fprintf( stderr, "off1 = %d, off2 = %d\n", off1, off2 ); + fprintf( stderr, "localhopt = %p, skip = %d\n", localhompt, skip ); + fprintf( stderr, "pt1 = \n%s\n, pt2 = \n%s\n", pt1, pt2 ); +#endif + + if( skip ) + { + while( --skip > 0 ) localhompt = localhompt->next; + localhompt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); + localhompt = localhompt->next; +// fprintf( stderr, "tmppt = %p, localhompt = %p\n", tmppt, localhompt ); + } + tmppt = localhompt; + + st = 0; + iscore = 0; + while( *pt1 != 0 ) + { +// fprintf( stderr, "In in while loop\n" ); +// fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st ); + if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) ) + { + end1 = pos1 - 1; + end2 = pos2 - 1; + + if( nlocalhom++ > 0 ) + { +// fprintf( stderr, "reallocating ...\n" ); + tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); +// fprintf( stderr, "done\n" ); + tmppt = tmppt->next; + tmppt->next = NULL; + } + tmppt->start1 = start1; + tmppt->start2 = start2; + tmppt->end1 = end1 ; + tmppt->end2 = end2 ; + +#if 1 + isumscore += iscore; + sumoverlap += end2-start2+1; +#else + tmppt->overlapaa = end2-start2+1; + tmppt->opt = iscore * 5.8 / 600; + tmppt->overlapaa = overlapaa; + tmppt->opt = (double)opt; +#endif + +#if 0 + fprintf( stderr, "iscore (1)= %d\n", iscore ); + fprintf( stderr, "al1: %d - %d\n", start1, end1 ); + fprintf( stderr, "al2: %d - %d\n", start2, end2 ); +#endif + iscore = 0; + st = 0; + } + else if( *pt1 != '-' && *pt2 != '-' ) + { + if( st == 0 ) + { + start1 = pos1; start2 = pos2; + st = 1; + } + iscore += n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; +// fprintf( stderr, "%c-%c, score(0) = %d\n", *pt1, *pt2, iscore ); + } + if( *pt1++ != '-' ) pos1++; + if( *pt2++ != '-' ) pos2++; + } + + if( st ) + { + if( nlocalhom++ > 0 ) + { +// fprintf( stderr, "reallocating ...\n" ); + tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); +// fprintf( stderr, "done\n" ); + tmppt = tmppt->next; + tmppt->next = NULL; + } + end1 = pos1 - 1; + end2 = pos2 - 1; + tmppt->start1 = start1; + tmppt->start2 = start2; + tmppt->end1 = end1 ; + tmppt->end2 = end2 ; + +#if 1 + isumscore += iscore; + sumoverlap += end2-start2+1; +#else + tmppt->overlapaa = end2-start2+1; + tmppt->opt = (double)iscore * 5.8 / 600; + tmppt->overlapaa = overlapaa; + tmppt->opt = (double)opt; +#endif +#if 0 + fprintf( stderr, "score (2)= %d\n", iscore ); + fprintf( stderr, "al1: %d - %d\n", start1, end1 ); + fprintf( stderr, "al2: %d - %d\n", start2, end2 ); +#endif + } + + for( tmppt=localhompt; tmppt; tmppt=tmppt->next ) + { + tmppt->overlapaa = sumoverlap; + tmppt->opt = (double)sumscore * 5.8 / 600 / sumoverlap; + } + return( nlocalhom ); +} + +#endif + + + +static int addlocalhom_r( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, int skip ) +{ + int pos1, pos2, start1, start2, end1, end2; + char *pt1, *pt2; + double score; + double sumscore; + int sumoverlap; + LocalHom *tmppt = NULL; // by D.Mathog, a guess + int st; + int nlocalhom = 0; + pt1 = al1; pt2 = al2; + pos1 = off1; pos2 = off2; + + sumscore = 0.0; + sumoverlap = 0; + start1 = 0; // by D.Mathog, a guess + start2 = 0; // by D.Mathog, a guess + +#if 0 + fprintf( stderr, "nlocalhom = %d in addlocalhom\n", nlocalhom ); + fprintf( stderr, "al1 = %s, al2 = %s\n", al1, al2 ); + fprintf( stderr, "off1 = %d, off2 = %d\n", off1, off2 ); + fprintf( stderr, "localhopt = %p, skip = %d\n", localhompt, skip ); +#endif + fprintf( stderr, "pt1 = \n%s\n, pt2 = \n%s\n", pt1, pt2 ); + + if( skip ) + { + while( --skip > 0 ) localhompt = localhompt->next; + localhompt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); + localhompt = localhompt->next; + fprintf( stderr, "tmppt = %p, localhompt = %p\n", (void *)tmppt, (void *)localhompt ); + } + tmppt = localhompt; + + st = 0; + score = 0.0; + while( *pt1 != 0 ) + { + fprintf( stderr, "In in while loop\n" ); + fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st ); + if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) ) + { + end1 = pos1 - 1; + end2 = pos2 - 1; + + if( nlocalhom++ > 0 ) + { +// fprintf( stderr, "reallocating ...\n" ); + tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); +// fprintf( stderr, "done\n" ); + tmppt = tmppt->next; + tmppt->next = NULL; + } + tmppt->start1 = start1; + tmppt->start2 = start2; + tmppt->end1 = end1 ; + tmppt->end2 = end2 ; + +#if 1 + sumscore += score; + sumoverlap += end2-start2+1; +#else + tmppt->overlapaa = end2-start2+1; + tmppt->opt = score * 5.8 / 600; + tmppt->overlapaa = overlapaa; + tmppt->opt = (double)opt; +#endif + + fprintf( stderr, "score (1)= %f\n", score ); + fprintf( stderr, "al1: %d - %d\n", start1, end1 ); + fprintf( stderr, "al2: %d - %d\n", start2, end2 ); + score = 0.0; + st = 0; + } + else if( *pt1 != '-' && *pt2 != '-' ) + { + if( st == 0 ) + { + start1 = pos1; start2 = pos2; + st = 1; + } + score += (double)n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; +// fprintf( stderr, "%c-%c, score(0) = %f\n", *pt1, *pt2, score ); + } + if( *pt1++ != '-' ) pos1++; + if( *pt2++ != '-' ) pos2++; + } + if( nlocalhom++ > 0 ) + { +// fprintf( stderr, "reallocating ...\n" ); + tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); +// fprintf( stderr, "done\n" ); + tmppt = tmppt->next; + tmppt->next = NULL; + } + end1 = pos1 - 1; + end2 = pos2 - 1; + tmppt->start1 = start1; + tmppt->start2 = start2; + tmppt->end1 = end1 ; + tmppt->end2 = end2 ; + +#if 1 + sumscore += score; + sumoverlap += end2-start2+1; +#else + tmppt->overlapaa = end2-start2+1; + tmppt->opt = score * 5.8 / 600; + tmppt->overlapaa = overlapaa; + tmppt->opt = (double)opt; +#endif + + fprintf( stderr, "score (2)= %f\n", score ); + fprintf( stderr, "al1: %d - %d\n", start1, end1 ); + fprintf( stderr, "al2: %d - %d\n", start2, end2 ); + + for( tmppt=localhompt; tmppt; tmppt=tmppt->next ) + { + tmppt->overlapaa = sumoverlap; + tmppt->opt = sumscore * 5.8 / 600 / sumoverlap; + } + return( nlocalhom ); +} +void putlocalhom3( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ) +{ + int pos1, pos2, start1, start2, end1, end2; + char *pt1, *pt2; + double score; + double sumscore; + int sumoverlap; + LocalHom *tmppt; + LocalHom *subnosento; + int st; + int saisho; + + pt1 = al1; pt2 = al2; + pos1 = off1; pos2 = off2; + + sumscore = 0.0; + sumoverlap = 0; + start1 = 0; // by Mathog, a guess + start2 = 0; // by Mathog, a guess + + subnosento = localhompt; + while( subnosento->next ) subnosento = subnosento->next; + tmppt = subnosento; + + saisho = ( localhompt->nokori == 0 ); + + fprintf( stderr, "localhompt = %p\n", (void *)localhompt ); + fprintf( stderr, "tmppt = %p\n", (void *)tmppt ); + fprintf( stderr, "subnosento = %p\n", (void *)subnosento ); + + st = 0; + score = 0.0; + while( *pt1 != 0 ) + { +// fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st ); + if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) ) + { + end1 = pos1 - 1; + end2 = pos2 - 1; + + if( localhompt->nokori++ > 0 ) + { +// fprintf( stderr, "reallocating ...\n" ); + tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); +// fprintf( stderr, "done\n" ); + tmppt = tmppt->next; + tmppt->next = NULL; + } + tmppt->start1 = start1; + tmppt->start2 = start2; + tmppt->end1 = end1 ; + tmppt->end2 = end2 ; + +#if 1 + if( divpairscore ) + { + tmppt->overlapaa = end2-start2+1; + tmppt->opt = score / tmppt->overlapaa * 5.8 / 600; + } + else + { + sumscore += score; + sumoverlap += end2-start2+1; + } +#else + tmppt->overlapaa = overlapaa; + tmppt->opt = (double)opt; +#endif + +#if 0 + fprintf( stderr, "score (1)= %f\n", score ); + fprintf( stderr, "al1: %d - %d\n", start1, end1 ); + fprintf( stderr, "al2: %d - %d\n", start2, end2 ); +#endif + score = 0.0; + st = 0; + } + else if( *pt1 != '-' && *pt2 != '-' ) + { + if( st == 0 ) + { + start1 = pos1; start2 = pos2; + st = 1; + } + score += (double)n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; // - offset ?????????????? +// fprintf( stderr, "%c-%c, score(0) = %f\n", *pt1, *pt2, score ); + } + if( *pt1++ != '-' ) pos1++; + if( *pt2++ != '-' ) pos2++; + } + if( *(pt1-1) != '-' && *(pt2-1) != '-' ) + { + if( localhompt->nokori++ > 0 ) + { +// fprintf( stderr, "reallocating ...\n" ); + tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); +// fprintf( stderr, "done\n" ); + tmppt = tmppt->next; + tmppt->next = NULL; + } + + end1 = pos1 - 1; + end2 = pos2 - 1; + tmppt->start1 = start1; + tmppt->start2 = start2; + tmppt->end1 = end1 ; + tmppt->end2 = end2 ; + + +#if 1 + if( divpairscore ) + { + tmppt->overlapaa = end2-start2+1; + tmppt->opt = score / tmppt->overlapaa * 5.8 / 600; + } + else + { + sumscore += score; + sumoverlap += end2-start2+1; + } +#else + tmppt->overlapaa = overlapaa; + tmppt->opt = (double)opt; +#endif + +#if 0 + fprintf( stderr, "score (2)= %f\n", score ); + fprintf( stderr, "al1: %d - %d\n", start1, end1 ); + fprintf( stderr, "al2: %d - %d\n", start2, end2 ); +#endif + } + + fprintf( stderr, "sumscore = %f\n", sumscore ); + if( !divpairscore ) + { + + if( !saisho ) subnosento = subnosento->next; + for( tmppt=subnosento; tmppt; tmppt=tmppt->next ) + { + tmppt->overlapaa = sumoverlap; + tmppt->opt = sumscore * 5.8 / 600 / sumoverlap; + fprintf( stderr, "tmpptr->opt = %f\n", tmppt->opt ); + } + } +} +void putlocalhom_ext( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ) +{ + int pos1, pos2, start1, start2, end1, end2; + char *pt1, *pt2; + int iscore; + int isumscore; + int sumoverlap; + LocalHom *tmppt = localhompt; + int nlocalhom = 0; + int st; + pt1 = al1; pt2 = al2; + pos1 = off1; pos2 = off2; + + + isumscore = 0; + sumoverlap = 0; + start1 = 0; // by D.Mathog, a guess + start2 = 0; // by D.Mathog, a guess + + st = 0; + iscore = 0; + while( *pt1 != 0 ) + { +// fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st ); + if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) ) + { + end1 = pos1 - 1; + end2 = pos2 - 1; + + if( nlocalhom++ > 0 ) + { +// fprintf( stderr, "reallocating ...\n" ); + tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); +// fprintf( stderr, "done\n" ); + tmppt = tmppt->next; + tmppt->next = NULL; + } + tmppt->start1 = start1; + tmppt->start2 = start2; + tmppt->end1 = end1 ; + tmppt->end2 = end2 ; + +#if 1 + if( divpairscore ) + { + tmppt->overlapaa = end2-start2+1; + tmppt->opt = (double)iscore / tmppt->overlapaa * 5.8 / 600; + } + else + { + isumscore += iscore; + sumoverlap += end2-start2+1; + } +#else + tmppt->overlapaa = overlapaa; + tmppt->opt = (double)opt; +#endif + +#if 0 + fprintf( stderr, "iscore (1)= %d\n", iscore ); + fprintf( stderr, "al1: %d - %d\n", start1, end1 ); + fprintf( stderr, "al2: %d - %d\n", start2, end2 ); +#endif + iscore = 0; + st = 0; + } + else if( *pt1 != '-' && *pt2 != '-' ) + { + if( st == 0 ) + { + start1 = pos1; start2 = pos2; + st = 1; + } + iscore += n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; // - offset ?????????????? +// fprintf( stderr, "%c-%c, iscore(0) = %d\n", *pt1, *pt2, iscore ); + } + if( *pt1++ != '-' ) pos1++; + if( *pt2++ != '-' ) pos2++; + } + if( *(pt1-1) != '-' && *(pt2-1) != '-' ) + { + if( nlocalhom++ > 0 ) + { +// fprintf( stderr, "reallocating ...\n" ); + tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); +// fprintf( stderr, "done\n" ); + tmppt = tmppt->next; + tmppt->next = NULL; + } + end1 = pos1 - 1; + end2 = pos2 - 1; + tmppt->start1 = start1; + tmppt->start2 = start2; + tmppt->end1 = end1 ; + tmppt->end2 = end2 ; + +#if 1 + if( divpairscore ) + { + tmppt->overlapaa = end2-start2+1; + tmppt->opt = (double)iscore / tmppt->overlapaa * 5.8 / 600; + } + else + { + isumscore += iscore; + sumoverlap += end2-start2+1; + } +#else + tmppt->overlapaa = overlapaa; + tmppt->opt = (double)opt; +#endif + +#if 0 + fprintf( stderr, "iscore (2)= %d\n", iscore ); + fprintf( stderr, "al1: %d - %d\n", start1, end1 ); + fprintf( stderr, "al2: %d - %d\n", start2, end2 ); +#endif + } + + if( !divpairscore ) + { + for( tmppt=localhompt; tmppt; tmppt=tmppt->next ) + { + tmppt->overlapaa = sumoverlap; +// tmppt->opt = (double)isumscore * 5.8 / ( 600 * sumoverlap ); + tmppt->opt = (double)600 * 5.8 / 600; +// fprintf( stderr, "tmpptr->opt = %f\n", tmppt->opt ); + } + } +} +void putlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ) +{ + int pos1, pos2, start1, start2, end1, end2; + char *pt1, *pt2; + int iscore; + int isumscore; + int sumoverlap; + LocalHom *tmppt = localhompt; + int nlocalhom = 0; + int st; + pt1 = al1; pt2 = al2; + pos1 = off1; pos2 = off2; + + + isumscore = 0; + sumoverlap = 0; + start1 = 0; // by D.Mathog, a guess + start2 = 0; // by D.Mathog, a guess + + st = 0; + iscore = 0; + while( *pt1 != 0 ) + { +// fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st ); + if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) ) + { + end1 = pos1 - 1; + end2 = pos2 - 1; + + if( nlocalhom++ > 0 ) + { +// fprintf( stderr, "reallocating ...\n" ); + tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); +// fprintf( stderr, "done\n" ); + tmppt = tmppt->next; + tmppt->next = NULL; + } + tmppt->start1 = start1; + tmppt->start2 = start2; + tmppt->end1 = end1 ; + tmppt->end2 = end2 ; + +#if 1 + if( divpairscore ) + { + tmppt->overlapaa = end2-start2+1; + tmppt->opt = (double)iscore / tmppt->overlapaa * 5.8 / 600; + } + else + { + isumscore += iscore; + sumoverlap += end2-start2+1; + } +#else + tmppt->overlapaa = overlapaa; + tmppt->opt = (double)opt; +#endif + +#if 0 + fprintf( stderr, "iscore (1)= %d\n", iscore ); + fprintf( stderr, "al1: %d - %d\n", start1, end1 ); + fprintf( stderr, "al2: %d - %d\n", start2, end2 ); +#endif + iscore = 0; + st = 0; + } + else if( *pt1 != '-' && *pt2 != '-' ) + { + if( st == 0 ) + { + start1 = pos1; start2 = pos2; + st = 1; + } + iscore += n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; // - offset ?????????????? +// fprintf( stderr, "%c-%c, iscore(0) = %d\n", *pt1, *pt2, iscore ); + } + if( *pt1++ != '-' ) pos1++; + if( *pt2++ != '-' ) pos2++; + } + if( *(pt1-1) != '-' && *(pt2-1) != '-' ) + { + if( nlocalhom++ > 0 ) + { +// fprintf( stderr, "reallocating ...\n" ); + tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); +// fprintf( stderr, "done\n" ); + tmppt = tmppt->next; + tmppt->next = NULL; + } + end1 = pos1 - 1; + end2 = pos2 - 1; + tmppt->start1 = start1; + tmppt->start2 = start2; + tmppt->end1 = end1 ; + tmppt->end2 = end2 ; + +#if 1 + if( divpairscore ) + { + tmppt->overlapaa = end2-start2+1; + tmppt->opt = (double)iscore / tmppt->overlapaa * 5.8 / 600; + } + else + { + isumscore += iscore; + sumoverlap += end2-start2+1; + } +#else + tmppt->overlapaa = overlapaa; + tmppt->opt = (double)opt; +#endif + +#if 0 + fprintf( stderr, "iscore (2)= %d\n", iscore ); + fprintf( stderr, "al1: %d - %d\n", start1, end1 ); + fprintf( stderr, "al2: %d - %d\n", start2, end2 ); +#endif + } + + if( !divpairscore ) + { + for( tmppt=localhompt; tmppt; tmppt=tmppt->next ) + { + tmppt->overlapaa = sumoverlap; + tmppt->opt = (double)isumscore * 5.8 / ( 600 * sumoverlap ); +// fprintf( stderr, "tmpptr->opt = %f\n", tmppt->opt ); + } + } +} +void putlocalhom( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ) +{ + int pos1, pos2, start1, start2, end1, end2; + char *pt1, *pt2; + double score; + double sumscore; + int sumoverlap; + LocalHom *tmppt = localhompt; + int nlocalhom = 0; + int st; + pt1 = al1; pt2 = al2; + pos1 = off1; pos2 = off2; + + + sumscore = 0.0; + sumoverlap = 0; + start1 = 0; // by D.Mathog, a guess + start2 = 0; // by D.Mathog, a guess + + st = 0; + score = 0.0; + while( *pt1 != 0 ) + { +// fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st ); + if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) ) + { + end1 = pos1 - 1; + end2 = pos2 - 1; + + if( nlocalhom++ > 0 ) + { +// fprintf( stderr, "reallocating ...\n" ); + tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); +// fprintf( stderr, "done\n" ); + tmppt = tmppt->next; + tmppt->next = NULL; + } + tmppt->start1 = start1; + tmppt->start2 = start2; + tmppt->end1 = end1 ; + tmppt->end2 = end2 ; + +#if 1 + if( divpairscore ) + { + tmppt->overlapaa = end2-start2+1; + tmppt->opt = score / tmppt->overlapaa * 5.8 / 600; + } + else + { + sumscore += score; + sumoverlap += end2-start2+1; + } +#else + tmppt->overlapaa = overlapaa; + tmppt->opt = (double)opt; +#endif + +#if 0 + fprintf( stderr, "score (1)= %f\n", score ); + fprintf( stderr, "al1: %d - %d\n", start1, end1 ); + fprintf( stderr, "al2: %d - %d\n", start2, end2 ); +#endif + score = 0.0; + st = 0; + } + else if( *pt1 != '-' && *pt2 != '-' ) + { + if( st == 0 ) + { + start1 = pos1; start2 = pos2; + st = 1; + } + score += (double)n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; // - offset ?????????????? +// fprintf( stderr, "%c-%c, score(0) = %f\n", *pt1, *pt2, score ); + } + if( *pt1++ != '-' ) pos1++; + if( *pt2++ != '-' ) pos2++; + } + if( nlocalhom++ > 0 ) + { +// fprintf( stderr, "reallocating ...\n" ); + tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); +// fprintf( stderr, "done\n" ); + tmppt = tmppt->next; + tmppt->next = NULL; + } + end1 = pos1 - 1; + end2 = pos2 - 1; + tmppt->start1 = start1; + tmppt->start2 = start2; + tmppt->end1 = end1 ; + tmppt->end2 = end2 ; + +#if 1 + if( divpairscore ) + { + tmppt->overlapaa = end2-start2+1; + tmppt->opt = score / tmppt->overlapaa * 5.8 / 600; + } + else + { + sumscore += score; + sumoverlap += end2-start2+1; + } +#else + tmppt->overlapaa = overlapaa; + tmppt->opt = (double)opt; +#endif + +#if 0 + fprintf( stderr, "score (2)= %f\n", score ); + fprintf( stderr, "al1: %d - %d\n", start1, end1 ); + fprintf( stderr, "al2: %d - %d\n", start2, end2 ); +#endif + + if( !divpairscore ) + { + for( tmppt=localhompt; tmppt; tmppt=tmppt->next ) + { + tmppt->overlapaa = sumoverlap; + tmppt->opt = sumscore * 5.8 / 600 / sumoverlap; +// fprintf( stderr, "tmpptr->opt = %f\n", tmppt->opt ); + } + } +} + +char *cutal( char *al, int al_display_start, int start, int end ) +{ + int pos; + char *pt = al; + char *val = NULL; + + pos = al_display_start; + do + { + if( start == pos ) val = pt; + if( end == pos ) break; +// fprintf( stderr, "pos=%d, *pt=%c, val=%p\n", pos, *pt, val ); + if( *pt != '-' ) pos++; + } while( *pt++ != 0 ); + *(pt+1) = 0; + return( val ); +} + +void ErrorExit( char *message ) +{ + fprintf( stderr, "%s\n", message ); + exit( 1 ); +} + +void strncpy_caseC( char *str1, char *str2, int len ) +{ + if( dorp == 'd' && upperCase > 0 ) + { + while( len-- ) + *str1++ = toupper( *str2++ ); + } + else strncpy( str1, str2, len ); +} + +void seqUpper( int nseq, char **seq ) /* not used */ +{ + int i, j, len; + for( i=0; i return 1 */ +{ + int c, i = 0 ; + int noteofflag = 0; + for( i=0; i return 1 */ +char s[] ; int l ; FILE *fp ; +{ + int c = 0, i = 0 ; + int noteofflag = 0; + + if( feof( fp ) ) return( 1 ); + + for( i=0; i M ) + { + fprintf( stderr, "TOO MANY SEQUENCE!\n" ); + fprintf( stderr, "%d > %d\n", njob, M ); + exit( 1 ); + } +} + +int allSpace( char *str ) +{ + int value = 1; + while( *str ) value *= ( !isdigit( *str++ ) ); + return( value ); +} + +void Read( char name[M][B], int nlen[M], char **seq ) +{ + extern void FRead( FILE *x, char y[M][B], int z[M], char **w ); + FRead( stdin, name, nlen, seq ); +} + + +void FRead( FILE *fp, char name[][B], int nlen[], char **seq ) +{ + int i, j; + char b[B]; + + fgets( b, B-1, fp ); +#if DEBUG + fprintf( stderr, "b = %s\n", b ); +#endif + + if( strstr( b, "onnet" ) ) scoremtx = 1; + else if( strstr( b, "DnA" ) ) + { + scoremtx = -1; + upperCase = -1; + } + else if( strstr( b, "dna" ) ) + { + scoremtx = -1; + upperCase = 0; + } + else if( strstr( b, "DNA" ) ) + { + scoremtx = -1; + upperCase = 1; + } + else if( strstr( b, "M-Y" ) || strstr( b, "iyata" ) ) scoremtx = 2; + else scoremtx = 0; +#if DEBUG + fprintf( stderr, " %s->scoremtx = %d\n", b, scoremtx ); +#endif + + geta2 = GETA2; + +#if 0 + if( strlen( b ) >=25 ) + { + b[25] = 0; + #if DEBUG + fprintf( stderr, "kimuraR = %s\n", b+20 ); + #endif + kimuraR = atoi( b+20 ); + + if( kimuraR < 0 || 20 < kimuraR ) ErrorExit( "Illeagal kimuraR value.\n" ); + if( allSpace( b+20 ) ) kimuraR = NOTSPECIFIED; + } + else kimuraR = NOTSPECIFIED; + #if DEBUG + fprintf( stderr, "kimuraR = %d\n", kimuraR ); + #endif + + if( strlen( b ) >=20 ) + { + b[20] = 0; + #if DEBUG + fprintf( stderr, "pamN = %s\n", b+15 ); + #endif + pamN = atoi( b+15 ); + if( pamN < 0 || 400 < pamN ) ErrorExit( "Illeagal pam value.\n" ); + if( allSpace( b+15 ) ) pamN = NOTSPECIFIED; + } + else pamN = NOTSPECIFIED; + + if( strlen( b ) >= 15 ) + { + b[15] = 0; + #if DEBUG + fprintf( stderr, "poffset = %s\n", b+10 ); + #endif + poffset = atoi( b+10 ); + if( poffset > 500 ) ErrorExit( "Illegal extending gap ppenalty\n" ); + if( allSpace( b+10 ) ) poffset = NOTSPECIFIED; + } + else poffset = NOTSPECIFIED; + + if( strlen( b ) >= 10 ) + { + b[10] = 0; + #if DEBUG + fprintf( stderr, "ppenalty = %s\n", b+5 ); + #endif + ppenalty = atoi( b+5 ); + if( ppenalty > 0 ) ErrorExit( "Illegal opening gap ppenalty\n" ); + if( allSpace( b+5 ) ) ppenalty = NOTSPECIFIED; + } + else ppenalty = NOTSPECIFIED; +#endif + + for( i=0; i' ) ) + value++; + b = c; + } + rewind( fp ); + return( value ); +} + +void searchKUorWA( FILE *fp ) +{ + int c, b; + b = '\n'; + while( !( ( ( c = getc( fp ) ) == '>' || c == '=' || c == EOF ) && b == '\n' ) ) + b = c; + ungetc( c, fp ); +} + +static int onlyAlpha_lower( char *str ) +{ + char tmp; + char *res = str; + char *bk = str; + + while( (tmp=*str++) ) + if( isalpha( tmp ) || tmp == '-' || tmp == '*' || tmp == '.' ) + *res++ = tolower( tmp ); + *res = 0; + return( res - bk ); +} +static int onlyAlpha_upper( char *str ) +{ + char tmp; + char *res = str; + char *bk = str; + + while( (tmp=*str++) ) + if( isalpha( tmp ) || tmp == '-' || tmp == '*' || tmp == '.' ) + *res++ = toupper( tmp ); + *res = 0; + return( res - bk ); +} + +void kake2hiku( char *str ) +{ + do + if( *str == '*' ) *str = '-'; + while( *str++ ); +} + +char *load1SeqWithoutName_realloc( FILE *fpp ) +{ + int c, b; + char *cbuf; + int size = N; + char *val; + + val = malloc( (size+1) * sizeof( char ) ); + cbuf = val; + + b = '\n'; + while( ( c = getc( fpp ) ) != EOF && + !( ( c == '>' || c == '=' || c == '(' || c == EOF ) && b == '\n' ) ) + { + *cbuf++ = (char)c; /* ?????????????????? */ + if( cbuf - val == size ) + { + size += N; + fprintf( stderr, "reallocating...\n" ); + val = (char *)realloc( val, (size+1) * sizeof( char ) ); + if( !val ) + { + fprintf( stderr, "Allocation error in load1SeqWithoutName_realloc \n" ); + exit( 1 ); + } + fprintf( stderr, "done.\n" ); + cbuf = val + size-N; + } + b = c; + } + ungetc( c, fpp ); + *cbuf = 0; + if( dorp == 'd' ) + onlyAlpha_lower( val ); + else + onlyAlpha_upper( val ); + kake2hiku( val ); + return( val ); +} + +int load1SeqWithoutName_new( FILE *fpp, char *cbuf ) +{ + int c, b; + char *bk = cbuf; + + b = '\n'; + while( ( c = getc( fpp ) ) != EOF && /* by T. Nishiyama */ + !( ( c == '>' || c == '=' || c == '(' || c == EOF ) && b == '\n' ) ) + { + *cbuf++ = (char)c; /* ?????????????????? */ + b = c; + } + ungetc( c, fpp ); + *cbuf = 0; + if( dorp == 'd' ) + onlyAlpha_lower( bk ); + else + onlyAlpha_upper( bk ); + kake2hiku( bk ); + return( 0 ); +} + + +void readDataforgaln( FILE *fp, char **name, int *nlen, char **seq ) +{ + int i; + static char *tmpseq = NULL; + +#if 0 + if( !tmpseq ) + { + tmpseq = AllocateCharVec( N ); + } +#endif + + rewind( fp ); + searchKUorWA( fp ); + + for( i=0; i nlenmax ) nlenmax = tmp; + if( tmp < *nlenminpt ) *nlenminpt = tmp; + atgcnum += countATGC( tmpseq, &nsite ); + total += nsite; + free( tmpseq ); + } + free( tmpname ); + atgcfreq = (double)atgcnum / total; + fprintf( stderr, "##### atgcfreq = %f\n", atgcfreq ); + if( dorp == NOTSPECIFIED ) + { + if( atgcfreq > 0.75 ) + { + dorp = 'd'; + upperCase = -1; + } + else + { + dorp = 'p'; + upperCase = 0; + } + } +} + +void getnumlen( FILE *fp ) +{ + int total; + int nsite; + int atgcnum; + int i, tmp; + char *tmpseq; + char *tmpname; + double atgcfreq; + tmpname = AllocateCharVec( N ); + njob = countKUorWA( fp ); + searchKUorWA( fp ); + nlenmax = 0; + atgcnum = 0; + total = 0; + for( i=0; i nlenmax ) nlenmax = tmp; + atgcnum += countATGC( tmpseq, &nsite ); + total += nsite; +// fprintf( stderr, "##### total = %d\n", total ); + free( tmpseq ); + } + + atgcfreq = (double)atgcnum / total; +// fprintf( stderr, "##### atgcfreq = %f\n", atgcfreq ); + if( dorp == NOTSPECIFIED ) + { + if( atgcfreq > 0.75 ) + { + dorp = 'd'; + upperCase = -1; + } + else + { + dorp = 'p'; + upperCase = 0; + } + } + free( tmpname ); +} + + + +void WriteGapFill( FILE *fp, int locnjob, char name[][B], int nlen[M], char **aseq ) +{ + static char b[N]; + int i, j; + int nalen[M]; + static char gap[N]; + static char buff[N]; + +#if IODEBUG + fprintf( stderr, "IMAKARA KAKU\n" ); +#endif + nlenmax = 0; + for( i=0; i%s\n", name[i]+1 ); + for( j=0; j%s\n", name[i]+1 ); + for( j=0; j%s\n", name[i]+1 ); + for( j=0; j max ) max = mtx[i][j]; + + fprintf( hat2p, "%5d\n", 1 ); + fprintf( hat2p, "%5d\n", locnjob ); + fprintf( hat2p, " %#6.3f\n", max * 2.5 ); + + for( i=0; i max ) max = mtx[i][j]; + + fprintf( hat2p, "%5d\n", 1 ); + fprintf( hat2p, "%5d\n", locnjob ); + fprintf( hat2p, " %#6.3f\n", max * 2.5 ); + + for( i=0; i max ) max = mtx[i][j]; + max /= INTMTXSCALE; + + fprintf( hat2p, "%5d\n", 1 ); + fprintf( hat2p, "%5d\n", locnjob ); + fprintf( hat2p, " %#6.3f\n", max * 2.5 ); + + for( i=0; i max ) max = mtx[i][j]; + + fprintf( hat2p, "%5d\n", 1 ); + fprintf( hat2p, "%5d\n", locnjob ); + fprintf( hat2p, " %#6.3f\n", max * 2.5 ); + + for( i=0; i", b, 19 ) || !strncmp( " ", b, 23 ) ) break; + } + + if( !strncmp( " ", b, 19 ) ) + { + junban[count] = atoi( b+31 ); + nlocalhom = 0; + } + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 25 ) ) break; + pt = b + 25; + score = atof( pt ); + sumscore += score; + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 30 ) ) break; + pt = b + 30; + qstart = atoi( pt ) - 1; + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 28 ) ) break; + pt = b + 28; + qend = atoi( pt ) - 1; + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 28 ) ) break; + pt = b + 28; + tstart = atoi( pt ) - 1; + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 26 ) ) break; + pt = b + 26; + tend = atoi( pt ) - 1; + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 29 ) ) break; + pt = b + 29; + len = atoi( pt ); + sumlen += len; + + + while( fgets( al, N-100, fp ) ) + if( !strncmp( " ", al, 24 ) ) break; + + strcpy( qal, al+24 ); + pt = qal; + while( *++pt != '<' ) + ; + *pt = 0; + + + while( fgets( al, N-100, fp ) ) + if( !strncmp( " ", al, 24 ) ) break; + + strcpy( tal, al+24 ); + pt = tal; + while( *++pt != '<' ) + ; + *pt = 0; + + +// fprintf( stderr, "t=%d, score = %f, qstart=%d, qend=%d, tstart=%d, tend=%d, overlapaa=%d\n", junban[count], score, qstart, qend, tstart, tend, overlapaa ); + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " :", b, 18 ) ) break; + + + fgets( b, B-1, fp ); + + + if( !strncmp( " ", b, 21 ) ) + { + dis[junban[count++]] = sumscore; + sumscore = 0.0; + fgets( b, B-1, fp ); + fgets( b, B-1, fp ); + scorepersite = sumscore / sumlen; + if( scorepersite != (int)scorepersite ) + { + fprintf( stderr, "ERROR! sumscore=%f, sumlen=%f, and scorepersite=%f\n", sumscore, sumlen, scorepersite ); + exit( 1 ); + } + + if( !strncmp( " ", b, 23 ) ) break; + } + } + + free( junban ); + + return (int)scorepersite; +} +int ReadBlastm7_scoreonly( FILE *fp, double *dis, int nin ) +{ + int count=0; + char b[B]; + char *pt; + int *junban; + int overlapaa; + double score, sumscore; + int qstart, qend, tstart, tend; + static char qal[N], tal[N], al[N]; + int nlocalhom; + + junban = calloc( nin, sizeof( int ) ); + + count = 0; + sumscore = 0.0; + score = 0.0; + while( 1 ) + { + + if( feof( fp ) ) break; + + while( fgets( b, B-1, fp ) ) + { + if( !strncmp( " ", b, 19 ) || !strncmp( " ", b, 23 ) ) break; + } + + if( !strncmp( " ", b, 19 ) ) + { + junban[count] = atoi( b+31 ); + nlocalhom = 0; + } + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 25 ) ) break; + pt = b + 25; + score = atof( pt ); + sumscore += score; + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 30 ) ) break; + pt = b + 30; + qstart = atoi( pt ) - 1; + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 28 ) ) break; + pt = b + 28; + qend = atoi( pt ) - 1; + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 28 ) ) break; + pt = b + 28; + tstart = atoi( pt ) - 1; + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 26 ) ) break; + pt = b + 26; + tend = atoi( pt ) - 1; + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 29 ) ) break; + pt = b + 29; + overlapaa = atoi( pt ); + + + while( fgets( al, N-100, fp ) ) + if( !strncmp( " ", al, 24 ) ) break; + + strcpy( qal, al+24 ); + pt = qal; + while( *++pt != '<' ) + ; + *pt = 0; + + + while( fgets( al, N-100, fp ) ) + if( !strncmp( " ", al, 24 ) ) break; + + strcpy( tal, al+24 ); + pt = tal; + while( *++pt != '<' ) + ; + *pt = 0; + + +// fprintf( stderr, "t=%d, score = %f, qstart=%d, qend=%d, tstart=%d, tend=%d, overlapaa=%d\n", junban[count], score, qstart, qend, tstart, tend, overlapaa ); + +// nlocalhom += addlocalhom_r( qal, tal, localhomlist+junban[count], qstart, tstart, score, overlapaa, nlocalhom ); + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " :", b, 18 ) ) break; + + + fgets( b, B-1, fp ); + + + if( !strncmp( " ", b, 21 ) ) + { + dis[junban[count++]] = sumscore; + sumscore = 0.0; + fgets( b, B-1, fp ); + fgets( b, B-1, fp ); + if( !strncmp( " ", b, 23 ) ) break; + } + } + + free( junban ); + + return count; +} + +int ReadBlastm7( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist ) +{ + int count=0; + char b[B]; + char *pt; + static int junban[M]; + int overlapaa; + double score, sumscore; + int qstart, qend, tstart, tend; + static char qal[N], tal[N], al[N]; + int nlocalhom; + + + + count = 0; + sumscore = 0.0; + score = 0.0; + nlocalhom = 0; + while( 1 ) + { + + if( feof( fp ) ) break; + + while( fgets( b, B-1, fp ) ) + { + if( !strncmp( " ", b, 19 ) || !strncmp( " ", b, 23 ) ) break; + } + + if( !strncmp( " ", b, 19 ) ) + { + junban[count] = atoi( b+31 ); + nlocalhom = 0; + } + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 25 ) ) break; + pt = b + 25; + score = atof( pt ); + sumscore += score; + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 30 ) ) break; + pt = b + 30; + qstart = atoi( pt ) - 1; + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 28 ) ) break; + pt = b + 28; + qend = atoi( pt ) - 1; + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 28 ) ) break; + pt = b + 28; + tstart = atoi( pt ) - 1; + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 26 ) ) break; + pt = b + 26; + tend = atoi( pt ) - 1; + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " ", b, 29 ) ) break; + pt = b + 29; + overlapaa = atoi( pt ); + + + while( fgets( al, N-100, fp ) ) + if( !strncmp( " ", al, 24 ) ) break; + + strcpy( qal, al+24 ); + pt = qal; + while( *++pt != '<' ) + ; + *pt = 0; + + + while( fgets( al, N-100, fp ) ) + if( !strncmp( " ", al, 24 ) ) break; + + strcpy( tal, al+24 ); + pt = tal; + while( *++pt != '<' ) + ; + *pt = 0; + + +// fprintf( stderr, "t=%d, score = %f, qstart=%d, qend=%d, tstart=%d, tend=%d, overlapaa=%d\n", junban[count], score, qstart, qend, tstart, tend, overlapaa ); + + nlocalhom += addlocalhom_r( qal, tal, localhomlist+junban[count], qstart, tstart, score, overlapaa, nlocalhom ); + + while( fgets( b, B-1, fp ) ) + if( !strncmp( " :", b, 18 ) ) break; + + + fgets( b, B-1, fp ); + + + if( !strncmp( " ", b, 21 ) ) + { + dis[junban[count++]] = sumscore; + sumscore = 0.0; + fgets( b, B-1, fp ); + fgets( b, B-1, fp ); + if( !strncmp( " ", b, 23 ) ) break; + } + } + return count; +} + +int ReadFasta34noalign( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist ) +{ + int count=0; + char b[B]; + char *pt; + static int junban[M]; + int opt; + double z, bits; + + + count = 0; +#if 0 + for( i=0; i<10000000 && count>+==========+", b, 14 ) ) + { + break; + } + + } + if( !count ) return -1; + + count = 0; + while( 1 ) + { + if( strncmp( ">>+==========+", b, 14 ) ) + { + fgets( b, B-1, fp ); + if( feof( fp ) ) break; + continue; + } + junban[count++] = atoi( b+14 ); +// fprintf( stderr, "t = %d\n", atoi( b+14 ) ); + while( fgets( b, B-1, fp ) ) + if( !strncmp( "; fa_opt:", b, 9 ) || !strncmp( "; sw_s-w opt:", b, 13 ) ) break; + pt = strstr( b, ":" ) +1; + opt = atoi( pt ); + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( "_overlap:", b+4, 9 ) ) break; + pt = strstr( b, ":" ) +1; + overlapaa = atoi( pt ); + + while( fgets( b, B-1, fp ) ) + if( !strncmp( "_start:", b+4, 7 ) ) break; + pt = strstr( b, ":" ) +1; + qstart = atoi( pt ) - 1; + + while( fgets( b, B-1, fp ) ) + if( !strncmp( "_stop:", b+4, 6 ) ) break; + pt = strstr( b, ":" ) +1; + qend = atoi( pt ) - 1; + + while( fgets( b, B-1, fp ) ) + if( !strncmp( "_display_start:", b+4, 15 ) ) break; + pt = strstr( b, ":" ) +1; + qal_display_start = atoi( pt ) - 1; + + pt = qal; + while( (c = fgetc( fp )) ) + { + if( c == '>' ) + { + ungetc( c, fp ); + break; + } + if( isalpha( c ) || c == '-' ) + *pt++ = c; + } + *pt = 0; + + while( fgets( b, B-1, fp ) ) + if( !strncmp( "_start:", b+4, 7 ) ) break; + pt = strstr( b, ":" ) + 1; + tstart = atoi( pt ) - 1; + + while( fgets( b, B-1, fp ) ) + if( !strncmp( "_stop:", b+4, 6 ) ) break; + pt = strstr( b, ":" ) + 1; + tend = atoi( pt ) - 1; + + while( fgets( b, B-1, fp ) ) + if( !strncmp( "_display_start:", b+4, 15 ) ) break; + pt = strstr( b, ":" ) + 1; + tal_display_start = atoi( pt ) - 1; + + pt = tal; + while( ( c = fgetc( fp ) ) ) + { + if( c == '>' ) + { + ungetc( c, fp ); + break; + } + if( isalpha( c ) || c == '-' ) + *pt++ = c; + } + *pt = 0; + +// fprintf( stderr, "(%d-%d:%d-%d)\n", qstart, qend, tstart, tend ); +// fprintf( stderr, "qal_display_start = %d, tal_display_start = %d\n", qal_display_start, tal_display_start ); + +// fprintf( stderr, "qal = %s\n", qal ); +// fprintf( stderr, "tal = %s\n", tal ); + + qal2 = cutal( qal, qal_display_start, qstart, qend ); + tal2 = cutal( tal, tal_display_start, tstart, tend ); + +// fprintf( stderr, "qal2 = %s\n", qal2 ); +// fprintf( stderr, "tal2 = %s\n", tal2 ); + +// fprintf( stderr, "putting %d - %d, opt = %d\n", qmem, junban[count-1], opt ); + putlocalhom( qal2, tal2, localhomlist+junban[count-1], qstart, tstart, opt, overlapaa ); + } +// fprintf( stderr, "count = %d\n", count ); + return count; +} +int ReadFasta34m10( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist ) +{ + int count=0; + char b[B]; + char *pt; + static int junban[M]; + int overlapaa; + int opt, qstart, qend, tstart, tend; + double z, bits; + int qal_display_start, tal_display_start; + static char qal[N], tal[N]; + char *qal2, *tal2; + int c; + + + count = 0; +#if 0 + for( i=0; i<10000000 && count>+==========+", b, 14 ) ) + { + break; + } + + } + if( !count ) return -1; + + count = 0; + while( 1 ) + { + if( strncmp( ">>+==========+", b, 14 ) ) + { + fgets( b, B-1, fp ); + if( feof( fp ) ) break; + continue; + } + junban[count++] = atoi( b+14 ); +// fprintf( stderr, "t = %d\n", atoi( b+14 ) ); + while( fgets( b, B-1, fp ) ) + if( !strncmp( "; fa_opt:", b, 9 ) || !strncmp( "; sw_s-w opt:", b, 13 ) ) break; + pt = strstr( b, ":" ) +1; + opt = atoi( pt ); + + + while( fgets( b, B-1, fp ) ) + if( !strncmp( "_overlap:", b+4, 9 ) ) break; + pt = strstr( b, ":" ) +1; + overlapaa = atoi( pt ); + + while( fgets( b, B-1, fp ) ) + if( !strncmp( "_start:", b+4, 7 ) ) break; + pt = strstr( b, ":" ) +1; + qstart = atoi( pt ) - 1; + + while( fgets( b, B-1, fp ) ) + if( !strncmp( "_stop:", b+4, 6 ) ) break; + pt = strstr( b, ":" ) +1; + qend = atoi( pt ) - 1; + + while( fgets( b, B-1, fp ) ) + if( !strncmp( "_display_start:", b+4, 15 ) ) break; + pt = strstr( b, ":" ) +1; + qal_display_start = atoi( pt ) - 1; + + pt = qal; + while( (c = fgetc( fp )) ) + { + if( c == '>' ) + { + ungetc( c, fp ); + break; + } + if( isalpha( c ) || c == '-' ) + *pt++ = c; + } + *pt = 0; + + while( fgets( b, B-1, fp ) ) + if( !strncmp( "_start:", b+4, 7 ) ) break; + pt = strstr( b, ":" ) + 1; + tstart = atoi( pt ) - 1; + + while( fgets( b, B-1, fp ) ) + if( !strncmp( "_stop:", b+4, 6 ) ) break; + pt = strstr( b, ":" ) + 1; + tend = atoi( pt ) - 1; + + while( fgets( b, B-1, fp ) ) + if( !strncmp( "_display_start:", b+4, 15 ) ) break; + pt = strstr( b, ":" ) + 1; + tal_display_start = atoi( pt ) - 1; + + pt = tal; + while( ( c = fgetc( fp ) ) ) + { + if( c == '>' ) + { + ungetc( c, fp ); + break; + } + if( isalpha( c ) || c == '-' ) + *pt++ = c; + } + *pt = 0; + +// fprintf( stderr, "(%d-%d:%d-%d)\n", qstart, qend, tstart, tend ); +// fprintf( stderr, "qal_display_start = %d, tal_display_start = %d\n", qal_display_start, tal_display_start ); + +// fprintf( stderr, "qal = %s\n", qal ); +// fprintf( stderr, "tal = %s\n", tal ); + + qal2 = cutal( qal, qal_display_start, qstart, qend ); + tal2 = cutal( tal, tal_display_start, tstart, tend ); + +// fprintf( stderr, "qal2 = %s\n", qal2 ); +// fprintf( stderr, "tal2 = %s\n", tal2 ); + +// fprintf( stderr, "putting %d - %d, opt = %d\n", qmem, junban[count-1], opt ); + putlocalhom( qal2, tal2, localhomlist+junban[count-1], qstart, tstart, opt, overlapaa ); + } +// fprintf( stderr, "count = %d\n", count ); + return count; +} +int ReadFasta34m10_scoreonly_nucbk( FILE *fp, double *dis, int nin ) +{ + int count=0; + char b[B]; + char *pt; + int pos; + int opt; + double z, bits; + + count = 0; + while( !feof( fp ) ) + { + fgets( b, B-1, fp ); + if( !strncmp( "+===========+", b, 13 ) ) + { + pos = atoi( b+13 ); + + if( strchr( b, 'r' ) ) continue; + +// pt = strchr( b, ')' ) + 1; + pt = strchr( b, ']' ) + 1; + sscanf( pt, "%d %lf %lf", &opt, &bits, &z ); + dis[pos] += (double)opt; + count++; +#if 0 + fprintf( stderr, "b=%s\n", b ); + fprintf( stderr, "opt=%d\n", opt ); + fprintf( stderr, "pos=%d\n", pos ); + fprintf( stderr, "dis[pos]=%f\n", dis[pos] ); +#endif + + } + else if( 0 == strncmp( ">>><<<", b, 6 ) ) + { + break; + } + + } + if( !count ) return -1; + + return count; +} + +int ReadFasta34m10_scoreonly_nuc( FILE *fp, double *dis, int nin ) +{ + int count=0; + char b[B]; + char *pt; + int pos; + int opt; + double z, bits; + int c; + int *yonda; + + + yonda = AllocateIntVec( nin ); + for( c=0; c>>", b, 3 ) ) + { + for( c=0; c>><<<", b, 6 ) ) + { + break; + } + + } + + free( yonda ); + + if( !count ) return -1; + + return count; +} + +int ReadFasta34m10_scoreonly( FILE *fp, double *dis, int nin ) +{ + int count=0; + char b[B]; + char *pt; + int pos; + int opt; + double z, bits; + int c; + int *yonda; + + + yonda = AllocateIntVec( nin ); + for( c=0; c>>", b, 3 ) ) + { + for( c=0; c>><<<", b, 6 ) ) + { + break; + } + + } + + free( yonda ); + + if( !count ) return -1; + + return count; +} +int ReadFasta34( FILE *fp, double *dis, int nseq, char name[M][B], LocalHom *localhomlist ) +{ + int count=0; + char b[B]; + char *pt; + static int junban[M]; + int overlapaa; + int opt, qstart, qend, tstart, tend; + double z, bits; + + + count = 0; +#if 0 + for( i=0; i<10000000 && count>+==========+", b, 14 ) ) + { + break; + } + + } + if( !count ) return -1; + + count = 0; + while( !feof( fp ) ) + { + if( !strncmp(">>+==========+", b, 14 ) ) + { + junban[count] = atoi( b+14 ); + count++; + fgets( b, B-1, fp ); // initn: + pt = strstr( b, "opt: " ) + 5; + localhomlist[junban[count-1]].opt = atof( pt ); + fgets( b, B-1, fp ); // Smith-Waterman score + pt = strstr( b, "ungapped) in " ) + 13; + sscanf( pt, "%d", &overlapaa ); + fprintf( stderr, "pt = %s, overlapaa = %d\n", pt, overlapaa ); + pt = strstr( b, "overlap (" ) + 8; + sscanf( pt, "(%d-%d:%d-%d)", &qstart, &qend, &tstart, &tend ); + localhomlist[junban[count-1]].overlapaa = overlapaa; + localhomlist[junban[count-1]].start1 = qstart-1; + localhomlist[junban[count-1]].end1 = qend-1; + localhomlist[junban[count-1]].start2 = tstart-1; + localhomlist[junban[count-1]].end2 = tend-1; + } + fgets( b, B-1, fp ); + } + fprintf( stderr, "count = %d\n", count ); + return count; +} + +int ReadFasta3( FILE *fp, double *dis, int nseq, char name[M][B] ) +{ + int count=0; + char b[B]; + char *pt; + int junban[M]; + int initn, init1, opt; + double z; + + count = 0; +#if 0 + for( i=0; i<10000000 && count 0 ) + { +#if 0 /* /tmp/pre ???????????????? */ + if( ferror( prep_g ) ) prep_g = fopen( "pre", "w" ); + if( !prep_g ) ErrorExit( "Cannot re-open pre." ); +#endif + rewind( prep_g ); + signalSM[STATUS] = IMA_KAITERU; +#if IODEBUG + if( force ) fprintf( stderr, "FINAL " ); +#endif + if( devide ) dvWrite( prep_g, nseq, name, nlen, aseq ); + else WriteGapFill( prep_g, nseq, name, nlen, aseq ); + /* + fprintf( prep_g, '\EOF' ); + */ + fflush( prep_g ); + if( force ) signalSM[STATUS] = OSHIMAI; + else signalSM[STATUS] = KAKIOWATTA; + value = 1; + signalSM[SEMAPHORE]++; +#if IODEBUG + fprintf( stderr, "signalSM[STATUS] = %c\n", signalSM[STATUS] ); +#endif + break; + } + else + { +#if IODEBUG + fprintf( stderr, "YONDERUKARA_AKIRAMERU\n" ); +#endif + value = 0; + signalSM[SEMAPHORE]++; + if( !force ) break; +#if IODEBUG + fprintf( stderr, "MATSU\n" ); +#endif + sleep( 1 ); + } + } + if( force && !value ) ErrorExit( "xced ga pre wo hanasanai \n" ); + return( value ); +#else + if( force ) + { + rewind( prep_g ); + writeData( prep_g, nseq, name, nlen, aseq ); + } +#endif + return( 0 ); +} + + +void readOtherOptions( int *ppidptr, int *fftThresholdptr, int *fftWinSizeptr ) +{ + if( calledByXced ) + { + FILE *fp = fopen( "pre", "r" ); + char b[B]; + if( !fp ) ErrorExit( "Cannot open pre.\n" ); + fgets( b, B-1, fp ); + sscanf( b, "%d %d %d", ppidptr, fftThresholdptr, fftWinSizeptr ); + fclose( fp ); +#if IODEBUG + fprintf( stderr, "b = %s\n", b ); + fprintf( stderr, "ppid = %d\n", ppid ); + fprintf( stderr, "fftThreshold = %d\n", fftThreshold ); + fprintf( stderr, "fftWinSize = %d\n", fftWinSize ); +#endif + } + else + { + *ppidptr = 0; + *fftThresholdptr = FFT_THRESHOLD; + if( dorp == 'd' ) + *fftWinSizeptr = FFT_WINSIZE_D; + else + *fftWinSizeptr = FFT_WINSIZE_P; + } +#if 0 + fprintf( stderr, "fftThresholdptr=%d\n", *fftThresholdptr ); + fprintf( stderr, "fftWinSizeptr=%d\n", *fftWinSizeptr ); +#endif +} + +void initSignalSM( void ) +{ +// int signalsmid; + +#if IODEBUG + if( ppid ) fprintf( stderr, "PID of xced = %d\n", ppid ); +#endif + if( !ppid ) + { + signalSM = NULL; + return; + } + +#if 0 + signalsmid = shmget( (key_t)ppid, 3, IPC_ALLOC | 0666 ); + if( signalsmid == -1 ) ErrorExit( "Cannot get Shared memory for signal.\n" ); + signalSM = shmat( signalsmid, 0, 0 ); + if( (int)signalSM == -1 ) ErrorExit( "Cannot attatch Shared Memory for signal!\n" ); + signalSM[STATUS] = IMA_KAITERU; + signalSM[SEMAPHORE] = 1; +#endif +} + +void initFiles( void ) +{ + char pname[100]; + if( ppid ) + sprintf( pname, "/tmp/pre.%d", ppid ); + else + sprintf( pname, "pre" ); + prep_g = fopen( pname, "w" ); + if( !prep_g ) ErrorExit( "Cannot open pre" ); + + trap_g = fopen( "trace", "w" ); + if( !trap_g ) ErrorExit( "cannot open trace" ); + fprintf( trap_g, "PID = %d\n", getpid() ); + fflush( trap_g ); +} + + +void WriteForFasta( FILE *fp, int locnjob, char name[][B], int nlen[M], char **aseq ) +{ + static char b[N]; + int i, j; + int nalen[M]; + + for( i=0; i%s\n", name[i] ); + for( j=0; j 0 ) + { + tmpptr1 = localhomtable[i][j].last; +// fprintf( stderr, "reallocating, localhomtable[%d][%d].nokori = %d\n", i, j, localhomtable[i][j].nokori ); + tmpptr1->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); + tmpptr1 = tmpptr1->next; + tmpptr1->extended = -1; + tmpptr1->next = NULL; + localhomtable[i][j].last = tmpptr1; +// fprintf( stderr, "### i,j = %d,%d, nokori=%d\n", i, j, localhomtable[i][j].nokori ); + } + else + { + tmpptr1 = localhomtable[i]+j; +// fprintf( stderr, "### i,j = %d,%d, nokori=%d\n", i, j, localhomtable[i][j].nokori ); + } + + tmpptr1->start1 = start1; + tmpptr1->start2 = start2; + tmpptr1->end1 = end1; + tmpptr1->end2 = end2; +// tmpptr1->opt = ( opt / overlapaa + 0.00 ) / 5.8 * 600; +// tmpptr1->opt = opt; + tmpptr1->opt = ( opt + 0.00 ) / 5.8 * 600; + tmpptr1->overlapaa = overlapaa; + } +// else + { + if( localhomtable[j][i].nokori++ > 0 ) + { + tmpptr2 = localhomtable[j][i].last; + tmpptr2->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); + tmpptr2 = tmpptr2->next; + tmpptr2->extended = -1; + tmpptr2->next = NULL; + localhomtable[j][i].last = tmpptr2; +// fprintf( stderr, "### i,j = %d,%d, nokori=%d\n", j, i, localhomtable[j][i].nokori ); + } + else + { + tmpptr2 = localhomtable[j]+i; +// fprintf( stderr, "### i,j = %d,%d, nokori=%d\n", j, i, localhomtable[j][i].nokori ); + } + + tmpptr2->start2 = start1; + tmpptr2->start1 = start2; + tmpptr2->end2 = end1; + tmpptr2->end1 = end2; +// tmpptr2->opt = ( opt / overlapaa + 0.00 ) / 5.8 * 600; +// tmpptr2->opt = opt; + tmpptr2->opt = ( opt + 0.00 ) / 5.8 * 600; + tmpptr2->overlapaa = overlapaa; + +// fprintf( stderr, "i=%d, j=%d, st1=%d, en1=%d, opt = %f\n", i, j, tmpptr1->start1, tmpptr1->end1, opt ); + } + + } +} +void readlocalhomtable( FILE*fp, int njob, LocalHom **localhomtable ) +{ + double opt; + static char buff[B]; + int i, j, overlapaa, start1, end1, start2, end2; + int **nlocalhom = NULL; + LocalHom *tmpptr1=NULL, *tmpptr2=NULL; // by D.Mathog, a guess + + nlocalhom = AllocateIntMtx( njob, njob ); + for( i=0; i 0 ) + { +// fprintf( stderr, "reallocating, nlocalhom[%d][%d] = %d\n", i, j, nlocalhom[i][j] ); + tmpptr1->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); + tmpptr1 = tmpptr1->next; + tmpptr1->next = NULL; + } + else + { + tmpptr1 = localhomtable[i]+j; +// fprintf( stderr, "nlocalhom[%d][%d] = %d\n", i, j, nlocalhom[i][j] ); + } + + tmpptr1->start1 = start1; + tmpptr1->start2 = start2; + tmpptr1->end1 = end1; + tmpptr1->end2 = end2; +// tmpptr1->opt = ( opt / overlapaa + 0.00 ) / 5.8 * 600; +// tmpptr1->opt = opt; + tmpptr1->opt = ( opt + 0.00 ) / 5.8 * 600; + tmpptr1->overlapaa = overlapaa; + +// fprintf( stderr, "i=%d, j=%d, opt = %f\n", i, j, opt ); + } +// else + { + if( nlocalhom[j][i]++ > 0 ) + { + tmpptr2->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) ); + tmpptr2 = tmpptr2->next; + tmpptr2->next = NULL; + } + else + tmpptr2 = localhomtable[j]+i; + + tmpptr2->start2 = start1; + tmpptr2->start1 = start2; + tmpptr2->end2 = end1; + tmpptr2->end1 = end2; +// tmpptr2->opt = ( opt / overlapaa + 0.00 ) / 5.8 * 600; +// tmpptr2->opt = opt; + tmpptr2->opt = ( opt + 0.00 ) / 5.8 * 600; + tmpptr2->overlapaa = overlapaa; + } + + } + FreeIntMtx( nlocalhom ); +} + +void outlocalhom( LocalHom **localhom, int nseq ) +{ + int i, j; + LocalHom *tmpptr; + for( i=0; istart1, tmpptr->end1, tmpptr->start2, tmpptr->end2, tmpptr->importance, tmpptr->opt ); + } + while( (tmpptr=tmpptr->next) ); + } +} + +void outlocalhompt( LocalHom ***localhom, int n1, int n2 ) +{ + int i, j; + LocalHom *tmpptr; + for( i=0; istart1, tmpptr->end1, tmpptr->start2, tmpptr->end2, tmpptr->importance, tmpptr->opt, tmpptr->wimportance ); + } + while( (tmpptr=tmpptr->next) ); + } +} + +void FreeLocalHomTable( LocalHom **localhomtable, int n ) +{ + int i, j; + LocalHom *ppp, *tmpptr; + fprintf( stderr, "freeing localhom\n" ); + for( i=0; inext; + for( ; tmpptr; tmpptr=ppp ) + { +#if DEBUG + fprintf( stderr, "i=%d, j=%d\n", i, j ); +#endif + ppp = tmpptr->next; + if( tmpptr!=localhomtable[i]+j ) + { +#if DEBUG + fprintf( stderr, "freeing %p\n", tmpptr ); +#endif + free( tmpptr ); + } + } + } +#if DEBUG + fprintf( stderr, "freeing localhomtable[%d]\n", i ); +#endif + free( localhomtable[i] ); + } +#if DEBUG + fprintf( stderr, "freeing localhomtable\n" ); +#endif + free( localhomtable ); +#if DEBUG + fprintf( stderr, "freed\n" ); +#endif +} + +char *progName( char *str ) +{ + char *value; + if( ( value = strrchr( str, '/' ) ) != NULL ) + return( value+1 ); + else + return( str ); +} + +static void tabtospace( char *str ) +{ + char *p; +// fprintf( stderr, "before = %s\n", str ); + while( NULL != ( p = strchr( str , '\t' ) ) ) + { + *p = ' '; + } +// fprintf( stderr, "after = %s\n", str ); +} + +static char *extractfirstword( char *str ) +{ + char *val = str; + + tabtospace( str ); + while( *str ) + { + if( val == str && *str == ' ' ) + { + val++; str++; + } + else if( *str != ' ' ) + { + str++; + } + else if( *str == ' ' ) + { + *str = 0; + } + } + return( val ); +} + + +void clustalout_pointer( FILE *fp, int nseq, int maxlen, char **seq, char **name, char *mark, char *comment, int *order ) +{ + int pos, j; + pos = 0; + if( comment == NULL ) + fprintf( fp, "CLUSTAL format alignment by MAFFT (v%s)\n\n", VERSION ); + else + fprintf( fp, "CLUSTAL format alignment by MAFFT %s (v%s)\n\n", comment, VERSION ); + + while( pos < maxlen ) + { + fprintf( fp, "\n" ); + for( j=0; j%s\n", name[k]+1 ); + for( j=0; j%s\n", name[k]+1 ); + for( j=0; j 19 ) break; + } + + for( i=0; i<20; i++ ) raw[20][i] = -1.0; + while( !feof( mf ) ) + { + fgets( line, 999, mf ); + if( line[0] == 'f' ) + { +// fprintf( stderr, "line = %s\n", line ); + ptr1 = line; + for( j=0; j<20; j++ ) + { + while( !isdigit( *ptr1 ) && *ptr1 != '-' && *ptr1 != '.' ) + ptr1++; + + raw[20][j] = atof( ptr1 ); +// fprintf( stderr, "raw[20][]=%f, %c %d\n", raw[20][j], inorder[i], j ); + ptr1 = strchr( ptr1, ' ' ); + if( ptr1 == NULL && j<19) showaamtxexample(); + } + break; + } + } + + k = 0; + for( i=0; i<20; i++ ) + { + for( j=0; j<=i; j++ ) + { + if( i != j ) + { + ii = MAX( map[i], map[j] ); + jj = MIN( map[i], map[j] ); + } + else ii = jj = map[i]; + val[k++] = raw[ii][jj]; +// fprintf( stderr, "%c-%c, %f\n", aaorder[i], aaorder[j], val[k-1] ); + } + } + for( i=0; i<20; i++ ) val[400+i] = raw[20][map[i]]; + + fprintf( stderr, "inorder = %s\n", inorder ); + fclose( mf ); + free( inorder ); + free( line ); + FreeDoubleMtx( raw ); + free( map ); + return( val ); +} + +void miyataout_reorder_pointer( FILE *fp, int locnjob, int nlenmax, char **name, int *nlen, char **aseq, int *order ) +{ + int i, j, k; + int nalen; + + fprintf( fp, "%5d\n", 1 ); + fprintf( fp, "%5d\n", 1 ); + fprintf( fp, "%5d%5d\n", 1, nlenmax ); + fprintf( fp, "%5d\n", 0 ); + fprintf( fp, "%5d\n", locnjob ); + for( i=0; i' ) + { + break; + } + fgets( gett, 999, fp ); +// fprintf( stderr, "gett = %s\n", gett ); + sscanf( gett, "%d %d %f", &left, &right, &prob ); + + if( left >= length || right >= length ) + { + fprintf( stderr, "format error in hat4\n" ); + exit( 1 ); + } + + if( prob < 0.01 ) continue; // 080607, mafft ni dake eikyou + + if( left != right && prob > 0.0 ) + { + pairprob[left] = (RNApair *)realloc( pairprob[left], (pairnum[left]+2) * sizeof( RNApair ) ); + pairprob[left][pairnum[left]].bestscore = prob; + pairprob[left][pairnum[left]].bestpos = right; + pairnum[left]++; + pairprob[left][pairnum[left]].bestscore = -1.0; + pairprob[left][pairnum[left]].bestpos = -1; +// fprintf( stderr, "%d-%d, %f\n", left, right, prob ); + + pairprob[right] = (RNApair *)realloc( pairprob[right], (pairnum[right]+2) * sizeof( RNApair ) ); + pairprob[right][pairnum[right]].bestscore = prob; + pairprob[right][pairnum[right]].bestpos = left; + pairnum[right]++; + pairprob[right][pairnum[right]].bestscore = -1.0; + pairprob[right][pairnum[right]].bestpos = -1; +// fprintf( stderr, "%d-%d, %f\n", right, left, prob ); + } + } + free( pairnum ); +} + +void readpairfoldalign( FILE *fp, char *s1, char *s2, char *aln1, char *aln2, int q1, int q2, int *of1, int *of2, int sumlen ) +{ + char gett[1000]; + int *maptoseq1; + int *maptoseq2; + char dumc; + int dumi; + char sinseq[100], sinaln[100]; + int posinseq, posinaln; + int alnlen; + int i; + int pos1, pos2; + char *pa1, *pa2; + char qstr[1000]; + + *of1 = -1; + *of2 = -1; + + maptoseq1 = AllocateIntVec( sumlen+1 ); + maptoseq2 = AllocateIntVec( sumlen+1 ); + + posinaln = 0; // foldalign ga alingment wo kaesanaitok no tame. + + while( !feof( fp ) ) + { + fgets( gett, 999, fp ); + if( !strncmp( gett, "; ALIGNING", 10 ) ) break; + } + sprintf( qstr, "; ALIGNING %d against %d\n", q1+1, q2+1 ); + if( strcmp( gett, qstr ) ) + { + fprintf( stderr, "Error in FOLDALIGN\n" ); + fprintf( stderr, "qstr = %s, but gett = %s\n", qstr, gett ); + exit( 1 ); + } + + while( !feof( fp ) ) + { + fgets( gett, 999, fp ); + if( !strncmp( gett, "; --------", 10 ) ) break; + } + + + while( !feof( fp ) ) + { + fgets( gett, 999, fp ); + if( !strncmp( gett, "; ********", 10 ) ) break; +// fprintf( stderr, "gett = %s\n", gett ); + sscanf( gett, "%c %c %s %s %d %d", &dumc, &dumc, sinseq, sinaln, &dumi, &dumi ); + posinaln = atoi( sinaln ); + posinseq = atoi( sinseq ); +// fprintf( stderr, "posinseq = %d\n", posinseq ); +// fprintf( stderr, "posinaln = %d\n", posinaln ); + maptoseq1[posinaln-1] = posinseq-1; + } + alnlen = posinaln; + + while( !feof( fp ) ) + { + fgets( gett, 999, fp ); + if( !strncmp( gett, "; --------", 10 ) ) break; + } + + while( !feof( fp ) ) + { + fgets( gett, 999, fp ); + if( !strncmp( gett, "; ********", 10 ) ) break; +// fprintf( stderr, "gett = %s\n", gett ); + sscanf( gett, "%c %c %s %s %d %d", &dumc, &dumc, sinseq, sinaln, &dumi, &dumi ); + posinaln = atof( sinaln ); + posinseq = atof( sinseq ); +// fprintf( stderr, "posinseq = %d\n", posinseq ); +// fprintf( stderr, "posinaln = %d\n", posinaln ); + maptoseq2[posinaln-1] = posinseq-1; + } + if( alnlen != posinaln ) + { + fprintf( stderr, "Error in foldalign?\n" ); + exit( 1 ); + } + + pa1 = aln1; + pa2 = aln2; + for( i=0; i -1 ) + *pa1++ = s1[pos1]; + else + *pa1++ = '-'; + + if( pos2 > -1 ) + *pa2++ = s2[pos2]; + else + *pa2++ = '-'; + } + *pa1 = 0; + *pa2 = 0; + + *of1 = 0; + for( i=0; i -1 ) break; + } + *of2 = 0; + for( i=0; i -1 ) break; + } + +// fprintf( stderr, "*of1=%d, aln1 = :%s:\n", *of1, aln1 ); +// fprintf( stderr, "*of2=%d, aln2 = :%s:\n", *of2, aln2 ); + + free( maptoseq1 ); + free( maptoseq2 ); +} Added: test-suite/trunk/MultiSource/Benchmarks/mafft/license URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/license?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/license (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/license Thu Feb 19 06:37:59 2009 @@ -0,0 +1,48 @@ +============================================================ + +If you have the './extensions' directory, please also see +license.extensions file. + +============================================================ + +The codes in the './core' directory is distributed with +the BSD license. + +MAFFT: multiple sequence alignment program +Copyright (c) 2007 Kazutaka Katoh + +Redistribution and use in source and binary forms, +with or without modification, are permitted provided +that the following conditions are met: + +Redistributions of source code must retain the +above copyright notice, this list of conditions +and the following disclaimer. Redistributions in +binary form must reproduce the above copyright +notice, this list of conditions and the following +disclaimer in the documentation and/or other +materials provided with the distribution. + +The name of the author may not be used to endorse +or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +OF SUCH DAMAGE. +--------------------------------------------------------------------------------- + + + Added: test-suite/trunk/MultiSource/Benchmarks/mafft/miyata.h URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/miyata.h?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/miyata.h (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/miyata.h Thu Feb 19 06:37:59 2009 @@ -0,0 +1,47 @@ +double polarity_[] = +{ + 8.1, /* A */ + 10.5, /* R */ + 11.6, /* N */ + 13.0, /* D */ + 5.5, /* C */ + 10.5, /* Q */ + 12.3, /* E */ + 9.0, /* G */ + 10.4, /* H */ + 5.2, /* I */ + 4.9, /* L */ + 11.3, /* K */ + 5.7, /* M */ + 5.2, /* F */ + 8.0, /* P */ + 9.2, /* S */ + 8.6, /* T */ + 5.4, /* W */ + 6.2, /* Y */ + 5.9, /* V */ +}; + +double volume_[] = +{ + 31.0, /* A */ + 124.0, /* R */ + 56.0, /* N */ + 54.0, /* D */ + 55.0, /* C */ + 85.0, /* Q */ + 83.0, /* E */ + 3.0, /* G */ + 96.0, /* H */ + 111.0, /* I */ + 111.0, /* L */ + 119.0, /* K */ + 105.0, /* M */ + 132.0, /* F */ + 32.5, /* P */ + 32.0, /* S */ + 61.0, /* T */ + 170.0, /* W */ + 136.0, /* Y */ + 84.0, /* V */ +}; Added: test-suite/trunk/MultiSource/Benchmarks/mafft/miyata5.h URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/mafft/miyata5.h?rev=65043&view=auto ============================================================================== --- test-suite/trunk/MultiSource/Benchmarks/mafft/miyata5.h (added) +++ test-suite/trunk/MultiSource/Benchmarks/mafft/miyata5.h Thu Feb 19 06:37:59 2009 @@ -0,0 +1,166 @@ +int locpenaltym = -1440; +int exgpm = +0; /* != 0 nisuruto kowareru. exgp ha constants.c de kurikomu */ +char locaminom[] = "ARNDCQEGHILKMFPSTWYVBZX.-U"; +char locgrpm[] = +{ + 0, 3, 2, 2, 5, 2, 2, 0, 3, 1, 1, 3, 1, 4, 0, 0, 0, 4, 4, 1, 2, 2, + 6, 6, 6, 6, +}; +int locn_dism[26][26] = + { + { + 600, -235, 91, -78, 202, 51, -103, 340, -21, -169, + -189, -246, -92, -323, 582, 454, 342, -400, -309, 71, + 7, -26, -15, -400, 0,-1400, + }, + + { + -235, 600, 17, -69, -275, 277, 185, -400, 365, -112, + -149, 485, -55, -106, -229, -183, 20, -178, 22, -95, + -26, 231, -15, -400, 0,-1400, + }, + + { + 91, 17, 600, 414, -209, 317, 357, 39, 231, -363, + -398, 74, -280, -400, 85, 225, 200, -400, -378, -189, + 507, 337, -15, -400, 0,-1400, + }, + + { + -78, -69, 414, 600, -395, 179, 342, -78, 108, -400, + -400, 14, -400, -400, -86, 65, 14, -400, -400, -372, + 507, 261, -15, -400, 0,-1400, + }, + + { + 202, -275, -209, -395, 600, -109, -332, -35, -132, 134, + 128, -335, 182, -40, 220, 74, 185, -355, -81, 354, + -302, -220, -15, -400, 0,-1400, + }, + + { + 51, 277, 317, 179, -109, 600, 360, -109, 508, -135, + -172, 297, -58, -203, 51, 128, 280, -378, -109, -9, + 248, 480, -15, -400, 0,-1400, + }, + + { + -103, 185, 357, 342, -332, 360, 600, -195, 325, -369, + -400, 274, -295, -400, -109, 11, 77, -400, -321, -249, + 350, 480, -15, -400, 0,-1400, + }, + + { + 340, -400, 39, -78, -35, -109, -195, 600, -195, -400, + -400, -400, -355, -400, 322, 357, 114, -400, -400, -189, + -19, -152, -15, -400, 0,-1400, + }, + + { + -21, 365, 231, 108, -132, 508, 325, -195, 600, -100, + -141, 374, -26, -152, -15, 45, 222, -303, -49, -3, + 169, 417, -15, -400, 0,-1400, + }, + + { + -169, -112, -363, -400, 134, -135, -369, -400, -100, 600, + 560, -212, 517, 425, -149, -243, -12, 108, 354, 357, + -400, -252, -15, -400, 0,-1400, + }, + + { + -189, -149, -398, -400, 128, -172, -400, -400, -141, 560, + 600, -252, 482, 420, -172, -269, -43, 105, 331, 340, + -400, -290, -15, -400, 0,-1400, + }, + + { + -246, 485, 74, 14, -335, 297, 274, -400, 374, -212, + -252, 600, -152, -215, -240, -175, -1, -289, -92, -172, + 44, 285, -15, -400, 0,-1400, + }, + + { + -92, -55, -280, -400, 182, -58, -295, -355, -26, 517, + 482, -152, 600, 365, -75, -163, 68, 59, 334, 422, + -368, -176, -15, -400, 0,-1400, + }, + + { + -323, -106, -400, -400, -40, -203, -400, -400, -152, 425, + 420, -215, 365, 600, -306, -386, -143, 282, 462, 191, + -400, -315, -15, -400, 0,-1400, + }, + + { + 582, -229, 85, -86, 220, 51, -109, 322, -15, -149, + -172, -240, -75, -306, 600, 440, 351, -400, -292, 88, + 0, -29, -15, -400, 0,-1400, + }, + + { + 454, -183, 225, 65, 74, 128, 11, 357, 45, -243, + -269, -175, -163, -386, 440, 600, 345, -400, -352, -15, + 145, 70, -15, -400, 0,-1400, + }, + + { + 342, 20, 200, 14, 185, 280, 77, 114, 222, -12, + -43, -1, 68, -143, 351, 345, 600, -400, -100, 194, + 107, 178, -15, -400, 0,-1400, + }, + + { + -400, -178, -400, -400, -355, -378, -400, -400, -303, 108, + 105, -289, 59, 282, -400, -400, -400, 600, 297, -118, + -400, -400, -15, -400, 0,-1400, + }, + + { + -309, 22, -378, -400, -81, -109, -321, -400, -49, 354, + 331, -92, 334, 462, -292, -352, -100, 297, 600, 165, + -400, -215, -15, -400, 0,-1400, + }, + + { + 71, -95, -189, -372, 354, -9, -249, -189, -3, 357, + 340, -172, 422, 191, 88, -15, 194, -118, 165, 600, + -280, -129, -15, -400, 0,-1400, + }, + + { + 7, -26, 507, 507, -302, 248, 350, -19, 169, -400, + -400, 44, -368, -400, 0, 145, 107, -400, -400, -280, + 507, 299, -400, -400, 0,-1400, + }, + + { + -26, 231, 337, 261, -220, 480, 480, -152, 417, -252, + -290, 285, -176, -315, -29, 70, 178, -400, -215, -129, + 299, 480, -400, -400, 0,-1400, + }, + + { + -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, + -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, + -400, -400, -400, -400, 0,-1400, + }, + + { + -400, -400, -400, -400, -400, -400, -400, -400, -400, -400