[llvm-commits] [129555] Implement missing dwarf builtins, used by the libstdc++ unwinder.

2007-07-14 Thread clattner
Revision: 129555
Author:   clattner
Date: 2007-07-14 11:39:13 -0700 (Sat, 14 Jul 2007)

Log Message:
---
Implement missing dwarf builtins, used by the libstdc++ unwinder.
This is more or less workable on x86-32/linux only

Patch by Anton Korobeynikov

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 07:20:19 UTC 
(rev 129554)
+++ apple-local/branches/llvm/gcc/llvm-convert.cpp  2007-07-14 18:39:13 UTC 
(rev 129555)
@@ -59,8 +59,10 @@
 #include "target.h"
 #include "hard-reg-set.h"
 #include "except.h"
+#include "rtl.h"
 extern bool tree_could_throw_p(tree);  // tree-flow.h uses non-C++ C 
constructs.
 extern int get_pointer_alignment (tree exp, unsigned int max_align);
+extern enum machine_mode reg_raw_mode[FIRST_PSEUDO_REGISTER];
 }
 
 #define ITANIUM_STYLE_EXCEPTIONS
@@ -4140,7 +4142,25 @@
return EmitBuiltinExtractReturnAddr(exp, Result);
   case BUILT_IN_FROB_RETURN_ADDR:
return EmitBuiltinFrobReturnAddr(exp, Result);
-
+
+  // Builtins used by the exception handling runtime.
+  case BUILT_IN_DWARF_CFA:
+return EmitBuiltinDwarfCFA(exp, Result);
+#ifdef DWARF2_UNWIND_INFO
+  case BUILT_IN_DWARF_SP_COLUMN:
+return EmitBuiltinDwarfSPColumn(exp, Result);
+  case BUILT_IN_INIT_DWARF_REG_SIZES:
+return EmitBuiltinInitDwarfRegSizes(exp, Result);
+#endif
+  case BUILT_IN_EH_RETURN:
+return EmitBuiltinEHReturn(exp, Result);
+#ifdef EH_RETURN_DATA_REGNO
+  case BUILT_IN_EH_RETURN_DATA_REGNO:
+return EmitBuiltinEHReturnDataRegno(exp, Result);
+#endif
+  case BUILT_IN_UNWIND_INIT:
+return EmitBuiltinUnwindInit(exp, Result);
+
 #define HANDLE_UNARY_FP(F32, F64, V) \
 Result = EmitBuiltinUnaryFPOp(V, Intrinsic::F32, Intrinsic::F64)
 
@@ -4216,19 +4236,8 @@
 case BUILT_IN_LONGJMP:
 case BUILT_IN_UPDATE_SETJMP_BUF:
 case BUILT_IN_TRAP:
-  
-  // Various hooks for the DWARF 2 __throw routine.
-case BUILT_IN_UNWIND_INIT:
-case BUILT_IN_DWARF_CFA:
-#ifdef DWARF2_UNWIND_INFO
-case BUILT_IN_DWARF_SP_COLUMN:
-case BUILT_IN_INIT_DWARF_REG_SIZES:
-#endif
-case BUILT_IN_EH_RETURN:
-#ifdef EH_RETURN_DATA_REGNO
-case BUILT_IN_EH_RETURN_DATA_REGNO:
-#endif
-  // FIXME: HACK: Just ignore these.
+
+// FIXME: HACK: Just ignore these.
 {
   const Type *Ty = ConvertType(TREE_TYPE(exp));
   if (Ty != Type::VoidTy)
@@ -4509,6 +4518,171 @@
   return true;
 }
 
+
+// Builtins used by the exception handling runtime.
+
+// On most machines, the CFA coincides with the first incoming parm.
+#ifndef ARG_POINTER_CFA_OFFSET
+#define ARG_POINTER_CFA_OFFSET(FNDECL) FIRST_PARM_OFFSET (FNDECL)
+#endif
+
+// The mapping from gcc register number to DWARF 2 CFA column number.  By
+// default, we just provide columns for all registers.
+#ifndef DWARF_FRAME_REGNUM
+#define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
+#endif
+
+// Map register numbers held in the call frame info that gcc has
+// collected using DWARF_FRAME_REGNUM to those that should be output in
+// .debug_frame and .eh_frame.
+#ifndef DWARF2_FRAME_REG_OUT
+#define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
+#endif
+
+/* Registers that get partially clobbered by a call in a given mode.
+   These must not be call used registers.  */
+#ifndef HARD_REGNO_CALL_PART_CLOBBERED
+#define HARD_REGNO_CALL_PART_CLOBBERED(REGNO, MODE) 0
+#endif
+
+bool TreeToLLVM::EmitBuiltinDwarfCFA(tree exp, Value *&Result) {
+  if (!validate_arglist(TREE_OPERAND(exp, 1), VOID_TYPE))
+return false;
+
+  int cfa_offset = ARG_POINTER_CFA_OFFSET(0);
+
+  Result = Builder.CreateCall(Intrinsic::getDeclaration(TheModule,
+  Intrinsic::eh_dwarf_cfa),
+  ConstantInt::get(Type::Int32Ty, cfa_offset));
+
+  return true;
+}
+
+bool TreeToLLVM::EmitBuiltinDwarfSPColumn(tree exp, Value *&Result) {
+  if (!validate_arglist(TREE_OPERAND(exp, 1), VOID_TYPE))
+return false;
+
+  unsigned int dwarf_regnum = DWARF_FRAME_REGNUM(STACK_POINTER_REGNUM);
+  Result = ConstantInt::get(ConvertType(TREE_TYPE(exp)), dwarf_regnum);
+
+  return true;
+}
+
+bool TreeToLLVM::EmitBuiltinEHReturnDataRegno(tree exp, Value *&Result) {
+  tree arglist = TREE_OPERAND(exp, 1);
+
+  if (!validate_arglist(arglist, INTEGER_TYPE, VOID_TYPE))
+return false;
+
+  tree which = TREE_VALUE (arglist);
+  unsigned HOST_WIDE_INT iwhich;
+
+  if (TREE_CODE (which) != INTEGER_CST) {
+error ("argument of %<__builtin_eh_return_regno%> must be constant");
+return false;
+  }
+
+  iwhich = tree_low_cst (which, 1);
+  iwhich = EH_RETURN_DATA_REGNO (iwhich);
+  if (iwhich == INVALID_REGNUM)
+return false;
+
+  iwhich = DWARF_FRAME_REGNUM (iwhich);
+
+  Result = ConstantInt::

[llvm-commits] [llvm] r39857 - in /llvm/trunk: include/llvm/Support/ConstantRange.h lib/Support/ConstantRange.cpp

2007-07-14 Thread Nick Lewycky
Author: nicholas
Date: Sat Jul 14 12:41:03 2007
New Revision: 39857

URL: http://llvm.org/viewvc/llvm-project?rev=39857&view=rev
Log:
Clarify the language. Pointed out by Duncan Sands.

Modified:
llvm/trunk/include/llvm/Support/ConstantRange.h
llvm/trunk/lib/Support/ConstantRange.cpp

Modified: llvm/trunk/include/llvm/Support/ConstantRange.h
URL: 
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ConstantRange.h?rev=39857&r1=39856&r2=39857&view=diff

==
--- llvm/trunk/include/llvm/Support/ConstantRange.h (original)
+++ llvm/trunk/include/llvm/Support/ConstantRange.h Sat Jul 14 12:41:03 2007
@@ -145,8 +145,11 @@
 
   /// maximalIntersectWith - Return the range that results from the 
intersection
   /// of this range with another range.  The resultant range is guaranteed to
-  /// include all elements contained in both input ranges, and is also
-  /// guaranteed to be the smallest possible set that does so.
+  /// include all elements contained in both input ranges, and to have the
+  /// smallest possible set size that does so.  Because there may be two
+  /// intersections with the same set size, A.maximalIntersectWith(B) might not
+  /// be equal to B.maximalIntersectWith(A).
+  ///
   ConstantRange maximalIntersectWith(const ConstantRange &CR) const;
 
   /// unionWith - Return the range that results from the union of this range

Modified: llvm/trunk/lib/Support/ConstantRange.cpp
URL: 
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ConstantRange.cpp?rev=39857&r1=39856&r2=39857&view=diff

==
--- llvm/trunk/lib/Support/ConstantRange.cpp (original)
+++ llvm/trunk/lib/Support/ConstantRange.cpp Sat Jul 14 12:41:03 2007
@@ -248,8 +248,10 @@
 
 /// maximalIntersectWith - Return the range that results from the intersection
 /// of this range with another range.  The resultant range is guaranteed to
-/// include all elements contained in both input ranges, and is also guaranteed
-/// to be the smallest possible set that does so.
+/// include all elements contained in both input ranges, and to have the
+/// smallest possible set size that does so.  Because there may be two
+/// intersections with the same set size, A.maximalIntersectWith(B) might not
+/// be equal to B.maximalIntersect(A).
 ConstantRange ConstantRange::maximalIntersectWith(const ConstantRange &CR) 
const {
   assert(getBitWidth() == CR.getBitWidth() && 
  "ConstantRange types don't agree!");


___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] [llvm] r39851 - in /llvm/trunk: include/llvm/Support/ConstantRange.h lib/Support/ConstantRange.cpp

2007-07-14 Thread Duncan Sands
Hi Nick,

> +  /// maximalIntersectWith - Return the range that results from the 
> intersection
> +  /// of this range with another range.  The resultant range is guaranteed to
> +  /// include all elements contained in both input ranges, and is also
> +  /// guaranteed to be the smallest possible set that does so.

this should really be "a smallest possible set" since there can be two.
I guess by "smallest" you mean "with the minimal number of elements".
[The other possible definition, "smallest" = "contained in every interval
that contains the intersection", doesn't work on the circle].  There are
cases in which two intervals contain the intersection and have the smallest
possible number of elements (they go around the circle in different
directions) and then you presumably make an arbitrary choice.  Unfortunately
this means that maximalIntersection(A,B) and maximalIntersection(B,A) may
not be equal.  Probably this doesn't matter much.

Ciao,

Duncan.
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] [llvm] r39856 - /llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

2007-07-14 Thread Nick Lewycky
Author: nicholas
Date: Sat Jul 14 10:11:14 2007
New Revision: 39856

URL: http://llvm.org/viewvc/llvm-project?rev=39856&view=rev
Log:
Fix the build. Patch from Holger Schurig.

Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
URL: 
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=39856&r1=39855&r2=39856&view=diff

==
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Sat Jul 14 10:11:14 2007
@@ -696,7 +696,7 @@
 }
 }
 break;
-  case ISD::EH_RETURN:
+  case ISD::EH_RETURN: {
 MVT::ValueType VT = Node->getValueType(0);
 // The only "good" option for this node is to custom lower it.
 switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
@@ -710,6 +710,7 @@
   Result = LegalizeOp(Node->getOperand(0));
   break;
 }
+}
 break;
   case ISD::AssertSext:
   case ISD::AssertZext:


___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] [llvm] r39855 - in /llvm/trunk: include/llvm/ include/llvm/CodeGen/ include/llvm/Target/ lib/CodeGen/ lib/CodeGen/SelectionDAG/ lib/Target/ARM/ lib/Target/Alpha/ lib/Target/IA64/ lib/Ta

2007-07-14 Thread Anton Korobeynikov
Author: asl
Date: Sat Jul 14 09:06:15 2007
New Revision: 39855

URL: http://llvm.org/viewvc/llvm-project?rev=39855&view=rev
Log:
Long live the exception handling!

This patch fills the last necessary bits to enable exceptions
handling in LLVM. Currently only on x86-32/linux.

In fact, this patch adds necessary intrinsics (and their lowering) which
represent really weird target-specific gcc builtins used inside unwinder.

After corresponding llvm-gcc patch will land (easy) exceptions should be
more or less workable. However, exceptions handling support should not be 
thought as 'finished': I expect many small and not so small glitches
everywhere.

Modified:
llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h
llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
llvm/trunk/include/llvm/Intrinsics.td
llvm/trunk/include/llvm/Target/MRegisterInfo.h
llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp
llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
llvm/trunk/lib/Target/ARM/ARMRegisterInfo.cpp
llvm/trunk/lib/Target/ARM/ARMRegisterInfo.h
llvm/trunk/lib/Target/Alpha/AlphaRegisterInfo.cpp
llvm/trunk/lib/Target/Alpha/AlphaRegisterInfo.h
llvm/trunk/lib/Target/IA64/IA64RegisterInfo.cpp
llvm/trunk/lib/Target/IA64/IA64RegisterInfo.h
llvm/trunk/lib/Target/PowerPC/PPCRegisterInfo.cpp
llvm/trunk/lib/Target/PowerPC/PPCRegisterInfo.h
llvm/trunk/lib/Target/Sparc/SparcRegisterInfo.cpp
llvm/trunk/lib/Target/Sparc/SparcRegisterInfo.h
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
llvm/trunk/lib/Target/X86/X86ISelLowering.h
llvm/trunk/lib/Target/X86/X86InstrInfo.td
llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp
llvm/trunk/lib/Target/X86/X86RegisterInfo.h
llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp

Modified: llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h?rev=39855&r1=39854&r2=39855&view=diff

==
--- llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h Sat Jul 14 09:06:15 2007
@@ -1030,6 +1030,9 @@
   // Personalities - Vector of all personality functions ever seen. Used to 
emit
   // common EH frames.
   std::vector Personalities;
+
+  bool CallsEHReturn;
+  bool CallsUnwindInit;
 public:
   static char ID; // Pass identification, replacement for typeid
 
@@ -1072,6 +1075,12 @@
   /// needsFrameInfo - Returns true if we need to gather callee-saved register
   /// move info for the frame.
   bool needsFrameInfo() const;
+
+  bool callsEHReturn() const { return CallsEHReturn; }
+  void setCallsEHReturn(bool b) { CallsEHReturn = b; }
+
+  bool callsUnwindInit() const { return CallsUnwindInit; }
+  void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
   
   /// NextLabelID - Return the next unique label id.
   ///

Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
URL: 
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h?rev=39855&r1=39854&r2=39855&view=diff

==
--- llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h (original)
+++ llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h Sat Jul 14 09:06:15 2007
@@ -110,6 +110,11 @@
 // to the current function's frame or return address, an index of one to 
the
 // parent's frame or return address, and so on.
 FRAMEADDR, RETURNADDR,
+
+// FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
+// 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.
@@ -119,6 +124,12 @@
 // the selection index of the exception thrown.
 EHSELECTION,
 
+// OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
+// 'eh_return' gcc dwarf builtin, which is used to return from
+// exception. The general meaning is: adjust stack by OFFSET and pass
+// execution to HANDLER. Many platform-related details also :)
+EH_RETURN,
+
 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
 // simplification of the constant.
 TargetConstant,

Modified: llvm/trunk/include/llvm/Intrinsics.td
URL: 
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Intrinsics.td?rev=39855&r1=39854&r2=39855&view=diff

==
--- llvm/trunk/include/llvm/Intrinsics.td (original)
+++ llvm/trunk/include/llvm/Intrinsics

[llvm-commits] [llvm-gcc-4-2] r39854 - /llvm-gcc-4-2/trunk/README.LLVM

2007-07-14 Thread Anton Korobeynikov
Author: asl
Date: Sat Jul 14 08:36:06 2007
New Revision: 39854

URL: http://llvm.org/viewvc/llvm-project?rev=39854&view=rev
Log:
Correct documentation

Modified:
llvm-gcc-4-2/trunk/README.LLVM

Modified: llvm-gcc-4-2/trunk/README.LLVM
URL: 
http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/README.LLVM?rev=39854&r1=39853&r2=39854&view=diff

==
--- llvm-gcc-4-2/trunk/README.LLVM (original)
+++ llvm-gcc-4-2/trunk/README.LLVM Sat Jul 14 08:36:06 2007
@@ -10,20 +10,22 @@
 Please follow these instructions carefully.  In particular, the target-specific
 configure instructions should be followed to ensure correct builds.
 
+Please also note, that this branch is still in early development phase and can
+be not usable at all.
 
 
//===--===//
First Step: Build LLVM
 
//===--===//
 
-First, check out LLVM from CVS, then build it in optimized mode (a Release
-build, as opposed to a Debug one)):
+First, check out LLVM from Subversion, then build it in optimized mode (a 
+Release build, as opposed to a Debug one)):
 
   make ENABLE_OPTIMIZED=1
 
 If you use a Debug instead of a Release build of LLVM, make sure you add
 --enable-checking to the configure flags below or llvm-gcc-4.2 will not build!
 
-Below we assume the LLVM OBJDIR is $LLVMOBJDIR.  
+Below we assume the LLVM OBJ_ROOT is $LLVMOBJDIR.
 
 
 
//===--===//


___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits