[llvm-commits] [llvm-gcc-4-2] r39869 - /llvm-gcc-4-2/trunk/gcc/tree.h
Author: baldrick Date: Sun Jul 15 06:55:54 2007 New Revision: 39869 URL: http://llvm.org/viewvc/llvm-project?rev=39869&view=rev Log: Check correctness of using decl_with_rtl in LLVM constructs. Modified: llvm-gcc-4-2/trunk/gcc/tree.h Modified: llvm-gcc-4-2/trunk/gcc/tree.h URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/gcc/tree.h?rev=39869&r1=39868&r2=39869&view=diff == --- llvm-gcc-4-2/trunk/gcc/tree.h (original) +++ llvm-gcc-4-2/trunk/gcc/tree.h Sun Jul 15 06:55:54 2007 @@ -2831,8 +2831,9 @@ #endif #define SET_DECL_LLVM(NODE, LLVM) (llvm_set_decl (NODE,LLVM)) -#define SET_DECL_LLVM_INDEX(NODE, INDEX) ((NODE)->decl_with_rtl.llvm = INDEX) -#define GET_DECL_LLVM_INDEX(NODE) ((NODE)->decl_with_rtl.llvm) +#define SET_DECL_LLVM_INDEX(NODE, INDEX) \ + (DECL_WRTL_CHECK(NODE)->decl_with_rtl.llvm = INDEX) +#define GET_DECL_LLVM_INDEX(NODE) (DECL_WRTL_CHECK(NODE)->decl_with_rtl.llvm) /* Returns nonzero if the DECL_LLVM for NODE has already been set. */ extern bool llvm_set_decl_p(tree); @@ -2840,7 +2841,8 @@ /* Copy the LLVM from NODE1 to NODE2. If the LLVM was not set for NODE1, it will not be set for NODE2; this is a lazy copy. */ #define COPY_DECL_LLVM(NODE1, NODE2) \ - ((NODE2)->decl_with_rtl.llvm = (NODE1)->decl_with_rtl.llvm) + (DECL_WRTL_CHECK(NODE2)->decl_with_rtl.llvm = \ + DECL_WRTL_CHECK(NODE1)->decl_with_rtl.llvm) /* The DECL_LLVM for NODE, if it is set, or NULL, if it is not set. */ #define DECL_LLVM_IF_SET(NODE) \ (DECL_LLVM_SET_P (NODE) ? DECL_LLVM (NODE) : NULL) ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm-gcc-4-2] r39870 - /llvm-gcc-4-2/trunk/gcc/varasm.c
Author: baldrick Date: Sun Jul 15 06:58:12 2007 New Revision: 39870 URL: http://llvm.org/viewvc/llvm-project?rev=39870&view=rev Log: Move RTL checks inside ifndef ENABLE_LLVM. Restore some logic from llvm-gcc-4.0 that got lost. Modified: llvm-gcc-4-2/trunk/gcc/varasm.c Modified: llvm-gcc-4-2/trunk/gcc/varasm.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/gcc/varasm.c?rev=39870&r1=39869&r2=39870&view=diff == --- llvm-gcc-4-2/trunk/gcc/varasm.c (original) +++ llvm-gcc-4-2/trunk/gcc/varasm.c Sun Jul 15 06:58:12 2007 @@ -1861,10 +1861,10 @@ return; } - gcc_assert (MEM_P (decl_rtl)); - gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF); /* LLVM LOCAL begin */ #ifndef ENABLE_LLVM /* register globals are not supported */ + gcc_assert (MEM_P (decl_rtl)); + gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF); symbol = XEXP (decl_rtl, 0); name = XSTR (symbol, 0); #else @@ -1876,6 +1876,16 @@ /* Compute the alignment of this data. */ align_variable (decl, dont_output_data); + /* LLVM LOCAL begin */ +#ifdef ENABLE_LLVM + if (dont_output_data) { +fprintf(stderr, "LLVM must emit the data!"); +abort(); + } + emit_global_to_llvm(decl); + return; +#endif + /* LLVM LOCAL end */ set_mem_align (decl_rtl, DECL_ALIGN (decl)); if (TREE_PUBLIC (decl)) @@ -5111,7 +5121,7 @@ } #endif } -/* LLVM LCOAL */ +/* LLVM LOCAL */ #endif /* First pass of completing pending aliases. Make sure that cgraph knows ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm-gcc-4-2] r39871 - in /llvm-gcc-4-2/trunk/gcc: bt-load.c c-common.c llvm-backend.cpp
Author: baldrick Date: Sun Jul 15 07:02:31 2007 New Revision: 39871 URL: http://llvm.org/viewvc/llvm-project?rev=39871&view=rev Log: Fix a bunch of small problems noticed by the compiler. Modified: llvm-gcc-4-2/trunk/gcc/bt-load.c llvm-gcc-4-2/trunk/gcc/c-common.c llvm-gcc-4-2/trunk/gcc/llvm-backend.cpp Modified: llvm-gcc-4-2/trunk/gcc/bt-load.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/gcc/bt-load.c?rev=39871&r1=39870&r2=39871&view=diff == --- llvm-gcc-4-2/trunk/gcc/bt-load.c (original) +++ llvm-gcc-4-2/trunk/gcc/bt-load.c Sun Jul 15 07:02:31 2007 @@ -1506,7 +1506,7 @@ static int warned = 0; /* LLVM LOCAL begin - reduce cc1 size. */ #ifdef ENABLE_LLVM - return; + return 0; #endif /* LLVM LOCAL end. */ /* Leave this a warning for now so that it is possible to experiment Modified: llvm-gcc-4-2/trunk/gcc/c-common.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/gcc/c-common.c?rev=39871&r1=39870&r2=39871&view=diff == --- llvm-gcc-4-2/trunk/gcc/c-common.c (original) +++ llvm-gcc-4-2/trunk/gcc/c-common.c Sun Jul 15 07:02:31 2007 @@ -6057,7 +6057,7 @@ } else { -warning ("%qs attribute ignored", IDENTIFIER_POINTER (name)); +warning (0, "%qs attribute ignored", IDENTIFIER_POINTER (name)); *no_add_attrs = true; } 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=39871&r1=39870&r2=39871&view=diff == --- llvm-gcc-4-2/trunk/gcc/llvm-backend.cpp (original) +++ llvm-gcc-4-2/trunk/gcc/llvm-backend.cpp Sun Jul 15 07:02:31 2007 @@ -619,8 +619,7 @@ } if (!Aliasee) { - error ("%J%qD aliased to undefined symbol %qE", - decl, decl, target); + error ("%J%qD aliased to undefined symbol %qs", decl, decl, AliaseeName); timevar_pop(TV_LLVM_GLOBALS); return; } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm-gcc-4-2] r39872 - /llvm-gcc-4-2/trunk/gcc/langhooks-def.h
Author: baldrick Date: Sun Jul 15 07:04:54 2007 New Revision: 39872 URL: http://llvm.org/viewvc/llvm-project?rev=39872&view=rev Log: Fix misplaced langhook initializer. Apple people take note: you may want to fix this in your own gcc 4.2 tree. Modified: llvm-gcc-4-2/trunk/gcc/langhooks-def.h Modified: llvm-gcc-4-2/trunk/gcc/langhooks-def.h URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/gcc/langhooks-def.h?rev=39872&r1=39871&r2=39872&view=diff == --- llvm-gcc-4-2/trunk/gcc/langhooks-def.h (original) +++ llvm-gcc-4-2/trunk/gcc/langhooks-def.h Sun Jul 15 07:04:54 2007 @@ -337,10 +337,10 @@ LANG_HOOKS_GIMPLIFY_EXPR, \ LANG_HOOKS_FOLD_OBJ_TYPE_REF, \ LANG_HOOKS_BUILTIN_FUNCTION, \ -/* APPLE LOCAL define this sensibly for all languages */ \ - LANG_HOOKS_FLAG_NO_BUILTIN, \ LANG_HOOKS_INIT_TS, \ LANG_HOOKS_EXPR_TO_DECL, \ +/* APPLE LOCAL define this sensibly for all languages */ \ + LANG_HOOKS_FLAG_NO_BUILTIN, \ } #endif /* GCC_LANG_HOOKS_DEF_H */ ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm-gcc-4-2] r39873 - /llvm-gcc-4-2/trunk/gcc/passes.c
Author: asl Date: Sun Jul 15 08:53:47 2007 New Revision: 39873 URL: http://llvm.org/viewvc/llvm-project?rev=39873&view=rev Log: Propagate missed patch from llvm-gcc-4.0 Modified: llvm-gcc-4-2/trunk/gcc/passes.c Modified: llvm-gcc-4-2/trunk/gcc/passes.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/gcc/passes.c?rev=39873&r1=39872&r2=39873&view=diff == --- llvm-gcc-4-2/trunk/gcc/passes.c (original) +++ llvm-gcc-4-2/trunk/gcc/passes.c Sun Jul 15 08:53:47 2007 @@ -473,6 +473,12 @@ { struct tree_opt_pass **p; +/* LLVM LOCAL begin - Reduce cc1 size with dead code stripping. */ +#ifdef ENABLE_LLVM + return; +#endif +/* LLVM LOCAL end */ + #define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS)) /* Interprocedural optimization passes. */ p = &all_ipa_passes; ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm-gcc-4-2] r39874 - in /llvm-gcc-4-2/trunk/gcc: llvm-backend.cpp passes.c tree-optimize.c
Author: asl Date: Sun Jul 15 10:55:06 2007 New Revision: 39874 URL: http://llvm.org/viewvc/llvm-project?rev=39874&view=rev Log: My last commit is wrong. gcc internals changed dramatically since 4.01. Now we have 'cfg gimple' as input for llvm-convert, not just 'gimple'. Fix the code by cfg traversal. Big thanks for Andrew Pinski for noting this. Modified: llvm-gcc-4-2/trunk/gcc/llvm-backend.cpp llvm-gcc-4-2/trunk/gcc/passes.c llvm-gcc-4-2/trunk/gcc/tree-optimize.c 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=39874&r1=39873&r2=39874&view=diff == --- llvm-gcc-4-2/trunk/gcc/llvm-backend.cpp (original) +++ llvm-gcc-4-2/trunk/gcc/llvm-backend.cpp Sun Jul 15 10:55:06 2007 @@ -66,6 +66,7 @@ #include "function.h" #include "tree-inline.h" #include "langhooks.h" +#include "cgraph.h" } // Non-zero if bytecode from PCH is successfully read. @@ -556,10 +557,12 @@ // Set up parameters and prepare for return, for the function. Emitter.StartFunctionBody(); - -// Emit the body of the function. -Emitter.Emit(DECL_SAVED_TREE(fndecl), 0); - + +// Emit the body of the function iterating over all BBs +basic_block bb; +FOR_EACH_BB_FN (bb, DECL_STRUCT_FUNCTION (fndecl)) + Emitter.Emit(bb->stmt_list, 0); + // Wrap things up. Fn = Emitter.FinishFunctionBody(); } Modified: llvm-gcc-4-2/trunk/gcc/passes.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/gcc/passes.c?rev=39874&r1=39873&r2=39874&view=diff == --- llvm-gcc-4-2/trunk/gcc/passes.c (original) +++ llvm-gcc-4-2/trunk/gcc/passes.c Sun Jul 15 10:55:06 2007 @@ -473,12 +473,6 @@ { struct tree_opt_pass **p; -/* LLVM LOCAL begin - Reduce cc1 size with dead code stripping. */ -#ifdef ENABLE_LLVM - return; -#endif -/* LLVM LOCAL end */ - #define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS)) /* Interprocedural optimization passes. */ p = &all_ipa_passes; 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=39874&r1=39873&r2=39874&view=diff == --- llvm-gcc-4-2/trunk/gcc/tree-optimize.c (original) +++ llvm-gcc-4-2/trunk/gcc/tree-optimize.c Sun Jul 15 10:55:06 2007 @@ -49,8 +49,9 @@ #include "graph.h" /* APPLE LOCAL optimization pragmas 3124235/3420242 */ #include "opts.h" -/* LLVM LOCAL */ +/* LLVM LOCAL begin */ #include "llvm.h" +/* LLVM LOCAL end */ #include "cfgloop.h" #include "except.h" ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm-gcc-4-2] r39875 - /llvm-gcc-4-2/trunk/gcc/llvm-backend.cpp
Author: asl Date: Sun Jul 15 11:04:59 2007 New Revision: 39875 URL: http://llvm.org/viewvc/llvm-project?rev=39875&view=rev Log: Use more sane way to emit a function: per statement. 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=39875&r1=39874&r2=39875&view=diff == --- llvm-gcc-4-2/trunk/gcc/llvm-backend.cpp (original) +++ llvm-gcc-4-2/trunk/gcc/llvm-backend.cpp Sun Jul 15 11:04:59 2007 @@ -64,6 +64,7 @@ #include "timevar.h" #include "tm.h" #include "function.h" +#include "tree-flow.h" #include "tree-inline.h" #include "langhooks.h" #include "cgraph.h" @@ -561,7 +562,9 @@ // Emit the body of the function iterating over all BBs basic_block bb; FOR_EACH_BB_FN (bb, DECL_STRUCT_FUNCTION (fndecl)) - Emitter.Emit(bb->stmt_list, 0); + for (block_stmt_iterator bsi = bsi_start (bb); + !bsi_end_p (bsi); bsi_next (&bsi)) +Emitter.Emit(bsi_stmt (bsi), 0); // Wrap things up. Fn = Emitter.FinishFunctionBody(); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm-gcc-4-2] r39876 - /llvm-gcc-4-2/trunk/gcc/varasm.c
Author: asl Date: Sun Jul 15 11:20:19 2007 New Revision: 39876 URL: http://llvm.org/viewvc/llvm-project?rev=39876&view=rev Log: Disable two new rtl-related hooks Modified: llvm-gcc-4-2/trunk/gcc/varasm.c Modified: llvm-gcc-4-2/trunk/gcc/varasm.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/gcc/varasm.c?rev=39876&r1=39875&r2=39876&view=diff == --- llvm-gcc-4-2/trunk/gcc/varasm.c (original) +++ llvm-gcc-4-2/trunk/gcc/varasm.c Sun Jul 15 11:20:19 2007 @@ -53,8 +53,9 @@ #include "cgraph.h" #include "cfglayout.h" #include "basic-block.h" -/* LLVM LOCAL */ +/* LLVM LOCAL begin */ #include "llvm.h" +/* LLVM LOCAL end */ #ifdef XCOFF_DEBUGGING_INFO #include "xcoffout.h" /* Needed for external data @@ -3705,7 +3706,11 @@ void output_shared_constant_pool (void) { + /* LLVM LOCAL begin */ +#ifndef ENABLE_LLVM output_constant_pool_contents (shared_constant_pool); +#endif + /* LLVM LOCAL end */ } /* Determine what kind of relocations EXP may need. */ @@ -6455,7 +6460,11 @@ void output_object_blocks (void) { + /* LLVM LOCAL begin */ +#ifndef ENABLE_LLVM htab_traverse (object_block_htab, output_object_block_htab, NULL); +#endif + /* LLVM LOCAL end */ } #include "gt-varasm.h" ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm-gcc-4-2] r39877 - /llvm-gcc-4-2/trunk/gcc/tree.h
Author: baldrick Date: Sun Jul 15 12:02:38 2007 New Revision: 39877 URL: http://llvm.org/viewvc/llvm-project?rev=39877&view=rev Log: Condition DECL_LLVM_SET_P on HAS_RTL_P, as in DECL_RTL_SET_P. This makes print-tree work in the presence of FIELD_DECLs which can no longer hold RTL. Modified: llvm-gcc-4-2/trunk/gcc/tree.h Modified: llvm-gcc-4-2/trunk/gcc/tree.h URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/gcc/tree.h?rev=39877&r1=39876&r2=39877&view=diff == --- llvm-gcc-4-2/trunk/gcc/tree.h (original) +++ llvm-gcc-4-2/trunk/gcc/tree.h Sun Jul 15 12:02:38 2007 @@ -2837,7 +2837,7 @@ /* Returns nonzero if the DECL_LLVM for NODE has already been set. */ extern bool llvm_set_decl_p(tree); -#define DECL_LLVM_SET_P(NODE) (llvm_set_decl_p(NODE)) +#define DECL_LLVM_SET_P(NODE) (HAS_RTL_P (NODE) && llvm_set_decl_p(NODE)) /* Copy the LLVM from NODE1 to NODE2. If the LLVM was not set for NODE1, it will not be set for NODE2; this is a lazy copy. */ #define COPY_DECL_LLVM(NODE1, NODE2) \ ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
Re: [llvm-commits] [129555] Implement missing dwarf builtins, used by the libstdc++ unwinder.
Can you please also apply it on the 4.2 branch. I would do it myself but it hasn't turned up in the mirror yet (which is strange - maybe something is wrong with the mirror?), and I think you changed it a bit compared to the version in bugzilla. Thanks, Duncan. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm-gcc-4-2] r39878 - in /llvm-gcc-4-2/trunk/gcc: llvm-convert.cpp llvm-internal.h llvm-types.cpp
Author: baldrick Date: Sun Jul 15 12:58:07 2007 New Revision: 39878 URL: http://llvm.org/viewvc/llvm-project?rev=39878&view=rev Log: We used to stash the index of the LLVM field corresponding to a FIELD_DECL directly in the field declaration. But the place we would store it doesn't exist in gcc 4.2, so use (yet another) map instead. Modified: llvm-gcc-4-2/trunk/gcc/llvm-convert.cpp llvm-gcc-4-2/trunk/gcc/llvm-internal.h llvm-gcc-4-2/trunk/gcc/llvm-types.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=39878&r1=39877&r2=39878&view=diff == --- llvm-gcc-4-2/trunk/gcc/llvm-convert.cpp (original) +++ llvm-gcc-4-2/trunk/gcc/llvm-convert.cpp Sun Jul 15 12:58:07 2007 @@ -4928,15 +4928,15 @@ tree field_offset = component_ref_field_offset (exp); // If this is a normal field at a fixed offset from the start, handle it. if (TREE_CODE(field_offset) == INTEGER_CST) { -assert(DECL_LLVM_SET_P(FieldDecl) && "Struct not laid out for LLVM?"); -ConstantInt *CI = cast(DECL_LLVM(FieldDecl)); -uint32_t MemberIndex = CI->getZExtValue(); +unsigned int MemberIndex = TheTypeConverter->GetFieldIndex(FieldDecl); +assert(MemberIndex != ~0U && "Struct not laid out for LLVM?"); assert(MemberIndex < StructTy->getNumContainedTypes() && "Field Idx out of range!"); FieldPtr = Builder.CreateGEP(StructAddrLV.Ptr, - Constant::getNullValue(Type::Int32Ty), CI, + Constant::getNullValue(Type::Int32Ty), + ConstantInt::get(Type::Int32Ty, MemberIndex), "tmp"); - + // Now that we did an offset from the start of the struct, subtract off // the offset from BitStart. if (MemberIndex) { @@ -5630,7 +5630,7 @@ // that contains bits from the bitfield overlayed with the declared type of // the bitfield. This bitfield value may be spread across multiple fields, or // it may be just this field, or it may just be a small part of this field. - unsigned FieldNo = cast(DECL_LLVM(Field))->getZExtValue(); + unsigned int FieldNo = TheTypeConverter->GetFieldIndex(Field); assert(FieldNo < ResultElts.size() && "Invalid struct field number!"); // Get the offset and size of the LLVM field. @@ -5768,8 +5768,8 @@ ProcessBitFieldInitialization(Field, Val, STy, ResultElts); } else { // If not, things are much simpler. - assert(DECL_LLVM_SET_P(Field) && "Struct not laid out for LLVM?"); - unsigned FieldNo = cast(DECL_LLVM(Field))->getZExtValue(); + unsigned int FieldNo = TheTypeConverter->GetFieldIndex(Field); + assert(FieldNo != ~0U && "Struct not laid out for LLVM?"); assert(FieldNo < ResultElts.size() && "Invalid struct field number!"); // Example: struct X { int A; char C[]; } x = { 4, "foo" }; @@ -6002,13 +6002,12 @@ tree field_offset = component_ref_field_offset (exp); // If this is a normal field at a fixed offset from the start, handle it. if (TREE_CODE(field_offset) == INTEGER_CST) { -assert(DECL_LLVM_SET_P(FieldDecl) && "Struct not laid out for LLVM?"); -ConstantInt *CI = cast(DECL_LLVM(FieldDecl)); -uint64_t MemberIndex = CI->getZExtValue(); +unsigned int MemberIndex = TheTypeConverter->GetFieldIndex(FieldDecl); +assert(MemberIndex != ~0U && "Struct not laid out for LLVM?"); std::vector Idxs; Idxs.push_back(Constant::getNullValue(Type::Int32Ty)); -Idxs.push_back(CI); +Idxs.push_back(ConstantInt::get(Type::Int32Ty, MemberIndex)); FieldPtr = ConstantExpr::getGetElementPtr(StructAddrLV, &Idxs[0], Idxs.size()); 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=39878&r1=39877&r2=39878&view=diff == --- llvm-gcc-4-2/trunk/gcc/llvm-internal.h (original) +++ llvm-gcc-4-2/trunk/gcc/llvm-internal.h Sun Jul 15 12:58:07 2007 @@ -124,11 +124,20 @@ /// POINTER_TYPE to this list. /// std::vector PointersToReresolve; + + /// FieldIndexMap - Holds the mapping from a FIELD_DECL to the index of the + /// corresponding LLVM field. + std::map FieldIndexMap; public: TypeConverter() : ConvertingStruct(false) {} const Type *ConvertType(tree_node *type); - + + /// GetFieldIndex - Returns the index of the LLVM field corresponding to + /// this FIELD_DECL, or ~0U if the type the field belongs to has not yet + /// been converted. + unsigned int GetFieldIndex(tree_node *field_decl); + /// GCCTypeOverlapsWithLLVMTypePadding - Return true if the specified GCC type /// has any data that overlaps with structure padding in the specified LLVM /
[llvm-commits] [llvm] r39879 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/shift-simplify.ll
Author: lattner Date: Sun Jul 15 15:42:37 2007 New Revision: 39879 URL: http://llvm.org/viewvc/llvm-project?rev=39879&view=rev Log: Implement shift-simplify.ll:test3, turning: (X << 31) (X&1) != 0 This happens dozens of times in the CFE. Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp llvm/trunk/test/Transforms/InstCombine/shift-simplify.ll Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=39879&r1=39878&r2=39879&view=diff == --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Sun Jul 15 15:42:37 2007 @@ -2271,26 +2271,21 @@ return 0; } -/// isSignBitCheck - Given an exploded icmp instruction, return true if it -/// really just returns true if the most significant (sign) bit is set. -static bool isSignBitCheck(ICmpInst::Predicate pred, ConstantInt *RHS) { +/// isSignBitCheck - Given an exploded icmp instruction, return true if the +/// comparison only checks the sign bit. If it only checks the sign bit, set +/// TrueIfSigned if the result of the comparison is true when the input value is +/// signed. +static bool isSignBitCheck(ICmpInst::Predicate pred, ConstantInt *RHS, + bool &TrueIfSigned) { switch (pred) { -case ICmpInst::ICMP_SLT: - // True if LHS s< RHS and RHS == 0 - return RHS->isZero(); -case ICmpInst::ICMP_SLE: - // True if LHS s<= RHS and RHS == -1 - return RHS->isAllOnesValue(); -case ICmpInst::ICMP_UGE: - // True if LHS u>= RHS and RHS == high-bit-mask (2^7, 2^15, 2^31, etc) - return RHS->getValue() == - APInt::getSignBit(RHS->getType()->getPrimitiveSizeInBits()); -case ICmpInst::ICMP_UGT: - // True if LHS u> RHS and RHS == high-bit-mask - 1 - return RHS->getValue() == - APInt::getSignedMaxValue(RHS->getType()->getPrimitiveSizeInBits()); -default: - return false; + case ICmpInst::ICMP_SLT: // True if LHS s< 0 +TrueIfSigned = true; +return RHS->isZero(); + case ICmpInst::ICMP_SGT: // True if LHS s> -1 +TrueIfSigned = false; +return RHS->isAllOnesValue(); + default: +return false; } } @@ -2377,11 +2372,13 @@ if (ICmpInst *SCI = dyn_cast(BoolCast->getOperand(0))) { Value *SCIOp0 = SCI->getOperand(0), *SCIOp1 = SCI->getOperand(1); const Type *SCOpTy = SCIOp0->getType(); - + bool TIS = false; + // If the icmp is true iff the sign bit of X is set, then convert this // multiply into a shift/and combination. if (isa(SCIOp1) && - isSignBitCheck(SCI->getPredicate(), cast(SCIOp1))) { + isSignBitCheck(SCI->getPredicate(), cast(SCIOp1), TIS) && + TIS) { // Shift the X value right to turn it into "all signbits". Constant *Amt = ConstantInt::get(SCIOp0->getType(), SCOpTy->getPrimitiveSizeInBits()-1); @@ -2805,23 +2802,19 @@ // isMaxValueMinusOne - return true if this is Max-1 static bool isMaxValueMinusOne(const ConstantInt *C, bool isSigned) { uint32_t TypeBits = C->getType()->getPrimitiveSizeInBits(); - if (isSigned) { -// Calculate 01..1 -APInt Val(APInt::getSignedMaxValue(TypeBits)); -return C->getValue() == Val-1; - } - return C->getValue() == APInt::getAllOnesValue(TypeBits) - 1; + if (!isSigned) +return C->getValue() == APInt::getAllOnesValue(TypeBits) - 1; + return C->getValue() == APInt::getSignedMaxValue(TypeBits)-1; } // isMinValuePlusOne - return true if this is Min+1 static bool isMinValuePlusOne(const ConstantInt *C, bool isSigned) { - if (isSigned) { -// Calculate 11 -uint32_t TypeBits = C->getType()->getPrimitiveSizeInBits(); -APInt Val(APInt::getSignedMinValue(TypeBits)); -return C->getValue() == Val+1; - } - return C->getValue() == 1; // unsigned + if (!isSigned) +return C->getValue() == 1; // unsigned + + // Calculate 11 + uint32_t TypeBits = C->getType()->getPrimitiveSizeInBits(); + return C->getValue() == APInt::getSignedMinValue(TypeBits)+1; } // isOneBitSet - Return true if there is exactly one bit set in the specified @@ -5415,85 +5408,105 @@ } break; - case Instruction::Shl: // (icmp pred (shl X, ShAmt), CI) -if (ConstantInt *ShAmt = dyn_cast(LHSI->getOperand(1))) { - if (ICI.isEquality()) { -uint32_t TypeBits = RHSV.getBitWidth(); - -// Check that the shift amount is in range. If not, don't perform -// undefined shifts. When the shift is visited it will be -// simplified. -if (ShAmt->uge(TypeBits)) - break; - -// If we are comparing against bits always
[llvm-commits] [llvm] r39880 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/shift-simplify.ll
Author: lattner Date: Sun Jul 15 15:54:51 2007 New Revision: 39880 URL: http://llvm.org/viewvc/llvm-project?rev=39880&view=rev Log: Implement shift-simplify.ll:test[45]. First teach instcombine that sign bit checks only demand the sign bit, this allows simplify demanded bits to hack on expressions better. Second, teach instcombine that ashr is useless if only the sign bit is demanded. Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp llvm/trunk/test/Transforms/InstCombine/shift-simplify.ll Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=39880&r1=39879&r2=39880&view=diff == --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Sun Jul 15 15:54:51 2007 @@ -1342,6 +1342,11 @@ InsertNewInstBefore(cast(NewVal), *I); return UpdateValueUsesWith(I, NewVal); } + +// If the sign bit is the only bit demanded by this ashr, then there is no +// need to do it, the shift doesn't change the high bit. +if (DemandedMask.isSignBit()) + return UpdateValueUsesWith(I, I->getOperand(0)); if (ConstantInt *SA = dyn_cast(I->getOperand(1))) { uint32_t ShiftAmt = SA->getLimitedValue(BitWidth); @@ -4841,22 +4846,29 @@ // already been handled above, this requires little checking. // switch (I.getPredicate()) { - default: break; - case ICmpInst::ICMP_ULE: -return new ICmpInst(ICmpInst::ICMP_ULT, Op0, AddOne(CI)); - case ICmpInst::ICMP_SLE: -return new ICmpInst(ICmpInst::ICMP_SLT, Op0, AddOne(CI)); - case ICmpInst::ICMP_UGE: -return new ICmpInst( ICmpInst::ICMP_UGT, Op0, SubOne(CI)); - case ICmpInst::ICMP_SGE: -return new ICmpInst(ICmpInst::ICMP_SGT, Op0, SubOne(CI)); +default: break; +case ICmpInst::ICMP_ULE: + return new ICmpInst(ICmpInst::ICMP_ULT, Op0, AddOne(CI)); +case ICmpInst::ICMP_SLE: + return new ICmpInst(ICmpInst::ICMP_SLT, Op0, AddOne(CI)); +case ICmpInst::ICMP_UGE: + return new ICmpInst( ICmpInst::ICMP_UGT, Op0, SubOne(CI)); +case ICmpInst::ICMP_SGE: + return new ICmpInst(ICmpInst::ICMP_SGT, Op0, SubOne(CI)); } // See if we can fold the comparison based on bits known to be zero or one -// in the input. +// in the input. If this comparison is a normal comparison, it demands all +// bits, if it is a sign bit comparison, it only demands the sign bit. + +bool UnusedBit; +bool isSignBit = isSignBitCheck(I.getPredicate(), CI, UnusedBit); + uint32_t BitWidth = cast(Ty)->getBitWidth(); APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0); -if (SimplifyDemandedBits(Op0, APInt::getAllOnesValue(BitWidth), +if (SimplifyDemandedBits(Op0, + isSignBit ? APInt::getSignBit(BitWidth) + : APInt::getAllOnesValue(BitWidth), KnownZero, KnownOne, 0)) return &I; Modified: llvm/trunk/test/Transforms/InstCombine/shift-simplify.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/shift-simplify.ll?rev=39880&r1=39879&r2=39880&view=diff == --- llvm/trunk/test/Transforms/InstCombine/shift-simplify.ll (original) +++ llvm/trunk/test/Transforms/InstCombine/shift-simplify.ll Sun Jul 15 15:54:51 2007 @@ -28,3 +28,15 @@ ret i1 %tmp2 } +define i1 @test4(i32 %X) { +%tmp1 = lshr i32 %X, 7 +%tmp2 = icmp slt i32 %tmp1, 0 +ret i1 %tmp2 +} + +define i1 @test5(i32 %X) { +%tmp1 = ashr i32 %X, 7 +%tmp2 = icmp slt i32 %tmp1, 0 +ret i1 %tmp2 +} + ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm-gcc-4-2] r39881 - in /llvm-gcc-4-2/trunk/gcc: fold-const.c llvm-convert.cpp tree-inline.c tree.c varasm.c
Author: asl Date: Sun Jul 15 16:57:06 2007 New Revision: 39881 URL: http://llvm.org/viewvc/llvm-project?rev=39881&view=rev Log: Another bunch of fixes here and there. Modified: llvm-gcc-4-2/trunk/gcc/fold-const.c llvm-gcc-4-2/trunk/gcc/llvm-convert.cpp llvm-gcc-4-2/trunk/gcc/tree-inline.c llvm-gcc-4-2/trunk/gcc/tree.c llvm-gcc-4-2/trunk/gcc/varasm.c Modified: llvm-gcc-4-2/trunk/gcc/fold-const.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/gcc/fold-const.c?rev=39881&r1=39880&r2=39881&view=diff == --- llvm-gcc-4-2/trunk/gcc/fold-const.c (original) +++ llvm-gcc-4-2/trunk/gcc/fold-const.c Sun Jul 15 16:57:06 2007 @@ -12935,7 +12935,14 @@ { if ((TREE_CODE (exp) == INDIRECT_REF || TREE_CODE (exp) == ARRAY_REF) - && TREE_CODE (TREE_TYPE (exp)) == INTEGER_TYPE) + && TREE_CODE (TREE_TYPE (exp)) == INTEGER_TYPE && +/* LLVM LOCAL begin */ +#if ENABLE_LLVM +/* LLVM extends ARRAY_REF to allow pointers to be the base value. */ + (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == ARRAY_TYPE) +#endif +/* LLVM LOCAL end */ +) { tree exp1 = TREE_OPERAND (exp, 0); tree index; 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=39881&r1=39880&r2=39881&view=diff == --- llvm-gcc-4-2/trunk/gcc/llvm-convert.cpp (original) +++ llvm-gcc-4-2/trunk/gcc/llvm-convert.cpp Sun Jul 15 16:57:06 2007 @@ -676,8 +676,8 @@ // As it turns out, not all temporaries are associated with blocks. For those // that aren't, emit them now. for (tree t = cfun->unexpanded_var_list; t; t = TREE_CHAIN(t)) { -assert(!DECL_LLVM_SET_P(TREE_VALUE(t)) && "var already emitted?"); -EmitAutomaticVariableDecl(TREE_VALUE(t)); +if (!DECL_LLVM_SET_P(TREE_VALUE(t))) + EmitAutomaticVariableDecl(TREE_VALUE(t)); } // Create a new block for the return node, but don't insert it yet. 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=39881&r1=39880&r2=39881&view=diff == --- llvm-gcc-4-2/trunk/gcc/tree-inline.c (original) +++ llvm-gcc-4-2/trunk/gcc/tree-inline.c Sun Jul 15 16:57:06 2007 @@ -2633,7 +2633,13 @@ /* The new variable/label has no RTL, yet. */ if (CODE_CONTAINS_STRUCT (TREE_CODE (copy), TS_DECL_WRTL) && !TREE_STATIC (copy) && !DECL_EXTERNAL (copy)) -SET_DECL_RTL (copy, NULL_RTX); + /* LLVM LOCAL begin */ +#ifdef ENABLE_LLVM +SET_DECL_LLVM (copy, 0); +#else +SET_DECL_RTL (copy, NULL_RTX); +#endif + /* LLVM_LOCAL end */ /* These args would always appear unused, if not for this. */ TREE_USED (copy) = 1; @@ -2823,6 +2829,8 @@ /* Generate a new name for the new version. */ if (!update_clones) DECL_NAME (new_decl) = create_tmp_var_name (NULL); + /* LLVM LOCAL begin */ + #ifndef ENABLE_LLVM /* Create a new SYMBOL_REF rtx for the new name. */ if (DECL_RTL (old_decl) != NULL) { @@ -2831,7 +2839,9 @@ gen_rtx_SYMBOL_REF (GET_MODE (XEXP (DECL_RTL (old_decl), 0)), IDENTIFIER_POINTER (DECL_NAME (new_decl))); } - + #endif + /* LLVM LOCAL end */ + /* Prepare the data structures for the tree copy. */ memset (&id, 0, sizeof (id)); Modified: llvm-gcc-4-2/trunk/gcc/tree.c URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/gcc/tree.c?rev=39881&r1=39880&r2=39881&view=diff == --- llvm-gcc-4-2/trunk/gcc/tree.c (original) +++ llvm-gcc-4-2/trunk/gcc/tree.c Sun Jul 15 16:57:06 2007 @@ -7067,6 +7067,14 @@ if (TREE_CODE (idx) != INTEGER_CST) return false; + /* LLVM LOCAL begin */ +#if ENABLE_LLVM +/* LLVM extends ARRAY_REF to allow pointers to be the base value. */ + if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) != ARRAY_TYPE) +return false; +#endif + /* LLVM LOCAL end */ + min = array_ref_low_bound (ref); max = array_ref_up_bound (ref); if (!min @@ -7089,6 +7097,15 @@ bool range_in_array_bounds_p (tree ref) { + /* LLVM LOCAL begin */ +#if ENABLE_LLVM +/* LLVM extends ARRAY_REF to allow pointers to be the base value. */ + if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) != ARRAY_TYPE) +return false; + else { +#endif + /* LLVM LOCAL end */ + tree domain_type = TYPE_DOMAIN (TREE_TYPE (ref)); tree range_min, range_max, min, max; @@ -7113,6 +7130,11 @@ return false; return true; + /* LLVM LOCAL begin */ +#if ENABLE_LLVM + } +#endif + /* LLVM LOCAL end */ } /* Return true if T (assumed to be a DECL) is a global variable. */ Modified: llvm-gcc-4-2/trunk/gcc/varasm.c URL: h
[llvm-commits] [129557] implement test/CFrontend/exact-div-expr.c by compiling
Revision: 129557 Author: clattner Date: 2007-07-15 15:30:12 -0700 (Sun, 15 Jul 2007) Log Message: --- implement test/CFrontend/exact-div-expr.c by compiling a pointer difference into a shift, instead of a divide. This was actually a feature of llvm-gcc3 that was never reimplemented in llvm-gcc4. This commonly occurs in C++ code that is using iterators. Modified Paths: -- apple-local/branches/llvm/gcc/llvm-convert.cpp apple-local/branches/llvm/gcc/llvm-internal.h Modified: apple-local/branches/llvm/gcc/llvm-convert.cpp === --- apple-local/branches/llvm/gcc/llvm-convert.cpp 2007-07-14 18:57:56 UTC (rev 129556) +++ apple-local/branches/llvm/gcc/llvm-convert.cpp 2007-07-15 22:30:12 UTC (rev 129557) @@ -865,8 +865,8 @@ case PLUS_EXPR: Result = EmitBinOp(exp, DestLoc, Instruction::Add);break; case MINUS_EXPR:Result = EmitBinOp(exp, DestLoc, Instruction::Sub);break; case MULT_EXPR: Result = EmitBinOp(exp, DestLoc, Instruction::Mul);break; + case EXACT_DIV_EXPR: Result = EmitEXACT_DIV_EXPR(exp, DestLoc); break; case TRUNC_DIV_EXPR: - case EXACT_DIV_EXPR: // TODO: Optimize EXACT_DIV_EXPR. if (TYPE_UNSIGNED(TREE_TYPE(exp))) Result = EmitBinOp(exp, DestLoc, Instruction::UDiv); else @@ -3314,6 +3314,29 @@ TREE_CODE(exp) == MAX_EXPR ? "max" : "min"); } +Value *TreeToLLVM::EmitEXACT_DIV_EXPR(tree exp, Value *DestLoc) { + // Unsigned EXACT_DIV_EXPR -> normal udiv. + if (TYPE_UNSIGNED(TREE_TYPE(exp))) +return EmitBinOp(exp, DestLoc, Instruction::UDiv); + + // If this is a signed EXACT_DIV_EXPR by a constant, and we know that + // the RHS is a multiple of two, we strength reduce the result to use + // a signed SHR here. We have no way in LLVM to represent EXACT_DIV_EXPR + // precisely, so this transform can't currently be performed at the LLVM + // level. This is commonly used for pointer subtraction. + if (TREE_CODE(TREE_OPERAND(exp, 1)) == INTEGER_CST) { +uint64_t IntValue = getINTEGER_CSTVal(TREE_OPERAND(exp, 1)); +if (isPowerOf2_64(IntValue)) { + // Create an ashr instruction, by the log of the division amount. + Value *LHS = Emit(TREE_OPERAND(exp, 0), 0); + return Builder.CreateAShr(LHS, ConstantInt::get(LHS->getType(), + Log2_64(IntValue)),"tmp"); +} + } + + // Otherwise, emit this as a normal signed divide. + return EmitBinOp(exp, DestLoc, Instruction::SDiv); +} Value *TreeToLLVM::EmitFLOOR_MOD_EXPR(tree exp, Value *DestLoc) { // Notation: FLOOR_MOD_EXPR <-> Mod, TRUNC_MOD_EXPR <-> Rem. Modified: apple-local/branches/llvm/gcc/llvm-internal.h === --- apple-local/branches/llvm/gcc/llvm-internal.h 2007-07-14 18:57:56 UTC (rev 129556) +++ apple-local/branches/llvm/gcc/llvm-internal.h 2007-07-15 22:30:12 UTC (rev 129557) @@ -511,6 +511,7 @@ Value *EmitABS_EXPR(tree_node *exp); Value *EmitBIT_NOT_EXPR(tree_node *exp); Value *EmitTRUTH_NOT_EXPR(tree_node *exp); + Value *EmitEXACT_DIV_EXPR(tree_node *exp, Value *DestLoc); Value *EmitCompare(tree_node *exp, unsigned UIPred, unsigned SIPred, unsigned FPOpc); Value *EmitBinOp(tree_node *exp, Value *DestLoc, unsigned Opc); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm] r39882 - /llvm/trunk/test/CFrontend/exact-div-expr.c
Author: lattner Date: Sun Jul 15 17:30:34 2007 New Revision: 39882 URL: http://llvm.org/viewvc/llvm-project?rev=39882&view=rev Log: new testcase Added: llvm/trunk/test/CFrontend/exact-div-expr.c Added: llvm/trunk/test/CFrontend/exact-div-expr.c URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CFrontend/exact-div-expr.c?rev=39882&view=auto == --- llvm/trunk/test/CFrontend/exact-div-expr.c (added) +++ llvm/trunk/test/CFrontend/exact-div-expr.c Sun Jul 15 17:30:34 2007 @@ -0,0 +1,6 @@ +// RUN: %llvmgcc -S %s -o - -O | grep ashr +// RUN: %llvmgcc -S %s -o - -O | not grep sdiv + +int test(int *A, int *B) { + return A-B; +} ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm-gcc-4-2] r39883 - in /llvm-gcc-4-2/trunk/gcc: llvm-convert.cpp llvm-internal.h
Author: lattner Date: Sun Jul 15 17:53:54 2007 New Revision: 39883 URL: http://llvm.org/viewvc/llvm-project?rev=39883&view=rev Log: implement test/CFrontend/exact-div-expr.c by compiling a pointer difference into a shift, instead of a divide. This was actually a feature of llvm-gcc3 that was never reimplemented in llvm-gcc4. This commonly occurs in C++ code that is using iterators. Modified: 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-convert.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/gcc/llvm-convert.cpp?rev=39883&r1=39882&r2=39883&view=diff == --- llvm-gcc-4-2/trunk/gcc/llvm-convert.cpp (original) +++ llvm-gcc-4-2/trunk/gcc/llvm-convert.cpp Sun Jul 15 17:53:54 2007 @@ -864,8 +864,8 @@ case PLUS_EXPR: Result = EmitBinOp(exp, DestLoc, Instruction::Add);break; case MINUS_EXPR:Result = EmitBinOp(exp, DestLoc, Instruction::Sub);break; case MULT_EXPR: Result = EmitBinOp(exp, DestLoc, Instruction::Mul);break; + case EXACT_DIV_EXPR: Result = EmitEXACT_DIV_EXPR(exp, DestLoc); break; case TRUNC_DIV_EXPR: - case EXACT_DIV_EXPR: // TODO: Optimize EXACT_DIV_EXPR. if (TYPE_UNSIGNED(TREE_TYPE(exp))) Result = EmitBinOp(exp, DestLoc, Instruction::UDiv); else @@ -3313,6 +3313,29 @@ TREE_CODE(exp) == MAX_EXPR ? "max" : "min"); } +Value *TreeToLLVM::EmitEXACT_DIV_EXPR(tree exp, Value *DestLoc) { + // Unsigned EXACT_DIV_EXPR -> normal udiv. + if (TYPE_UNSIGNED(TREE_TYPE(exp))) +return EmitBinOp(exp, DestLoc, Instruction::UDiv); + + // If this is a signed EXACT_DIV_EXPR by a constant, and we know that + // the RHS is a multiple of two, we strength reduce the result to use + // a signed SHR here. We have no way in LLVM to represent EXACT_DIV_EXPR + // precisely, so this transform can't currently be performed at the LLVM + // level. This is commonly used for pointer subtraction. + if (TREE_CODE(TREE_OPERAND(exp, 1)) == INTEGER_CST) { +uint64_t IntValue = getINTEGER_CSTVal(TREE_OPERAND(exp, 1)); +if (isPowerOf2_64(IntValue)) { + // Create an ashr instruction, by the log of the division amount. + Value *LHS = Emit(TREE_OPERAND(exp, 0), 0); + return Builder.CreateAShr(LHS, ConstantInt::get(LHS->getType(), + Log2_64(IntValue)),"tmp"); +} + } + + // Otherwise, emit this as a normal signed divide. + return EmitBinOp(exp, DestLoc, Instruction::SDiv); +} Value *TreeToLLVM::EmitFLOOR_MOD_EXPR(tree exp, Value *DestLoc) { // Notation: FLOOR_MOD_EXPR <-> Mod, TRUNC_MOD_EXPR <-> Rem. 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=39883&r1=39882&r2=39883&view=diff == --- llvm-gcc-4-2/trunk/gcc/llvm-internal.h (original) +++ llvm-gcc-4-2/trunk/gcc/llvm-internal.h Sun Jul 15 17:53:54 2007 @@ -521,6 +521,7 @@ Value *EmitABS_EXPR(tree_node *exp); Value *EmitBIT_NOT_EXPR(tree_node *exp); Value *EmitTRUTH_NOT_EXPR(tree_node *exp); + Value *EmitEXACT_DIV_EXPR(tree_node *exp, Value *DestLoc); Value *EmitCompare(tree_node *exp, unsigned UIPred, unsigned SIPred, unsigned FPOpc); Value *EmitBinOp(tree_node *exp, Value *DestLoc, unsigned Opc); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm] r39885 - /llvm/trunk/include/llvm/ADT/APSInt.h
Author: lattner Date: Sun Jul 15 18:32:03 2007 New Revision: 39885 URL: http://llvm.org/viewvc/llvm-project?rev=39885&view=rev Log: add a helper method. 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=39885&r1=39884&r2=39885&view=diff == --- llvm/trunk/include/llvm/ADT/APSInt.h (original) +++ llvm/trunk/include/llvm/ADT/APSInt.h Sun Jul 15 18:32:03 2007 @@ -50,6 +50,7 @@ bool isSigned() const { return !IsUnsigned; } bool isUnsigned() const { return IsUnsigned; } void setIsUnsigned(bool Val) { IsUnsigned = Val; } + void setIsSigned(bool Val) { IsUnsigned = !Val; } const APSInt &operator%=(const APSInt &RHS) { ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm] r39893 - in /llvm/trunk: include/llvm/Analysis/ScalarEvolutionExpressions.h lib/Analysis/ScalarEvolution.cpp test/Analysis/ScalarEvolution/2007-07-15-NegativeStride.ll
Author: nicholas Date: Sun Jul 15 21:08:00 2007 New Revision: 39893 URL: http://llvm.org/viewvc/llvm-project?rev=39893&view=rev Log: Handle decrementing loops properly. Fixes PR1533. Always pass the constant as the second parameter to HowManyLessThans. Remove obsolete "isSigned" parameter. Added: llvm/trunk/test/Analysis/ScalarEvolution/2007-07-15-NegativeStride.ll Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h llvm/trunk/lib/Analysis/ScalarEvolution.cpp Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h?rev=39893&r1=39892&r2=39893&view=diff == --- llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h (original) +++ llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h Sun Jul 15 21:08:00 2007 @@ -475,10 +475,8 @@ /// looking at this is that it returns the first iteration number where the /// value is not in the condition, thus computing the exit count. If the /// iteration count can't be computed, an instance of SCEVCouldNotCompute is -/// returned. The isSigned parameter indicates whether the ConstantRange -/// should be treated as signed or unsigned. -SCEVHandle getNumIterationsInRange(ConstantRange Range, - bool isSigned) const; +/// returned. +SCEVHandle getNumIterationsInRange(ConstantRange Range) const; SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym, const SCEVHandle &Conc) const; Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=39893&r1=39892&r2=39893&view=diff == --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original) +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Sun Jul 15 21:08:00 2007 @@ -1671,8 +1671,7 @@ ConstantRange CompRange( ICmpInst::makeConstantRange(Cond, CompVal->getValue())); - SCEVHandle Ret = AddRec->getNumIterationsInRange(CompRange, - false /*Always treat as unsigned range*/); + SCEVHandle Ret = AddRec->getNumIterationsInRange(CompRange); if (!isa(Ret)) return Ret; } } @@ -1696,7 +1695,8 @@ break; } case ICmpInst::ICMP_SGT: { -SCEVHandle TC = HowManyLessThans(RHS, LHS, L); +SCEVHandle TC = HowManyLessThans(SCEV::getNegativeSCEV(LHS), + SCEV::getNegativeSCEV(RHS), L); if (!isa(TC)) return TC; break; } @@ -2406,8 +2406,7 @@ /// this is that it returns the first iteration number where the value is not in /// the condition, thus computing the exit count. If the iteration count can't /// be computed, an instance of SCEVCouldNotCompute is returned. -SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range, - bool isSigned) const { +SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range) const { if (Range.isFullSet()) // Infinite loop. return new SCEVCouldNotCompute(); @@ -2419,7 +2418,7 @@ SCEVHandle Shifted = SCEVAddRecExpr::get(Operands, getLoop()); if (SCEVAddRecExpr *ShiftedAddRec = dyn_cast(Shifted)) return ShiftedAddRec->getNumIterationsInRange( - Range.subtract(SC->getValue()->getValue()),isSigned); + Range.subtract(SC->getValue()->getValue())); // This is strange and shouldn't happen. return new SCEVCouldNotCompute(); } @@ -2443,17 +2442,16 @@ // If this is an affine expression then we have this situation: // Solve {0,+,A} in Range === Ax in Range -// Since we know that zero is in the range, we know that the upper value of -// the range must be the first possible exit value. Also note that we -// already checked for a full range. -const APInt &Upper = Range.getUpper(); -APInt A = cast(getOperand(1))->getValue()->getValue(); +// We know that zero is in the range. If A is positive then we know that +// the upper value of the range must be the first possible exit value. +// If A is negative then the lower of the range is the last possible loop +// value. Also note that we already checked for a full range. APInt One(getBitWidth(),1); +APInt A = cast(getOperand(1))->getValue()->getValue(); +APInt End = A.sge(One) ? (Range.getUpper() - One) : Range.getLower(); -// The exit value should be (Upper+A-1)/A. -APInt ExitVal(Upper); -if (A != One) - ExitVal = (Upper + A - One).sdiv(A); +// The exit value should be (End+A)/A. +APInt ExitVal = (End + A).sdiv(A); Con
[llvm-commits] [llvm] r39894 - /llvm/trunk/lib/Transforms/Scalar/PredicateSimplifier.cpp
Author: nicholas Date: Sun Jul 15 21:58:37 2007 New Revision: 39894 URL: http://llvm.org/viewvc/llvm-project?rev=39894&view=rev Log: Start adding and cleaning up comments. Modified: llvm/trunk/lib/Transforms/Scalar/PredicateSimplifier.cpp Modified: llvm/trunk/lib/Transforms/Scalar/PredicateSimplifier.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/PredicateSimplifier.cpp?rev=39894&r1=39893&r2=39894&view=diff == --- llvm/trunk/lib/Transforms/Scalar/PredicateSimplifier.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/PredicateSimplifier.cpp Sun Jul 15 21:58:37 2007 @@ -212,13 +212,19 @@ } } +/// getRootNode - This returns the entry node for the CFG of the function. Node *getRootNode() const { return Entry; } +/// getNodeForBlock - return the node for the specified basic block. Node *getNodeForBlock(BasicBlock *BB) const { if (!NodeMap.count(BB)) return 0; return const_cast(this)->NodeMap[BB]; } +/// dominates - returns true if the basic block for I1 dominates that of +/// the basic block for I2. If the instructions belong to the same basic +/// block, the instruction first instruction sequentially in the block is +/// considered dominating. bool dominates(Instruction *I1, Instruction *I2) { BasicBlock *BB1 = I1->getParent(), *BB2 = I2->getParent(); @@ -240,7 +246,10 @@ return Node1 && Node2 && Node1->dominates(Node2); } } + private: +/// renumber - calculates the depth first search numberings and applies +/// them onto the nodes. void renumber() { std::stack > S; unsigned n = 0; @@ -2234,11 +2243,11 @@ } private: -/// Forwards - Adds new properties into PropertySet and uses them to +/// Forwards - Adds new properties to VRPSolver and uses them to /// simplify instructions. Because new properties sometimes apply to /// a transition from one BasicBlock to another, this will use the /// PredicateSimplifier::proceedToSuccessor(s) interface to enter the -/// basic block with the new PropertySet. +/// basic block. /// @brief Performs abstract execution of the program. class VISIBILITY_HIDDEN Forwards : public InstVisitor { friend class InstVisitor; @@ -2294,8 +2303,7 @@ } } -// Tries to simplify each Instruction and add new properties to -// the PropertySet. +// Tries to simplify each Instruction and add new properties. void visitInstruction(Instruction *I, DomTreeDFS::Node *DT) { DOUT << "Considering instruction " << *I << "\n"; DEBUG(VN->dump()); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm] r39895 - /llvm/trunk/test/Transforms/InstCombine/mul.ll
Author: lattner Date: Sun Jul 15 23:09:00 2007 New Revision: 39895 URL: http://llvm.org/viewvc/llvm-project?rev=39895&view=rev Log: rename function to avoid llvm-upgrade warning Modified: llvm/trunk/test/Transforms/InstCombine/mul.ll Modified: llvm/trunk/test/Transforms/InstCombine/mul.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/mul.ll?rev=39895&r1=39894&r2=39895&view=diff == --- llvm/trunk/test/Transforms/InstCombine/mul.ll (original) +++ llvm/trunk/test/Transforms/InstCombine/mul.ll Sun Jul 15 23:09:00 2007 @@ -65,7 +65,7 @@ ret uint %e } -uint %test11(ubyte %a, uint %b) { +uint %test12(ubyte %a, uint %b) { %c = setgt ubyte %a, 127 %d = cast bool %c to uint %e = mul uint %d, %b ; e = b & (a >> 31) ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] [llvm] r39896 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Author: lattner Date: Sun Jul 15 23:15:34 2007 New Revision: 39896 URL: http://llvm.org/viewvc/llvm-project?rev=39896&view=rev Log: Repair a regression in Transforms/InstCombine/mul.ll that Reid noticed. 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=39896&r1=39895&r2=39896&view=diff == --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Sun Jul 15 23:15:34 2007 @@ -2286,9 +2286,22 @@ case ICmpInst::ICMP_SLT: // True if LHS s< 0 TrueIfSigned = true; return RHS->isZero(); + case ICmpInst::ICMP_SLE: // True if LHS s<= RHS and RHS == -1 +TrueIfSigned = true; +return RHS->isAllOnesValue(); case ICmpInst::ICMP_SGT: // True if LHS s> -1 TrueIfSigned = false; return RHS->isAllOnesValue(); + case ICmpInst::ICMP_UGT: +// True if LHS u> RHS and RHS == high-bit-mask - 1 +TrueIfSigned = true; +return RHS->getValue() == + APInt::getSignedMaxValue(RHS->getType()->getPrimitiveSizeInBits()); + case ICmpInst::ICMP_UGE: +// True if LHS u>= RHS and RHS == high-bit-mask (2^7, 2^15, 2^31, etc) +TrueIfSigned = true; +return RHS->getValue() == + APInt::getSignBit(RHS->getType()->getPrimitiveSizeInBits()); default: return false; } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits